<template>
  <v-card class="pa-5 card-box">
    <div class="d-flex justify-space-between">
      <v-tabs v-model="tab" 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="tab" class="mt-1">
      <v-window-item v-for="k in tabList" :value="k.value" :key="k.value">
        <TablePage :items="items" :tab="k.value" :tabList="tabList" @refresh="getList" @radio="handleSelect" @reset="handleReset"></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 { getHireJobCvPage } from '@/api/recruit/public/delivery'
import { dealDictObjData } from '@/utils/position'
import TablePage from './components/table.vue'

const total = ref(0)
const query = ref({
  pageNo: 1,
  pageSize: 10,
  status: null
})
const tab = ref(0)
const items = ref([])
const tabList = ref([
  { label: '简历投递', value: 0, status: null },
  { label: '已邀约', value: 1, status: 2 },
  { label: '已入职', value: 2, status: 3 },
  { label: '已结算', value: 3, status: 4 },
  { label: '不合适', value: 4, status: 99 }
])
const textItems = ref({
  type: 'text',
  value: '',
  width: 250,
  label: '搜索姓名',
  clearable: true,
  appendInnerIcon: 'mdi-magnify'
})

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 handleSelect = (e) => {
  query.value.status = e
  query.value.pageNo = 1
  getList()
}

const handleReset = () => {
  query.value.status = null
  query.value.pageNo = 1
  getList()
}

// tab
const handleUpdateTab = () => {
  query.value.status = tabList.value.find(e => e.value === tab.value).status
  query.value.pageNo = 1
  getList()
}

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

<style scoped lang="scss">
</style>
