|
@@ -125,6 +125,13 @@ const { mapActions: trainPlan } = createNamespacedHelpers('trainplan');
|
|
|
const { mapActions: util } = createNamespacedHelpers('util');
|
|
|
const { mapActions: school } = createNamespacedHelpers('school');
|
|
|
const { mapActions: schPlan } = createNamespacedHelpers('schPlan');
|
|
|
+// 表中变量:
|
|
|
+// batch-${batchid}:${batch}
|
|
|
+// batch_total-${batchid}:${number}
|
|
|
+// car_total-${batchid}: ${carnum}
|
|
|
+// term-${termid}:${term}
|
|
|
+// term_batch-${batchid}: ${termid} 关键变量,拿到它,就可以找到配套的其他所有变量
|
|
|
+// arrange_id-${batchid}: ${_id}
|
|
|
export default {
|
|
|
name: 'school-arrange',
|
|
|
props: {},
|
|
@@ -231,30 +238,29 @@ export default {
|
|
|
//修改学校上报计划,整理数据
|
|
|
let duplicate = _.cloneDeep(this.list);
|
|
|
duplicate = duplicate.filter(f => Object.keys(f).find(key => key.includes('batch_total')));
|
|
|
- console.log(duplicate);
|
|
|
- let schPlan = duplicate.map(i => {
|
|
|
+ let schPlan = duplicate.map((i, index) => {
|
|
|
let plan = _.cloneDeep(i.plan);
|
|
|
- console.log(i);
|
|
|
- // let keys = Object.keys(i).filter(f => _.startsWith(f, 'term'));
|
|
|
- // if (keys.length > 0) {
|
|
|
- // let term = [];
|
|
|
- // for (const key of keys) {
|
|
|
- // let object = {};
|
|
|
- // object.termnum = key.match(/\d+(.\d+)?/g)[0];
|
|
|
- // object._id = i[`_id_term${object.termnum}`];
|
|
|
- // object.number = i[`term${object.termnum}`];
|
|
|
- // object.termid = i[`id_term${object.termnum}`];
|
|
|
- // if (i.carTerm) {
|
|
|
- // let car = i.carTerm.find(f => f.term == object.termnum);
|
|
|
- // if (car) object.carnum = car.num;
|
|
|
- // }
|
|
|
- // term.push(object);
|
|
|
- // plan.term.push(object);
|
|
|
- // }
|
|
|
- // plan.term = term;
|
|
|
+ let arrange = [];
|
|
|
+ //arrange [object] object: _id;term;termid;batch;batchid;number;carnum
|
|
|
+ let arr_term_batch = Object.keys(i).filter(f => f.includes('term_batch')); //key的id为批次id;值为期id
|
|
|
+ arr_term_batch.map(key => {
|
|
|
+ let { value: batchid, affix } = this.proAffix(key);
|
|
|
+ let termid = i[key];
|
|
|
+ let term = i[this.proAffix(termid, 'term')];
|
|
|
+ let batch = i[this.proAffix(batchid, 'batch')];
|
|
|
+ let number = i[this.proAffix(batchid, 'batch_total')] || 0;
|
|
|
+ let carnum = i[this.proAffix(batchid, 'car_total')] || 0;
|
|
|
+ //数据的原_id arrange_id-${batchid}
|
|
|
+ let _id = i[this.proAffix(batchid, 'arrange_id')];
|
|
|
+ //去掉值为undefined的key和value
|
|
|
+ arrange.push(_.pickBy({ _id, term, termid, batch, batchid, number, carnum }, _.identity));
|
|
|
+ });
|
|
|
+ plan.arrange = arrange;
|
|
|
return plan;
|
|
|
// }
|
|
|
});
|
|
|
+ console.log(schPlan);
|
|
|
+ this.$set(this, `schPlan`, schPlan);
|
|
|
schPlan = _.compact(schPlan);
|
|
|
// const res = await this.setSchPlan(schPlan);
|
|
|
// this.$checkRes(res, '保存成功', res.errmsg);
|
|
@@ -360,31 +366,34 @@ export default {
|
|
|
let planid = _.get(this.defaultOption, 'planid');
|
|
|
const res = await this.schPlanQuery({ planid });
|
|
|
if (this.$checkRes(res)) {
|
|
|
- let nl = this.list.map(i => {
|
|
|
- let r = res.data.find(f => f.schid == i.code);
|
|
|
- if (r) {
|
|
|
- i.daterange = r.daterange;
|
|
|
+ let duplicate = _.cloneDeep(res.data);
|
|
|
+ let list = this.list.map((i, index) => {
|
|
|
+ // console.log(i);
|
|
|
+ let plan = duplicate.find(f => f.schid == i.code);
|
|
|
+ // console.log(plan);
|
|
|
+ if (plan) {
|
|
|
+ let { arrange, daterange } = plan;
|
|
|
+ i.daterange = daterange;
|
|
|
//改变上报时间格式
|
|
|
i = this.changeRange(i);
|
|
|
- let term = _.get(r, `term`);
|
|
|
- term = this.checkTerm(term);
|
|
|
- if (term) {
|
|
|
- i.carTerm = [];
|
|
|
- for (const t of term) {
|
|
|
- //需要重命名
|
|
|
- // i[`term${t.termnum}`] = t.number;
|
|
|
- // i[`id_term${t.termnum}`] = t.termid;
|
|
|
- // i[`_id_term${t.termnum}`] = t._id;
|
|
|
- //TODO 车辆需要之后计算
|
|
|
- // i.carTerm.push({ term: t.termnum, num: t.carnum });
|
|
|
- }
|
|
|
- // i.remaining = i.remaining - term.reduce((prev, next) => prev + (next.number * 1 || 0), 0);
|
|
|
- }
|
|
|
- i.plan = r;
|
|
|
+ arrange.map(p => {
|
|
|
+ let { termid, term, batchid, batch, number, carnum, _id } = p;
|
|
|
+ let obj = {};
|
|
|
+ obj[this.proAffix(batchid, 'term_batch')] = termid;
|
|
|
+ obj[this.proAffix(batchid, 'batch')] = batch;
|
|
|
+ obj[this.proAffix(batchid, 'batch_total')] = number;
|
|
|
+ obj[this.proAffix(batchid, 'car_total')] = carnum;
|
|
|
+ obj[this.proAffix(termid, 'term')] = term;
|
|
|
+ obj[this.proAffix(batchid, 'arrange_id')] = _id;
|
|
|
+ i = { ...i, ...obj };
|
|
|
+ });
|
|
|
+ i.plan = plan;
|
|
|
}
|
|
|
return i;
|
|
|
});
|
|
|
- this.$set(this, `list`, nl);
|
|
|
+ this.$set(this, `list`, list);
|
|
|
+ //计算下期列表的情况
|
|
|
+ this.computedTermList();
|
|
|
}
|
|
|
this.$set(this, `already`, true);
|
|
|
},
|
|
@@ -546,10 +555,6 @@ export default {
|
|
|
await this.getSchool();
|
|
|
},
|
|
|
//batch分离与拼接
|
|
|
- /**
|
|
|
- * value 拼接标识值
|
|
|
- * affix 拼接词缀
|
|
|
- */
|
|
|
proAffix(value, affix) {
|
|
|
if (affix) return `${affix}-${value}`;
|
|
|
else {
|
|
@@ -570,6 +575,22 @@ export default {
|
|
|
obj.batch = object[arr.find(f => f.includes('batch'))];
|
|
|
return obj;
|
|
|
},
|
|
|
+ //重新计算期列表
|
|
|
+ computedTermList() {
|
|
|
+ let dt = _.cloneDeep(this.termList);
|
|
|
+ let dl = _.cloneDeep(this.list);
|
|
|
+ let arr = dt.map(t => {
|
|
|
+ t.batchnum.map(b => {
|
|
|
+ let { batchid, remaining } = b;
|
|
|
+ let num = dl.reduce((prev, next) => prev + next[this.proAffix(batchid, 'batch_total')] * 1, 0);
|
|
|
+ let remainder = remaining - num;
|
|
|
+ b.remaining = remainder >= 0 ? remainder : 0;
|
|
|
+ return b;
|
|
|
+ });
|
|
|
+ return t;
|
|
|
+ });
|
|
|
+ this.$set(this, `termList`, arr);
|
|
|
+ },
|
|
|
},
|
|
|
filters: {
|
|
|
getProp(data, prop) {
|