<!-- 委托方名录 --> <script name="CustomerInfoList" lang="ts" setup> import type { DateModelType } from 'element-plus' import dayjs from 'dayjs' import { ElMessage, ElMessageBox } from 'element-plus' import type { ICustomerInfo, IDictType, IListQuery } from './customer-info' import CustomerApprovalDialog from './customerApprovalDialog.vue' import type { IMenu } from '@/components/buttonBox/buttonBox' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { draftDelete, getCustomerInfoList } from '@/api/resource/customer' // 定义常量 const buttonBoxActive = 'customerInfoApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 const flowFormId = 'zyglwtfml' const { proxy } = getCurrentInstance() as any const router = useRouter() // 选中的审批状态按钮 const active = ref('') const menu = ref<IMenu[]>([]) // 审批状态按钮组合 const approvalStatusList = ref<String[]>([ '全部', '已审批', '草稿箱', '待审批', '审批中', '已通过', '未通过', '已取消', '我的审批单', ]) // 弹窗子组件 const apprDial = ref() // 查询条件 const searchQuery = ref<IListQuery>({ customerNo: '', // 委托方编号 customerName: '', // 委托方名字 contacts: '', // 联系人 createTimeStart: '', // 创建时间-起始 createTimeEnd: '', // 创建时间-结束 approvalStatus: active.value, // 审批状态 formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 20, }) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '委托方编号', value: 'customerNo', align: 'center', width: '175' }, { text: '委托方名称', value: 'customerName', align: 'center' }, { text: '联系人', value: 'contacts', align: 'center', width: '120' }, { text: '座机电话', value: 'mobile', align: 'center', width: '140' }, { text: '手机号码', value: 'phone', align: 'center', width: '125' }, { text: '地址', value: 'address', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center', width: '160' }, { text: '审批状态', value: 'approvalStatusName', align: 'center', width: '100' }, ]) const customerInfoList = ref<Array<ICustomerInfo>>([]) // 表格数据 // 逻辑 // 跳转到新建的页面 const addCustomerInfo = () => { router.push({ query: { type: 'create', }, path: '/customer/info/detail', }) } // 点击编辑按钮 const updateInfo = (row: ICustomerInfo) => { sessionStorage.setItem('customerInfo', JSON.stringify(row)) router.push({ query: { type: 'update', id: row.id, status: searchQuery.value.approvalStatus, }, path: '/customer/info/detail', }) } // 点击查看(或编辑)按钮 const detail = (row: ICustomerInfo) => { if (searchQuery.value.approvalStatus === '1') { // 全部或草稿箱 状态的 查看 是可以编辑的组件 updateInfo(row) } else { // 将行数据存入缓存 用来在路由之间传递数据 sessionStorage.setItem('customerInfo', JSON.stringify(row)) router.push({ query: { type: 'detail', id: row.id, status: searchQuery.value.approvalStatus, }, path: '/customer/info/detail', }) } } // 删除委托方名录 或 删除草稿箱中的审批单 const deleteById = (row: any) => { const confirmStr = `${active.value}` === '0' ? `委托方${row.customerName}` : `委托方审批单${row.customerNo}` ElMessageBox.confirm(`是否删除${confirmStr}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { draftDelete({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success(`${confirmStr} 删除成功`) fetchData() } else { ElMessage.error(`${confirmStr} 删除失败: ${res.message}`) } }) }) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } getCustomerInfoList(searchQuery.value).then((response) => { if (response.data.total === 0) { // 测试用mock数据 customerInfoList.value.length = 0 customerInfoList.value.push({ id: 'string', customerNo: 'string', customerName: 'string', deptId: 'string', customerLocation: 'string', customerLocationName: 'string', contacts: 'string', mobile: 'string', phone: 'string', postalCode: 'string', address: 'string', }) } else { customerInfoList.value = response.data.rows.map((item: { createTime: string }) => { return { ...item, createTime: item.createTime.length > 16 ? item.createTime.substring(0, 16) : '', } }) } total.value = parseInt(response.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } const searchList = () => { fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData() } // 重置 const reset = () => { searchQuery.value = { customerNo: '', // 委托方编号 customerName: '', // 委托方名字 contacts: '', // 联系人 createTimeStart: '', // 创建时间-起始 createTimeEnd: '', // 创建时间-结束 approvalStatus: active.value, // 审批状态 formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 审批按钮点击切换事件 const changeCurrentButton = (val: string) => { active.value = val // 此时的tab window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态 reset() // 刷新 } // 流程审批-同意 const approvalAgreeHandler = (row: ICustomerInfo) => { apprDial.value.initDialog('agree', row.id, row.taskId, '') } // 流程审批-拒绝 const approvalRefuseHandler = (row: ICustomerInfo) => { apprDial.value.initDialog('refuse', row.id, row.taskId, '') } // 取消(撤回审批单) const revokeApprById = (row: ICustomerInfo) => { apprDial.value.initDialog('revoke', row.id, row.taskId, row.processId) } // 流程操作之后刷新 const afterApprovalHandler = () => { fetchData(true) } // 初始化流程审批状态按钮 const getApprovalStatusDict = () => { getDictByCode('approvalStatus').then((res) => { if (res.code === 200) { res.data.forEach((item: IDictType) => { if (approvalStatusList.value.includes(item.name)) { menu.value.push({ name: item.name, id: `${item.value}`, }) } }) } }) } const getDict = async () => { getApprovalStatusDict() } watch(dateRange, (val) => { if (val) { searchQuery.value.createTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD') searchQuery.value.createTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD') } else { searchQuery.value.createTimeStart = '' searchQuery.value.createTimeEnd = '' } }) onMounted(async () => { await getDict() if (sessionStorage.getItem(buttonBoxActive) !== 'undefined') { active.value = sessionStorage.getItem(buttonBoxActive)! } else { active.value = '0' // 全部 } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model="searchQuery.customerNo" placeholder="委托方编号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.customerName" placeholder="委托方名称" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.contacts" placeholder="联系人" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" start-placeholder="创建时间(开始)" end-placeholder="创建时间(结束)" /> </search-item> </search-area> <!-- 表格数据展示 --> <table-container> <!-- 表头区域 --> <template v-if="active === '0'" #btns-right> <icon-button icon="icon-add" title="新建" @click="addCustomerInfo" /> </template> <!-- 表格区域 --> <normal-table id="customerInfoTabel" :data="customerInfoList" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column fixed="right" label="操作" align="center" width="130"> <template #default="{ row }"> <el-button size="small" type="primary" link @click="detail(row)"> 查看 </el-button> <el-button v-if="active === '0'" size="small" type="primary" link @click="updateInfo(row)"> 编辑 </el-button> <el-button v-if="active === '0' && proxy.hasPerm(`/resource/customer/infoList/del`)" size="small" type="danger" link @click="deleteById(row)"> 删除 </el-button> <el-button v-if="(active === '1' || active === '6') && proxy.hasPerm(`/resource/customer/infoList/delAppr`)" size="small" type="danger" link @click="deleteById(row)"> 删除2 </el-button> <template v-if="active === '2'"> <el-button size="small" type="primary" link @click="approvalAgreeHandler(row)"> 同意 </el-button> <el-button size="small" type="primary" link @click="approvalRefuseHandler(row)"> 拒绝 </el-button> </template> <template v-if="active === '3'"> <el-button size="small" type="primary" link @click="revokeApprById(row)"> 取消 </el-button> </template> </template> </el-table-column> </template> </normal-table> </table-container> <!-- 审批单弹窗 --> <customer-approval-dialog ref="apprDial" @on-success="afterApprovalHandler" /> <!-- 右上角按钮集合 --> <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" /> </app-container> </template>