能源手动抄表

This commit is contained in:
朱菊兰 2024-04-07 12:18:52 +08:00
parent 1e4a33a703
commit 7fe8d7e72c
5 changed files with 368 additions and 166 deletions

View File

@ -18,7 +18,7 @@ VUE_APP_TITLE = MES系统
# VUE_APP_BASE_API = 'http://192.168.2.173:48080' # VUE_APP_BASE_API = 'http://192.168.2.173:48080'
# VUE_APP_BASE_API = 'http://192.168.1.49:48082' # VUE_APP_BASE_API = 'http://192.168.1.49:48082'
# VUE_APP_BASE_API = 'http://192.168.1.8:48082' # VUE_APP_BASE_API = 'http://192.168.1.8:48082'
# VUE_APP_BASE_API = 'http://192.168.4.173:48082' # VUE_APP_BASE_API = 'http://192.168.4.173:9001'
# VUE_APP_BASE_API = 'http://192.168.1.104:48082' # VUE_APP_BASE_API = 'http://192.168.1.104:48082'
VUE_APP_BASE_API = 'http://192.168.0.33:48082' VUE_APP_BASE_API = 'http://192.168.0.33:48082'
# VUE_APP_BASE_API = 'http://192.168.1.62:48082' # VUE_APP_BASE_API = 'http://192.168.1.62:48082'

View File

@ -0,0 +1,139 @@
<template>
<div class="energyQuantityManualAddTable">
<el-table
:data="renderData"
border
style="width: 100%"
:header-cell-style="{
background: '#F2F4F9',
color: '#606266',
}">
<el-table-column
prop="tableName"
label="表名*">
<template slot-scope="scope">
<div class="tableInner">
<el-select
v-model="scope.row.tableName"
placeholder="请选择"
style="width: 100%"
@change="changeSelect(scope.row, 'tableName')">
<el-option
v-for="item in tableNameList"
:key="item.id"
:label="item.label"
:value="item.id"></el-option>
</el-select>
</div>
</template>
</el-table-column>
<el-table-column
prop="readingQuantity"
label="抄表数*">
<template slot-scope="scope">
<div class="tableInner">
<el-input-number
v-model="scope.row.readingQuantity"
:min="0"
:max="999999999"
style="width: 100%"
:controls="false"
@change="changeInput(scope.row, 'readingQuantity')"
:precision="2"></el-input-number>
</div>
</template>
</el-table-column>
</el-table>
<el-button
class="addButton"
icon="el-icon-plus"
@click="emitButtonClick">
新增
</el-button>
</div>
</template>
<script>
export default {
name: 'AddTable',
props: {
tableData: {
type: Array,
required: true,
default: () => {
return [];
},
},
tableNameList: {
type: Array,
required: true,
default: () => {
return [];
},
},
},
data() {
return {};
},
computed: {
renderData() {
return this.tableData.map((item, index) => {
return {
...item,
_pageIndex: index + 1,
};
});
},
},
methods: {
emitButtonClick() {
this.$emit('emitButtonClick');
},
changeInput(val1, val2) {
val1.prop = val2;
this.$emit('emitFun', val1);
},
changeSelect(val1, val2) {
val1.prop = val2;
this.$emit('emitFun', val1);
},
},
};
</script>
<style lang='scss' scoped>
.energyQuantityManualAddTable {
.el-table .el-table__cell {
padding: 0;
height: 35px;
}
.addButton {
width: 100%;
height: 35px;
border-top: none;
color: #0b58ff;
border-color: #ebeef5;
border-radius: 0;
}
.addButton:hover {
color: #0b58ff;
border-color: #ebeef5;
background-color: #fff;
}
.addButton:focus {
border-color: #ebeef5;
background-color: #fff;
}
.tableInner .el-input__inner {
border: none;
padding: 0;
height: 33px;
}
}
</style>
<style lang='scss'>
.energyQuantityManualAddTable {
.el-table .el-table__cell {
padding: 0;
height: 35px;
}
}
</style>

View File

