lrf402788946 5 tahun lalu
induk
melakukan
755eb5ad6e
1 mengubah file dengan 52 tambahan dan 11 penghapusan
  1. 52 11
      src/views/new-plan/arrange/school-arrange.vue

+ 52 - 11
src/views/new-plan/arrange/school-arrange.vue

@@ -161,13 +161,12 @@ export default {
         type: 'warning',
       })
         .then(() => {
-          this.toArrange();
+          this.toReset();
         })
         .catch(() => {});
     },
     //自动安排
     async toArrange() {
-      this.toReset();
       let school = this.list.filter(f => f.daterange);
       //整理之后的学校列表
       school = _.reverse(_.sortBy(school, ['level', 'hascar']));
@@ -198,23 +197,22 @@ export default {
                 }
                 b.remaining = 0; //本批次剩余名额=0;
                 sch[this.proAffix(classtype, 'remaining')] = schremaining;
-                sch = this.computedSchRemaining(sch);
                 continue;
               } else {
                 //学校名额<=本批次剩余名额
                 b.remaining = b.remaining - schremaining; //本批次剩余名额 = 本批次剩余名额(原) - 学校剩余名额;
                 if (schremaining > 0) {
-                  this.setNumOthers(sch, b, sch.remaining);
+                  this.setNumOthers(sch, b, schremaining);
                 }
                 schremaining = 0; //学校剩余名额 = 0
                 sch[this.proAffix(classtype, 'remaining')] = schremaining;
-                sch = this.computedSchRemaining(sch);
                 //让循环自然结束就好了
                 continue;
               }
             }
           }
         }
+        sch = this.computedSchRemaining(sch);
         let index = _.findIndex(this.list, f => f.code == sch.code);
         if (index >= 0) this.$set(this.list, index, sch);
       }
@@ -491,7 +489,9 @@ export default {
     },
     //分配重置
     async toReset() {
-      this.getBatchList();
+      await this.getBatchList();
+      await this.resetSchool();
+      this.toArrange();
     },
     //抽屉名额响应式计算
     dComputed(cv = 0, ov = 0) {
@@ -658,12 +658,28 @@ export default {
       let dl = _.cloneDeep(this.list);
       dl = dl.map(i => {
         let keys = Object.keys(i).filter(f => f.includes('batch_total'));
+        let term_batchKeys = Object.keys(i).filter(f => f.includes('term_batch')); //key为batchid value为termid
         let { remaining } = i;
-        let n = keys.reduce((prev, next) => {
-          let num = i[next] || 0;
-          return prev + num;
-        }, 0);
-        i.remaining = remaining - n;
+        //TODO 需要计算每种类型班级的remaining
+        // 找到批次id => 再找到对应的班级类型 => 用对应的remaining - 对应 batch_total => 最后将所有的remaining加一起,用btp - 和
+        let arr = this.termList.map(i => i.batchnum).flat();
+        for (const tbk of term_batchKeys) {
+          let { value } = this.proAffix(tbk);
+          let r = arr.find(f => f._id == value);
+          if (r) {
+            let { classtype } = r;
+            let num = i[this.proAffix(value, 'batch_total')];
+            i[this.proAffix(classtype, 'remaining')] = i[this.proAffix(classtype, 'remaining')] * 1 - num * 1;
+          }
+        }
+        let remainkey = Object.keys(i).filter(f => f.includes('remaining-'));
+        let sum = remainkey.reduce((p, n) => p + i[n] * 1, 0);
+        i['remaining'] = i.number - sum;
+        // let n = keys.reduce((prev, next) => {
+        //   let num = i[next] || 0;
+        //   return prev + num;
+        // }, 0);
+        // i.remaining = remaining - n;
         return i;
       });
       this.$set(this, `list`, dl);
@@ -675,6 +691,31 @@ export default {
       sch.remaining = num;
       return sch;
     },
+    //重置学校设置
+    async resetSchool() {
+      let res = await this.query();
+      if (this.$checkRes(res)) {
+        let nd = res.data.map(i => (i = _.omit(i, ['meta', 'id', '_id', 'logourl', 'number'])));
+        nd = this.setSchoolNumber(nd);
+        //TODO 日期没有放进去 daterange
+        let planid = _.get(this.defaultOption, 'planid');
+        res = await this.schPlanQuery({ planid });
+        if (this.$checkRes(res)) {
+          let duplicate = _.cloneDeep(res.data);
+          let list = nd.map((i, index) => {
+            let plan = duplicate.find(f => f.schid == i.code);
+            if (plan) {
+              let { daterange } = plan;
+              i.daterange = daterange;
+              //改变上报时间格式
+              i = this.changeRange(i);
+            }
+            return i;
+          });
+        }
+        this.$set(this, `list`, nd);
+      }
+    },
     async getOtherList() {
       const res = await this.getClassType();
       if (this.$checkRes(res)) this.$set(this, `classTypeList`, res.data);