Browse Source

调试接口,目前后端没有添加type字段导致前面回显时无法分辨类型

lrf402788946 5 years ago
parent
commit
2311425a25
1 changed files with 48 additions and 30 deletions
  1. 48 30
      src/views/plan/detail.vue

+ 48 - 30
src/views/plan/detail.vue

@@ -54,19 +54,13 @@ export default {
   props: {},
   components: { detailFrame, calendar, dataTable },
   data: () => ({
-    info: {
-      year: '',
-      termnum: {
-        batchnum: [],
-      },
-    },
+    info: {},
     form: {},
     events: [],
     collapse: '1',
     fields: [
       // { label: '期数', prop: 'termnum' },
       { label: '名称', prop: 'name' },
-      { label: '班级类型', prop: 'type', format: item => (item === '0' ? '正常班级' : '特殊班级') },
       { label: '总人数', prop: 'number', format: item => `${item}人` },
     ],
     opera: [
@@ -83,14 +77,35 @@ export default {
   created() {
     this.search();
     //TODO 正常来说:我是根据计划进来的,我需要查的不仅是计划的信息,还需要根据计划id和用户id查询出我曾经添加过的信息做回显及修改
+    this.searchSch();
   },
   mounted() {},
   methods: {
     ...mapActions(['fetch', 'create', 'update']),
     ...schPlan({
+      schQuery: 'query',
       schPlanCreate: 'create',
       schPlanUpdate: 'update',
     }),
+    async searchSch() {
+      let res = await this.schQuery({ planid: this.info.id, schid: '99991' });
+      if (this.$checkRes(res)) {
+        let data = JSON.parse(JSON.stringify(res.data));
+        if (res.data.length > 0) {
+          this.$set(this.info, `schplanid`, data[0]._id);
+          let list = _.flatten(data.map(i => i.term));
+          list = list.map(i => {
+            if (i.type === '0') i.name = `第${i.termnum}期`;
+            else if (i.type) {
+              let fRes = _.find(this.events, f => f.termid === i.termid && f.type === i.type);
+              i.name = fRes.name || fRes.title;
+            }
+            return i;
+          });
+          this.$set(this, `selected`, list);
+        }
+      }
+    },
     //查询计划
     async search() {
       const res = await this.fetch(this.id);
@@ -128,16 +143,14 @@ export default {
     eventClick({ event }) {
       let arr = this.events.filter(fil => fil.id == event.id);
       let object = {};
-      let nextArr = [];
       if (arr.length > 0) {
         //有这个事件
         object = arr[0];
-        //再判断这个类型是普通,还是特殊;如果是普通类型:则需要将这一期的所有普通类型都查出来;特殊类型直接object
-        if (object.type === '0') nextArr = this.events.filter(f => f.termid === object.termid && f.type === '0');
-        if (!_.get(object, 'editable', true)) {
-          this.$message.warning('不能上报假期的时间');
-          return;
-        }
+        if (object.type === '0')
+          if (!_.get(object, 'editable', true)) {
+            this.$message.warning('不能上报假期的时间');
+            return;
+          }
       } else {
         console.warn(`无对应id事件`);
         return;
@@ -160,18 +173,22 @@ export default {
       // 需要判断期id和期类型
       let isSelected = this.selected.filter(i => i.termid === termid && i.type == type);
       if (isSelected.length > 0) {
-        //普通班=>重复加入
-        if (type === '0') re();
-        else {
-          // 特殊班=>使用id(batchid,批的id)判断
-          let res = this.selected.filter(f => f.id === id);
-          //特殊班重复加入
-          if (res.length > 0) re();
-          else push(this.setSchoolDate(object)); //加入
-        }
+        //因为特殊班一期有一个班,按上面条件过滤后,能确定是否有该期该种班
+        re();
+        // //普通班=>重复加入
+        // if (type === '0') re();
+        // else {
+        //   // 特殊班=>使用id(batchid,批的id)判断
+        //   let res = this.selected.filter(f => f.id === id);
+        //   //特殊班重复加入
+        //   if (res.length > 0) re();
+        //   else push(this.setSchoolDate(object)); //加入
+        // }
       } else {
-        if (type === '0') push(this.setSchoolDate(nextArr));
-        else push(this.setSchoolDate(object)); //加入
+        if (type === '0') {
+          let nextArr = this.events.filter(f => f.termid === object.termid && f.type === '0');
+          push(this.setSchoolDate(nextArr));
+        } else push(this.setSchoolDate(object)); //加入
       }
     },
     //列表删除事件
@@ -183,9 +200,11 @@ export default {
       // 获取已选择的时间
       let arr = JSON.parse(JSON.stringify(this.selected));
       //TODO整理数据
-      let { year, _id, remark } = JSON.parse(JSON.stringify(this.info));
+      let { year, _id, remark, schplanid } = JSON.parse(JSON.stringify(this.info));
       arr = arr.map(i => {
-        return { termnum: i.termnum, termid: i.termid, number: i.number };
+        let obj = { termnum: i.termnum, termid: i.termid, number: i.number, type: i.type };
+        i._id ? (obj.id = i._id) : '';
+        return obj;
       });
       // TODO 修改schoolid为登录用户的id
       let object = { year, planid: _id, remark, term: arr, schid: '99991' };
@@ -193,11 +212,11 @@ export default {
       let msg;
       //TODO 连接接口
       //需要找到条件判断是修改还是添加,默认先修改看看出现什么情况
-      let isNew = true;
-      if (isNew) {
+      if (!schplanid) {
         res = this.schPlanCreate(object);
         msg = `时间上报成功`;
       } else {
+        object.id = schplanid;
         res = this.schPlanUpdate(object);
         msg = `时间修改成功`;
       }
@@ -227,7 +246,6 @@ export default {
         res.termid = JSON.parse(JSON.stringify(data.termid));
         res.type = JSON.parse(JSON.stringify(data.type));
         res.name = JSON.parse(JSON.stringify(data.title));
-        res.id = JSON.parse(JSON.stringify(data._id));
       }
       return res;
     },