<!-- 委托方情况报告列表 --> <script name="SituationReportList" lang="ts" setup> import { ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { DateModelType } from 'element-plus' import type { IListQuery, ISituationReportInfo } from './customer-report' import type { TableColumn } from '@/components/NormalTable/table_interface' import { deleteSituationReport, getSituationReportList } from '@/api/resource/situationReport' const { proxy } = getCurrentInstance() as any const router = useRouter() // 右上角菜单 const menu = [ { id: '1', value: '1', name: '草稿箱', }, { id: '2', value: '2', name: '全部', }, ] const active = ref('') // 是否为草稿箱(1/2) // 查询条件 const searchQuery = ref<IListQuery>({ reportNo: '', // 报告单编号 createUserName: '', // 拟制人名字 createTimeStart: '', // 创建时间-起始 createTimeEnd: '', // 创建时间-结束 draft: '', offset: 1, limit: 20, }) const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '报告单编号', value: 'reportNo', align: 'center', width: '240' }, { text: '报告单名称', value: 'reportName', align: 'center', width: '240' }, { text: '委托方名称', value: 'customerName', align: 'center' }, { text: '拟制人', value: 'createUserName', align: 'center', width: '240' }, { text: '拟制时间', value: 'createTime', align: 'center', width: '180' }, ]) const reportList = ref<Array<ISituationReportInfo>>([]) // 表格数据 const reset = () => { searchQuery.value = { reportNo: '', // 报告单编号 createUserName: '', // 拟制人名字 createTimeStart: '', // 创建时间-起始 createTimeEnd: '', // 创建时间-结束 draft: '', offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } const searchList = () => { fetchData(true) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } searchQuery.value.draft = active.value getSituationReportList(searchQuery.value).then((response) => { if (response.code === 200) { reportList.value = response.data.rows total.value = parseInt(response.data.total) } loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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(true) } const addSituationReport = () => { router.push({ query: { type: 'create', }, path: 'situationReport/detail', }) } // 点击编辑按钮 const updateInfo = (row: ISituationReportInfo) => { sessionStorage.setItem('situationReportInfo', JSON.stringify(row)) router.push({ query: { type: 'update', id: row.id, }, path: 'situationReport/detail', }) } const detail = (row: ISituationReportInfo) => { // 将行数据存入缓存 用来在路由之间传递数据 sessionStorage.setItem('situationReportInfo', JSON.stringify(row)) if (active.value === '1') { // 草稿箱 router.push({ query: { type: 'detail', id: row.id, }, path: 'situationReport/detail', }) } else { router.push({ query: { type: 'detail', id: row.id, }, path: `situationReportDoc/detail/${row.id}`, }) } } const deleteReportById = (row: ISituationReportInfo) => { ElMessageBox.confirm( `确认删除情况报告 ${row.reportNo} 吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { deleteSituationReport({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success(`情况报告 ${row.reportNo} 删除成功`) fetchData(true) } else { ElMessage.error(`情况报告 ${row.reportNo} 删除失败:${res.message}`) } }) }) } 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 = '' } }) // 切换tab状态 const changeCurrentButton = (val: string) => { active.value = val // clearList() fetchData() } onMounted(async () => { active.value = '1' searchList() }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model="searchQuery.reportNo" placeholder="报告单编号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.createUserName" 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 #btns-right> <icon-button v-if="proxy.hasPerm('/resource/customer/situationReport/add')" icon="icon-add" title="新建" @click="addSituationReport" /> </template> <!-- 表格区域 --> <normal-table :data="reportList" :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 v-if="proxy.hasPerm('/resource/customer/situationReport/edit') && active === '1'" size="small" type="primary" link @click="updateInfo(row)"> 编辑 </el-button> <el-button size="small" type="primary" link @click="detail(row)"> 详情 </el-button> <el-button v-if="proxy.hasPerm('/resource/customer/situationReport/del') && active === '1'" size="small" type="danger" link @click="deleteReportById(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> <!-- 右上角按钮集合 --> <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" /> </table-container> </app-container> </template>