<template>
  <div class="card-edit">
    <a-divider orientation="left">岗位基础信息</a-divider>
    <a-descriptions bordered>
      <a-descriptions-item label="企业名称">{{ postInfo.companyName }}</a-descriptions-item>
      <a-descriptions-item label="岗位名称">{{ postInfo.professionName }}</a-descriptions-item>
      <a-descriptions-item label="招聘人数">{{ postInfo.recruitCount }}</a-descriptions-item>
      <a-descriptions-item label="招聘日期">
        {{ postInfo.startTime ? dayjs(postInfo.startTime).format('YYYY-MM-DD') : '' }}
        至
        {{ postInfo.endTime ? dayjs(postInfo.endTime).format('YYYY-MM-DD') : '' }}
      </a-descriptions-item>
      <a-descriptions-item :span="3" label="招聘地点">{{ postInfo.jobPlace }}</a-descriptions-item>
    </a-descriptions>
    <a-divider orientation="left">其他信息</a-divider>
    <a-descriptions bordered>
      <a-descriptions-item label="岗位月薪（元）">
        {{ postInfo.minSalary }}
        至
        {{ postInfo.maxSalary }}
      </a-descriptions-item>
      <a-descriptions-item label="是否有试用期">{{ postInfo.isTrail ? '是' : '否' }}</a-descriptions-item>
      <a-descriptions-item label="试用期（月）">{{ postInfo.trailMonths }}</a-descriptions-item>
      <a-descriptions-item label="试用期月薪（元）">
        {{ postInfo.trailMinSalary }}
        至
        {{ postInfo.trailMaxSalary }}
      </a-descriptions-item>
      <a-descriptions-item label="工作年限要求">{{ workYear }}</a-descriptions-item>
      <a-descriptions-item label="学历要求">{{ postInfo.cultureLevelName }}</a-descriptions-item>
      <a-descriptions-item :span="3" label="福利待遇">{{ postInfo.welfare }}</a-descriptions-item>
      <a-descriptions-item :span="3" label="其他要求">{{ postInfo.postDesc }}</a-descriptions-item>
    </a-descriptions>
  </div>
</template>

<script setup lang="ts">
import {getPostByID} from "@/api/companyService/post";
import {computed, onMounted, reactive, ref} from "vue";
import dayjs from "dayjs";
import {get} from "@/api/common";

// 岗位信息
const postInfo = reactive({
  companyName: "",
  professionName: "",
  recruitCount: "",
  startTime: "",
  endTime: "",
  jobPlace: "",
  minSalary: "",
  maxSalary: "",
  isTrail: "",
  trailMonths: "",
  trailMinSalary: "",
  trailMaxSalary: "",
  workYear: "",
  cultureLevelName: "",
  welfare: "",
  postDesc: "",
})
// 工作年限数据
const WorkYearTypeList = ref<Array<any>>([])
// 获取工作年限
const workYear = computed(() => {
  if (postInfo.workYear && WorkYearTypeList.value.length > 0) {
    const item = WorkYearTypeList.value.find(item => item.value == postInfo.workYear)
    if (item) {
      return item.name;
    }
  }
  return postInfo.workYear;
})

// 数据加载
function loadData(id: any) {
  getPostByID(id).then(result => {
    Object.keys(postInfo).forEach((key) => {

      postInfo[key] = result[key];
    })
  })
}

// 页面初始化
onMounted(() => {
  const id = history.state.params?.id;
  loadData(id);
  get('system/dictionary/getDictionaryItemByCodeList', {code: 'WorkYearType'}).then(result => {
    WorkYearTypeList.value = result;
  });
})
</script>

<style scoped>

</style>
