<template>
  <div>
    <el-dialog
      :visible.sync="dialog_visible"
      title="人员详情"
      width="70%"
    >
      <div v-loading="listLoading">
        <table class="table-ui" style="margin-bottom: 20px;">
          <div class="level-title">
            <h1>人员信息</h1>
          </div>
          <tr>
            <th>照片</th>
            <td>
              <span v-if="imgUrl != ''">
                <div class="img-flex">
                  <viewer>
                    <img :src="imgUrl" width="40" height="40" style="object-fit: cover;">
                  </viewer>
                </div>
              </span>
              <span v-else/>
            </td>
            <th>姓名</th>
            <td>{{ dataForm.NAME }}</td>
            <th>性别</th>
            <td>{{ dataForm.SEX === '0' ? '男' : '女' }}</td>
          </tr>
          <tr>
            <th>出生年月</th>
            <td>{{ dataForm.DATE_OF_BIRTH }}</td>
            <th>年龄</th>
            <td>{{ dataForm.AGE }}</td>
            <th>手机号</th>
            <td>{{ dataForm.PHONE }}</td>
          </tr>
          <tr>
            <th>身份证</th>
            <td>{{ dataForm.CARD_ID }}</td>
            <th>身份证照片</th>
            <!--if条件不可删除-->
            <td v-if="userCardIDPhotoFile.length>0" colspan="3">
              <span>
                <div class="img-flex">
                  <viewer>
                    <img
                      v-for="item in userCardIDPhotoFile"
                      :src="config.fileUrl + item.FILEPATH"
                      :key="item.IMGFILES_ID"
                      width="40"
                      height="40"
                      style="object-fit: cover;">
                  </viewer>
                </div>
              </span>
            </td>
          </tr>

          <tr>
            <th>民族</th>
            <td>{{ dataForm.minzuName? dataForm.minzuName:'暂无信息' }}</td>
            <th>婚姻状况</th>
            <td>{{ dataForm.MARITALSTATUS === '0' ? '未婚' : '已婚' }}</td>
            <th>政治面貌</th>
            <td>{{ dataForm.zzName }} {{
              dataForm.zzName == '中共党员' ? '入党时间' + dataForm.POLITICAL_TIME : ''
            }}
            </td>
          </tr>

          <tr>
            <th>户口所在地</th>
            <td>{{ dataForm.HKLOCAL? dataForm.HKLOCAL:'暂无信息' }}</td>
            <th>现住址</th>
            <td>{{ dataForm.ADDRESS? dataForm.ADDRESS:'暂无信息' }}</td>
            <th>联系电话</th>
            <td>{{ dataForm.PHONE }}</td>
          </tr>
          <tr>
            <th>文化程度</th>
            <td>{{ dataForm.DEGREE_OF_EDUCATION_NAME }}</td>
            <!--            <th>本企业从业开始日期</th>-->
            <!--            <td>{{ dataForm.CORP_START_DATE }}</td>-->
            <th>岗位名称(工种)</th>
            <td colspan="3">{{ dataForm.POST_ID }}</td>
          </tr>
          <tr>
            <th>是否缴纳社保</th>
            <td :colspan="dataForm.IS_SOCIAL === '1' ? '':5">{{ formatLabel(dataForm.IS_SOCIAL) }}</td>
            <th v-if="dataForm.IS_SOCIAL === '1'">社会保障号码</th>
            <td v-if="dataForm.IS_SOCIAL === '1'">{{ dataForm.SOCIAL_NUMBER }}</td>
            <th v-if="dataForm.IS_SOCIAL === '1'">社保卡照片</th>
            <td v-if="dataForm.IS_SOCIAL === '1'&& socialPhotoFile.length>0" colspan="3">
              <span>
                <div class="img-flex">
                  <viewer>
                    <img
                      v-for="item in socialPhotoFile"
                      :src="config.fileUrl + item.FILEPATH"
                      :key="item.IMGFILES_ID"
                      width="40"
                      height="40"
                      style="object-fit: cover;">
                  </viewer>
                </div>
              </span>
            </td>
          </tr>
          <tr>
            <th>是否参加三级安全培训</th>
            <td >{{ formatLabel(dataForm.IS_LEVEL_THREE) }}</td>
            <th v-if="dataForm.IS_LEVEL_THREE == 1">三级安全培训照片</th>
            <td v-if="dataForm.IS_LEVEL_THREE == 1 && photosOfLevel.length>0" colspan="3">
              <span>
                <div class="img-flex">
                  <viewer>
                    <img
                      v-for="item in photosOfLevel"
                      :src="config.fileUrl + item.FILEPATH"
                      :key="item.IMGFILES_ID"
                      width="40"
                      height="40"
                      style="object-fit: cover;">
                  </viewer>
                </div>
              </span>
            </td>
          </tr>
          <tr>
            <th>是否缴纳保险</th>
            <td >{{ formatLabelBf(dataForm.IS_BF) }}</td>
            <th>是否特殊工种</th>
            <td >{{ formatLabel(dataForm.IS_SPECIAL_JOB) }}</td>
            <th>是否流动人员</th>
            <td >{{ formatLabel(dataForm.ISFLOW) }}</td>
          </tr>
        </table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog_visible = false">取 消</el-button>
        <el-button type="primary" @click="dialog_visible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { requestFN } from '@/utils/request'

