فهرست منبع

学校计划修改

lrf402788946 5 سال پیش
والد
کامیت
841b26dc37

+ 46 - 14
src/views/new-plan/arrange/school-arrange.vue

@@ -15,6 +15,7 @@
           </el-col> -->
         </el-row>
         <a-table
+          ref="planTabel"
           :termList="termList"
           :data="list"
           @cellClick="cellClick"
@@ -132,6 +133,7 @@ const { mapActions: schPlan } = createNamespacedHelpers('schPlan');
 // term-${termid}:${term}
 // term_batch-${batchid}: ${termid} 关键变量,拿到它,就可以找到配套的其他所有变量
 // arrange_id-${batchid}: ${_id}
+// remark-${batchid}: ${remark}
 export default {
   name: 'school-arrange',
   props: {},
@@ -176,7 +178,6 @@ export default {
         });
         this.$set(this, `list`, school);
         await this.getSchoolPlan();
-        // await this.getTotal();
       }
     },
     //自动安排提示确认
@@ -192,7 +193,8 @@ export default {
         .catch(() => {});
     },
     //自动安排
-    toArrange() {
+    async toArrange() {
+      let msg = this.$message({ message: '正在分配中,请稍后', duration: 0 });
       this.toReset();
       let school = this.list.filter(f => f.daterange);
       //整理之后的学校列表
@@ -232,10 +234,14 @@ export default {
       }
       this.$set(this, `termList`, termList);
       this.getCarTotal();
+      msg.close();
+      this.$message.success('分配完成');
     },
     //保存整体计划
     async toSave() {
       //修改学校上报计划,整理数据
+      //备注
+      let remarks = this.$refs.planTabel.remarks;
       let duplicate = _.cloneDeep(this.list);
       duplicate = duplicate.filter(f => Object.keys(f).find(key => key.includes('batch_total')));
       let schPlan = duplicate.map((i, index) => {
@@ -252,18 +258,19 @@ export default {
           let carnum = i[this.proAffix(batchid, 'car_total')] || 0;
           //数据的原_id arrange_id-${batchid}
           let _id = i[this.proAffix(batchid, 'arrange_id')];
+          //取出有备注的批次备注
+          let remark = remarks[batchid];
           //去掉值为undefined的key和value
-          arrange.push(_.pickBy({ _id, term, termid, batch, batchid, number, carnum }, _.identity));
+          arrange.push(_.pickBy({ _id, term, termid, batch, batchid, number, carnum, remark }, _.identity));
         });
         plan.arrange = arrange;
         return plan;
         // }
       });
-      console.log(schPlan);
-      this.$set(this, `schPlan`, schPlan);
+      // this.$set(this, `schPlan`, schPlan);
       schPlan = _.compact(schPlan);
-      // const res = await this.setSchPlan(schPlan);
-      // this.$checkRes(res, '保存成功', res.errmsg);
+      const res = await this.setSchPlan(schPlan);
+      this.$checkRes(res, '保存成功', res.errmsg);
     },
     cellClick(data) {
       this.drawer = true;
@@ -378,15 +385,17 @@ export default {
             i = this.changeRange(i);
             if (arrange)
               arrange.map(p => {
-                let { termid, term, batchid, batch, number, carnum, _id } = p;
+                let { termid, term, batchid, batch, number, carnum, _id, remark } = 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(batchid, 'batch_total')] = parseInt(number);
+                obj[this.proAffix(batchid, 'car_total')] = parseInt(carnum);
                 obj[this.proAffix(termid, 'term')] = term;
                 obj[this.proAffix(batchid, 'arrange_id')] = _id;
+                obj[this.proAffix(batchid, 'remark')] = remark;
                 i = { ...i, ...obj };
+                i = _.pickBy(i, _.identity);
               });
             i.plan = plan;
           }
@@ -394,10 +403,15 @@ export default {
         });
         this.$set(this, `list`, list);
         //计算下期列表的情况
-        this.computedTermList();
+        this.getTotal();
       }
       this.$set(this, `already`, true);
     },
+    //回显计算
+    getTotal() {
+      this.computedTermList();
+      this.computedSchool();
+    },
     //检查已分配的数据是否与现在的期对应
     //TODO term=>arrange {termid,batchid都需要检测}
     checkTerm(term) {
@@ -421,7 +435,6 @@ export default {
         return i; //bpt:该批次总人数 ,remaining:剩余人数
       });
       this.$set(this, `termList`, res);
