Quellcode durchsuchen

随着班级类型列表动态输出

lrf402788946 vor 4 Jahren
Ursprung
Commit
9403cf7942
1 geänderte Dateien mit 46 neuen und 114 gelöschten Zeilen
  1. 46 114
      src/views/new-plan/arrange/school-num.vue

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

@@ -18,43 +18,22 @@
       <el-table :data="getList()" border stripe size="mini" :summary-method="getSummaries" show-summary>
       <el-table :data="getList()" border stripe size="mini" :summary-method="getSummaries" show-summary>
         <el-table-column align="center" label="学校" prop="name"></el-table-column>
         <el-table-column align="center" label="学校" prop="name"></el-table-column>
         <el-table-column align="center" label="学校代码" prop="code"></el-table-column>
         <el-table-column align="center" label="学校代码" prop="code"></el-table-column>
-        <el-table-column align="center" label="就业人数">
+        <el-table-column align="center" v-for="(c, index) in classTypeList" :key="index" :label="c.name" :prop="`num${c.code}`">
           <template v-slot="{ row, $index }">
           <template v-slot="{ row, $index }">
             <el-input-number
             <el-input-number
-              v-model="row.jynum"
-              @change="numtotal(row, $index)"
-              :max="toComputed(row, $index, (type = 'jynum'))"
+              v-model="row[`num${c.code}`]"
+              :max="toComputedMax(row, `num${c.code}`, $index)"
               :min="0"
               :min="0"
               size="mini"
               size="mini"
               :controls="false"
               :controls="false"
             ></el-input-number>
             ></el-input-number>
           </template>
           </template>
         </el-table-column>
         </el-table-column>
-        <el-table-column align="center" label="创业人数">
+        <el-table-column align="center" :label="`总人数(共计:${template.total || 0})`" prop="total">
           <template v-slot="{ row, $index }">
           <template v-slot="{ row, $index }">
-            <el-input-number
-              v-model="row.cynum"
-              @change="numtotal(row, $index)"
-              :max="toComputed(row, $index, (type = 'cynum'))"
-              :min="0"
-              size="mini"
-              :controls="false"
-            ></el-input-number>
-          </template>
-        </el-table-column>
-        <el-table-column align="center" label="少数民族人数">
-          <template v-slot="{ row, $index }">
-            <el-input-number
-              v-model="row.mznum"
-              @change="numtotal(row, $index)"
-              :max="toComputed(row, $index, (type = 'mznum'))"
-              :min="0"
-              size="mini"
-              :controls="false"
-            ></el-input-number>
+            {{ getRowTotal(row) }}
           </template>
           </template>
         </el-table-column>
         </el-table-column>
-        <el-table-column align="center" :label="`总人数(共计:${template.total || 0})`" prop="num"> </el-table-column>
       </el-table>
       </el-table>
     </detail-frame>
     </detail-frame>
   </div>
   </div>
@@ -69,6 +48,7 @@ import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: plan } = createNamespacedHelpers('trainplan');
 const { mapActions: plan } = createNamespacedHelpers('trainplan');
 const { mapActions: school } = createNamespacedHelpers('school');
 const { mapActions: school } = createNamespacedHelpers('school');
 const { mapActions: util } = createNamespacedHelpers('util');
 const { mapActions: util } = createNamespacedHelpers('util');
+const { mapActions: classtype } = createNamespacedHelpers('classtype');
 export default {
 export default {
   name: 'school-num',
   name: 'school-num',
   props: {},
   props: {},
@@ -80,7 +60,6 @@ export default {
       form: {},
       form: {},
       plan: {},
       plan: {},
       template: {},
       template: {},
-      nextmaxnum: 0,
       opera: [
       opera: [
         {
         {
           label: '修改',
           label: '修改',
@@ -88,17 +67,18 @@ export default {
           method: 'edit',
           method: 'edit',
         },
         },
       ],
       ],
+      classTypeList: [],
     };
     };
   },
   },
   async created() {
   async created() {
-    // await this.trainTemplage();
-    // await this.searchPlan();
     await this.search();
     await this.search();
+    this.getOtherList();
   },
   },
   methods: {
   methods: {
     ...plan({ getPlan: 'fetch', updatePlan: 'update' }),
     ...plan({ getPlan: 'fetch', updatePlan: 'update' }),
     ...school(['query']),
     ...school(['query']),
     ...util({ modelFetch: 'fetch' }),
     ...util({ modelFetch: 'fetch' }),
+    ...classtype({ getClassType: 'query' }),
     async trainTemplage() {
     async trainTemplage() {
       let planid = _.get(this.defaultOption, 'planid');
       let planid = _.get(this.defaultOption, 'planid');
       let planyearid = _.get(this.defaultOption, 'planyearid');
       let planyearid = _.get(this.defaultOption, 'planyearid');
@@ -106,7 +86,6 @@ export default {
       if (this.$checkRes(res)) {
       if (this.$checkRes(res)) {
         if (res.data !== null) {
         if (res.data !== null) {
           this.$set(this, `template`, res.data);
           this.$set(this, `template`, res.data);
-          this.$set(this, `nextmaxnum`, Number(res.data.total));
         }
         }
       }
       }
     },
     },
@@ -115,22 +94,15 @@ export default {
       if (!planid) return;
       if (!planid) return;
       let res = await this.getPlan(planid);
       let res = await this.getPlan(planid);
       if (this.$checkRes(res)) {
       if (this.$checkRes(res)) {
-        // res.data.school = _.uniqBy(res.data.school, 'code');
         this.$set(this, 'plan', res.data);
         this.$set(this, 'plan', res.data);
       }
       }
     },
     },
     async search({ skip = 0, limit = 10, ...info } = {}) {
     async search({ skip = 0, limit = 10, ...info } = {}) {
       let res = await this.query({ ...info });
       let res = await this.query({ ...info });
       if (this.$checkRes(res)) {
       if (this.$checkRes(res)) {
-        //TODO 查出这页的学校分配的人数,放到学校里面,表格输出
         this.$set(this, `list`, res.data);
         this.$set(this, `list`, res.data);
       }
       }
     },
     },
-    async toEdit({ data }) {
-      let { code, name, num, num_id } = data;
-      this.$set(this, `form`, { code, name, num, num_id });
-      this.dialog = true;
-    },
     async handleSave() {
     async handleSave() {
       for (const _list of this.list) {
       for (const _list of this.list) {
         let { num_id: _id, name, ...info } = _list;
         let { num_id: _id, name, ...info } = _list;
@@ -141,29 +113,7 @@ export default {
       }
       }
       let duplicate = _.cloneDeep(this.plan);
       let duplicate = _.cloneDeep(this.plan);
       let res = await this.updatePlan(duplicate);
       let res = await this.updatePlan(duplicate);
-      if (this.$checkRes(res)) {
-        this.toClose();
-        this.getNum();
-      }
-    },
-    getNum() {
-      let spl = _.get(this.plan, `school`);
-      let list = this.list.map(i => {
-        let r = spl.find(f => f.code == i.code);
-        if (r) {
-          i.num_id = r._id;
-          if (r.jynum) i.jynum = Number(r.jynum);
-          if (r.cynum) i.cynum = Number(r.cynum);
-          if (r.mznum) i.mznum = Number(r.mznum);
-          i.num = r.num;
-        }
-        return i;
-      });
-      this.$set(this, `list`, list);
-    },
-    toClose() {
-      this.dialog = false;
-      this.form = {};
+      this.$checkRes(res);
     },
     },
     getList() {
     getList() {
       let duplicate = this.list;
       let duplicate = this.list;
@@ -177,71 +127,53 @@ export default {
       });
       });
       return res;
       return res;
     },
     },
