Pārlūkot izejas kodu

添加课表store,修改安排课程

lrf402788946 5 gadi atpakaļ
vecāks
revīzija
1c81f51213
3 mainītis faili ar 301 papildinājumiem un 71 dzēšanām
  1. 4 0
      src/store/index.js
  2. 232 35
      src/views/plan/lesson-plan.vue
  3. 65 36
      src/views/plan/lesson.vue

+ 4 - 0
src/store/index.js

@@ -15,6 +15,8 @@ import trainplan from '@frame/store/trainplan';
 import duty from '@frame/store/duty';
 import school from '@frame/store/school';
 import schPlan from '@frame/store/sch-plan';
+import teaPlan from '@frame/store/tea-plan';
+import lesson from '@frame/store/lesson';
 
 Vue.use(Vuex);
 
@@ -35,6 +37,8 @@ export default new Vuex.Store({
     duty,
     schPlan,
     school,
+    teaPlan,
+    lesson,
   },
   state: {},
   mutations: {},

+ 232 - 35
src/views/plan/lesson-plan.vue

@@ -6,37 +6,59 @@
           <span style="font-size:24px">{{ item.name }}</span>
         </template>
         <data-table style="padding:10px" ref="table" :fields="fields" :data="item.lessons" :opera="opera" @edit="toEdit"></data-table>
-        <el-form :inline="true" size="small" style="padding:0 10px" label-width="150px">
+        <el-form :inline="true" size="small" style="padding:0 10px" label-width="120px" @submit.native.prevent>
+          <el-form-item label="班主任">
+            <el-select v-model="item.headteacherid" placeholder="请选择班主任">
+              <el-option-group v-for="group in directorList" :key="group.label" :label="group.label">
+                <el-option v-for="item in group.options" :key="item._id" :label="item.name" :value="item._id"> </el-option>
+              </el-option-group>
+            </el-select>
+          </el-form-item>
+
           <el-form-item label="礼仪课教师">
-            <el-select v-model="item.lyteacher" placeholder="请选择礼仪课教师">
+            <el-select v-model="item.lyteacherid" placeholder="请选择礼仪课教师">
               <el-option v-for="(tea, index) in lyTeacherList" :key="`lytea${index}`" :label="tea.name" :value="tea.id"></el-option>
             </el-select>
           </el-form-item>
-          <el-form-item label="开班地点">
-            <el-select v-model="item.kb" placeholder="请选择开班地点">
+
+          <el-form-item label="教室地点">
+            <el-select v-model="item.jslocationid" placeholder="请选择教室地点">
               <el-option v-for="(place, index) in locationList" :key="`lytea${index}`" :label="place.name" :value="place.id"></el-option>
             </el-select>
           </el-form-item>
-          <el-form-item label="教室地点">
-            <el-select v-model="item.room" placeholder="请选择教室地点">
+
+          <el-form-item label="开班地点">
+            <el-select v-model="item.kbyslocationid" placeholder="请选择开班地点">
               <el-option v-for="(place, index) in locationList" :key="`lytea${index}`" :label="place.name" :value="place.id"></el-option>
             </el-select>
           </el-form-item>
+
           <el-form-item label="拓展训练地点">
-            <el-select v-model="item.pra" placeholder="请选择拓展训练地点">
+            <el-select v-model="item.kzjhlocationid" placeholder="请选择拓展训练地点">
               <el-option v-for="(place, index) in locationList" :key="`lytea${index}`" :label="place.name" :value="place.id"></el-option>
             </el-select>
           </el-form-item>
+
+          <el-form-item label="用餐地点">
+            <el-select v-model="item.yclocationid" placeholder="请选择用餐地点">
+              <el-option v-for="(place, index) in locationList" :key="`lytea${index}`" :label="place.name" :value="place.id"></el-option>
+            </el-select>
+          </el-form-item>
+          <el-row type="flex" justify="center" align="middle">
+            <el-col :span="5">
+              <el-button type="primary" @click="saveLessson(item.class)" size="mini">保存班级课程</el-button>
+            </el-col>
+          </el-row>
         </el-form>
       </el-collapse-item>
     </el-collapse>
-    <el-drawer :with-header="false" :visible.sync="drawer" direction="rtl">
+    <el-drawer :with-header="false" :visible.sync="drawer" direction="rtl" @close="drawerClose">
       <el-tabs>
         <el-tab-pane style="padding:10px">
           <template #label>
             <span style="zoom:1.3">{{ form.name }}</span>
           </template>
-          <el-form ref="form" :model="form" label-width="120px" size="mini" :rules="rules">
+          <el-form ref="form" :model="form" label-width="120px" size="mini" :rules="rules" @submit.native.prevent>
             <el-form-item label="时间" prop="date">
               {{ form.date }}
             </el-form-item>
@@ -48,8 +70,8 @@
                 <el-option v-for="(item, index) in subjectList" :key="`subject${index}`" :label="item.name" :value="item.id"></el-option>
               </el-select>
             </el-form-item>
-            <el-form-item label="任课教师" prop="teacherid" required>
-              <el-input v-model="form.teacher_name" :readonly="true" placeholder="点击选择教师" @click="toChooseTeacher"></el-input>
+            <el-form-item label="任课教师" prop="teaid">
+              <el-input v-model="form.teaname" :readonly="true" placeholder="点击选择教师" @click.native="toChooseTeacher"></el-input>
             </el-form-item>
             <el-form-item label="时长" prop="day" required>
               <el-radio-group v-model="form.day">
@@ -63,37 +85,92 @@
         </el-tab-pane>
       </el-tabs>
     </el-drawer>
-    <el-dialog :visible.sync="dialog" title="选择教师"></el-dialog>
+    <el-dialog :visible.sync="dialog" title="选择教师" center @close="toClose">
+      <el-tabs v-model="teaTab">
+        <el-tab-pane style="padding:10px" label="申请授课教师" name="apply">
+          <el-form :model="applyTeacherListPag" :inline="true">
+            <el-form-item label="姓名">
+              <el-input v-model="applyTeacherListPag.name" size="mini" placeholder="请输入要查询的教师姓名"></el-input>
+            </el-form-item>
+            <el-form-item>
+              <el-button type="primary" size="mini" @click="changePage(null, 'teacher')">查询</el-button>
+            </el-form-item>
+          </el-form>
+          <data-table style="padding:10px" :fields="teaFields" :data="applyTeacherList" :opera="teaOpera" @seletTea="setTea" :height="300"></data-table>
+          <el-row type="flex" align="middle" justify="end">
+            <el-col :span="24" style="text-align:right;">
+              <el-pagination
+                background
+                layout="total, prev, pager, next"
+                :total="applyTeacherListPag.total"
+                :page-size="5"
+                :current-page.sync="applyTeacherListPag.currentPage"
+                @current-change="cur => changePage(cur, 'apply')"
+              >
+              </el-pagination>
+            </el-col>
+          </el-row>
+        </el-tab-pane>
+        <el-tab-pane style="padding:10px" label="可授课教师" name="list">
+          <el-form :model="teacherListPag" :inline="true">
+            <el-form-item label="姓名">
+              <el-input v-model="teacherListPag.name" size="mini" placeholder="请输入要查询的教师姓名"></el-input>
+            </el-form-item>
+            <el-form-item>
+              <el-button type="primary" size="mini" @click="changePage(null, 'teacher')">查询</el-button>
+            </el-form-item>
+          </el-form>
+          <data-table style="padding:10px" :fields="teaFields" :data="teacherList" :opera="teaOpera" @seletTea="setTea" :height="300"></data-table>
+          <el-row type="flex" align="middle" justify="end">
+            <el-col :span="24" style="text-align:right;">
+              <el-pagination
+                background
+                layout="total, prev, pager, next"
+                :total="teacherListPag.total"
+                :page-size="5"
+                :current-page.sync="teacherListPag.currentPage"
+                @current-change="cur => changePage(cur, 'teacher')"
+              >
+              </el-pagination>
+            </el-col>
+          </el-row>
+        </el-tab-pane>
+      </el-tabs>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import _ from 'lodash';
 import dataTable from '@frame/components/data-table';
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions: location } = createNamespacedHelpers('location'); //地点
+const { mapActions: subject } = createNamespacedHelpers('subject'); //科目
+const { mapActions: teacher } = createNamespacedHelpers('teacher'); //教师
+const { mapActions: teaPlan } = createNamespacedHelpers('teaPlan'); //教师申请
+const { mapActions: director } = createNamespacedHelpers('director'); //教师
+const { mapActions: dept } = createNamespacedHelpers('dept'); //配合教师表使用的部门表
+
 export default {
   name: 'lesson-plan',
   props: {
     start: { type: String, required: true },
     end: { type: String, required: true },
     classes: { type: Array, default: () => [] },
-    locationList: { type: Array, default: () => [] },
-    subjectList: { type: Array, default: () => [] },
-    lyTeacherList: { type: Array, default: () => [] },
-    teacherList: { type: Array, default: () => [] },
-    applyTeacherList: { type: Array, default: () => [] },
   },
   components: { dataTable },
   data: () => ({
     activeName: '0',
     drawer: false,
     dialog: false,
+    teaTab: 'apply',
     dateList: [],
     classList: [],
     fields: [
       { label: '日期', prop: 'date' },
       { label: '星期', prop: 'week' },
-      { label: '课程', prop: 'lesson' },
-      { label: '任课教师', prop: 'teacher' },
+      { label: '课程', prop: 'subname' },
+      { label: '任课教师', prop: 'teaname' },
     ],
     opera: [
       {
@@ -102,26 +179,52 @@ export default {
         method: 'edit',
       },
     ],
-    formFields: [
-      { label: '时间', model: 'date', type: 'text' },
-      { label: '星期', model: 'week', type: 'text' },
-      { label: '课程', model: 'subid', custom: true },
-      { label: '教师', model: 'teacherid', custom: true },
-      { label: '时长', model: 'day', type: 'radio' },
+    teaOpera: [
+      {
+        label: '选择教师',
+        icon: 'el-icon-check',
+        method: 'seletTea',
+      },
+    ],
+    teaFields: [
+      { label: '姓名', prop: 'name' },
+      { label: '学校', prop: 'school_name' },
+      // { label: '评分', prop: 'xxx' }, //TODO多个评分,暂时没显示
     ],
     dayList: [{ label: '一天' }, { label: '半天' }],
     rules: {
       subid: [{ required: true, message: '请选择科目' }],
-      teacherid: [{ required: true, message: '请选择任课教师' }],
       day: [{ required: true, message: '请选择时长' }],
     },
     form: {},
+    locationList: [],
+    subjectList: [],
+    lyTeacherList: [],
+    teacherList: [],
+    applyTeacherList: [],
+    directorList: [],
+    deptList: [],
+    teacherListPag: {
+      total: 0,
+      cur: 1,
+    },
+    applyTeacherListPag: {
+      total: 0,
+      cur: 1,
+    },
   }),
   created() {
     this.setDateList();
     this.setClasses();
+    this.getOtherList();
   },
   methods: {
+    ...location({ getLocationList: 'query' }),
+    ...subject({ getSubjectList: 'query' }),
+    ...teacher({ getTeacherList: 'query' }),
+    ...teaPlan({ getApplyTeacherList: 'query' }),
+    ...director({ getDirectorList: 'query' }),
+    ...dept({ getDeptList: 'query' }),
     setDateList() {
       let start = new Date(this.start);
       let end = new Date(this.end);
@@ -142,8 +245,11 @@ export default {
     setClasses() {
       let classes = JSON.parse(JSON.stringify(this.classes));
       classes.map(i => {
-        // i.dateList = JSON.parse(JSON.stringify(this.dateList));
-        i.lessons = JSON.parse(JSON.stringify(this.dateList));
+        i.lessons
+          ? i.lessons.map(i => {
+              i.week = new Date(i.date).getDay() === 0 ? 7 : new Date(i.date).getDay();
+            })
+          : (i.lessons = JSON.parse(JSON.stringify(this.dateList)));
         return i;
       });
       this.$set(this, `classList`, classes);
@@ -160,27 +266,118 @@ export default {
       this.form.day ? '' : (this.form.day = '一天');
       this.drawer = true;
     },
-    handleSave({ data, isNew }) {
-      console.log(data);
-      //根据data.id(班级id)找出是那条数据,然后根据data.date找到那条数据,将课程,教师,时长显示出来
-    },
     toChooseTeacher() {
       //TODO 根据科目id,查询教师和申请授课教师两个列表
       if (this.form.subid) {
         this.dialog = true;
-        this.$emit('getTeacher', this.form.subid);
-      }
+        this.toGetTeacherList({ query: { subid: this.form.subid } });
+      } else this.$message.warning('请选择所授科目');
+    },
+    setTea({ data }) {
+      //TODO 需要检查申请教师的数据内容
+      let { id, name } = data;
+      this.$set(this.form, `teaid`, id);
+      this.$set(this.form, `teaname`, name);
+      this.toClose();
+    },
+    toClose() {
+      this.dialog = false;
+    },
+    drawerClose() {
+      this.drawer = false;
+      this.form = {};
+      this.$refs.form.resetFields();
     },
     toSaveDrawer() {
       this.$refs['form'].validate(valid => {
         if (valid) {
-          console.log(this.form);
+          this.form.subname = this.subjectList.find(f => f._id === this.form.subid).name;
+          let form = JSON.parse(JSON.stringify(this.form));
+          let lesson = _.pick(form, ['day', 'subname', 'teaname', 'subid', 'teaid', 'date', 'week']);
+          // 整理列表所需要的数据
+          let res = this.classList.find(f => f.class === form.class);
+          let classIndex = this.classList.findIndex(f => f.class === form.class);
+          let index = res.lessons.findIndex(f => f.date === form.date);
+          this.$set(this.classList[classIndex].lessons, index, lesson);
+          this.drawerClose();
         } else {
           console.warn('form validate error!!!');
           return false;
         }
       });
     },
+    //选项列表请求
+    async getOtherList() {
+      let res;
+      res = await this.getLocationList();
+      if (this.$checkRes(res)) this.$set(this, `locationList`, res.data);
+      res = await this.getSubjectList();
+      if (this.$checkRes(res)) this.$set(this, `subjectList`, res.data);
+      res = await this.getTeacherList({ is_etiquette_teacher: '1' });
+      if (this.$checkRes(res)) this.$set(this, `lyTeacherList`, res.data);
+      res = await this.getDeptList();
+      if (this.$checkRes(res)) this.$set(this, `deptList`, res.data);
+      res = await this.getDirectorList();
+      if (this.$checkRes(res)) {
+        let arr = res.data;
+        arr = arr.map(i => {
+          let dept = this.deptList.find(f => f._id === i.department);
+          if (res) i.dept_name = dept.name;
+          else i.dept_name = '无所属部门';
+          return i;
+        });
+        let last = this.deptList.map(i => {
+          let options = arr.filter(f => f.department === i._id);
+          let label = i.name;
+          return { options, label };
+        });
+        this.$set(this, `directorList`, last);
+      }
+    },
+    //教师列表请求
+    async toGetTeacherList({ query, type }) {
+      let setTeacher = async query => {
+        let res = await this.getTeacherList(query);
+        if (this.$checkRes(res)) {
+          this.$set(this, `teacherList`, res.data);
+          this.$set(this.teacherListPag, `total`, res.total);
+        }
+      };
+      let setApply = async query => {
+        let res = await this.getApplyTeacherList(query);
+        if (this.$checkRes(res)) {
+          this.$set(this, `applyTeacherList`, res.data);
+          this.$set(this.applyTeacherListPag, `total`, res.total);
+        }
+      };
+      if (!type) {
+        //都查
+        setTeacher(query);
+        setApply(query);
+      } else if (type === 'teacher') {
+        //查教师
+        setTeacher(query);
+      } else if (type === 'apply') {
+        //查申请授课
+        setApply(query);
+      }
+    },
+    changePage(page = 1, type) {
+      let query = { skip: (page - 1) * 5 < 0 ? 0 : (page - 1) * 5, limit: 5 };
+      if (type === 'teacher') {
+        this.teacherListPag.name && this.teacherListPag.name !== '' ? (query.name = this.teacherListPag.name) : '';
+      } else {
+        this.applyTeacherListPag.name && this.applyTeacherListPag.name !== '' ? (query.name = this.applyTeacherListPag.name) : '';
+      }
+      this.toGetTeacherList({ query, type });
+    },
+    saveLessson(id) {
+      let tcc = this.classList.find(f => f.class === id);
+      console.log(tcc);
+      // let object = { class: tcc.id, term: tcc.termid, batch: tcc.batchid, lessons: tcc.lessons };
+      // // 礼仪课,开班地点,教师地点,拓展训练地点修改班级表
+      // this.$emit(`save`, tcc);
+    },
   },
   computed: {
     mainTitle() {

+ 65 - 36
src/views/plan/lesson.vue

@@ -10,16 +10,7 @@
         <data-table ref="table" :fields="fields" :data="list" :opera="opera" @date="toDate"></data-table>
       </list-frame>
       <detail-frame v-else title="返回批次列表" :returns="returnList">
-        <lesson-plan
-          :start="batch.startdate"
-          :end="batch.enddate"
-          :classes="classes"
-          :locationList="locationList"
-          :subjectList="subjectList"
-          :teacherList="teacherList"
-          :lyTeacherList="lyTeacherList"
-          @getTeacher="toGetTeacherList"
-        ></lesson-plan>
+        <lesson-plan :start="batch.startdate" :end="batch.enddate" :classes="classes" @save="handleSave"></lesson-plan>
       </detail-frame>
     </transition>
   </div>
@@ -34,9 +25,7 @@ import _ from 'lodash';
 import { createNamespacedHelpers } from 'vuex';
 const { mapActions: trainPlan } = createNamespacedHelpers('trainplan');
 const { mapActions: mapClasses } = createNamespacedHelpers('classes');
-const { mapActions: location } = createNamespacedHelpers('location'); //地点
-const { mapActions: subject } = createNamespacedHelpers('subject'); //科目
-const { mapActions: teacher } = createNamespacedHelpers('teacher'); //教师
+const { mapActions: lesson } = createNamespacedHelpers('lesson'); //教师申请
 
 //教师表,地点表,课程表
 export default {
@@ -46,6 +35,7 @@ export default {
   components: { listFrame, dataTable, detailFrame, lessonPlan },
   data: () => ({
     view: 'list',
+    term: '',
     termList: [],
     opera: [
       {
@@ -63,22 +53,14 @@ export default {
     batch: {},
     total: 0,
     classes: [],
-    locationList: [],
-    subjectList: [],
-    lyTeacherList: [],
-    teacherList: [],
-    applyTeacherList: [],
   }),
   created() {
     this.search();
-    this.getOtherList();
   },
   methods: {
     ...trainPlan({ getTrainPlan: 'fetch' }),
-    ...mapClasses({ getClass: 'query' }),
-    ...location({ getLocationList: 'query' }),
-    ...subject({ getSubjectList: 'query' }),
-    ...teacher({ getTeacherList: 'query' }),
+    ...mapClasses({ getClass: 'query', updateClass: 'update' }),
+    ...lesson({ getLessonList: 'query', lessonCreate: 'create', lessonUpdate: 'update' }),
     async search({ skip = 0, limit = 10, ...info } = {}) {
       let res = await this.getTrainPlan(this.id);
       if (this.$checkRes(res)) {
@@ -87,6 +69,7 @@ export default {
     },
     batchSearch({ skip, limit, ...info }) {
       let { term } = info;
+      this.$set(this, `term`, term);
       let res = this.termList.find(f => f._id === term);
       this.$set(this, `list`, _.sortBy(res.batchnum, ['batch']));
     },
@@ -97,25 +80,71 @@ export default {
       let { startdate, enddate } = data;
       this.$set(this.batch, `startdate`, startdate);
       this.$set(this.batch, `enddate`, enddate);
-      if (this.$checkRes(res)) this.$set(this, `classes`, res.data);
+      //查询到了班级,再查询班级是否有课表
+      if (this.$checkRes(res)) {
+        let cArr = [];
+        for (const tClass of res.data) {
+          let lesson = await this.getLessonList({ class: tClass.id });
+          if (this.$checkRes(lesson)) {
+            //根据classid查出的课表一定是唯一的,但是需要用query方法查出,所以如果有值只取出第一条,之后修改这条数据
+            let { name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid } = tClass;
+            if (lesson.data.length > 0) {
+              //说明这个班已经排过课了,整理数据
+              let ldata = JSON.parse(JSON.stringify(lesson.data[0]));
+              ldata = { ...ldata, name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid };
+              cArr.push(ldata);
+              let object = { name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid };
+              object.class = tClass.id;
+              object.batch = tClass.batchid;
+              object.term = tClass.termid;
+              cArr.push(object);
+            } else {
+              //没排课,需要动手干下,整理好数据
+              let object = { name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid };
+              object.class = tClass.id;
+              object.batch = tClass.batchid;
+              object.term = tClass.termid;
+              cArr.push(object);
+            }
+          }
+        }
+        this.$set(this, `classes`, cArr);
+      }
       this.view = 'lesson';
     },
     returnList() {
       this.view = 'list';
     },
-    async getOtherList() {
+    async handleSave(data) {
+      console.log(data);
+      //TODO 此处需要3个接口:1,课表添加;2,课表修改;3,班级修改
+      //根据data中是否有id,判断是课表的添加还是修改
+      //解构出data中class字段,是班级id,将各种地点,礼仪课老师,班主任修改好
+      let classid = data.class;
+      let { lessons, term, batch, headteacherid, jslocationid, yclocationid, kzjhlocationid, kbyslocationid, lyteacherid } = data;
+      let newLessons = { lessons, term, batch, class: classid };
+      let newClass = { id: classid, headteacherid, jslocationid, yclocationid, kzjhlocationid, kbyslocationid, lyteacherid };
+      let lid = _.get(data, `id`);
       let res;
-      res = await this.getLocationList();
-      if (this.$checkRes(res)) this.$set(this, `locationList`, res.data);
-      res = await this.getSubjectList();
-      if (this.$checkRes(res)) this.$set(this, `subjectList`, res.data);
-      res = await this.getTeacherList({ is_etiquette_teacher: '1' });
-      if (this.$checkRes(res)) this.$set(this, `lyTeacherList`, res.data);
-    },
-    async toGetTeacherList(subjectId) {
-      //applyTeacherList
-      let res = await this.getTeacherList({ subid: subjectId });
-      if (this.$checkRes(res)) this.$set(this, `teacherList`, res.data);
+      if (lid) {
+        res = await this.lessonCreate(newLessons);
+      } else {
+        newLessons.id = lid;
+        res = await this.lessonUpdate(newLessons);
+      }
+      let check = (res, sucMsg, errMsg) => {
+        if (res.errcode === 0) {
+          _.isString(sucMsg) ? this.$message.success(sucMsg) : '';
+          return true;
+        } else {
+          this.$message.error(errMsg || '处理失败');
+          return false;
+        }
+      };
+      if (check(res, null, `课表${lid ? '修改' : '添加'}失败`)) {
+        res = await this.updateClass(newClass);
+        check(res, '班级信息修改成功', '班级信息修改失败');
+      }
     },
   },
   computed: {