<template>
  <v-card class="pa-5 card-box">
    <div class="d-flex justify-space-between">
      <v-tabs v-model="query.status" align-tabs="start" color="primary" bg-color="#f7f8fa" @update:model-value="handleUpdateTab">
        <v-tab v-for="k in tabList" :value="k.value" :key="k.value">{{ k.label }}</v-tab>
      </v-tabs>
      <TextInput v-model="textItems.value" :item="textItems" @appendInnerClick="handleSearch" @enter="handleSearch"></TextInput>
    </div>

    <v-window v-model="query.status" class="mt-1">
      <v-window-item v-for="k in tabList" :value="k.value" :key="k.value">
        <TablePage :items="items" :tab="k.value" @refresh="getList"></TablePage>
        <CtPagination
          v-if="total > 0"
          :total="total"
          :page="query.pageNo"
          :limit="query.pageSize"
          @handleChange="handleChangePage"
        ></CtPagination>
      </v-window-item>
    </v-window>
  </v-card>
</template>

<script setup>
defineOptions({ name: 'public-recruitment-deliver'})
import { ref } from 'vue'
import { getDict } from '@/hooks/web/useDictionaries'
import { getHireJobCvPage } from '@/api/recruit/public/delivery'
import { dealDictObjData } from '@/views/recruit/personal/position/components/dict'
import TablePage from './components/table.vue'

const total = ref(0)
const query = ref({
  pageNo: 1,
  pageSize: 10,
  status: '0'
})
const items = ref([])
const tabList = ref([])
const textItems = ref({
  type: 'text',
  value: '',
  width: 250,
  label: '搜索姓名',
  clearable: true,
  appendInnerIcon: 'mdi-magnify'
})

// 获取tab列表项
const getTabData = () => {
  getDict('menduner_hire_job_cv_status').then(({ data }) => {
    data = data?.length && data || []
    tabList.value = data
  })
}
getTabData()

const getList = async () => {
  const res = await getHireJobCvPage(query.value)
  if (!res.list.length) {
    items.value = []
    total.value = 0
    return
  }
  items.value = res.list.map(e => {
    let obj = e
    obj.person = Object.assign(e.person, dealDictObjData({}, e.person))
    obj.job = Object.assign(e.job, dealDictObjData({}, e.job))
    return obj
  })
  total.value = res.total
}
getList()

const handleSearch = () => {
  if (textItems.value.value) query.value.name = textItems.value.value
  else delete query.value.name
  query.value.pageNo = 1
  getList()
}

const handleUpdateTab = () => {
  query.value.pageNo = 1
  getList()
}

// 分页
const handleChangePage = (i) => {
  query.value.pageNo = i
  getList()
}
</script>

<style scoped lang="scss">

</style>