-      this.already = true;
     },
     //整理计划=>和日历的 events 一样
     resetEvents() {
@@ -582,8 +595,11 @@ export default {
       let dl = _.cloneDeep(this.list);
       let arr = dt.map(t => {
         t.batchnum.map(b => {
-          let { batchid, remaining, bpt } = b;
-          let num = dl.reduce((prev, next) => prev + (next[this.proAffix(batchid, 'batch_total')] * 1 || 0), 0);
+          let { _id: batchid, remaining, bpt } = b;
+          let num = dl.reduce((prev, next) => {
+            let n = next[this.proAffix(batchid, 'batch_total')] * 1 || 0;
+            return prev + n;
+          }, 0);
           let remainder = bpt - num;
           b.remaining = remainder;
           return b;
@@ -592,6 +608,22 @@ export default {
       });
       this.$set(this, `termList`, arr);
     },
+    //根据当前情况重新计算学校剩余名额
+    computedSchool() {
+      let dl = _.cloneDeep(this.list);
+      dl = dl.map(i => {
+        let keys = Object.keys(i).filter(f => f.includes('batch_total'));
+        let { remaining } = i;
+        let n = keys.reduce((prev, next) => {
+          let num = i[next] || 0;
+          return prev + num;
+        }, 0);
+        i.remaining = remaining - n;
+        return i;
+      });
+      console.log(dl);
+      this.$set(this, `list`, dl);
+    },
   },
   filters: {
     getProp(data, prop) {

+ 30 - 13
src/views/new-plan/arrange/table/table.vue

@@ -75,7 +75,7 @@
 <script>
 import _ from 'lodash';
 const moment = require('moment');
-moment.locale('zh-cn');
+// moment.locale('zh-cn');
 import { mapState, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'table-frame',
@@ -117,13 +117,17 @@ export default {
     sumComputed({ columns, data }) {
       let arr = [];
       columns.map((col, index) => {
-        if (index == 0) arr.push('合计');
-        else {
+        if (index == 0) {
+          this.display ? arr.push('合计') : arr.push('车辆合计');
+        } else {
           let prop = _.get(col, 'property');
           if (prop == 'number') {
             let num = this.list.reduce((prev, next) => prev + next.number * 1, 0);
             arr.push(num);
-          } else arr.push(this.columnComputed(prop, data));
+          } else {
+            let r = this.display ? this.columnComputed(prop, data) : this.carComputed(prop, data);
+            arr.push(r);
+          }
         }
       });
       return arr;
@@ -142,6 +146,12 @@ export default {
       }
       return num;
     },
+    //车列计算
+    carComputed(prop, data) {
+      let { value: batchid } = this.proAffix(prop);
+      let num = data.reduce((prev, next) => prev + (next[this.proAffix(batchid, 'car_total')] || 0), 0);
+      return num;
+    },
     //手动更改
     cellClick(row, column) {
       let r = this.proAffix(column.property);
@@ -174,21 +184,28 @@ export default {
   watch: {
     termList: {
       handler(val) {
-        if (_.isArray(val)) {
-          val.map(i => {
-            i.batchnum.map(b => {
-              if (_.get(b, 'remark')) this.remarks[b._id] = _.get(b, 'remark');
-            });
-          });
-          this.$set(this, `tList`, val);
-        }
+        if (_.isArray(val)) this.$set(this, `tList`, val);
       },
       immediate: true,
       deep: true,
     },
     data: {
       handler(val) {
-        if (_.get(val, 'length', 0) > 0) this.$set(this, `list`, val);
+        if (_.get(val, 'length', 0) > 0) {
+          let remarks = {};
+          val.map(i => {
+            let keys = Object.keys(i).filter(f => f.startsWith('remark'));
+            if (keys.length > 0) {
+              keys.map(key => {
+                let remark = i[key];
+                let { value } = this.proAffix(key);
+                remarks[value] = remark;
+              });
+            }
+          });
+          this.$set(this, `remarks`, remarks);
+          this.$set(this, `list`, val);
+        }
       },
       immediate: true,
       deep: true,

+ 5 - 2
src/views/train-plan/parts/term-lesson-table.vue

@@ -30,7 +30,7 @@
 <script>
 import _ from 'lodash';
 const moment = require('moment');
-moment.locale('zh-cn');
+// moment.locale('zh-cn');
 import { mapState, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'term-lesson-table',
@@ -86,7 +86,10 @@ export default {
   },
   filters: {
     getWeekDay(date) {
-      if (date && moment(date).isValid() && moment.isMoment(moment(date))) return moment(date).format('dddd');
+      let day = '';
+      let arr = ['一', '二', '三', '四', '五', '六', '日'];
+      if (date && moment(date).isValid() && moment.isMoment(moment(date))) day = `星期${arr[moment(date).format('e')]}`;
+      return day;
     },
   },
   computed: {

+ 2 - 2
src/views/train-plan/term-lesson.vue

@@ -35,8 +35,8 @@
 <script>
 import _ from 'lodash';
 import axios from 'axios';
-const moment = require('moment');
-moment.locale('zh-cn');
+// const moment = require('moment');
+// moment.locale('zh-cn');
 import lessonTable from './parts/term-lesson-table';
 import lessonForm from './parts/term-lesson-form';
 import classForm from './parts/term-class-from';