Переглянути джерело

调试接口(添加已经成功,但是还没有调修改)

lrf402788946 5 роки тому
батько
коміт
0c007c82d5
3 змінених файлів з 75 додано та 24 видалено
  1. 2 1
      src/store/index.js
  2. 38 0
      src/store/sch-plan.js
  3. 35 23
      src/views/plan/detail.vue

+ 2 - 1
src/store/index.js

@@ -3,11 +3,12 @@ import Vuex from 'vuex';
 import student from '@center/src/store/student';
 import student from '@center/src/store/student';
 import teacher from '@center/src/store/teacher';
 import teacher from '@center/src/store/teacher';
 import trainplan from '@center/src/store/trainplan';
 import trainplan from '@center/src/store/trainplan';
+import schPlan from './sch-plan';
 Vue.use(Vuex);
 Vue.use(Vuex);
 
 
 export default new Vuex.Store({
 export default new Vuex.Store({
   state: {},
   state: {},
   mutations: {},
   mutations: {},
   actions: {},
   actions: {},
-  modules: { student, teacher, trainplan },
+  modules: { student, teacher, trainplan, schPlan },
 });
 });

+ 38 - 0
src/store/sch-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/schtime`,
+};
+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,
+};

+ 35 - 23
src/views/plan/detail.vue

@@ -47,6 +47,7 @@ import dataTable from '@frame/components/data-table';
 import _ from 'lodash';
 import _ from 'lodash';
 import { createNamespacedHelpers } from 'vuex';
 import { createNamespacedHelpers } from 'vuex';
 const { mapActions } = createNamespacedHelpers('trainplan');
 const { mapActions } = createNamespacedHelpers('trainplan');
+const { mapActions: schPlan } = createNamespacedHelpers('schPlan');
 export default {
 export default {
   metaInfo: { title: '计划详情' },
   metaInfo: { title: '计划详情' },
   name: 'detail',
   name: 'detail',
@@ -79,10 +80,16 @@ export default {
     heights: 250,
     heights: 250,
     selected: [],
     selected: [],
   }),
   }),
-  created() {},
+  created() {
+    this.search();
+  },
   mounted() {},
   mounted() {},
   methods: {
   methods: {
     ...mapActions(['fetch', 'create', 'update']),
     ...mapActions(['fetch', 'create', 'update']),
+    ...schPlan({
+      schPlanCreate: 'create',
+      schPlanUpdate: 'update',
+    }),
     //查询计划
     //查询计划
     async search() {
     async search() {
       const res = await this.fetch(this.id);
       const res = await this.fetch(this.id);
@@ -104,12 +111,17 @@ export default {
           return item.batchnum;
           return item.batchnum;
         })
         })
       );
       );
-      //这个events不完整,真正的events还需要将假期的数据整合至一起
-      // 不需要知道哪些是安排的计划.没有计划简表,计划简表=>上报时间表
-      //TODO,服务端修改后,整理假期事件并整合
-      console.log(events);
-      // 假期中添加一个字段 editable:false,只有假期有这个字段
-      this.$set(this, `events`, events);
+      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 }) {
     eventClick({ event }) {
@@ -170,14 +182,25 @@ export default {
       // 获取已选择的时间
       // 获取已选择的时间
       let arr = JSON.parse(JSON.stringify(this.selected));
       let arr = JSON.parse(JSON.stringify(this.selected));
       //TODO整理数据
       //TODO整理数据
-      let data = { ...this.info };
+      let { year, _id, remark } = JSON.parse(JSON.stringify(this.info));
       arr = arr.map(i => {
       arr = arr.map(i => {
-        console.log(i);
-        return { termnum: i.termnum, termid: i.termid, number: '未计算,使用实际数据计算' };
+        return { termnum: i.termnum, termid: i.termid, number: i.number };
       });
       });
-      data.term = arr;
-      //最后加入schoolId
+      // TODO 修改schoolid为登录用户的id
+      let object = { year, planid: _id, remark, term: arr, schid: '99991' };
+      let res;
+      let msg;
       //TODO 连接接口
       //TODO 连接接口
+      //需要找到条件判断是修改还是添加,默认先修改看看出现什么情况
+      let isNew = true;
+      if (isNew) {
+        res = this.schPlanCreate(object);
+        msg = `时间上报成功`;
+      } else {
+        res = this.schPlanUpdate(object);
+        msg = `时间修改成功`;
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/plan/index' });
     },
     },
     setHeight() {
     setHeight() {
       let heights = this.$refs.card.$el.clientHeight * 0.63;
       let heights = this.$refs.card.$el.clientHeight * 0.63;
@@ -208,14 +231,6 @@ export default {
       return res;
       return res;
     },
     },
   },
   },
-  watch: {
-    isNew: {
-      immediate: true,
-      handler(val) {
-        if (!val) this.search();
-      },
-    },
-  },
   computed: {
   computed: {
     widths() {
     widths() {
       let width = (document.body.clientWidth - 200) * 0.5;
       let width = (document.body.clientWidth - 200) * 0.5;
@@ -224,9 +239,6 @@ export default {
     id() {
     id() {
       return this.$route.query.id;
       return this.$route.query.id;
     },
     },
-    isNew() {
-      return this.$route.query.id ? false : true;
-    },
     mainTitle() {
     mainTitle() {
       let meta = this.$route.meta;
       let meta = this.$route.meta;
       let main = meta.title || '';
       let main = meta.title || '';