能源需求修改

This commit is contained in:
2024-04-02 16:54:36 +08:00
parent cea7fb622f
commit 94c7f803cc
20 changed files with 3816 additions and 3422 deletions

View File

@@ -1,139 +1,155 @@
<template>
<el-form ref="form" :rules="rules" label-width="100px" :model="form">
<el-form-item label="关联表名" prop="plcId">
<el-select v-model="form.plcId" placeholder="请选择" style="width: 100%;" filterable>
<el-option
v-for="item in plcList"
:key="item.id"
:label="item.plcTableName"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="对象" prop="bindObjectId">
<el-cascader
style='width: 100%;'
v-model="objIds"
:options="objList"
:props="{ checkStrictly: true, value: 'id', label: 'name' }"
popper-class="cascaderParent"
@change="selectObj"
clearable></el-cascader>
</el-form-item>
</el-form>
<el-form
ref="form"
:rules="rules"
label-width="100px"
:model="form">
<el-form-item
label="关联表名"
prop="plcId">
<el-select
v-model="form.plcId"
placeholder="请选择"
style="width: 100%"
filterable>
<el-option
v-for="item in plcList"
:key="item.id"
:label="item.plcTableName"
:value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item
label="对象"
prop="bindObjectId">
<el-cascader
style="width: 100%"
v-model="objIds"
:options="objList"
:props="{ checkStrictly: true, value: 'id', label: 'name' }"
@change="selectObj"
clearable></el-cascader>
</el-form-item>
</el-form>
</template>
<script>
import { getEnergyPlcConnect, updateEnergyPlcConnect, createEnergyPlcConnect } from '@/api/base/energyPlcConnect'
import { getEnergyPlcAll } from '@/api/base/energyPlc'
import {
getEnergyPlcConnect,
updateEnergyPlcConnect,
createEnergyPlcConnect,
} from '@/api/base/energyPlcConnect';
import { getEnergyPlcAll } from '@/api/base/energyPlc';
export default {
name: 'EnergyPlcConnectAdd',
props: {
objList: {
type: Array,
default: () => []
},
},
data() {
return {
form: {
id: '',
plcId: '',
bindObjectId: '',
bindObjectType: ''
},
objIds: [],// 回显数组
plcList: [],
isEdit: false, //是否是编辑
rules: {
plcId: [{ required: true, message: '关联表名不能为空', trigger: 'change' }],
bindObjectId: [{ required: true, message: '对象不能为空', trigger: 'change' }]
}
}
},
methods: {
init(id) {
getEnergyPlcAll().then((res) => {
this.plcList = res.data || []
})
if (id) {
this.isEdit = true
this.form.id = id
getEnergyPlcConnect( id ).then((res) => {
if (res.code === 0) {
this.form = res.data
this.objIds = this.changeDetSelect(this.form.bindObjectId, this.objList)
}
})
} else {
this.isEdit = false
this.form.id = ''
}
},
// 递归处理分类回显问题
changeDetSelect(key, treeData) {
let arr = [] // 递归时操作的数组
let returnArr = [] // 存放结果的数组
let depth = 0 // 定义全局层级
// 定义递归函数
function childrenEach(childrendData, depthN) {
for (var j = 0; j < childrendData.length; j++) {
depth = depthN
arr[depthN] = childrendData[j].id
if (childrendData[j].id == key) {
returnArr = arr.slice(0, depthN + 1)
break
} else {
if (childrendData[j].children) {
depth++
childrenEach(childrendData[j].children, depth)
}
}
}
return returnArr
}
return childrenEach(treeData, depth)
},
selectObj(val) {
this.form.bindObjectId = val[val.length-1]
this.form.bindObjectType = val.length-1
},
submitForm() {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.isEdit) {
// 编辑
updateEnergyPlcConnect({...this.form}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit')
}
})
} else {
createEnergyPlcConnect({...this.form}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit')
}
})
}
} else {
return false
}
})
},
formClear() {
this.form.id = ''
this.form.plcId = ''
this.form.bindObjectId = ''
this.form.bindObjectType = ''
this.objIds = []
this.isEdit = false
}
}
}
</script>
<style>
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
display: none;
}
</style>
name: 'EnergyPlcConnectAdd',
props: {
objList: {
type: Array,
default: () => [],
},
},
data() {
return {
form: {
id: '',
plcId: '',
bindObjectId: '',
bindObjectType: '',
},
objIds: [], // 回显数组
plcList: [],
isEdit: false, //是否是编辑
rules: {
plcId: [
{ required: true, message: '关联表名不能为空', trigger: 'change' },
],
bindObjectId: [
{ required: true, message: '对象不能为空', trigger: 'change' },
],
},
};
},
methods: {
init(id) {
getEnergyPlcAll().then((res) => {
this.plcList = res.data || [];
});
if (id) {
this.isEdit = true;
this.form.id = id;
getEnergyPlcConnect(id).then((res) => {
if (res.code === 0) {
this.form = res.data;
this.objIds = this.changeDetSelect(
this.form.bindObjectId,
this.objList
);
}
});
} else {
this.isEdit = false;
this.form.id = '';
}
},
// 递归处理分类回显问题
changeDetSelect(key, treeData) {
let arr = []; // 递归时操作的数组
let returnArr = []; // 存放结果的数组
let depth = 0; // 定义全局层级
// 定义递归函数
function childrenEach(childrendData, depthN) {
for (var j = 0; j < childrendData.length; j++) {
depth = depthN;
arr[depthN] = childrendData[j].id;
if (childrendData[j].id == key) {
returnArr = arr.slice(0, depthN + 1);
break;
} else {
if (childrendData[j].children) {
depth++;
childrenEach(childrendData[j].children, depth);
}
}
}
return returnArr;
}
return childrenEach(treeData, depth);
},
selectObj(val) {
this.form.bindObjectId = val[val.length - 1];
this.form.bindObjectType = val.length - 1;
},
submitForm() {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.isEdit) {
// 编辑
updateEnergyPlcConnect({ ...this.form }).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess('操作成功');
this.$emit('successSubmit');
}
});
} else {
createEnergyPlcConnect({ ...this.form }).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess('操作成功');
this.$emit('successSubmit');
}
});
}
} else {
return false;
}
});
},
formClear() {
this.form.id = '';
this.form.plcId = '';
this.form.bindObjectId = '';
this.form.bindObjectType = '';
this.objIds = [];
this.isEdit = false;
},
},
};
</script>

