Browse Source

调试接口,班主任上报时间-创建完成(修改未完成,看接口条件不足)

lrf402788946 5 years ago
parent
commit
134d47b734
6 changed files with 116 additions and 179 deletions
  1. 1 5
      src/router/index.js
  2. 38 0
      src/store/dir-plan.js
  3. 3 1
      src/store/index.js
  4. 66 168
      src/views/plan/detail.vue
  5. 7 4
      src/views/plan/index.vue
  6. 1 1
      vue.config.js

+ 1 - 5
src/router/index.js

@@ -39,17 +39,13 @@ const routes = [
         meta: { title: '学生', sub: '信息' },
         component: () => import('@/views/student/detail.vue'),
       },
-    
+
       {
         path: '/wenjuan/detail',
         name: 'wenjuan_detail',
         meta: { title: '学生', sub: '信息' },
         component: () => import('@/views/wenjuan/detail.vue'),
       },
-   
-
-
-
     ],
   },
 ];

+ 38 - 0
src/store/dir-plan.js

@@ -0,0 +1,38 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/train/teaplan`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 3 - 1
src/store/index.js

@@ -1,5 +1,7 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
+import trainplan from '@center/src/store/trainplan';
+import dirPlan from './dir-plan';
 
 Vue.use(Vuex);
 
@@ -7,5 +9,5 @@ export default new Vuex.Store({
   state: {},
   mutations: {},
   actions: {},
-  modules: {},
+  modules: { trainplan, dirPlan },
 });

+ 66 - 168
src/views/plan/detail.vue

@@ -11,9 +11,9 @@
               <el-form-item label="标题" prop="title">
                 {{ info.title }}
               </el-form-item>
-              <el-form-item label="备注" prop="remark">
+              <!-- <el-form-item label="备注" prop="remark">
                 <el-input v-model="info.remark" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }"></el-input>
-              </el-form-item>
+              </el-form-item> -->
 
               <el-collapse v-model="collapse" accordion>
                 <el-collapse-item title="无法带班时间列表" name="1">
@@ -32,7 +32,7 @@
         </el-col>
         <el-col :span="16" :style="`width:${widths}px`">
           <el-card ref="card">
-            <calendar @draft="selectDate" @eventClick="eventClick" :events="events"></calendar>
+            <calendar :useDraft="false" @eventClick="eventClick" :events="events"></calendar>
           </el-card>
         </el-col>
       </el-row>
@@ -45,24 +45,21 @@ import detailFrame from '@frame/layout/admin/detail-frame';
 import calendar from '@frame/components/calendar';
 import dataTable from '@frame/components/data-table';
 import _ from 'lodash';
-import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('trainplan');
+const { mapActions: dirPlan } = createNamespacedHelpers('dirPlan');
 export default {
   metaInfo: { title: '计划详情' },
   name: 'detail',
   props: {},
   components: { detailFrame, calendar, dataTable },
   data: () => ({
-    info: {
-      year: '',
-      termnum: {
-        batchnum: [],
-      },
-    },
-
+    info: {},
     form: {},
     events: [],
     collapse: '1',
     fields: [
+      { label: '名称', prop: 'name' },
       { label: '期数', prop: 'term' },
       { label: '班级类型', prop: 'type', format: item => (item === '0' ? '正常班级' : '特殊班级') },
     ],
@@ -76,160 +73,71 @@ export default {
     ],
     heights: 250,
     selected: [],
-    axiosData: {
-      termnum: [
-        {
-          term: '1',
-          batchnum: [
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '0',
-              number: '56',
-              color: '#0BEB95',
-              batch: '1',
-              class: '1',
-              title: '第1期第1批次',
-              id: 'p1580869239498',
-            },
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '1',
-              number: '56',
-              color: '#409EFF',
-              name: '第一期特殊1班',
-              title: '第一期特殊1班',
-              id: 'p1580869422722',
-            },
-          ],
-          classnum: 2,
-        },
-        {
-          term: '2',
-          batchnum: [
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '0',
-              number: '56',
-              color: '#0BEB95',
-              batch: '1',
-              class: '1',
-              title: '第2期第1批次',
-              id: 'p1580869239490',
-            },
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '1',
-              number: '56',
-              color: '#409EFF',
-              name: '第二期特殊1班',
-              title: '第二期特殊1班',
-              id: 'p1580869422723',
-            },
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '1',
-              number: '56',
-              color: '#409EFF',
-              name: '第二期特殊2班',
-              title: '第二期特殊2班',
-              id: 'p1580869422726',
-            },
-          ],
-          classnum: 3,
-        },
-        {
-          term: '3',
-          batchnum: [
-            {
-              start: '2020-01-01',
-              end: '2020-01-09',
-              type: '0',
-              number: '56',
-              color: '#ff4444',
-              batch: '1',
-              class: '1',
-              title: '第3期第1批次',
-              id: 'p1580869239499',
-            },
-          ],
-          classnum: 1,
-        },
-        {
-          term: '4',
-          batchnum: [
-            {
-              start: '2020-02-01',
-              end: '2020-02-09',
-              type: '0',
-              number: '56',
-              color: '#ff4444',
-              batch: '1',
-              class: '1',
-              title: '第4期第1批次',
-              id: 'p1580869239468',
-            },
-          ],
-          classnum: 1,
-        },
-      ],
-      title: 'test',
-      year: 2020,
-    },
   }),
   created() {
-    if (this.isNew) this.$set(this.info, `year`, new Date().getFullYear());
+    this.search();
+    //TODO 正常来说:我是根据计划进来的,我需要查的不仅是计划的信息,还需要根据计划id和用户id查询出我曾经添加过的信息做回显及修改
   },
   mounted() {},
   methods: {
-    // ...mapClass(['fetch', 'create', 'update']),
+    ...mapActions(['fetch', 'create', 'update']),
+    ...dirPlan({
+      dirCreatPlan: 'create',
+      dirUpdatePlan: 'update',
+    }),
     //查询计划
     async search() {
-      // const res = await this.fetch(this.id);
-      // if (this.$checkRes(res)) this.$set(this, `info`, res.data);
-      // this.loading = false;
+      const res = await this.fetch(this.id);
+      if (this.$checkRes(res)) this.$set(this, `info`, res.data);
+      let midArr = JSON.parse(JSON.stringify(res.data));
       let events = [];
       events = _.flatten(
-        this.axiosData.termnum.map(item => {
+        midArr.termnum.map(item => {
           item.batchnum.map(i => {
             i.term = item.term;
+            i.termid = item._id; //需要使用期id
+            i.id = i._id;
+            i.start = JSON.parse(JSON.stringify(i.startdate));
+            i.end = JSON.parse(JSON.stringify(i.enddate));
+            i.title = JSON.parse(JSON.stringify(i.name));
+            delete i.startdate, delete i.enddate;
             return i;
           });
           return item.batchnum;
         })
       );
-      let { termnum, year, title } = this.axiosData;
-      this.$set(this, `events`, events);
-      this.$set(this, `info`, { title, year });
-    },
-    selectDate(arg) {
-      let start = arg.startStr;
-      let end = arg.endStr;
-      let res = this.events.filter(fil => this.inEvents(fil.start, fil.end, start, end));
-      let arr = JSON.parse(JSON.stringify(this.selected));
-      arr = _.uniqBy(arr.concat(res), `id`);
-      this.$set(this, `selected`, arr);
+      let vac = midArr.festivals.map(i => {
+        let object = {};
+        object.id = i._id;
+        object.start = i.begindate;
+        object.end = i.finishdate;
+        object.rendering = 'background';
+        object.color = 'red';
+        object.editable = false;
+        return object;
+      });
+      this.$set(this, `events`, events.concat(vac));
     },
     //日历事件点击事件
     eventClick({ event }) {
       let arr = this.events.filter(fil => fil.id == event.id);
       let object = {};
-      if (arr.length > 0) object = arr[0];
-      else {
+      if (arr.length > 0) {
+        object = arr[0];
+        if (_.has(object, 'editable')) {
+          this.$message.warning(`不能选择假期`);
+          return false;
+        }
+      } else {
         console.warn(`无对应id事件`);
         return;
       }
-      let { term, type, name, termid, number } = object;
-      //查重,先查期数一致,再查类型
-      //期数没有,则加入;期数有,则看类型,如果是普通班级,则不加入;如果是特殊班级,则查该期是否有特殊班级的id,没有就加入
+      let { id } = object;
+      //查重,查批数id是否存在,存在重复提示;不存在添加
       let data = object;
       let re = () => {
         this.$notify({
-          title: '重复添加该',
+          title: '重复添加该批',
         });
       };
       let push = data => {
@@ -238,20 +146,9 @@ export default {
           title: '已添加',
         });
       };
-      if (_.findIndex(this.selected, i => i.term === term) >= 0) {
-        //重复加入
-        if (type === '0') re();
-        else {
-          // TODO此处需要根据实际有没有id可以区分开每期特殊班和特殊班,目前用name来区分
-          let res = _.findIndex(this.selected, i => {
-            if (i.name) return i.name === name;
-            else return false;
-          });
-          //特殊班重复加入
-          if (res > 0) re();
-          else push(data); //加入
-        }
-      } else push(data);
+      let res = _.find(this.selected, i => i.id === id);
+      if (!res) push(object);
+      else re();
     },
     //列表删除事件
     toDelete({ data, index }) {
@@ -262,10 +159,23 @@ export default {
       // 获取已选择的时间
       let arr = JSON.parse(JSON.stringify(this.selected));
       //TODO整理数据
-      let data = { ...this.info };
-      data.nobatchid = arr.map(i => i.batchId || `no id ${new Date().getTime()}`);
-      //最后加入班主任id
-      //TODO 连接接口
+      let { _id } = this.info;
+      let object = { trainplanid: _id };
+      object.nobatchid = arr.map(i => i.id || i._id);
+      //TODO修改班主任id为登录用户的id
+      object.headteacherid = 'headerTeacherTest 99991';
+      //TODO 此处需要根据什么条件来判断是修改还是添加
+      let isNew = true;
+      let res;
+      let msg;
+      if (isNew) {
+        res = this.dirCreatPlan(object);
+        msg = `时间上报成功`;
+      } else {
+        res = this.dirUpdatePlan(object);
+        msg = `时间修改成功`;
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/plan/index' });
     },
     setHeight() {
       let heights = this.$refs.card.$el.clientHeight * 0.63;
@@ -293,15 +203,6 @@ export default {
       } else return false;
     },
   },
-  watch: {
-    isNew: {
-      immediate: true,
-      handler(val) {
-        if (val) this.loading = false;
-        else this.search();
-      },
-    },
-  },
   computed: {
     widths() {
       let width = (document.body.clientWidth - 200) * 0.5;
@@ -310,9 +211,6 @@ export default {
     id() {
       return this.$route.query.id;
     },
-    isNew() {
-      return this.$route.query.id ? true : false; //false : true;
-    },
     mainTitle() {
       let meta = this.$route.meta;
       let main = meta.title || '';

+ 7 - 4
src/views/plan/index.vue

@@ -10,7 +10,8 @@
 import listFrame from '@frame/layout/admin/list-frame';
 import dataTable from '@frame/components/data-table';
 import { createNamespacedHelpers } from 'vuex';
-const { mapActions } = createNamespacedHelpers('dept');
+const { mapActions } = createNamespacedHelpers('trainplan');
+
 export default {
   metaInfo: { title: '计划管理' },
   name: 'index',
@@ -30,13 +31,15 @@ export default {
       },
     ],
     fields: [
-      { label: '计划标题', prop: 'name' },
-      { label: '时间', prop: 'time' },
+      { label: '计划标题', prop: 'title' },
+      { label: '年度', prop: 'year' },
     ],
     list: [{ name: '2020年计划', time: '2020-2021' }],
     total: 0,
   }),
-  created() {},
+  created() {
+    this.search();
+  },
   computed: {
     mainTitle() {
       let meta = this.$route.meta;

+ 1 - 1
vue.config.js

@@ -24,7 +24,7 @@ module.exports = {
     //api地址前缀
     proxy: {
       '/api': {
-        target: 'http://10.16.9.108:8001',
+        target: 'http://free.liaoningdoupo.com',
         changeOrigin: true,
         ws: true,
       },