|
@@ -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 }} </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) }} </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) }} </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>
|