<template> <!-- 运营维护范围配置 --> <div class="weihuPage"> <div class="searchBoxs"> <n-space> <div class="name">工程类型:</div> <n-select v-model:value="searchVal1" style="width: 200px" :options="bkwzOptions" 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: '800px', height: '560px' }" v-model:show="modalShow" > <n-form ref="formRef" label-align="right" require-mark-placement="left" :label-width="150" :rules="formInfo.rules" :model="formInfo.data" label-placement="left" > <n-form-item label="工程类型:" path="projectType"> <n-select v-model:value="formInfo.data.projectType" :options="bkwzOptions" clearable> </n-select> </n-form-item> <n-form-item label="工程子项名称:" path="projectSubName"> <n-input v-model:value="formInfo.data.projectSubName" placeholder="请输入工程子项名称:" /> </n-form-item> <n-form-item label="投入运营时间:" path="runningTime"> <n-date-picker v-model:value="formInfo.data.runningTime" type="datetime" /> </n-form-item> <n-form-item label="运营维护范围:" path="range"> <n-input v-model:value="formInfo.data.range" placeholder="请输入运营维护范围" /> </n-form-item> <n-form-item label="建设内容:" path="buildContent"> <n-input v-model:value="formInfo.data.buildContent" placeholder="请输入建设内容" type="textarea" :autosize="{ minRows: 3, maxRows: 5, }" /> </n-form-item> <n-form-item label="是否纳入考核:"> <n-switch v-model:value="formInfo.data.checkOn"> <template #checked> 是 </template> <template #unchecked> 否 </template> </n-switch> </n-form-item> </n-form> <template #action> <n-space> <n-button style="right: 300px" type="primary" @click="handleClick('submit')">保存 </n-button> <n-button style="right: 280px" @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 { ProjectConfigInfo, ProjectConfigDel, ProjectConfigSave, ProjectConfigUpdate, getAllProjectType } from '@/services'; import { resetForm, formatDate } from '@/utils/util'; import Editor from './editor.vue'; export default { name: 'weihuPage', components: { Search, Add, NButton, Editor }, setup() { const allData = reactive({ searchVal1: null, modalTitle: '新增运营项目', modalShow: false, uploadList: [], formInfo: { data: { projectSubName: null, range: '', buildContent: '', runningTime: null, projectType: null, checkOn: null, }, rules: { runningTime: { type: 'number', required: true, trigger: ['change', 'blur'], message: '请选择投入运营时间', }, projectType: { type: 'number', required: true, trigger: ['change'], message: '请选择', }, projectSubName: { required: true, trigger: ['blur'], message: '请输入工程子项名称', }, range: { required: true, trigger: ['blur'], message: '请输入运营维护范围', }, buildContent: { required: true, trigger: ['blur'], message: '请输入建设内容', }, }, }, tableLoading: true, tableData: [], bkwzOptions: [], columns: [ { title: '序号', align: 'center', width: '60', render(row, index) { return (paginationReactive.page - 1) * paginationReactive.pageSize + index + 1; }, }, { title: '工程类型', align: 'center', key: 'projectTypeName', width: '110' }, { title: '工程子项名称', align: 'center', key: 'projectSubName', width: '150' }, { title: '工程父项名称', align: 'center', key: 'projectParentName', width: '150' }, { title: '建设内容', align: 'center', key: 'buildContent', ellipsis: { tooltip: true } }, { title: '运营维护范围', align: 'center', key: 'range', ellipsis: { tooltip: true } }, { title: '投入运营时间', align: 'center', key: 'runningTime', width: '150' }, { 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 getTableData = async () => { allData.tableLoading = true; let pramas = { current: paginationReactive.page, size: paginationReactive.pageSize, projectType: allData.searchVal1, }; let res = await ProjectConfigInfo(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 GetProjectClass = async () => { let res = await getAllProjectType(); if (res && res.code == 200) { let data = res.data; data.forEach((item) => { let { codeId, codeName } = item; allData.bkwzOptions.push({ value: codeId, label: codeName }); }); } }; // 点击事件 const handleClick = async (type, row) => { switch (type) { case 'search': getTableData(); break; case 'add': allData.modalTitle = '新增运营项目'; resetForm(allData.formInfo.data); allData.modalShow = true; allData.formInfo.data.runningTime = new Date().getTime(); allData.uploadList = []; break; case 'edit': allData.modalTitle = '修改'; allData.formInfo.data = { ...row }; allData.modalShow = true; allData.formInfo.data.runningTime = row.runningTime ? Number(new Date(String(row.runningTime)).getTime()) : null; allData.formInfo.data.projectType = row.projectTypeName; allData.formInfo.data.checkOn = row.checkOn ? Boolean(row.projectType) : null; 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 ProjectConfigDel({ ids: ids }); if (res && res.code === 200) { $message.success('删除成功'); getTableData(); } } // 提交数据 async function submitData() { let params = { ...allData.formInfo.data }; params.checkOn = Number(allData.formInfo.data.checkOn); params.projectType = Number(allData.formInfo.data.projectType); params.runningTime = formatDate(allData.formInfo.data.runningTime); if (allData.modalTitle == '新增运营项目') { let res = await ProjectConfigSave(params); if (res && res.code == 200) { $message.success('操作成功'); getTableData(); allData.modalShow = false; } } else { let res = await ProjectConfigUpdate(params); if (res && res.code == 200) { $message.success('操作成功'); getTableData(); allData.modalShow = false; } } } onMounted(() => { GetProjectClass(); getTableData(); }); return { ...toRefs(allData), pagination: paginationReactive, handleClick, getTableData, formRef, richEditor, GetProjectClass, }; }, }; </script> <style lang="less" scoped> .weihuPage { width: 100%; .name { height: 34px; line-height: 34px; } .searchBoxs { margin: 10px; } } </style>