feat(forecast): 支持温湿度预测记录编辑与删除,修复组件调用并级联清理周期数据
这个提交包含在:
@@ -82,19 +82,32 @@ define([], function () {
|
||||
}
|
||||
},
|
||||
create: {
|
||||
template: '#forecast-create-template', props: ['granaries', 'busy', 'siteDefaultEnv'],
|
||||
data: function () { return {
|
||||
form: {gid: '', observed_date: today(), horizons: [7, 15, 30, 60], tm_i: 18.5, hm_i: 70.0, tm_o: 32.0, hm_o: 55.0, request_key: requestKey()},
|
||||
dateOptions: dateOptions,
|
||||
presets: PRESETS,
|
||||
selectedPresetKey: 'quasi_low',
|
||||
fields: [
|
||||
{key: 'tm_i', label: '仓内温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:18.5'},
|
||||
{key: 'hm_i', label: '仓内相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:70.0'},
|
||||
{key: 'tm_o', label: '仓外温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:32.0'},
|
||||
{key: 'hm_o', label: '仓外相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:55.0'}
|
||||
]
|
||||
}; },
|
||||
template: '#forecast-create-template', props: ['granaries', 'busy', 'initialData', 'isEdit'],
|
||||
data: function () {
|
||||
var d = this.initialData;
|
||||
return {
|
||||
form: {
|
||||
id: d && d.id ? d.id : '',
|
||||
gid: d && d.gid ? d.gid : '',
|
||||
observed_date: d && d.observed_date ? d.observed_date : today(),
|
||||
horizons: d && d.horizons ? d.horizons.slice() : [7, 15, 30, 60],
|
||||
tm_i: d && d.tm_i !== undefined ? Number(d.tm_i) : 18.5,
|
||||
hm_i: d && d.hm_i !== undefined ? Number(d.hm_i) : 70.0,
|
||||
tm_o: d && d.tm_o !== undefined ? Number(d.tm_o) : 32.0,
|
||||
hm_o: d && d.hm_o !== undefined ? Number(d.hm_o) : 55.0,
|
||||
request_key: requestKey()
|
||||
},
|
||||
dateOptions: dateOptions,
|
||||
presets: PRESETS,
|
||||
selectedPresetKey: d ? '' : 'quasi_low',
|
||||
fields: [
|
||||
{key: 'tm_i', label: '仓内温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:18.5'},
|
||||
{key: 'hm_i', label: '仓内相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:70.0'},
|
||||
{key: 'tm_o', label: '仓外温度', unit: '℃', min: -50, max: 80, step: 0.1, placeholder: '例:32.0'},
|
||||
{key: 'hm_o', label: '仓外相对湿度', unit: '%', min: 0, max: 100, step: 0.1, placeholder: '例:55.0'}
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
tempStatus: function () {
|
||||
return evaluateTemp(this.form.tm_i, this.form.hm_i);
|
||||
@@ -107,7 +120,9 @@ define([], function () {
|
||||
watch: {
|
||||
'form.gid': function (newGid) {
|
||||
if (!newGid) return;
|
||||
this.onGranaryChange(newGid);
|
||||
if (!this.isEdit) {
|
||||
this.onGranaryChange(newGid);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -119,7 +134,7 @@ define([], function () {
|
||||
this.form.hm_i = p.hm_i;
|
||||
this.form.tm_o = p.tm_o;
|
||||
this.form.hm_o = p.hm_o;
|
||||
this..success('已套用【' + p.name + '】规范温湿度');
|
||||
this.$message.success('已套用【' + p.name + '】规范温湿度');
|
||||
},
|
||||
onGranaryChange: function (gid) {
|
||||
var granary = this.granaries.find(function (g) { return String(g.id) === String(gid); });
|
||||
@@ -131,18 +146,18 @@ define([], function () {
|
||||
this.form.tm_o = Number(granary.last_env.tm_o);
|
||||
this.form.hm_o = Number(granary.last_env.hm_o);
|
||||
this.selectedPresetKey = '';
|
||||
this..info('已自动读取【' + granary.name + '】最近一次温湿度记录');
|
||||
this.$message.info('已自动读取【' + granary.name + '】最近一次温湿度记录');
|
||||
} else if (this.form.tm_i === '' || this.form.tm_i === undefined) {
|
||||
this.applyPreset('quasi_low');
|
||||
}
|
||||
},
|
||||
submit: function () {
|
||||
if (!this.form.gid || !this.form.observed_date || !this.form.horizons.length) return this..warning('请选择仓库、采集日期和预测周期');
|
||||
if (!this.form.gid || !this.form.observed_date || !this.form.horizons.length) return this.$message.warning('请选择仓库、采集日期和预测周期');
|
||||
for (var i = 0; i < this.fields.length; i++) {
|
||||
var f = this.fields[i], v = this.form[f.key];
|
||||
if (v === '' || !Number.isFinite(Number(v)) || Number(v) < f.min || Number(v) > f.max) return this..warning('请填写有效的' + f.label + '(' + f.min + '~' + f.max + ')');
|
||||
if (v === '' || !Number.isFinite(Number(v)) || Number(v) < f.min || Number(v) > f.max) return this.$message.warning('请填写有效的' + f.label + '(' + f.min + '~' + f.max + ')');
|
||||
}
|
||||
this.('submit', JSON.parse(JSON.stringify(this.form)));
|
||||
this.$emit('submit', JSON.parse(JSON.stringify(this.form)));
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -182,7 +197,7 @@ define([], function () {
|
||||
},
|
||||
confirmDiscard: function () {
|
||||
if (this.busy) return Promise.reject();
|
||||
return this.dirty ? this.('当前周期有未保存的实测数据,确定放弃修改?', '未保存的数据', {type: 'warning'}) : Promise.resolve();
|
||||
return this.dirty ? this.$confirm('当前周期有未保存的实测数据,确定放弃修改?', '未保存的数据', {type: 'warning'}) : Promise.resolve();
|
||||
},
|
||||
beforeLeave: function () {
|
||||
return this.confirmDiscard().then(function () { return true; });
|
||||
@@ -193,10 +208,10 @@ define([], function () {
|
||||
var m = this.record.metrics[i], v = this.actual[m.key];
|
||||
if (v === '') continue;
|
||||
any = true;
|
||||
if (!Number.isFinite(Number(v)) || Number(v) < 0 || Number(v) > m.max) return this..warning('请填写有效的' + m.name + '实测值');
|
||||
if (!Number.isFinite(Number(v)) || Number(v) < 0 || Number(v) > m.max) return this.$message.warning('请填写有效的' + m.name + '实测值');
|
||||
}
|
||||
if (any && !this.actualDate) return this..warning('请选择实际检测日期');
|
||||
this.('save', {point_id: this.point.id, version: this.point.version, actual_date: this.actualDate, actual: Object.assign({}, this.actual)});
|
||||
if (any && !this.actualDate) return this.$message.warning('请选择实际检测日期');
|
||||
this.$emit('save', {point_id: this.point.id, version: this.point.version, actual_date: this.actualDate, actual: Object.assign({}, this.actual)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户