@ -1,167 +1,228 @@
<template> <template>
<el-form ref="energyQuantityManualForm" :rules="rules" label-width="90px" :model="form"> <el-form
<el-row :gutter="20"> ref="energyQuantityManualForm"
<el-col :span='12'> :rules="rules"
<el-form-item label="能源类型" prop="energyTypeId"> label-width="90px"
<el-select v-model="form.energyTypeId" placeholder="请选择" style="width: 100%;" filterable> :model="form">
<el-option v-for="item in this.energyTypeList" :key="item.id" :label="item.name" :value="item.id"> <el-row :gutter="20">
</el-option> <el-col :span="12">
</el-select> <el-form-item
</el-form-item> label="能源类型"
</el-col> prop="energyTypeId">
<el-col :span='12'> <el-select
<el-form-item label="抄表日期" prop="recordTime"> v-model="form.energyTypeId"
<el-date-picker v-model="form.recordTime" type="date" format="yyyy-MM-dd" value-format="timestamp" placeholder="请选择"
placeholder="选择日期" style="width: 100%;"> style="width: 100%"
</el-date-picker> @change="selEnergyType"
</el-form-item> filterable>
</el-col> <el-option
</el-row> v-for="item in this.energyTypeList"
<el-row :gutter="20"> :key="item.id"
<el-col :span='24'> :label="item.labelName"
<base-table border :table-props="tableProps" :table-data="tableData" :add-button-show="addButtonShow" :value="item.id"></el-option>
@emitFun="inputChange" @emitButtonClick="emitButtonClick" /> </el-select>
</el-col> </el-form-item>
</el-row> </el-col>
</el-form> <el-col :span="12">
<el-form-item
label="抄表日期"
prop="recordTime">
<el-date-picker
v-model="form.recordTime"
type="date"
format="yyyy-MM-dd"
value-format="timestamp"
placeholder="选择日期"
style="width: 100%"></el-date-picker>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="24">
<add-table
:table-props="tableProps"
:table-data="tableData"
:table-name-list="tableNameList"
@emitFun="inputChange"
@emitButtonClick="emitButtonClick" />
<!-- <base-table
border
:table-props="tableProps"
:table-data="tableData"
:add-button-show="addButtonShow"
@emitFun="inputChange"
@emitButtonClick="emitButtonClick" /> -->
</el-col>
</el-row>
</el-form>
</template> </template>
<script> <script>
import { energyQuantityManualCreate, energyQuantityManualUpdate, energyQuantityManualGet } from '@/api/base/energyQuantityManual' import {
import moment from 'moment' energyQuantityManualCreate,
import InputArea from './InputArea' energyQuantityManualUpdate,
import SelectArea from './SelectArea' energyQuantityManualGet,
} from '@/api/base/energyQuantityManual';
import moment from 'moment';
import AddTable from './AddTable';
import InputArea from './InputArea';
import SelectArea from './SelectArea';
import { energyTableGet } from '@/api/base/energyQuantityManual';
const tableProps = [ const tableProps = [
{ {
prop: 'tableName', prop: 'tableName',
label: '表名*', label: '表名*',
subcomponent: SelectArea subcomponent: SelectArea,
}, },
{ {
prop: 'readingQuantity', prop: 'readingQuantity',
label: '抄表数*', label: '抄表数*',
subcomponent: InputArea subcomponent: InputArea,
} },
] ];
export default { export default {
name: 'EnergyQuantityManualAdd', name: 'EnergyQuantityManualAdd',
props: { props: {
energyTypeList: { energyTypeList: {
type: Array, type: Array,
required: true, required: true,
default: () => { default: () => {
return [] return [];
} },
} },
}, },
data() { data() {
return { return {
tableProps, tableProps,
tableData: [], tableData: [],
addButtonShow: '新增', tableNameList: [], //list
form: { addButtonShow: '新增',
id: '', form: {
energyTypeId: '', id: '',
unit: '', energyTypeId: '',
recordTime: '' unit: '',
}, recordTime: '',
rules: { },
energyTypeId: [{ required: true, message: '能源类型不能为空', trigger: 'change' }], rules: {
recordTime: [{ required: true, message: '抄表日期不能为空', trigger: 'change' }] energyTypeId: [
}, { required: true, message: '能源类型不能为空', trigger: 'change' },
isEdit: false ],
} recordTime: [
}, { required: true, message: '抄表日期不能为空', trigger: 'change' },
methods: { ],
init(params) { },
this.form.recordTime = moment().valueOf() isEdit: false,
if (params.type === 'add') { };
this.isEdit = false },
} else if (params.type === 'meterReading') { components: { AddTable },
this.isEdit = false methods: {
this.form.energyTypeId = params.energyTypeId init(params) {
let obj = {} this.form.recordTime = moment().valueOf();
obj.tableName = params.tableName + '' if (params.type === 'add') {
obj.readingQuantity = 0 this.isEdit = false;
this.tableData.push(obj) } else if (params.type === 'meterReading') {
} else { this.isEdit = false;
this.isEdit = true this.form.energyTypeId = params.energyTypeId;
this.form.id = params.id let obj = {};
this.addButtonShow = '' obj.tableName = params.tableName + '';
energyQuantityManualGet({ id: this.form.id }).then(res => { obj.readingQuantity = 0;
if (res.code === 0) { this.tableData.push(obj);
this.form.energyTypeId = res.data.energyTypeId } else {
this.form.recordTime = res.data.recordTime ? res.data.recordTime : null this.isEdit = true;
let obj = {} this.form.id = params.id;
obj.tableName = res.data.tableName ? res.data.tableName + '' : '' this.addButtonShow = '';
obj.readingQuantity = res.data.readingQuantity energyQuantityManualGet({ id: this.form.id }).then((res) => {
this.tableData.push(obj) if (res.code === 0) {
} this.form.energyTypeId = res.data.energyTypeId;
}) this.form.recordTime = res.data.recordTime
} ? res.data.recordTime
}, : null;
inputChange(val) { let obj = {};
this.tableData[val._pageIndex - 1][val.prop] = val[val.prop] obj.tableName = res.data.tableName ? res.data.tableName + '' : '';
}, obj.readingQuantity = res.data.readingQuantity;
emitButtonClick() { this.tableData.push(obj);
let obj = {} }
obj.tableName = '' });
obj.readingQuantity = 0 }
this.tableData.push(obj) },
}, inputChange(val) {
submitForm() { this.tableData[val._pageIndex - 1][val.prop] = val[val.prop];
this.$refs['energyQuantityManualForm'].validate((valid) => { console.log(this.tableData);
if (valid) { },
// emitButtonClick() {
if (this.tableData.length === 0) { if (!this.form.energyTypeId) {
this.$modal.msgError("抄表数据不能为空"); this.$modal.msgWarning('请先选择能源类型');
return false return false;
} else { }
for (let item of this.tableData) { let obj = {};
console.log(item) obj.tableName = '';
if (!item.tableName || (!item.readingQuantity && item.readingQuantity !== 0)) { obj.readingQuantity = 0;
this.$modal.msgError("抄表数据有空值,请检查"); this.tableData.push(obj);
return false },
} selEnergyType(id) {
} //
} this.tableData = [];
if (this.isEdit) { this.tableNameList = [];
// energyTableGet({ energyTypeId: id }).then((res) => {
energyQuantityManualUpdate({ this.tableNameList = res.data.tableObjs || [];
id: this.form.id, });
energyTypeId: this.form.energyTypeId, },
recordTime: this.form.recordTime, submitForm() {
tableName: this.tableData[0].tableName, this.$refs['energyQuantityManualForm'].validate((valid) => {
readingQuantity: this.tableData[0].readingQuantity if (valid) {
}).then((res) => { //
if (res.code === 0) { if (this.tableData.length === 0) {
this.$modal.msgSuccess("操作成功"); this.$modal.msgError('抄表数据不能为空');
this.$emit('successSubmit') return false;
} } else {
}) for (let item of this.tableData) {
} else { console.log(item);
energyQuantityManualCreate({ if (
energyTypeId: this.form.energyTypeId, !item.tableName ||
recordTime: this.form.recordTime, (!item.readingQuantity && item.readingQuantity !== 0)
data: this.tableData ) {
}).then((res) => { this.$modal.msgError('抄表数据有空值,请检查');
if (res.code === 0) { return false;
this.$modal.msgSuccess("操作成功"); }
this.$emit('successSubmit') }
} }
}) if (this.isEdit) {
} //
} else { energyQuantityManualUpdate({
return false id: this.form.id,
} energyTypeId: this.form.energyTypeId,
}) recordTime: this.form.recordTime,
}, tableName: this.tableData[0].tableName,
formClear() { readingQuantity: this.tableData[0].readingQuantity,
this.$refs.energyQuantityManualForm.resetFields() }).then((res) => {
this.form.unit = '' if (res.code === 0) {
this.isEdit = false this.$modal.msgSuccess('操作成功');
this.addButtonShow = '新增' this.$emit('successSubmit');
this.tableData = [] }
} });
} } else {
} energyQuantityManualCreate({
energyTypeId: this.form.energyTypeId,
recordTime: this.form.recordTime,
data: this.tableData,
}).then((res) => {
if (res.code === 0) {
this.$modal.msgSuccess('操作成功');
this.$emit('successSubmit');
}
});
}
} else {
return false;
}
});
},
formClear() {
this.$refs.energyQuantityManualForm.resetFields();
this.form.unit = '';
this.isEdit = false;
this.addButtonShow = '新增';
this.tableData = [];
},
},
};
</script> </script>

