<template>
  <div class="app-container">
    <div class="tab-header webtop">
      <div>{{ viewTitle }}</div>
      <div>
        <el-button type="primary" size="small" :disabled="submitdisabled" @click="dialogStatus === 'add' ? saveAdd() : saveEdit()">保存</el-button>
        <el-button type="primary" size="small" @click="dialogStatus === 'create' ? saveAdd() : saveEdit()">提交</el-button>
        <el-button type="primary" size="small">打印</el-button>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
    </div>
    <div class="listconadd">
      <el-form ref="dataForm" :model="temp" label-position="right" class="formadd" :rules="rules">
        <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
          <div>客户基础信息</div>
        </div>
        <el-container>
          <el-main>
            <el-row>
              <el-col :span="4">
                <span><span class="icon">*</span>工号</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="jobNumber">
                  <el-input v-model="temp.jobNumber" maxlength="20" placeholder="系统自动生成" clearable readonly/>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <span><span class="icon">*</span>姓名</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="name">
                  <el-input v-model="temp.name" maxlength="20" placeholder="请输入姓名" clearable/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="4">
                <span><span class="icon">*</span>性别</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="gender">
                  <el-radio v-model="temp.gender" label="男">男</el-radio>
                  <el-radio v-model="temp.gender" label="女">女</el-radio>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <span><span class="icon">*</span>出生年月日</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="birthday">
                  <el-date-picker v-model="temp.birthday" style="width: 100%" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="4">
                <span><span class="icon">*</span>身份证</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="idNo">
                  <el-input v-model="temp.idNo" maxlength="20" placeholder="请输入身份证号" clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <span><span class="icon">*</span>证件有效期</span>
              </el-col>
              <el-col :span="8" class="jiguan">
                <el-form-item prop="idTerm">
                  <el-date-picker v-model="temp.idTerm" style="width: 100%" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="4">
                <span><span class="icon">*</span>民族</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="national">
                  <el-select v-model="temp.national" style="width: 100%" placeholder="请选择民族" @change="getNational">
                    <el-option v-for="(item, index) in national_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <span><span class="icon">*</span>手机号码</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="mobile">
                  <el-input v-model="temp.mobile" maxlength="11" show-word-limit placeholder="请输入手机号码" clearable/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="4">
                <span>政治面貌</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="poliCode">
                  <el-select v-model="temp.poliCode" style="width: 100%" placeholder="请选择政治面貌" @change="getPoliCode">
                    <el-option v-for="(item, index) in political_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <span>婚姻状况</span>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="maritalStatus">
                  <el-select v-model="temp.maritalStatus" style="width: 100%" placeholder="请选择婚姻状况" @change="getMari">
                    <el-option v-for="(item, index) in maritalstatus_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-main>
          <el-aside style="text-align: center;width: 25%;border-right: 1px solid #e0e3eb">
            <!--头像上传 :limit="1" bucket="map" :upload-data="{ type: '0001' }"-->
            <upload-head ref="uploadHead" :front-photo="temp.photo" @photoAdd="photoPath"/>
          </el-aside>
        </el-container>
        <el-row>
          <el-col :span="3">
            <span>紧急联系人</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="emergencyContact">
              <el-input v-model="temp.emergencyContact" maxlength="20" placeholder="请输入紧急联系人" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>紧急联系电话</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="emergencyMobile">
              <el-input v-model="temp.emergencyMobile" maxlength="20" placeholder="请输入紧急联系电话" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="2" style="border-top:1px solid #e0e3eb" class="spe_style">
            <span>邮箱</span>
          </el-col>
          <el-col :span="4" style="border-top:1px solid #e0e3eb" class="spe_style02">
            <el-form-item prop="email">
              <el-input v-model="temp.email" maxlength="20" placeholder="请输入邮箱" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="3">
            <span>住址</span>
          </el-col>
          <el-col :span="21">
            <el-form-item prop="address">
              <el-input v-model="temp.address" maxlength="20" placeholder="请输入住址" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="3">
            <span>籍贯</span>
          </el-col>
          <el-col :span="21">
            <el-form-item prop="">
              <el-select v-model="temp.province" filterable placeholder="请选择省" style="width: 148px" @change="getShen">
                <el-option v-for="item in inputProvinceList" :key="item.sid" :label="item.name" :value="item.sid"/>
              </el-select>
              <el-select v-model="temp.city" filterable placeholder="请选择市" class="filter-item" @change="getShi">
                <el-option v-for="item in inputCityList" :key="item.sid" :label="item.name" :value="item.sid"/>
              </el-select>
              <el-select v-model="temp.county" filterable placeholder="请选择县" style="width: 148px" @change="getQu">
                <el-option v-for="item in inputCountyList" :key="item.sid" :label="item.name" :value="item.sid"/>
              </el-select>
              <el-input v-model="temp.nativePlace" maxlength="20" placeholder="请输入详细地址" style="margin-left:15px;width: 40%" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
          <div>更多信息</div>
        </div>
        <el-row>
          <el-col :span="6">
            <div class="span-sty">
              <span><span class="icon">*</span>员工类型</span>
            </div>
            <!--          </el-col>-->
            <!--          <el-col :span="6">-->
            <el-form-item prop="personType">
              <el-select v-model="temp.personType" placeholder="请选择员工类型" class="addinputw02" @change="getPersonType">
                <el-option v-for="(item, index) in personType_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span><span class="icon">*</span>所在部门</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="orgName">
              <el-cascader ref="clearableCascader" class="addinputw" v-model="orgName_list" :props="props" :options="options" clearable @change="orgNameChange"/>
            </el-form-item>
          </el-col>
          <el-col :span="3" class="spe_style">
            <span><span class="icon">*</span>岗位</span>
          </el-col>
          <el-col :span="6" class="spe_style02">
            <el-form-item prop="postSid">
              <el-select v-model="temp.postName" class="addinputw" filterable placeholder="请选择岗位" @change="getPostSid">
                <el-option v-for="(item, index) in postSid_list" :key="index.postCode" :label="item.name" :value="item.postCode"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="span-sty">
              <span><span class="icon">*</span>入职日期</span>
            </div>
            <el-form-item prop="joinCompnyDate">
              <el-date-picker v-model="temp.joinCompnyDate" class="addinputw02" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>试用期</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="probPeriod">
              <el-select v-model="temp.probPeriod" class="addinputw" placeholder="请选择试用期" @change="getProbPeriod">
                <el-option v-for="(item, index) in probPeriod_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3" class="spe_style">
            <span>计划转正日期</span>
          </el-col>
          <el-col :span="6" class="spe_style02">
            <el-form-item prop="plannedConfirmDate">
              <el-date-picker v-model="temp.plannedConfirmDate" class="addinputw" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="span-sty">
              <span>实际转正日期</span>
            </div>
            <el-form-item prop="confirmationDate">
              <el-date-picker v-model="temp.confirmationDate" class="addinputw02" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>开户行</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="openBank">
              <el-input v-model="temp.openBank" maxlength="20" placeholder="请输入开户行" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3" class="spe_style">
            <span>银行账号</span>
          </el-col>
          <el-col :span="6" class="spe_style02">
            <el-form-item prop="bankCardNo">
              <el-input v-model="temp.bankCardNo" maxlength="20" placeholder="请输入银行账号" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- !!!!各种附件证明图片!!!! -->
        <el-row>
          <el-col :span="6">
            <div class="span-sty">
              <span>身份证(人像面)</span>
            </div>
            <Upload ref="uploadImg" class="addinputw02" v-model="idCardA_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
          </el-col>
          <el-col :span="3">
            <span>身份证(国徽面)</span>
          </el-col>
          <el-col :span="6">
            <Upload ref="uploadImg" v-model="idCardB_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
          </el-col>
          <el-col :span="3" class="spe_style">
            <span>前公司离职证明</span>
          </el-col>
          <el-col :span="6" class="spe_style02">
            <Upload ref="uploadImg" v-model="leave_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
          </el-col>
        </el-row>
        <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
          <div>学历/技能信息</div>
        </div>
        <el-row>
          <el-col :span="3">
            <span>毕业院校</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="graduate">
              <el-input v-model="temp.graduate" maxlength="20" placeholder="请输入毕业院校" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>学历/专业</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="education">
              <el-select v-model="temp.education" placeholder="请选择学历" @change="getEducate">
                <el-option v-for="(item, index) in educate_list" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="spe_style">
            <span>职称</span>
          </el-col>
          <el-col :span="4" class="spe_style02">
            <el-form-item prop="title">
              <el-input v-model="temp.title" maxlength="20" placeholder="请输入职称" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="3">
            <span>资格认证</span>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="qualification">
              <el-input v-model="temp.qualification" maxlength="20" placeholder="请输入资格认证" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>驾照类型</span>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="licenseType">
              <el-select v-model="temp.licenseType" placeholder="请选择驾照类型" @change="getLicenseType">
                <el-option v-for="item in licenseType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="3">
            <span>学历证书</span>
          </el-col>
          <el-col :span="6">
            <Upload ref="uploadImg" v-model="diploma_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
          </el-col>
          <el-col :span="3">
            <span>学位证书</span>
          </el-col>
          <el-col :span="12">
            <Upload ref="uploadImg" v-model="degree_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
          </el-col>
        </el-row>
        <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
          <div>社保信息</div>
        </div>
        <el-row>
          <el-col :span="3">
            <span>意外险参保</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="isHaveInsurance">
              <el-radio v-model="temp.isHaveInsurance" :label="1">是</el-radio>
              <el-radio v-model="temp.isHaveInsurance" :label="0">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>意外险参保地</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="insuranceAddr">
              <el-input v-model="temp.insuranceAddr" maxlength="20" style="width: 100%" placeholder="请输入参保地" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>意外险参保时间</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="insuranceStartDate">
              <el-date-picker v-model="temp.insuranceStartDate" style="width: 100%" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>意外险终止时间</span>
          </el-col>
          <el-col :span="3"  class="spe_style02">
            <el-form-item prop="insuranceEndDate">
              <el-date-picker v-model="temp.insuranceEndDate" style="width: 100%" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="3">
            <span>养老</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="isHaveAged">
              <el-radio v-model="temp.isHaveAged" :label="1">是</el-radio>
              <el-radio v-model="temp.isHaveAged" :label="0">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>医疗/生育</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="isHaveMedical">
              <el-radio v-model="temp.isHaveMedical" :label="1">是</el-radio>
              <el-radio v-model="temp.isHaveMedical" :label="0">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>工伤</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="isHaveInjury">
              <el-radio v-model="temp.isHaveInjury" :label="1">是</el-radio>
              <el-radio v-model="temp.isHaveInjury" :label="0">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>失业</span>
          </el-col>
          <el-col :span="3" class="spe_style02">
            <el-form-item prop="isHaveUnemploy">
              <el-radio v-model="temp.isHaveUnemploy" :label="1">是</el-radio>
              <el-radio v-model="temp.isHaveUnemploy" :label="0">否</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="3">
            <span>社保参保地</span>
          </el-col>
          <el-col :span="9">
            <el-form-item prop="insuredPlace">
              <el-input v-model="temp.insuredPlace" maxlength="20" placeholder="请输入社保参保地" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>纸质档案保管地</span>
          </el-col>
          <el-col :span="9">
            <el-form-item prop="paperPlace">
              <el-input v-model="temp.paperPlace" maxlength="20" placeholder="请输入纸质档案保管地" class="addinputw" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
          <div>合同信息</div>
        </div>
        <el-row>
          <el-col :span="3">
            <span>合同起止日期</span>
          </el-col>
          <el-col :span="9">
            <el-form-item prop="contractStartDate">
              <el-date-picker v-model="temp.contractStartDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <span>合同结束日期</span>
          </el-col>
          <el-col :span="9">
            <el-form-item prop="contractEndDate">
              <el-date-picker v-model="temp.contractEndDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-show="isQuit">
          <div class="title" style=" display: flex; align-items: center; justify-content: space-between;">
            <div>离职信息</div>
          </div>
          <el-row>
            <el-col :span="3">
              <span>离职日期</span>
            </el-col>
            <el-col :span="9">
              <el-form-item prop="quitDate">
                <el-date-picker v-model="temp.quitDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"/>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <span>离职理由</span>
            </el-col>
            <el-col :span="9">
              <el-form-item prop="quitReason">
                <el-input v-model="temp.quitReason" maxlength="20" placeholder="请输入离职理由" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getCity, getCounty, getProvince } from '@/api/Common/areaPicker' // 省市区
