<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="`${mainData.name}${mainData.hrcode}`"
        :oldFormPath="{edit:'HManagement/department/staff/list/modules'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221102090303"
        delApiId="20221102090403"
        idname="hrid"
        ownertable="sys_hr"
        tags=""
        :tabs="['基础信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <linkAccount class="inline-16" v-if="tool.checkAuth($route.name,'update')"  :data="mainData"  @onSuccess="queryMainData"></linkAccount>
        <createUser class="inline-16" v-if="tool.checkAuth($route.name,'update') && !mainData.userid" :data="mainData"  @onSuccess="queryMainData"></createUser>
        <restPas v-if="tool.checkAuth($route.name,'restpas')" :userid="mainData.userid" class="inline-16"></restPas>
      </div>
      <div class="container normal-panel" slot="slot0" >
        <baseInfo :mainInfo="mainData"></baseInfo>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import baseInfo from './modules/main.vue'
import restPas from "./modules/restPassword.vue"
import linkAccount from "./modules/linkAccount.vue"
import createUser from "./modules/createUser.vue"
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{}
    }
  },
  components:{
    baseInfo,
    restPas,
    linkAccount,
    createUser
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "classname": "webmanage.hr.hr",
        "method": "query_hrMain",
        "content": {
          "hrid":this.$route.query.id
        }
      })
      this.mainData = res.data
      this.$refs['details'].param.content.containssub = 1
      this.$refs['details'].param.content.departmentids = [this.$route.query.depid]
      this.changeDataStructure()
    },
    changeDataStructure() {
      this.mainAreaData = [
        {
          label:'电话',
          value:this.mainData.accountno !== ''?this.mainData.userphonenumber:this.mainData.phonenumber
        },
        {
          label:'办公电话',
          value:this.mainData.officetelephone
        },
        {
          label:'部门',
          value:this.mainData.depname
        },
        {
          label:'职位',
          value:this.mainData.position
        },
        {
          label:'是否部门负责人',
          value:this.mainData.isleader === 1?'是':'否'
        },
        {
          label:'电子邮箱',
          value:this.mainData.email
        },
        {
          label:'汇报对象',
          value:this.mainData.reporthrname
        },
        {
          label:'身份证号',
          value:this.mainData.idcard
        },
        {
          label:'性别',
          value:this.mainData.sex
        },
        {
          label:'是否服务人员',
          value:this.mainData.isworker === 1?'是':'否'
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/depManage/staffDetail',query:{id:id,rowindex:rowindex,depid:this.$route.query.depid}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>