| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- <script setup lang="tsx">
- import { reactive, ref, unref } from 'vue'
- import { getWorker, addWorker, putWorker, delWorker } from '@/api/staff'
- import { useTable } from '@/hooks/web/useTable'
- import { useI18n } from '@/hooks/web/useI18n'
- import { Table, TableColumn } from '@/components/Table'
- import { Search } from '@/components/Search'
- import { FormSchema } from '@/components/Form'
- import { ContentWrap } from '@/components/ContentWrap'
- import Write from './components/Write.vue'
- import { BaseButton } from '@/components/Button'
- import { ElMessage, ElDivider, ElMessageBox, ElTag } from 'element-plus'
- import { Dialog } from '@/components/Dialog'
- import { TableImage } from '@/components/tableImage'
- import { designerData, designerSearch } from '@/api/staff/types'
- import { formatToDate } from '@/utils/dateUtil'
- const { t } = useI18n()
- const { tableRegister, tableState, tableMethods } = useTable({
- fetchDataApi: async () => {
- const { pageSize, currentPage } = tableState
- const res = await getWorker({
- page: unref(currentPage) || 1,
- limit: unref(pageSize) || 10,
- ...unref(searchParams)
- })
- return {
- list: res.data.list,
- total: res.data.count || 0
- }
- }
- })
- const { dataList, loading, total, currentPage, pageSize } = tableState
- const { getList } = tableMethods
- const tableColumns = reactive<TableColumn[]>([
- {
- field: 'id',
- label: 'ID',
- align: 'center',
- width: 70
- },
- {
- field: 'avatar',
- label: '头像',
- width: 80,
- slots: {
- default: ({ row }: any) => {
- return (
- <>
- <TableImage src={row.avatar} />
- </>
- )
- }
- }
- },
- {
- field: 'name',
- label: '姓名',
- minWidth: 100
- },
- {
- field: 'phone',
- label: '手机号',
- minWidth: 120
- },
- {
- field: 'start_job_year',
- label: '就业年份',
- align: 'center',
- headerAlign: 'center',
- minWidth: 100
- },
- {
- field: 'gender_chs',
- align: 'center',
- headerAlign: 'center',
- label: '性别',
- minWidth: 60
- },
- {
- field: 'area',
- label: '区域',
- minWidth: 200,
- slots: {
- default: ({ row }: any) => {
- return (
- <>
- {row.province_text} {row.city_text} {row.area_text}
- </>
- )
- }
- }
- },
- {
- field: 'detail_address',
- label: '定位',
- minWidth: 200
- },
- {
- field: 'tag_list_chs',
- label: '标签',
- minWidth: 100,
- slots: {
- default: ({ row }: any) => {
- return (
- <>
- {row.tag_list_chs.map((item: any) => {
- return (
- <>
- <ElTag type="primary">{item}</ElTag>
- </>
- )
- })}
- </>
- )
- }
- }
- },
- {
- field: 'action',
- label: t('userDemo.action'),
- width: 110,
- align: 'center',
- headerAlign: 'center',
- fixed: 'right',
- slots: {
- default: (data: any) => {
- const row = data.row
- return (
- <>
- <BaseButton link size="small" type="primary" onClick={() => action(row, 'edit')}>
- {t('exampleDemo.edit')}
- </BaseButton>
- <ElDivider direction="vertical" />
- <BaseButton link size="small" type="danger" onClick={() => delAction(row)}>
- {t('exampleDemo.del')}
- </BaseButton>
- </>
- )
- }
- }
- }
- ])
- const searchSchema = reactive<FormSchema[]>([
- {
- field: 'gender',
- label: '性别',
- component: 'Select',
- value: '',
- componentProps: {
- placeholder: '性别',
- options: [
- {
- label: '全部',
- value: ''
- },
- {
- label: '保密',
- value: 0
- },
- {
- label: '男',
- value: 1
- },
- {
- label: '女',
- value: 2
- }
- ]
- }
- },
- {
- field: 'tag_list',
- label: '标签',
- component: 'Input',
- value: '',
- componentProps: {
- placeholder: '请输入搜索标签'
- }
- },
- {
- field: 'name',
- label: '姓名',
- component: 'Input',
- value: '',
- componentProps: {
- placeholder: '请输入姓名'
- }
- }
- ])
- const searchParams = ref<designerSearch>({
- gender: '',
- tag_list: '',
- name: ''
- })
- const setSearchParams = (data: any) => {
- searchParams.value = data
- getList()
- }
- const dialogVisible = ref(false)
- const currentRow = ref()
- const dialogTitle = ref('')
- const actionType = ref('')
- const writeRef = ref<ComponentRef<typeof Write>>()
- const saveLoading = ref(false)
- const action = async (row: any, type: string) => {
- dialogTitle.value = t(type === 'edit' ? 'exampleDemo.edit' : 'exampleDemo.detail')
- actionType.value = type
- currentRow.value = {
- name: row.name,
- uid: row.uid,
- id: row.id,
- phone: row.phone,
- avatar: [row.avatar],
- gender: row.gender,
- birth_day_time: formatToDate(row.birth_day_time * 1000),
- province: row.province,
- city: row.city,
- area: row.area,
- tag_list: row.tag_list.split(','),
- longitude: row.longitude,
- latitude: row.latitude,
- detail_address: row.detail_address,
- start_job_year: row.start_job_year
- }
- dialogVisible.value = true
- }
- const AddAction = () => {
- dialogTitle.value = t('exampleDemo.add')
- currentRow.value = undefined
- dialogVisible.value = true
- actionType.value = ''
- }
- const save = async () => {
- const write = unref(writeRef)
- const formData = await write?.submit()
- if (formData) {
- saveLoading.value = true
- const data: designerData = {
- name: formData.name,
- uid: formData.uid,
- phone: formData.phone,
- avatar: formData.avatar[0],
- gender: formData.gender,
- birth_day_time: formatToDate(formData.birth_day_time),
- province: formData.province,
- city: formData.city,
- area: formData.area,
- tag_list: formData.tag_list,
- longitude: formData.longitude,
- latitude: formData.latitude,
- detail_address: formData.detail_address,
- start_job_year: formData.start_job_year
- }
- try {
- let res: any = {}
- if (actionType.value === 'edit') {
- data.id = formData.id
- res = await putWorker(data)
- } else if (actionType.value === '') {
- res = await addWorker(data)
- }
- if (res?.status === 200) {
- ElMessage({
- showClose: true,
- message: '保存成功',
- type: 'success'
- })
- getList()
- dialogVisible.value = false
- }
- } catch (error) {
- console.log(error)
- } finally {
- saveLoading.value = false
- }
- }
- }
- const delAction = (row: any) => {
- ElMessageBox.confirm('删除后无法恢复,是否删除?', {
- confirmButtonText: '删除',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- const re = await delWorker(row.id)
- if (re) {
- ElMessage({
- showClose: true,
- message: '删除成功',
- type: 'success'
- })
- }
- await getList()
- })
- .catch(() => {})
- }
- </script>
- <template>
- <ContentWrap>
- <div class="searchBox">
- <Search :schema="searchSchema" @reset="setSearchParams" @search="setSearchParams" />
- </div>
- <div class="mb-10px">
- <BaseButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</BaseButton>
- </div>
- <Table
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :columns="tableColumns"
- default-expand-all
- node-key="id"
- stripe
- :data="dataList"
- :loading="loading"
- @register="tableRegister"
- :pagination="{
- total
- }"
- />
- </ContentWrap>
- <Dialog v-model="dialogVisible" :title="dialogTitle" width="900px" max-height="700px">
- <Write v-if="actionType !== 'detail'" ref="writeRef" :current-row="currentRow" />
- <template #footer>
- <BaseButton
- v-if="actionType !== 'detail'"
- type="primary"
- :loading="saveLoading"
- @click="save"
- >
- {{ t('exampleDemo.save') }}
- </BaseButton>
- <BaseButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</BaseButton>
- </template>
- </Dialog>
- </template>
- <style lang="less">
- .searchBox {
- max-width: 1000px;
- }
- </style>
|