lrf402788946 4 年之前
父節點
當前提交
c92b08f3fc
共有 3 個文件被更改,包括 238 次插入9 次删除
  1. 224 0
      src/components/excel-term-lesson.vue
  2. 3 5
      src/views/bedroom/detail.vue
  3. 11 4
      src/views/new-plan/teacher-lesson.vue

+ 224 - 0
src/components/excel-term-lesson.vue

@@ -0,0 +1,224 @@
+<template>
+  <div id="excel-term-lesson">
+    <table>
+      <tr style="border: 0.1px solid;">
+        <template v-for="(b, bindex) in getBatchData('0', '5f5aed5e69b4221aedaa4fb5')">
+          <th :key="bindex">
+            日期
+            <tr>
+              <template v-for="(d, dindex) in getBatchDayList('0', '5f5aed5e69b4221aedaa4fb5', b)">
+                <td :key="`date-${dindex}`" style="display: grid;">{{ d }}&nbsp;</td>
+              </template>
+            </tr>
+          </th>
+
+          <th :key="bindex">
+            星期
+            <tr>
+              <template v-for="(d, dindex) in getBatchDayList('0', '5f5aed5e69b4221aedaa4fb5', b)">
+                <td :key="`day-${dindex}`" style="display: grid;">{{ getDay(d) }}&nbsp;</td>
+              </template>
+            </tr>
+          </th>
+
+          <th :key="bindex">
+            课程
+            <tr>
+              <template v-for="(d, dindex) in getBatchDayList('0', '5f5aed5e69b4221aedaa4fb5', b)">
+                <td :key="`lesson-${dindex}`" style="display: grid;">{{ getLesson(d, b) }}&nbsp;</td>
+              </template>
+            </tr>
+          </th>
+
+          <template v-for="(c, cindex) in b.class">
+            <th :key="`${bindex}-${cindex}`">{{ c.name.includes('班') ? c.name : `${c.name}班` }}</th>
+          </template>
+        </template>
+      </tr>
+    </table>
+
+    <!-- <el-row type="flex" class="row_header">
+      <el-col :span="24" v-for="(b, bindex) in getBatchData('0', '5f5aed5e69b4221aedaa4fb5')" :key="bindex" style="border: 0.1px solid;">
+        <el-col :span="4">
+          <el-row>
+            <el-col :span="24">日期</el-col>
+          </el-row>
+        </el-col>
+        <el-col :span="4">星期</el-col>
+        <el-col :span="3">课程</el-col>
+        <template v-for="(c, cindex) in b.class">
+          <el-col :key="`${bindex}-${cindex}`" :span="4">{{ c.name.includes('班') ? c.name : `${c.name}班` }}</el-col>
+        </template>
+      </el-col>
+    </el-row> -->
+    <!-- <el-row type="flex" align="center" style="contentRow">
+      <el-col :span="24" v-for="(b, bindex) in getBatchData('0', '5f5aed5e69b4221aedaa4fb5')" :key="bindex">
+        <el-col :span="6">
+          <el-row style="display: grid;">
+            <el-col :span="24" v-for="(d, dindex) in getBatchDayList('0', '5f5aed5e69b4221aedaa4fb5', b)" :key="dindex">
+              <span> {{ `${d}` }}</span>
+            </el-col>
+          </el-row>
+        </el-col>
+        <el-col :span="4">
+          <el-row style="display: grid;">
+            <el-col :span="24" v-for="(d, dindex) in getBatchDayList('0', '5f5aed5e69b4221aedaa4fb5', b)" :key="dindex">
+              <span>{{ getDay(d) }}</span>
+            </el-col>
+          </el-row>
+        </el-col>
+      </el-col>
+    </el-row> -->
+  </div>
+</template>
+
+<script>
+const _ = require('lodash');
+const moment = require('moment');
+import { mapState, createNamespacedHelpers } from 'vuex';
+export default {
+  name: 'excel-term-lesson',
+  props: {
+    data: { type: Array, default: () => [] },
+    classType: { type: Array, default: () => [] },
+    termnum: { type: Array, default: () => [] },
+  },
+  components: {},
+  data: function() {
+    var _this = this;
+    return {
+      list: {},
+      headerList: [],
+      dayObject: {},
+      term: [],
+    };
+  },
+  created() {
+    this.init();
+  },
+  methods: {
+    init() {
+      // 先留着
+      let glist = _.groupBy(this.data, 'type');
+      let keys = Object.keys(glist);
+      for (const k of keys) {
+        this.$set(this.list, `list${k}`, glist[k]);
+      }
+      // 整理338期数据
+      this.toDisplay('5f5aed5e69b4221aedaa4fb5');
+    },
+    toDisplay(termid) {
+      // 以338期模拟试下
+      const term = this.termnum.find(f => f._id === termid);
+      this.$set(this, 'term', term);
+      // 取出338期所有数据
+      const l = this.data.filter(f => f.termid === termid);
+      // 按班级类型分组
+      const groupl = _.groupBy(l, 'type');
+      // 整理出日期列表
+      const ctList = Object.keys(groupl);
+      for (const ct of ctList) {
+        const ctLesson = groupl[ct];
+        const newOrder = _.orderBy(ctLesson, ['day'], ['asc']);
+        const firstDay = _.get(_.head(newOrder), 'day');
+        const lastDay = _.get(_.last(newOrder), 'day');
+        const dayList = this.getDayList(firstDay, lastDay);
+        this.$set(this.dayObject, `${ct}`, dayList);
+      }
+      // 将每个类型按批次分组
+      const batchGroup = {};
+      for (const ct of ctList) {
+        const ctLesson = groupl[ct];
+        const gb = _.groupBy(ctLesson, 'batchid');
+        // 以 班级类型-班级批次id来组合存储这批的内容
+        const batchids = Object.keys(gb);
+        for (const bid of batchids) {
+          let bList = gb[bid];
+          // 按时间排下序
+          bList = _.orderBy(bList, 'day');
+          // 按班分组
+          const gc = _.groupBy(bList, 'classid');
+          batchGroup[`${ct}-${bid}`] = gc;
+        }
+      }
+      console.log(batchGroup);
+    },
+
+    getDayList(start, end) {
+      const r = moment(end).diff(start, 'days');
+      const arr = [];
+      for (let i = 0; i < r + 1; i++) {
+        const d = moment(start)
+          .add(i, 'days')
+          .format('YYYY-MM-DD');
+        arr.push(d);
+      }
+      return arr;
+    },
+    // 获取指定班级类型的头
+    getBatchData(type, termid) {
+      let duplicate = _.cloneDeep(this.termnum.find(f => f._id === termid));
+      let data = duplicate.batchnum.filter(f => f.class.every(ce => ce.type === type));
+      return data;
+    },
+    // 获取批次的天列表
+    getBatchDayList(type, termid, batch) {
+      console.log(type, termid, batch);
+      let duplicate = _.cloneDeep(this.termnum.find(f => f._id === termid));
+      let data = duplicate.batchnum.filter(f => f.class.every(ce => ce.type === type));
+      const newOrder = _.orderBy(data, ['startdate'], ['asc']);
+      const firstDay = _.get(_.head(newOrder), 'startdate');
+      const lastDay = _.get(_.last(newOrder), 'enddate');
+      let dayList = this.getDayList(firstDay, lastDay);
+      dayList = dayList.map(i => {
+        const r = moment(i).isBetween(batch.startdate, batch.enddate, null, '[]');
+        if (!r) return '-';
+        else return i;
+      });
+      return dayList;
+    },
+    // 获取星期
+    getDay(d) {
+      if (d === '-') return d;
+      if (d && d.includes('-')) {
+        let dl = ['日', '一', '二', '三', '四', '五', '六'];
+        return `星期${dl[moment(d).day()]}`;
+      }
+    },
+    // 获取课程
+    getLesson(date, batch) {
+      const lessons = _.get(batch, 'lessons', []);
+      console.log(lessons);
+      const r = lessons.find(f => f.day === date && f.subid);
+      if (r) {
+        let res = r.subname;
+        if (res.length > 4) {
+          res = `${res.substr(0, 4)}...`;
+        }
+        return res;
+      }
+      return '-';
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.el-col {
+  min-height: 30px;
+}
+.row_header {
+  .el-col {
+    text-align: center;
+  }
+}
+</style>

+ 3 - 5
src/views/bedroom/detail.vue

@@ -38,17 +38,15 @@ export default {
     fields: [
       { label: '寝室号', required: true, model: 'code' },
       { label: '人数', required: true, model: 'number' },
-      { label: '批次', required: true, model: 'batch' },
+      { label: '批次', required: false, model: 'batch' },
       { label: '男女限制', model: 'gender', type: 'radio' },
       { label: '状态', model: 'status', type: 'radio' },
-      { label: '楼层', required: true, model: 'floor', type: 'radio' },
-      { label: '蓝牙id', required: true, model: 'ibeacon' },
+      { label: '楼层', required: false, model: 'floor', type: 'radio' },
+      { label: '蓝牙id', required: false, model: 'ibeacon' },
     ],
     rules: {
       code: [{ required: true, message: '请输入寝室号' }],
       number: [{ required: true, message: '请输入人数' }],
-      batch: [{ required: true, message: '请输入批次' }],
-      floor: [{ required: true, message: '请选择楼层' }],
     },
   }),
   created() {},

+ 11 - 4
src/views/new-plan/teacher-lesson.vue

@@ -1,6 +1,10 @@
 <template>
   <div id="teacher-lesson">
     <list-frame :title="pageTitle" :needFilter="false" :needAdd="false" :needPag="false">
+      <!-- <el-radio-group v-model="view">
+        <el-radio-button label="table">表格</el-radio-button>
+        <el-radio-button label="new">新课表</el-radio-button>
+      </el-radio-group> -->
       <el-row style="padding:15px 0" :gutter="10">
         <el-col :span="2">
           <el-select v-model="form.termid" placeholder="请选择期数" size="mini" clearable filterable>
@@ -49,7 +53,7 @@
           <el-button type="warning" size="mini" @click="toConDialog">确定安排</el-button>
         </el-col>
       </el-row>
-      <el-table :data="filterList()" border stripe @cell-click="cellClick">
+      <el-table :data="filterList()" border stripe @cell-click="cellClick" v-if="view === 'table'">
         <el-table-column align="center" label="期" prop="term" sortable></el-table-column>
         <el-table-column align="center" label="班级" prop="name" sortable></el-table-column>
         <el-table-column align="center" label="科目" prop="subname" sortable></el-table-column>
@@ -67,6 +71,9 @@
           </template>
         </el-table-column>
       </el-table>
+      <div v-else>
+        <excel-term-lesson v-if="lessonsList.length > 0" :data="lessonsList" :classType="ctList" :termnum="plan.termnum"></excel-term-lesson>
+      </div>
 
       <el-dialog title="选择教师" width="30%" :visible.sync="dialog" center :destroy-on-close="true" @close="toClose">
         <el-row class="row">
@@ -166,6 +173,7 @@
 </template>
 
 <script>
+import excelTermLesson from '@/components/excel-term-lesson.vue';
 import listFrame from '@frame/layout/admin/list-frame';
 const _ = require('lodash');
 const moment = require('moment');
@@ -181,9 +189,11 @@ export default {
   props: {},
   components: {
     listFrame,
+    excelTermLesson,
   },
   data: function() {
     return {
+      view: 'table',
       dialog: false,
       msgDialog: false,
       conDialog: false,
@@ -357,9 +367,6 @@ export default {
           else return !f.teaid;
         });
       res = _.orderBy(res, ['term', 'day'], ['asc', 'asc']);
-      let test = res.filter(f => f.teaname === '鞠鹏');
-      test = test.map(i => _.pick(i, ['term', 'day', 'teaname']));
-      console.log(test);
       return res;
     },
     setData() {