<!-- 选择通知文件弹窗 --> <script name="FileSelectDialog" lang="ts" setup> import { ElMessage, ElMessageBox } from 'element-plus' import type { IFileApprovalForm } from '../approval/approval-interface' import type { IFileFilterQuery } from './notice-interface' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getFileApprovalFormList } from '@/api/resource/fileApproval' const emit = defineEmits(['recordSelected']) const searchQuery = ref<IFileFilterQuery>({ fileNo: '', // 文件编号 fileName: '', approvalStatus: '0', // 审批通过 formId: 'zyglwjsp', // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 10, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading const fileList = ref<Array<IFileApprovalForm>>([]) // 表格数据 const fileColumns = ref<Array<TableColumn>>([ { text: '审批编号', value: 'approvalNo', align: 'center', width: '180' }, { text: '文件编号', value: 'fileNo', align: 'center' }, { text: '文件名称', value: 'fileName', align: 'center' }, { text: '版本号', value: 'fileVersion', align: 'center', width: '180' }, ]) // 表头 const refFileTabel = ref() const fileSelected = ref<IFileApprovalForm[]>([]) const showDialog = ref(false) // 逻辑 // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } getFileApprovalFormList(searchQuery.value).then((res) => { if (res.code === 200) { fileList.value = res.data.rows total.value = parseInt(res.data.total) } }) 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(true) } // 重置 const reset = () => { searchQuery.value = { fileNo: '', // 文件编号 fileName: '', approvalStatus: '0', // 审批通过 formId: 'zyglwjsp', // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 10, } fetchData(true) } const fileMultiSelect = (e: any) => { console.log(e) fileSelected.value = e } const showRecordDialog = (show: boolean) => { showDialog.value = show if (show === false) { searchQuery.value = { fileNo: '', // 文件编号 fileName: '', approvalStatus: '0', // 审批通过 formId: 'zyglwjsp', // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值 offset: 1, limit: 10, } fileSelected.value = [] refFileTabel.value.clearMulti() } else { searchList() } } const fileSelectConfirmed = () => { if (fileSelected.value.length === 0) { ElMessage.warning('请至少选择一行') } else { ElMessageBox.prompt('请输入文件更改内容', '选中文件', { confirmButtonText: '确定', cancelButtonText: '取消', inputType: 'textarea', inputPattern: /.+?/, inputErrorMessage: '文件更改内容不能为空', }).then(({ value }) => { emit('recordSelected', fileSelected.value, value) showRecordDialog(false) }).catch(() => {}) } } defineExpose({ showRecordDialog, }) </script> <template> <el-dialog v-model="showDialog" title="选择文件" :append-to-body="true" :close-on-click-modal="false" width="75%"> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model="searchQuery.fileNo" placeholder="文件编号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.fileName" placeholder="文件名称" clearable /> </search-item> </search-area> <table-container title="文件列表"> <normal-table ref="refFileTabel" :data="fileList" :total="total" :columns="fileColumns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" :is-showmulti-select="true" :is-multi="false" @change="changePage" @multi-select="fileMultiSelect" > <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> </normal-table> </table-container> <template #footer> <span class="dialog-footer"> <el-button @click="showRecordDialog(false)">取消</el-button> <el-button type="primary" @click="fileSelectConfirmed"> 保存 </el-button> </span> </template> </el-dialog> </template>