View File

@@ -1,236 +1,270 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
<!-- 列表 -->
<base-table :page="queryParams.pageNo" :limit="queryParams.pageSize" :table-props="tableProps" :table-data="list"
:max-height="tableH">
<method-btn v-if="tableBtn.length" slot="handleBtn" :width="160" label="操作" :method-list="tableBtn"
@clickBtn="handleClick" />
</base-table>
<pagination :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" :total="total"
@pagination="getList" />
<!-- 新增 -->
<base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="centervisible" @cancel="handleCancel"
@confirm="handleConfirm" :before-close="handleCancel" width='30%'>
<energy-plc-connect-add ref="energyPlcConnect" :objList="objList" @successSubmit="successSubmit" />
</base-dialog>
<!-- 参数绑定/查看 -->
<energy-plc-param v-if="paramVisible" ref="plcParam" @closeDrawer="closeDrawer"
:energyTypeList="energyTypeList"></energy-plc-param>
</div>
<div class="app-container">
<!-- 搜索工作栏 -->
<search-bar
:formConfigs="formConfig"
ref="searchBarForm"
@headBtnClick="buttonClick" />
<!-- 列表 -->
<base-table
:page="queryParams.pageNo"
:limit="queryParams.pageSize"
:table-props="tableProps"
:table-data="list"
:max-height="tableH">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="160"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick" />
</base-table>
<pagination
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
:total="total"
@pagination="getList" />
<!-- 新增 -->
<base-dialog
:dialogTitle="addOrEditTitle"
:dialogVisible="centervisible"
@cancel="handleCancel"
@confirm="handleConfirm"
:before-close="handleCancel"
width="30%">
<energy-plc-connect-add
ref="energyPlcConnect"
:objList="objList"
@successSubmit="successSubmit" />
</base-dialog>
<!-- 参数绑定/查看 -->
<energy-plc-param
v-if="paramVisible"
ref="plcParam"
@closeDrawer="closeDrawer"
:energyTypeList="energyTypeList"></energy-plc-param>
</div>
</template>
<script>
import { getEnergyPlcConnectPage, deleteEnergyPlcConnect } from "@/api/base/energyPlcConnect";
import {
getEnergyPlcConnectPage,
deleteEnergyPlcConnect,
} from '@/api/base/energyPlcConnect';
// import { publicFormatter } from '@/utils/dict'
import { getTree } from '@/api/base/factory'
import { getEnergyTypeListAll } from '@/api/base/energyType'
import EnergyPlcConnectAdd from './components/energyPlcConnectAdd'
import EnergyPlcParam from './components/energyPlcParam'
import { getTree } from '@/api/analysis/energyAnalysis';
import { getEnergyTypeListAll } from '@/api/base/energyType';
import EnergyPlcConnectAdd from './components/energyPlcConnectAdd';
import EnergyPlcParam from './components/energyPlcParam';
const tableProps = [
{
prop: 'objName',
label: '对象'
},
{
prop: 'objCode',
label: '对象编码',
showOverflowtooltip: true
},
{
prop: 'plcTableName',
label: '关联表名'
},
{
prop: 'plcTableCode',
label: '关联表编码',
minWidth: 150,
showOverflowtooltip: true
},
{
prop: 'cnName',
label: '标识名',
minWidth: 150,
showOverflowtooltip: true
},
{
prop: 'varNum',
label: '绑定参数数量'
}
]
{
prop: 'objName',
label: '对象',
},
{
prop: 'objCode',
label: '对象编码',
showOverflowtooltip: true,
},
{
prop: 'plcTableName',
label: '关联表名',
},
{
prop: 'plcTableCode',
label: '关联表编码',
minWidth: 150,
showOverflowtooltip: true,
},
{
prop: 'cnName',
label: '标识名',
minWidth: 150,
showOverflowtooltip: true,
},
{
prop: 'varNum',
label: '绑定参数数量',
},
];
export default {
name: "EnergyPlcConnect",
components: { EnergyPlcConnectAdd, EnergyPlcParam },
data() {
return {
formConfig: [
{
type: 'input',
label: '标识名',
placeholder: '标识名',
param: 'cnName'
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary'
},
{
type: 'separate'
},
{
type: this.$auth.hasPermi('base:energy-plc-connect:create') ? 'button' : '',
btnName: '新增',
name: 'add',
color: 'success',
plain: true
}
],
tableProps,
tableBtn: [
this.$auth.hasPermi('base:energy-plc-connect:bind')
? {
type: 'connect',
btnName: '绑定'
}
: undefined,
{
type: 'detail',
btnName: '详情'
},
this.$auth.hasPermi('base:energy-plc-connect:update')
? {
type: 'edit',
btnName: '编辑'
}
: undefined,
this.$auth.hasPermi('base:energy-plc-connect:delete')
? {
type: 'delete',
btnName: '删除'
}
: undefined
].filter((v) => v),
tableH: this.tableHeight(260),
// 总条数
total: 0,
// 班次基础信息列表
list: [],
// 弹出层标题
addOrEditTitle: "",
// 是否显示弹出层
centervisible: false,
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 20,
cnName: null
},
paramVisible: false,
energyTypeList: [],
objList: []
};
},
created() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260)
})
this.getList();
},
mounted() {
// 获取能源列表
this.getEnergyTypeList()
// 获取对象树形结构
this.getObjTree()
},
methods: {
buttonClick(val) {
switch (val.btnName) {
case 'search':
this.queryParams.pageNo = 1;
this.queryParams.cnName = val.cnName
this.getList()
break
default:
this.addOrEditTitle = '新增'
this.centervisible = true
this.$nextTick(() => {
this.$refs.energyPlcConnect.init()
})
}
},
/** 查询列表 */
getList() {
getEnergyPlcConnectPage(this.queryParams).then(response => {
let arr = response.data.list || [];
this.list = arr
this.total = response.data.total;
});
},
handleClick(val) {
console.log(val)
switch (val.type) {
case 'edit':
this.addOrEditTitle = '编辑'
this.$nextTick(() => {
this.$refs.energyPlcConnect.init(val.data.id)
})
this.centervisible = true
break
case 'delete':
this.handleDelete(val.data)
break
case 'detail':
this.paramVisible = true
this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'detail')
})
break
default:
this.paramVisible = true
this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'connect')
})
}
},
handleCancel() {
this.$refs.energyPlcConnect.formClear()
this.centervisible = false
this.addOrEditTitle = ''
},
handleConfirm() {
this.$refs.energyPlcConnect.submitForm()
},
successSubmit() {
this.handleCancel()
this.getList()
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除对象为"' + row.objName + '"的数据项?').then(function () {
return deleteEnergyPlcConnect(row.id);
}).then(() => {
this.queryParams.pageNo = 1;
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => { });
},
closeDrawer() {
this.getList()
},
getEnergyTypeList() {
getEnergyTypeListAll().then((res) => {
this.energyTypeList = res.data || []
})
},
getObjTree() {
getTree().then(res => {
this.objList = res.data || []
})
}
}
name: 'EnergyPlcConnect',
components: { EnergyPlcConnectAdd, EnergyPlcParam },
data() {
return {
formConfig: [
{
type: 'input',
label: '标识名',
placeholder: '标识名',
param: 'cnName',
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary',
},
{
type: 'separate',
},
{
type: this.$auth.hasPermi('base:energy-plc-connect:create')
? 'button'
: '',
btnName: '新增',
name: 'add',
color: 'success',
plain: true,
},
],
tableProps,
tableBtn: [
this.$auth.hasPermi('base:energy-plc-connect:bind')
? {
type: 'connect',
btnName: '绑定',
}
: undefined,
{
type: 'detail',
btnName: '详情',
},
this.$auth.hasPermi('base:energy-plc-connect:update')
? {
type: 'edit',
btnName: '编辑',
}
: undefined,
this.$auth.hasPermi('base:energy-plc-connect:delete')
? {
type: 'delete',
btnName: '删除',
}
: undefined,
].filter((v) => v),
tableH: this.tableHeight(260),
// 总条数
total: 0,
// 班次基础信息列表
list: [],
// 弹出层标题
addOrEditTitle: '',
// 是否显示弹出层
centervisible: false,
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 20,
cnName: null,
},
paramVisible: false,
energyTypeList: [],
objList: [],
};
},
created() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260);
});
this.getList();
},
mounted() {
// 获取能源列表
this.getEnergyTypeList();
// 获取对象树形结构
this.getObjTree();
},
methods: {
buttonClick(val) {
switch (val.btnName) {
case 'search':
this.queryParams.pageNo = 1;
this.queryParams.cnName = val.cnName;
this.getList();
break;
default:
this.addOrEditTitle = '新增';
this.centervisible = true;
this.$nextTick(() => {
this.$refs.energyPlcConnect.init();
});
}
},
/** 查询列表 */
getList() {
getEnergyPlcConnectPage(this.queryParams).then((response) => {
let arr = response.data.list || [];
this.list = arr;
this.total = response.data.total;
});
},
handleClick(val) {
console.log(val);
switch (val.type) {
case 'edit':
this.addOrEditTitle = '编辑';
this.$nextTick(() => {
this.$refs.energyPlcConnect.init(val.data.id);
});
this.centervisible = true;
break;
case 'delete':
this.handleDelete(val.data);
break;
case 'detail':
this.paramVisible = true;
this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'detail');
});
break;
default:
this.paramVisible = true;
this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'connect');
});
}
},
handleCancel() {
this.$refs.energyPlcConnect.formClear();
this.centervisible = false;
this.addOrEditTitle = '';
},
handleConfirm() {
this.$refs.energyPlcConnect.submitForm();
},
successSubmit() {
this.handleCancel();
this.getList();
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal
.confirm('是否确认删除对象为"' + row.objName + '"的数据项?')
.then(function () {
return deleteEnergyPlcConnect(row.id);
})
.then(() => {
this.queryParams.pageNo = 1;
this.getList();
this.$modal.msgSuccess('删除成功');
})
.catch(() => {});
},
closeDrawer() {
this.getList();
},
getEnergyTypeList() {
getEnergyTypeListAll().then((res) => {
this.energyTypeList = res.data || [];
});
},
getObjTree() {
getTree().then((res) => {
this.objList = res.data || [];
});
},
},
};
</script>

