<template>
  <view class="taskContent">
    <u--form
      :model="model"
      ref="uForm"
      :labelAlign="'left'"
      :labelStyle="{ fontSize: '28rpx' }"
      labelPosition="top"
      :style="{ marginTop: tarbarHeight }"
      class="formBox"
    >
      <u-form-item
        label="发送者应用"
        prop="sendAppName"
        ref="item1"
        required
        :borderBottom="true"
        :labelWidth="'180rpx'"
      >
        <uni-easyinput
          v-model="model.sendAppName"
          :disabled="true"
          :inputBorder="false"
          :styles="{ disableColor: '#ffffff', color: '#999999' }"
        ></uni-easyinput>
      </u-form-item>
      <u-form-item
        label="接口名称"
        prop="apiName"
        ref="item1"
        required
        :borderBottom="true"
        :labelWidth="'180rpx'"
      >
        <uni-easyinput
          v-model="model.apiName"
          :inputBorder="false"
          :disabled="true"
          :styles="{ disableColor: '#ffffff', color: '#999999' }"
        ></uni-easyinput>
      </u-form-item>
      <u-form-item
        label="源数据"
        prop="sourceData"
        ref="item1"
        required
        :borderBottom="true"
        :labelWidth="'180rpx'"
      >
        <uni-easyinput
          v-model="model.sourceData"
          type="textarea"
          autoHeight
          :inputBorder="false"
          :maxlength="-1"
          :styles="{
            paddingLeft: '10px',
          }"
        ></uni-easyinput>
      </u-form-item>
      <u-form-item
        label="目标数据"
        prop="targetData"
        ref="item1"
        required
        :borderBottom="true"
        :labelWidth="'180rpx'"
      >
        <uni-easyinput
          v-model="model.targetData"
          type="textarea"
          autoHeight
          :inputBorder="false"
          :maxlength="-1"
          :styles="{
            paddingLeft: '10px',
          }"
        ></uni-easyinput>
      </u-form-item>
      <u-form-item
        label="状态"
        prop="status"
        ref="item1"
        :borderBottom="true"
        :labelWidth="'180rpx'"
      >
        <u-radio-group
          v-model="model.status"
          iconPlacement="left"
          style="margin-left: 10rpx"
          :disabled="true"
        >
          <u-radio
            :customStyle="{ marginRight: '15px' }"
            v-for="(item, index) in radiolist"
            :key="index"
            :label="item.name"
            :name="item.id"
            :labelSize="13"
            :iconSize="13"
          ></u-radio>
        </u-radio-group>
      </u-form-item>
      <u-form-item
        label="错误状态"
        prop="errorStatus"
        ref="item1"
        :borderBottom="true"
        :labelWidth="'180rpx'"
        :disabled="true"
      >
        <u-radio-group
          v-model="model.errorStatus"
          iconPlacement="left"
          style="margin-left: 10rpx"
          :disabled="true"
        >
          <u-radio
            :customStyle="{ marginRight: '15px' }"
            v-for="(item, index) in errorRadiolist"
            :key="index"
            :label="item.name"
            :name="item.id"
            :labelSize="13"
            :iconSize="13"
          ></u-radio>
        </u-radio-group>
      </u-form-item>
      <u-form-item
        label="返回信息"
        prop="returnData"
        ref="item1"
        required
        :borderBottom="true"
        :labelWidth="'180rpx'"
        :disabled="true"
      >
        <uni-easyinput
          v-model="model.returnData"
          type="textarea"
          autoHeight
          :inputBorder="false"
          :disabled="true"
          :styles="{ disableColor: '#ffffff', color: '#999999' }"
        ></uni-easyinput>
      </u-form-item>
    </u--form>
    <!-- 按钮控制 -->
    <view class="bottomPage">
      <u-button
        text="标记成功"
        @click="signSuccess"
        style="margin-right: 30rpx"
      ></u-button>
      <u-button
        text="重新推送"
        type="primary"
        size="normal"
        @click="resend"
      ></u-button>
    </view>
    <base-tarbar ref="baseTarbar" pageTitle="查看异常日志"></base-tarbar>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
import { authApi } from "@/api/login";
import baseTarbar from "@/components/baseTarbar/index.vue";
export default {
  onLoad: function (option) {
    //option为object类型，会序列化上个页面传递的参数
    if (Object.getOwnPropertyNames(option).length != 0) {
      this.billID = option.billid;
    }
  },
  components: {
    baseTarbar,
  },
  data() {
    return {
      billID: "",
      tarbarHeight: "0",
      radiolist: [
        { id: "1", label: "待发送" },
        { id: "2", label: "发送中" },
        { id: "3", label: "发送成功" },
        { id: "4", label: "发送失败" },
      ],
      errorRadiolist: [
        { id: "1", label: "需要重新发送" },
        { id: "2", label: "不需要重新发送" },
      ],
      model: {},
    };
  },
  onReady() {
    this.$refs.baseTarbar.currentEnvironment();
    if (this.$refs.baseTarbar.isOther) {
      this.tarbarHeight = "84rpx";
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.messageLogGetById(this.billID);
    },
    // 编辑详情
    async messageLogGetById(id, row) {
      let params = {
        id: id,
        // status: row.status,
      };

      let res = await authApi(
        "sysMessageManageLogService",
        "messageManage",
        "thirdInterfacequeryEntity",
        "",
        params
      );

      if (res.status == "200") {
        let res2 = await authApi(
          "sysApplicationApiService",
          "application",
          "queryEntity",
          "",
          { apiCode: res.attribute.receiveCode }
        );
        if (res2.status == "200") {
          this.$set(res.attribute, "apiName", res2.attribute[0].apiName);
        } else {
          this.$set(res.attribute, "apiName", "未配置该接口");
        }
        this.$nextTick(() => {
          this.model = {
            ...res.attribute,
          };
        });
      }
    },
    async signSuccess() {
      let params = {
        id: this.billID,
        status: "3",
      };
      let res = await authApi(
        "sysMessageManageLogService",
        "messageManage",
        "updateEntity",
        "",
        params
      );
      if (res.status == "200") {
        this.$vmNews("标记成功", "success");
        this.$refs.uToast.show({
          type: "success",
          message: "标记成功",
        });

        setTimeout(() => {
          uni.navigateBack();
        }, 500);
      }
    },
    async resend() {
      let formData = new FormData();
      formData.append("id", this.billID);
      formData.append("sourceData", this.model.sourceData);

      let res = await request({
        url: "kangarooDataCenterV3/entranceController/externalCallInterfaceResend",
        method: "post",
        data: formData,
      });
      if (res.status == "200") {
        this.handleDialogClose();
        if (res.msg == "重推成功") {
          this.$refs.uToast.show({
            type: "success",
            message: res.msg,
          });
        }
        if (res.msg == "重推失败") {
          this.$refs.uToast.show({
            type: "error",
            message: res.msg,
          });
        }
        setTimeout(() => {
          uni.navigateBack();
        }, 500);
      }
    },
  },
};
</script>

<style scoped>
.bottomPage {
  width: 100%;
  position: fixed;
  bottom: 0;
  padding: 20rpx 30rpx 30rpx 30rpx;
  background-color: #fff;
  margin-top: 15rpx;
  display: flex;
  border-top: 8rpx solid #f1f1f1;
}
.formBox {
  padding: 10px 10px 100px 10px;
}
::v-deep .uni-easyinput__content-textarea {
  padding-left: 10px !important;
}
page {
  height: 100vh;
  background: #fff;
}
</style>