<template>
  <el-card shadow="never">
    <template #header>
      <CardTitle :title="props.title" />
    </template>
		<el-table v-loading="loading" :data="list" :stripe="true">
			<el-table-column label="发布企业" align="center" prop="enterprise.name">
        <template #default="scope">{{ formatName(scope.row.enterprise.anotherName || scope.row.enterprise.name) }}</template>
      </el-table-column>
      <el-table-column label="职位名称" align="center" prop="name">
        <template #default="scope">{{ formatName(scope.row.name) }}</template>
      </el-table-column>
			<el-table-column label="薪资" align="center" prop="payFrom">
        <template #default="scope">{{ scope.row.payFrom && scope.row.payTo ? scope.row.payFrom + '-' + scope.row.payTo + '/' + getIntDictOptions(DICT_TYPE.MENDUNER_PAY_UNIT).find(e => e.value === Number(scope.row.payUnit))?.label : '面议' }}</template>
      </el-table-column>
      <el-table-column label="工作经验" align="center" prop="expType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MENDUNER_EXP_TYPE" :value="scope.row.expType" />
        </template>
      </el-table-column>
      <el-table-column label="学历要求" align="center" prop="eduType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MENDUNER_EDUCATION_TYPE" :value="scope.row.eduType" />
        </template>
      </el-table-column>
			<el-table-column label="地区" align="center" prop="areaId">
        <template #default="scope">{{ !scope.row.areaId ? '全国' : scope.row.area.str }}</template>
      </el-table-column>
			<el-table-column label="更新时间" align="center" prop="updateTime" :formatter="dateFormatter" width="180px" />
      <el-table-column label="发布时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
		/>
  </el-card>
</template>

<script lang="ts" setup>
defineOptions({name: 'EnterpriseJob'})
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { JobFairManageApi } from '@/api/menduner/system/jobFair/manage'
import { formatName } from '@/utils'

const props = defineProps({
  title: {
    type: String,
    default: () => ''
  },
  query: {
    type: Object,
    default: () => {}
  }
})

const total = ref(0)
const loading = ref(false)
const list = ref([])
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10
})

const getList = async () => {
	const result = await JobFairManageApi.getEnterpriseJob(Object.assign(queryParams, props.query))

	list.value = result.list
	total.value = result.total
}

watch(() => props.query, () => {
	getList()
}, { deep: true, immediate: true })
</script>
