中航光电热表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.

284 lines
7.6 KiB

<template>
6 months ago
<div>
<avue-crud
6 months ago
:option="option"
v-model:search="search"
6 months ago
:table-loading="loading"
:data="data"
v-model="form"
v-model:page="page"
ref="crud"
@row-del="rowDel"
@row-save="rowSave"
@row-update="rowUpdate"
6 months ago
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
6 months ago
<el-button type="danger" icon="el-icon-delete" @click="handleDelete"
>删除
</el-button>
</template>
<template #menu-right>
<el-button type="primary" icon="el-icon-upload" @click="handleImport"
>导入
</el-button>
<el-button type="primary" icon="el-icon-download" @click="handleExport"
>导出
6 months ago
</el-button>
</template>
<template #menu> </template>
6 months ago
</avue-crud>
6 months ago
<!-- 导入 -->
<basic-import v-if="isShowImport" title="导入" :isShow="isShowImport"
templateUrl="/blade-desk/QA/CycleTestItem/download-excel-template"
templateName="试验项目模板.xls"
6 months ago
importUrl="/blade-desk/QA/CycleTestItem/import-excel"
@closeDialog="closeDialog"></basic-import>
6 months ago
</div>
</template>
<script>
6 months ago
import basicImport from '@/components/basic-import/main.vue'
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: {},
6 months ago
option: {
height: "auto",
calcHeight: 32,
tip: false,
simplePage: true,
searchShow: true,
searchMenuSpan: 6,
searchIcon: true,
searchIndex: 3,
tree: false,
border: true,
index: true,
selection: true,
viewBtn: false,
delBtn: false,
addBtn: true,
editBtnText: "修改",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
viewBtnText: "详情",
labelWidth: 120,
menuWidth: 180,
dialogWidth: 640,
dialogClickModal: false,
searchEnter: true,
excelBtn: false,
filterBtn: true,
searchShowBtn: false,
columnSort: true,
excelBtn: true,
columnSort: true,
index: false,
showOverflowTooltip: true,
searchLabelPosition: "left",
searchLabelPosition: "left",
searchGutter: 24,
searchSpan: 6,
menuAlign: "left",
gridBtn: false,
searchMenuPosition: "right",
addBtnIcon: " ",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
align: "center",
6 months ago
column: [
{
label: "月份",
prop: "month",
6 months ago
search: true,
sortable: true,
filter: true,
span: 24,
type: "month",
format: "YYYY-MM",
valueFormat: "YYYY-MM",
6 months ago
rules: [
{
required: true,
message: "请输入月份",
6 months ago
trigger: "blur",
},
],
},
{
label: "用水目标(L/d㎡)",
prop: "tapWater",
search: false,
sortable: true,
filter: true,
span: 24,
},
],
},
form: {},
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
};
},
methods: {
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();
});
},
6 months ago
closeDialog(){
this.isShowImport = false
},
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.warning("请选择至少一条数据");
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;
},
onLoad() {
this.loading = true;
pageList(
this.page.currentPage,
this.page.pageSize,
{ type: 1 }
).then(res => {
this.data = res.data.data.records;
this.page.total = res.data.data.total;
this.loading = false;
setTimeout(() => {
this.selectionClear();
}, 500);
}).catch(() => {
this.loading = false;
});
6 months ago
},
},
};
</script>
6 months ago
<style lang="scss" scoped></style>