wszhyWx/src/views/page/formula.vue
2025-06-27 17:42:15 +08:00

500 lines
18 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="formula">
<set-params></set-params>
<div class="page-content">
<div class="table-title">
<img src="../../assets/image/formula.png" alt=""> {{ titleName }}{{$t('formula.parameters')}} <div class="tips">{{$store.state.equipmentName['fertilization' + $store.state.nameList[indexs-1]]}}</div>
</div>
<div class="input-view">
<div class="input-sel">
<span>{{$t('formula.formulaMode')}}</span>
<el-dropdown @command="handleCommand">
<div class="el-dropdown-link">
<input type="text" v-model="dataSel" class="input-input" :placeholder="$t('formula.flowRatioMode')">
<div class="arrow"><img src="../../assets/image/arrow.png" alt=""></div>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="item.value" v-for="item, index in selList" :key="index">{{ item.label
}}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<div class="input-main">
<span>{{$t('formula.targetPH')}}</span>
<input @blur="blurChangeCount(store.formulaNum[indexs - 1], $event)"
v-model="inputData[store.formulaNum[indexs - 1]]"
@input="changeCount(store.formulaNum[indexs - 1], $event)" type="number" placeholder="0.0">
</div>
<div class="input-main">
<span>{{$t('formula.targetEC')}}</span>
<input @blur="blurChangeCount(store.formulaNum[indexs - 1] + 1, $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 1]"
@input="changeCount(store.formulaNum[indexs - 1] + 1, $event)" type="number" placeholder="0.0">
</div>
</div>
<div class="table-view">
<el-table :data="tableData" :row-class-name="tableRowClassName" height="620" style="width: 100%">
<el-table-column prop="data0" :label="$t('formula.fertilizerType')">
<template slot-scope="scope">
<div @click="openType(scope.$index)" class="status" :class="'status' + scope.row.status + (scope.row.open ? '' : ' noSel')">{{ scope.row.data0 }}
</div>
</template>
</el-table-column>
<el-table-column :label="$t('formula.waterToFertilizerRatio')">
<template slot-scope="scope">
<div class="input-main-60">
<input @blur="blurChange(store.formulaNum[indexs - 1] + 5 + scope.$index, $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 5 + scope.$index]"
@input="change(store.formulaNum[indexs - 1] + 5 + scope.$index, $event)" type="number"
style="height: 34px;margin: 0 auto;" placeholder="0.0">
</div>
</template>
</el-table-column>
<el-table-column :label="$t('formula.fixedIntakeIntensity')">
<template slot-scope="scope">
<div class="input-main-60">
<input @blur="blurChange(store.formulaNum[indexs - 1] + 15 + scope.$index, $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 15 + scope.$index]"
@input="change(store.formulaNum[indexs - 1] + 15 + scope.$index, $event)" type="number"
style="height: 34px;margin: 0 auto;" placeholder="0.0">
</div>
</template>
</el-table-column>
<el-table-column prop="data3" :label="$t('formula.targetPHECMode')">
<template slot-scope="scope">
<div class="type0" v-if="scope.row.type == 0">
<div class="input-main-60 table-input">
<span> {{ scope.row.data3 }}</span>
<input @blur="blurChangeCount(store.formulaNum[indexs - 1] + 24 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 24]"
@input="changeCount(store.formulaNum[indexs - 1] + 24, $event)" type="number" style="height: 34px;"
placeholder="0.0">
</div>
</div>
<div class="type0" v-if="scope.row.type == 1">
<div class="input-main-60 table-input">
<span> {{ scope.row.data3 }}</span>
<input @blur="blurChangeCount(store.formulaNum[indexs - 1] + 25 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 25]"
@input="changeCount(store.formulaNum[indexs - 1] + 25, $event)" type="number" style="height: 34px;"
placeholder="0.0">
</div>
</div>
<div class="type1" v-if="scope.row.type == 2">
<div class="input-main-60">
<span> {{$t('formula.fertilizerChannelMax')}}</span>
<input @blur="blurChange(store.formulaNum[indexs - 1] + 4 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 4]"
@input="change(store.formulaNum[indexs - 1] + 4, $event)" type="number" style="height: 34px;"
placeholder="0.0">
</div>
</div>
<div class="type2"
@click="change14(store.formulaNum[indexs - 1] + 14, inputData[store.formulaNum[indexs - 1] + 14])"
:class="inputData[store.formulaNum[indexs - 1] + 14] ? '' : 'noSel'" v-if="scope.row.type == 3">
<img src="../../assets/image/left-img1.png" alt="">
{{ scope.row.data3 }}
</div>
<div class="type1" v-if="scope.row.type == 5">
<div class="input-main-60">
<span>{{$t('formula.initialPH')}}</span>
<input @blur="blurChange(store.formulaNum[indexs - 1] + 26 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 26]"
@input="change(store.formulaNum[indexs - 1] + 26, $event)" type="number" style="height: 34px;margin: 0 5px;"
placeholder="0.0">
<span style="padding:0">%</span>
</div>
</div>
<div class="type1" v-if="scope.row.type == 6">
<div class="input-main-60">
<span>{{$t('formula.initialEC')}}</span>
<input @blur="blurChange(store.formulaNum[indexs - 1] + 27 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 27]"
@input="change(store.formulaNum[indexs - 1] + 27, $event)" type="number" style="height: 34px;margin: 0 5px;"
placeholder="0.0">
<span style="padding:0">%</span>
</div>
</div>
<div class="type1" v-if="scope.row.type == 7">
<div class="input-main-60">
<span>{{$t('formula.initialTime')}}</span>
<input @blur="blurChange(store.formulaNum[indexs - 1] + 28 , $event)"
v-model="inputData[store.formulaNum[indexs - 1] + 28]"
@input="change(store.formulaNum[indexs - 1] + 28, $event)" type="number" style="height: 34px;margin: 0 5px;"
placeholder="0.0">
<span style="padding:0"></span>
</div>
</div>
</template>
</el-table-column>
</el-table>
</div>
</div>
</div>
</template>
<script>
import setParams from '../../components/setParams.vue';
export default {
components: {
setParams
},
data() {
return {
selList: [ { label: this.$t('formula.formulaModes.flowRatio'), value: 1 },
{ label: this.$t('formula.formulaModes.fixedIntakeFlow'), value: 2 },
{ label: this.$t('formula.formulaModes.phEcPid'), value: 3 }],
tableData: [{
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'A'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: this.$t('formula.fertilizerOptions.ecMaxDeviation'),
type: 0
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'B'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: this.$t('formula.fertilizerOptions.phMaxDeviation'),
type: 1
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'C'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: '',
type: 4
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'D'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: '0',
type: 2
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'E'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: this.$t('formula.fertilizerOptions.targetValueLimit'),
type: 3
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'F'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: '',
type: 5
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'G'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: '',
type: 6
}, {
data0: this.$t('formula.fertilizerOptions.Fertilizer', {n: 'H'}),
open: true,
status: 0,
data1: '0',
data2: '0',
data3: '',
type: 7
}, {
data0: this.$t('formula.fertilizerOptions.acid'),
open: true,
status: 1,
data1: '0',
data2: '0',
data3: '',
type: 4
}],
indexs: 1,
titleName: '',
inputData: [],
dataSel: '',
store: this.$store.state,
loading:null,
numlist:[],
}
},
watch: {
$route(newVal, oldVal) {
const that = this;
var store = this.$store.state
this.indexs = this.$route.query.id ? this.$route.query.id : 1;
this.titleName = store.equipmentName['fertilization' + store.nameList[this.indexs - 1]]
this.loading = this.$loading({
lock: true,
text: this.$t('message.loading'),
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
setTimeout(() => {
that.dataInit();
}, 0);
},
},
mounted() {
const that = this;
var store = this.$store.state
this.indexs = this.$route.query.id ? Number(this.$route.query.id) : 1;
this.titleName = store.equipmentName['fertilization' + store.nameList[this.indexs - 1]]
this.loading = this.$loading({
lock: true,
text: this.$t('message.loading'),
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
setTimeout(() => {
that.dataInit();
}, 0);
this.$nextTick(() => {
let inputList = document.querySelectorAll('input');
for (let index = 0; index < inputList.length; index++) {
inputList[index].onfocus = this.selectValue;//input放入焦点全选文本
}
});
//input获取焦点后全选
},
methods: {
openType(index){
var store = this.$store.state
if(this.tableData[index].open){
this.numlist[this.numlist.length - 1 - index]='0'
this.tableData[index].open=false
}else{
this.numlist[this.numlist.length - 1 - index]='1'
this.tableData[index].open=true
}
var num = this.numlist.join("");
var dataNum = {
target: {
value: parseInt(num, 2),
},
};
this.changeBtn(store.formulaNum[this.indexs - 1] + 3, dataNum);
},
//修改数据的函数
changeBtn(code, el) {
var store = this.$store.state
var data = {
equipmentId: store.equipmentList[store.equipmentIndex - 1].deviceId,
regAddress: code,
num: el.target.value,
};
this.delayTimerBtn(0, data);
},
//切换btn的限制 写入停止后j*100毫秒调取函数
delayTimerBtn(i, data) {
const that = this;
//整体接口
let j = this.$store.state.lateSendBtn;
//避免开启多个计时器
this.timer && clearInterval(this.timer);
this.timer = setInterval(() => {
++i;
if (i == j) {
that.changeData(data);
clearInterval(this.timer);
}
}, 100);
},
getSeldata3(num) {
var number = this.padString(num.toString(2), 16)
this.numlist = number.split('')
this.numlist.forEach((el, index) => {
if(index<this.tableData.length){
if (Number(this.numlist[this.numlist.length - 1 - index])) {
this.tableData[index].open = true
} else {
this.tableData[index].open = false
}
}
})
},
padString(str, length) {
return str.padStart(length, '0');
},
dataInit() {
var store = this.$store.state
var data = {
equipmentId: store.equipmentList[store.equipmentIndex - 1].deviceId,
pattern: store.formulaNum[this.indexs - 1], //需要根据文档填写 //6目标ph-数值
regNum: 29,
};
this.api.postReg(data).then((res) => {
this.loading.close()
if (res.data.code == 200) {
this.inputData = res.data.data;
this.inputData[store.formulaNum[this.indexs - 1]] = this.countData1(this.inputData[store.formulaNum[this.indexs - 1]])
this.inputData[store.formulaNum[this.indexs - 1] + 1] = this.countData1(this.inputData[store.formulaNum[this.indexs - 1] + 1])
this.inputData[store.formulaNum[this.indexs - 1] + 24] = this.countData1(this.inputData[store.formulaNum[this.indexs - 1] + 24])
this.inputData[store.formulaNum[this.indexs - 1] + 25] = this.countData1(this.inputData[store.formulaNum[this.indexs - 1] + 25])
this.getSeldata(this.inputData[store.formulaNum[this.indexs - 1] + 2])
this.getSeldata3(this.inputData[store.formulaNum[this.indexs - 1] + 3])
} else {
this.$message.error(res.data.msg);
}
});
},
//点击限制按钮 打开/关闭
change14(code, data) {
var store = this.$store.state
if (data) {
this.inputData[store.formulaNum[this.indexs - 1] + 14] = 0
} else {
this.inputData[store.formulaNum[this.indexs - 1] + 14] = 1
}
var data = {
target: {
value: this.inputData[store.formulaNum[this.indexs - 1] + 14]
}
}
this.changeBtn(code, data)
},
//反向计算 上传前 *10
changeCount(code, el) {
var store = this.$store.state
var data = {
target: {
value: el.target.value * 10
}
};
// console.log(data,11);
// this.changeBtn(code, data)
},
//失去焦点
blurChangeCount(code, el) {
var store=this.$store.state
var data = {
equipmentId: store.equipmentList[store.equipmentIndex-1].deviceId,
regAddress: code,
num: el.target.value * 10,
}; //避免开启多个计时器
if (store.nowInput != el.target.value) {
this.changeData(data);
}
// if (this.timer) {
// this.timer && clearInterval(this.timer);
// this.changeData(data);
// }
},
//计算数据 /10
countData1(data) {
return data / 10
},
getSeldata(index) {
var data = index;
var textSel = "";
if (data == "1") {
textSel = this.$t('formula.formulaModes.flowRatio');
} else if (data == "2") {
textSel =this.$t('formula.formulaModes.fixedIntakeFlow');
} else if (data == "3") {
textSel =this.$t('formula.formulaModes.phEcPid');
}
this.dataSel = textSel;
},
handleCommand(command) {
var store = this.$store.state
this.inputData[store.formulaNum[this.indexs - 1] + 2] = command;
this.getSeldata(command)
var dataSel = {
target: {
value: this.inputData[store.formulaNum[this.indexs - 1] + 2],
},
}
this.changeBtn(store.formulaNum[this.indexs - 1] + 2, dataSel);
},
//全选文本
selectValue(e) {
var store = this.$store.state
store.nowInput=e.target.value
e.currentTarget.select();
},
//失去焦点
blurChange(code, el) {
var store=this.$store.state
var data = {
equipmentId: store.equipmentList[store.equipmentIndex-1].deviceId,
regAddress: code,
num: el.target.value,
}; //避免开启多个计时器
if (store.nowInput != el.target.value) {
this.changeData(data);
}
// if (this.timer) {
// this.timer && clearInterval(this.timer);
// this.changeData(data);
// }
},
change(code, el) {
var store = this.$store.state
var data = {
equipmentId: store.equipmentList[store.equipmentIndex - 1].deviceId,
regAddress: code,
num: el.target.value,
};
this.delayTimer(0, data);
},
//限制 写入停止后j*100毫秒调取函数
delayTimer(i, data) {
// const that = this;
// //整体接口
// let j = this.$store.state.lateSend;
// //避免开启多个计时器
// this.timer && clearInterval(this.timer);
// this.timer = setInterval(() => {
// ++i;
// if (i == j) {
// that.changeData(data);
// clearInterval(this.timer);
// }
// }, 100);
},
changeData(data) {
var store = this.$store.state
this.api.postWriteFs(data).then((res) => {
if (res.data.code == 200) {
this.$message({
message: res.data.msg,
type: "success",
});
store.nowInput=''
// this.dataInit();
} else {
this.inputData[data.regAddress]=store.nowInput
this.$message.error(res.data.msg);
}
this.timer = null
});
},
tableRowClassName({ row, rowIndex }) {
if (rowIndex % 2 == 1) {
return 'warning-row';
} else if (rowIndex % 2 == 0) {
return 'success-row';
}
return '';
}
},
}
</script>
<style lang="scss"></style>