lrf402788946 %!s(int64=5) %!d(string=hai) anos
pai
achega
10c2a12403
Modificáronse 4 ficheiros con 61 adicións e 60 borrados
  1. 0 3
      src/store/index.js
  2. 0 38
      src/store/plan.js
  3. 61 18
      src/views/plan/detail.vue
  4. 0 1
      src/views/plan/index.vue

+ 0 - 3
src/store/index.js

@@ -12,8 +12,6 @@ import question from './question';
 import questionnaire from './questionnaire';
 import teacher from './teacher';
 import trainplan from './trainplan';
-
-import plan from './plan';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
@@ -30,7 +28,6 @@ export default new Vuex.Store({
     questionnaire,
     teacher,
     trainplan,
-    plan,
   },
   state: {},
   mutations: {},

+ 0 - 38
src/store/plan.js

@@ -1,38 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  interface: `/api/train/trainplan`,
-};
-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,
-};

+ 61 - 18
src/views/plan/detail.vue

@@ -4,7 +4,7 @@
       <el-row :gutter="10" type="flex">
         <el-col :span="12">
           <el-card header="全年计划信息">
-            <el-form :model="info" :rules="rules" :isNew="isNew" label-width="60px" size="small" @submit.native.prevent>
+            <el-form ref="planForm" :model="info" :rules="rules" :isNew="isNew" label-width="60px" size="small" @submit.native.prevent>
               <el-form-item label="年份" required>
                 {{ info.year }}
               </el-form-item>
@@ -20,7 +20,7 @@
               <el-form-item>
                 <el-row type="flex" align="middle" justify="space-around" style="margin-top:20px">
                   <el-col :span="6">
-                    <el-button type="primary" @click="savePlan">保存全年计划</el-button>
+                    <el-button type="primary" @click="toSavePlan">保存全年计划</el-button>
                   </el-col>
                 </el-row>
               </el-form-item>
@@ -50,8 +50,8 @@ import dataTable from '@frame/components/data-table';
 import vacationForm from './parts/vacation';
 import event from './parts/event';
 import _ from 'lodash';
-import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
-const { mapActions: mapClass } = createNamespacedHelpers('trainplan');
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('trainplan');
 export default {
   metaInfo: { title: '计划详情' },
   name: 'detail',
@@ -119,15 +119,33 @@ export default {
   },
   mounted() {},
   methods: {
-    ...mapClass(['fetch', 'create', 'update']),
-    // ...mapClass(['fetch', 'create', 'update']),
-    //查询计划
-
     ...mapActions(['fetch', 'create', 'update']),
     //查询计划
     async search() {
       const res = await this.fetch(this.id);
-      console.log(res);
+      if (this.$checkRes(res)) this.$set(this, `info`, res.data);
+      let midArr = JSON.parse(JSON.stringify(res.data));
+      let events = [];
+      events = _.flatten(
+        midArr.termnum.map(item => {
+          item.batchnum.map(i => {
+            i.term = item.term;
+            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, delete i.name;
+            return i;
+          });
+          return item.batchnum;
+        })
+      );
+      //这个events不完整,真正的events还需要将假期的数据整合至一起
+      //计划+假期=所有事件 当前events=selectList 计划事件
+      //TODO,服务端修改后,整理假期事件并整合
+      console.log(events);
+      this.$set(this, `selectList`, JSON.parse(JSON.stringify(events)));
+      this.$set(this, `events`, events);
     },
     //拖拽选择事件
     selectDate(object) {
@@ -169,17 +187,37 @@ export default {
       let newEvents = this.events.filter(fil => fil.id !== data.id);
       this.$set(this, `events`, newEvents);
     },
+    //全年计划保存验证
+    toSavePlan() {
+      this.$refs['planForm'].validate(valid => {
+        if (valid) {
+          this.savePlan();
+        } else {
+          console.warn('form validate error!!!');
+        }
+      });
+    },
     //保存计划事件
-    savePlan({ isNew }) {
+    savePlan() {
       //全年计划内容
       let data = JSON.parse(JSON.stringify(this.info));
       data.year = this.info.year;
       let termnum = [];
       //1,获取所有期数
-      //2,按期数将events内数据分组
-      termnum = _.uniq(this.events.map(item => item.term)).map(i => {
+      //2,按期数将selectList内数据分组
+      termnum = _.uniq(this.selectList.map(item => item.term)).map(i => {
         let object = { term: i };
-        object.batchnum = this.events.filter(fil => fil.term === i).map(b => _.pickBy(b, (val, key) => key !== 'term'));
+        object.batchnum = this.selectList
+          .filter(fil => fil.term === i)
+          .map(b => {
+            b = _.pickBy(b, (val, key) => key !== 'term');
+            b.startdate = JSON.parse(JSON.stringify(b.start));
+            b.enddate = JSON.parse(JSON.stringify(b.end));
+            b.name ? b.name : (b.name = JSON.parse(JSON.stringify(b.title)));
+            delete b.start, delete b.end;
+            if (_.startsWith(b.id, 'eve') || _.startsWith(b.id, 'vac')) delete b.id;
+            return b;
+          });
         object.classnum = object.batchnum.reduce((pre, cur) => {
           if (cur.type === '0') return pre + parseInt(cur.class);
           else return pre + 1;
@@ -187,12 +225,17 @@ export default {
         return object;
       });
       data.termnum = termnum;
+      //3 设置假期
+      let vacation = JSON.parse(JSON.stringify(this.vacation));
+      vacation = vacation.map(i => {
+        let object = { begindate: i.start, finishdate: i.end, name: i.title };
+        return object;
+      });
+      data.festivals = vacation;
       let res;
       let msg;
-      console.log(this.isNew);
       if (this.isNew) {
         res = this.create(data);
-        console.log(data);
         msg = `${this.keyWord}添加成功`;
       } else {
         res = this.update(data);
@@ -220,7 +263,7 @@ export default {
         object = { start, end, term, type, number, color, name, title: name };
       }
       if (isNew) {
-        object.id = `p${new Date().getTime()}`;
+        object.id = `eve${new Date().getTime()}`;
         this.events.push(object);
         this.selectList.push(object);
       } else {
@@ -243,7 +286,7 @@ export default {
     //关闭抽屉函数
     toClose() {
       this.drawer = false;
-      this.form = {};
+      this.form = { color: '#409EFF' };
       this.formIsNew = true;
       this.setHeight();
     },
@@ -259,7 +302,7 @@ export default {
         arr = data.map(i => {
           i.color = `red`;
           i.editable = false;
-          i.id ? '' : (i.id = `p${new Date().getTime()}`);
+          i.id ? '' : (i.id = `vac${new Date().getTime()}`);
           return i;
         });
         this.$set(this, `events`, this.selectList.concat(arr));

+ 0 - 1
src/views/plan/index.vue

@@ -58,7 +58,6 @@ export default {
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);
         this.$set(this, `total`, res.total);
-        console.log(res.data);
       }
     },
     toEdit({ data }) {