|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<avue-crud
|
|
|
|
|
:option="option"
|
|
|
|
|
v-model:search="search"
|
|
|
|
|
:table-loading="loading"
|
|
|
|
|
:data="data"
|
|
|
|
|
v-model="form"
|
|
|
|
|
v-model:page="page"
|
|
|
|
|
ref="crud"
|
|
|
|
|
@row-del="rowDel"
|
|
|
|
|
@row-save="rowSave"
|
|
|
|
|
@row-update="rowUpdate"
|
|
|
|
|
@search-change="searchChange"
|
|
|
|
|
@search-reset="searchReset"
|
|
|
|
|
@selection-change="selectionChange"
|
|
|
|
|
@current-change="currentChange"
|
|
|
|
|
@size-change="sizeChange"
|
|
|
|
|
@refresh-change="refreshChange"
|
|
|
|
|
@on-load="onLoad"
|
|
|
|
|
@sort-change="sortChange"
|
|
|
|
|
>
|
|
|
|
|
<template #menu-left>
|
|
|
|
|
<el-button type="danger" @click="handleDelete" v-if="permission.waterTarget_delete">删除 </el-button>
|
|
|
|
|
</template>
|
|
|
|
|
<template #menu-right>
|
|
|
|
|
<el-button type="primary" @click="handleExport" v-if="permission.waterTarget_export">导出 </el-button>
|
|
|
|
|
<el-button type="primary" @click="handleImport" v-if="permission.waterTarget_import">导入 </el-button>
|
|
|
|
|
</template>
|
|
|
|
|
<template #menu> </template>
|
|
|
|
|
</avue-crud>
|
|
|
|
|
<!-- 导入 -->
|
|
|
|
|
<basic-import
|
|
|
|
|
v-if="isShowImport"
|
|
|
|
|
title="导入"
|
|
|
|
|
:isShow="isShowImport"
|
|
|
|
|
templateUrl="/blade-desk/bsEnergyTarget/water-download-excel-template"
|
|
|
|
|
templateName="用水目标模板.xls"
|
|
|
|
|
importUrl="/blade-desk/bsEnergyTarget/water-import-excel"
|
|
|
|
|
@closeDialog="closeDialog"
|
|
|
|
|
></basic-import>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import basicImport from '@/components/basic-import/main.vue'
|
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
|
import { pageList, removeItem, saveItem, exportData } from '@/api/energyManagement/energyManagement';
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
basicImport,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
isShowImport:false,
|
|
|
|
|
selectionList: [],
|
|
|
|
|
query: {},
|
|
|
|
|
search: {},
|
|
|
|
|
loading: false,
|
|
|
|
|
data: [],
|
|
|
|
|
option: {
|
|
|
|
|
height: "auto",
|
|
|
|
|
calcHeight: 32,
|
|
|
|
|
tip: false,
|
|
|
|
|
simplePage: true,
|
|
|
|
|
searchShow: true,
|
|
|
|
|
searchMenuSpan: 18,
|
|
|
|
|
searchIcon: true,
|
|
|
|
|
searchIndex: 3,
|
|
|
|
|
tree: false,
|
|
|
|
|
border: true,
|
|
|
|
|
index: true,
|
|
|
|
|
selection: true,
|
|
|
|
|
viewBtn: false,
|
|
|
|
|
delBtn: false,
|
|
|
|
|
addBtn: false,
|
|
|
|
|
editBtn: false,
|
|
|
|
|
editBtnText: "修改",
|
|
|
|
|
viewBtnIcon: " ",
|
|
|
|
|
delBtnIcon: " ",
|
|
|
|
|
editBtnIcon: " ",
|
|
|
|
|
viewBtnText: "详情",
|
|
|
|
|
labelWidth: 120,
|
|
|
|
|
menuWidth: 80,
|
|
|
|
|
dialogWidth: 640,
|
|
|
|
|
dialogClickModal: false,
|
|
|
|
|
searchEnter: true,
|
|
|
|
|
excelBtn: false,
|
|
|
|
|
filterBtn: true,
|
|
|
|
|
searchShowBtn: false,
|
|
|
|
|
columnSort: true,
|
|
|
|
|
columnSort: true,
|
|
|
|
|
index: false,
|
|
|
|
|
showOverflowTooltip: true,
|
|
|
|
|
searchLabelPosition: "left",
|
|
|
|
|
searchLabelPosition: "left",
|
|
|
|
|
searchLabelWidth: "auto",
|
|
|
|
|
searchGutter: 24,
|
|
|
|
|
searchSpan: 6,
|
|
|
|
|
menuAlign: "center",
|
|
|
|
|
gridBtn: false,
|
|
|
|
|
searchMenuPosition: "right",
|
|
|
|
|
addBtnIcon: " ",
|
|
|
|
|
viewBtnIcon: " ",
|
|
|
|
|
delBtnIcon: " ",
|
|
|
|
|
editBtnIcon: " ",
|
|
|
|
|
align: "center",
|
|
|
|
|
|
|
|
|
|
column: [
|
|
|
|
|
{
|
|
|
|
|
label: "年份",
|
|
|
|
|
prop: "year",
|
|
|
|
|
search: true,
|
|
|
|
|
sortable: 'custom',
|
|
|
|
|
filter: true,
|
|
|
|
|
span: 24,
|
|
|
|
|
type: "year",
|
|
|
|
|
format: "YYYY",
|
|
|
|
|
valueFormat: "YYYY",
|
|
|
|
|
valueType: "string",
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: "请输入年份",
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "用水目标(L/d㎡)",
|
|
|
|
|
prop: "target",
|
|
|
|
|
type:"number",
|
|
|
|
|
search: false,
|
|
|
|
|
sortable: 'custom',
|
|
|
|
|
filter: true,
|
|
|
|
|
span: 24,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
form: {},
|
|
|
|
|
page: {
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
currentPage: 1,
|
|
|
|
|
total: 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created(){
|
|
|
|
|
console.log('permission-------',this.permission)
|
|
|
|
|
this.option.addBtn = this.permission.waterTarget_add ? true : false;
|
|
|
|
|
this.option.editBtn = this.permission.waterTarget_edit ? true : false;
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapGetters(['permission']),
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 表格排序
|
|
|
|
|
sortChange({ prop, order }) {
|
|
|
|
|
if (!prop) {
|
|
|
|
|
// 如果取消排序,清空排序参数
|
|
|
|
|
this.query.orderByField = undefined;
|
|
|
|
|
// this.query.isAsc = undefined;
|
|
|
|
|
this.query.asc = undefined;
|
|
|
|
|
} else {
|
|
|
|
|
const orderByField = prop.replace(/([a-z])([A-Z0-9])/g, '$1_$2').toUpperCase();
|
|
|
|
|
|
|
|
|
|
this.query.orderByField = orderByField;
|
|
|
|
|
// this.query.isAsc = order === 'ascending' ? true : false;
|
|
|
|
|
this.query.asc = order === 'ascending' ? true : false;
|
|
|
|
|
}
|
|
|
|
|
// // 重新加载数据
|
|
|
|
|
this.onLoad(this.page, this.query);
|
|
|
|
|
},
|
|
|
|
|
selectionClear() {
|
|
|
|
|
this.selectionList = [];
|
|
|
|
|
this.$refs.crud.toggleSelection();
|
|
|
|
|
},
|
|
|
|
|
searchReset() {
|
|
|
|
|
this.query = {};
|
|
|
|
|
this.onLoad(this.page);
|
|
|
|
|
},
|
|
|
|
|
searchChange(params, done) {
|
|
|
|
|
this.query = params;
|
|
|
|
|
this.page.currentPage = 1;
|
|
|
|
|
this.onLoad(this.page, params);
|
|
|
|
|
done();
|
|
|
|
|
},
|
|
|
|
|
currentChange(currentPage) {
|
|
|
|
|
this.page.currentPage = currentPage;
|
|
|
|
|
},
|
|
|
|
|
sizeChange(pageSize) {
|
|
|
|
|
this.page.pageSize = pageSize;
|
|
|
|
|
},
|
|
|
|
|
refreshChange() {
|
|
|
|
|
this.onLoad(this.page, this.query);
|
|
|
|
|
},
|
|
|
|
|
rowDel(row) {
|
|
|
|
|
this.$confirm("确定将选择数据删除?", {
|
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning",
|
|
|
|
|
}).then(() => {
|
|
|
|
|
removeItem(row.id).then(() => {
|
|
|
|
|
this.$message.success("删除成功");
|
|
|
|
|
this.onLoad(this.page);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
rowSave(row, done, loading) {
|
|
|
|
|
// 转换日期格式,避免后端解析错误
|
|
|
|
|
const submitData = { ...row, type: 1 };
|
|
|
|
|
if (submitData.month && typeof submitData.month === 'string') {
|
|
|
|
|
// 将 ISO 8601 格式转换为 YYYY-MM 格式
|
|
|
|
|
submitData.month = submitData.month.substring(0, 7);
|
|
|
|
|
}
|
|
|
|
|
saveItem(submitData).then(() => {
|
|
|
|
|
this.$message.success("新增成功");
|
|
|
|
|
this.onLoad(this.page);
|
|
|
|
|
done();
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
loading();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
rowUpdate(row, index, done, loading) {
|
|
|
|
|
// 转换日期格式,避免后端解析错误
|
|
|
|
|
const submitData = { ...row, type: 1 };
|
|
|
|
|
if (submitData.month && typeof submitData.month === 'string') {
|
|
|
|
|
// 将 ISO 8601 格式转换为 YYYY-MM 格式
|
|
|
|
|
submitData.month = submitData.month.substring(0, 7);
|
|
|
|
|
}
|
|
|
|
|
saveItem(submitData).then(() => {
|
|
|
|
|
this.$message.success("修改成功");
|
|
|
|
|
this.onLoad(this.page);
|
|
|
|
|
done();
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
loading();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closeDialog(val){
|
|
|
|
|
this.isShowImport = false
|
|
|
|
|
if(val){
|
|
|
|
|
this.onLoad()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleImport() {
|
|
|
|
|
this.isShowImport = true
|
|
|
|
|
},
|
|
|
|
|
handleExport() {
|
|
|
|
|
this.$confirm('是否导出数据?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning',
|
|
|
|
|
}).then(() => {
|
|
|
|
|
this.loading = true;
|
|
|
|
|
exportData({ type: 1 }).then(res => {
|
|
|
|
|
const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
|
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = url;
|
|
|
|
|
link.download = '用水目标数据.xlsx';
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
link.click();
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
|
this.$message.success('导出成功');
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
handleDelete() {
|
|
|
|
|
if (this.selectionList.length === 0) {
|
|
|
|
|
this.$message.error("请选择至少一条数据");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.$confirm("确定将选择数据删除?", {
|
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning",
|
|
|
|
|
}).then(() => {
|
|
|
|
|
const ids = this.selectionList.map(item => item.id).join(',');
|
|
|
|
|
removeItem(ids).then(() => {
|
|
|
|
|
this.$message.success("删除成功");
|
|
|
|
|
this.onLoad(this.page);
|
|
|
|
|
this.selectionClear();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// 多选
|
|
|
|
|
selectionChange(list) {
|
|
|
|
|
this.selectionList = list;
|
|
|
|
|
},
|
|
|
|
|
onLoad(page, params = {}) {
|
|
|
|
|
console.log('=== onLoad 开始 ===');
|
|
|
|
|
console.log('请求参数:', {
|
|
|
|
|
current: this.page.currentPage,
|
|
|
|
|
size: this.page.pageSize,
|
|
|
|
|
type: 1,
|
|
|
|
|
...params
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
pageList({
|
|
|
|
|
current:this.page.currentPage,
|
|
|
|
|
size: this.page.pageSize,
|
|
|
|
|
type: 1,
|
|
|
|
|
...this.query
|
|
|
|
|
}).then(res => {
|
|
|
|
|
console.log('API 响应:', res);
|
|
|
|
|
console.log('res.data:', res.data);
|
|
|
|
|
|
|
|
|
|
if (res.data && res.data.data) {
|
|
|
|
|
this.data = res.data.data.records || [];
|
|
|
|
|
this.page.total = res.data.data.total || 0;
|
|
|
|
|
console.log('数据处理成功:', {
|
|
|
|
|
records: this.data,
|
|
|
|
|
total: this.page.total,
|
|
|
|
|
dataLength: this.data.length
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.warn('响应数据格式不正确:', res);
|
|
|
|
|
this.data = [];
|
|
|
|
|
this.page.total = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('准备设置 loading = false');
|
|
|
|
|
this.loading = false;
|
|
|
|
|
console.log('loading 状态:', this.loading);
|
|
|
|
|
|
|
|
|
|
// 强制更新视图
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('请求失败:', err);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
this.data = [];
|
|
|
|
|
this.page.total = 0;
|
|
|
|
|
});
|
|
|
|
|
console.log('=== onLoad 结束 ===');
|
|
|
|
|
},
|
|
|
|
|
// onLoad() {
|
|
|
|
|
// this.loading = true;
|
|
|
|
|
// console.log('=== onLoad 开始 ===');
|
|
|
|
|
// console.log('请求参数:', {
|
|
|
|
|
// current: this.page.currentPage,
|
|
|
|
|
// size: this.page.pageSize,
|
|
|
|
|
// type: 1
|
|
|
|
|
// });
|
|
|
|
|
// pageList(
|
|
|
|
|
// this.page.currentPage,
|
|
|
|
|
// this.page.pageSize,
|
|
|
|
|
// { type: 1 }
|
|
|
|
|
// ).then(res => {
|
|
|
|
|
|
|
|
|
|
// if (res.data && res.data.data) {
|
|
|
|
|
// this.data = res.data.data.records || [];
|
|
|
|
|
// this.page.total = res.data.data.total || 0;
|
|
|
|
|
// console.log('最终数据:', {
|
|
|
|
|
// records: this.data,
|
|
|
|
|
// total: this.page.total,
|
|
|
|
|
// dataLength: this.data.length
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
// console.error('响应数据格式不正确:', res);
|
|
|
|
|
// this.data = [];
|
|
|
|
|
// this.page.total = 0;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 使用 nextTick 确保 loading 状态更新
|
|
|
|
|
// this.$nextTick(() => {
|
|
|
|
|
// this.loading = false;
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// this.selectionClear();
|
|
|
|
|
// }, 500);
|
|
|
|
|
// });
|
|
|
|
|
// }).catch(err => {
|
|
|
|
|
// console.error('请求失败:', err);
|
|
|
|
|
// this.loading = false;
|
|
|
|
|
// });
|
|
|
|
|
// console.log('=== onLoad 结束 ===');
|
|
|
|
|
// },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped></style>
|