<template>
  <div class="eibs-tab">
    <c-col :span="12" style="padding-right: 20px">
      <c-col :span="24">
        <el-form-item label="企业客户号" prop="entmod.extkey">
          <c-input disabled placeholder="请输入" maxlength="16" v-model="model.entmod.extkey"></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="企业代码" prop="entmod.corpid">
          <c-input disabled placeholder="请输入" maxlength="18" v-model="model.entmod.corpid"></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="进口可付汇余额(美元)" prop="entmod.entinf.paybal">
          <c-input-currency disabled placeholder="请输入" v-model="model.entmod.entinf.paybal" :precision="2"></c-input-currency>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="分类起始日期" prop="entmod.entinf.rakbegdat">
          <c-date-picker disabled type="date" v-model="model.entmod.entinf.rakbegdat" style="width:100%" placeholder="请输入">
          </c-date-picker>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="特殊监管区域类型" prop="entmod.entinf.taxfrecod">
          <c-select disabled placeholder="请输入" :code="taxfreCode" v-model="model.entmod.entinf.taxfrecod"></c-select>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="企业所属外汇局代码" prop="entmod.entinf.safecode">
          <c-input disabled placeholder="请输入" maxlength="6" v-model="model.entmod.entinf.safecode"></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="企业所属外汇局名称" prop="entmod.entinf.safename">
          <c-input disabled placeholder="请输入" maxlength="60" v-model="model.entmod.entinf.safename"></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="跨境人民币出口重点监管企业状态" prop="entmod.entinf.ismoncorp" class="custom-form-item-red">
          <c-select disabled placeholder="请输入" v-model="model.entmod.entinf.ismoncorp" dbCode="CGYN"></c-select>
        </el-form-item>
      </c-col>
    </c-col>
    <c-col :span="12" style="padding-left: 20px">
      <c-col :span="24">
        <el-form-item label="企业名称" prop="entmod.corpname">
          <c-input disabled placeholder="请输入" maxlength="60" v-model="model.entmod.entinf.corpname"></c-input>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="分类结果" prop="entmod.entinf.entrank" class="custom-form-item-red">
          <c-select disabled placeholder="请输入" v-model="model.entmod.entinf.entrank" :code="entrankCode"></c-select>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="出口可收汇余额(美元)" prop="entmod.entinf.rcvbal">
          <c-input-currency disabled placeholder="请输入" v-model="model.entmod.entinf.rcvbal" :precision="2"></c-input-currency>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="分类截止日期" prop="entmod.entinf.rakenddat">
          <c-date-picker disabled type="date" v-model="model.entmod.entinf.rakenddat" style="width:100%" placeholder="请输入">
          </c-date-picker>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="是否特殊监管区域内企业" prop="entmod.entinf.istaxfre">
          <c-select disabled placeholder="请输入" dbCode="ISYN" v-model="model.entmod.entinf.istaxfre"></c-select>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="辅导期企业" prop="entmod.entinf.newcorp" class="custom-form-item-red">
          <c-select disabled placeholder="请输入" dbCode="CGYN" v-model="model.entmod.entinf.newcorp"></c-select>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="名录状态" prop="entmod.entinf.paylist" class="custom-form-item-red">
          <c-select disabled placeholder="请输入" dbCode="CGYN" v-model="model.entmod.entinf.paylist"></c-select>
        </el-form-item>
      </c-col>
      <c-col :span="24">
        <el-form-item label="提示信息" prop="entmod.entinf.chkmsg" class="custom-form-item-red">
          <c-input disabled type="textarea" :row="5" placeholder="请输入" v-model="model.entmod.entinf.chkmsg"></c-input>
        </el-form-item>
      </c-col>
			<c-col :span="24">
				<el-form-item prop="entmod.rtyflg" :rules="[{required:model.entmod.entinf.ismoncorp == '',message:'请点击校验企业名录信息'}]">
					<c-button size="mini" type="primary" @click="getData">手动获取
					</c-button>
				</el-form-item>
					
			</c-col>
    </c-col>
  {{isEntmodDate}}
  </div>
</template>
<script>
import Api from "~/service/Api";
import event from '../event';
import { cloneDeep } from 'lodash';
import commonDepend from "~/mixin/commonDepend.js";
import moment from 'moment';

