feat(forecast): 支持温湿度预测记录编辑与删除,修复组件调用并级联清理周期数据
这个提交包含在:
@@ -4,7 +4,7 @@ define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], functi
|
||||
new Vue({
|
||||
el: '#forecast-app',
|
||||
components: {'forecast-list': components.list, 'forecast-create': components.create, 'forecast-detail': components.detail},
|
||||
data: { rows: [], granaries: [], total: 0, page: 1, gid: '', site: '', siteOptions: Config.granarySites || [], loading: false, saving: false, creating: false, viewing: false, selected: null, loadSequence: 0 },
|
||||
data: { rows: [], granaries: [], total: 0, page: 1, gid: '', site: '', siteOptions: Config.granarySites || [], loading: false, saving: false, creating: false, editing: false, editData: null, viewing: false, selected: null, loadSequence: 0 },
|
||||
created: function () { this.load(); },
|
||||
methods: {
|
||||
api: function (action, data, method) {
|
||||
@@ -32,6 +32,25 @@ define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], functi
|
||||
changePage: function (page) { this.page = page; this.load(); },
|
||||
newRecord: function () { this.creating = true; },
|
||||
closeCreate: function (done) { if (!this.saving) { this.creating = false; if (typeof done === 'function') done(); } },
|
||||
editRecord: function (row) {
|
||||
var self = this;
|
||||
this.api('detail', {id: row.id}).then(function (res) {
|
||||
var d = res.data;
|
||||
var horizons = (d.points || []).map(function (p) { return Number(p.horizon); });
|
||||
self.editData = {
|
||||
id: d.id,
|
||||
gid: d.gid,
|
||||
observed_date: d.observed_date,
|
||||
horizons: horizons.length ? horizons : [7, 15, 30, 60],
|
||||
tm_i: d.tm_i,
|
||||
hm_i: d.hm_i,
|
||||
tm_o: d.tm_o,
|
||||
hm_o: d.hm_o
|
||||
};
|
||||
self.editing = true;
|
||||
}).catch(function () {});
|
||||
},
|
||||
closeEdit: function (done) { if (!this.saving) { this.editing = false; this.editData = null; if (typeof done === 'function') done(); } },
|
||||
closeDetail: function (done) {
|
||||
var self = this;
|
||||
if (this.saving) return;
|
||||
@@ -41,6 +60,27 @@ define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], functi
|
||||
var self = this;
|
||||
this.api('detail', {id: id}).then(function (res) { self.selected = res.data; self.viewing = true; }).catch(function () {});
|
||||
},
|
||||
deleteRecord: function (row) {
|
||||
var self = this;
|
||||
if (this.saving) return;
|
||||
this.$confirm('确定要删除【' + (row.granary_name || '') + ' · ' + (row.observed_date || '') + '】的温湿度预测记录吗?删除后关联周期的预测与实测值将一并移除且不可恢复。', '删除记录确认', {
|
||||
confirmButtonText: '确定删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function () {
|
||||
self.saving = true;
|
||||
self.api('dell', {id: row.id}, 'POST').then(function () {
|
||||
self.$message.success('删除成功');
|
||||
if (self.viewing && self.selected && self.selected.id === row.id) {
|
||||
self.viewing = false;
|
||||
self.selected = null;
|
||||
}
|
||||
self.load();
|
||||
}).catch(function () {}).then(function () {
|
||||
self.saving = false;
|
||||
});
|
||||
}).catch(function () {});
|
||||
},
|
||||
write: function (action, data, callback) {
|
||||
if (this.saving) return;
|
||||
var self = this;
|
||||
@@ -48,7 +88,7 @@ define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], functi
|
||||
this.api(action, data, 'POST').then(function (res) {
|
||||
self.selected = res.data;
|
||||
if (action !== 'actual' && res.data.status === 'failed') self.$message.warning('温湿度已保存,算法暂不可用,可稍后重新生成');
|
||||
else self.$message.success(action === 'actual' ? '实测值已保存' : res.data.status === 'ready' ? '预测已生成并保存' : '记录已保存');
|
||||
else self.$message.success(action === 'actual' ? '实测值已保存' : action === 'edit' ? '修改成功并已更新预测' : res.data.status === 'ready' ? '预测已生成并保存' : '记录已保存');
|
||||
if (callback) callback();
|
||||
self.load();
|
||||
}).catch(function () {}).then(function () { self.saving = false; });
|
||||
@@ -57,6 +97,10 @@ define(['jquery', 'bootstrap', 'backend', 'backend/forecast/components'], functi
|
||||
var self = this;
|
||||
this.write('add', form, function () { self.creating = false; self.viewing = true; });
|
||||
},
|
||||
updateRecord: function (form) {
|
||||
var self = this;
|
||||
this.write('edit', form, function () { self.editing = false; self.editData = null; self.viewing = true; });
|
||||
},
|
||||
saveActual: function (form) { this.write('actual', form); },
|
||||
retry: function (id) {
|
||||
var self = this;
|
||||
|
||||
在新工单中引用
屏蔽一个用户