<template>
  <div>
    <NavHeader color="#0687D2" title="人才码申请" @back="$router.go(-1)" />
    <van-form class="form" @submit="onSubmit" ref="talentsForm">
      <div class="section">
        <van-field v-model="form.name" label="姓名" required :readonly="readonly" :disabled="disabled" placeholder="请填写姓名"
          :rules="[{ required: true, message: '请填写姓名' }]" />
        <van-field v-model="form.idCard" :label="form.passport === 0 ? '身份证' : '护照'" required :readonly="readonly"
          :disabled="disabled" placeholder="请填写身份证号" :rules="[{ required: true, message: '请填写身份证号' }]" />
        <van-field :disabled="disabled" label="性别" required :rules="[
          { required: true, message: '请选择性别', trigger: 'onChange' },
        ]">
          <template #input>
            <van-radio-group :disabled="disabled" v-model="form.sex" direction="horizontal">
              <van-radio :name="0">男</van-radio>
              <van-radio :name="1">女</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field v-if="form.passport === 1" v-model="form.birthPlace" label="出生地" required :disabled="disabled"
          :class="[disabled ? 'test' : '']" placeholder="详细地址必须包含：国家，城市"
          :rules="[{ required: true, message: '请填写出生地' }]" />
        <van-field v-else v-model="form.birthPlace" label="出生地" required readonly clickable @click="areaPick = true"
          :class="[disabled ? 'test' : '']" :disabled="disabled" placeholder="请选择出生地" :rules="[
            { required: true, message: '请选择出生地', trigger: 'onChange' },
          ]" />
        <van-field v-if="form.passport === 0" v-model="form.nation" label="民族" required :disabled="disabled"
          placeholder="请填写民族" :rules="[{ required: true, message: '请填写民族' }]" />
        <van-field v-if="form.passport === 0" v-model="form.politicalFace" label="政治面貌" required readonly clickable
          :class="[disabled ? 'test' : '']" @click="pickerPoliticalFace = true" :disabled="disabled" placeholder="请填写政治面貌"
          :rules="[
            { required: true, message: '请填写政治面貌', trigger: 'onChange' },
          ]" />
        <van-field v-if="this.form.passport == 0" v-model="form.birthDate" label="出生年月" required readonly class="test"
          :disabled="true" placeholder="请输入出生年月" />
        <van-field v-else v-model="form.birthDate" label="出生年月" required readonly clickable :disabled="false"
          placeholder="请输入出生年月" @click="openDatePicker('birthDate')" :rules="[
            { required: true, message: '请输入出生年月', trigger: 'onChange' },
          ]" />
        <van-field v-model="form.phone" label="手机号" type="number" required :disabled="disabled" placeholder="请输入手机号"
          :rules="[
            { required: true, message: '请输入手机号' },
            { pattern: phoneReg, message: '请输入正确内容' },
          ]" />
      </div>
      <div style="margin-top: 20px">
        <van-field :disabled="disabled" label="学历所在" required :rules="[
          { required: true, message: '请选择学历所在', trigger: 'onChange' },
        ]">
          <template #input>
            <van-radio-group :disabled="disabled" v-model="form.educationPassport" direction="horizontal">
              <van-radio :name="0">国内</van-radio>
              <van-radio :name="1">国外</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field v-model="form.highestEducation" label="最高学历" readonly required clickable
          @click="pickerEducation = true" :disabled="disabled" :class="[disabled ? 'test' : '']" placeholder="请填写最高学历"
          :rules="[
            { required: true, message: '请填写最高学历', trigger: 'onChange' },
          ]" />
        <van-field v-if="form.highestEducation !== '其他'" v-model="form.major" label="所学专业" required :disabled="disabled"
          placeholder="例：软件工程" :rules="[{ required: true, message: '请填写所学专业' }]" />
        <van-field v-model="form.graduateSchool" label="毕业院校" required :disabled="disabled" placeholder="例：江苏大学"
          :rules="[{ required: true, message: '请填写毕业院校' }]" />
        <!-- <van-field
          v-model="form.studyTime"
          label="入学时间"
          required
          readonly
          clickable
          :disabled="disabled"
          placeholder="请选择入学时间"
          @click="openDatePicker('studyTime')"
          :rules="[{ required: true, message: '请选择入学时间', trigger: 'onChange' }]"
        /> -->
        <van-field v-model="form.graduationTime" label="毕业时间" required readonly :class="[disabled ? 'test' : '']"
          clickable :disabled="disabled" placeholder="请选择毕业时间" @click="openDatePicker('graduationTime')" :rules="[
            { required: true, message: '请选择毕业时间', trigger: 'onChange' },
          ]" />
        <!-- <van-field
          v-if="
            form.highestEducation !== '大专' &&
            form.highestEducation !== '中专' &&
            form.highestEducation !== '其他'
          "
          v-model="form.highestDegree"
          label="最高学位"
          required
          :disabled="disabled"
          placeholder="请填写最高学位"
          :rules="[{ required: true, message: '请填写最高学位' }]"
        /> -->
        <!-- <van-field
          v-if="
            form.highestEducation !== '大专' &&
            form.highestEducation !== '中专' &&
            form.highestEducation !== '其他'
          "
          v-model="form.awardingUnit"
          label="授予单位"
          required
          :disabled="disabled"
          placeholder="请填写授予单位"
          :rules="[{ required: true, message: '请填写授予单位' }]"
        /> -->
        <!-- <van-field
          v-if="
            form.highestEducation !== '大专' &&
            form.highestEducation !== '中专' &&
            form.highestEducation !== '其他'
          "
          v-model="form.timeGrant"
          label="授予时间"
          required
          readonly
          clickable
          :disabled="disabled"
          placeholder="请选择授予时间"
          @click="openDatePicker('timeGrant')"
          :rules="[{ required: true, message: '请选择授予时间', trigger: 'onChange' }]"
        /> -->
        <!-- :rules="[{ required: true, message: '请填写职称' }]" -->
        <!-- 职称 -->
        <van-field v-model="form.title" readonly required clickable label="职称" :class="[disabled ? 'test' : '']"
          @click="titlePicker = true" :disabled="disabled" placeholder="请选择职称"
          :rules="[{ required: true, message: '请选择职称' }]" />
        <van-field v-if="form.title !== '无'" v-model="form.titleName" label="职称名称" required :disabled="disabled"
          placeholder="请填写职称名称" :rules="[{ required: true, message: '请填写职称名称' }]" />
      </div>
      <div style="margin-top: 20px">
        <!-- <van-field
          :disabled="disabled"
          label="在职状态"
          required
          :rules="[{ required: true, message: '请选择在职状态', trigger: 'onChange' }]"
        >
          <template #input>
            <van-radio-group
              :disabled="disabled"
              v-model="form.jobStatus"
              direction="horizontal"
            >
              <van-radio :name="0">离职</van-radio>
              <van-radio :name="1">在职</van-radio>
            </van-radio-group>
          </template>
        </van-field> -->
        <van-field v-model="form.socialPremiumLocation" label="工作或社保所在地" :required="
          (this.classType != 'AB' && this.genera == '企业全职人员') ||
          this.genera == '事业单位专技人员（不包含管理岗）'
        " readonly clickable :disabled="disabled" :class="[disabled ? 'test' : '']" placeholder="请选择工作或社保所在地"
          @click="openWorkerPicker('graduationTime')" :rules="[
            {
              required:
                (this.classType != 'AB' && this.genera == '企业全职人员') ||
                this.genera == '事业单位专技人员（不包含管理岗）',
              message: '请选择工作所在地',
              trigger: 'onChange',
            },
          ]" />
        <van-field v-model="form.unitName" label="工作单位名称" required :disabled="disabled" placeholder="请填写单位名称"
          :rules="[{ required: true, message: '请填写单位名称' }]" />
        <van-field v-model="form.socialUnit" label="社保缴纳单位" :disabled="disabled" :required="
          (this.classType != 'AB' && this.genera == '企业全职人员') ||
          this.genera == '事业单位专技人员（不包含管理岗）'
        " placeholder="请填写单位名称" :rules="[
  {
    required:
      (this.classType != 'AB' && this.genera == '企业全职人员') ||
      this.genera == '事业单位专技人员（不包含管理岗）',
    message: '请填写单位名称',
  },
]" />
        <van-field :disabled="disabled" label="单位类别" style="margin-top:10px" required :rules="[
          { required: true, message: '请选择单位类别', trigger: 'onChange' },
        ]" v-if="this.genera == '企业全职人员' && this.classType != 'AB'">
          <template #input>
            <van-radio-group :disabled="disabled" v-model="form.unitType" direction="horizontal">
              <van-radio name="1">企业</van-radio>
              <van-radio name="3" style="margin-top:15px" @click="changeRadio">劳务派遣</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field :disabled="disabled" label="单位类别" style="margin-top:10px" required :rules="[
          { required: true, message: '请选择单位类别', trigger: 'onChange' },
        ]" v-if="
  this.genera != '企业全职人员' &&
  this.classType != 'AB' &&
  this.genera != '海外设立研发中心等机构的全职引进人才'
