<template>
  <div class="insured-person-container redRadioCheckbox">
    <IdentityCardScan :scanShow="isScan" @getScanInfo="getIdentityInfo" :options="{ showIDInfo: false }" />

    <van-field
      :value="userInfo.relationToAppnt | idToText('relationToAppnt')"
      readonly
      required
      label="是投保人的"
      name="是投保人的"
      right-icon="arrow"
      placeholder="请选择"
      v-validate="'required'"
      @click="toSelect('7')"
    />
    <div class="pl10 pt10 pb10 pr10 address fs14">
      <van-checkbox v-model="withRootUser.value">同投保人</van-checkbox>
    </div>
    <customer-picker
      @on-choose="chooseCustomer"
      v-validate="'required|salename'"
      name="姓名"
      label="姓名"
      required
      v-model="userInfo.name"
      :parentShowPicker.sync="customerShowPicker"
      @nameChange="nameChange"
      @on-click="selectClick('1')"
      :readonly="isReadonly"
    />
    <van-field
      :value="userInfo.idType | idToText('idType')"
      v-validate="'required'"
      readonly
      required
      label="证件类型"
      name="证件类型"
      right-icon="arrow"
      placeholder="请选择"
      @click="toSelect('2')"
    />
    <!-- <van-field v-model="userInfo.idNo" v-validate="'required|idNo'" maxlength="18" label="证件号码" name="证件号码" placeholder="请输入" clearable> -->
    <van-field
      v-model="userInfo.idNo"
      maxlength="18"
      label="证件号码"
      name="证件号码"
      required
      placeholder="手工录入或点击右侧证件扫描"
      clearable
      :readonly="isReadonly"
      v-validate="'required'"
      @blur="getRelatedData(userInfo.idNo)"
    />
    <FieldDatePicker
      v-validate="'required'"
      label="证件起始日期"
      name="证件起始日期"
      required
      :defaultDate="new Date()"
      :value.sync="userInfo.certificateValidate"
      type="date"
      :flag="true"
      @confirm="onDateConfirm($event, '0')"
      ref="certificateValidate"
      :readonly="isReadonly"
    ></FieldDatePicker>
    <FieldDatePicker
      v-validate="{ required: certiexpiredateRequired }"
      label="证件截止日期"
      name="证件截止日期"
      :required="isRequired"
      :defaultDate="new Date()"
      :value.sync="userInfo.certiexpiredate"
      type="date"
      @confirm="onDateConfirm($event, '1')"
      ref="certiexpiredate"
      :flag="certiexpiredateShow"
      :readonly="isReadonly || idLimit"
    ></FieldDatePicker>
    <div class="border-bt relative fs14 p10 flex align-center">
      <van-checkbox v-model="userInfo.effectiveDateType" class="fr" :disabled="effectiveDateTypeAble"
                    @change="effectiveDataTypeChange">长期
      </van-checkbox>
    </div>
    <select-radio :radios="sexRadio" label="性别" name="性别" required v-validate="'required'"
                  :value.sync="userInfo.sex" :disabled="isReadonly"></select-radio>
    <FieldDatePicker
      v-validate="'required'"
      label="出生日期"
      name="出生日期"
      :value.sync="userInfo.birthday"
      type="date"
      required
      :flag="true"
      @confirm="onDateConfirm($event, '2')"
      ref="birthday"
      :readonly="isReadonly"
      :maxDate="currentTime"
    />
    <van-field
      :value="userInfo.marriageStatus"
      readonly
      required
      label="婚姻状况"
      name="婚姻状况"
      v-validate="'required'"
      right-icon="arrow"
      placeholder="请选择"
      @click="setMarriageStatus('10')"
    />
    <van-field
      :value="userInfo.nativeplace | idToText('nativeplace')"
      readonly
      label="国籍"
      name="国籍"
      required
      v-validate="'required'"
      right-icon="arrow"
      placeholder="请选择"
      @click="toSelect('1')"
    />
    <!-- <van-field
        :value="census"
        required
        readonly
        label="户籍"
        name="户籍"
        v-validate="'required'"
        right-icon="arrow"
        placeholder="请选择"
        @click="areaChoose('1')"
      /> -->

    <van-field
      v-model="userInfo.mobile"
      clearable
      label="移动电话"
      name="移动电话"
      required
      placeholder="请输入"
      v-validate="'required|mobileLength11|mobileStartWith1|mobile'"
      maxlength="11"
      :readonly="isReadonly"
    />
    <!-- <van-field
        v-if="!isReadonly"
        v-model="userInfo.authCode"
        center
        clearable
        label=""
        name="短信验证码"
        placeholder="请输入短信验证码"
        v-validate="'required'"
        maxlength="6"
      >
        <van-button slot="button" size="small" type="danger" :disabled="codeDisabled" @click="getCode" v-no-more-click="1000">{{
          codeDisabled ? `${countDown}s后重新获取` : '发送验证码'
        }}</van-button>
      </van-field> -->
    <!-- <van-field
        v-model="userInfo.email"
        required
        label="电子邮箱"
        name="电子邮箱"
        placeholder="请输入"
        v-validate="'required|email'"
        clearable
        :readonly="isAppnt"
      /> -->
    <van-field
      v-if="Number(branchType) !== 14"
      v-model="userInfo.stature"
      label="身高(cm)"
      name="身高"
      required
      placeholder="请输入，单位cm"
      v-validate="Number(branchType) !== 14 ? '' : 'required|' + 'onlyNumber|stature'"
      clearable
      maxlength="5"
      :readonly="isAppnt"
      @blur="checkStature(userInfo.stature)"
    />
    <van-field
      v-if="Number(branchType) !== 14"
      v-model="userInfo.avoirdupois"
      label="体重(kg)"
      name="体重"
      required
      placeholder="请输入，单位kg"
      v-validate="Number(branchType) !== 14 ? '' : 'required|' + 'required|onlyNumber'"
      clearable
      :readonly="isAppnt"
      @blur="checkAvoirdupois(userInfo.avoirdupois)"
    />
    <div
      class="p15 pl8 fs14"
      style="border-bottom: 1px solid #eee;display: flex;justify-content: space-between;align-items: center;"
      v-if="manageComCode == '45'"
    >
      <van-radio-group v-model="userInfo.isNewPeopleFlag" :disabled="isReadonly" class="flex">
        <label>
          <i class="red">*</i>
          新市民身份
          <van-icon class="red" name="question-o" size="20" @click="isNewPeopleFlagTip" />
        </label>
        <van-radio name="1" class="ml30">是</van-radio>
        <van-radio name="0" class="ml20">否</van-radio>
      </van-radio-group>

    </div>
    <van-field
      v-if="userInfo.isNewPeopleFlag == 1"
      :value="userInfo.npType | idToText('npType')"
      readonly
      label="新市民类型"
      name="新市民类型"
      required
      right-icon="arrow"
      placeholder="请选择"
      v-validate="'required'"
      @click="toSelect('11')"
    />
    <!-- 工作信息 -->
    <!-- <van-field
        :value="userInfo.degree | idToText('degree')"
        readonly
        label="文化程度"
        name="文化程度"
        required
        right-icon="arrow"
        placeholder="请选择"
        v-validate="'required'"
        @click="toSelect('3')"
      /> -->
    <select-radio
      :radios="medicalRadio"
      label="有无社保"
      name="有无社保"
      v-validate="'required'"
      required
      :value.sync="userInfo.medical"
      :disabled="isAppnt"
    ></select-radio>
    <!-- <van-field
        :value="userInfo.taxResidentId | idToText('taxIdentity')"
        readonly
        label="税收居民身份"
        name="税收居民身份"
        required
        right-icon="arrow"
        placeholder="请选择"
        v-validate="'required'"
        @click="toSelect('5')"
      /> -->

    <occupation-picker
      :value.sync="userInfo.occupationCode"
      :chooseName.sync="userInfo.occupationName"
      :lifeGrade.sync="userInfo.lifeGrade"
      :healthGrade.sync="userInfo.healthGrade"
      clearable
      label="职业类别"
      name="职业类别"
      required
      :readonly="isReadonly"
      v-validate="'required'"
      placeholder="请选择"
      :parentShowPicker.sync="occupationShowPicker"
      @on-click="selectClick('2')"
      @on-choose="chooseOccupation"
    />
    <van-field
      :value="userInfo.salarySource | idToText('salarySource')"
      readonly
      label="收入来源"
      name="收入来源"
      required
      right-icon="arrow"
      placeholder="请选择"
      v-validate="'required'"
      @click="toSelect('9')"
      v-if="branchType != '14'"
    />
    <van-field
      v-show="isShowOthenSalarySource"
      v-model="userInfo.otherSalarySource"
      label
      name="其他来源"
      required
      placeholder="请输入其它收入来源"
      clearable
      maxlength="30"
    />
    <van-field
      v-model="userInfo.averageAnnualIncome"
      label="平均年收入（万元）"
      name="平均年收入"
      placeholder="请输入，单位万元"
      required
      v-validate="'required|onlyNumber'"
      clearable
      maxlength="5"
      :readonly="isAppnt"
    />
    <van-field
      v-model="userInfo.liabilitiesMoney"
      name="负债金额"
      placeholder="请输入，单位万元"
      required
      v-validate="'required|onlyNumber'"
      clearable
      maxlength="5"
      :readonly="isAppnt"
      v-if="branchType != '14'"
    >
      <div slot="label" class="flex flex-wrap"><span>负债金额</span><span>（万元）</span></div>
    </van-field>
    <!-- <van-field
        :value="userInfo.jobStatus | idToText('workCondition')"
        readonly
        label="在职情况"
        name="在职情况"
        required
        placeholder="请选择"
        v-validate="'required'"
        right-icon="arrow"
        @click="toSelect('8')"
      /> -->
    <!-- <van-field
        v-model="userInfo.workcompany"
        label="工作单位"
        name="工作单位"
        placeholder="无工作单位，请输入无"
        maxlength="50"
        required
        v-validate="'required'"
        clearable
        :readonly="isAppnt"
      /> -->
    <select-radio
      v-if="Number(userInfo.relationToAppnt) !== 1 && Number(branchType) !== 14"
      required
      :radios="Asyncs"
      label="是否协同工作单位"
      name="是否协同工作单位"
      v-validate="'required'"
      :value.sync="userInfo.isAsync"
    ></select-radio>
    <SearchField
      v-model="userInfo.workcompany"
      @workcompanys="workcompanys"
      :isAsync="Number(userInfo.isAsync) === 1"
      label="工作单位"
      placeholder="无工作单位，请输入无"
      v-validate="'required'"
      name="工作单位"
      v-if="Number(branchType) !== 14 && Number(userInfo.relationToAppnt) !== 1"
    />
    <!-- <van-field
        v-model="areaName"
        readonly
        label="单位地址"
        name="单位地址"
        required
        right-icon="arrow"
        placeholder="请选择"
        v-validate="'required'"
        @click="areaChoose('3')"
      /> -->
    <!-- <van-field
        v-model="userInfo.companyAddress"
        label=""
        name="详细地址"
        placeholder="请输入详细地址"
        v-validate="'required'"
        clearable
        maxlength="30"
        :readonly="isAppnt"
      /> -->
    <!-- <van-field
        v-model="userInfo.companyZip"
        label="邮编"
        name="邮编"
        placeholder="请输入"
        required
        v-validate="'required|zipCode'"
        maxlength="6"
        clearable
        :readonly="isAppnt"
      /> -->
    <!-- <van-field v-model="userInfo.companyPhone" label="单位电话" name="单位电话" placeholder="非必填" maxlength="13" clearable :readonly="isAppnt" /> -->
    <!-- 家庭信息 -->
    <!-- <van-field
        :value="userInfo.marriage | idToText('marriage')"
        readonly
        required
        label="婚姻状况"
        name="婚姻状况"
        right-icon="arrow"
        placeholder="请选择"
        v-validate="'required'"
        @click="toSelect('6')"
      /> -->
    <!-- <van-field
        v-model="userInfo.familyAnnualIncome"
        label="家庭年收入（万元）"
        name="家庭年收入"
        required
        placeholder="请输入，单位万元"
        v-validate="'required|onlyNumber'"
        clearable
        maxlength="5"
        :readonly="isAppnt"
      /> -->
    <van-field
      v-model="homeName"
      readonly
      label="联系地址"
      name="联系地址"
      required
      right-icon="arrow"
      placeholder="请选择"
      v-validate="'required|contactAdderss'"
      @click="areaChoose('2')"
    />
    <van-field
      v-model="userInfo.homeAddress"
      label=""
      name="详细地址"
      placeholder="具体到街道、门牌号、楼号、单元号、室号"
      v-validate="'required|homeAddressNum|homeAddressCh'"
      clearable
      maxlength="30"
      :readonly="isAppnt"
      style="font-size: 3.5vw"
    />
    <!-- <van-field
        v-model="userInfo.homeZip"
        label="邮编"
        name="邮编"
        required
        placeholder="请输入"
        v-validate="'required|zipCode'"
        maxlength="6"
        clearable
        :readonly="isAppnt"
      /> -->
    <!-- <van-field v-model="userInfo.homePhone" label="家庭电话" name="家庭电话" placeholder="非必填" maxlength="13" clearable :readonly="isAppnt" /> -->

    <!--    <van-button type="danger" class="bottom-btn" @click="nextStep" v-if="!isScan" v-no-more-click="1000">下一步</van-button>-->

    <!-- 字段选择 -->
    <van-popup v-model="popupShow" position="bottom">
      <van-picker show-toolbar :columns="columns" @confirm="onConfirm" @cancel="popupShow = false" />
    </van-popup>
    <!-- 地区选择 -->
    <van-popup v-model="areaShow" position="bottom">
      <van-area :area-list="areaList" value="110101" @confirm="sureArea($event, '1')" @cancel="areaShow = false" />
    </van-popup>
    <!-- 联系地址选择 -->
    <van-popup v-model="homeShow" position="bottom">
      <van-area :area-list="areaLists" :value="areaValue" @confirm="sureArea($event, '2')" @cancel="homeShow = false" />
    </van-popup>
    <!-- 户籍选择 -->
    <van-popup v-model="censusShow" position="bottom">
      <van-area :area-list="areaList" value="110101" :columns-num="2" @confirm="sureArea($event, '3')"
                @cancel="censusShow = false" />
    </van-popup>
    <van-popup v-model="isMarriageStatusShow" position="bottom">
      <van-picker show-toolbar :columns="columns" @confirm="onMarriageConfirm" @cancel="isMarriageStatusShow = false" />
    </van-popup>
    <van-dialog v-model="isNewPeopleFlagTipshow" :showConfirmButton="false">
      <div slot="title">
        <p style="color: #E9332E;">新市民身份说明</p>
      </div>
      <div style="padding: 20px 30px 30px;font-size: 14px;">
        <div style="line-height: 25px;">
          新市民是指因本人创业就业、子女上学、投靠子女等原因来到城镇常住，未获得当地户籍或获得当地户籍不满三年的各类群体，包括但不限于进城务工人员、新就业大中专毕业生等。
        </div>
      </div>
      <div style="text-align: center;margin-bottom: 30px;">
        <van-button round type="danger" size="small" style="padding:0px 35px;font-size: 14px;"
                    @click="isNewPeopleFlagTipshow = false">我知道了
        </van-button>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { Area, CellGroup, Checkbox, Dialog, Field, Picker, Popup, Radio, RadioGroup } from 'vant'
