<template>
  <div class="content-main">
    <h1 class="content-title">粮食竞价交易购销合同</h1>
    <el-form
      :model="dform"
      ref="dform"
      label-position="right"
      label-width="11em"
      :rules="rules"
      :disabled="isView"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="合同编号:" prop="htbh">
            <el-input clearable v-model="dform.htbh"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="场次:" prop="apcc">
            <el-select clearable v-model="dform.apcc" @change="changeApcc">
              <el-option
                v-for="(item, index) in ccOptions"
                :key="index"
                :label="item.apcc"
                :value="item.apcc"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="标的:" prop="bdbm">
            <!-- <el-select
              clearable
              v-model="dform.bdh"
              @change="handleSelect"
            >
              <el-option
                v-for="(item, index) in bdList"
                :key="index"
                :label="item.bdh"
                :value="item.bdbm"
              ></el-option>
            </el-select> -->
            <el-select clearable v-model="dform.bdbm" @change="changeBd">
              <el-option
                v-for="(item, index) in bdList"
                :key="index"
                :label="item.bdh"
                :value="item.bdbm"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="委托单位:" prop="wtfmc">
            <el-input v-model="dform.wtfmc" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交易方向">
            <el-checkbox-group
              disabled
              style="width: 100%"
              v-model="jyfxCheckbox"
            >
              <el-checkbox class="radioSize" label="0">采购</el-checkbox>
              <el-checkbox class="radioSize" label="1">销售</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交易方式:" prop="jyfs">
            <el-radio-group v-model="dform.jyfs" disabled>
              <el-radio label="0">竞价</el-radio>
              <el-radio label="1">挂牌</el-radio>
              <el-radio label="2">购销双向</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="承储单位:" prop="cckmc">
            <el-input v-model="dform.cckmc" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="仓号:" prop="nch">
            <el-input v-model="dform.nch" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="品种:">
            <el-input clearable v-model="dform.pzmc" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生产年份:">
            <el-input clearable v-model="dform.nnf" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交易日期:">
            <el-input v-model="dform.jyrq" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="完成时间:">
            <el-input v-model="dform.promptDate" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="成交数量(吨)" prop="nzcjl">
            <!-- <el-input
              disabled
              v-model="dform.nzcjl"
              oninput="this.value= this.value.replace(/[^\d.]/g, '').replace(/(\d+\.\d{1,3})\.?\d*/, '$1')"
            ></el-input> -->
            <el-input
              disabled
              v-bind:value="
                String(dform.nzcjl).indexOf('.') > -1
                  ? Number(dform.nzcjl).toFixed(3)
                  : dform.nzcjl
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="成交单位:" prop="cjfmc">
            <!-- <el-input
              clearable
            
              disabled
              v-model="dform.sgmc"
              v-if="this.dform.jylx == 0"
              key="q2"
            ></el-input>
            <el-select
              v-else
              key="q3"
              clearable
              v-model="dform.sgmc"
              filterable
              :disabled="$route.query.type != 'add'"
              @change="dform.sgdw = qys.filter(p => p.dwmc == $event)[0]['dwbm']"
            >
              <el-option
                v-for="(item,index) in qys"
                :key="index"
                :label="item.dwmc"
                :value="item.dwmc"
              ></el-option>
            </el-select> -->
            <el-select
              clearable
              v-model="dform.cjfmc"
              filterable
              @change="changeCjdw"
            >
              <!-- <el-option
                v-for="(item, index) in qys"
                :key="index"
                :label="item.dwmc"
                :value="item.dwbm"
              ></el-option> -->
              <el-option
                v-for="(item, index) in qys"
                :key="index"
                :label="item.khmc"
                :value="item.khmc"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="起拍单价(元/吨):" prop="qpdj">
            <!-- <el-input clearable v-model="dform.qpdj" :disabled="isView"></el-input> -->
            <el-input
              clearable
              :disabled="isView"
              oninput="this.value= this.value.replace(/[^\d.]/g, '').replace(/(\d+\.\d{1,3})\.?\d*/, '$1')"
              v-model="dform.qpdj"
              v-bind:value="
                String(dform.qpdj).indexOf('.') > -1
                  ? Number(dform.qpdj).toFixed(2)
                  : dform.qpdj
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="成交单价(元/吨):" prop="cjdj">
            <!-- <el-input clearable v-model="dform.cjdj" :disabled="isView"></el-input> -->
            <el-input
              clearable
              :disabled="isView"
              oninput="this.value= this.value.replace(/[^\d.]/g, '').replace(/(\d+\.\d{1,3})\.?\d*/, '$1')"
              v-model="dform.cjdj"
              v-bind:value="
                String(dform.cjdj).indexOf('.') > -1
                  ? Number(dform.cjdj).toFixed(2)
                  : dform.cjdj
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="成交额(元):" prop="cje">
            <!-- <el-input v-if="$route.query.dataVer != 0" v-model="cje" disabled></el-input>
            <el-input v-else v-model="dform.je" disabled></el-input> -->
            <el-input
              v-if="$route.query.dataVer != 0"
              disabled
              v-bind:value="
                String(cje).indexOf('.') > -1 ? Number(cje).toFixed(2) : cje
              "
            ></el-input>
            <el-input
              v-else
              disabled
              v-bind:value="
                String(dform.je).indexOf('.') > -1
                  ? Number(dform.je).toFixed(2)
                  : dform.je
              "
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="实际交款额(元):">
            <!-- <el-input clearable v-model="dform.sjjke" :disabled="isView"></el-input> -->
            <el-input
              clearable
              :disabled="isView"
              oninput="this.value= this.value.replace(/[^\d.]/g, '').replace(/(\d+\.\d{1,3})\.?\d*/, '$1')"
              v-model="dform.sjjke"
              v-bind:value="
                dform.sjjke
                  ? /^[0-9]+$/.test(Number(dform.sjjke))
                    ? Number(dform.sjjke).toFixed()
                    : Number(dform.sjjke).toFixed(2)
                  : ''
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手续费(元):" prop="sxf">
            <el-input
              disabled
              v-bind:value="
                /^[0-9]+$/.test(Number(sxf))
                  ? Number(sxf).toFixed()
                  : Number(sxf).toFixed(2)
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交易保证金(元):" prop="jybzj">
            <el-input
              disabled
              v-bind:value="
                /^[0-9]+$/.test(Number(jybzj))
                  ? Number(jybzj).toFixed()
                  : Number(jybzj).toFixed(2)
              "
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="履约保证金(元):" prop="lybzj">
            <el-input
              disabled
              v-bind:value="
                /^[0-9]+$/.test(Number(lybzj))
                  ? Number(lybzj).toFixed()
                  : Number(lybzj).toFixed(2)
              "
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="联系人:" prop="lxr">
            <el-input
              clearable
              v-model="dform.lxr"
              placeholder="请输入联系人"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系方式:" prop="lxfs">
            <el-input
              clearable
              v-model="dform.lxfs"
              placeholder="请输入联系电话"
            ></el-input>
          </el-form-item>
        </el-col>

        <!-- <el-col :span="12">
          <el-form-item label="卖方:" prop="cmmc">
            <el-input
              clearable
            
              disabled
              v-model="dform.cmmc"
              v-if="this.dform.jylx == 1"
              key="q0"
            ></el-input>
            <el-select
              v-else
              key="q1"
              clearable
              v-model="dform.cmmc"
              filterable
            
              :disabled="$route.query.type != 'add'"
              @change="dform.cmdw = qys.filter(p => p.dwmc == $event)[0]['dwbm']"
            >
              <el-option
                v-for="(item,index) in qys"
                :key="index"
                :label="item.dwmc"
                :value="item.dwmc"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="买方:" prop="sgmc">
            <el-input
              clearable
            
              disabled
              v-model="dform.sgmc"
              v-if="this.dform.jylx == 0"
              key="q2"
            ></el-input>
            <el-select
              v-else
              key="q3"
              clearable
              v-model="dform.sgmc"
              filterable
            
              :disabled="$route.query.type != 'add'"
              @change="dform.sgdw = qys.filter(p => p.dwmc == $event)[0]['dwbm']"
            >
              <el-option
                v-for="(item,index) in qys"
                :key="index"
                :label="item.dwmc"
                :value="item.dwmc"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->

        <!-- <el-col :span="12">
          <el-form-item label="等级:">
            <el-select v-model="dform.lsdj" disabled>
              <el-option
                v-for="(item, index) in grades"
                :key="index"
                :label="item.dictName"
                :value="item.dictCode"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="数量:" prop="lssl">
            <el-input clearable v-model="dform.lssl" :disabled="isView"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单价:" prop="dj">
            <el-input clearable v-model="dform.dj" :disabled="isView"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="价款:">
            <el-input v-model="sum" clearable disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="成交时间:" prop="cjrq">
            <el-date-picker
              clearable
              v-model="dform.cjrq"
              :disabled="isView"
              type="date"
              format="yyyy-MM-dd"
            
            ></el-date-picker>
          </el-form-item>
        </el-col> -->

        <!-- <el-col :span="12">
          <el-form-item label="商户编号:">
            <el-input clearable v-model="dform.shbh" :disabled="isView"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="签订地点:">
            <el-input clearable v-model="dform.qddd" :disabled="isView"></el-input>
          </el-form-item>
        </el-col>
        <article>
          <p class="text">
            受国家有关部门委托，由中国储备粮管理总公司作为卖方代行签订交易合同，交货仓库为中标标的号对应的
            所卖粮食的实际存粮地点，承贷库作为卖方代表具体负责粮食交货、商务处理等工作并承担合同规定的相应责
            任。
          </p>
          <p class="text">
            <span class="sub-title">第一条</span>中标标的号、品种、数量、单价、价款：
          </p>
          <table>
            <thead>
              <tr>
                <th width="16%">标的号</th>
                <th width="16%">品种</th>
                <th width="16%">等级</th>
                <th width="16%">数量</th>
                <th width="16%">单价</th>
                <th width="16%">价款（元）</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td></td>
                <td>
                  <span>{{ dform.pzmc }}</span>
                </td>
                <td>
                  <el-form-item id="form-zdy">
                    
                    <el-select v-model="dform.lsdj" disabled>
                      <el-option
                        v-for="(item, index) in grades"
                        :key="index"
                        :label="item.dictName"
                        :value="item.dictCode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </td>

                <td>
                  <span>{{ dform.lssl }}</span>
                </td>
                <td>
                  <el-form-item id="form-zdy" prop="dj">
                    <el-input clearable v-model="dform.dj" :disabled="isView"></el-input>
                  </el-form-item>
                </td>
                <td>
                  <span>{{ dform.lssl * dform.dj || 0 }}</span>
                </td>
              </tr>
              <tr>
                <td colspan="6" class="td-left">合计人民币（大写金额）：{{ sum }} 元</td>
              </tr>
            </tbody>
          </table>
          <p class="text">
            <span class="sub-title">第二条</span>质量标准、用途：中标标的号对应的质量等级。
          </p>
          <p class="text">
            <span class="sub-title">第三条</span>交(提)货期限：按照《粮食竞价销售交易规则》第二十八条规定执行。
          </p>
          <p class="text">
            <span class="sub-title">第四条</span>交(提)货地点：中标标的号对应的所卖粮食的实际存粮地点。
          </p>
          <p class="text">
            <span class="sub-title">第五条</span>包装物标准及费用负担（含打包、上车费用）：按《粮食竞价销售交易规则》第二十、三十一条规定 执行。
          </p>
          <p class="text">
            <span class="sub-title">第六条</span>交货方式：卖方承储库的实际存粮库点仓内交货。
          </p>
          <p class="text">
            <span class="sub-title">第七条</span>运输方式及到达站（港）和费用负担：买方自负。
          </p>
          <p class="text">
            <span class="sub-title">第八条</span>货物验收办法：买方提货时验收，数量以卖方交货仓库计量衡器数为准。
          </p>
          <p class="text">
            <span class="sub-title">第九条</span>结算方式：买方根据《粮食竞价销售交易规则》及当期《交易公告》要求将货款提前汇入国家粮食局
            粮食交易协调中心指定账户，按《粮食竞价销售交易规则》第三十四条结算。
          </p>
          <p class="text">
            <span class="sub-title">第十条</span>违约责任：按照《合同法》及《粮食竞价销售交易规则》第四十一、四十二、四十三、四十四条规定 执行。
          </p>
          <p class="text">
            <span class="sub-title">第十一条</span>合同争议的解决方式：本合同在履行过程中发生的争议由当事人协商解决,
            <b>天津市场</b>负责调解;
            当事人经调解达不成一致意见的，买卖双方可自行选择通过法律程序解决。
          </p>
          <p class="text sub-text">
            <span class="sub-title">附则:(1)</span>
            本合同根据
            <b>{{dform.jyrq}}</b>在
            <b>天津市场</b>举行的"国家 政策性粮食竞价销售交易会"交易结果签订本合同。
          </p>
          <p class="text sub2-text">
            <span class="sub-title">(2)</span>
            本合同签订各方确认并承诺遵守《粮食竞价销售交易规则》及当期《交易公告》。
          </p>
          <p class="text sub2-text">
            <span class="sub-title">(3)</span>
            本合同自成交之日起生效。
          </p>
          <p class="text">
            <span class="sub-title">第十二条</span>其它约定事项：
          </p>
          <p class="text">
            <span class="sub-title">第十三条</span>
            本合同一式三份，买卖双方各执一份，对{{
            dform.marketName
            }}留存一份。
          </p>
        </article>
        <div class="subform">
          <el-col :span="12">
            <el-form-item label="卖方(代章)：">
              <el-input clearable disabled v-model="dform.cmmc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="买方名称：">
              <el-input clearable :disabled="isView" v-model="dform.sgmc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="承贷库名称：">
              <el-input clearable v-model="dform.cdkmc" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址：">
              <el-input clearable :disabled="isView" v-model="dform.adress"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际储存库名称：">
              <el-select clearable v-model="dform.cckmc" disabled>
                <el-option
                  v-for="(item, index) in sinkpointList"
                  :key="index"
                  :label="item.kdmc"
                  :value="item.kddm"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法定代表人(签字）：">
              <el-input clearable v-model="dform.fddbr" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话：" prop="mtel">
              <el-input clearable v-model="dform.mtel" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="委托代理人(签字）：">
              <el-input clearable v-model="dform.wtdlr" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开户银行：">
              <el-input clearable v-model="dform.khyh" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话：" prop="sgtel">
              <el-input clearable v-model="dform.sgtel" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账号：">
              <el-input clearable v-model="dform.zh" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开户银行账号：">
              <el-input clearable v-model="dform.khzh" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮政编码：" prop="yzbm">
              <el-input clearable v-model="dform.yzbm" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮政编码：" prop="sgbm">
              <el-input clearable v-model="dform.sgbm" :disabled="isView"></el-input>
            </el-form-item>
          </el-col>
        </div>
        <div class="col-r">
          <el-date-picker
            clearable
            v-model="dform.cjrq"
            disabled
            type="date"
            format="yyyy年MM月dd日"
            class="w200"
          ></el-date-picker>
        </div>-->
      </el-row>
    </el-form>

    <footer>
      <el-button
        type="primary"
        v-if="!isView"
        class="iconfont iconbaocun"
        @click="handleSave"
        >保存</el-button
      >
      <!-- <el-button type="primary" v-if="!isView" class="iconfont icontijiao" @click="handleSubmit">提交</el-button> -->
      <el-button
        type="primary"
        class="iconfont iconfanhui"
        @click="$router.push('index')"
        >返回</el-button
      >
    </footer>
  </div>
</template>
<script>
import {
  selectContract,
  selectContractDetail,
  selectTradeMarkAll,
  updateContract,
  insertContract,
  selectTransactionSignUpAll,
  listSignUpByCcbm,
} from "@/api/transaction/registrationFee/contractInfo/index.js";
import { customInfo } from "@/api/transaction/trading/fieldInfo/index";
import { getconfig } from "@/api/transaction/creditAssess/creditEvaluationRules/index";
import { getNowDate } from "@/utils";
import { NumberToChinese } from "@/utils/num2cn";
import { sinkpointList, findByGroupId } from "@/api/base";
export default {
  data() {
    var checkCall = (rule, val, callback) => {
      if (
        /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(val) ||
        val == "" ||
        val == undefined
      ) {
        callback();
      } else {
        callback(new Error("请按正确电话号码格式填写"));
      }
    };
    var checkPostal = (rule, val, callback) => {
      //   console.log(val);
      if (/^[0-9]{6}$/.test(val) || val == "" || val == undefined) {
        callback();
      } else {
        callback(new Error("请按照正确的邮编格式填写"));
      }
    };
    return {
      dform: { lssl: "", apcc: "", cjfmc: "" },
      isAdd: false,
      isView: false,
      bdList: [],
      id: "",
      sinkpointList: [],
      ccOptions: [],
      qys: [],
      jylx: 0,
      rules: {
        apcc: [{ required: true, message: "请选择", trigger: "change" }],
        bdbm: [{ required: true, message: "请选择", trigger: "change" }],
        cjfmc: [{ required: true, message: "请选择", trigger: "change" }],
        htbh: [{ required: true, message: "请输入", trigger: "blur" }],
        qpdj: [{ required: true, message: "请输入", trigger: "blur" }],
        sjjke: [{ required: true, message: "请输入", trigger: "blur" }],
        cjdj: [{ required: true, message: "请输入", trigger: "blur" }],
        lxfs: [{ pattern:/^(?:(?:\+|00)86)?1\d{10}$/, message: "请输入正确电话号码格式", trigger: "blur" }],
      },
      grades: [],
      postData: {},
      jyfxCheckbox: [],
      lybzjl: "",
      jybzjl: "",
      bdbmCopy: "",
    };
  },
  filters: {
    formatDate(value) {
      let reg = /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})\+0000/;
      let date = value;
      if (reg.test(value)) {
        let d = value.replace(reg, "$1Z");
        let _date = new Date(d);
        date = _date.setHours(_date.getHours() + 8);
      }
      date = new Date(date);
    },
  },
  computed: {
    sum() {
      return this.dform.lssl * this.dform.dj || "0";
    },
    cje() {
      return this.dform.cjdj * this.dform.nzcjl || "0";
    },
    sxf() {
      return this.cje * this.dform.sxfl * 0.01 || "0";
    },
    jybzj() {
      return this.jybzjl * this.dform.nzcjl || "0";
    },
    lybzj() {
      return this.lybzjl * this.dform.nzcjl || "0";
    },
  },
  mounted() {
    let { type, htbh } = this.$route.query;
    this.id = htbh;
    this.isAdd = type == "add";
    this.isView = type == "show";
    // this.init();
    this.selectTradeMarkAll();
  },
  methods: {
    changeApcc(val) {
      let selectList = this.ccOptions.find((d) => d.apcc == val);
      console.log("场次", selectList);

      this.bdList = selectList.warehousingArrangementList;
      // 采购0 委托单位 sgmc 成交单位 cmmc  if(selectList.jyfx == 0){
      // 销售1 委托单位 cmmc 成交单位 sgmc  if(selectList.jyfx == 1){
      this.dform.ccbm = selectList.ccbm;
      this.dform.jyfs = selectList.jyfs;
      this.dform.jyfx = selectList.jyfx;

      this.dform.wtfmc = selectList.wtfmc;
      this.dform.wtfbm = selectList.wtfbm;
      // this.dform.jylx = selectList.jylx;
      this.dform.sxfl = selectList.sxfl;
      this.dform.jyrq = selectList.jyrq;  //新增交易日期
      this.dform.cjrq = selectList.jyrq;  //成交日期等同于交易日期
      this.lybzjl = selectList.lybzj;
      this.jybzjl = selectList.jybzj;

      this.postData.fsdw = selectList.wtfbm;
      if (selectList.jyfs != 2) {
        this.jyfxCheckbox = [selectList.jyfx];
      } else {
        this.jyfxCheckbox = ["0", "1"];
      }
        console.log(this.jyfxCheckbox,"this.jyfxCheckbox");
      // listSignUpByCcbm({apcc: val}).then((res) => {
      //   this.qys = res.data
      // })
      // listSignUpByCcbm({ ccbm: selectList.ccbm }).then((res) => {
      //   this.qys = res.data;
      // });
      customInfo(selectList.ccbm).then(res=>{
        this.qys = res.data.tyJyccKhxxList
        
      })
      // console.log(this.dform, "this.dform");
    },
    async changeBd(val) {
      let selectList = this.bdList.find((d) => d.bdbm == val);

      console.log("标的-------------", selectList);

      this.postData.jylx = selectList.jylx;
      this.postData.lssl = selectList.lssl;

      this.postData.bdh = selectList.bdh;

      this.dform.cckmc = selectList.dwmc;
      this.dform.njhck = selectList.dwbm;
      this.dform.jylx = selectList.jylx;
      this.dform.ncfbm = selectList.cfbm;

      this.dform.nch = selectList.ccdd;

      this.dform.pzmc = selectList.pzmc;
      this.dform.pzbm = selectList.pzbm;
      this.dform.nnf = selectList.scnd;
      this.dform.nzcjl = selectList.lssl;
      this.dform.promptDate = selectList.wcsj;

      let res = await sinkpointList();
      this.sinkpointList = res.data;
      let cckdmList = this.sinkpointList.find((d) => d.tyshxydm == selectList.dwbm.substr(0,18))
      console.log(cckdmList.cgbh,"cckdmList.cgbh");
      this.dform.cckdm = cckdmList.cgbh;
    },
    changeCjdw(val) {
      // console.log(val, this.dform.jylx, "val");
      // let selectList = this.qys.find((d) => d.dwbm == val);
      // let selectList = this.qys.find((d) => d.yyzzbh == val);
      // console.log("单位", selectList);

      // let dwmc = selectList.dwmc,
      //   dwbm = val;
      // let dwmc = selectList.khmc,
      //   dwbm = val;
      let dwmc = val,
        dwbm = '';
        // TODO dwbm获取

      // if(this.dform.jyfx == 0){
      if (this.dform.jylx == 0) {
        this.postData.sgmc = this.dform.wtfmc;
        this.postData.sgdw = this.dform.wtfbm;

        this.postData.cmmc = dwmc;
        this.postData.cmdw = dwbm;
      } else if (this.dform.jylx == 1) {
        this.postData.sgmc = dwmc;
        this.postData.sgdw = dwbm;

        this.postData.cmmc = this.dform.wtfmc;
        this.postData.cmdw = this.dform.wtfbm;
      }
      // this.dform.lxr = selectList.lxr;
      // this.dform.lxfs = selectList.lxdh;
      console.log(111, this.postData);
    },
    async init() {
      let res = await sinkpointList();
      this.sinkpointList = res.data;
      // let comps = await selectTransactionSignUpAll();
      // this.qys = comps.data;
      let resp = await findByGroupId("LSDJ");
      this.grades = resp.data;
    },
    async getDetail() {
      let res = await selectContractDetail(this.id);
      this.dform = res.data.data;
      if (this.$route.query.dataVer == 0) {
        this.dform.nzcjl = res.data.data.lssl;
      }
      this.changeApcc(res.data.data.apcc);
      // 因为当前data中场次的标的组已经去除了当前data中的标的号相关信息，导致bdh无法显示，这里先将bdh赋值给bdbm显示
      this.bdbmCopy = res.data.data.bdbm
      this.dform.bdbm = res.data.data.bdh
      // if(this.dform.jyfx == 0){
      if (this.dform.jylx == 0) {
        // this.$set(this.dform, "wtfmc", "");

        this.dform.wtfmc = this.dform.sgmc;
        this.dform.wtfbm = this.dform.sgdw;

        // this.dform.cjfmc = this.dform.cmdw;

        this.$set(this.dform, "cjfmc", this.dform.cmmc);
      } else if (this.dform.jylx == 1) {
        // this.dform.cjfmc = this.dform.sgdw;
        this.$set(this.dform, "cjfmc", this.dform.sgmc);

        this.dform.wtfmc = this.dform.cmmc;
        this.dform.wtfbm = this.dform.cmdw;
      }
      console.log(this.dform,this.dform.cmdw,this.dform.cmdw,"this.dform-------------");
      // if (this.dform.jyfs != 2) {
      //   this.jyfxCheckbox = [this.dform.jyfx];
      // } else {
      //   this.jyfxCheckbox = ["0", "1"];
      // }
      // if (this.$route.query.type == "update") {
      //   this.dform.cjrq = getNowDate();
      // }

      // this.handleSelect(this.dform.bdbm);
    },
    async insert(msg) {
      this.postData.je = this.dform.cjdj * this.dform.nzcjl || "0";
      this.dform.status = 0;
      console.log(333 + JSON.stringify(this.dform));
      let postData = {
        ...this.dform,
        ...this.postData,
        jyfx: this.dform.jyfs == 2 ? "1,2" : this.dform.jyfx,
      };
      console.log("result", postData);
      let res = await insertContract(postData);
      if (res.infoCode == 200) {
        this.$message.success(msg + "成功!");
        this.$router.push("index");
      } else {
        this.$message.error(res.msg);
      }
    },
    async update(msg) {
      this.dform.je = this.dform.cjdj * this.dform.nzcjl || "0";
      this.dform.status = 1;
      this.dform.bdbm = this.bdbmCopy;
      this.dform.jyfx = this.dform.jyfs == 2 ? "1,2" : this.dform.jyfx;
      let res = await updateContract({ ...this.dform, ...this.postData });
      if (res.infoCode == 200) {
        this.$message.success(msg + "成功!");
        this.$router.push("index");
      } else {
        this.$message.error(res.msg);
      }
    },
    handleSave() {
      this.$refs["dform"].validate((valid) => {
        if (valid) {
          this.dform.status = 0;
          getconfig("1045").then((res) => {
            if (res.infoCode === 200) {
              if (res.data.length) {
                let d = res.data[0];
                let configLastValue = JSON.parse(d.configLastValue);
                this.dform.a = configLastValue.a;
                this.dform.b = parseInt(configLastValue.b);
                this.dform.c = parseInt(configLastValue.c);
                if (this.isAdd) {
                  this.insert("保存");
                } else {
                  this.update("保存");
                }
              }
            }
          });
        }
      });
    },
    // handleSubmit() {
    //   this.$refs["dform"].validate(valid => {
    //     if (valid) {
    //       this.dform.status = 1;
    //       getconfig("1045").then(res => {
    //         if (res.infoCode === 200) {
    //           if (res.data.length) {
    //             let d = res.data[0];
    //             let configLastValue = JSON.parse(d.configLastValue);
    //             this.dform.a = configLastValue.a;
    //             this.dform.b = parseInt(configLastValue.b);
    //             this.dform.c = parseInt(configLastValue.c);
    //             if (this.isAdd) {
    //               this.insert("提交");
    //             } else {
    //               this.update("提交");
    //             }
    //           }
    //         }
    //       });
    //     }
    //   });
    // },
    async handleSelect(val) {
      if (val) {
        let cur = this.bdList.find((d) => d.bdbm == val);
        let res = await selectContract(val);
        if (res.infoCode == 200) {
          let data = res.data.data || {};
          let ee = data.entryAndExitOrderVO || {};
          let wa = data.warehousingArrangementVO || {};
          let tm = data.tradeMarkVO || {};
          // console.log(wa);

          // this.dform = {
          // ...this.dform,
          if (this.$route.query.type == "add") {
            this.dform.bdh = cur && cur.bdh;
          }
          (this.dform.bdbm = val),
            (this.dform.pzmc = ee.pzmc),
            (this.dform.sl = wa.lssl),
            (this.dform.lssl = wa.lssl),
            (this.dform.lsdj = wa.sgdj),
            (this.dform.cjsj = getNowDate()),
            (this.dform.jylx = ee.jylx),
            // (this.dform.cmmc = wa.dwmc),
            (this.dform.cckmc = wa.wtfmc),
            (this.dform.jyrq =
              ee.jyrq &&
              ee.jyrq.replace(/(\d{4})-(\d{2})-(\d{2})/, "$1年$2月$3日"));
          this.qys = data.transactionSignUpVOS;
          this.$set(this.dform, "sgmc", "");
          this.$set(this.dform, "sgdw", "");
          this.$set(this.dform, "cmmc", "");
          this.$set(this.dform, "cmdw", "");
          if (this.dform.jylx == 0) {
            this.dform.sgmc = ee.wtfmc;
            this.dform.sgdw = ee.wtfbm;
            // this.dform.cmmc = "";
            // this.dform.cmdw = "";
          } else {
            this.dform.cmmc = ee.wtfmc;
            this.dform.cmdw = ee.wtfbm;
            // this.dform.sgmc = "";
            // this.dform.sgdw = "";
          }

          // };
        }
      }
    },
    async selectTradeMarkAll() {
      let res = await selectTradeMarkAll();
      if (res.infoCode == 200) {
        if (this.isAdd) {
          this.ccOptions = res.data.data.filter((item,index)=>{
            return item.warehousingArrangementList != null
          });
        }else{
          this.ccOptions = res.data.data
        }
        // this.bdList = res.data.data.warehousingArrangementList || [];
        if (this.id) {
          this.getDetail();
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.content-title {
  font-size: 18px;
  color: #4588db;
  text-align: center;
}
.w90 {
  width: 90% !important;
}
article {
  width: 95%;
  margin: 0 auto;
}
.sub-title {
  margin-right: 0.8em;
}

.text {
  text-indent: 2em;
}
.sub-text {
  text-indent: 5em;
}
.sub2-text {
  text-indent: 7.3em;
}
.subform {
  border: 1px solid #eaeaea;
  width: 100%;
  overflow: hidden;
}
.col-r {
  text-align: right;
}
.w200 {
  width: 200px;
  margin-right: 5%;
}
table {
  width: 90%;
  margin-left: 2em;
}
th,
td {
  line-height: 43px;
  padding: 0 10px;
  text-align: center;
  border: 1px solid #eaeaea;
}
.td-left {
  text-align: left;
}
footer {
  text-align: center;
  margin: 20px auto;
}
#form-zdy /deep/ .el-form-item__content {
  margin: 0 !important;
}
</style>
