<template>

  <div class="eibs-tab">
    <c-col :span="12" class="col-left">
      <c-col :span="24">
        <c-fullbox>
          <el-form-item label="外汇客户类别" prop="crmtyp">
            <c-select dbCode="CRMTYP" v-model="model.crmtyp" :isShowKeyAndLabel="true" filterable clearable :disabled=true> </c-select>
          </el-form-item>   
          <template slot="footer">
            <c-button
              style="margin: 0 0 0 10px; padding: 0 12px"
              size="small"
              type="primary"
              :disabled="!model.extkey || type == 'info'"
              @click="getInfoFromCRM(model.extkey)">
                获取
            </c-button>
          </template>
        </c-fullbox>
      </c-col>

      <c-col :span="24">
        <el-form-item label="状态">
          <c-select dbCode="CRMSTA" v-model="ptycrm.crmSta" :isShowKeyAndLabel="true" filterable clearable  :disabled=true> </c-select>
        </el-form-item>
      </c-col>
    </c-col>
    <c-col :span="12" class="col-right">
      <c-col :span="24">
        <el-form-item label="可信客户分类">
          <c-select dbCode="CREDIT" v-model="ptycrm.creditSort" :isShowKeyAndLabel="true" filterable clearable :disabled=true> </c-select>
        </el-form-item>   
      </c-col>
      <c-col :span="24">
        <el-form-item label="认定日期">
          <c-date-picker v-model="model.khbsdt" value-format="yyyy-MM-dd" :disabled=true> </c-date-picker>
        </el-form-item>
      </c-col>
    </c-col>
    <c-col :span="24" v-if="ptycrm.creditSort == '3'">
      <c-col :span="12" class="col-left">
        <c-col :span="24">
          <el-form-item label="退汇单笔最大金额(美元)">
          	<c-input-currency v-model="ptycrm.refremitMaxBal" disabled :currency="'USD'"></c-input-currency>
            <!-- <c-input v-model="ptycrm.refremitMaxBal" :disabled=true> </c-input> -->
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="服务贸易单笔最大金额(美元)">
            <c-input-currency v-model="ptycrm.sertradeMaxBal" disabled :currency="'USD'"></c-input-currency>
            <!-- <c-input v-model="ptycrm.sertradeMaxBal" :disabled=true> </c-input> -->
          </el-form-item>
        </c-col>
      </c-col>
      <c-col :span="12" class="col-right">
        <c-col :span="24">
          <el-form-item label="货物贸易单笔最大金额(美元)">
            <c-input-currency v-model="ptycrm.gootradeMaxBal" disabled :currency="'USD'"></c-input-currency>
            <!-- <c-input v-model="ptycrm.gootradeMaxBal"  :disabled=true> </c-input> -->
          </el-form-item>
        </c-col>

      </c-col>
    </c-col>
    <c-col :span="24">
      <el-form-item label="适用类型" style="width: 100%">
        <el-checkbox-group  v-model="checkedList"  :disabled=true>
          <el-checkbox :key="sta.value" :label="sta.value" class="el-checkbox-width" v-for="sta in businessList">{{sta.label}}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
     </c-col>
  </div>
</template>

<script>
import codes from "~/config/CodeTable";
import Api from "~/service/Api";
// import Ptycrm from './PtycrmModel.js';

export default {
  name: "",
  props: ["model", "ptycrm","type"],
  data() {
    return {
      businessList: [
        { label: "货物贸易", value: "01" },
        { label: "服务贸易", value: "02" },
        { label: "收益与经常转移", value: "03" },
        { label: "境外直接投资", value: "04" },
        { label: "境内直接投资", value: "05" },
        { label: "跨境担保", value: "06" },
        { label: "企业境外放款", value: "07" },
        { label: "外债", value: "08" },
        { label: "境外贷款", value: "09" },
        { label: "国际贸易融资", value: "10" }
      ],
      first:true,
      checkedList:[]
    };
  },
  mounted() {},
  created() {},
  computed: {},
  methods: {
    init(){
      if (this.first){
        this.getInfoFromDB(this.model.inr);
        this.first = false;
      }
    },
    getInfoFromDB(ptyinr){
      let data={
        "ptyinr": ptyinr
        };
      Api.post('/manager/ptycrm/getInfoFromDB',data).then(res => {
        if (res.respCode == SUCCESS) {
          this.ptycrm.ptyinr=ptyinr;
          this.ptycrm.creditSort=res.data.creditSort;
          this.ptycrm.crmSta = res.data.crmSta;
          this.ptycrm.business = res.data.business;
          this.ptycrm.refremitMaxBal = res.data.refremitMaxBal;
          this.ptycrm.gootradeMaxBal = res.data.gootradeMaxBal;
          this.ptycrm.sertradeMaxBal = res.data.sertradeMaxBal;
          if(res.data.business){
            this.checkedList = res.data.business.split(",")
          } else {
            this.checkedList = [];
          }
          console.log("res.data:",JSON.stringify(res.data));
          console.log("res.data:",JSON.stringify(this.ptycrm))
        } else {
          this.$notify.error({
            	title: '错误:',
              message: res.data.msg,
              dangerouslyUseHTMLString: true 
            });
        }
      }).catch((err) => {
        this.$notify.error("查询OCRM客户信息失败")
      });
    },

    getInfoFromCRM(extkey){
       let data={
        "extkey": extkey
        };
      Api.post('/manager/ptycrm/getInfoFromCRM',data).then(res => {
        if (res.respCode == SUCCESS) {
          this.ptycrm.ptyinr = this.model.inr;
          this.model.crmtyp = res.data.crmtyp;
          if (res.data.khbsdt) {
            this.model.khbsdt = res.data.khbsdt.substr(0,4)+"-"+res.data.khbsdt.substr(4,2)+"-"+res.data.khbsdt.substr(6,2)
          } else {
            this.model.khbsdt = "";
          }
          this.ptycrm.creditSort=res.data.ptycrm.creditSort;
          this.ptycrm.crmSta = res.data.ptycrm.crmSta;
          this.ptycrm.business = res.data.ptycrm.business;
          this.ptycrm.refremitMaxBal = res.data.ptycrm.refremitMaxBal;
          this.ptycrm.gootradeMaxBal = res.data.ptycrm.gootradeMaxBal;
          this.ptycrm.sertradeMaxBal = res.data.ptycrm.sertradeMaxBal;
          if(res.data.ptycrm.business){
            this.checkedList = res.data.ptycrm.business.split(",")
          } else {
            this.checkedList = [];
          }
        } else {
          this.$notify.error({
            	title: '错误:',
              message: res.data.msg,
              dangerouslyUseHTMLString: true 
            });
        }
      }).catch((err) => {
        this.$notify.error("查询OCRM客户信息失败")
      });
    }
  }
};
</script>

<style lang="less" scoped>
  .el-checkbox-width {
    margin-right: 0px;
    float: left;
    text-align: left !important;
    width: 150px;
  }
</style>