<template>
  <view class="content">
    <view class="card">
      <u-cell-group>
        <u-cell title="照片">
          <template #value>
            <u--image :src="userPhoto" shape="circle" width="100rpx" height="100rpx"></u--image>
          </template>
        </u-cell>
        <u-cell title="姓名" :value="info.name"></u-cell>
        <u-cell title="性别" :value="info.userDetails.sex === '1' ? '女' : '男'"></u-cell>
        <u-cell title="出生年月" :value="info.userDetails.dateOfBirth"></u-cell>
        <u-cell title="年龄" :value="info.userDetails.age"></u-cell>
        <u-cell title="身份证" :value="info.userDetails.cardId"></u-cell>
        <u-cell title="身份证照片">
          <template #value>
            <view v-for="(item,index) in userCardIDPhotoFile" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(userCardIDPhotoFile)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="民族" :value="info.userDetails.nationalityName"></u-cell>
        <u-cell title="户口所在地">
          <template #value>
            <u--text :lines="2" align="right" :text="info.userDetails.hklocal"></u--text>
          </template>
        </u-cell>
        <u-cell title="现住址">
          <template #value>
            <u--text :lines="2" align="right" :text="info.userDetails.address"></u--text>
          </template>
        </u-cell>
        <u-cell title="联系电话" :value="info.userDetails.phone"></u-cell>
        <u-cell title="婚姻状况" :value="info.userDetails.maritalstatus === 0 ? '未婚':'已婚'"></u-cell>
        <u-cell title="政治面貌" :value="info.userDetails.politicalStatusName"></u-cell>
        <u-cell v-if="info.userDetails.politicalStatus === 'zhonggongdangyuan'" title="入党时间"
                :value="info.userDetails.politicalTime"></u-cell>
        <u-cell title="是否缴纳社保" :value="info.userDetails.isSocial === '1'? '是' : '否'"></u-cell>
        <u-cell title="社会保障号" v-show="info.userDetails.isSocial==='1'" :value="info.userDetails.socialNumber"></u-cell>
        <u-cell title="社会保障卡照片" v-show="info.userDetails.isSocial === '1'">
          <template #value>
            <view v-for="(item,index) in socialPhotoFile" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(socialPhotoFile)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="是否签订劳动合同" :value="info.userDetails.isSignLabor === '1' ? '是':'否'"></u-cell>
        <u-cell title="合同图片" v-show="info.userDetails.isSignLabor==='1'">
          <template #value>
            <view v-for="(item,index) in contractFile" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(contractFile)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="是否缴纳商业保险" :value="info.userDetails.ispay === '1' ? '是':'否'"></u-cell>
        <u-cell title="商业保险单号" v-show="info.userDetails.ispay === '1'" :value="info.ispayNumber"></u-cell>
        <u-cell title="保险图片" v-show="info.userDetails.ispay === '1'">
          <template #value>
            <view v-for="(item,index) in insuranceFile" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(insuranceFile)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="是否按期缴纳工伤保险" :value="info.userDetails.isInjuriesPay === '1' ? '是':'否'"></u-cell>
        <u-cell title="工伤保险有效期" v-show="info.userDetails.isInjuriesPay==='1'" :value="info.userDetails.isInjuriesPayTime"></u-cell>
        <u-cell title="工伤保险凭证" v-show="info.userDetails.isInjuriesPay==='1'">
          <template #value>
            <view v-for="(item,index) in injuriesPayTiemFile" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(injuriesPayTiemFile)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="岗位名称(工种)" :value="info.userDetails.postName"></u-cell>
        <u-cell title="是否参加三级安全培训" :value="info.userDetails.isLevelThree === '1' ? '是':'否'"></u-cell>
        <u-cell title="三级安全培训照片" v-show="info.userDetails.isLevelThree === '1'">
          <template #value>
            <view v-for="(item,index) in photosOfLevel" :key="index"
                  style="display: flex;justify-content: space-between;margin-left: 10rpx;">
              <u--image :src="item" width="100rpx" height="100rpx"
                        @click="fnPreview(photosOfLevel)"></u--image>
            </view>
          </template>
        </u-cell>
        <u-cell title="是否流动人员" :value="info.emp.isflow === '1' ? '是':'否'"></u-cell>
      </u-cell-group>
    </view>
    <fab-button type="edit" @click="$u.route({url: '/pages/mine/information/update'})"/>
  </view>
</template>

<script>
import {
  getUserInfo,
  getEmployedBy, getIDCardDeduplication
} from "../../../api";
import FabButton from "@/components/fab_button/index.vue";
import {getUserInfoV1} from "../../../api/api";

export default {
  components: {FabButton},
  data() {
    return {
      info: {
        userDetails:{
          sex:'0',
          dateOfBirth:'1900-01-01'
        },
        emp:{
          isflow:'0'
        },
        age: '0',
        nationalityName:'',
        hklocal: '',
        maritalstatus:'0'
      },
      userCardIDPhotoFile: [],
      socialPhotoFile: [],
      injuriesPayTiemFile: [],
      photosOfLevel: [],
      contractFile: [],
      insuranceFile: [],
      userPhoto: ''
    }
  },
  onShow() {
    this.fnGetData()
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  methods: {
    fnPreview(urls) {
      uni.previewImage({
        urls
      })
    },
    async fnGetData() {
      let data = await getUserInfoV1(
          {
            id: this.$store.getters.getUserInfo.USER_ID,
            postMethod: 'application/json'
          }
      )
      this.info = data.info
      // 身份证
      this.userCardIDPhotoFile = []
      for (let i = 0; i < this.info.userCardInfo.length; i++) {
        this.userCardIDPhotoFile.push(this.$filePath + this.info.userCardInfo[i].filepath)
      }
      // 社保
      this.socialPhotoFile = []
      for (let i = 0; i < this.info.socSecurityInfo.length; i++) {
        this.socialPhotoFile.push(this.$filePath + this.info.socSecurityInfo[i].filepath)
      }
      // 工伤保险
      this.injuriesPayTiemFile = []
      for (let i = 0; i < this.info.empInsuranceInfo.length; i++) {
        this.injuriesPayTiemFile.push(this.$filePath + this.info.empInsuranceInfo[i].filepath)
      }
      // 劳动合同
      this.contractFile = []
      for (let i = 0; i < this.info.contractInfo.length; i++) {
        this.contractFile.push(this.$filePath + this.info.contractInfo[i].filepath)
      }
      // 三级培训
      this.photosOfLevel = []
      for (let i = 0; i < this.info.threeLevelInfo.length; i++) {
        this.photosOfLevel.push(this.$filePath + this.info.threeLevelInfo[i].filepath)
      }
      // 商业保险
      this.insuranceFile = []
      for (let i = 0; i < this.info.insuranceInfo.length; i++) {
        this.insuranceFile.push(this.$filePath + this.info.insuranceInfo[i].filepath)
      }
      // 头像
      this.userPhoto = []
      if (this.info.userPhotoInfo && this.info.userPhotoInfo.length > 0){
        this.userPhoto = this.$filePath + this.info.userPhotoInfo[0].filepath
      }
    }
  },
}
</script>

<style scoped>

</style>