View File

@@ -1,329 +1,422 @@
<template>
<el-form ref="form" :rules="rules" label-width="100px" :model="form">
<el-row>
<el-col :span="12">
<el-form-item label="能源类型" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="类型编码" prop="code">
<el-input v-model="form.code" disabled></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="单位" prop="unit">
<el-select v-model="form.unit" placeholder="请选择" style="width: 100%;">
<el-option v-for="item in getDictDatas(DICT_TYPE.ENERGY_UNIT)" :key="item.value" :label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="计价方式" prop="pricingMethod">
<el-select v-model="form.pricingMethod" placeholder="请选择" style="width: 100%;">
<el-option label="时间段" :value='0'></el-option>
<el-option label="使用量" :value='1'></el-option>
<el-option label="固定价位" :value='2'></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12" v-show="form.pricingMethod === 2">
<el-form-item label="单价(元)" prop="pricingMethod">
<el-input-number v-model="form.singlePrice" :precision="2" :min="0" :max="999999999"
style="width: 100%;"></el-input-number>
</el-form-item>
</el-col>
<el-col :span="12" v-show="form.pricingMethod === 1">
<el-form-item label="计量维度" prop="dim">
<el-select v-model="form.dim" placeholder="请选择" style="width: 100%;">
<el-option label="月" :value='4'></el-option>
<el-option label="年" :value='5'></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24" v-show="form.pricingMethod === 0">
<el-form-item label="时间段" prop="pricingMethod">
<base-table :key='timeKye' :table-props="tableProps1" :table-data="tableData1"
:add-button-show="addButtonShow" @emitButtonClick="emitButtonClick1" @emitFun="inputChange1">
<method-btn v-if="tableBtn.length" slot="handleBtn" :width="80" label="操作" :method-list="tableBtn"
@clickBtn="handleClick1" />
</base-table>
</el-form-item>
</el-col>
<el-col :span="24" v-show="form.pricingMethod === 1">
<el-form-item label="使用量" prop="pricingMethod">
<base-table :key='usedKye' :table-props="tableProps2" :table-data="tableData2"
:add-button-show="addButtonShow" @emitButtonClick="emitButtonClick2" @emitFun="inputChange2">
<method-btn v-if="tableBtn.length" slot="handleBtn" :width="80" label="操作" :method-list="tableBtn"
@clickBtn="handleClick2" />
</base-table>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="是否推送" prop="push">
<el-switch v-model="form.push"></el-switch>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="描述" prop="description">
<el-input v-model="form.description"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-form
ref="form"
:rules="rules"
label-width="100px"
:model="form">
<el-row>
<el-col :span="12">
<el-form-item
label="能源类型"
prop="name">
<el-select
v-model="form.name"
placeholder="请选择"
style="width: 100%">
<el-option
v-for="item in getDictDatas(DICT_TYPE.ENERGY_TYPE)"
:key="item.value"
:label="item.label"
:value="item.value"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item
label="类型编码"
prop="code">
<el-input
v-model="form.code"
disabled></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item
label="单位"
prop="unit">
<el-select
v-model="form.unit"
placeholder="请选择"
filterable
style="width: 100%">
<el-option
v-for="item in getDictDatas(DICT_TYPE.UNIT_DICT)"
:key="item.value"
:label="item.label"
:value="item.value"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item
label="计价方式"
prop="pricingMethod">
<el-select
v-model="form.pricingMethod"
placeholder="请选择"
style="width: 100%">
<el-option
label="时间段"
:value="0"></el-option>
<el-option
label="使用量"
:value="1"></el-option>
<el-option
label="固定价位"
:value="2"></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col
:span="12"
v-show="form.pricingMethod === 2">
<el-form-item
label="单价(元)"
prop="pricingMethod">
<el-input-number
v-model="form.singlePrice"
:precision="2"
:min="0"
:max="999999999"
style="width: 100%"></el-input-number>
</el-form-item>
</el-col>
<el-col
:span="12"
v-show="form.pricingMethod === 1">
<el-form-item
label="计量维度"
prop="dim">
<el-select
v-model="form.dim"
placeholder="请选择"
style="width: 100%">
<el-option
label="月"
:value="4"></el-option>
<el-option
label="年"
:value="5"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col
:span="24"
v-show="form.pricingMethod === 0">
<el-form-item
label="时间段"
prop="pricingMethod">
<base-table
:key="timeKye"
:table-props="tableProps1"
:table-data="tableData1"
:add-button-show="addButtonShow"
@emitButtonClick="emitButtonClick1"
@emitFun="inputChange1">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick1" />
</base-table>
</el-form-item>
</el-col>
<el-col
:span="24"
v-show="form.pricingMethod === 1">
<el-form-item
label="使用量"
prop="pricingMethod">
<base-table
:key="usedKye"
:table-props="tableProps2"
:table-data="tableData2"
:add-button-show="addButtonShow"
@emitButtonClick="emitButtonClick2"
@emitFun="inputChange2">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick2" />
</base-table>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item
label="描述"
prop="description">
<el-input v-model="form.description"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
<script>
import { getEnergyType, updateEnergyType, createEnergyType, getEnergyTypeCode } from '@/api/base/energyType'
import inputArea from './InputArea.vue'
import timePickerArea from './TimePickerArea.vue'
import {
getEnergyType,
updateEnergyType,
createEnergyType,
getEnergyTypeCode,
} from '@/api/base/energyType';
import inputArea from './InputArea.vue';
import timePickerArea from './TimePickerArea.vue';
const tableProps1 = [
{
prop: 'startTime',
label: '开始时间',
subcomponent: timePickerArea
},
{
prop: 'endTime',
label: '结束时间',
subcomponent: timePickerArea
},
{
prop: 'price',
label: '单价(元)',
subcomponent: inputArea
}
]
{
prop: 'startTime',
label: '开始时间',
subcomponent: timePickerArea,
},
{
prop: 'endTime',
label: '结束时间',
subcomponent: timePickerArea,
},
{
prop: 'price',
label: '单价(元)',
subcomponent: inputArea,
},
];
const tableProps2 = [
{
prop: 'startUsed',
label: '下限值',
// subcomponent: inputArea
},
{
prop: 'endUsed',
label: '上限量',
subcomponent: inputArea
},
{
prop: 'price',
label: '单价(元)',
subcomponent: inputArea
}
]
{
prop: 'startUsed',
label: '下限值',
// subcomponent: inputArea
},
{
prop: 'endUsed',
label: '上限量',
subcomponent: inputArea,
},
{
prop: 'price',
label: '单价(元)',
subcomponent: inputArea,
},
];
export default {
name: 'energyTypeAdd',
data() {
return {
form: {
id: '',
name: '',
code: '',
unit: '',
singlePrice: 0,
pricingMethod: 2,
dim: '',
push: false,
description: ''
},
isEdit: false, //是否是编辑
rules: {
name: [{ required: true, message: '能源类型不能为空', trigger: 'blur' }],
pricingMethod: [{ required: true, message: '计价方式不能为空', trigger: 'change' }]
},
timeKye: 0,
usedKye: 0,
tableProps1,
tableProps2,
tableData1: [],
tableData2: [],
tableBtn: [
{
type: 'delete',
name: '删除'
}
],
addButtonShow: '新增'
}
},
methods: {
init(id) {
if (id) {
this.isEdit = true
this.form.id = id
getEnergyType(id).then((res) => {
if (res.code === 0) {
this.form.name = res.data.name
this.form.code = res.data.code
this.form.unit = res.data.unit
this.form.pricingMethod = res.data.pricingMethod
this.form.push = res.data.push ? true : false
this.form.description = res.data.description
switch (this.form.pricingMethod) {
case 0:
this.tableData1 = res.data.segPriceList || []
break;
case 1:
this.tableData2 = res.data.usedPriceList || []
this.form.dim = res.data.dim
break;
default:
this.form.singlePrice = res.data.singlePrice || 0
}
}
})
console.log(this.form)
} else {
this.isEdit = false
this.form.id = ''
getEnergyTypeCode().then((res) => {
this.form.code = res.data
})
}
},
// 输入框失去焦点
inputChange1(val) {
this.tableData1[val._pageIndex - 1][val.prop] = val[val.prop]
if ((this.tableData1.length > val._pageIndex) && val.prop === 'endTime') {
this.tableData1[val._pageIndex].startTime = val[val.prop]
}
this.timeKye++
},
inputChange2(val) {
// 上限值必须大于下限值
if (!!val.endUsed && (val.endUsed <= val.startUsed)) {
this.$modal.msgError('上限值不能等于或者小于下限值')
return false
}
this.tableData2[val._pageIndex - 1][val.prop] = val[val.prop]
if ((this.tableData2.length > val._pageIndex) && val.prop === 'endUsed') {
this.tableData2[val._pageIndex].startUsed = val[val.prop]
}
this.usedKye++
},
// 增加
emitButtonClick1() {
let n = this.tableData1.length
let obj = {}
obj.startTime = n === 0 ? '' : this.tableData1[n - 1].endTime
obj.endTime = ''
obj.price = 0
this.tableData1.push(obj)
},
emitButtonClick2() {
let n = this.tableData2.length
let obj = {}
obj.startUsed = n === 0 ? 0 : this.tableData2[n - 1].endUsed
obj.endUsed = 0
obj.price = 0
this.tableData2.push(obj)
},
// 删除
handleClick1(val) {
this.tableData1.splice(val.data._pageIndex - 1, 1)
this.timeKye++
},
handleClick2(val) {
this.tableData2.splice(val.data._pageIndex - 1, 1)
this.usedKye++
},
submitForm() {
this.$refs['form'].validate((valid) => {
if (valid) {
switch (this.form.pricingMethod) {
case 0:// 时间段
if (this.tableData1.length === 0) {
this.$modal.msgError('时间段表格数据不能为空')
return false
} else {
this.tableData1.map(item => {
if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查')
return false
}
})
}
break;
case 1:// 使用量
if (this.tableData2.length === 0) {
this.$modal.msgError('使用量表格数据不能为空')
return false
} else {
this.tableData1.map(item => {
if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查')
return false
}
})
}
break;
default:// 固定单价
if (!this.form.singlePrice) {
this.$modal.msgError('单价有误请检查,请检查')
return false
}
}
console.log(this.form)
if (this.isEdit) {
// 编辑
updateEnergyType({
id: this.form.id,
code: this.form.code,
name: this.form.name,
unit: this.form.unit,
pricingMethod: this.form.pricingMethod,
description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice: this.form.pricingMethod === 2 ? this.form.singlePrice : '',
segPriceList: this.form.pricingMethod === 0 ? this.tableData1 : [],
usedPriceList: this.form.pricingMethod === 1 ? this.tableData2 : [],
push: this.form.push ? 1 : 0
}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit')
}
})
} else {
createEnergyType({
code: this.form.code,
name: this.form.name,
unit: this.form.unit,
pricingMethod: this.form.pricingMethod,
description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice: this.form.pricingMethod === 2 ? this.form.singlePrice : '',
segPriceList: this.form.pricingMethod === 0 ? this.tableData1 : [],
usedPriceList: this.form.pricingMethod === 1 ? this.tableData2 : [],
push: this.form.push ? 1 : 0
}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit')
}
})
}
} else {
return false
}
})
},
formClear() {
this.$refs.form.resetFields()
this.form.singlePrice = 0
this.isEdit = false
this.timeKye = 0
this.usedKye = 0
this.tableData1 = []
this.tableData2 = []
}
}
}
name: 'energyTypeAdd',
data() {
return {
form: {
id: '',
name: '',
code: '',
unit: '',
singlePrice: 0,
pricingMethod: 2,
dim: '',
description: '',
},
isEdit: false, //是否是编辑
rules: {
name: [
{ required: true, message: '能源类型不能为空', trigger: 'blur' },
],
pricingMethod: [
{ required: true, message: '计价方式不能为空', trigger: 'change' },
],
},
timeKye: 0,
usedKye: 0,
tableProps1,
tableProps2,
tableData1: [],
tableData2: [],
tableBtn: [
{
type: 'delete',
name: '删除',
},
],
addButtonShow: '新增',
};
},
methods: {
init(id) {
if (id) {
this.isEdit = true;
this.form.id = id;
getEnergyType(id).then((res) => {
if (res.code === 0) {
this.form.name = res.data.name;
this.form.code = res.data.code;
this.form.unit = res.data.unit;
this.form.pricingMethod = res.data.pricingMethod;
this.form.description = res.data.description;
switch (this.form.pricingMethod) {
case 0:
this.tableData1 = res.data.segPriceList || [];
break;
case 1:
this.tableData2 = res.data.usedPriceList || [];
this.form.dim = res.data.dim;
break;
default:
this.form.singlePrice = res.data.singlePrice || 0;
}
}
});
console.log(this.form);
} else {
this.isEdit = false;
this.form.id = '';
getEnergyTypeCode().then((res) => {
this.form.code = res.data;
});
}
},
// 输入框失去焦点
inputChange1(val) {
this.tableData1[val._pageIndex - 1][val.prop] = val[val.prop];
if (this.tableData1.length > val._pageIndex && val.prop === 'endTime') {
this.tableData1[val._pageIndex].startTime = val[val.prop];
}
this.timeKye++;
},
inputChange2(val) {
// 上限值必须大于下限值
if (!!val.endUsed && val.endUsed <= val.startUsed) {
this.$modal.msgError('上限值不能等于或者小于下限值');
return false;
}
this.tableData2[val._pageIndex - 1][val.prop] = val[val.prop];
if (this.tableData2.length > val._pageIndex && val.prop === 'endUsed') {
this.tableData2[val._pageIndex].startUsed = val[val.prop];
}
this.usedKye++;
},
// 增加
emitButtonClick1() {
let n = this.tableData1.length;
let obj = {};
obj.startTime = n === 0 ? '' : this.tableData1[n - 1].endTime;
obj.endTime = '';
obj.price = 0;
this.tableData1.push(obj);
},
emitButtonClick2() {
let n = this.tableData2.length;
let obj = {};
obj.startUsed = n === 0 ? 0 : this.tableData2[n - 1].endUsed;
obj.endUsed = 0;
obj.price = 0;
this.tableData2.push(obj);
},
// 删除
handleClick1(val) {
this.tableData1.splice(val.data._pageIndex - 1, 1);
this.timeKye++;
},
handleClick2(val) {
this.tableData2.splice(val.data._pageIndex - 1, 1);
this.usedKye++;
},
submitForm() {
this.$refs['form'].validate((valid) => {
if (valid) {
switch (this.form.pricingMethod) {
case 0: // 时间段
if (this.tableData1.length === 0) {
this.$modal.msgError('时间段表格数据不能为空');
return false;
} else {
this.tableData1.map((item) => {
if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查');
return false;
}
});
}
break;
case 1: // 使用量
if (this.tableData2.length === 0) {
this.$modal.msgError('使用量表格数据不能为空');
return false;
} else {
this.tableData1.map((item) => {
if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查');
return false;
}
});
}
break;
default: // 固定单价
if (!this.form.singlePrice) {
this.$modal.msgError('单价有误请检查,请检查');
return false;
}
}
console.log(this.form);
if (this.isEdit) {
// 编辑
updateEnergyType({
id: this.form.id,
code: this.form.code,
name: this.form.name,
unit: this.form.unit,
pricingMethod: this.form.pricingMethod,
description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice:
this.form.pricingMethod === 2 ? this.form.singlePrice : '',
segPriceList:
this.form.pricingMethod === 0 ? this.tableData1 : [],
usedPriceList:
this.form.pricingMethod === 1 ? this.tableData2 : [],
}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess('操作成功');
this.$emit('successSubmit');
}
});
} else {
createEnergyType({
code: this.form.code,
name: this.form.name,
unit: this.form.unit,
pricingMethod: this.form.pricingMethod,
description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice:
this.form.pricingMethod === 2 ? this.form.singlePrice : '',
segPriceList:
this.form.pricingMethod === 0 ? this.tableData1 : [],
usedPriceList:
this.form.pricingMethod === 1 ? this.tableData2 : [],
}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess('操作成功');
this.$emit('successSubmit');
}
});
}
} else {
return false;
}
});
},
formClear() {
this.$refs.form.resetFields();
this.form.singlePrice = 0;
this.isEdit = false;
this.timeKye = 0;
this.usedKye = 0;
this.tableData1 = [];
this.tableData2 = [];
},
},
};
</script>