View File

@ -49,9 +49,7 @@ import {
} from '@/api/base/energyQuantityManual'; } from '@/api/base/energyQuantityManual';
import { getEnergyTypeListAll } from '@/api/base/energyType'; import { getEnergyTypeListAll } from '@/api/base/energyType';
import { publicFormatter } from '@/utils/dict'; import { publicFormatter } from '@/utils/dict';
import { parseTime, parseTimeTable } from '@/utils/ruoyi'; import { parseTimeTable } from '@/utils/ruoyi';
// import FileSaver from "file-saver"
// import * as XLSX from 'xlsx/xlsx.mjs'
import EnergyQuantityManualAdd from './components/energyQuantityManualAdd'; import EnergyQuantityManualAdd from './components/energyQuantityManualAdd';
import moment from 'moment'; import moment from 'moment';
const tableProps = [ const tableProps = [

View File

@ -47,7 +47,11 @@ export default {
energyTableGet({ energyTypeId: id }).then((res) => { energyTableGet({ energyTypeId: id }).then((res) => {
this.form.energyType = res.data.energyType || ''; this.form.energyType = res.data.energyType || '';
this.form.energyTypeId = res.data.energyTypeId || ''; this.form.energyTypeId = res.data.energyTypeId || '';
this.form.tableIds = res.data.tableIds || []; this.form.tableIds =
res.data.tableObjs &&
res.data.tableObjs.map((item) => {
return item.id;
});
}); });
}, },
submitForm() { submitForm() {