中航光电热表web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

388 lines
11 KiB

<template>
6 months ago
<div>
<avue-crud
2 months ago
: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"
1 month ago
@sort-change="sortChange"
2 months ago
>
<template #menu-left>
1 month ago
<el-button type="danger" @click="handleDelete" v-if="permission.waterTarget_delete">删除 </el-button>
2 months ago
</template>
<template #menu-right>
1 month ago
<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>
2 months ago
</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"
2 months ago
@closeDialog="closeDialog"
></basic-import>
6 months ago
</div>
</template>
<script>
6 months ago
import basicImport from '@/components/basic-import/main.vue'
1 month ago
import { mapGetters } from 'vuex';
import { pageList, removeItem, saveItem, exportData } from '@/api/energyManagement/energyManagement';
export default {
6 months ago
components: {
basicImport,
},
6 months ago
data() {
return {
6 months ago
isShowImport:false,
6 months ago
selectionList: [],
query: {},
search: {},
2 months ago
loading: false,
data: [],
6 months ago
option: {
height: "auto",
calcHeight: 32,
tip: false,
simplePage: true,
searchShow: true,
searchMenuSpan: 18,
6 months ago
searchIcon: true,
searchIndex: 3,
tree: false,
border: true,
index: true,
selection: true,
viewBtn: false,
delBtn: false,
1 month ago
addBtn: false,
editBtn: false,
6 months ago
editBtnText: "修改",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
viewBtnText: "详情",
labelWidth: 120,
menuWidth: 80,
6 months ago
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",
6 months ago
searchGutter: 24,
searchSpan: 6,
menuAlign: "center",
6 months ago
gridBtn: false,
searchMenuPosition: "right",
addBtnIcon: " ",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
align: "center",
6 months ago
column: [
{
label: "年份",
prop: "year",
6 months ago
search: true,
sortable: 'custom',
6 months ago
filter: true,
span: 24,
type: "year",
format: "YYYY",
valueFormat: "YYYY",
valueType: "string",
6 months ago
rules: [
{
required: true,
message: "请输入年份",
6 months ago
trigger: "blur",
},
],
},
{
label: "用水目标(L/d㎡)",
prop: "target",
type:"number",
6 months ago
search: false,
sortable: 'custom',
6 months ago
filter: true,
span: 24,
},
],
},
form: {},
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
};
},
1 month ago
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']),
},
6 months ago
methods: {
1 month ago
// 表格排序
sortChange({ prop, order }) {
if (!prop) {
// 如果取消排序,清空排序参数
this.query.orderByField = undefined;
// this.query.isAsc = undefined;
this.query.asc = undefined;
1 month ago
} 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;
1 month ago
}
// // 重新加载数据
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){
6 months ago
this.isShowImport = false
if(val){
this.onLoad()
}
6 months ago
},
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;
});
});
},
6 months ago
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.error("请选择至少一条数据");
6 months ago
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();
});
});
6 months ago
},
// 多选
selectionChange(list) {
this.selectionList = list;
},
2 months ago
onLoad(page, params = {}) {
console.log('=== onLoad 开始 ===');
console.log('请求参数:', {
current: this.page.currentPage,
size: this.page.pageSize,
2 months ago
type: 1,
...params
});
2 months ago
this.loading = true;
pageList({
current:this.page.currentPage,
size: this.page.pageSize,
type: 1,
...this.query
}).then(res => {
2 months ago
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;
2 months ago
console.log('数据处理成功:', {
records: this.data,
total: this.page.total,
dataLength: this.data.length
});
} else {
2 months ago
console.warn('响应数据格式不正确:', res);
this.data = [];
this.page.total = 0;
}
2 months ago
console.log('准备设置 loading = false');
this.loading = false;
console.log('loading 状态:', this.loading);
// 强制更新视图
this.$forceUpdate();
}).catch(err => {
console.error('请求失败:', err);
this.loading = false;
2 months ago
this.data = [];
this.page.total = 0;
});
console.log('=== onLoad 结束 ===');
6 months ago
},
2 months ago
// 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 结束 ===');
// },
6 months ago
},
};
</script>
6 months ago
<style lang="scss" scoped></style>