<template>
  <div class="content-main">
    <header>
      <h1 class="header">退款信息</h1>
    </header>
    <el-form :model="dform" label-position="right" label-width="6em" ref="dform">
      <el-col :span="12">
        <el-form-item label="退款单位:">
          <el-input v-model="dform.dwmc" disabled clearable class="w90"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="退款金额:">
          <el-input
            v-model="dform.tkje"
            :disabled="isView"
            clearable
            class="w90"
            oninput="this.value= this.value.replace(/[^\d.]/g, '').replace(/(\d+\.\d{1,2})\.?\d*/, '$1')"
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="退款说明">
          <el-input
            :disabled="isView"
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 4 }"
            v-model="dform.remark"
            class="w95"
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="退款时间">
          <el-input v-model="dform.tksj" class="w90" disabled></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="操作人">
          <el-input class="w90" v-model="dform.czr" disabled></el-input>
        </el-form-item>
      </el-col>
    </el-form>
    <footer>
      <el-button type="primary" class="iconfont icontijiao" v-if="!isView" @click="handleSubmit">提交</el-button>
      <el-button type="primary" class="iconfont iconfanhui" @click="$router.go(-1)">返回</el-button>
    </footer>
  </div>
</template>
<script>
import {
  confirmMarginRefundBusiness,
  getMarginRefundDetail
} from "@/api/transaction/ensureManage/index.js";
import { dateTimeFormat } from "@/utils/index";
export default {
  data() {
    return {
      dform: {
        remark: `结算部
      XXXX签订的XXX合同已履约完成，共计XXX吨，单价XXX元/吨，请扣除合同手续费sss元，剩余保证金ssss元。`
      },
      isView: false,
      dwmc: "",
      wthbm: ""
    };
  },
  created() {
    let { state, tkbm, dwmc, type, wthbm } = this.$route.query;
    this.dwmc = dwmc;
    this.isView = state == "show" || type == 1;
    this.dform.tkbm = tkbm;
    this.wthbm = wthbm;
    this.getDetail();
  },
  methods: {
    async handleSubmit() {
      // alert("111");
      this.dform.tkfl = 0;
      this.dform.tkzt = "91000056";
      this.dform.tkztmc = "待确认";
      this.dform.url = `/transaction/ensureManage/marginRefundFinancialDetail`;
      this.dform.itemQuery = JSON.stringify({
        type: "2",
        idKey: "tkbm",
        backUrl: "marginRefundFinancialList"
      });
      this.dform.itemQueryHaveDone = JSON.stringify({
        type: "1",
        idKey: "tkbm",
        backUrl: "marginRefundFinancialList"
      });

      let res = await confirmMarginRefundBusiness(this.dform);
      if (res.infoCode == 200) {
        this.$message.success("提交成功!");
        this.$router.go(-1);
      }
    },
    async getDetail() {
      let res = await getMarginRefundDetail({ tkbm: this.dform.tkbm });
      if (res.infoCode == 200) {
        this.dform = res.data;
        if (!this.isView) {
          this.dform.tksj = dateTimeFormat(new Date());
          this.dform.czr = sessionStorage.orgName;
          this.dform.dwmc = this.dwmc;
          // this.dform.wthbm = this.wthbm;
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.header {
  font-size: 20px;
  text-align: center;
  margin-bottom: 20px;
}
.w90 {
  width: 90% !important;
}
.w95 {
  width: 95%;
}
.el-form {
  overflow: hidden;
}
footer {
  text-align: center;
  margin: 20px;
}
</style>
