<template>
  <view>
    <CuNavbar title="升职申请">
      <template v-if="data.promotion_status > 2" #right>
        <view class="text-sm text-white" @click="checkLogs">审核流程</view>
      </template>
    </CuNavbar>
    <uv-sticky bgColor="white">
      <view class="px-base box-shadow text-28rpx">
        <view class="px-base">
          <BaseData :data="data" :colums="titleColumns" />
        </view>
      </view>
    </uv-sticky>
    <view class="p-base">
      <view class="card-shadow px-base">
        <BaseData :data="data" :colums="columns" />
      </view>
    </view>
  </view>
</template>
<script setup>
import CuNavbar from '@/components/cu-navbar/index'
import BaseData from '../audits/base-data.vue'
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { http } from '@/utils/request'
import statusFun from '@/utils/status'

const data = ref({})

const titleColumns = [
  { title: '晋升职位', dataIndex: 'job.name' },
  { title: '申请人', dataIndex: 'employee.name' },
  { title: '推荐人', dataIndex: 'invitor.name' },
  { title: '状态', dataIndex: 'promotion_status', format: (value) => statusFun(value, 'promotion_status', 'name') },
]

const columns = [
  { title: '年龄', dataIndex: 'employee_data.age' },
  { title: '性别', dataIndex: 'employee_data.sex' },
  { title: '学历', dataIndex: 'employee_data.education' },
  { title: '首次参加工作时间', dataIndex: 'employee_data.first_work_time' },
  { title: '工作年限', dataIndex: 'employee_data.work_years' },
  { title: '本公司工作年限', dataIndex: 'employee_data.work_years_in_company' },
  { title: '员工自评', dataIndex: 'employee_data.comment_self', labelPosition: 'top' },
  { title: '未来计划', dataIndex: 'employee_data.plans', labelPosition: 'top' },
  { title: '推荐理由', dataIndex: 'employee_data.reason', labelPosition: 'top' },
  { title: '未通过原因', dataIndex: 'workflow_check.check_remarks', labelPosition: 'top', isShow: (row) => row?.workflow_check?.check_status == 4 }
]

onLoad((options) => {
  http.get(`/hr/promotion/${options.id}`).then(res => {
    data.value = res
  })
})

const checkLogs = () => {
  if (data.value.workflow_check.id) {
    return uni.navigateTo({
      url: `/pages/audits/log?id=${data.value.workflow_check.id}`
    })
  }
}


</script>