export default {
  inject: ["root"],
  mixins: [commonDepend, event],
  props: ["model", "codes"],
  data() {
    return {
      visible: false,
      entrankCode:[
        {label: "A类企业", value: "A"},
        {label: "B类企业", value: "B"},
        {label: "C类企业", value: "C"},
      ],
      taxfreCode:[
        {label: "一般贸易区", value: "00"},
        {label: "保税区", value: "01"},
        {label: "出口加工区", value: "02"},
        {label: "保税物流中心B型", value: "03"},
        {label: "保税物流园区", value: "04"},
        {label: "钻石交易所", value: "05"},
        {label: "保税港区", value: "06"},
        {label: "综合保税区", value: "07"},
        {label: "跨境工业园区", value: "08"},
        {label: "保税物流中心A型", value: "09"},
        {label: "出口监管仓库", value: "10"},
        {label: "进口保税仓库", value: "11"},
        {label: "自由贸易试验区(特殊监管区)", value: "12"},
        {label: "自由贸易试验区(非特殊监管区)", value: "60"},
        {label: "其他", value: "99"},
      ],
    };
	},
  methods: {
    handleClose () {
      this.visible = false
    },
  },
  watch:{
     customerPath:{
       handler(newVal,oldVal){
         if (oldVal && newVal != oldVal) {
            if (this.model.entmod) {
                console.log("企业名录客户变化", newVal, oldVal);
                this.model.entmod.rtynum = 0;
                this.model.entmod.rtyflg = "";
                this.model.entmod.chkflg = "";
            }
         }
      },
      immediate: true,
     },
     curAmtPath:{
       handler(newVal,oldVal){
         if (oldVal && newVal != oldVal) {
            if (this.model.entmod 
                && this.model.entmod.entinf.entrank === 'B'
                && this.model.entmod.rtynum < 3) {
              console.log("企业名录金额币种变化", newVal, oldVal);
              this.model.entmod.chkflg = "";
            }
         }
      },
      immediate: true,
     },
  },
  computed: {
    isEntmodDate(){
      if (this.model.entmod) {
          if (this.model.entmod.entdat && moment(this.model.entmod.entdat).diff(moment(), 'day') != 0) {
            console.log("企业名录查询日期不是今天,需要重新查询");
            this.model.entmod.rtynum = 0;
            this.model.entmod.rtyflg = "";
            this.model.entmod.chkflg = "";  
          }
      }
    },
    curAmtPath(){
      if (this.model.entmod){
        let trnName = this.trnName;
        if (this.root) {
          trnName = this.root.trnName;
        }
        if ("-CPTOPN-CPTREP-CPTADV-CPTATO-CPTATI-".includes(trnName.toUpperCase())) {
          return this.model.cpdgrp.cbs.max.cur + '-' + this.model.cpdgrp.cbs.max.amt;
        }
        if ("BOTSET".includes(trnName.toUpperCase())) {
          return this.model.setmod.doccur + '-' + this.model.setmod.docamt;
        }
        if ("BCTSET1".includes(trnName.toUpperCase())) {
          return this.model.setmod.doccur + '-' + this.model.setmod.docamt;
        }
        if ("BOTDAV1".includes(trnName.toUpperCase())) {
          return this.model.bodgrp.cbs.max.cur + '-' +this.model.bodgrp.cbs.max.amt;
        }
        if ("BCTDAV1".includes(trnName.toUpperCase())) {
          return this.model.bcdgrp.cbs.max.cur + '-' +this.model.bcdgrp.cbs.max.amt;
        }
        if ("LITOPN1".includes(trnName.toUpperCase())) {
          return this.model.lidgrp.cbs.max.cur + '-' + this.model.lidgrp.cbs.max.amt;
        }
        if ("LITAME1".includes(trnName.toUpperCase())) {
          return this.model.litamep.maxcur + '-' + this.model.litamep.maxamt;
        }
        if ("BETSET".includes(trnName.toUpperCase())) {
          return this.model.setmod.doccur + '-' + this.model.setmod.docamt;
        }
        if ("TRTOPN".includes(trnName.toUpperCase())) {
          return this.model.trdgrp.cbs.max.cur + '-' + this.model.trdgrp.cbs.max.amt;
        }
        if ("BPTOPN".includes(trnName.toUpperCase())) {
          return this.model.bpdgrp.cbs.max.cur + '-' + this.model.bpdgrp.cbs.max.amt;
        }
        if ("BRTUDP1-BRTSET1".includes(trnName.toUpperCase())) {
          return this.model.setmod.doccur + '-' + this.model.setmod.docamt;
        }
        if ("LETOPN".includes(trnName.toUpperCase())) {
          return this.model.ledgrp.cbs.max.cur + '-' + this.model.ledgrp.cbs.max.amt;
        }
        if ("BTTSET".includes(trnName.toUpperCase())) {
          return this.model.setmod.doccur + '-' + this.model.be1amt;
        }if ("JSTOPN-JSTOPT".includes(trnName.toUpperCase())) {
          return this.model.jsdgrp.cbs.max.cur + '-' + this.model.jsdgrp.cbs.max.amt;
        }
      }
    },
    customerPath(){
      if (this.model.entmod){
        let trnName = this.trnName;
          if (this.root) {
            trnName = this.root.trnName;
          }
          if ("-CPTOPN-CPTREP-CPTADV-CPTATO-CPTATI-".includes(trnName.toUpperCase())) {
            if ("-CPTOPN-CPTATO-".includes(trnName.toUpperCase())) {
              return this.model.cpdgrp.orc.pts.ptyinr;
            } else {
              return this.model.cpdgrp.pye.pts.ptyinr;
            }
          }
          if ("LITOPN1".includes(trnName.toUpperCase())) {
            if (this.model.lidgrp.rec.dkflg === 'X') {
              return this.model.lidgrp.apo.pts.ptyinr;
            } else {
              return this.model.lidgrp.apl.pts.ptyinr;
            }
          }
          if ("TRTOPN".includes(trnName.toUpperCase())) {
            return this.model.trdgrp.fip.pts.ptyinr;
          }
          if ("BPTOPN".includes(trnName.toUpperCase())) {
            return this.model.bpdgrp.fia.pts.ptyinr;
          }
          if ("LETOPN".includes(trnName.toUpperCase())) {
            return this.model.ledgrp.ben.pts.ptyinr;
          }
          if ("LTTOPN1".includes(trnName.toUpperCase())) {
            return this.model.ltdgrp.be1.pts.ptyinr;
          }
          if ("JSTOPN-JSTOPT".includes(trnName.toUpperCase())) {
            return this.model.jsdgrp.apl.pts.ptyinr;
          }
          if ("BOTDAV1".includes(trnName.toUpperCase())) {
            return this.model.bodgrp.drr.pts.ptyinr;
          }
          if ("BCTDAV1".includes(trnName.toUpperCase())) {
            return this.model.bcdgrp.dre.pts.ptyinr;
          }
        }
    },
  }
};
</script>
<style lang="less" scoped>

</style>