import { getOcrCard } from '@/api/dictionary'
export default {
  methods: {
    callBack() {
      const cardFrontList = this.$refs.idCardFront.getFileLists
      const cardReversList = this.$refs.idCardReverse.getFileLists
      const front = cardFrontList.length ? cardFrontList[0].id : ''
      const back = cardReversList.length ? cardReversList[0].id : ''
      if (cardFrontList.length && cardReversList.length) {
        getOcrCard({ front, back }).then(({ data }) => {
          const { validfrom, validto, idcard, sex, name, address } = data
          this.ruleForm.periodValidityDate = [validfrom, validto]
          this.ruleForm.idNumber = idcard
          this.ruleForm.gender = sex === '男' ? 0 : 1
          this.ruleForm.personName = name
          if (!this.ruleForm.name) {
            this.ruleForm.name = name
          }
          this.ruleForm.contactAddress = address
          this.ruleForm.address = address
          this.getIdType()
        })
      }
    },
    // 确定证件种类
    getIdType() {
      if (this.ruleForm.idNumber.length !== 18) {
        this.ruleForm.idType = 'idCard_0101'
      } else {
        this.ruleForm.idType = 'idCard_0102'
      }
    }
  }
}