export default {
  name: 'UserBaseInfoView',
  props: {
    base_info_url: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      config: config,
      imgUrl: '',
      listLoading: false,
      dialog_visible: false,
      wenhuachengduList: [],
      postList: [],
      contractFileList: [], // 合同文件
      insuranceFileList: [], // 保险文件
      userPhotoFile: [], // 头像
      userCardIDPhotoFile: [], // 身份证照片
      photosOfLevel: [], // 三级教育培训
      socialPhotoFile: [], // 身份证照片
      gongshangbaoxianFile: [], // 身份证照片
      dataForm: {
        contractFileList: [], // 合同文件
        insuranceFileList: [], // 保险文件
        CARD_ID: '', // 身份证号
        DEPARTMENT_NAME: '', // 部门名称
        CORPINFO_ID: '', // 企业id
        HKLOCAL: '', // 户口所在地
        AGE: '',
        SEX: '',
        ADDRESS: '',
        PHONE: '',
        IS_SOCIAL: '', // 是否缴纳社保
        SOCIAL_NUMBER: '', // 社会保障号码
        IS_LEVEL_THREE: '', // 是否参加三级安全培训
        IS_SPECIAL_JOB: '', // 是否特殊工种
        ISFLOW: '', //
        PHOTO: [],
        IS_INJURIES_PAY: '',
        CORP_START_DATE: '',
        IS_BODY_ADAPT: '',
        IS_SAFETY_TELL: '',
        ISPAY: '',
        IS_SIGN_LABOR: '',
        DEPARTMENT_ID: '',
        POST_ID: '',
        PERSON_WORK_TYPE: '', // 工种
        USERNAME: '',
        NAME: '',
        BZ: '',
        PERSON_TYPE: '',
        PASSWORD: 'Aa@123456789',
        DATE_OF_BIRTH: '', // 出生年月

        DEGREE_OF_EDUCATION: '', // 文化程度
        POST: '', // 职务
        TYPE_OF_WORK: '', // 工种
        ENTRY_DATE: '', // 入职日期
        WORK_DATE: '' // 参加工作日期
      },
      USER_ID: '',
      CORPINFO_ID: ''
    }
  },
  methods: {
    openWindow(user_id, corpinfo_id) {
      console.log('openWindow')
      console.log(this.base_info_url)
      this.getList(user_id, corpinfo_id)
      this.$nextTick(() => {
        this.dialog_visible = !this.dialog_visible
      })
    },
    formatLabelBf(value) {
      if (value) {
        var valList = value.split(',')
        var label = []
        for (let i = 0; i < valList.length; i++) {
          if (valList[i] == 0) {
            label.push('无')
            break
          }
          if (valList[i] == 1) {
            label.push('商业保险')
          }
          if (valList[i] == 2) {
            label.push('工伤保险')
          }
        }
        return label.join(',')
      }
    },
    // 转换是否
    formatLabel(value) {
      if (value == '1') {
        return '是'
      } else if (value == '0') {
        return '否'
      } else {
        return ''
      }
    },
    // 获取数据字典数据
    getList(user_id, corpinfo_id) {
      this.listLoading = true
      requestFN(
        this.base_info_url,
        {
          USER_ID: user_id,
          CORPINFO_ID: corpinfo_id
        }
      ).then((data) => {
        this.listLoading = false
        this.dataForm = Object.assign(this.dataForm, data.pd)
        this.userPhotoFile = data.userPhotoFile
        if (this.userPhotoFile.length > 0) {
          this.imgUrl = config.fileUrl + this.userPhotoFile[0].FILEPATH
        }
        this.photosOfLevel = data.photosOfLevel
        // this.insuranceFileList = data.insuranceFile
        // this.contractFileList = data.contractFile
        this.userCardIDPhotoFile = data.userCardIDPhotoFile
        this.socialPhotoFile = data.socialPhotoFile
        // this.gongshangbaoxianFile = data.gongshangbaoxianFile
      }).catch((e) => {
        this.listLoading = false
      })
    }
  }

}
</script>
