<template>
  <div class="content-main">
    <h2
      style="
        text-align: center;
        font-weight: 700;
        margin-bottom: 10px;
        font-size: 18px;
        color: #4588db;
      "
    >
      场次基本情况
    </h2>
    
      <el-form
        style="width: 100%"
        ref="formDetail"
        label-width="140px"
        :model="formDetail"
      >
        <div class="wrap">
          <el-row>
            <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>
            
            <!-- <el-col :span="12">
              <el-form-item label="交易保证金:" prop="jybzj">
                <el-input
                  disabled
                  clearable
                  v-model="formDetail.jybzj"
                  placeholder="请输入交易保证金"
                  class="w90"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="履约保证金:" prop="lybzj">
                <el-input
                  disabled
                  clearable
                  v-model="formDetail.lybzj"
                  placeholder="请输入履约保证金"
                  class="w90"
                ></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="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="yxbd">
              <el-select
                multiple
                disabled
                clearable
                v-model="formDetail.yxbd"
                class="w90"
              >
                <el-option
                  v-for="item in bdOptions"
                  :key="item.bdh"
                  :label="item.bdh"
                  :value="item.bdh"
                ></el-option>
              </el-select>
            </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-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>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审核结果:" prop="jyshjg" required>
                <el-radio-group
                  v-model="formDetail.jyshjg"
                  :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="jyshsj">
                <el-date-picker
                  v-model="formDetail.jyshsj"
                  disabled
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="审核意见:" prop="jyshyj">
                <el-input
                  :disabled="disableFlag"
                  type="textarea"
                  clearable
                  v-model="formDetail.jyshyj"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    <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 } from "@/utils/index";
import { FileApi } from "@/api/index";
export default {
  // components: {},
  // name: 'userInfo',
  data() {
    return {
      fileUrl: `${FileApi}/file/upload`,
      tableData: [{ name: "000" }],
      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,
            jyfxmc: this.formDetail.jyfsmc == '购销双向' ? "采购、销售" : this.formDetail.jyfxmc,
            jyshjg: ts.jyshjg == 0 ? 0 : 1,
            jyshsj: ts.jyshsj || getNowDate(),
            shsj: ts.shsj || getNowDate(),
            shjg: ts.shztmc == "已驳回" ? "不通过" : "通过",
          };
          this.formDetail.yxbd = this.formDetail.yxbd
            ? this.formDetail.yxbd.split(",")
            : [];

          if (this.$route.query.state == "detail") {
            if (
              ts.shztmc != "已驳回" &&
              ts.shztmc != "已通过" &&
              ts.shztmc != "确认已付款" &&
              ts.shztmc != "审核通过"
            ) {
              this.formDetail.shjg = "不通过";
            }
          }
          // 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() {
      let state = this.formDetail.shjg == "通过" ? 0 : 1;
      this.save(state);
    },
    save(state) {
      let comData = {
        jyshjg: this.formDetail.jyshjg,
        jyshsj: this.formDetail.jyshsj,
        jyshyj: this.formDetail.jyshyj,
        jyshr: sessionStorage.getItem("userName"),

        shzt: this.formDetail.jyshjg == 1 ? status1.passed.value : status1.hasRefused.value,
        shztmc: this.formDetail.jyshjg == 1 ? status1.passed.name : status1.hasRefused.name,
        // shyj: this.formDetail.shyj,
        jybm: this.$route.query.jybm,
        apcc: this.formDetail.apcc,
        bdbm: this.formDetail.bdbm,
        shsj: this.formDetail.shsj,
        spr: this.formDetail.spr,
        wtbm: this.formDetail.wtbm,
        skzt: 0,
        skztmc: "否",
        itemQueryHaveDone: JSON.stringify({
          state: "detail",
          idKey: "jybm",
          ccbm: this.formDetail.ccbm,
        }),
      }
      if (state == 0) {
        
        let data = {
          ...comData,
          url: `/transaction/registrationFee/remittanceConfirm/detail`,
          itemQuery: JSON.stringify({
            state: "edit",
            idKey: "jybm",
            ccbm: this.formDetail.ccbm,
          })
        };
        updateTransactionSignUp(data).then((res) => {
          if (res.infoCode == 200) {
            this.$message({
              message: "审核成功",
              type: "success",
            });
            // this.$router.push({ name: 'signupExamine' })
            this.$router.go(-1);
          }
        });
      } else {
        let data = {
          dwbm: this.formDetail.dwbm,
          url: `/transaction/registrationFee/transactionSignup/detail`,
          itemQuery: JSON.stringify({
            state: "submit",
            idKey: "jybm",
            ccbm: this.formDetail.ccbm,
          })
        };
        updateTransactionSignUp(data).then((res) => {
          if (res.infoCode == 200) {
            this.$message({
              message: "操作成功",
              type: "success",
            });
            // this.$router.push({ name: 'signupExamine' })
            this.$router.go(-1);
          }
        });
      }
    },
    submit() {},
    handlePreview(file, fileList) {
      window.location.href = `${FileApi}/file/download?id=${this.formDetail.fjid}`;
    },
    returnList() {
      this.$router.go(-1);
    },
  },
  created() {
    switch (this.$route.query.state) {
      case "edit":
        this.disableFlag = false;
        this.formDetail.spr = sessionStorage.getItem("userName");
        this.formDetail.shsj = getNowDate();
        this.formDetail.jyshsj = getNowDate();
        break;
      case "detail":
        this.disableFlag = true;
        this.saveorfalse = false;
        break;
    }
    this.getDetail();
  },
  mounted() {},
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.content-main .com-h2 {
  font-size: 16px;
  line-height: 20px;
  color: #333;
  font-weight: normal;
  letter-spacing: 1px;
  padding: 0 20px;
  position: relative;
}

.com-h2 i {
  position: absolute;
  width: 3px;
  height: 20px;
  background: #56a9d6;
  left: 0;
  top: 20px;
  margin-left: 10px;
}

.com-h2 span {
  display: block;
  border-bottom: 1px solid #eaeaea;
  padding: 20px 0 5px;
}
.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>