">
          <template #input>
            <van-radio-group :disabled="disabled" v-model="form.unitType" direction="horizontal">
              <van-radio name="2" @click="changeRadio">事业单位(专技人员)</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field :disabled="disabled" label="单位类别" style="margin-top:10px" required :rules="[
          { required: true, message: '请选择单位类别', trigger: 'onChange' },
        ]" v-if="
  this.classType == 'AB' ||
  this.genera == '海外设立研发中心等机构的全职引进人才'
">
          <template #input>
            <van-radio-group :disabled="disabled" v-model="form.unitType" direction="horizontal">
              <van-radio name="1">企业</van-radio>
              <van-radio name="2" @click="changeRadio">事业单位(专技人员)</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field v-model="form.socialCredit" label="单位统一社会信用代码" required :disabled="disabled"
          placeholder="请填写单位统一社会信用代码" :rules="[{ required: true, message: '请填写单位统一社会信用代码' }]" />
        <van-field v-model="form.post" label="职务/岗位" required :disabled="disabled" placeholder="例：软件开发工程师"
          :rules="[{ required: true, message: '请填写职务/岗位' }]" />
        <van-field v-model="form.contactPerson" label="单位联系人" required :disabled="disabled" placeholder="请填写单位联系人"
          :rules="[{ required: true, message: '请填写单位联系人' }]" />
        <van-field v-model="form.contactNumber" label="单位联系电话" required :disabled="disabled" placeholder="请填写单位联系电话"
          :rules="[{ required: true, message: '请填写单位联系电话' }]" />
      </div>
      <div style="margin-top: 20px">
        <van-field v-model="form.reportType" label="申请认定类型" readonly required :disabled="disabled"
          :rules="[{ required: true, message: '请选择申请认定类型' }]" />
        <van-field v-model="form.reportContent" label="申请认定内容" autosize type="textarea" readonly required
          :disabled="disabled" :rules="[{ required: true, message: '请选择申请认定内容' }]" />
        <van-field v-model="form.country" label="申报人所属" readonly required :disabled="disabled"
          :rules="[{ required: true, message: '请选择申请认定类型' }]" />
        <van-field v-if="form.socialSecurity" v-model="form.socialSecurity" label="申报人分类" autosize type="textarea"
          readonly required :disabled="disabled" :rules="[{ required: true, message: '请选择申请申报人分类' }]" />
      </div>
      <!-- <div class="down-template">下载承诺函模板</div> -->
      <div style="margin-top: 20px">
        <van-field :disabled="disabled" label="上传个人承诺函" required :class="[disabled ? 'test' : '']">
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.promise" max-count="1" />
          </template>
          <template #button>
            <span @click="
              download(
                'https://www.smart-zj.cn:55901/image/gerenchengnuohan',
                'https://www.smart-zj.cn:55901/image/gerenchengnuohan.docx',
                '承诺函模板'
              )
            " class="down-text">下载承诺函模板</span>
          </template>
        </van-field>
        <van-field :disabled="disabled" label="上传个人照片" required :class="[disabled ? 'test' : '']">
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.headPortrait" max-count="1" />
          </template>
        </van-field>
        <van-field v-if="form.unitType == 2" :disabled="disabled" label="上传工资变动审批表" required>
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.payroll" max-count="1" />
          </template>
          <template #button>
            <span @click="
              download(
                'https://www.smart-zj.cn:55901/image/事业工资变动审批表',
                'https://www.smart-zj.cn:55901/image/gongzibiandongshenpibiaoIos.doc',
                '工资变动审批表模板'
              )
            " class="down-text">下载工资变动审批表模板</span>
          </template>
        </van-field>
        <van-field v-if="form.unitType == 3" :disabled="disabled" label="上传劳务派遣合同个人签字和盖章页" required>
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.payroll" max-count="1" />
          </template>
        </van-field>
        <!--        <van-field-->
        <!--          v-if="form.unitType == 2"-->
        <!--          :disabled="disabled"-->
        <!--          label="上传职称证明"-->
        <!--          required-->
        <!--        >-->
        <!--          <template #input>-->
        <!--            <van-uploader-->
        <!--              :disabled="disabled"-->
        <!--              :deletable="!disabled"-->
        <!--              :after-read="afterRead"-->
        <!--              v-model="form.titleCertificate"-->
        <!--              max-count="1"-->
        <!--            />-->
        <!--          </template>-->
        <!--        </van-field>-->
      </div>
      <div style="margin-top: 20px">
        <p style="font-size: 14px; color: #eb4e3f; padding: 0 10px 10px">
          请上传 <b>{{ form.reportContent.replace(";", "") }}</b> 有关的证明材料
        </p>
        <div class="buttonCnntainer">
          <van-button native-type="button" icon="plus" size="small" type="info" :disabled="disabled"
            @click="addImageProof">图片佐证材料</van-button>
          <van-button native-type="button" icon="plus" size="small" type="primary" :disabled="disabled"
            style="margin-left: 20px" @click="addFileProof">文件佐证材料</van-button>
        </div>
        <div v-for="item in form.pictureList" :key="item.proofId">
          <template v-if="item.pictureType === 2">
            <van-field :disabled="disabled" label="佐证文件材料" required>
              <template #input>
                <van-uploader :disabled="disabled" :deletable="!disabled" accept=".doc,.docx,.pdf" :after-read="afterRead"
                  :max-size="10 * 1024 * 1024" @oversize="onOversize" v-model="item.picture" max-count="1" />
              </template>
              <template #button>
                <van-button :disabled="disabled" size="small" type="danger"
                  @click="delProof(item.proofId)">删除</van-button>
              </template>
            </van-field>
            <van-field :disabled="disabled" v-model="item.fileName" label="文件名称" placeholder="请填写文件名称(选填)" />
            <van-field :disabled="disabled" v-model="item.documentNumber" label="文号" placeholder="请填写文号(选填)" />
            <van-field :disabled="disabled" v-model="item.issuingOrganization" label="发文机构" placeholder="请填写发文机构(选填)" />
          </template>
          <template v-if="item.pictureType === 1">
            <van-field :disabled="disabled" label="佐证图片材料" required :class="[disabled ? 'test' : '']">
              <template #input>
                <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead"
                  :max-size="10 * 1024 * 1024" @oversize="onOversize" v-model="item.picture" max-count="1" />
              </template>
              <template #button>
                <van-button :disabled="disabled" size="small" type="danger"
                  @click="delProof(item.proofId)">删除</van-button>
              </template>
            </van-field>
          </template>
        </div>
      </div>
      <div style="margin-top: 20px">
        <van-field :disabled="disabled" label="学信网学历证明(选填)">
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.education" max-count="1" />
          </template>
        </van-field>
        <van-field :disabled="disabled" label="学信网学籍证明(选填)">
          <template #input>
            <van-uploader :disabled="disabled" :deletable="!disabled" :after-read="afterRead" :max-size="10 * 1024 * 1024"
              @oversize="onOversize" v-model="form.studentStatus" max-count="1" />
          </template>
        </van-field>
      </div>
      <!-- 工作所在地 -->
      <van-popup v-model="showWorkerAddress" position="bottom">
        <van-picker show-toolbar :columns="workerColumns" @cancel="showWorkerAddress = false" @confirm="workerConfirm" />
      </van-popup>
      <van-popup v-model="showDatePicker" position="bottom">
        <van-datetime-picker v-model="currentDate" type="date" :min-date="minDate" :max-date="maxDate"
          @confirm="onConfirm" @cancel="onCancel" />
      </van-popup>
      <!-- 职称 -->
      <van-popup v-model="titlePicker" round position="bottom">
        <van-picker show-toolbar :columns="titleColumns" @cancel="titlePicker = false" @confirm="titleConfirm" />
      </van-popup>
      <van-popup v-model="areaPick" position="bottom">
        <van-area title="出生地" :area-list="areaList" @confirm="onConfirmArea" @cancel="areaPick = false" value="110101" />
      </van-popup>
      <van-popup v-model="pickerEducation" position="bottom">
        <van-picker title="学历" :columns="[
          '博士研究生',
          '硕士研究生',
          '本科',
          '大专',
          '中专',
          '其他',
        ]" @confirm="onConfirmEducation" show-toolbar @cancel="pickerEducation = false" />
      </van-popup>
      <van-popup v-model="pickerPoliticalFace" position="bottom">
        <van-picker title="政治面貌" :columns="['中共党员', '民主党派', '无党派人士', '共青团员', '群众']" @confirm="onConfirmPoliticalFace"
          show-toolbar @cancel="pickerPoliticalFace = false" />
      </van-popup>
    </van-form>
    <div v-if="state === -1">
      <van-button class="submit" color="#F5A623" @click="send('save')">保存</van-button>
      <van-button class="submit" color="#0687D2" @click="send('submit')">提交</van-button>
    </div>
    <div v-if="state === 0" class="foot">
      <div class="option" @click="delform">
        <img src="@/assets/common/delete_icon.png" alt="" />
        <p>删除</p>
      </div>
      <van-button class="submit" color="#F5A623" @click="send('save')">保存</van-button>
      <van-button class="submit" color="#0687D2" @click="send('submit')">提交</van-button>
    </div>
    <!-- <div class="footextra" v-if="state === 2">
      <van-button block type="warning" @click="revoke">撤销</van-button>
    </div> -->
    <div class="footextra" v-if="state === 2 || state === 3 || state === 4">
      <van-button block disabled>{{
        state === 2 ? "正在公示中" : state === 3 ? "已发码" : "公示暂停中"
      }}无法修改</van-button>
    </div>
    <div class="foot" v-if="state === 5 || state === 6 || state === 8">
      <div class="option" @click="delform">
        <img src="@/assets/common/delete_icon.png" alt="" />
        <p>删除</p>
      </div>
      <van-button block color="#0687D2" @click="resubmit">重新提交</van-button>
    </div>
  </div>