import SelectRadio from '@/components/ebiz/SelectRadio'
import FieldDatePicter from '@/components/ebiz/FieldDatePicter'
import OccupationPicker from './components/OccupationPicker.vue'
import CustomerPicker from '@/components/ebiz/customer/CustomerPicker'
import DataDictionary from '@/assets/js/utils/data-dictionary'
import areaList from '@/assets/js/utils/areaForSale'
import areaLists from '@/assets/js/utils/areaNewForSale'
import countCredentialValidity from '@/assets/js/utils/countCredentialValidity'
import { getAuthCode, getOrderDetail, saveOrUpdateOrderInfo } from '@/api/ebiz/sale/sale'
import utilsAge from '@/assets/js/utils/age'
import getAreaName from '@/assets/js/utils/getAreaNameForSale'
import idNoCheck from '@/assets/js/utils/idNoCheck'
import beforeDate from '@/assets/js/utils/getBeforeDate.js'
import { idToData } from './js/verification'
import { getIdentityInfo, selectComp } from './js/methods'
import IndexBar from '@/components/ebiz/sale/IndexBar'
import SearchField from './components/SearchField'
import riskRules from '@/views/ebiz/common/risk-rules'

export default {
  name: 'insuredInfo',
  components: {
    SelectRadio: SelectRadio,
    FieldDatePicker: FieldDatePicter,
    OccupationPicker: OccupationPicker,
    CustomerPicker: CustomerPicker,
    [Field.name]: Field,
    [CellGroup.name]: CellGroup,
    [Checkbox.name]: Checkbox,
    [Popup.name]: Popup,
    [Picker.name]: Picker,
    [Area.name]: Area,
    IdentityCardScan: () => import('./components/IdentityCardScan.vue'),
    [IndexBar.name]: IndexBar,
    [Dialog.name]: Dialog,
    [RadioGroup.name]: RadioGroup,
    [Radio.name]: Radio,
    SearchField
  },
  data() {
    return {
      source: this.$route.query.source,
      isNewPeopleFlagTipshow: false,
      isMarriageStatusShow: false,
      withRootUser: {
        load: false, //防止重复请求
        value: false
      },
      isScan: false, //是否显示证件扫描组件
      effectiveDateTypeAble: false, //长期按钮是否禁用
      Asyncs: [
        {
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '0'
        }
      ],
      sexRadio: [
        {
          label: '男',
          value: '0'
        },
        {
          label: '女',
          value: '1'
        }
      ],
      medicalRadio: [
        {
          label: '有',
          value: '0'
        },
        {
          label: '无',
          value: '1'
        }
      ],
      currentTime: beforeDate.getBeforeDays(28),
      fromCustomer: false, //是否从客户列表拉取的数据
      codeDisabled: false, //获取验证码是否禁用
      countDown: 60, //倒计时
      certiexpiredateRequired: true, //证件截止日期是否需要校验
      popupShow: false,
      areaShow: false, //省级联动
      homeShow: false,
      certiexpiredateShow: true, //证件截止日期是否可编辑
      censusShow: false, //户籍联动
      pickerType: undefined,
      columns: [],
      valueKey: 'text',
      // census: '', //户籍
      // areaName: '',
      homeName: '',
      isRequired: '', //长期前是否有*
      userInfo: {
        marriageStatus: '',
        name: '',
        // sex: '0',
        sex: '',
        nativeplace: '1', //国家地区
        birthday: '',
        idType: '1', //证件类型
        idNo: '', //证件号码
        certificateValidate: '', //证件起始日期
        certiexpiredate: '', //证件到期时间
        effectiveDateType: false, //是否长期
        occupationCode: '',
        occupationName: '',
        salarySource: '', // 收入来源
        otherSalarySource: '', // 其他来源
        lifeGrade: '', //寿险等级
        healthGrade: '', //健康等级
        // jobStatus: '', //在职情况
        postcode: '', //邮编
        mobile: '',
        officeTel: '', //单位电话
        stature: '', //身高
        avoirdupois: '', //体重
        // authCode: '', //验证码
        // degree: '', //文化程度
        medical: '1', //有无社保
        // taxResidentId: '', //税收居民身份
        averageAnnualIncome: '', //平均年收入
        liabilitiesMoney: '', //负债金额
        workcompany: '', //工作单位
        isAsync: 0, //是否协同工作单位 0否 1是
        // village: '',
        province: '',
        // city: '',
        area: '',
        marriage: '',
        // familyAnnualIncome: '', //家庭年收入
        relationToAppnt: '',
        // email: '',
        // companyProvince: '', //单位省
        companyCity: '', //单位市
        companyArea: '', //单位区
        // companyAddress: '', //单位详细地址
        // companyZip: '', //单位邮编
        // companyPhone: '', //单位电话
        homeProvince: '', //家庭省
        homeCity: '', //家庭市
        homeArea: '', //家庭区
        homeAddress: '', //家庭详细地址
        // homeZip: '', //家庭邮编
        // homePhone: '' //家庭电话
        // householdProvince: '', //户籍省
        // householdCity: '' //户籍市
        // addressStatus: '' //是否是联系地址
        isNewPeopleFlag: '', //新市民身份
        npType: '' //新市民类型
      },
      areaList: areaList,
      areaLists: areaLists,
      currentPopupIndex: '',
      customerShowPicker: false,
      occupationShowPicker: false,
      isAppnt: false, // 是否投被同人
      // appntMarriage: '', //投保人婚姻状况
      idLimit: false, //证件起止日期是否只读
      salePageFlag: '2',
      userWorkcompanys: [], //单位数据
      manageComCode: '', //代理人管理机构 52贵州 45广西
      areaValue: '', //代理人管理机构--省级编号
      renovate: '', //是否展示风险测评
      branchType: ''
    }
  },
  created() {
    this.specilFlag = this.$route.query.specilFlag
    if (window.localStorage.getItem('branchType')) {
      this.branchType = window.localStorage.getItem('branchType')
    } else if (this.$route.query.branchType) {
      window.localStorage.setItem('branchType', this.$route.query.branchType)
      this.branchType = this.$route.query.branchType
    }
    //如果是编辑/导航进来
    // if (this.$route.query.edit) {
    const orderNo = this.$route.query.orderNo
    if (orderNo) {
      getOrderDetail({ orderNo: orderNo }).then(res => {
        if (res.result == 0) {
          this.renovate = new Date().getTime()
          //投被同人
          if (res.orderDTO.insuredDTOs.length && res.orderDTO.insuredDTOs[0].relationToAppnt == '1') {
            this.$nextTick(() => {
              this.isAppnt = true
              //获取投保人信息
              let insuredInfo = res.orderDTO.appntDTO
              for (let key in this.userInfo) {
                this.userInfo[key] = insuredInfo[key]
              }
              // let insuredCustomer = res.orderDTO.insuredDTOs[0]
              // if (insuredCustomer) {
              this.setCustomerMarriage(insuredInfo.marriage)
              // }
              this.userInfo.birthday = insuredInfo.birthday
              //户籍
              // this.sureArea([{ code: insuredInfo.householdProvince }, { code: insuredInfo.householdCity }], '3')
              //单位地址
              // this.sureArea([{ code: insuredInfo.companyProvince }, { code: insuredInfo.companyCity }, { code: insuredInfo.companyArea }], '1')
              //联系地址
              this.sureArea([{ code: insuredInfo.homeProvince }, { code: insuredInfo.homeCity }, { code: insuredInfo.homeArea }], '2')
              //是否长期
              if (insuredInfo.effectiveDateType == 'false') {
                this.userInfo.effectiveDateType = false
                this.effectiveDateTypeAble = false
              } else {
                this.userInfo.effectiveDateType = true
                this.effectiveDateTypeAble = true
                this.userInfo.certiexpiredate = ''
                this.$refs.certiexpiredate.date = ''
              }
              // this.userInfo.effectiveDateType = insuredInfo.effectiveDateType == 'false' ? false : true
              //数据不是从用户列表拉取
              this.fromCustomer = false
              this.userInfo.relationToAppnt = '1'
              //长期判断
              if (this.userInfo.idType == '1') {
                // 计算年龄
                let age = utilsAge.getAge(this.userInfo.birthday, new Date())
                // 长期按钮是否禁用
                this.effectiveDateTypeAble = age <= 45
              }
            })
          }
          // this.appntMarriage = res.orderDTO.appntDTO.marriage
          this.$utils.intLocalStorage(res)
          if (res.orderDTO.insuredDTOs[0]) {
            let insuredPersonInfo = res.orderDTO.insuredDTOs[0]
            for (let key in this.userInfo) {
              this.userInfo[key] = res.orderDTO.insuredDTOs[0][key]
            }
            //是否长期
            this.userInfo.effectiveDateType = insuredPersonInfo.effectiveDateType == 'false' ? false : true
            //设为联系地址
            // this.userInfo.addressStatus = '0'

            // if (this.$route.query.isShow) {
            //户籍
            // if (insuredPersonInfo.householdProvince.length) {
            //   this.census = getAreaName([{ code: insuredPersonInfo.householdProvince }, { code: insuredPersonInfo.householdCity }])
            // }
            //单位地址
            // if (insuredPersonInfo.companyProvince.length) {
            //   this.areaName = getAreaName([
            //     { code: insuredPersonInfo.companyProvince },
            //     { code: insuredPersonInfo.companyCity },
            //     { code: insuredPersonInfo.companyArea }
            //   ])
            // }
            //联系地址
            if (insuredPersonInfo.homeProvince && insuredPersonInfo.homeProvince.length) {
              this.homeName = getAreaName([
                { code: insuredPersonInfo.homeProvince },
                { code: insuredPersonInfo.homeCity },
                { code: insuredPersonInfo.homeArea }
              ])
            }
            //是否长期
            this.userInfo.effectiveDateType = insuredPersonInfo.effectiveDateType == 'false' ? false : true
            // let saleInsuredPersonInfo = JSON.parse(localStorage.saleInsuredPersonInfo)
            // this.userInfo = saleInsuredPersonInfo
            // this.census = getAreaName([{ code: saleInsuredPersonInfo.householdProvince }, { code: saleInsuredPersonInfo.householdCity }]) //户籍
            // this.areaName = getAreaName([
            //   { code: saleInsuredPersonInfo.companyProvince },
            //   { code: saleInsuredPersonInfo.companyCity },
            //   { code: saleInsuredPersonInfo.companyArea }
            // ]) //单位地址
            // this.homeName = getAreaName([
            //   { code: saleInsuredPersonInfo.homeProvince },
            //   { code: saleInsuredPersonInfo.homeCity },
            //   { code: saleInsuredPersonInfo.homeArea }
            // ]) //联系地址
            // }
            if (this.userInfo.idType == '2') {
              //证件类型如果是户口本时，证件有效止期不可编辑
              this.idLimit = true
              this.effectiveDateTypeAble = false
              this.userInfo.effectiveDateType = false
            }
            //被保人证件类型如果是户口本时，证件截止日期证件截止日期应为第16周岁的生日日期。
            if (this.userInfo.idType == '2' && idToData(this.userInfo.idNo).age < 16) {
              // 获取出生日期年份＋16
              let year = Number(this.userInfo.birthday.substr(0, 4)) + 16
              if (this.userInfo.birthday.substr(5, 5) == '02-29') {
                // 获取某年某月一共多少天
                let date = new Date(year, 2, 1)
                let dayEnd = new Date(date.getTime() - 864e5).getDate()
                this.userInfo.certiexpiredate = year + '-02-' + dayEnd
              } else {
                this.userInfo.certiexpiredate = year + '-' + this.userInfo.birthday.substr(5, 5)
              }
            }
          }
          //------------------------专为惠企写死--begin---------------//
          if (res.orderDTO.insuredDTOs[0] && res.orderDTO.insuredDTOs[0].riskDTOLst) {
            this.specilFlag = res.orderDTO.insuredDTOs[0].riskDTOLst.some(v => {
              return v.riskCode == 'GFRS_M0024' || v.riskCode == 'GFRS_M0040'
            })
              ? '1'
              : '0'
          } else if (res.orderDTO.orderInfoDTO.productCode == 'GFRS_M0024') {
            this.specilFlag = '1'
          } else if (res.orderDTO.orderInfoDTO.productCode == 'GFRS_M0040') {
            this.specilFlag = '1'
          }
          // ------------------------专为惠企写死--end---------------//
        } else {
          return this.$toast(res.resultMessage)
        }
      })
    } else {
      localStorage.setItem('salePageFlag', this.salePageFlag)
    }
    if (this.$route.query.edit && !this.$route.query.salePageFlag) {
      //如果从保单列表点击编辑按钮进入
      this.salePageFlag = '2'
      localStorage.setItem('salePageFlag', this.salePageFlag)
    }
  },
  async mounted() {
    window.cvThis = this
    setTimeout(() => {
      // eslint-disable-next-line no-undef
      EWebBridge.webCallAppInJs('webview_left_button', {
        img: this.$assetsUrl + 'images/del-close-btn@3x.png',
        intercept: '1' //是否拦截原生返回事件 1是 其他否
      })
    }, 100)
    window.appCallBack = this.appCallBack
    //   // document.body.style.backgroundColor = '#F5F5F5'
    //获取代理人管理机构 52贵州 45广西
    let dataReturn = await riskRules.getAgentInfoFunc(this)
    this.manageComCode = dataReturn.manageComCode
    if (this.manageComCode == '45') {
      areaLists.province_list = {
        450000: '广西壮族自治区'
      }
      this.areaValue = '450000'
    } else {
      areaLists.province_list = {
        520000: '贵州省'
      }
      this.areaValue = '520000'
    }
    this.areaLists = areaLists
  },
  methods: {
    isNewPeopleFlagTip() {
      this.isNewPeopleFlagTipshow = true
    },
    workcompanys(list) {
      // 单位数据
      console.log(list)
      this.userWorkcompanys = list
    },
    setCustomerMarriage(marriageCode) {
      for (let status of DataDictionary.marriage) {
        if (status.id == marriageCode) {
          this.userInfo.marriageStatus = status.text
          this.userInfo.marriage = status.id
        }
      }
    },
    onMarriageConfirm(value) {
      this.userInfo.marriageStatus = value.text
      this.isMarriageStatusShow = false
    },
    setMarriageStatus() {
      // 投被同人不允许编辑
      if (this.isReadonly) {
        return
      }
      this.isMarriageStatusShow = true
      this.columns = DataDictionary.marriage
    },
    //监听名字变化
    nameChange(name) {
      this.userInfo.name = name
    },
    selectClick(index) {
      // 投被保险人不允许编辑
      if (this.isReadonly) {
        return
      }
      // this.currentPopupIndex = index
      // let title = ''
      // if (index == 1) {
      //   ;[this.customerShowPicker, title] = [true, '客户列表']
      // } else if (index == 2) {
      //   ;[this.occupationShowPicker, title] = [true, '职业类别']
      // } else if (index == 3) {
      //   localStorage.scanFromInsured = 'false'
      //   ;[this.isScan, title] = [true, '身份证扫描']
      // }

      // setTimeout(() => {
      //   this.$jump({
      //     flag: 'navigation',
      //     extra: {
      //       title,
      //       hiddenLeft: '1'
      //     }
      //   })
      //   this.closeBtn()
      // }, 400)
      // let that = this
      selectComp(this, index, '2')
    },
    chooseOccupation() {
      this.$jump({
        flag: 'navigation',
        extra: {
          title: '被保险人信息',
          hiddenRight: '1'
        }
      })
      this.occupationShowPicker = false
    },
    //弹框选择
    toSelect(pickerType, valueKey) {
      // 投被同人不允许编辑
      if (this.isReadonly && pickerType != '7') {
        return
      }
      //pickerType 1、国家地区 2、证件类型 3、文化程度 4、有无社保(弃用) 5、税收居民身份 6、婚姻状况 7、在职情况 8、收入来源 11、新市民类型
      ;[this.popupShow, this.pickerType] = [true, pickerType]
      if (valueKey) this.valueKey = valueKey
      if (pickerType == '1') {
        this.columns = DataDictionary.nativeplace
      } else if (pickerType == '2') {
        this.columns = DataDictionary.idType
      } /*else if (pickerType == '3') {
        this.columns = DataDictionary.degree
      } */ else if (pickerType == '4') {
        this.columns = [
          { id: 0, text: '有' },
          { id: 1, text: '无' }
        ]
      } else if (pickerType == '5') {
        this.columns = DataDictionary.taxIdentity
      } /* else if (pickerType == '6') {
        this.columns = DataDictionary.marriage
      }*/ else if (pickerType == '7') {
        if (this.specilFlag == '1') {
          // 惠企保 投被关系限制
          this.columns = DataDictionary.hqbRelationToAppnt
        } else {
          this.columns = DataDictionary.relationToAppnt
        }
      } else if (pickerType == '8') {
        this.columns = DataDictionary.workCondition
      } else if (pickerType == '9') {
        this.columns = DataDictionary.salarySource
      } else if (pickerType == '11') {
        this.columns = DataDictionary.npType
      }
    },
    //确认选择字段
    onConfirm(value) {
      this.popupShow = false
      if (this.pickerType == '1') {
        this.userInfo.nativeplace = value.id
      } else if (this.pickerType == '2') {
        this.idLimit = false
        this.userInfo.idNo = this.userInfo.certiexpiredate = this.userInfo.birthday = ''
        this.effectiveDateTypeAble = false
        console.log(value.id)
        //身份证以外的证件类型可以使用长期
        if (value.id == '1') {
          //若身份证件类型为身份证，自动带入年龄
          let age = utilsAge.getAge(this.userInfo.birthday, new Date())
          this.effectiveDateTypeAble = age <= 45

          //若身份证件类型为身份证，自动带入性别
          let sexSign =
            this.userInfo.idNo.length == 18 ? this.userInfo.idNo.substr(16, 1) : this.userInfo.idNo.length == 15 ? this.userInfo.idNo.substr(14, 1) : ''
          //18位身份证第17位是性别位, 奇男偶女;15位身份证第15位是性别位, 奇男偶女
          if (sexSign) {
            if (parseInt(sexSign) % 2 == 0) {
              this.userInfo.sex = '1'
            } else {
              this.userInfo.sex = '0'
            }
          }
        } else if (value.id == 2) {
          //证件类型户口本时，证件截止日期和是否长期不可选择
          this.idLimit = true
          this.effectiveDateTypeAble = true
          this.userInfo.effectiveDateType = false
          // this.userInfo.effectiveDateType = true
          // this.effectiveDateTypeAble = true
          this.userInfo.certiexpiredate = ''
          this.$refs.certiexpiredate.date = ''
        } else if (value.id == 3) {
          this.userInfo.effectiveDateType = true
          // this.effectiveDateTypeAble = true
          this.userInfo.certiexpiredate = ''
          this.$refs.certiexpiredate.date = ''
        } else {
          // else if (value.id == 2 || value.id == 3) {
          //   this.effectiveDateTypeAble = true
          // }
          this.effectiveDateTypeAble = false
        }
        // //出生证明返显证件截止日期
        // if (value.id == 3 && this.userInfo.birthday != '') {
        //   let exipreDate = Date.parse(this.userInfo.birthday) + Date.parse('1972-12-31')
        //   this.userInfo.certiexpiredate = this.timeStampFormat(exipreDate)
        //   this.certiexpiredateShow = false
        // }
        // if (value.id == 2 || value.id == 3) {
        //   this.effectiveDateTypeAble = true
        // }
        // //户口本返显证件截止日期
        // else if (value.id == 2 && this.userInfo.birthday != '') {
        //   let exipreDate = Date.parse(this.userInfo.birthday) + Date.parse('1986-01-01')
        //   this.userInfo.certiexpiredate = this.timeStampFormat(exipreDate)
        //   this.certiexpiredateShow = false
        // } else {
        //   this.certiexpiredateShow = true
        // }
        this.userInfo.idType = value.id
      } /*else if (this.pickerType == '3') {
        this.userInfo.degree = value.id
      }*/ else if (this.pickerType == '4') {
        this.userInfo.socialSecurity = value.id
      } /*else if (this.pickerType == '5') {
        this.userInfo.taxResidentId = value.id
      }  else if (this.pickerType == '6') {
        this.userInfo.marriage = value.id
      } */ else if (
        this.pickerType == '7'
      ) {
        //如果关系是本人
        if (value.id == 1) {
          //获取订单详情
          const orderNo = this.$route.query.orderNo
          getOrderDetail({ orderNo: orderNo }).then(res => {
            if (res.result == 0) {
              this.isAppnt = true
              //获取投保人信息
              let insuredInfo = res.orderDTO.appntDTO
              // console.log(insuredInfo)
              //清空验证码
              // insuredInfo.authCode = ''
              for (let key in this.userInfo) {
                this.userInfo[key] = insuredInfo[key]
              }
              console.log('是本人了~')
              console.log(this.userInfo)
              // this.userInfo = insuredInfo
              //处理时间戳
              // for (let key in this.userInfo) {
              //   this.userInfo[key] = insuredInfo[key]
              // }
              // this.userInfo = insuredInfo
              this.userInfo.birthday = insuredInfo.birthday
              this.setCustomerMarriage(insuredInfo.marriage)
              //户籍
              // this.sureArea([{ code: insuredInfo.householdProvince }, { code: insuredInfo.householdCity }], '3')
              //单位地址
              // this.sureArea([{ code: insuredInfo.companyProvince }, { code: insuredInfo.companyCity }, { code: insuredInfo.companyArea }], '1')
              //联系地址
              this.sureArea([{ code: insuredInfo.homeProvince }, { code: insuredInfo.homeCity }, { code: insuredInfo.homeArea }], '2')
              //是否长期
              if (insuredInfo.effectiveDateType == 'false') {
                this.userInfo.effectiveDateType = false
              } else {
                this.userInfo.effectiveDateType = true
                this.userInfo.certiexpiredate = ''
                this.$refs.certiexpiredate.date = ''
              }
              this.effectiveDateTypeAble = true
              // this.userInfo.effectiveDateType = insuredInfo.effectiveDateType == 'false' ? false : true
              //数据不是从用户列表拉取
              this.fromCustomer = false
              this.userInfo.relationToAppnt = value.id
              //长期判断
              // if (this.userInfo.idType == '1') {
              //   // 计算年龄
              //   let age = utilsAge.getAge(this.userInfo.birthday, new Date())
              //   // 长期按钮是否禁用
              //   this.effectiveDateTypeAble = age <= 45
              // }
            } else {
              this.$toast(res.resultMessage)
            }
          })
          //获取投保人信息
          // let insuredInfo = JSON.parse(localStorage.saleInsuredInfo)
        } else {
          this.isAppnt = false
          //数据是否从用户列表拉取
          if (this.fromCustomer) {
            return (this.userInfo.relationToAppnt = value.id)
          }
          //如果关系不是本人(选了本人之后修改), 清空 userInfo 信息
          for (var key in this.userInfo) {
            if (!['nativeplace', 'sex', 'idType', 'effectiveDateType', 'medical'].includes(key)) {
              this.userInfo[key] = ''
            }
          }
          this.userInfo.effectiveDateType = false
          this.effectiveDateTypeAble = false
          this.areaName = this.homeName = ''
          // this.areaName = this.homeName = this.census = ''
          this.userInfo.relationToAppnt = value.id
        }
      } /*else if (this.pickerType == '8') {
        this.userInfo.jobStatus = value.id
      }*/ else if (this.pickerType == '9') {
        this.userInfo.salarySource = value.id
      } else if (this.pickerType === '10') {
        this.userInfo
      } else if (this.pickerType === '11') {
        this.userInfo.npType = value.id
      }
      // 如果是主动选择本人， 那么不让填写了
      this.source = ''
    },
    //证件起始截止日期
    onDateConfirm(val, type) {
      switch (type) {
        case '0': {
          //证件起始日期
          //如果录入日期早于出生日期或晚于当前日期
          if (Date.parse(val) > Date.parse(new Date()) || Date.parse(val) < Date.parse(this.userInfo.birthday)) {
            this.userInfo.certificateValidate = ''
            this.$refs.certificateValidate.date = ''
            return this.$toast('证件起始日期填写错误')
          }

          // 计算年龄
          if (this.userInfo.idType == '1') {
            let age = utilsAge.getAge(this.userInfo.birthday, new Date())
            // 长期按钮是否禁用
            this.effectiveDateTypeAble = age <= 45
            if (this.userInfo.birthday && !this.userInfo.certiexpiredate) {
              this.userInfo.certiexpiredate = countCredentialValidity.getEndDate(this.userInfo.birthday, val)
              if (this.userInfo.certiexpiredate) {
                this.userInfo.certiexpiredate = this.userInfo.certiexpiredate
                this.effectiveDateTypeAble = true
                this.userInfo.effectiveDateType = false
              }
            }
          }
        }
          break
        case '1': {
          //证件截止日期
          //如果已经勾选了长期
          // if (this.userInfo.effectiveDateType) {
          //   //清空数据并返回
          //   this.userInfo.certiexpiredate = ''
          //   this.$refs.certiexpiredate.date = ''
          //   return
          // }
          this.userInfo.effectiveDateType = false
          //如果录入日期早于当前日期
          if (Date.parse(val) < Date.parse(new Date())) {
            this.userInfo.certiexpiredate = ''
            this.$refs.certiexpiredate.date = ''
            return this.$toast('亲，请您核实被保险人身份证件有效期~')
          }

          //身份证证件类型的判断
          if (this.userInfo.idType == '1') {
            //获取年龄
            let age = utilsAge.getAge(this.userInfo.birthday, new Date())
            console.log(age)
            // if(this.userInfo.birthday){
            //   this.userInfo.certificateValidate = countCredentialValidity.getStartDate(this.userInfo.birthday,val)
            // }
          }
        }
          break
        case '2': {
          //出生日期
          //如果录入日期晚于当前日期
          if (Date.parse(val) > Date.parse(new Date())) {
            this.userInfo.birthday = ''
            this.$refs.birthday.date = ''
            return this.$toast('出生日期不晚于当日')
          }
          //长期判断
          let age = utilsAge.getAge(this.userInfo.birthday, new Date())
          //年龄小于18周岁，工作单位默认值为‘无’
          if (age < 18) {
            this.userInfo.workcompany = this.userInfo.workcompany || '无'
          }
          if (this.userInfo.idType == '1') {
            this.effectiveDateTypeAble = age <= 45
          } else {
            if (age < 16) {
              this.userInfo.salarySource = this.branchType == '14' ? null : 4
              this.userInfo.otherSalarySource = '无'
              this.userInfo.averageAnnualIncome = '0'
              this.userInfo.liabilitiesMoney = this.branchType == '14' ? '' : '0'
            }
          }
          if (this.userInfo.certificateValidate && !this.userInfo.certiexpiredate) {
            this.userInfo.certiexpiredate = countCredentialValidity.getEndDate(this.userInfo.birthday, this.userInfo.certificateValidate)
          }
          if (this.userInfo.certiexpiredate && !this.userInfo.certificateValidate) {
            this.userInfo.certificateValidate = countCredentialValidity.getEndDate(this.userInfo.birthday, this.userInfo.certiexpiredate)
          }
        }
          break
      }
    },
    appCallBack(data) {
      if (data.trigger == 'left_button_click') {
        return this.$dialog
          .confirm({
            className: 'dialog-delete',
            title: '提示',
            message: '退出流程可能会丢失部分数据，是否确认退出？',
            cancelButtonColor: '#E9332E',
            confirmButtonColor: '#FFFFFF'
          })
          .then(() => {
            this.$jump({
              flag: 'h5',
              extra: {
                title: '电子投保单列表',
                forbidSwipeBack: 1, //当前页面禁止右滑返回
                url: location.origin + `/#/sale/list`
              },
              routerInfo: {
                path: `/sale/list`,
                type: '1'
              }
            })
          })
          .catch(() => {
            return
          })
      } else {
        // 筛选按钮的点击事件
        this.$jump({
          flag: 'navigation',
          extra: {
            title: '被保人信息',
            hiddenRight: '1'
          }
        })
        console.log(this.currentPopupIndex)
        if (this.currentPopupIndex == 1) {
          this.customerShowPicker = false
        } else if (this.currentPopupIndex == 2) {
          this.occupationShowPicker = false
        } else if (this.currentPopupIndex == 3) {
          this.isScan = false
        }
      }
    },
    //选择客户
    chooseCustomer(data) {
      console.log(data)
      this.customerShowPicker = false
      this.$jump({
        flag: 'navigation',
        extra: {
          title: '被保险人信息',
          hiddenRight: '1'
        }
      })
      let { customerName, customerSex } = data
      this.userInfo.name = customerName //用户名
      if (customerSex == null) {
        this.userInfo.sex = ''
      } else {
        this.userInfo.sex = String(customerSex) //性别
      }
      this.userInfo.nativeplace = data.country //国家地区
      this.userInfo.birthday = data.birthday //出生日期
      this.userInfo.idType = data.customerIdType //证件类型
      // 证件截止日期证件截止日期应为第16周岁的生日日期
      if (this.userInfo.idType == '2') {
        //证件类型如果是户口本时，证件有效止期不可编辑
        this.idLimit = true
        this.effectiveDateTypeAble = false
        this.userInfo.effectiveDateType = false
      }
      if (this.userInfo.idType == '2' && idToData(this.userInfo.idNo).age < 16) {
        // 获取出生日期年份＋16
        let year = Number(this.userInfo.birthday.substr(0, 4)) + 16
        if (this.userInfo.birthday.substr(5, 5) == '02-29') {
          // 获取某年某月一共多少天
          let date = new Date(year, 2, 1)
          let dayEnd = new Date(date.getTime() - 864e5).getDate()
          this.userInfo.certiexpiredate = year + '-02-' + dayEnd
        } else {
          this.userInfo.certiexpiredate = year + '-' + this.userInfo.birthday.substr(5, 5)
        }
      }
      this.userInfo.idNo = data.customerIdNumber //证件号码
      this.userInfo.certificateValidate = data.idEffectStartDate //证件起始日期
      // this.userInfo.certiexpiredate = data.idEffectEndDate //证件截止日期
      // this.userInfo.effectiveDateType = data.idEffectEndDate == '9999-12-31' //是否长期
      if (data.idEffectEndDate == '9999-12-31') {
        this.userInfo.effectiveDateType = true //是否长期
      } else {
        this.userInfo.certiexpiredate = data.idEffectEndDate //证件截止日期
      }
      this.userInfo.occupationCode = data.occupationCode //职业类别编码
      this.userInfo.occupationName = data.occupationName //职业类别名称
      this.userInfo.salarySource = this.branchType == '14' ? null : data.salarySource //收入来源
      this.userInfo.otherSalarySource = data.otherSalarySource // 其他收入来源
      this.userInfo.lifeGrade = data.lifeGrade //寿险等级
      this.userInfo.healthGrade = data.healthGrade //健康等级
      this.userInfo.mobile = data.customerPhone //移动电话
      this.userInfo.stature = data.height //身高
      this.userInfo.avoirdupois = data.weight //体重
      // this.userInfo.degree = data.educationLevel //教育水平
      this.userInfo.medical = data.socialSecurity //有无社保
      // this.userInfo.taxResidentId = data.residentStatus //税收居民身份
      this.userInfo.averageAnnualIncome = data.averageYearlyIncome //平均年收入
      this.userInfo.workcompany = data.workUnits //工作单位
      // this.userInfo.jobStatus = data.jobStatus //工作情况
      this.setCustomerMarriage(data.marryStatus)
      // this.userInfo.familyAnnualIncome = data.familyAnnualIncome //家庭年收入
      // this.userInfo.email = data.email //电子邮箱
      this.userInfo.liabilitiesMoney = this.branchType == '14' ? '' : data.liabilitiesMoney //负债金额
      // this.userInfo.companyProvince = data.companyProvince //单位省
      // this.userInfo.companyCity = data.companyCity //单位市
      // this.userInfo.companyArea = data.companyArea //单位区
      // this.userInfo.companyAddress = data.companyAddress //单位详细地址
      // this.userInfo.companyZip = data.companyZip //单位邮编
      // this.userInfo.companyPhone = data.companyPhone //单位电话
      this.userInfo.homeProvince = data.homeProvince //家庭省
      this.userInfo.homeCity = data.homeCity //家庭市
      this.userInfo.homeArea = data.homeArea //家庭区
      this.userInfo.homeAddress = data.homeAddress //家庭详细地址
      this.userInfo.isNewPeopleFlag = data.isNewPeopleFlag //新市民身份
      this.userInfo.npType = data.npType //新市民类型
      // this.userInfo.homeZip = data.homeZip //家庭邮编
      // this.userInfo.homePhone = data.homePhone //家庭电话
      // this.userInfo.householdProvince = data.province //户籍省
      // this.userInfo.householdCity = data.city //户籍市
      // if (data.province.length) {
      //   this.census = getAreaName([{ code: data.province }, { code: data.city }]) //户籍
      // }
      // if (data.companyProvince.length) {
      //   this.areaName = getAreaName([{ code: data.companyProvince }, { code: data.companyCity }, { code: data.companyArea }]) //单位地址
      // }
      if (data.homeProvince.length) {
        this.homeName = getAreaName([{ code: data.homeProvince }, { code: data.homeCity }, { code: data.homeArea }]) //联系地址
      }
      //计算年龄
      let age = utilsAge.getAge(this.userInfo.birthday, new Date())
      // 长期按钮是否禁用
      this.effectiveDateTypeAble = age <= 45
      //数据是否从客户列表拉取
      this.fromCustomer = true
      this.getRelatedData(this.userInfo.idNo, 'select')
    },
    //下一步
    async nextStep({ passValidate = false }) {
      let valid = passValidate ? true : await this.$validator.validate()
      if (this.manageComCode == '45') {
        if (this.userInfo.isNewPeopleFlag == '' || this.userInfo.isNewPeopleFlag == null || this.userInfo.isNewPeopleFlag == undefined) {
          this.$toast('新市民身份不能为空')
          return false
        }
      }
      // .then(valid => {
      if (true === valid) {
        // 职业 学龄前儿童 2099908， 离休人员 8000003，家庭主妇 4071203，无业人员 8000001，
        // 亲，您填写的工作单位过于简短哦~
        // if (
        //   this.userInfo.occupationCode == '2099908' ||
        //   this.userInfo.occupationCode == '8000003' ||
        //   this.userInfo.occupationCode == '4071203' ||
        //   this.userInfo.occupationCode == '8000001'
        // ) {
        // }
        if (!this.userInfo.workcompany) {
          this.userInfo.workcompany = '无'
        }
        // 计算年龄
        let age = utilsAge.getAge(this.userInfo.birthday, new Date())

        // 被保险人人年龄≤13岁，学历不可以为研究生、本科、高中、大专
        // if (age < 14 && this.userInfo.degree - 0 <= 5) {
        //   return this.$toast('亲，请确认被保险人学历哦~')
        // }

        //投被保险人关系是配偶
        if (this.userInfo.relationToAppnt == '2') {
          //投保人或者被保险人不是已婚
          // if (this.appntMarriage != '1' || this.userInfo.marriage != '1') {
          //   return this.$toast('亲，被保险人与投保人关系为配偶，投保人或被保险人婚姻状况必须为已婚哦~')
          // }
          let insuredSex = this.userInfo.sex
          console.log(JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')), 'saleInsuredInfo')
          let appntSex = JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')).sex
          //投被保险人性别相同
          if (insuredSex == appntSex) {
            return this.$toast('额~配偶关系性别不能相同哦~')
          }
        } else if (this.userInfo.relationToAppnt == '4') {
          //投被保人关系是子女
          // 被保险人的出生日期大于投保人的出生日期（即被保险人年龄小于投保人年龄）点击【下一步】提示“当前被保险人是投保人的子女，被保险人年龄需小于投保人年龄。
          if (age > JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')).age) {
            return this.$toast('当前被保险人是投保人的子女，被保险人年龄需小于投保人年龄')
            // await this.$dialog.confirm({
            //   title: '提示',
            //   message: '亲，请确认被保险人与投保人关系哦~',
            //   confirmButtonText: '继续填写',
            //   cancelButtonText: '返回修改',
            // })
          }
        } else if (this.userInfo.relationToAppnt == '3') {
          //投被保人关系是父母
          // 被保险人的出生日期小于投保人的出生日期（即被保险人年龄大于投保人年龄）点击【下一步】提示“当前被保险人是投保人的父母，被保险人年龄需大于投保人年龄。
          if (age < JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')).age) {
            return this.$toast('当前被保险人是投保人的父母，被保险人年龄需大于投保人年龄')
            // await this.$dialog.confirm({
            //   title: '提示',
            //   message: '亲，请确认被保险人与投保人关系哦~',
            //   confirmButtonText: '继续填写',
            //   cancelButtonText: '返回修改',
            // })
          }
        }
        if (this.userInfo.relationToAppnt != '1') {
          //投被保人关系不是本人
          //投保人和被保险人的证件信息（证件号码、证件类型）相同时，关系只能是本人，当“是投保人的”枚举为非本人（配偶、父母、子女、其他），但证件号码和本人相同，点击【下一步】提示“投保人和被保人关系不是本人，证件号码不可一致，请修改。”
          if (
            this.userInfo.idNo == JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')).idNo &&
            this.userInfo.idType == JSON.parse(this.$CacheUtils.getLocItem('saleInsuredInfo')).idType
          ) {
            return this.$toast('投保人和被保人关系不是本人，证件号码不可一致，请修改。')
          }
        }

        // if (this.userInfo.marriage == '1') {
        //   if (this.userInfo.sex == '0' && age < 22) {
        //     return this.$toast('年龄与婚姻状况不符')
        //   } else if (this.userInfo.sex == '1' && age < 20) {
        //     return this.$toast('年龄与婚姻状况不符')
        //   }
        // }

        //如果证件类型是身份证
        if (this.userInfo.idType == '1') {
          if (this.userInfo.nativeplace != '1') {
            return this.$toast('证件类型”为“身份证，国籍必须为中国哦')
          }
          //校验性别是否与身份证号码位相符
          if (this.userInfo.idNo.length == '15') {
            //15位身份证第15位是性别位, 奇男偶女
            let sexSign = this.userInfo.idNo.substr(14, 1)
            if ((parseInt(sexSign) % 2 == 0 && this.userInfo.sex != 1) || (parseInt(sexSign) % 2 != 0 && this.userInfo.sex != 0)) {
              return this.$toast('性别录入与身份证不符')
            }

            //15位身份证第7-12位是生日位, 年月日
            let birthSign = this.userInfo.idNo.substr(6, 6)
            if (
              this.userInfo.birthday.substr(2, 2) != birthSign.substr(0, 2) ||
              this.userInfo.birthday.substr(5, 2) != birthSign.substr(2, 2) ||
              this.userInfo.birthday.substr(8, 2) != birthSign.substr(4, 2)
            ) {
              return this.$toast('生日录入与身份证不符')
            }
          } else if (this.userInfo.idNo.length == '18') {
            //18位身份证第17位是性别位, 奇男偶女
            let sexSign = this.userInfo.idNo.substr(16, 1)
            if ((parseInt(sexSign) % 2 == 0 && this.userInfo.sex != 1) || (parseInt(sexSign) % 2 != 0 && this.userInfo.sex != 0)) {
              return this.$toast('性别录入与身份证不符')
            }

            //18位身份证第7-14位是生日位, 年月日
            let birthSign = this.userInfo.idNo.substr(6, 8)
            if (
              this.userInfo.birthday.substr(0, 4) != birthSign.substr(0, 4) ||
              this.userInfo.birthday.substr(5, 2) != birthSign.substr(4, 2) ||
              this.userInfo.birthday.substr(8, 2) != birthSign.substr(6, 2)
            ) {
              return this.$toast('生日录入与身份证不符')
            }
          }

          // 证件号码规则校验
          if (!idNoCheck.isIdno(this.userInfo.idNo)) {
            console.log('证件号码校验有误')
            return this.$toast('您填写的证件号码有误')
          }
          console.log(age)
          //年龄在小于周岁（不含46周岁），证件有效期不能为长期
          if (age < 46 && this.userInfo.effectiveDateType == true) {
            return this.$toast('证件有效期错误，年龄小于46周岁的公民身份证有效期不能为长期')
          }

          //证件止期
          let val = this.userInfo.certiexpiredate
          if (Date.parse(val) < Date.parse(new Date())) {
            this.userInfo.certiexpiredate = ''
            this.$refs.certiexpiredate.date = ''
            return this.$toast('您的证件已过期')
          }
          //年龄在16周岁以下
          if (age < 16) {
            if (new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 5) {
              return this.$toast('16周岁以下的证件有效期为5年')
            }
            //年龄在16-21周岁之间
          } else if (age >= 16 && age <= 21) {
            if (
              new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 10 &&
              new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 5
            ) {
              return this.$toast('16周岁~21周岁的证件有效期为10年或5年')
            }
            //年龄在22-25周岁之间
          } else if (age >= 22 && age <= 25) {
            if (new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 10) {
              return this.$toast('22周岁~25周岁的证件有效期为10年')
            }
            //年龄在26-35周岁之间
          } else if (age >= 26 && age <= 35) {
            if (
              new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 20 &&
              new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 10
            ) {
              return this.$toast('26周岁~35周岁的证件有效期为20年或10年')
            }
            //年龄在36-45周岁之间
          } else if (age >= 36 && age <= 45) {
            if (new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 20) {
              return this.$toast('36周岁~45周岁的证件有效期为20年')
            }
            //年龄在46-65周岁之间
          } else if (age >= 46 && age <= 65) {
            if (new Date(val).getFullYear() - new Date(this.userInfo.certificateValidate).getFullYear() != 20 && this.userInfo.effectiveDateType == false) {
              return this.$toast('46周岁~65周岁的证件有效期为20年或长期')
            }
            //年龄在65周岁以上
          } else if (age > 65) {
            if (this.userInfo.effectiveDateType == false) {
              return this.$toast('65周岁以上的证件有效期为长期')
            }
          }
          //年龄在0-15周岁之间
          // if (age <= 15) {
          //   if (Date.parse(this.userInfo.certiexpiredate) - Date.parse(new Date()) > Date.parse('1975-01-01')) {
          //     this.userInfo.certiexpiredate = ''
          //     this.$refs.certiexpiredate.date = ''
          //     // this.effectiveDateTypeAble = true
          //     return this.$toast('证件有效期错误，未满16周岁的公民身份证有效期应小于等于5年')
          //   }
          //   //年龄在 16-25 周岁之间
          // } else if (age >= 16 && age <= 25) {
          //   if (Date.parse(this.userInfo.certiexpiredate) - Date.parse(new Date()) > Date.parse('1980-01-01')) {
          //     this.userInfo.certiexpiredate = ''
          //     this.$refs.certiexpiredate.date = ''
          //     // this.effectiveDateTypeAble = true
          //     return this.$toast('证件有效期错误，16周岁~25周岁的公民身份证有效期应小于等于10年')
          //   }
          //   //年龄在 26-45 周岁之间
          // } else if (age >= 26 && age <= 45) {
          //   if (Date.parse(this.userInfo.certiexpiredate) - Date.parse(new Date()) > Date.parse('1990-01-01')) {
          //     this.userInfo.certiexpiredate = ''
          //     this.$refs.certiexpiredate.date = ''
          //     // this.effectiveDateTypeAble = true
          //     return this.$toast('证件有效期错误，26周岁~45周岁的公民身份证有效期应小于等于20年')
          //   }
          // }
          //如果是身份证，且未成年，则与投保人关系必须是子女关系
          // if(age < 18 && this.userInfo.relationToAppnt != '4'){
          //   return this.$toast('被保险人小于18周岁，选择身份证时，与投保人关系必须为子女')
          // }

          //证件类型是户口本
        } else if (this.userInfo.idType == '2') {
          if (this.userInfo.nativeplace != '1') {
            return this.$toast('证件类型”为“身份证，国籍必须为中国哦')
          }
          //校验性别是否与身份证号码位相符
          if (this.userInfo.idNo.length == '15') {
            //15位身份证第15位是性别位, 奇男偶女
            let sexSign = this.userInfo.idNo.substr(14, 1)
            if ((parseInt(sexSign) % 2 == 0 && this.userInfo.sex != 1) || (parseInt(sexSign) % 2 != 0 && this.userInfo.sex != 0)) {
              return this.$toast('性别录入与身份证不符')
            }

            //15位身份证第7-12位是生日位, 年月日
            let birthSign = this.userInfo.idNo.substr(6, 6)
            if (
              this.userInfo.birthday.substr(2, 2) != birthSign.substr(0, 2) ||
              this.userInfo.birthday.substr(5, 2) != birthSign.substr(2, 2) ||
              this.userInfo.birthday.substr(8, 2) != birthSign.substr(4, 2)
            ) {
              return this.$toast('生日录入与身份证不符')
            }
          } else if (this.userInfo.idNo.length == '18') {
            //18位身份证第17位是性别位, 奇男偶女
            let sexSign = this.userInfo.idNo.substr(16, 1)
            if ((parseInt(sexSign) % 2 == 0 && this.userInfo.sex != 1) || (parseInt(sexSign) % 2 != 0 && this.userInfo.sex != 0)) {
              return this.$toast('性别录入与身份证不符')
            }

            //18位身份证第7-14位是生日位, 年月日
            let birthSign = this.userInfo.idNo.substr(6, 8)
            if (
              this.userInfo.birthday.substr(0, 4) != birthSign.substr(0, 4) ||
              this.userInfo.birthday.substr(5, 2) != birthSign.substr(4, 2) ||
              this.userInfo.birthday.substr(8, 2) != birthSign.substr(6, 2)
            ) {
              return this.$toast('生日录入与身份证不符')
            }
          }

          // 证件号码规则校验
          if (!idNoCheck.isIdno(this.userInfo.idNo)) {
            console.log('证件号码校验有误')
            return this.$toast('您填写的证件号码有误')
          }
          if (age >= 16) {
            return this.$toast('客户年龄在16周岁以上，不能使用户口本作为有效证件')
          }
          // else if (this.userInfo.idNo.length != 18) {
          //   return this.$toast('户口本的证件号码长度应等于18位')
          // }
          //证件类型是出生证明
        } else if (this.userInfo.idType == '3') {
          if (age >= 2) {
            return this.$toast('客户年龄在2周岁及以上，不能使用出生证作为有效证件')
          }
          // 证件号码规则校验
          if (!idNoCheck.isCardNoBirth(this.userInfo.idNo)) {
            console.log('证件号码校验有误')
            return this.$toast('您填写的证件号码有误')
          }
          // else if (this.userInfo.idNo.length < 3) {
          //   return this.$toast('出生证须大于等于3个字符')
          // }
          //证件类型是护照
        } else if (this.userInfo.idType == '4') {
          if (this.userInfo.nativeplace == '1') {
            return this.$toast('“证件类型”为“外国人护照”，“国籍”不能选择为“中国”哦~')
          }
        } else if (this.userInfo.idType == '5') {
          console.log(this.userInfo.nativeplace, 'nativeplace')
          if (this.userInfo.nativeplace != 2 && this.userInfo.nativeplace != 3) {
            return this.$toast('“证件类型”为“港澳居民来往内地通行证”，“国籍”请选择“中国香港”或“中国澳门”哦~')
          }
        } else if (this.userInfo.idType == '6') {
          if (this.userInfo.nativeplace != 4) {
            return this.$toast('“证件类型”为“台湾居民来往大陆通行证”，“国籍”请选择“中国台湾”~')
          }
        } else if (this.userInfo.idType == '9') {
          if (this.userInfo.nativeplace != 2 && this.userInfo.nativeplace != 3 && this.userInfo.nativeplace != 4) {
            return this.$toast('“证件类型”为“港澳台居民居住证”，“国籍”请选择“中国香港”、“中国澳门”或“中国台湾”~')
          }
        }
        // else if (this.userInfo.idType == '4' && this.userInfo.idNo.length < 3) {
        //   return this.$toast('护照须大于等于3个字符')
        //   //证件是港澳居民通行证
        // } else if (this.userInfo.idType == '5') {
        //   if (this.userInfo.idNo.length != 9) {
        //     return this.$toast('证件类型为港澳居民通行证的，证件号码须为9位')
        //   } else if (!/^(H|M)[0-9]{8}$/.test(this.userInfo.idNo)) {
        //     return this.$toast('证件类型为港澳居民通行证的，证件号码首位字母为"H"/"M",证件号码第2位至第9位为阿拉伯数字')
        //   }
        //   //证件是台湾居民通行证
        // } else if (this.userInfo.idType == '6' && this.userInfo.idNo.length != 8) {
        //   return this.$toast('证件类型为台湾居民通行证的，证件号码须为8位数字')
        // }

        // 年龄 0-7 周岁且不是投保人的子女
        if (age < 7 && this.userInfo.relationToAppnt != '4') {
          return this.$toast('0-7岁未成年人须由其父母投保，请确定')
        }

        if (this.userInfo.salarySource == '4' && this.branchType != '14') {
          if (!this.userInfo.otherSalarySource) {
            return this.$toast('请输入其它收入来源')
          }
        }

        // 婚姻状况处理: 使用computed/watch可能会出现检测不到的情况
        for (let status of DataDictionary.marriage) {
          if (status.text === this.userInfo.marriageStatus) {
            this.userInfo.marriage = status.id
          }
        }

        //如果是已婚
        // if ((this.userInfo.sex == '0' && age < 22) || (this.userInfo.sex == '1' && age < 20)) {
        //   if (this.userInfo.marriage != '2') {
        //     return this.$toast('被保险人不符合国家婚姻法定年龄')
        //   }
        // }

        // 通过国籍判断 证件是否符合要求
        // 如果是国籍选择中国大陆
        if (Number(this.userInfo.nativeplace) <= 4) {
          // “身份证”或“台湾居民来往大陆通行证”或“港澳居民来往内地通行证”
          let obj = {
            1: true,
            5: true,
            6: true,
            9: true
          }
          let idType = this.userInfo.idType
          // 通过年龄 判断证件是否符合要求
          // 小于2岁
          if (age < 2) {
            // “出生证”,"户口本"
            obj['2'] = true
            obj['3'] = true
            if (obj[idType] === undefined) {
              return this.$toast(
                '亲，国籍为中国，且未满2周岁儿童，证件类型必须“身份证”或“户口本”或“出生证”或“台湾居民来往大陆通行证”或“港澳居民来往内地通行证”'
              )
            }
          } else if (age < 16) {
            // 小于16岁
            // “户口本”
            obj['2'] = true
            if (obj[idType] === undefined) {
              return this.$toast(
                '亲，国籍为中国，且大于2周岁小于16周岁的未成年人，证件类型必须为“身份证”或“户口本”或“台湾居民来往大陆通行证”或“港澳居民来往内地通行证”'
              )
            }
          } else {
            // 大于16岁
            if (obj[idType] === undefined) {
              return this.$toast('亲，国籍为中国，证件类型必须为“身份证”或“台湾居民来往大陆通行证”或“港澳居民来往内地通行证”')
            }
          }
        } else {
          // 非大陆人员按外籍人员
          let obj = {
            4: true,
            8: true
          }
          let idType = this.userInfo.idType
          if (obj[idType] === undefined) {
            return this.$toast('亲，国籍为外籍，证件类型必须为护照或外国人永久居留身份证投保')
          }
        }
        if (this.userInfo.isAsync == 1) {
          if (
            !this.userWorkcompanys.some(item => {
              return item.asscompanies == this.userInfo.workcompany
            })
          ) {
            if (
              this.userWorkcompanys.some(item => {
                return item.asscompanies.search(this.userInfo.workcompany) != -1
              })
            ) {
              return this.$toast('请填写完整的协同单位名称')
            }
            return this.$toast('您选择的为非协同单位，请重新选择。')
          }
        }
        this.infoUpdate()
      } else {
        return this.$toast(this.$validator.errors.all()[0])
      }
    },
    //信息变更
    infoUpdate() {
      //local 里面是否存有险种信息
      let chooseProductCodes = localStorage.chooseProductCodesNew && JSON.parse(localStorage.chooseProductCodesNew)
      // if (chooseProductCodes && chooseProductCodes.length) {
      if (this.$CacheUtils.getLocItem('saleInsuredPersonInfo')) {
        //获取险种列表
        //取出local中的被保险人信息
        let saleInsuredPersonInfo = JSON.parse(this.$CacheUtils.getLocItem('saleInsuredPersonInfo'))
        //如果 性别, 出生日期, 有无社保, 职业 发生变化
        console.log(this.userInfo, '这是userInfo')
        console.log(saleInsuredPersonInfo, '这是saleInsuredPersonInfo')
        if (
          this.userInfo.sex != saleInsuredPersonInfo.sex ||
          this.userInfo.birthday != saleInsuredPersonInfo.birthday ||
          this.userInfo.medical != saleInsuredPersonInfo.medical ||
          this.userInfo.occupationCode != saleInsuredPersonInfo.occupationCode
        ) {
          //提示用户
          if (chooseProductCodes && chooseProductCodes.length)
            return Dialog.confirm({
              className: 'dialog-delete',
              title: '提示',
              message: '当前信息已经发生改变，有可能影响险种费率，是否确认修改并清除险种信息?',
              cancelButtonColor: '#4FC6B3',
              confirmButtonColor: '#FFFFFF'
            })
              .then(() => {
                // on confirm
                localStorage.chooseProductCodesNew = ''
                this.save()
              })
              .catch(() => {
                // on cancel
                return
              })
        }
      }
      this.save()
    },
    //存储信息
    async save() {
      let params = {
        orderType: 'INSURED_ORDER',
        orderDTO: {
          orderInfoDTO: {
            orderNo: this.$route.query.orderNo
          },
          appntDTO: {},
          userModel: {
            branchType: this.branchType
          }
        }
      }
      if (this.userInfo.mediaDTOS == '') {
        delete this.userInfo.mediaDTOS
      }
      console.dir(this.userInfo)
      params.orderDTO.insuredDTOs = [this.userInfo]
      let str = ''
      let resultData = await saveOrUpdateOrderInfo(params)
      if (resultData.result == 0) {
        localStorage.salePageFlag = '3'
        //deleteFlag 0-该页面修改了信息且修改的信息影响到后面流程，后台进行了删除数据的操作
        if (resultData.deleteFlag == '0') {
          localStorage.salePageFlag = '3'
        } else if (!this.$route.query.salePageFlag) {
          //如果从保单列表编辑按钮/新增保单进入
          localStorage.salePageFlag = '3'
        } else {
          str = 'edit=1&salePageFlag=3'
        }
        localStorage.isFrom = 'sale'
        //清理计时器
        window.clearInterval(this.timeId)
        this.timeId = null
        this.countDown = 60
        this.codeDisabled = false
        // this.$jump({
        //   flag: 'h5',
        //   extra: {
        //     forbidSwipeBack: '1',
        //     url: location.origin + `/#/common/selectedProduct?${str}` + '&orderNo=' + this.$route.query.orderNo
        //   },
        //   routerInfo: {
        //     path: `/common/selectedProduct?${str}` + '&orderNo=' + this.$route.query.orderNo
        //   }
        // })
      } else {
        return this.$toast(resultData.resultMessage)
      }
    },
    //区域选择
    sureArea(area, type) {
      switch (type) {
        // case '1': //单位地址
        //   this.areaName = getAreaName(area)
        //   ;[this.userInfo.companyProvince, this.userInfo.companyCity, this.userInfo.companyArea] = [area[0].code, area[1].code, area[2].code]
        //   this.areaShow = false
        //   break
        case '2': //联系地址
          this.homeName = getAreaName(area)
          ;[this.userInfo.homeProvince, this.userInfo.homeCity, this.userInfo.homeArea] = [area[0].code, area[1].code, area[2].code]
          this.homeShow = false
          break
        // case '3': //户籍
        //   this.census = getAreaName(area)
        //   ;[this.userInfo.householdProvince, this.userInfo.householdCity] = [area[0].code, area[1].code]
        //   this.censusShow = false
        //   break
      }
    },
    //获取验证码
    getCode() {
      if (this.userInfo.mobile == '') {
        return this.$toast('请填写移动电话')
      }
      //生成请求参数
      let data = {
        operateType: 'insureInfoEntry',
        type: 'H5',
        operateCode: this.userInfo.mobile,
        system: 'agentApp',
        operateCodeType: '0'
      }
      this.codeDisabled = true
      //倒计时
      let timeId = setInterval(() => {
        this.countDown--
        if (this.countDown <= 0) {
          window.clearInterval(timeId)
          this.codeDisabled = false
          this.countDown = 60
        }
      }, 1000)
      //获取验证码
      getAuthCode(data).then(res => {
        console.log(res)
        if (res.result == 0) {
          this.sessionId = res.sessionId
        }
      })
    },
    //长期状态改变时
    effectiveDataTypeChange(val) {
      //勾选长期状态时,证件截止日期置空
      if (val) {
        this.userInfo.certiexpiredate = ''
        // this.isRequired = false
        // this.idLimit = true
        this.certiexpiredateRequired = false
      } else {
        this.certiexpiredateRequired = true
        // this.isRequired = true
        // this.idLimit = false
      }
    },
    //获取身份证扫描信息
    getIdentityInfo(data) {
      getIdentityInfo(this, data, '2')
    },
    //时间戳格式处理
    timeStampFormat(timeStamp) {
      let date = new Date(timeStamp)
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      month = month.toString().padStart(2, '0')
      let day = Number(date.getDate()) + 1
      day = day.toString().padStart(2, '0')
      return `${year}-${month}-${day}`
    },
    //地区选择
    areaChoose(index) {
      if (this.isReadonly) {
        return
      }
      switch (index) {
        // case '1': //户籍
        //   this.censusShow = true
        //   break
        case '2': //联系地址
          this.homeShow = true
          break
        case '3': //单位地址
          this.areaShow = true
          break
        default:
          break
      }
    },
    //校验身高
    checkStature(val) {
      if (val == null || !val) return
      if (val.trim().length === 0) {
        return this.$toast('身高不能为空')
      }

      let res = /^[0-9]{0,3}([.]{1}[0-9]{1})?$/.test(val) && val < 300 && val > 10
      if (!res) {
        this.userInfo.stature = ''
        return this.$toast('身高输入有误')
      }
    },
    //校验体重
    checkAvoirdupois(val) {
      if (val == null || !val) return
      if (val && val.trim().length === 0) {
        return this.$toast('体重不能为空')
      }

      let res = /^[0-9]+([.]{1}[0-9]{1})?$/.test(val) && val > 0.1
      if (!res) {
        this.userInfo.avoirdupois = ''
        return this.$toast('体重输入有误')
      }
    },
    getRelatedData(val, from) {
      // debugger
      if (this.userInfo.idType != '1' && this.userInfo.idType != '2') {
        return
      }
      // if (!['1', '2', '3', 1, 2, 3].includes(this.userInfo.idType)) {
      //   return
      // }
      //如果证件校验不通过,恢复默认值
      if (idToData(val).text) {
        if (this.userInfo.idType == '2') {
          ;[this.userInfo.idNo, this.userInfo.sex, this.userInfo.birthday, this.effectiveDateTypeAble] = ['', '0', '', true]
        } else {
          ;[this.userInfo.idNo, this.userInfo.sex, this.userInfo.birthday, this.effectiveDateTypeAble] = ['', '0', '', false]
        }
        return this.$toast(idToData(val).text)
      }
      if (this.userInfo.idType == '2' && idToData(this.userInfo.idNo).age >= 16) {
        this.idLimit = false //截止日期是否可编辑--被保人
        return this.$toast('客户年龄在16周岁以上，不能使用户口本作为有效证件')
      } else if (this.userInfo.idType == '2' && idToData(this.userInfo.idNo).age < 16) {
        this.idLimit = true //截止日期是否可编辑--被保人
      } else {
        this.idLimit = false
      }
      this.userInfo.effectiveDateType = false
      this.effectiveDateTypeAble = idToData(val).age <= 45
      this.userInfo.birthday = idToData(val).birthday
      // 获取出生日期年份＋16
      if (this.userInfo.idType == '2' && idToData(this.userInfo.idNo).age < 16) {
        this.userInfo.certiexpiredate = countCredentialValidity.getEndDate2(this.userInfo.birthday, this.userInfo.certificateValidate)
        // let year = Number(this.userInfo.birthday.substr(0,4)) + 16
        // if(this.userInfo.birthday.substr(5,5) == '02-29'){
        //   // 获取某年某月一共多少天
        //   let date = new Date(year, 2, 1)
        //   let dayEnd = new Date(date.getTime() - 864e5).getDate()
        //   this.userInfo.certiexpiredate = year+'-02-'+ dayEnd
        // }else{
        //   this.userInfo.certiexpiredate =  year+'-'+ this.userInfo.birthday.substr(5,5)
        // }
      }
      this.userInfo.sex = idToData(val).sex
      //年龄小于18周岁，工作单位默认值为‘无’
      if (idToData(val).age < 18) {
        this.userInfo.workcompany = this.userInfo.workcompany || '无'
        this.userInfo.marriageStatus = this.branchType == '14' ? '未婚' : this.userInfo.marriageStatus
        this.userInfo.marriage = this.branchType == '14' ? 2 : this.userInfo.marriage
      } else {
        this.userInfo.marriageStatus = this.branchType == '14' ? '' : this.userInfo.marriageStatus
        this.userInfo.marriage = this.branchType == '14' ? null : this.userInfo.marriage
      }
      if (!from) {
        if (idToData(val).age < 16) {
          this.userInfo.salarySource = this.branchType == '14' ? null : 4
          this.userInfo.otherSalarySource = '无'
          this.userInfo.averageAnnualIncome = '0'
          this.userInfo.liabilitiesMoney = this.branchType == '14' ? '' : '0'
        } else {
          this.userInfo.salarySource = ''
          this.userInfo.averageAnnualIncome = ''
          this.userInfo.liabilitiesMoney = ''
        }
      }
      if (idToData(val).age > 45) {
        if (from) {
          this.userInfo.effectiveDateType = true
        }
        this.effectiveDateTypeAble = false
      }
      //如果选择户口本
      if (this.userInfo.idType == '2') {
        let exipreDate = Date.parse(this.userInfo.birthday) + Date.parse('1985-12-31')
        this.userInfo.certificateValidate = this.userInfo.birthday
        // this.userInfo.certiexpiredate = this.timeStampFormat(exipreDate)
        this.userInfo.certiexpiredate = countCredentialValidity.getEndDate2(this.userInfo.birthday, this.userInfo.certificateValidate)
        this.idLimit = true
        //如果选择出生证明
      }
      // else if (this.userInfo.idType == '3') {
      //   let exipreDate = Date.parse(this.userInfo.birthday) + Date.parse('1972-12-31')
      //   this.userInfo.certificateValidate = this.userInfo.birthday
      //   this.userInfo.certiexpiredate = this.timeStampFormat(exipreDate)
      //   this.idLimit = true
      // } else {
      //   this.idLimit = false
      // }
    }
  },
  computed: {
    isReadonly() {
      return this.isAppnt && this.source !== 'trial'
    },
    isShowOthenSalarySource() {
      if (this.userInfo.salarySource == '4') {
        return true
      } else {
        this.userInfo.otherSalarySource = ''
        return false
      }
    }
  },
  beforeDestroy() {
    //清理计时器
    window.clearInterval(this.timeId)
    this.timeId = null
    this.countDown = 60
    this.codeDisabled = false
  },
  watch: {
    userInfo: {
      deep: true,
      async handler() {
        await this.$nextTick()
        if (this.timer) {
          console.log(`clear timer`)
          clearTimeout(this.timer)
        }
        this.timer = setTimeout(async () => {
          if (await this.$validator.validate()) {
            console.log(`form input success`)
            this.nextStep({ passValidate: true })
          } else console.log(`validate error`)
        }, 1000)
      }
    },
    async 'withRootUser.value'(n) {
      const orderNo = this.$route.query.orderNo
      if (n && orderNo) {
        const rs = await getOrderDetail({ orderNo: orderNo })
        this.homeName = getAreaName([
          { code: rs.orderDTO.appntDTO.homeProvince },
          { code: rs.orderDTO.appntDTO.homeCity },
          { code: rs.orderDTO.appntDTO.homeArea }
        ])
        this.userInfo.homeProvince = rs.orderDTO.appntDTO.homeProvince
        this.userInfo.homeCity = rs.orderDTO.appntDTO.homeCity
        this.userInfo.homeArea = rs.orderDTO.appntDTO.homeArea
        this.userInfo.homeAddress = rs.orderDTO.appntDTO.homeAddress
      } else {
        this.homeName = this.userInfo.homeAddress = ''
      }
    },
    'userInfo.marriageStatus'(nv) {
      for (let status of DataDictionary.marriage) {
        if (status.text === nv) {
          this.userInfo.marriage = status.id
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.insured-person-container {
  .title {
    font-weight: 600;
    border-bottom: 1px solid #ebedf0;
  }

  /deep/ .van-checkbox {
    margin-left: auto;
  }

  .address {
    display: flex;
    flex-direction: row-reverse;
  }

  .isNewPeopleFlagTipClass {
    margin-top: 45px;
    line-height: 24px;
    text-indent: 2em;
    letter-spacing: 1px;
    padding: 2px 10px;
  }
}
</style>