-    numtotal(row, index) {
-      let { jynum = 0, cynum = 0, mznum = 0 } = row;
-      this.list[index].num = jynum + cynum + mznum;
+    getSummaries({ columns, data }) {
+      let arr = columns.map(i => {
+        let prop = _.get(i, 'property');
+        if (prop == 'name') return '合计';
+        else if (prop == 'code') return 'N/A';
+        else {
+          if (prop == 'total') return data.reduce((p, n) => p + this.getRowTotal(n), 0);
+          else return data.reduce((p, n) => p + (n[prop] || 0) * 1, 0);
+        }
+      });
+      return arr;
     },
     },
-    toComputed(row, index, type) {
-      let { jynum = 0, cynum = 0, mznum = 0 } = row;
-      const list = this.list;
-      let nowrow = 0;
-      if (row[type]) nowrow = row[type];
-      const total = this.computeTotal(index, type);
-      // if (index == 0) {
-      //   console.log('nextmaxnum-----' + this.nextmaxnum);
-      //   console.log('total-----' + total);
-      //   console.log('nowrow-----' + nowrow);
-      //   console.log(this.nextmaxnum - total - nowrow);
-      // }
-      return this.nextmaxnum - total + nowrow;
+    async getOtherList() {
+      const res = await this.getClassType();
+      if (this.$checkRes(res)) this.$set(this, `classTypeList`, res.data);
     },
     },
-    computeTotal() {
-      let total = 0;
-      for (const _list of this.list) {
-        if (_list.jynum) {
-          total = total + _list.jynum;
-        }
-        if (_list.cynum) {
-          total = total + _list.cynum;
+    toComputedMax(row, prop, index) {
+      let keys = this.classTypeList.map(i => `num${i.code}`);
+      let { total } = this.template;
+      let lt = this.list.reduce((p, n) => {
+        let t = 0;
+        for (const key of keys) {
+          t = t + (n[key] || 0) * 1;
         }
         }
-        if (_list.mznum) {
-          total = total + _list.mznum;
-        }
-      }
-      return total;
+        return p + t;
+      }, 0);
+      let thisnum = (row[prop] || 0) * 1;
+      let elsenum = total - lt + thisnum;
+      return elsenum;
     },
     },
-    getSummaries() {
-      let numtotal = 0;
-      let jynumtotal = 0;
-      let cynumtotal = 0;
-      let mznumtotal = 0;
-      for (const _list of this.list) {
-        if (_list.num) {
-          numtotal = numtotal + Number(_list.num);
-        }
-        if (_list.jynum) {
-          jynumtotal = jynumtotal + _list.jynum;
-        }
-        if (_list.cynum) {
-          cynumtotal = cynumtotal + _list.cynum;
-        }
-        if (_list.mznum) {
-          mznumtotal = mznumtotal + _list.mznum;
-        }
+    getRowTotal(row) {
+      let keys = this.classTypeList.map(i => `num${i.code}`);
+      let total = 0;
+      for (const key of keys) {
+        total = total + (row[key] || 0) * 1;
       }
       }
-      let sums = ['合计', 'N/A', jynumtotal, cynumtotal, mznumtotal, numtotal];
-      return sums;
+      return total;
     },
     },
   },
   },
   watch: {
   watch: {
     defaultOption: {
     defaultOption: {
-      async handler(val) {
-        await this.trainTemplage();
-        await this.searchPlan();
-        // this.$refs.table.changePage();
-        await this.getNum();
+      handler(val) {
+        this.trainTemplage();
+        this.searchPlan();
       },
       },
       deep: true,
       deep: true,
+      immediate: true,
     },
     },
   },
   },
   computed: {
   computed: {