<template>
  <div style="padding: 10px">
    <el-form v-loading="listLoading" ref="form" :rules="rules" :model="form" label-width="210px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="照片" prop="userImg" >
            <el-upload
              ref="photoUpload"
              :file-list="form.userImg"
              :multiple="false"
              :limit="1"
              :class="{hide:hideUpload}"
              :auto-upload="false"
              :before-remove="handlePhotoBeforeRemove"
              :on-remove="handleRemove"
              :on-change="handleChangeIMG"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card">
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="姓名" prop="NAME" class="input-width">
            <el-input :span="5" v-model="form.NAME" placeholder="这里输入姓名..."/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用户名" prop="USERNAME" class="input-width">
            <el-input v-model="form.USERNAME" :disabled="dialog_type == 'editPerson'" placeholder="这里输入用户名..." />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="PHONE" style="display:none">
            <el-input v-model="form.PHONE" disabled placeholder="这里输入联系电话..."/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门" prop="DEPARTMENT_ID" label-width="">
            <SelectTree
              ref="deptTree"
              :clearable="false"
              :options="treeData"
              :props="defaultProps"
              v-model="form.DEPARTMENT_ID"
              placeholder="请选择部门"
              style="width: 290px"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="身份证号" prop="CARD_ID" class="input-width">
            <el-input v-model="form.CARD_ID" placeholder="这里输入身份证号..."/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="身份证照片" class="input-width" prop="userCardFile" >
            <el-upload
              ref="userCardUpload"
              :file-list="form.userCardFile"
              :multiple="false"
              :limit="2"
              :class="{hide:userCardIDUpload}"
              :auto-upload="false"
              :before-remove="handlePhotoBeforeRemove"
              :on-remove="handleUserCardPhoneRemove"
              :on-change="handleUserCardPhoneZhengshu"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card">
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="民族" prop="NATIONALITY">
            <el-select v-model="form.NATIONALITY" placeholder="请选择" style="width: 290px">
              <el-option
                v-for="item in minzuList"
                :key="item.DICTIONARIES_ID"
                :label="item.NAME"
                :value="item.BIANMA"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" >
            <el-radio-group v-model="form.SEX" disabled>
              <el-radio v-model="form.SEX" label="1">女</el-radio>
              <el-radio v-model="form.SEX" label="0">男</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="出生年月" prop="DATE_OF_BIRTH">
            <el-date-picker
              v-model="form.DATE_OF_BIRTH"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              disabled
              style="width: 290px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="年龄" prop="AGE" class="input-width">
            <el-input v-model="form.AGE" type="number" placeholder="这里输入年龄..." disabled/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="户口所在地" prop="HKLOCAL" class="input-width">
            <el-input v-model="form.HKLOCAL" placeholder="这里输入户口所在地..."/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="现住址" prop="ADDRESS" class="input-width">
            <el-input v-model="form.ADDRESS" placeholder="这里输入现住址..."/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="文化程度" prop="DEGREE_OF_EDUCATION">
            <el-select v-model="form.DEGREE_OF_EDUCATION" placeholder="请选择" style="width: 290px">
              <el-option
                v-for="item in wenhuachengduList"
                :key="item.DICTIONARIES_ID"
                :label="item.NAME"
                :value="item.BIANMA"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="婚姻状况" prop="MARITALSTATUS" class="input-width">
            <el-radio-group v-model="form.MARITALSTATUS" >
              <el-radio v-model="form.MARITALSTATUS" label="1">已婚</el-radio>
              <el-radio v-model="form.MARITALSTATUS" label="0">未婚</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="政治面貌" prop="POLITICAL_STATUS">
            <el-select v-model="form.POLITICAL_STATUS" placeholder="请选择" style="width: 290px">
              <el-option
                v-for="item in zhengzhimianmaoList"
                :key="item.DICTIONARIES_ID"
                :label="item.NAME"
                :value="item.BIANMA"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-show="form.POLITICAL_STATUS == 'zhonggongdangyuan'" :span="12">
          <el-form-item label="入党时间" prop="POLITICAL_TIME">
            <el-date-picker
              v-model="form.POLITICAL_TIME"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              style="width: 290px"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="是否缴纳社保" prop="IS_SOCIAL">
            <el-radio-group v-model="form.IS_SOCIAL" @change="form.zhebaoZhaopian = []">
              <el-radio v-model="form.IS_SOCIAL" label="1">是</el-radio>
              <el-radio v-model="form.IS_SOCIAL" label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="form.IS_SOCIAL === '1'" label="社会保障号码" class="input-width" prop="SOCIAL_NUMBER">
            <el-input v-model="form.SOCIAL_NUMBER" placeholder="这里输入社会保障号码..." @keyup.native="number"/>
          </el-form-item>
          <el-form-item v-if="form.IS_SOCIAL === '1'" label="社保卡照片" prop="zhebaoZhaopian" >
            <el-upload
              ref="zhenbaoUpload"
              :file-list="form.zhebaoZhaopian"
              :multiple="false"
              :limit="2"
              :class="{hide:zhebaoUpload}"
              :auto-upload="false"
              :before-remove="handlePhotoBeforeRemove"
              :on-remove="handleZhebaoRemove"
              :on-change="handleZhebaoChangeIMG"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card">
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否参加三级安全培训" prop="IS_LEVEL_THREE" >
            <el-radio-group v-model="form.IS_LEVEL_THREE">
              <el-radio v-model="form.IS_LEVEL_THREE" label="1">是</el-radio>
              <el-radio v-model="form.IS_LEVEL_THREE" label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="form.IS_LEVEL_THREE === '1'" label="三级安全培训照片" prop="photosOfLevel" >
            <el-upload
              ref="photosOfLevel"
              :file-list="form.photosOfLevel"
              :multiple="false"
              :limit="5"
              :class="{hide:photosOfLevel}"
              :auto-upload="false"
              :before-remove="handlePhotoBeforeRemove"
              :on-remove="handleLevelPhotoRemove"
              :on-change="handleLevelPhotoChangeIMG"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card">
              <i class="el-icon-plus" />
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="岗位名称(工种)" prop="POST_ID">
            <el-input v-model="form.POST_ID" placeholder="这里输入岗位名称(工种)..."/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="是否缴纳保险" prop="IS_BF">
            <el-select v-model="form.IS_BF" multiple placeholder="请选择" @change="changeBf">
              <el-option
                v-for="item in BF_OPTIONS"
                :key="item.value"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否特殊工种" prop="IS_SPECIAL_JOB">
            <el-radio-group v-model="form.IS_SPECIAL_JOB" disabled>
              <el-radio v-model="form.IS_SPECIAL_JOB" label="1">是</el-radio>
              <el-radio v-model="form.IS_SPECIAL_JOB" label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-alert
            v-show="form.IS_SPECIAL_JOB == 1"
            :closable="false"
            title="请提示该用户去相关方app端完善特种证书信息"
            type="error"
            class="alertClass"
          />
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否流动人员" prop="ISFLOW" style="float:left">
            <el-radio-group v-model="form.ISFLOW" :disabled="whetherServiceCompany">
              <el-radio v-model="form.ISFLOW" label="1">是</el-radio>
              <el-radio v-model="form.ISFLOW" label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-alert
            v-show="whetherServiceCompany"
            :closable="false"
            title="该人员已固定服务企业，无法变更人员类型"
            type="error"
            class="alertClass"
          />
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { requestFN } from '@/utils/request'
import SelectTree from '@/components/SelectTree'
import { upload } from '@/utils/upload'