</template>

<script>
import NavHeader from "@/components/NavHeader";
import Vue from "vue";
import {
  Area,
  Form,
  Field,
  Button,
  Popup,
  Picker,
  Uploader,
  RadioGroup,
  Radio,
  DatetimePicker,
} from "vant";
// import { uploadFile, add, get, update, del, updateState } from "@/api/talents";
import { uploadFile, add, get, update, del } from "@/api/talents";
import { phoneReg, idcardReg } from "@/utils/constant";
import { getDate, decryptByDES, encryptByDES } from "@/utils/utils";
import areaList from "@/utils/area";

Vue.use(Form)
  .use(Field)
  .use(Popup)
  .use(Picker)
  .use(Button)
  .use(Uploader)
  .use(RadioGroup)
  .use(Radio)
  .use(DatetimePicker)
  .use(Area);

let proofId = 1;

export default {
  components: { NavHeader },
  computed: {
    disabled() {
      return (
        this.state === 1 ||
        this.state === 2 ||
        this.state === 3 ||
        this.state === 4
      );
    },
  },
  data() {
    return {
      talentCode: "",
      state: -1, // 默认是从未保存提交过
      phoneReg,
      idcardReg,
      showDatePicker: false,
      showWorkerAddress: false,
      minDate: new Date(1870, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(),
      formKey: "",
      type: "",
      readonly: true,
      form: {
        userId: "",
        passport: 0, // 0:国内 1: 国外
        name: "", // 姓名
        idCard: "", // 身份证号
        sex: "", // 性别
        birthPlace: "", // 出生地
        nation: "", // 民族
        politicalFace: "", // 政治面貌
        birthDate: "", // 出生年月
        phone: "", // 手机号
        educationPassport: "", // 学历所在
        highestEducation: "", // 最高学历
        major: "", // 所学专业
        graduateSchool: "", // 毕业院校
        graduationTime: "", // 毕业时间
        highestDegree: "", // 最高学位
        studyTime: "", // 入学时间
        awardingUnit: "", // 授予单位
        timeGrant: "", // 授予时间
        title: "", // 职称
        titleName: "", // 职称名称
        // jobStatus: "", // 在职状态
        unitName: "", // 单位名称
        socialUnit: "", // 社保缴纳单位名称
        unitType: "", // 单位类别
        socialCredit: "", // 单位统一社会信用代码
        socialSecurity: "", // 是否在镇江缴纳社保
        post: "", // 职务/岗位
        contactPerson: "", // 单位联系人
        contactNumber: "", // 单位联系电话
        reportType: "", // 申请认定类型
        reportContent: "", // 申请认定内容
        contentCode: "", // 申请认定内容code
        country: "", // 申报人所属
        promise: [], // 个人承诺函
        headPortrait: [], // 个人照片
        // titleCertificate: [], // 职称证明(图片)
        payroll: [], //
        education: [], // 学信网学历证明
        studentStatus: [], // 学信网学籍证明
        pictureList: [], // 佐证材料
        socialPremiumLocation: "",
      },
      areaPick: false, // 地区选择器
      areaList,
      pickerEducation: false,
      pickerPoliticalFace: false,
      showPicker: false,
      titlePicker: false,
      titleColumns: ["无", "初级", "中级", "高级"],
      workerColumns: ["镇江市区", "丹阳市", "句容市", "扬中市"],
      // titleDisplay: false, // 职称名称是否显示
      genera: "",
      classType: "",
      userInfo: {},
    };
  },
  methods: {
    onOversize(file) {
      console.log(file);
      this.$toast("文件大小不能超过 10MB");
    },
    init() {
      console.log(this.userInfo,"user------");
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "查询中...",
      });
      console.log(this.userId);
      let params = {
        appId: 1234,
        talentCode: this.talentCode,
        userId: this.userId,
        idCard: this.userInfo.idCardNo
          ? decryptByDES(this.userInfo.idCardNo, "MnuYbhGv")
          : null,
      };

      get(params).then((res) => {
        console.log("身份证信息res----", res);
        console.log("res.idCard---", res.idCard);
        // alert(JSON.stringify(res))
        // if (res.passport == 0) {
        //   let birthDate =
        //     res.idCard.substr(6, 4) +
        //     "-" +
        //     res.idCard.substr(10, 2) +
        //     "-" +
        //     res.idCard.substr(12, 2);
        //   res.birthDate = birthDate;
        // }
        this.$toast.clear();
        this.state = res.state;
        this.form = {
          userId: res.userId,
          passport: res.passport,
          name: res.name,
          // idCard: decryptByDES(res.idCard,"MnuYbhGvF"),
          idCard: res.idCard,
          sex: res.sex,
          birthPlace: res.birthPlace,
          nation: res.nation,
          politicalFace: res.politicalFace,
          birthDate: res.birthDate,
          phone: res.phone,
          educationPassport: res.educationPassport,
          highestEducation: res.highestEducation,
          major: res.major,
          graduateSchool: res.graduateSchool,
          graduationTime: res.graduationTime,
          highestDegree: res.highestDegree,
          studyTime: res.studyTime,
          awardingUnit: res.awardingUnit,
          timeGrant: res.timeGrant,
          title: res.title,
          socialPremiumLocation: res.socialPremiumLocation,
          titleName: res.titleName,
          // jobStatus: res.jobStatus,
          unitName: res.unitName,
          socialUnit: res.socialUnit,
          unitType: res.unitType,
          socialCredit: res.socialCredit,
          socialSecurity: res.socialSecurity,
          post: res.post,
          contactPerson: res.contactPerson,
          contactNumber: res.contactNumber,
          reportType: res.category,
          reportContent: res.contentName,
          contentCode: res.contentCode,
          country: res.passport === 0 ? "国内" : "港澳台及国外",
          promise: [{ url: res.promise }],
          headPortrait: [{ url: res.headPortrait }],
          // titleCertificate: res.titleCertificate ? [{ url: res.titleCertificate }] : [],
          payroll: res.payroll ? [{ url: res.payroll }] : [],
          education: res.education ? [{ url: res.education }] : [],
          studentStatus: res.studentStatus ? [{ url: res.studentStatus }] : [],
          pictureList: res.pictureList.map((item) => {
            let a = [];
            a.push({ url: item.picture });
            item.picture = a;
            item.proofId = proofId++;
            return item;
          }),
        };
      });
    },
    // 职称
    titleConfirm(value) {
      // console.log("value---", value);
      // if (value == "无") {
      //   this.titleDisplay = false;
      // } else {
      //   this.titleDisplay = true;
      // }
      this.titlePicker = false;
      this.form.title = value;
      this.pickerPoliticalFace = false;
    },
    workerConfirm(value) {
      this.showWorkerAddress = false;
      this.form.socialPremiumLocation = value;
    },
    onSubmit() {
      const { form, type } = this;
      console.log(type);
      console.log(1);
      let parmas = JSON.parse(JSON.stringify(form));
      delete parmas.reportContent;
      delete parmas.reportType;
      delete parmas.country;
      console.log(1);
      if (form.passport === 1) {
        // 国外需要删除民族、政治面貌
        delete parmas.nation;
        delete parmas.politicalFace;
      }
      // if(this.titleDisplay == false) {
      //   delete parmas.titleName
      // }
      if (form.highestEducation === "其他") {
        // 最高学历为其他需要删除所学专业
        delete parmas.major;
      }
      if (
        form.highestEducation === "大专" ||
        form.highestEducation === "中专" ||
        form.highestEducation === "其他"
      ) {
        // 最高学历为大专或者中专或者其他需要删除最高学位、授予单位、授予时间
        delete parmas.highestDegree;
        delete parmas.awardingUnit;
        delete parmas.timeGrant;
      }
      if (form.unitType === "1") {
        // 单位类别为企业需要删除工资变动审批表、职称证明
        // delete parmas.titleCertificate;
        delete parmas.payroll;
      }
      // 个人承诺函
      if (parmas.promise.length > 0 && parmas.promise[0].url !== "") {
        parmas.promise = parmas.promise[0].url;
      } else {
        this.$toast("请上传个人承诺函");
        return;
      }
      // 个人照片
      console.log("parmas.headPortrait-----", parmas.headPortrait);
      if (parmas.headPortrait.length > 0 && parmas.headPortrait[0].url !== "") {
        parmas.headPortrait = parmas.headPortrait[0].url;
      } else {
        this.$toast("请上传个人照片");
        return;
      }

      // 企业类别为事业单位才校验必填
      if (form.unitType === "2") {
        // 职称证明照片
        // if (parmas.titleCertificate.length > 0) {
        //   parmas.titleCertificate = parmas.titleCertificate[0].url;
        // } else {
        //   this.$toast("请上传职称证明照片");
        //   return;
        // }

        // 工资变动审批表
        if (
          parmas.payroll.length > 0 &&
          parmas.payroll[0].url !== "" &&
          parmas.unitType == "2"
        ) {
          parmas.payroll = parmas.payroll[0].url;
        } else {
          this.$toast("请上传工资变动审批表");
          return;
        }
      }

      // 企业类别为事业单位才校验必填
      if (form.unitType === "3") {
        console.log("paramas---", parmas);
        // 工资变动审批表
        if (
          parmas.payroll.length > 0 &&
          parmas.payroll[0].url !== "" &&
          parmas.unitType == "3"
        ) {
          parmas.payroll = parmas.payroll[0].url;
        } else {
          this.$toast("请上传劳务派遣合同个人签字和盖章页");
          return;
        }
      }

      // 佐证材料
      let flag = true;
      if (parmas.pictureList.length > 0) {
        if (parmas.pictureList[0].picture.length > 0) {
          let picArr = parmas.pictureList.filter((item) => {
            if (item.picture.length > 0 && item.picture[0].url) {
              return item
            }
          })
          parmas.pictureList = picArr.map((item) => {
            if (item.pictureType === 1) {
              return {
                picture: item.picture[0].url,
                pictureType: 1,
              };
            } else {
              return {
                picture: item.picture[0].url,
                pictureType: 2,
                documentNumber: item.documentNumber,
                fileName: item.fileName,
                issuingOrganization: item.issuingOrganization,
              };
            }
          })
        } else {
          flag = false;
          parmas.pictureList = [];
          this.$toast("请上传佐证材料");
          return
        }
      } else {
        if (
          this.form.reportContent != "年薪50万以上" &&
          this.form.reportContent != "年薪30万以上"
        ) {
          this.$toast("请上传至少一个佐证材料");
          return;
        }
      }
      if (!flag) {
        this.$toast("请上传完整的佐证材料");
        return;
      }
      // 学信网学历证明 学信网学籍证明
      if (parmas.education.length > 0) {
        parmas.education = parmas.education[0].url;
      } else {
        parmas.education = "";
      }
      if (parmas.studentStatus.length > 0) {
        parmas.studentStatus = parmas.studentStatus[0].url;
      } else {
        parmas.studentStatus = "";
      }
      // 处理国内国外的数据 如果是国内
      parmas.appId = 1234;
      parmas.state = type === "save" ? 0 : 1;
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "加载中...",
      });
      console.log("this.talentCode----", this.talentCode);
      if (this.talentCode) {
        console.log(333);
        console.log("提交");
        parmas.talentCode = this.talentCode;
        update(parmas).then((res) => {
          console.log(444);
          this.$toast.clear();
          console.log(res);
          if (type === "save") this.$toast("保存成功");
          else this.$toast("提交成功");
          setTimeout(() => {
            this.$router.go(-1);
          }, 500);
        });
      } else {
        console.log("保存");
        add(parmas).then((res) => {
          console.log(111);
          this.$toast.clear();
          console.log(res);
          if (type === "save") this.$toast("保存成功");
          else this.$toast("提交成功");
          setTimeout(() => {
            let category = this.$store.state.talents.category;
            if (
              category !== "国内外顶尖人才(A)" &&
              category !== "国家级领军人才(B)"
            )
              this.$router.go(-3);
            else this.$router.go(-2);
            console.log(222);
          }, 500);
        });
      }
    },
    send(type) {
      this.type = type;
      if (type === "save") {
        const { form, type } = this;
        console.log("form---", form);
        let parmas = JSON.parse(JSON.stringify(form));
        // parmas.idCard = encryptByDES(form.idCard,"MnuYbhGv")
        delete parmas.reportContent;
        delete parmas.reportType;
        delete parmas.country;
        if (form.passport === 1) {
          // 国外需要删除民族、政治面貌
          delete parmas.nation;
          delete parmas.politicalFace;
        }
        // if(this.titleDisplay == false) {
        //   delete parmas.titleName
        // }
        if (form.highestEducation === "其他") {
          // 最高学历为其他需要删除所学专业
          delete parmas.major;
        }
        if (
          form.highestEducation === "大专" ||
          form.highestEducation === "中专" ||
          form.highestEducation === "其他"
        ) {
          // 最高学历为大专或者中专或者其他需要删除最高学位、授予单位、授予时间
          delete parmas.highestDegree;
          delete parmas.awardingUnit;
          delete parmas.timeGrant;
        }
        if (form.unitType !== "2") {
          // 单位类别为企业需要删除工资变动审批表、职称证明
          // delete parmas.titleCertificate;
          delete parmas.payroll;
        }
        // 个人承诺函
        if (parmas.promise.length > 0 && parmas.promise[0].url !== "") {
          parmas.promise = parmas.promise[0].url;
        } else {
          parmas.promise = "";
        }
        // 个人照片
        if (
          parmas.headPortrait.length > 0 &&
          parmas.headPortrait[0].url !== ""
        ) {
          parmas.headPortrait = parmas.headPortrait[0].url;
        } else {
          parmas.headPortrait = "";
        }
        // 企业类别为事业单位才校验必填
        if (form.unitType == "2") {
          // 职称证明照片
          // if (parmas.titleCertificate.length > 0) {
          //   parmas.titleCertificate = parmas.titleCertificate[0].url;
          // } else {
          //   this.$toast("请上传职称证明照片");
          //   return;
          // }
          // 工资变动审批表
          if (parmas.payroll.length > 0 && parmas.payroll[0].url !== "") {
            parmas.payroll = parmas.payroll[0].url;
          } else {
            parmas.payroll = "";
          }
        }
        // 佐证材料
        if (parmas.pictureList.length > 0) {
          if (parmas.pictureList[0].picture.length > 0) {
            let picArr = parmas.pictureList.filter((item) => {
              if (item.picture.length > 0 && item.picture[0].url) {
                return item
              }
            })
            parmas.pictureList = picArr.map((item) => {
              if (item.pictureType === 1) {
                return {
                  picture: item.picture[0].url,
                  pictureType: 1,
                };
              } else {
                return {
                  picture: item.picture[0].url,
                  pictureType: 2,
                  documentNumber: item.documentNumber,
                  fileName: item.fileName,
                  issuingOrganization: item.issuingOrganization,
                };
              }
            })
          } else {
            parmas.pictureList = [];
            this.$toast("请上传佐证材料");
            return
          }
        } else {
          parmas.pictureList = [];
        }

        // 学信网学历证明 学信网学籍证明
        if (parmas.education.length > 0) {
          parmas.education = parmas.education[0].url;
        } else {
          parmas.education = "";
        }
        if (parmas.studentStatus.length > 0) {
          parmas.studentStatus = parmas.studentStatus[0].url;
        } else {
          parmas.studentStatus = "";
        }
        // 处理国内国外的数据 如果是国内
        parmas.appId = 1234;
        parmas.state = type === "save" ? 0 : 1;
        this.$toast.loading({
          duration: 0, // 持续展示 toast
          forbidClick: true,
          message: "加载中...",
        });
        if (this.talentCode) {
          parmas.talentCode = this.talentCode;
          update(parmas).then((res) => {
            this.$toast.clear();
            console.log(res);
            if (type === "save") this.$toast("保存成功");
            else this.$toast("提交成功");
            setTimeout(() => {
              this.$router.go(-1);
            }, 500);
          });
        } else {
          add(parmas).then((res) => {
            this.$toast.clear();
            console.log(res);
            if (type === "save") this.$toast("保存成功");
            else this.$toast("提交成功");
            setTimeout(() => {
              let category = this.$store.state.talents.category;
              if (
                category !== "国内外顶尖人才(A)" &&
                category !== "国家级领军人才(B)"
              )
                this.$router.go(-3);
              else this.$router.go(-2);
            }, 500);
          });
        }
      } else {
        this.$refs.talentsForm.submit();
      }
      // if(this.type == "save") {
      //   console.log(123);
      // }
      // console.log(1);
    },
    resubmit() {
      this.type = "submit";
      this.$refs.talentsForm.submit();
    },
    update() {
      this.$dialog
        .confirm({
          message: "更新信息的话，将重新审核公示，您确定继续吗？",
        })
        .then(() => {
          this.type = "submit";
          this.$refs.talentsForm.submit();
        })
        .catch(() => {
          console.log("取消");
        });
    },
    openDatePicker(formKey) {
      this.currentDate = new Date();
      this.formKey = formKey;
      this.showDatePicker = true;
    },
    openWorkerPicker() {
      this.showWorkerAddress = true;
    },
    onConfirm(date) {
      this.form[this.formKey] = getDate(date);
      this.showDatePicker = false;
    },
    onCancel() {
      this.formKey = "";
      this.showDatePicker = false;
    },
    afterRead(file) {
      file.status = "uploading";
      file.message = "上传中...";
      let param = new FormData();
      param.append("file", file.file);
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "上传图片中...",
      });
      uploadFile(param)
        .then((res) => {
          this.$toast.clear();
          file.status = "done";
          file.message = "上传成功";
          file.url = res;
        })
        .catch((err) => {
          console.log(err);
          file.status = "failed";
          file.message = "上传失败";
        });
    },
    addImageProof() {
      this.form.pictureList.push({
        proofId,
        pictureType: 1,
        picture: [],
      });
      proofId = proofId + 1;
    },
    addFileProof() {
      this.form.pictureList.push({
        proofId,
        pictureType: 2,
        picture: [],
        documentNumber: "", // 文号
        fileName: "", // 文件名称
        issuingOrganization: "", // 发文机构
      });
      proofId = proofId + 1;
    },
    delProof(id) {
      this.form.pictureList = this.form.pictureList.filter((item) => {
        return item.proofId !== id;
      });
    },
    delform() {
      this.$dialog
        .confirm({
          message: "是否确认删除该申请",
        })
        .then(() => {
          del({ appId: 1234, talentCode: this.talentCode }).then((res) => {
            console.log(res);
            this.$toast("删除成功");
            setTimeout(() => {
              this.$router.go(-1);
            }, 300);
          });
        })
        .catch(() => {
          console.log("取消");
        });
    },
    // revoke() {
    //   this.$dialog
    //     .confirm({
    //       message: "是否撤销本次申请？",
    //     })
    //     .then(() => {
    //       updateState({
    //         appId: 1234,
    //         talentCode: this.talentCode,
    //         state: 0,
    //       }).then((res) => {
    //         console.log(res);
    //         this.$toast("撤销成功");
    //         this.init();
    //       });
    //     })
    //     .catch(() => {
    //       console.log("取消");
    //     });
    // },
    onConfirmArea(value) {
      this.areaPick = false;
      if (!value[2]) {
        this.form.birthPlace = value[0].name + "/" + value[1].name;
        return;
      }
      this.form.birthPlace =
        value[0].name + "-" + value[1].name + "-" + value[2].name;
    },
    onConfirmEducation(value) {
      this.form.highestEducation = value;
      this.pickerEducation = false;
    },
    onConfirmPoliticalFace(value) {
      this.form.politicalFace = value;
      this.pickerPoliticalFace = false;
    },
    download(url, url1, fileName) {
      console.log("url--", url);
      if (this.$route.query.ticket) {
        if (navigator.userAgent.toLowerCase().includes("mac")) {
          console.log(111);
          this.$dialog
            .confirm({
              message: "请点击复制按钮，去浏览器粘贴该链接下载文件",
              confirmButtonText: "复制",
            })
            .then(() => {
              var input = document.createElement("input"); // js创建一个input输入框
              input.value = url1; // 将需要复制的文本赋值到创建的input输入框中
              document.body.appendChild(input); // 将输入框暂时创建到实例里面
              input.select(); // 选中输入框中的内容
              document.execCommand("Copy"); // 执行复制操作
              document.body.removeChild(input); // 最后删除实例中临时创建的input输入框，完成复制操作
              // resolve();
            });
        } else {
          const link = document.createElement("a");
          link.href = url1;
          link.target = "_blank";
          link.download = fileName;
          link.style.display = "none";
          document.body.append(link);
          link.click();
          link.remove();
        }
      } else {
        if (window.android !== undefined) {
          window.android.downLoadFile(url);
        } else if (window.webkit) {
          window.webkit &&
            window.webkit.messageHandlers.downLoadFile.postMessage(
              `${url1}|showNav`
            );
        } else {
          const link = document.createElement("a");
          link.href = url1;
          link.target = "_blank";
          link.download = fileName;
          link.style.display = "none";
          document.body.append(link);
          link.click();
          link.remove();
        }
      }
    },
    changeRadio() {
      console.log(1);
      console.log(this.form.payroll);
      this.form.payroll = [];
    },
  },
  mounted() { },
  created() {
    this.userId = encryptByDES(
      JSON.parse(sessionStorage.getItem("ZJCD-UserInfo")).userId,
      "MnuYbhGv"
    );
    this.genera = this.$route.query.genera;
    this.talentCode = this.$route.query.talentCode;
    this.classType = this.$route.query.type ? this.$route.query.type : "";
    // alert(JSON.stringify(this.$route.query))
    console.log(" this.talentCode---", this.talentCode);
    if (this.talentCode) {
      console.log(1);
      this.userInfo = JSON.parse(sessionStorage.getItem("ZJCD-UserInfo"));
      // 已经至少保存过一次信息
      this.init();
    } else {
      console.log(2);
      // 第一次申请
      let area = this.$store.state.talents.area;
      this.form.passport = area;
      let res = sessionStorage.getItem("ZJCD-UserInfo");
      let company = sessionStorage.getItem("ZJCD-Company");
      // alert(JSON.stringify(res))
      this.form.socialUnit = company;
      let userInfo = JSON.parse(res);
      console.log("userInfo---", userInfo);
      // alert(JSON.stringify(userInfo))
      if (area === 0) {
        // 国内人员
        this.form.name = userInfo.realName;
        console.log("身份证号---", userInfo.idCardNo);
        // let a = userInfo.idCardNo.substring(0, 4);
        // if (Number(a) + "" !== NaN + "") {
        //   this.form.idCard = userInfo.idCardNo;
        // } else {
        //   this.form.idCard = decryptByDES(
        //     userInfo.idCardNo,
        //     "MnuYbhGvF"
        //   );
        // }
        this.form.idCard = decryptByDES(userInfo.idCardNo, "MnuYbhGvF")
          ? decryptByDES(userInfo.idCardNo, "MnuYbhGvF")
          : userInfo.idCardNo;
        this.form.phone = userInfo.mobileNo;
        let birthDate =
          this.form.idCard.substr(6, 4) +
          "-" +
          this.form.idCard.substr(10, 2) +
          "-" +
          this.form.idCard.substr(12, 2);
        this.form.birthDate = birthDate;
      } else {
        console.log(4);
        // 外籍或港澳台
        this.form.name = this.$store.state.talents.name;
        this.form.idCard = this.$store.state.talents.passport;
        if (this.form.name && this.form.idCard) {
          console.log(5);
          this.readonly = true;
        } else {
          console.log(6);
          this.readonly = false;
        }
      }
      console.log(7);
      this.form.userId = userInfo.userId;
      this.form.socialSecurity = this.$store.state.talents.genera;
      this.form.reportType = this.$store.state.talents.category;
      this.form.reportContent = this.$store.state.talents.content.contentName;
      this.form.contentCode = this.$store.state.talents.content.contentCode;
      this.form.country = area === 0 ? "国内" : "港澳台及国外";
    }
  },
};
</script>

<style lang="stylus" scoped>

.form {
  height: calc(100vh - 250px);
  overflow-y: auto;

  .buttonCnntainer {
    padding: 30px 20px;
    display: flex;
    align-items: center;
    background: #fff;
  }
}

.down-template {
  margin: 20px 10px 3px;
  font-size: 32px;
  text-decoration: line;
}

.submit {
  width: 50%;
  height: 90px;
  font-size: 36px;
  font-weight: 500;
  color: #FFFFFF;
}

.foot {
  display: flex;

  .option {
    width: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;

    img {
      width: 30px;
      height: 30px;
    }

    p {
      margin-top: 10px;
      font-size: 22px;
      color: #333;
    }
  }
}

.down-text {
  font-size: 20px;
  color: #6077e8;
}

.footextra {
  height: 90px;
  font-size: 36px;
  font-weight: 500;
  color: #FFFFFF;
}
</style>
<style lang="stylus">
.short-placeholder {
  input.van-field__control::placeholder {
    font-size: 16px;
  }
}

.test {
  pointer-events: none;
}
</style>
