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.
424 lines
12 KiB
424 lines
12 KiB
<template> |
|
<div> |
|
<avue-crud |
|
:option="option" |
|
:table-loading="loading" |
|
:data="data" |
|
v-model="form" |
|
v-model:page="page" |
|
ref="crud" |
|
@row-del="rowDel" |
|
@search-change="searchChange" |
|
@search-reset="searchReset" |
|
@selection-change="selectionChange" |
|
@current-change="currentChange" |
|
@size-change="sizeChange" |
|
@refresh-change="refreshChange" |
|
@on-load="onLoad" |
|
@row-save="rowSave" |
|
@row-update="rowUpdate" |
|
:beforeOpen="beforeOpen" |
|
@sort-change="sortChange" |
|
> |
|
<template #equipmentId-form="{type,disabled}"> |
|
<jhSelect |
|
:value="form.equipmentId" |
|
placeholder="请搜索选择" |
|
api-url="/blade-desk/equipment/page" |
|
echo-api="/blade-desk/equipment/page" |
|
echoParamsKey="id" |
|
echo-method="get" |
|
api-method="get" |
|
list-key="records" |
|
total-key="total" |
|
label-key="deviceName" |
|
value-key="id" |
|
search-key="deviceName" |
|
:debounce-time="100" |
|
@change="changeEquipment" |
|
:title="'修改'" |
|
/> |
|
</template> |
|
<template #menu-left> |
|
<el-button type="danger" @click="handleDelete" v-if="permission.electricityQuota_delete">删除</el-button> |
|
</template> |
|
<template #menu-right> |
|
<el-button type="primary" @click="handleExport" v-if="permission.electricityQuota_export">导出</el-button> |
|
<el-button type="primary" @click="handleImport" v-if="permission.electricityQuota_import">导入</el-button> |
|
</template> |
|
<template #menu="scope"> </template> |
|
</avue-crud> |
|
<!-- 导入 --> |
|
<basic-import v-if="isShowImport" title="导入" :isShow="isShowImport" |
|
templateUrl="/blade-desk/bsEnergyQuota/electric-download-excel-template" |
|
templateName="用电定额模板.xls" |
|
importUrl="blade-desk/bsEnergyQuota/electric-import-excel" |
|
@closeDialog="closeDialog"></basic-import> |
|
</div> |
|
</template> |
|
<script> |
|
import basicImport from '@/components/basic-import/main.vue' |
|
import { pageList, removeItem, saveItem, exportData } from '@/api/energyManagement/bsEnergyQuota'; |
|
import { mapGetters } from 'vuex'; |
|
export default { |
|
components: { |
|
basicImport, |
|
}, |
|
data() { |
|
return { |
|
data:[], |
|
isShowImport:false, |
|
selectionList: [], |
|
query:{}, |
|
option: { |
|
height: "auto", |
|
calcHeight: 32, |
|
tip: false, |
|
simplePage: true, |
|
searchShow: true, |
|
searchMenuSpan: 12, |
|
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: "workCenterId", |
|
sortable: 'custom', |
|
filterable: true, |
|
span: 24, |
|
search: true, |
|
type: "select", |
|
multiple:true, |
|
dicUrl:"/api/blade-desk/BA/WorkCenter/listForSelect", |
|
props: { |
|
label: 'wcName', |
|
value: 'id', |
|
}, |
|
rules: [ |
|
{ |
|
required: true, |
|
message: "请选择作业中心", |
|
trigger: "change", |
|
}, |
|
], |
|
change:(row) =>{ |
|
let wcIds = row && row.value && row.value |
|
const filteredUsers = row.dic.filter(user => wcIds.includes(user.id)); |
|
this.form.workCenterName = filteredUsers.map(item => item.wcName).join(',') |
|
} |
|
}, |
|
{ |
|
label: "设备", |
|
prop: "equipmentName", |
|
// bind: "equipmentName", |
|
search: false, |
|
sortable: "custom", |
|
filter: true, |
|
span: 24, |
|
display:false, |
|
// type: "select", |
|
// dicUrl:"/api/blade-desk/equipment/page?current=1&size=999&deviceName={{key}}", |
|
// props:{ |
|
// label:"deviceName", |
|
// value:"id", |
|
// res:"data.records", |
|
// }, |
|
// remote: true, |
|
// // dicData: [ |
|
// // { label: "化学镀镍", value: "化学镀镍" }, |
|
// // { label: "电镀设备", value: "电镀设备" }, |
|
// // { label: "喷涂设备", value: "喷涂设备" }, |
|
// // ], |
|
// rules: [ |
|
// { |
|
// required: true, |
|
// message: "请选择设备", |
|
// trigger: "blur", |
|
// }, |
|
// ], |
|
// change:(row) =>{ |
|
// this.form.equipmentName = row && row.item && row.item.deviceName |
|
// } |
|
}, |
|
{ |
|
label: "设备", |
|
prop: "equipmentId", |
|
// bind: "equipmentName", |
|
search: false, |
|
sortable: "custom", |
|
filter: true, |
|
span: 24, |
|
hide:true, |
|
rules: [ |
|
{ |
|
required: true, |
|
message: "请选择设备", |
|
trigger: "blur", |
|
}, |
|
], |
|
}, |
|
{ |
|
label: "日期", |
|
prop: "date", |
|
type:'date', |
|
search: true, |
|
searchRange: true, |
|
sortable: "custom", |
|
filter: true, |
|
span: 24, |
|
format:"YYYY-MM-DD", |
|
valueFormat:'YYYY-MM-DD', |
|
startPlaceholder: "开始日期", |
|
endPlaceholder: "结束日期", |
|
rules: [ |
|
{ |
|
required: true, |
|
message: "请输入日期", |
|
trigger: "blur", |
|
}, |
|
], |
|
}, |
|
{ |
|
label: "定额单位面积用电量(kWh/dm²)", |
|
prop: "electricNum", |
|
search: false, |
|
sortable: "custom", |
|
filter: true, |
|
span: 24, |
|
rules: [ |
|
{ |
|
required: true, |
|
message: "请输入日期", |
|
trigger: "blur", |
|
}, |
|
], |
|
}, |
|
], |
|
}, |
|
form: {}, |
|
page: { |
|
pageSize: 10, |
|
currentPage: 1, |
|
total: 0, |
|
}, |
|
}; |
|
}, |
|
computed: { |
|
...mapGetters(['permission']), |
|
}, |
|
created(){ |
|
console.log('pero--------',this.permission) |
|
this.option.addBtn = this.permission.electricityQuota_add ? true : false; |
|
this.option.editBtn = this.permission.electricityQuota_edit ? true : false; |
|
}, |
|
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 == "DATE" ? `"${orderByField}"` : orderByField; |
|
// this.query.isAsc = order === 'ascending' ? true : false; |
|
this.query.asc = order === 'ascending' ? true : false; |
|
} |
|
// // 重新加载数据 |
|
this.onLoad(this.page, this.query); |
|
}, |
|
changeEquipment(val, item){ |
|
console.log('val------------------',val) |
|
console.log('item------------------',item) |
|
this.form.equipmentId = val |
|
this.form.equipmentName = item && item.deviceName |
|
}, |
|
handleImport() { |
|
this.isShowImport = true |
|
}, |
|
searchChange(params, done){ |
|
this.query = params; |
|
this.page.currentPage = 1; |
|
this.onLoad() |
|
done() |
|
}, |
|
searchReset(){ |
|
this.query = {} |
|
this.onLoad() |
|
}, |
|
currentChange(currentPage){ |
|
this.page.currentPage = currentPage; |
|
}, |
|
sizeChange(pageSize){ |
|
this.page.pageSize = pageSize; |
|
}, |
|
refreshChange(){ |
|
this.onLoad() |
|
}, |
|
closeDialog(val){ |
|
this.isShowImport = false |
|
if(val){ |
|
this.onLoad() |
|
} |
|
}, |
|
handleDelete() { |
|
if (this.selectionList.length === 0) { |
|
this.$message.error("请选择至少一条数据"); |
|
return; |
|
} |
|
this.$confirm("确定将选择数据删除?", { |
|
confirmButtonText: "确定", |
|
cancelButtonText: "取消", |
|
type: "warning", |
|
}).then(() => { |
|
removeItem(this.selectionList.map(item => item.id).join(',')).then(res =>{ |
|
if(res.data.code == 200){ |
|
this.$message.success('删除成功') |
|
this.onLoad() |
|
} |
|
}) |
|
}); |
|
}, |
|
handleExport() { |
|
this.$confirm('是否导出数据?', '提示', { |
|
confirmButtonText: '确定', |
|
cancelButtonText: '取消', |
|
type: 'warning', |
|
}).then(() => { |
|
this.loading = true; |
|
exportData({type:2}).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; |
|
}); |
|
}); |
|
}, |
|
formatDate(dateStr) { |
|
const date = new Date(dateStr); |
|
|
|
// 获取年份 |
|
const year = date.getFullYear(); |
|
|
|
// 获取月份 (注意:getMonth() 返回 0-11,所以要 +1) |
|
const month = String(date.getMonth() + 1).padStart(2, '0'); |
|
|
|
// 获取日期 |
|
const day = String(date.getDate()).padStart(2, '0'); |
|
|
|
return `${year}-${month}-${day}`; |
|
}, |
|
beforeOpen(done, type){ |
|
if(type == 'edit'){ |
|
this.form.workCenterId = this.form.workCenterId + '' |
|
this.form.equipmentId = this.form.equipmentId + '' |
|
this.form.date = this.form.date && this.form.date.indexOf('/') != -1 ? this.formatDate(this.form.date) : this.form.date |
|
done() |
|
console.log('edit-------------',this.form) |
|
|
|
}else{ |
|
done() |
|
} |
|
}, |
|
// 多选 |
|
selectionChange(list) { |
|
this.selectionList = list; |
|
}, |
|
rowSave(row, done, loading) { |
|
const submitData = { ...row,type:2,workCenterId:typeof(row.workCenterId) == 'object' ? row.workCenterId.join(',') : row.workCenterId}; |
|
saveItem(submitData).then(res => { |
|
if(res.data.code == 200){ |
|
this.$message.success("新增成功"); |
|
this.onLoad() |
|
done() |
|
} |
|
}).catch(err =>{ |
|
loading() |
|
}) |
|
}, |
|
rowUpdate(row, index, done, loading) { |
|
const submitData = { ...row,type:2 }; |
|
console.log('edit-------------',submitData) |
|
saveItem(submitData).then(() => { |
|
this.$message.success("修改成功"); |
|
this.onLoad(this.page); |
|
done(); |
|
}).catch(() => { |
|
loading(); |
|
}); |
|
}, |
|
onLoad() { |
|
this.loading = true; |
|
let param = { |
|
...this.query, |
|
startDate:this.query.date && this.query.date.length != 0 && this.query.date[0], |
|
endDate:this.query.date && this.query.date.length != 0 && this.query.date[1] |
|
} |
|
if(param.date) delete param.date |
|
pageList({ |
|
current:this.page.currentPage, |
|
size:this.page.pageSize, |
|
type:2, |
|
...param |
|
}).then(res =>{ |
|
res.data.data.records.map(item =>{ |
|
item.electricNum = Number(item.electricNum) |
|
}) |
|
this.data = res.data.data.records; |
|
this.page.total = res.data.data.total; |
|
this.loading = false; |
|
}) |
|
}, |
|
}, |
|
}; |
|
</script> |
|
<style lang="scss" scoped></style>
|
|
|