export default {
  name: 'UserBaseInfoUpd',
  components: { SelectTree },
  props: {
    user_id: {
      type: String,
      default: ''
    },
    corpinfo_id: {
      type: String,
      default: ''
    },
    employment_apply_management_id: {
      type: String,
      default: ''
    },
    dialog_type: {
      type: String,
      default: ''
    }
  },

  data() {
    var hasSOCIAL = (rule, value, callback) => {
      if (this.form.IS_SOCIAL == '0') {
        this.form.SOCIAL_NUMBER = ''
        callback()
      } else {
        if (this.form.SOCIAL_NUMBER == '') callback(new Error('社会保障号码不为空'))
      }
      callback()
    }
    var isCommunist = (rule, value, callback) => {
      if (this.form.POLITICAL_STATUS != 'zhonggongdangyuan') {
        this.form.POLITICAL_TIME = ''
        callback()
      } else {
        if (this.form.POLITICAL_TIME == '') callback(new Error('请选择入党时间'))
      }
      callback()
    }
    var hasCARD = (rule, value, callback) => {
      requestFN(
        '/user/hasUserCARD',
        {
          CARD_ID: value,
          USER_ID: this.user_id
        }
      ).then((data) => {
        if (data.pd) {
          callback(new Error('身份证号已存在'))
        }
        callback()
        // 获取出生年月
        this.form.DATE_OF_BIRTH = value.substring(6, 10) + '-' + value.substring(10, 12) + '-' + value.substring(12, 14)
        // 获取性别
        this.form.SEX = (parseInt(value.substr(16, 1)) % 2 == 1 ? '0' : '1')
        // 获取年龄
        var ageDate = new Date()
        var month = ageDate.getMonth() + 1
        var day = ageDate.getDate()
        var age = ageDate.getFullYear() - value.substring(6, 10) - 1
        if (value.substring(10, 12) < month || value.substring(10, 12) == month && value.substring(12, 14) <= day) {
          age++
        }
        if (age <= 0) {
          age = 1
        }
        this.form.AGE = age
      }).catch((e) => {
        callback()
      })
    }
    var hasName = (rule, value, callback) => {
      requestFN(
        '/user/hasUserName',
        {
          USERNAME: value,
          USER_ID: this.user_id

        }
      ).then((data) => {
        if (data.pd) {
          callback(new Error('用户名已存在'))
        }
        callback()
      }).catch((e) => {
        callback()
      })
    }
    // 三级培训
    var hasLevelThree = (rule, value, callback) => {
      console.log('hasLevelThree')
      if (this.form.IS_LEVEL_THREE == '0') {
        this.form.photosOfLevel = []
        callback()
      } else {
        if (this.form.photosOfLevel.length == 0) callback(new Error('三级培训不为空'))
      }
      callback()
    }
    // 是否缴纳社保
    var hasSOCIALPHTOT = (rule, value, callback) => {
      if (this.form.IS_SOCIAL == '0') {
        this.form.zhebaoZhaopian = []
        callback()
      } else {
        if (this.form.zhebaoZhaopian.length == 0) callback(new Error('社会卡照片不为空'))
      }
      callback()
    }
    return {
      form: {
        userCardFile: [],
        zhebaoZhaopian: [],
        photosOfLevel: [],
        gongshangbaoxianFile: [],
        userImg: [],
        NATIONALITY: '',
        POLITICAL_TIME: '',
        MARITALSTATUS: '1',
        POLITICAL_STATUS: '',
        contractFileList: [], // 合同文件
        insuranceFileList: [], // 保险文件
        CARD_ID: '', // 身份证号
        DEPARTMENT_NAME: '', // 部门名称
        CORPINFO_ID: '', // 企业id
        HKLOCAL: '', // 户口所在地
        AGE: '',
        SEX: '',
        ADDRESS: '',
        PHONE: '',
        IS_SAFETY_TIME: '',
        IS_SOCIAL: '1',
        SOCIAL_NUMBER: '', // 社会保障号码
        IS_LEVEL_THREE: '1', // 是否参加三级安全培训
        IS_SPECIAL_JOB: '0', // 是否特殊工种
        ISFLOW: '', //
        PHOTO: [],
        IS_INJURIES_PAY: '',
        CORP_START_DATE: '',
        IS_BODY_ADAPT: '',
        IS_SAFETY_TELL: '',
        ISPAY: '',
        IS_INJURIES_PAY_TIME: '',
        ISPAY_NUMBER: '',
        IS_SIGN_LABOR: '',
        IS_HAZARDCONFIRMER: 0,
        INFORPOST: '',
        INFORTITLE: '',
        INFORTITLEValue: '',
        infortitleType: 'select',
        INFORWORK: '',
        INFORWORKValue: '',
        inforworkType: 'select',
        ROLE_ID: [],
        ROLE_NAME: [],
        DEPARTMENT_ID: '',
        POST_ID: '',
        PERSON_WORK_TYPE: '', // 工种
        USERNAME: '',
        NAME: '',
        EMAIL: '',
        LEARNERCATEGORY: '',
        LEARNERCATEGORYSTATUS: 'select',
        SORT: '',
        JCR: '',
        BZ: '',
        PERSON_TYPE: '',
        PASSWORD: 'Aa@123456789',
        USERAVATARPREFIX: '',
        USERAVATARURL: '',
        USERAVATARURL_CONVERT: '',
        SHIFTDUTYONE: '',
        SHIFTDUTYTWO: '',
        DURATION: '',
        WORKSTATUS: '',
        WORKPERIOD: '',
        ISSTUDENT: false,
        NATION: '', // 民族

        POLITICAL_OUTLOOK: '', // 政治面貌
        DATE_OF_BIRTH: '', // 出生年月

        DEGREE_OF_EDUCATION: '', // 文化程度
        POST: '', // 职务
        TYPE_OF_WORK: '', // 工种
        ENTRY_DATE: '', // 入职日期
        WORK_DATE: '', // 参加工作日期
        INCUMBENCY: '', // 在职情况
        CERTIFICATE_INFORMATION: '', // 证书信息
        TITLE: '', // 职称
        DUTIESValue: '',
        DUTIES: '',
        inforpostType: 'select',
        INFORPOSTValue: '',
        letDutiesType: 'select',
        letPostType: 'select',
        letTitleValue: '',
        letTitleId: '',
        letTitleType: 'select',
        letTypeOfWorkValue: '',
        letTypeOfWorkId: '',
        letTypeOfWorkType: 'select',
        USER_ID_CARD: '',
        PERSONNEL_TYPE: '',
        userCerList: [],
        IS_BF: ''
      },
      pdrelated: {},
      BF_OPTIONS: [
        { value: '0', label: '无' },
        { value: '1', label: '商业保险' },
        { value: '2', label: '工伤保险' }

      ],
      config: config,
      wenhuachengduList: [],
      zhengzhimianmaoList: [],
      minzuList: [],
      treeData: [],
      imgDelKey: [],
      whetherHaveCertificate: false,
      photosOfLevel: false,
      dialogFormEdit: false,
      zhebaoUpload: false, // 社保卡照片
      listLoading: false,
      buttonLoading: false,
      whetherServiceCompany: false,
      specialJob: '0',
      defaultProps: {
        children: 'nodes',
        label: 'name',
        value: 'id'
      },
      hideUpload: false,
      userCardIDUpload: false,
      rules: {
        NAME: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        POLITICAL_STATUS: [{ required: true, message: '请选择政治面貌', trigger: 'blur' }],
        MARITALSTATUS: [{ required: true, message: '请选择婚姻状况', trigger: 'blur' }],
        NATIONALITY: [{ required: false, message: '请选择民族', trigger: 'blur' }],
        POLITICAL_TIME: [{ required: true, validator: isCommunist, message: '请选择入党时间', trigger: 'blur' }],
        USERNAME: [
          { required: true, message: '用户名不能为空', trigger: 'blur' },
          {
            pattern: /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[0-9])\d{8}$/,
            message: '用户名为手机号，请正确输入'
          },
          { validator: hasName, trigger: 'blur' }
        ],
        userCardFile: [{ type: 'array', required: true, message: '请上传身份证图片', trigger: 'blur' }],
        IS_BF: [{ type: 'array', required: true, message: '请选择是否缴纳保险', trigger: 'blur' }],
        IS_SOCIAL: [{ required: true, message: '请选择是否缴纳社保', trigger: 'blur' }],
        zhebaoZhaopian: [{ type: 'array', required: true, message: '请上传社保卡照片', trigger: 'blur' }, { validator: hasSOCIALPHTOT }],
        photosOfLevel: [{ type: 'array', required: true, message: '请上传三级培训照片', trigger: 'blur' }, { validator: hasLevelThree }],
        SOCIAL_NUMBER: [{ required: true, message: '社会保障号码不能为空', trigger: 'blur' },
          { validator: hasSOCIAL }],
        ISFLOW: [{ required: true, message: '请选择是否流动人员', trigger: 'blur' }],
        IS_LEVEL_THREE: [{ required: true, message: '请选择是否参加三级安全培训', trigger: 'blur' }],
        IS_SPECIAL_JOB: [{ required: true, message: '请选择是否特种工种', trigger: 'blur' }],
        HKLOCAL: [{ required: false, message: '请输入户口所在地', trigger: 'blur' }],
        ADDRESS: [{ required: false, message: '请输入现住址', trigger: 'blur' }],
        DEGREE_OF_EDUCATION: [{ required: true, message: '请选择文化程度', trigger: 'blur' }],
        POST_ID: [{ required: true, message: '请输入岗位名称(工种)', trigger: 'blur' }],
        PHONE: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
          {
            pattern: /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[0-9])\d{8}$/,
            message: '请输入正确的手机号码'
          }],
        ROLE_ID: [{ required: true, message: '请选择角色', trigger: 'change' }],
        DEPARTMENT_ID: [{ required: true, message: '请选择部门', trigger: 'change' }],
        CARD_ID: [{ required: true, message: '身份证号不能为空', trigger: 'blur' },
          {
            pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
            message: '请输入正确的身份证号'
          },
          { validator: hasCARD, trigger: 'blur' }
        ],
        AGE: [{ required: true, message: '年龄不能为空', trigger: 'blur' },
          {
            pattern: /^\d{2}$/,
            message: '请输入两位数年龄'
          }
        ],
        PHOTO: [
          {
            type: 'array',
            required: true,
            message: '请上传照片',
            trigger: 'blur'
          }
        ],
        userImg: [
          {
            type: 'array',
            required: true,
            message: '请上传照片',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  watch: {
    'form.USERNAME': {
      handler: function() {
        if (this.form.USERNAME) {
          this.form.PHONE = this.form.USERNAME
        }
      }
    },
    'form.userCardFile': {
      handler: function() {
        if (this.form.userCardFile.length >= 2) {
          this.userCardIDUpload = true
        } else {
          this.userCardIDUpload = false
        }
      }
    },
    'form.zhebaoZhaopian': {
      handler: function() {
        if (this.form.zhebaoZhaopian.length >= 2) {
          this.zhebaoUpload = true
        } else {
          this.zhebaoUpload = false
        }
      }
    },
    'form.photosOfLevel': {
      handler: function() {
        if (this.form.photosOfLevel.length >= 4) {
          this.photosOfLevel = true
        } else {
          this.photosOfLevel = false
        }
      }
    },
    'form.userImg': {
      handler: function() {
        if (this.form.userImg.length >= 1) {
          this.hideUpload = true
        } else {
          this.hideUpload = false
        }
      }
    }
  },
  async created() {
    this.getDict()
    this.getTreeList()
    if (this.dialog_type != 'saveUser') {
      this.handleEdit(this.user_id, this.corpinfo_id, this.employment_apply_management_id)
      await this.checkSpecialCertificateList(this.user_id, this.corpinfo_id, this.employment_apply_management_id)
    }
  },
  methods: {
    number() {
      this.form.SORT = this.form.SORT.replace(/[^\.\d]/g, '')
      this.form.SORT = this.form.SORT.replace('.', '')
    },
    // 查询是否有特种证书
    checkSpecialCertificateList() {
      return new Promise((resolve, reject) => {
        requestFN(
          '/specialUser/list',
          {
            USER_ID: this.user_id,
            CORPINFO_ID: this.corpinfo_id,
            keyCrelType: '7498057c4c1f4a11b9a960e66ea04a7a'
          }
        ).then((data) => {
          this.listLoading = false
          if (data.varList.length > 0) {
            this.whetherHaveCertificate = false
            this.specialJob = '1'
          }
        }).catch((e) => {
          this.listLoading = false
        })
      })
    },
    getTreeList() {
      requestFN(
        '/department/listzTree',
        {}
      ).then((data) => {
        this.treeData = JSON.parse(data.zTreeNodes)
      }).catch((e) => {
      })
    },
    // 只能选择1无.
    // 2商业保险
    // 3工伤保险
    // 4商业保险,工伤保险
    changeBf(event) {
      for (let i = 0; i < event.length; i++) {
        if (event[event.length - 1] == '0') {
          this.form.IS_BF = ['0']
          break
        }
        if (event[i] == '0') {
          if (this.form.IS_BF.length !== 1) {
            this.form.IS_BF = this.form.IS_BF.filter(item => {
              return item != '0'
            })
          }
        }
      }
    },
    // 查看
    handleEdit(USER_ID, CORPINFO_ID, EMPLOYMENT_APPLY_MANAGEMENT_ID) {
      this.listLoading = true
      requestFN(
        '/user/goEdit',
        {
          USER_ID: USER_ID,
          CORPINFO_ID: CORPINFO_ID,
          EMPLOYMENT_APPLY_MANAGEMENT_ID: EMPLOYMENT_APPLY_MANAGEMENT_ID
        }
      ).then((data) => {
        this.form = Object.assign(this.form, data.pd) // copy obj
        this.form.IS_BF = this.form.IS_BF.split(',')
        if (data.userPhotoFile) {
          data.userPhotoFile.map(item => {
            const obj = { id: item.IMGFILES_ID, name: item.FILENAME, url: config.fileUrl + item.FILEPATH }
            this.form.userImg.push(obj)
          })
        }
        if (data.userCardIDPhotoFile) {
          data.userCardIDPhotoFile.map(item => {
            const obj = { id: item.IMGFILES_ID, name: item.FILENAME, url: config.fileUrl + item.FILEPATH }
            this.form.userCardFile.push(obj)
          })
        }
        if (data.socialPhotoFile) {
          data.socialPhotoFile.map(item => {
            const obj = { id: item.IMGFILES_ID, name: item.FILENAME, url: config.fileUrl + item.FILEPATH }
            this.form.zhebaoZhaopian.push(obj)
          })
        }
        if (data.threeLevelFile) {
          data.threeLevelFile.map(item => {
            const obj = { id: item.IMGFILES_ID, name: item.FILENAME, url: config.fileUrl + item.FILEPATH }
            this.form.photosOfLevel.push(obj)
          })
        }
        const node = {}
        node.id = this.form.DEPARTMENT_ID
        this.$refs.deptTree.clearHandle()
        this.$nextTick(() => { // 此处使用这个可以等节点渲染后再获取节点
          this.$refs.deptTree.handleNodeClick(node)
        })
        if (this.form.ISFLOW) {
          this.checkWhetherUserService()
        }
        this.pdrelated = Object.assign(this.pdrelated, data.pdrelated)
        Object.assign(this.form, data.pdrelated)
      }).catch((e) => {
        console.log(e)
        this.listLoading = false
      })
      this.dialogFormEdit = true
    },
    handleChangeIMG(file, fileList) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.raw.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        fileList.pop()
        this.form.userImg = []
        return
      }
      this.form.userImg = []
      this.form.userImg.push(file)
      this.hideUpload = fileList.length >= 1
    },
    checkWhetherUserService() {
      return new Promise((resolve, reject) => {
        requestFN(
          '/user/checkWhetherUserService',
          {
            USER_ID: this.user_id,
            IS_FLOW: this.form.ISFLOW
          }
        ).then((data) => {
          this.listLoading = false
          if (data.pd) {
            this.whetherServiceCompany = true
          }
        }).catch((e) => {
          this.listLoading = false
        })
      })
    },
    handlePhotoBeforeRemove(file, fileList) {
      return this.$confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (file.id) {
          this.imgDelKey.push(file.id)
        }
      })
    },
    /** 社保照片 **/
    handleZhebaoRemove(file, fileList) {
      this.form.zhebaoZhaopian = fileList
    },
    handleZhebaoChangeIMG(file, fileList) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.raw.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        fileList.pop()
        return
      }
      this.form.zhebaoZhaopian.push(file)
    },
    /** 三级教育培训 **/
    handleLevelPhotoRemove(file, fileList) {
      this.form.photosOfLevel = fileList
    },
    handleLevelPhotoChangeIMG(file, fileList) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.raw.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        fileList.pop()
        return
      }
      this.form.photosOfLevel.push(file)
    },
    handleUserCardPhoneRemove(file, fileList) {
      this.form.userCardFile = fileList
      this.userCardIDUpload = fileList >= 2
    },
    handleUserCardPhoneZhengshu(file, fileList) {
      const types = ['image/jpeg', 'image/jpg', 'image/png']
      const isImage = types.includes(file.raw.type)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
        fileList.pop()
        this.form.userCardFile = []
        return
      }
      this.form.userCardFile.push(file)
      this.userCardIDUpload = this.form.userCardFile.length >= 2
    },
    handleRemove(file, fileList) {
      this.form.userImg = fileList
      this.hideUpload = fileList.length >= 1
    },
    getDict() {
      requestFN(
        'dictionaries/getLevels',
        { DICTIONARIES_ID: 'd7d80f08d73a4accbccf4fd3d8d1d867' }
      ).then((data) => {
        this.wenhuachengduList = data.list
      }).catch((e) => {
        this.listLoading = false
      })
      requestFN(
        'dictionaries/getLevels',
        { DICTIONARIES_ID: '0a0e406f27f74ee698fe9979d25f62dd' }
      ).then((data) => {
        this.minzuList = data.list
      }).catch((e) => {
        this.listLoading = false
      })
      requestFN(
        'dictionaries/getLevels',
        { DICTIONARIES_ID: '6351efdd12dc4730952e5d195718e252' }
      ).then((data) => {
        this.zhengzhimianmaoList = data.list
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 提交信息
    // 保存
    confirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.form.userCardFile.length < 2) {
            this.$message.error('请上传身份证正反面照片')
            return false
          } else {
            this.listLoading = true
            this.buttonLoading = true

            // this.form.IS_SPECIAL_JOB = this.specialJob
            // 校验社保和工伤保险必须有一个选是
            if ((this.form.IS_BF.length == 0 && this.form.IS_BF[0].length == 0) && this.form.IS_SOCIAL === '0') {
              this.$message.error('保险或社保全无人员，不可进入本系统相关方人员管理！')
              this.listLoading = false
              this.buttonLoading = false
              return
            }
            const formData = new FormData()
            formData.append('imgDelKey', this.imgDelKey)
            Object.keys(this.form).map(key => {
              formData.append(key, this.form[key])
            })
            // 头像
            if (this.$refs['photoUpload'].uploadFiles.length > 0) {
              for (let i = 0; i < this.$refs['photoUpload'].uploadFiles.length; i++) {
                if (this.$refs['photoUpload'].uploadFiles[i]) {
                  formData.append('userPhoto', this.$refs['photoUpload'].uploadFiles[i].raw)
                }
              }
            }
            // 身份证
            if (this.$refs['userCardUpload'].uploadFiles.length > 0) {
              for (let i = 0; i < this.$refs['userCardUpload'].uploadFiles.length; i++) {
                if (this.$refs['userCardUpload'].uploadFiles[i]) {
                  formData.append('userCard', this.$refs['userCardUpload'].uploadFiles[i].raw)
                }
              }
            }
            // 社保照片
            if (this.form.IS_SOCIAL === '1') {
              if (this.$refs['zhenbaoUpload'].uploadFiles.length > 0) {
                for (let i = 0; i < this.$refs['zhenbaoUpload'].uploadFiles.length; i++) {
                  if (this.$refs['zhenbaoUpload'].uploadFiles[i]) {
                    formData.append('SOCIAL_IMG', this.$refs['zhenbaoUpload'].uploadFiles[i].raw)
                  }
                }
              }
            }
            // 三级教育培训照片
            if (this.form.IS_LEVEL_THREE === '1') {
              if (this.$refs['photosOfLevel'].uploadFiles.length > 0) {
                for (let i = 0; i < this.$refs['photosOfLevel'].uploadFiles.length; i++) {
                  if (this.$refs['photosOfLevel'].uploadFiles[i]) {
                    formData.append('photosOfLevel', this.$refs['photosOfLevel'].uploadFiles[i].raw)
                  }
                }
              }
            }
            formData.append('CORPINFO_ID', JSON.parse(sessionStorage.getItem('user')).CORPINFO_ID)
            if (this.dialog_type != 'saveUser') {
              formData.append('EMPLOYMENT_APPLY_MANAGEMENT_ID', this.employment_apply_management_id)
            }
            upload(
              '/user/' + this.dialog_type,
              formData
            ).then((data) => {
              this.$message.success('保存成功！')
              this.listLoading = false
              this.buttonLoading = false
              this.$emit('go-back')
              // this.$parent.goBack()
            }).catch((e) => {
              console.log(e)
              this.$message.success('保存失败！')
              this.listLoading = false
              this.buttonLoading = false
            })
          }
        } else {
          this.$message.warning('请补全必填项')
          return false
        }
      })
    }
  }
}
</script>