import Upload from '@/components/uploadFileimg/upload.vue'
import uploadHead from '@/components/uploadFileimg/upload_head.vue'
import req from '@/api/management/yuangongguanli'

export default {
  name: 'YuangongAdd',
  components: { Upload, uploadHead },
  data() {
    var checkSubmit = (rule, value, callback) => {
      if (value !== undefined && value !== null) {
        if (value.length < 11) {
          callback(new Error('请输入正确的手机号'))
        }
      } else {
        callback(new Error('请输入手机号'))
      }
      callback()
    }
    var identitycard = (rules, value, callback) => {
      const card =
        /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
      if (card.test(value)) {
        return callback()
      }
      callback(new Error('请输入身份证号码'))
    }
    return {
      viewTitle: '',
      dialogStatus: '',
      index: 0,
      isQuit: false,
      // 下拉框
      national_list: [], // 民族 12
      maritalstatus_list: [], // 婚姻 12
      political_list: [], // 政治面貌 12
      postSid_list: [], // 岗位
      personType_list: [], // 员工类型 12
      probPeriod_list: [], // 试用期 12
      gender_list: [], // 性别 1
      educate_list: [], // 学历
      licenseType_list: [], // 驾照类型
      // 省市区
      province: [],
      city: [],
      county: [],
      inputProvinceList: [],
      inputCityList: [],
      inputCountyList: [],
      // 部门级联列表
      orgSid: '',
      orgName_list: [], // 所在部门
      dataArr: [],
      options: [], // 级联列表选项
      props: {
        // props传值
        value: 'sid',
        label: 'name',
        children: 'children',
        checkStrictly: true
      },
      // 上传图片
      // photo_list: [],
      idCardA_list: [],
      idCardB_list: [],
      diploma_list: [],
      degree_list: [],
      leave_list: [],
      sid: '', // 一条数据的sid
      temp: {
        provinceCode: '',
        postName: '',
        cityCode: '',
        countyCode: '',
        genderKey: '', // 性别code
        nativePlace: '', // 籍贯
        sysStaffOrg: {
          orgName: '',
          orgSid: ''
        },
        sysStaffPost: {} // 岗位信息
      },
      rules: {
        name: [{ required: true, message: '姓名不能为空', trigger: 'change' }],
        gender: [{ required: true, message: '性别不能为空', trigger: 'change' }],
        idNo: [{ required: true, message: '身份证号不能为空', validator: identitycard, trigger: 'change' }],
        idTerm: [{ required: true, message: '证件有效期不能为空', trigger: 'change' }],
        national: [{ required: true, message: '民族不能为空', trigger: 'change' }],
        mobile: [{ required: true, validator: checkSubmit, trigger: 'blur' }],
        personType: [{ required: true, message: '员工类型不能为空', trigger: 'change' }],
        joinCompnyDate: [{ required: true, message: '入职日期不能为空', trigger: 'blur' }]
      },
      submitdisabled: false
    }
  },
  created() {
    // 下拉框
    this.getType()
    // 部门级联列表
    this.getBuMen()
    this.huoquSheng()
  },
  methods: {
    // 邮箱正则
    // email_blur(){
    //   var verify =/^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
    //   if(!verify.test(this.temp.email)){
    //     this.message ='邮箱格式错误, 请重新输⼊'
    //   }
    // },
    // -------------------------获取省市县方法-------------------------
    huoquSheng() {
      getProvince().then((res) => {
        // console.log('11111省：', res)
        if (res.code === '200') {
          this.inputProvinceList = res.data
        }
      })
    },
    getShen(value) {
      let bb = ''
      this.inputProvinceList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      console.log('shengshengsheng', this.inputProvinceList)
      // 这里是把code的值赋给province省字段
      this.temp.province = bb.name
      this.temp.provinceCode = bb.districtCode
      this.huoquShi(bb.sid)
    },
    huoquShi(sid1) {
      var sid = {
        sid: sid1
      }
      getCity(sid).then((res) => {
        console.log('2222市', res)
        if (res.code === '200') {
          this.inputCityList = res.data
        }
      })
    },
    getShi(value) {
      let bb = ''
      this.inputCityList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      this.temp.city = bb.name
      this.temp.cityCode = bb.districtCode
      this.huoquXian(bb.sid)
    },
    huoquXian(sid1) {
      var sid = {
        sid: sid1
      }
      getCounty(sid).then((res) => {
        console.log('333县', res)
        if (res.code === '200') {
          this.inputCountyList = res.data
        }
      })
    },
    getQu(value) {
      let bb = ''
      this.inputCountyList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      this.temp.county = bb.name
      this.temp.countyCode = bb.districtCodes
      console.log('6666677777777', this.deCode)
    },
    // 级联列表 部门
    getBuMen() {
      req.salesDepName().then((res) => {
        if (res.code === '200') {
          this.options = res.data
          console.log('请求到的部门级联列表', this.options)
          this.BuMen0(this.options)
        }
      })
    },
    BuMen0(data) {
      data.forEach((e) => {
        if (e.children) {
          if (e.children.length !== 0) {
            this.BuMen0(e.children)
          } else {
            delete e.children
            this.dataArr.push(e)
            return
          }
        }
      })
    },
    // 部门
    orgNameChange(e) {
      console.log('选中结果：' + JSON.stringify(e))
      var result = ''
      var result_Sid = ''
      var sidPath = ''
      var namePath = ''
      var result_code = ''
      if (e.length > 0) {
        // 循环多选项
        e.forEach((item) => {
          var last_id = item
          // 循环查找名字
          this.select_temp_Name = '' // 临时遍历，用来保存选中结果(组织名称)
          this.select_temp_Sid = '' // 临时遍历，用来保存选中结果(组织Sid)
          this.select_temp_NamePath = '' // 临时遍历，用来保存选中结果(名称路径)
          this.select_temp_SidPath = '' // 临时遍历，用来保存选中结果(sid路径)
          this.select_temp_code = '' // 临时遍历，用来保存选中结果(code)
          this.findOrgId(last_id, this.options)
          result = result + this.select_temp_Name + ','
          result_Sid = result_Sid + this.select_temp_Sid + ','
          sidPath = this.select_temp_SidPath
          namePath = namePath + this.select_temp_Name + '/'
          result_code = this.select_temp_code
        })
      }
      if (result !== '') {
        result = result.substring(0, result.length - 1)
      }
      if (namePath !== '') {
        namePath = namePath.substring(0, namePath.length - 1)
      }
      if (result_Sid !== '') {
        result_Sid = result_Sid.substring(0, result_Sid.length - 1)
      }
      const orgSidArray = result_Sid.split(',')
      const orgSid = orgSidArray[orgSidArray.length - 1]

      const orgNameArray = result.split(',')
      const orgName = orgNameArray[orgNameArray.length - 1]

      this.temp.sysStaffOrg.orgName = orgName
      this.temp.sysStaffOrg.orgSid = orgSid
      this.temp.sysStaffOrg.orgSidPath = sidPath
      this.temp.sysStaffOrg.orgNamePath = namePath
      this.temp.sysStaffOrg.orgCode = result_code
    },
    // --- 循环查询
    findOrgId(id, options) {
      if (options.length > 0) {
        for (var i = 0; i < options.length; i++) {
          if (id === options[i].sid) {
            this.select_temp_Name = options[i].name // 保存找到的内容
            this.select_temp_Sid = options[i].sid
            this.select_temp_NamePath = options[i].name
            this.select_temp_SidPath = options[i].orgSidPath
            this.select_temp_code = options[i].orgCode
            return true
          } else {
            // 判断是否最后一级
            if (options[i].children !== undefined && options[i].children !== null) {
              // 不是的话查询下一级
              if (this.findOrgId(id, options[i].children)) {
                return true
              }
            }
          }
        }
      }
    },

    // -------------------------数据字典下拉框-------------------------
    getType() {
      req.pullDown({ type: 'national' }).then((res) => {
        if (res.code === '200') {
          this.national_list = res.data
          console.log('下拉框请求民族', res.data)
        }
      })
      req.pullDown({ type: 'maritalstatus' }).then((res) => {
        if (res.code === '200') {
          this.maritalstatus_list = res.data
          console.log('下拉框请求婚姻', res.data)
        }
      })
      req.pullDown({ type: 'political' }).then((res) => {
        if (res.code === '200') {
          this.political_list = res.data
          console.log('下拉框请求政治', res.data)
        }
      })
      req.pullDown({ type: 'personType' }).then((res) => {
        if (res.code === '200') {
          this.personType_list = res.data
          console.log('下拉框员工类型', res.data)
        }
      })
      req.pullDown({ type: 'probPeriod' }).then((res) => {
        if (res.code === '200') {
          this.probPeriod_list = res.data
          console.log('下拉框试用期', res.data)
        }
      })
      req.pullDown({ type: 'sex' }).then((res) => {
        if (res.code === '200') {
          this.gender_list = res.data
          console.log('下拉框性别', res.data)
        }
      })
      req.postName().then((res) => {
        if (res.code === '200') {
          this.postSid_list = res.data
          console.log('下拉框请求岗位', res.data)
        }
      })
      req.pullDown({ type: 'educationdegree' }).then((res) => {
        if (res.code === '200') {
          this.educate_list = res.data
          console.log('下拉框请求学历', res.data)
        }
      })
      req.pullDown({ type: 'carType' }).then((res) => {
        if (res.code === '200') {
          this.licenseType_list = res.data
          console.log('下拉框请求驾照', res.data)
        }
      })
    },

    getNational(value) {
      console.log('触发下拉框按钮')
      let bb = null
      this.national_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.national = bb.name
      this.temp.nationalKey = bb.key
      console.log('name', this.temp.national)
    },

    getMari(value) {
      console.log('触发下拉框按钮')
      let bb = null
      this.maritalstatus_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.maritalStatus = bb.name
      this.temp.maritalStatusKey = bb.key
      console.log('name', this.temp.maritalStatus)
    },

    getPoliCode(value) {
      console.log('触发下拉框按钮')
      let bb = null
      this.political_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.poliCode = bb.name
      this.temp.poliCodeKey = bb.key
      console.log('name', this.temp.political)
    },

    getPersonType(value) {
      console.log('触发下拉框按钮')
      let bb = null
      this.personType_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      if (bb.name === '离职') {
        this.isQuit = true
      } else if (bb.name === '全职') {
        this.isQuit = false
      }
      this.temp.personType = bb.name
      this.temp.personTypeKey = bb.key
      console.log('name', this.temp.personType)
    },

    getProbPeriod(value) {
      console.log('触发下拉框按钮')
      let bb = null
      this.probPeriod_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.probPeriod = bb.name
      this.temp.probPeriodKey = bb.key
      console.log('name', this.temp.probPeriod)
    },

    getPostSid(value) {
      console.log('触发下拉框按钮', value)
      let bb = null
      this.postSid_list.forEach((e) => {
        if (e.postCode === value) {
          bb = {
            name: e.name,
            key: e.postCode,
            sid: e.sid
          }
        }
      })
      this.temp.sysStaffPost.postSid = bb.sid
      this.temp.postName = bb.name
      this.temp.sysStaffPost.postCode = bb.key
      console.log('name', this.temp.sysStaffPost.postSid)
    },

    getEducate(value) {
      console.log('触发下拉框按钮', value)
      let bb = null
      this.educate_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.education = bb.name
      this.temp.educationKey = bb.key
      console.log('name', this.temp.sysStaffPost.postSid)
    },

    getLicenseType(value) {
      console.log('触发下拉框按钮', value)
      let bb = null
      this.licenseType_list.forEach((e) => {
        if (e.dictKey === value) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      this.temp.licenseType = bb.name
      this.temp.licenseTypeKey = bb.key
      console.log('name', this.temp.licenseType)
    },

    getGenderKey() {
      console.log('触发下拉框按钮')
      let bb = {}
      this.gender_list.forEach((e) => {
        if (e.dictValue === this.temp.gender) {
          bb = {
            type: e.dictType,
            name: e.dictValue,
            key: e.dictKey,
            sid: e.sid
          }
        }
      })
      if (this.temp.gender === bb.name) {
        this.temp.genderKey = bb.key
      }
    },
    photoPath(val) {
      this.temp.photo = val
    },
    // 上传附件
    getUrl() {
      console.log('身份证人面像', this.idCardA_list)
      // 身份证(人像面)
      if (this.idCardA_list.length > 0) {
        this.temp.idCardA = this.idCardA_list[this.idCardA_list.length - 1].url
      } else {
        this.temp.idCardA = ''
      }
      // 身份证(国徽面)
      if (this.idCardB_list.length > 0) {
        this.temp.idCardB = this.idCardB_list[this.idCardB_list.length - 1].url
      } else {
        this.temp.idCardB = ''
      }
      // 学历证书
      if (this.diploma_list.length > 0) {
        this.temp.diploma = this.diploma_list[this.diploma_list.length - 1].url
      } else {
        this.temp.diploma = ''
      }
      // 学位证书
      if (this.degree_list.length > 0) {
        this.temp.degreeCertificate = this.degree_list[this.degree_list.length - 1].url
      } else {
        this.temp.degreeCertificate = ''
      }
      // 前公司离职证明 leaveCertificate
      if (this.leave_list.length > 0) {
        this.temp.leaveCertificate = this.leave_list[this.leave_list.length - 1].url
      } else {
        this.temp.leaveCertificate = ''
      }
    },

    // 返回（===既判断又赋值）
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      // this.photo_list = []
      this.$refs['uploadHead'].files = []
      this.$refs['uploadHead'].Photo = ''
      this.idCardA_list = []
      this.idCardB_list = []
      this.diploma_list = []
      this.degree_list = []
      this.leave_list = []
      this.temp = {
        sysStaffOrg: {}, // 部门信息
        sysStaffPost: {} // 岗位信息
      }
      this.orgName_list = []
      // this.$refs['clearableCascader'].checkedValue = ''
      this.$refs['dataForm'].resetFields()
      this.$emit('doback')
    },

    showAdd() {
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.dialogStatus = 'add'
      this.viewTitle = '【新增】员工信息'
    },

    showEdit(sid, row) {
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.dialogStatus = 'edit'
      this.viewTitle = '【编辑】员工信息'
      console.log('编辑页面sid', sid)
      req.fetchBySid(sid).then((resp) => {
        const data = resp.data
        this.sid = sid
        this.temp = data
        if (this.temp.personType === '全职') {
          this.isQuit = false
        } else {
          this.isQuit = true
        }
        this.orgName_list = data.sysStaffOrg.orgSidPath.split('/')
        let bb = {}
        this.postSid_list.forEach((e) => {
          if (e.sid === data.sysStaffPost.postSid) {
            bb = {
              name: e.name,
              key: e.postCode,
              sid: e.sid
            }
          }
        })
        this.temp.postName = bb.name
        // if (this.temp.photo !== '') {
        //   const imgName = this.temp.photo.split('/')
        //   this.photo_list.push({
        //     name: imgName[imgName.length - 1],
        //     url: this.temp.photo
        //   })
        // }
        if (this.temp.idCardA !== '') {
          const imgName = this.temp.idCardA.split('/')
          this.idCardA_list.push({
            name: imgName[imgName.length - 1],
            url: this.temp.idCardA
          })
        }
        console.log('身份证人面像', this.idCardA_list)
        if (this.temp.idCardB !== '') {
          const imgName = this.temp.idCardB.split('/')
          this.idCardB_list.push({
            name: imgName[imgName.length - 1],
            url: this.temp.idCardB
          })
        }
        if (this.temp.diploma !== '') {
          const imgName = this.temp.diploma.split('/')
          this.diploma_list.push({
            name: imgName[imgName.length - 1],
            url: this.temp.diploma
          })
        }
        if (this.temp.degreeCertificate !== '') {
          const imgName = this.temp.degreeCertificate.split('/')
          this.degree_list.push({
            name: imgName[imgName.length - 1],
            url: this.temp.degreeCertificate
          })
        }
        if (this.temp.leaveCertificate !== '') {
          const imgName = this.temp.leaveCertificate.split('/')
          this.leave_list.push({
            name: imgName[imgName.length - 1],
            url: this.temp.leaveCertificate
          })
        }
      }).catch((e) => {
        this.temp = row
      })
    },

    saveAdd() {
      const _this = this
      this.$refs['dataForm'].validate((valid) => {
        this.getGenderKey()
        this.getUrl()
        if (valid) {
          this.submitdisabled = true
          req.saveAdd(this.temp).then((resp) => {
            this.submitdisabled = false
            console.log(resp)
            if (resp.success) {
              _this.$message({
                showClose: true,
                type: 'success',
                message: resp.msg
              })
              _this.handleReturn('true')
              console.log('保存成功')
            } else {
              _this.$message({
                showClose: true,
                type: 'success',
                message: resp.msg
              })
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        } else {
          return false
        }
      })
    },

    saveEdit() {
      const _this = this
      this.$refs['dataForm'].validate((valid) => {
        this.getUrl()
        if (valid) {
          this.submitdisabled = true
          req.saveEdit(this.temp, this.sid).then((resp) => {
            this.submitdisabled = false
            _this.$message({
              showClose: true,
              type: 'success',
              message: resp.msg
            })
            _this.handleReturn('true')
          }).catch(() => {
            this.submitdisabled = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
/deep/ .el-main {
  padding: 0;
}
.formadd {
  margin: 0 2%;
}
/deep/ .el-form-item__content {
  margin-left: 0 !important;
}

.icon {
  color: #e84026;
  margin-right: 4px;
}

.jiguan {
  border-top: 1px solid #e0e3eb;
}

/deep/ .el-col-3,
.el-col-4 {
  text-align: right;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px !important;
  font-weight: 600;
}

.spe_style {
  text-align: right;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px !important;
  font-weight: 600;
}

.spe_style02 {
  text-align: left;
}

.span-sty {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  line-height: 60px;
  text-align: right;
  font-size: 14px;
  color: #606266;
  font-weight: 600;
  width: 110px;
  padding-right: 5px;
  border-right: 1px solid #e0e3eb;
}

.addinputw02 {
  padding: 5px 0;
  width: 60% !important;
  margin-left: 110px !important;
}
</style>
