<template> <!-- 考核问题原因库配置 --> <div class="causePage"> <div class="searchBoxs"> <n-space> <n-select v-model:value="searchVal1" :options="examineOptions" placeholder="工程类型" filterable clearable @update:value="changeType(searchVal1)" ></n-select> <n-select v-model:value="searchVal2" :options="zbOptions" placeholder="指标名称" filterable clearable> </n-select> <n-button type="primary" @click="handleClick('search')"> <template #icon> <n-icon><Search /> </n-icon> </template> 搜索 </n-button> <n-button type="primary" @click="handleClick('add')"> <template #icon> <n-icon><Add /> </n-icon> </template> 新增 </n-button> </n-space> </div> <!-- 表格 --> <div class="tableBox"> <n-data-table :bordered="false" :max-height="700" striped :columns="columns" :data="tableData" :loading="tableLoading" :remote="true" :pagination="pagination" > </n-data-table> </div> <!-- 新增修改弹窗 --> <n-modal :title="modalTitle" :mask-closable="false" preset="dialog" :show-icon="false" :style="{ width: '600px' }" v-model:show="modalShow" > <n-form ref="formRef" :label-width="100" label-align="right" require-mark-placement="left" :rules="formInfo.rules" :model="formInfo.data" label-placement="left" > <n-form-item label="工程类型:" path="codeId"> <n-select v-model:value="formInfo.data.codeId" :options="examineOptions" filterable @update:value="changeType(formInfo.data.codeId)" ></n-select> </n-form-item> <n-form-item label="指标名称:" path="indexId"> <n-select v-model:value="formInfo.data.indexId" :options="zbOptions" filterable> </n-select> </n-form-item> <n-form-item label="问题原因:" path="name"> <n-input v-model:value="formInfo.data.name" /> </n-form-item> <n-form-item label="原因描述:" path="nameDesc"> <n-input v-model:value="formInfo.data.nameDesc" /> </n-form-item> </n-form> <template #action> <n-space style="margin-top: 100px"> <n-button type="primary" @click="handleClick('submit')">保存 </n-button> <n-button @click="() => (modalShow = false)">取消</n-button> </n-space> </template> </n-modal> </div> </template> <script> import { toRefs, onMounted, reactive, h, ref, nextTick } from 'vue'; import { Search, Add } from '@vicons/ionicons5'; import { NButton, NImage } from 'naive-ui'; import { NewQuestionSave, NewQuestionInfo, NewQuestionDel, NewQuestionUpda, getProjectTypeList, getProjectTypeAllIndex } from '@/services'; import { resetForm, formatDate } from '@/utils/util'; import Editor from './editor.vue'; export default { name: 'payPage', components: { Search, Add, NButton, Editor }, setup() { const allData = reactive({ searchVal1: null, searchVal2: null, uploadList: [], modalTitle: '新增考核问题原因项', modalShow: false, examineOptions: [], zbOptions: [], formInfo: { data: { codeId: null, indexId: null, name: '', nameDesc: '', }, rules: { codeId: { required: true, trigger: ['change'], message: '请选择', type: 'number' }, indexId: { required: true, trigger: ['change'], message: '请选择' }, name: { required: true, trigger: ['blur'], message: '请输入' }, }, }, tableLoading: true, tableData: [], columns: [ { title: '序号', align: 'center', width: '80', render(row, index) { return (paginationReactive.page - 1) * paginationReactive.pageSize + index + 1; }, }, { title: '工程类型', align: 'center', key: 'codeName' }, { title: '指标名称', align: 'center', key: 'indexName' }, { title: '问题原因', align: 'center', key: 'name' }, { title: '原因描述', align: 'center', key: 'nameDesc' }, { title: '创建人', align: 'center', key: 'createUser' }, { title: '创建时间', align: 'center', key: 'createTime' }, { title: '操作', key: 'actions', width: '220', align: 'center', render(row) { const btn = allData.actionColumn.map((item, index) => { return h( NButton, { text: true, size: item.size, style: { margin: '10px', }, type: item.btnType, onClick: () => handleClick(item.type, row), }, { default: () => item.default } ); }); return btn; }, }, ], actionColumn: [ { size: 'small', btnType: 'primary', type: 'edit', default: '编辑', }, { size: 'small', btnType: 'error', type: 'delete', default: '删除', }, ], }); //分页 const paginationReactive = reactive({ page: 1, pageSize: 10, showSizePicker: true, pageSizes: [10, 20, 50], showQuickJumper: true, pageCount: 0, itemCount: 0, prefix: () => { return '共 ' + paginationReactive.itemCount + ' 项'; }, onChange: (page) => { paginationReactive.page = page; getTableData(); }, onPageSizeChange: (pageSize) => { paginationReactive.pageSize = pageSize; paginationReactive.page = 1; getTableData(); }, }); //获取工程子项 const GetIndexClass = async () => { let res = await getProjectTypeList(); if (res && res.code == 200) { let data = res.data; data.forEach((item) => { let { id, name } = item; allData.examineOptions.push({ value: Number(id), label: name }); }); } }; //获得表格数据 const getTableData = async () => { allData.tableLoading = true; let pramas = { current: paginationReactive.page, size: paginationReactive.pageSize, codeId: allData.searchVal1, indexId: allData.searchVal2, }; let res = await NewQuestionInfo(pramas); if (res && res.code == 200) { allData.tableData = res.data.records; paginationReactive.pageCount = res.data.pages; paginationReactive.itemCount = res.data.total; } allData.tableLoading = false; }; const formRef = ref(null); const richEditor = ref(null); // 点击事件 const handleClick = async (type, row) => { switch (type) { case 'search': getTableData(); break; case 'add': allData.modalTitle = '新增考核问题原因项'; resetForm(allData.formInfo.data); allData.formInfo.data.codeId = null; allData.modalShow = true; allData.uploadList = []; break; case 'edit': if (row.editable == 0) { $message.error('该项已被考核使用,不可编辑'); } else { allData.modalTitle = '修改考核问题原因项'; allData.formInfo.data = { ...row }; changeType(row.codeId); allData.modalShow = true; } break; case 'submit': formRef.value.validate((errors) => { if (!errors) { submitData(); } else { $message.error('验证失败,请检查必填项'); } }); break; case 'delete': $dialog.info({ title: '提示', content: `确定删除该数据吗?`, positiveText: '确定', negativeText: '取消', onPositiveClick: () => { let ids = [row.id]; dataDel(ids); }, }); break; } }; // 删除数据 async function dataDel(ids) { let res = await NewQuestionDel({ ids: ids }); if (res && res.code === 200) { $message.success('删除成功'); getTableData(); } } // 提交数据 async function submitData() { let params = { ...allData.formInfo.data }; if (allData.modalTitle == '新增考核问题原因项') { let res = await NewQuestionSave(params); if (res && res.code == 200) { $message.success('操作成功'); getTableData(); allData.modalShow = false; } } else { let res = await NewQuestionUpda(params); if (res && res.code == 200) { $message.success('操作成功'); getTableData(); allData.modalShow = false; } } } // 选择工程类型,加载对应指标名称 async function changeType(val) { allData.zbOptions = []; allData.searchVal2 = null; let res = await getProjectTypeAllIndex({ id: val }); if (res && res.code == 200) { if (res.data.length == 0) return; res.data.map((item) => { allData.zbOptions.push({ value: item.id, label: item.indexName, }); }); } } onMounted(() => { GetIndexClass(); getTableData(); }); return { ...toRefs(allData), pagination: paginationReactive, handleClick, getTableData, formRef, richEditor, changeType, GetIndexClass, }; }, }; </script> <style lang="less" scoped> .causePage { width: 100%; .searchBoxs { margin: 10px; } } </style>