View File

@@ -1,224 +1,191 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<search-bar
:formConfigs="formConfig"
ref="searchBarForm"
@headBtnClick="buttonClick"
/>
<!-- 列表 -->
<base-table
:page="queryParams.pageNo"
:limit="queryParams.pageSize"
:table-props="tableProps"
:table-data="list"
:max-height="tableH"
>
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick"
/>
</base-table>
<pagination
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
:total="total"
@pagination="getList"
/>
<!-- 新增 -->
<base-dialog
:dialogTitle="addOrEditTitle"
:dialogVisible="centervisible"
@cancel="handleCancel"
@confirm="handleConfirm"
:before-close="handleCancel"
>
<energy-type-add ref="energyType" @successSubmit="successSubmit" />
</base-dialog>
</div>
<div class="app-container">
<!-- 搜索工作栏 -->
<search-bar
:formConfigs="formConfig"
ref="searchBarForm"
:removeBlue="true"
@headBtnClick="buttonClick" />
<!-- 列表 -->
<base-table
:page="queryParams.pageNo"
:limit="queryParams.pageSize"
:table-props="tableProps"
:table-data="list"
:max-height="tableH">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick" />
</base-table>
<!-- 新增 -->
<base-dialog
:dialogTitle="addOrEditTitle"
:dialogVisible="centervisible"
@cancel="handleCancel"
@confirm="handleConfirm"
:before-close="handleCancel">
<energy-type-add
ref="energyType"
@successSubmit="successSubmit" />
</base-dialog>
</div>
</template>
<script>
import { getEnergyTypePage, deleteEnergyType } from "@/api/base/energyType";
import { publicFormatter } from '@/utils/dict'
import InnerTable from './components/InnerTable'
import EnergyTypeAdd from './components/energyTypeAdd'
import { getEnergyTypePage, deleteEnergyType } from '@/api/base/energyType';
import { publicFormatter } from '@/utils/dict';
import InnerTable from './components/InnerTable';
import EnergyTypeAdd from './components/energyTypeAdd';
const tableProps = [
{
prop: 'code',
label: '类型编码',
showOverflowtooltip: true,
minWidth: 150
},
{
prop: 'name',
label: '能源类型'
},
{
prop: 'unit',
label: '单位',
filter: publicFormatter('energy_unit')
},
{
prop: 'pricingMethod',
label: '计价方式'
},
{
prop: 'push',
label: '是否推送',
filter: publicFormatter('push')
},
{
prop: 'price',
label: '价格(元)',
subcomponent: InnerTable
}
]
{
prop: 'code',
label: '类型编码',
showOverflowtooltip: true,
minWidth: 150,
},
{
prop: 'name',
label: '能源类型',
filter: publicFormatter('energy_type'),
},
{
prop: 'unit',
label: '单位',
filter: publicFormatter('unit_dict'),
},
{
prop: 'pricingMethod',
label: '计价方式',
},
{
prop: 'price',
label: '价格(元)',
subcomponent: InnerTable,
},
];
export default {
name: "EnergyType",
components: { EnergyTypeAdd },
data() {
return {
formConfig: [
{
type: 'input',
label: '能源类型',
placeholder: '能源类型',
param: 'name'
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary'
},
{
type: this.$auth.hasPermi('base:energy-type:create') ? 'separate' : '',
},
{
type: this.$auth.hasPermi('base:energy-type:create') ? 'button' : '',
btnName: '新增',
name: 'add',
color: 'success',
plain: true
}
],
tableProps,
tableBtn: [
this.$auth.hasPermi('base:energy-type:update')
? {
type: 'edit',
btnName: '编辑'
}
: undefined,
this.$auth.hasPermi('base:energy-type:delete')
? {
type: 'delete',
btnName: '删除'
}
: undefined
].filter((v) => v),
tableH: this.tableHeight(260),
pricingMethodList: [
{value: 0,label: '分时间段计价'},
{value: 1,label: '分使用量计价'},
{value: 2,label: '单一计价'}
],
// 总条数
total: 0,
// 班次基础信息列表
list: [],
// 弹出层标题
addOrEditTitle: "",
// 是否显示弹出层
centervisible: false,
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 20,
name: null,
code: null
}
};
},
created() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260)
})
this.getList();
},
methods: {
buttonClick(val) {
switch (val.btnName) {
case 'search':
this.queryParams.pageNo = 1;
this.queryParams.name = val.name
this.queryParams.code = val.code
this.getList()
break
default:
this.addOrEditTitle = '新增'
this.centervisible = true
this.$nextTick(() => {
this.$refs.energyType.init()
})
}
},
/** 查询列表 */
getList() {
getEnergyTypePage(this.queryParams).then(response => {
let arr = response.data.list || [];
arr&&arr.map(item => {
this.pricingMethodList.map(i => {
if (item.pricingMethod === i.value) {
item.pricingMethod = i.label
}
})
})
this.list = arr
this.total = response.data.total;
});
},
handleClick(val) {
switch (val.type) {
case 'edit':
this.addOrEditTitle = '编辑'
this.$nextTick(() => {
this.$refs.energyType.init(val.data.id)
})
this.centervisible = true
break
default:
this.handleDelete(val.data)
}
},
handleCancel() {
this.$refs.energyType.formClear()
this.centervisible = false
this.addOrEditTitle = ''
},
handleConfirm() {
this.$refs.energyType.submitForm()
},
successSubmit() {
this.handleCancel()
this.getList()
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除能源类型为"' + row.name + '"的数据项?').then(function() {
return deleteEnergyType(row.id);
}).then(() => {
this.queryParams.pageNo = 1;
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
}
name: 'EnergyType',
components: { EnergyTypeAdd },
data() {
return {
formConfig: [
{
type: this.$auth.hasPermi('base:energy-type:create') ? 'button' : '',
btnName: '新增',
name: 'add',
color: 'success',
plain: true,
},
],
tableProps,
tableBtn: [
this.$auth.hasPermi('base:energy-type:update')
? {
type: 'edit',
btnName: '编辑',
}
: undefined,
this.$auth.hasPermi('base:energy-type:delete')
? {
type: 'delete',
btnName: '删除',
}
: undefined,
].filter((v) => v),
tableH: this.tableHeight(220),
pricingMethodList: [
{ value: 0, label: '分时间段计价' },
{ value: 1, label: '分使用量计价' },
{ value: 2, label: '单一计价' },
],
// 总条数
total: 0,
// 班次基础信息列表
list: [],
// 弹出层标题
addOrEditTitle: '',
// 是否显示弹出层
centervisible: false,
// 查询参数
queryParams: {
pageNo: 1,
pageSize: 100,
},
};
},
created() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(220);
});
this.getList();
},
methods: {
buttonClick() {
this.addOrEditTitle = '新增';
this.centervisible = true;
this.$nextTick(() => {
this.$refs.energyType.init();
});
},
/** 查询列表 */
getList() {
getEnergyTypePage(this.queryParams).then((response) => {
let arr = response.data.list || [];
arr &&
arr.map((item) => {
this.pricingMethodList.map((i) => {
if (item.pricingMethod === i.value) {
item.pricingMethod = i.label;
}
});
});
this.list = arr;
this.total = response.data.total;
});
},
handleClick(val) {
switch (val.type) {
case 'edit':
this.addOrEditTitle = '编辑';
this.$nextTick(() => {
this.$refs.energyType.init(val.data.id);
});
this.centervisible = true;
break;
default:
this.handleDelete(val.data);
}
},
handleCancel() {
this.$refs.energyType.formClear();
this.centervisible = false;
this.addOrEditTitle = '';
},
handleConfirm() {
this.$refs.energyType.submitForm();
},
successSubmit() {
this.handleCancel();
this.getList();
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal
.confirm('是否确认删除能源类型为"' + row.name + '"的数据项?')
.then(function () {
return deleteEnergyType(row.id);
})
.then(() => {
this.queryParams.pageNo = 1;
this.getList();
this.$modal.msgSuccess('删除成功');
})
.catch(() => {});
},
},
};
</script>