|
|
@@ -0,0 +1,317 @@
|
|
|
+<script setup lang="tsx">
|
|
|
+import { reactive, ref, unref } from 'vue'
|
|
|
+import { getWorkerGroup, addWorkerGroup, putWorkerGroup, delWorkerGroup } 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/workerWrite.vue'
|
|
|
+import { BaseButton } from '@/components/Button'
|
|
|
+import { ElMessage, ElDivider, ElMessageBox } from 'element-plus'
|
|
|
+import { Dialog } from '@/components/Dialog'
|
|
|
+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 getWorkerGroup({
|
|
|
+ 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: 'name',
|
|
|
+ label: '组名称',
|
|
|
+ minWidth: 100
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'phone',
|
|
|
+ label: '手机号',
|
|
|
+ minWidth: 120
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'province',
|
|
|
+ label: '省',
|
|
|
+ align: 'center',
|
|
|
+ headerAlign: 'center',
|
|
|
+ minWidth: 100
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'city',
|
|
|
+ align: 'center',
|
|
|
+ headerAlign: 'center',
|
|
|
+ label: '市',
|
|
|
+ minWidth: 60
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'area',
|
|
|
+ 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: '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 putWorkerGroup(data)
|
|
|
+ } else if (actionType.value === '') {
|
|
|
+ res = await addWorkerGroup(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 delWorkerGroup(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>
|