<template>
  <div class="content-main">
    <!-- <h2 style="font-weight:600;font-size:20px;text-align:center;margin-bottom:10px;">报名审核</h2> -->
    <el-row>
      <el-form style="width:100%;" ref="formDetail" label-width="140px" :model="formDetail">
        <div class="wrap">
          <el-col :span="12">
            <el-form-item label="委托编号:" required prop="wtbh">
              <el-input disabled clearable v-model="formDetail.wtbh"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场次:" prop="apcc">
              <el-input disabled clearable v-model="formDetail.apcc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易方向:" required>
              <el-input
                disabled
                clearable
                v-model="formDetail.jyfxmc"
                placeholder="请输入交易方向"
                class="w90"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易方式:" required>
              <el-input
                disabled
                clearable
                v-model="formDetail.jyfsmc"
                placeholder="请输入交易方向"
                class="w90"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易日期:" prop="jyrq">
              <el-input disabled clearable v-model="formDetail.jyrq"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交易时间:" prop="jysj">
              <el-input disabled clearable v-model="formDetail.jysj"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品种:" prop="lspzmc">
              <el-input disabled clearable v-model="formDetail.lspzmc" placeholder="请输入品种"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量(吨):" prop="sl">
              <!-- <el-input disabled clearable v-model="formDetail.sl" placeholder="请输入数量"></el-input> -->
              <el-input
                disabled
                clearable
                v-model="formDetail.sl"
                v-bind:value="
                  String(formDetail.sl).indexOf('.') > -1
                    ? Number(formDetail.sl).toFixed(3)
                    : formDetail.sl
                "
              ></el-input>
            </el-form-item>
          </el-col>
          
          <!-- <el-col :span="12">
					<el-form-item label="交易品种:" prop="lspzmc">
						<el-input
							disabled
							clearable
							v-model="formDetail.lspzmc"
							placeholder="请输入交易品种"
						></el-input>
					</el-form-item>
				</el-col>

				<el-col :span="12">
					<el-form-item label="金额:" prop="je">
						<el-input disabled clearable v-model="formDetail.je" placeholder="请输入金额"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="性质:" prop="lsxzmc">
						<el-input disabled clearable v-model="formDetail.lsxzmc" placeholder="请输入性质"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="类别:" prop="lslbmc">
						<el-input disabled clearable v-model="formDetail.lslbmc" placeholder="请输入类别"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col :span="12">
					<el-form-item label="联系电话:" prop="lxdh">
						<el-input disabled clearable v-model="formDetail.lxdh" placeholder="请输入联系电话"></el-input>
					</el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="交易保证金(元/吨):" prop="jybzj">
              <el-input
                disabled
                clearable
                class="w90"
                v-bind:value="
                  String(formDetail.jybzj).indexOf('.') > -1
                    ? Number(formDetail.jybzj).toFixed(2)
                    : formDetail.jybzj
                "
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="履约保证金(元/吨):" prop="lybzj">
              <el-input
                disabled
                clearable
                class="w90"
                v-bind:value="
                  String(formDetail.lybzj).indexOf('.') > -1
                    ? Number(formDetail.lybzj).toFixed(2)
                    : formDetail.lybzj
                "
              ></el-input>
            </el-form-item>
          </el-col>
        </div>

        <!-- <el-col :span="12">
					<el-form-item label="手续费率:" prop="lxr">
						<el-input disabled clearable v-model="formDetail.lxr" placeholder="请输入手续费率"></el-input>
					</el-form-item>
        </el-col>-->

        <el-col :span="12">
          <el-form-item label="报名日期:" prop="bmrq">
            <el-input disabled clearable v-model="formDetail.bmrq" placeholder="请输入报名日期"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报名单位:" prop="dwmc">
            <el-input disabled clearable v-model="formDetail.dwmc" placeholder="请输入报名单位"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="意向数量(吨):" prop="yxsl">
            <!-- <el-input disabled clearable v-model="formDetail.yxsl" placeholder="请输入意向数量"></el-input> -->
            <el-input
              disabled
              clearable
              v-model="formDetail.yxsl"
              v-bind:value="
                String(formDetail.yxsl).indexOf('.') > -1
                  ? Number(formDetail.yxsl).toFixed(3)
                  : formDetail.yxsl
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="意向标的:" prop="yxbd">
            <el-input disabled clearable v-model="formDetail.yxbd" placeholder="请输入报名单位"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="缴款额(元):" prop="jkje">
            <!-- <el-input disabled clearable v-model="formDetail.jkje" placeholder="请输入缴款额" class="w90"></el-input> -->
            <el-input
              disabled
              clearable
              v-model="formDetail.jkje"
              v-bind:value="
                String(formDetail.jkje).indexOf('.') > -1
                  ? Number(formDetail.jkje).toFixed(2)
                  : formDetail.jkje
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人:" prop="lxr">
            <el-input disabled clearable v-model="formDetail.lxr" placeholder="请输入联系人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话:" prop="lxdh">
            <el-input disabled clearable v-model="formDetail.lxdh" placeholder="请输入联系电话"></el-input>
          </el-form-item>
        </el-col>
        <el-row>
          <el-col :span="12">
            <el-form-item label="附件:">
              <el-upload
                style="width:40%;"
                disabled
                class="upload-demo"
                :action="fileUrl"
                :on-preview="handlePreview"
                :file-list="fileList"
              ></el-upload>
              <!-- <span  @click="fjdetail(scope.row)">{{fjmc}}</span> -->
            </el-form-item>
          </el-col>
        </el-row>
        <template>
          <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
            <span style="margin-left:10px">交易审核信息:</span>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审核结果:" prop="jyshjg" required>
                <el-radio-group v-model="formDetail.jyshjg" disabled>
                  <el-radio :label="1">通过</el-radio>>
                  <el-radio :label="0">不通过</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审核时间:" prop="jyshsj">
                <el-date-picker
                  v-model="formDetail.jyshsj"
                  disabled
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
                <!-- <el-input clearable v-model="formDetail.shsj" disabled placeholder="请输入审核时间"></el-input> -->
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审核意见:" prop="jyshyj">
                <el-input
                  disabled
                  type="textarea"
                  clearable
                  v-model="formDetail.jyshyj"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
        <template>
          <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
            <span style="margin-left:10px">汇款信息:</span>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审核结果:" prop="hkshjg" required>
                <el-radio-group v-model="formDetail.hkshjg" :disabled="disableFlag">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审核时间:" prop="hkshsj">
                <el-date-picker
                  v-model="formDetail.hkshsj"
                  disabled
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
                <!-- <el-input disabled v-model="formDetail.hksj"></el-input> -->
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审核意见:">
                <el-input
                  :disabled="disableFlag"
                  type="textarea"
                  clearable
                  v-model="formDetail.hkshyj"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
      </el-form>
    </el-row>
    <span class="detail-footer">
      <!-- <el-button @click="save(0)" type="primary" v-if="saveorfalse" size="small" class="iconfont iconbaocun"
				>审核通过</el-button
			>
			<el-button @click="save(1)" type="primary" v-if="saveorfalse" size="small" class="iconfont icontijiao"
				>驳回</el-button
      >-->
      <el-button
        @click="handleSave"
        type="primary"
        v-if="saveorfalse"
        size="small"
        class="iconfont iconbaocun"
      >保存</el-button>
      <el-button @click="returnList" type="primary" size="small" class="iconfont iconfanhui">返回</el-button>
    </span>
  </div>
