<template>
  <div class="content">
    <div style="width: 100%">
      <van-form label-width="25%" @submit="onSubmit">
        <!-- <mobile-input v-model="type_of_certificate" placeholder="营业执照" readonly label="证件类型" /> -->
        <d-select
          placeholder="请选择"
          label="证件类型"
          :value="IdentTp"
          border="true"
          :required="true"
          v-model="IdentTp"
          sfield="IdentTp"
          size="small"
          :rules="[{ required: true, message: '证件类型不能为空' }]"
        ></d-select>
        <mobile-input
          :formatter="formatter"
          format-trigger="reset"
          v-model="IdentNo"
          :required="true"
          :rules="[{ validator, message: msg == '' ? '类型不能为空' : msg }]"
          label="证件号码"
        />
        <mobile-input
          v-show="companyName != ''"
          class="contact_tel"
          placeholder="请输入联系电话"
          label="公司名称"
          readonly
          v-model="companyName"
        />
        <div style="margin: 16px; display: flex; justify-content: space-around">
          <van-button
            @click="reset"
            style="width: 40%"
            round
            color="#999999"
            native-type="info"
            plain
            >重置</van-button
          >
          <van-button style="width: 40%" round type="info" native-type="submit"
            >计算</van-button
          >
        </div>
      </van-form>
      <div class="content-style" v-show="LOAN_BAL != '' && LOAN_BAL != null">
        <table-single-view
          :data="AUMInfo"
          :keyValue="keyValueAum"
        ></table-single-view>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import nettyApi from "@/constants/api/ms-netty/netty.api.ts";
import systemApi from "@/constants/api/ms-system/system.api.ts";
import IF from "@/public/factory/InterFaceFactory";
import { NativeUI } from "@/public/ts/NativeUI";
import TableSingleView from "@/public/TableSingleView.vue";
// import emUtil from '@/public/js/em.util';
/**
 * @Description 年日均计算
 * @Author JiangTao
 * @Date 2021-11-10 下午 03:36
 */
@Component({
  name: "Calculate",
  components: { TableSingleView },
})
export default class Calculate extends Vue {
  IdentTp = "";
  IdentNo = "";
  msg = "输入不能为空";
  cusInfo: any = {};
  AUMInfo: any = {}; //查询AUM返回的信息
  keyValueAum = {
    LOAN_BAL: "贷款总额",
    LOAN_YEAR_DAY_AVG: "贷款年日均",
  };
  LOAN_BAL = "";
  companyName = "";
  onSubmit() {
    this.selectCustInfo();
  }
  formatter() {}
  reset() {
    this.IdentNo = "";
    this.IdentTp = "";
  }
  // 暂无拍照接口
  // ocrScan(bse64Img:any) {
  //     if (!this.IdentTp) {
  //       NativeUI.toast('请先选择证件类型');
  //     } else {
  //       emUtil.captureImage().then(localData => {
  //         let _this = this;
  //         let fileImage = _this.base64ToFile(localData);
  //         NativeUI.showWaiting('正在识别...');
  //         IF.transferFile(systemApi.ocrCertificateIdentify, { file: fileImage }).then(res => {
  //           NativeUI.closeWaiting();
  //           console.log(res);
  //           if (res.ret_code == '000000') {
  //             NativeUI.toast(res.msg);
  //             _this.IdentNo = res.REGISTER_ID;
  //             // _this.CstNm = res.COMPANY_NAME;
  //             // _this.displayValue = res.COMPANY_TYPE;
  //           } else {
  //             NativeUI.toast(res.msg || 'OCR识别失败');
  //           }
  //         });
  //       });
  //     }
  //   }
  //证件号校验规则
  validator(val: any) {
    if (this.IdentTp == "1") {
      this.msg = "组织机构代码输入有误";
      return /[A-Z0-9]{8}-[A-Z0-9]$|[A-Z0-9]{8}-[A-Z0-9]-[0-9]{2}$/.test(val);
    } else if (this.IdentTp == "2") {
      //社会统一信用代码
      this.msg = "社会统一信用代码输入有误";
      return /[1-9A-GY]{1}[1239]{1}[1-5]{1}[0-9]{5}[0-9A-Z]{10}/.test(val);
    }
  }
  //查询年日均AUM
  selectAUMInfo() {
    const param = {
      CUST_NO: this.cusInfo.cus_id, //'1003813734'
      CUST_NAME: this.cusInfo.cus_name, //'成***',
      tc: nettyApi.TRADE_CODE.selectCompanyAumInfo,
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        if (res.LOAN_BAL != null) {
          this.AUMInfo = res;
          this.LOAN_BAL = res.LOAN_BAL;
        } else {
          NativeUI.toast("此用户无AUM数据");
        }
      } else {
        NativeUI.toast(res.msg);
      }
    });
  }
  //查询客户列表
  selectCustInfo(pageNo = 1) {
    const param = {
      cus_status: "",
      cert_code: this.IdentNo,
      cus_type: "",
      maxLine: "1",
      targetPage: 1,
      tc: nettyApi.TRADE_CODE.selectXDGSXX,
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        if (res.CusComList.length > 0) {
          this.cusInfo = res.CusComList[0];
          this.companyName = res.CusComList[0].cus_name;
          this.selectAUMInfo();
        } else {
          NativeUI.toast("信贷系统无此用户");
        }
      } else {
        NativeUI.toast(res.msg);
      }
    });
  }
}
</script>

<style scoped lang="scss">
.content {
  width: 50%;
  padding-top: 5%;
  margin: 0 auto;
}
::v-deep .van-button--info {
  background-color: #fd5065;
  border: 1px solid #fd5065;
}
::v-deep .van-button__text {
  font-size: 16px;
}
.content-style {
  margin-left: 100px;
  margin-top: 100px;
}
</style>