<template> <!-- 工程项目考核指标权重配置 --> <div class="weightPage"> <div class="searchBoxs"> <n-space> <n-select v-model:value="selectyear" placeholder="请选择考核年份" clearable :options="yearOptions" style="width: 200px"></n-select> <n-button type="primary" @click="handleClick('search')"> <template #icon> <n-icon><Search /></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="修改考核指标权重配置" :mask-closable="false" preset="dialog" :show-icon="false" :style="{ width: '600px' }" v-model:show="modalShow" > <n-form label-align="right" require-mark-placement="left" :label-width="250" :model="formInfo" label-placement="left"> <n-form-item label="河道水利工程权重(%):" path="weight40"> <n-input-number :min="0" v-model:value="formInfo.weight40" placeholder="请输入" /> </n-form-item> <n-form-item label="污水处理工程权重(%):" path="weight42"> <n-input-number :min="0" v-model:value="formInfo.weight42" placeholder="请输入" /> </n-form-item> <n-form-item label="合流制溢流污染控制工程权重(%):" path="weight44"> <n-input-number :min="0" v-model:value="formInfo.weight44" placeholder="请输入" /> </n-form-item> <n-form-item label="景观生态工程权重(%):" path="weight46"> <n-input-number :min="0" v-model:value="formInfo.weight46" placeholder="请输入" /> </n-form-item> <n-form-item label="智慧水务及物联网工程权重(%):" path="weight48"> <n-input-number :min="0" v-model:value="formInfo.weight48" placeholder="请输入" /> </n-form-item> </n-form> <template #action> <n-space> <n-button style="right: 200px" type="primary" @click="handleClick('submit')">保存 </n-button> <n-button style="right: 180px" @click="() => (modalShow = false)">取消</n-button> </n-space> </template> </n-modal> </div> </template> <script> import { toRefs, onMounted, reactive, h } from 'vue'; import { Search, Add } from '@vicons/ionicons5'; import { NButton } from 'naive-ui'; import { performweightList, performweightUpdate, normalNameList } from '@/services'; export default { name: 'weightPage', components: { Search, Add, NButton }, setup() { const allData = reactive({ selectyear: null, modalShow: false, yearOptions: [], uploadList: [], formInfo: { id: null, weight40: null, weight42: null, weight44: null, weight46: null, weight48: null, }, tableLoading: true, tableData: [], columns: [ { title: '考核名称', align: 'center', key: 'performName', width: '200' }, { title: '河道水利工程权重(%)', align: 'center', key: 'weight40' }, { title: '污水处理工程权重(%)', align: 'center', key: 'weight42' }, { title: '合流制溢流污染控制工程权重(%)', align: 'center', key: 'weight44' }, { title: '景观生态工程权重(%)', align: 'center', key: 'weight46' }, { title: '智慧水务及物联网工程权重(%)', align: 'center', key: 'weight48' }, { title: '操作', key: 'actions', width: '220', align: 'center', render(row) { let arr = [{ btnType: 'primary', type: 'edit', default: '修改' }]; const btn = arr.map((item, index) => { return h( NButton, { text: true, size: 'small', style: { margin: '10px' }, type: item.btnType, onClick: () => handleClick(item.type, row), }, { default: () => item.default } ); }); return btn; }, }, ], }); //分页 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, year: allData.selectyear, }; let res = await performweightList(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 handleClick = async (type, row) => { switch (type) { case 'search': getTableData(); break; case 'edit': allData.modalTitle = '修改'; allData.formInfo = { ...row }; allData.modalShow = true; break; case 'submit': submitData(); break; } }; // 提交数据 async function submitData() { let params = { ...allData.formInfo }; let res = await performweightUpdate(params); if (res && res.code == 200) { $message.success('操作成功'); getTableData(); allData.modalShow = false; } } // 获取年份 async function getYear() { allData.yearOptions = []; let res = await normalNameList(); if (res && res.code === 200) { res.data.map((item) => { allData.yearOptions.push({ value: item.year, label: item.performName, }); }); } } onMounted(() => { getYear(); getTableData(); }); return { ...toRefs(allData), pagination: paginationReactive, handleClick, getTableData, }; }, }; </script> <style lang="less" scoped> .weightPage { width: 100%; .name { height: 34px; line-height: 34px; } .searchBoxs { margin: 10px; } } </style>