</template>

<script>
import {
  selectTransactionSignUpDetail,
  updateTransactionSignUp,
  fileInfo,
  selectTradeByCcbm
} from "@/api/transaction/registrationFee/transactionSignup/index";
import { status1 } from "@/utils/statusList.js";
import { getNowDate, dateTimeFormat } from "@/utils/index";
import { FileApi } from "@/api/index";
export default {
  // components: {},
  // name: 'userInfo',
  data() {
    return {
      fileUrl: `${FileApi}/file/upload`,
      tableData: [{ name: "" }],
      dialogTableVisible: false,
      formDetail: {},
      disableFlag: false,
      fileList: [],
      saveorfalse: true,
      bdOptions: []
    };
  },
  methods: {
    getDetail() {
      selectTradeByCcbm(this.$route.query.ccbm).then(res => {
        if (res.infoCode == 200) {
          this.bdOptions = res.data.data;
        }
      });
      let { ccbm, jybm } = this.$route.query;
      selectTransactionSignUpDetail({ jybm, ccbm }).then(res => {
        if (res.infoCode == 200) {
          let resp = res.data;
          // this.formDetail = resp.siteVO;
          this.formDetail = resp.transactionSignUpVO;
          // let ee = resp.entryAndExitOrderVO;
          let ts = resp.transactionSignUpVO || {};
          this.formDetail = {
            ...this.formDetail,
            jybm: jybm,
            shsj: ts.shsj || getNowDate(),
            hkshjg: ts.hkshjg == 0 ? 0 : 1,
            hkshsj: ts.shsj || getNowDate(),
            shjg: ts.shztmc == "已驳回" ? "不通过" : "通过",
            hksj: ts.hksj || dateTimeFormat(new Date()),
          };
          // this.formDetail.yxbd = this.formDetail.yxbd
          //   ? this.formDetail.yxbd.split(",")
          //   : [];
          if (this.$route.query.state == "edit") {
            this.formDetail.skzt = 1;
          }
          // this.formDetail = res.data
          if (this.formDetail.fjid) {
            fileInfo(this.formDetail.fjid).then(res => {
              this.fileList = res.data;
            });
          }
        }
      });
    },
    resetInfo(formName) {
      this.$refs[formName].resetFields();
      this.getList();
    },
    handleSave() {
      if (this.formDetail.skzt == 0) {
        this.formDetail.url = `/transaction/registrationFee/transactionSignup/detail`;
        this.formDetail.itemQuery = JSON.stringify({
          state: "submit",
          idKey: "jybm",
          ccbm: this.formDetail.ccbm
        });
        this.formDetail.itemQueryHaveDone = JSON.stringify({
          state: "detail",
          idKey: "jybm",
          ccbm: this.formDetail.ccbm
        });
      }
      this.save();
    },
    save() {
      let postData = {
        ...this.formDetail,
        shzt: this.formDetail.hkshjg == 1 ? status1.hkPassed.value : status1.hkHasRefused.value,
        shztmc: this.formDetail.hkshjg == 1 ? status1.hkPassed.name : status1.hkHasRefused.name,
        hkshjg: this.formDetail.hkshjg,
        hkshsj: this.formDetail.hkshsj,
        hkshyj: this.formDetail.hkshyj,
        hkshr: sessionStorage.getItem("userName"),
      }
      updateTransactionSignUp(postData).then(res => {
        if (res.infoCode == 200) {
          this.$message.success("保存成功!");
          this.$router.push("index");
        } else {
          this.$message.error("保存失败");
        }
      });
    },
    submit() {},
    handlePreview(file, fileList) {
      window.location.href = `${FileApi}/file/download?id=${this.formDetail.fjid}`;
    },
    returnList() {
      this.$router.push("index");
    }
  },
  created() {
    switch (this.$route.query.state) {
      case "edit":
        this.disableFlag = false;
        this.formDetail.spr = sessionStorage.getItem("userName");
        this.formDetail.shsj = getNowDate();
        this.formDetail.hkshsj = getNowDate();
        break;
      case "detail":
        this.disableFlag = true;
        this.saveorfalse = false;
        break;
    }
    this.getDetail();
  },
  mounted() {}
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.line {
  border-bottom: 1px solid #000;
}
.title {
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}
.text {
  text-align: center;
}
.wrap {
  width: 100%;
  overflow: hidden;
}
</style>
