|
@@ -12,18 +12,18 @@
|
|
|
<th class="th"><p>备注</p></th>
|
|
|
<th class="th"><p>备注</p></th>
|
|
|
</tr>
|
|
|
- <tr v-for="(d, di) in list[`${month}`]" :key="di">
|
|
|
+ <tr v-for="(b, bi) in list[`${month}`]" :key="bi">
|
|
|
<td
|
|
|
v-for="(date, ci) in makeCalendar(month)"
|
|
|
:key="ci"
|
|
|
- @click="cellClick(date, month, di, ci)"
|
|
|
- :style="setVS(date, month, di, ci)"
|
|
|
- :rowspan="toRowspan(date, month, di, ci)"
|
|
|
- :colspan="toColspan(date, month, di, ci)"
|
|
|
+ @click="cellClick(date, month, bi, ci)"
|
|
|
+ :style="setVS(date, month, bi, ci)"
|
|
|
+ :rowspan="toRowspan(date, month, bi, ci)"
|
|
|
+ :colspan="toColspan(date, month, bi, ci)"
|
|
|
>
|
|
|
- {{ getContent(date, month, di, ci) || '' }}
|
|
|
+ {{ getContent(date, month, bi, ci) || '' }}
|
|
|
</td>
|
|
|
- <template v-if="di == 0">
|
|
|
+ <template v-if="bi == 0">
|
|
|
<td :rowspan="getRowNumber(month)" :style="{ height: getRowNumber(month) * 15 }"></td>
|
|
|
<td :rowspan="getRowNumber(month)"></td>
|
|
|
</template>
|
|
@@ -45,6 +45,7 @@
|
|
|
<script>
|
|
|
import _ from 'lodash';
|
|
|
var moment = require('moment');
|
|
|
+var format = 'YYYY-MM-DD';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
export default {
|
|
|
name: 'tableCal',
|
|
@@ -56,7 +57,7 @@ export default {
|
|
|
components: {},
|
|
|
data: function() {
|
|
|
return {
|
|
|
- list: {},
|
|
|
+ list: { 7: [[], []], 8: [[]] },
|
|
|
has_it: false,
|
|
|
it: {},
|
|
|
already: false,
|
|
@@ -86,28 +87,47 @@ export default {
|
|
|
}
|
|
|
return dlist;
|
|
|
},
|
|
|
- cellClick(date, month, di, ci) {
|
|
|
- console.log(date, month, di, ci);
|
|
|
+ cellClick(date, month, bi, ci) {
|
|
|
+ console.log(date, month, bi, ci);
|
|
|
},
|
|
|
init() {
|
|
|
let list = {};
|
|
|
for (let month = 1; month <= 12; month++) {
|
|
|
+ //list长度决定每个月有几行,行数由同一批次班级数最多的期决定
|
|
|
+ //也就是说,需要根据期,批次,班级将各组数据整理好
|
|
|
+ list[month] = [];
|
|
|
if (_.isArray(this.events) && this.events.length > 0) {
|
|
|
- let r = this.events.filter(f => {
|
|
|
- let sm = moment(f.startdate).month() + 1;
|
|
|
- let em = moment(f.enddate).month() + 1;
|
|
|
- let res = _.inRange(month, sm, em + 1);
|
|
|
- return res;
|
|
|
- });
|
|
|
- r.push({});
|
|
|
- list[month] = r;
|
|
|
+ for (const term of this.events) {
|
|
|
+ let { batchnum, term: tn } = term;
|
|
|
+ for (const batch of batchnum) {
|
|
|
+ let { class: classList, batch: bn, startdate: start, enddate: end, color } = batch;
|
|
|
+ //确定这个批次是否在这个月份中(部分即可)
|
|
|
+ let sm = moment(start).month() + 1;
|
|
|
+ let em = moment(end).month() + 1;
|
|
|
+ let res = _.inRange(month, sm, em + 1); //+1因为inRange方法不是闭空间判断,是左闭右开
|
|
|
+ if (!res) continue;
|
|
|
+ for (const cla of classList) {
|
|
|
+ //拼成每个班的数据
|
|
|
+ let ncla = { term: tn, batch: bn, start, end, ...cla, color };
|
|
|
+ let ind = list[month].findIndex(f => f.every(e => e.batch == bn && e.name == ncla.name));
|
|
|
+ //根据batch,name确定是否有行,如果有行
|
|
|
+ if (ind < 0) {
|
|
|
+ //此时是没找到的情况,就说明没有该批次,班级,需要放进去
|
|
|
+ list[month].push([ncla]);
|
|
|
+ } else {
|
|
|
+ list[month][ind].push(ncla);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list[month].push([]);
|
|
|
} else list[month] = [{}];
|
|
|
}
|
|
|
this.$set(this, `list`, list);
|
|
|
},
|
|
|
- setVS(date, month, di, ci) {
|
|
|
+ setVS(date, month, bi, ci) {
|
|
|
let style = { cursor: 'default' };
|
|
|
- if (this.toRowspan(date, month, di, ci) == 0 || this.toColspan(date, month, di, ci) == 0) {
|
|
|
+ if (this.toRowspan(date, month, bi, ci) == 0 || this.toColspan(date, month, bi, ci) == 0) {
|
|
|
style['display'] = 'none';
|
|
|
style['pointer-events'] = 'none';
|
|
|
return style;
|
|
@@ -121,23 +141,36 @@ export default {
|
|
|
return style;
|
|
|
}
|
|
|
//查看时间是否在事件中
|
|
|
- res = this.checkEvents(date);
|
|
|
+ res = this.checkEvents(date, month, bi);
|
|
|
if (res) {
|
|
|
let { color } = res;
|
|
|
style = { background: color };
|
|
|
return style;
|
|
|
}
|
|
|
},
|
|
|
- toRowspan(date, month, di, ci) {
|
|
|
+ toRowspan(date, month, bi, ci) {
|
|
|
let res = this.checkVacation(date);
|
|
|
let rs = 1;
|
|
|
if (res) {
|
|
|
rs = this.list[month].length;
|
|
|
- if (di != 0) rs = 0;
|
|
|
+ if (bi != 0) rs = 0;
|
|
|
+ } else {
|
|
|
+ res = this.checkEvents(date, month, bi, true);
|
|
|
+ if (res) {
|
|
|
+ let r = this.getEventsRowCol(date, month, res);
|
|
|
+ console.log(r);
|
|
|
+ // let { start, end } = res;
|
|
|
+ // date = this.pointToCross(date);
|
|
|
+ // let omr = this.outMonth(start, end);
|
|
|
+ // if (omr) rs = this.outLotsMonth(date, start, end, omr);
|
|
|
+ // //没跨越
|
|
|
+ // else rs = this.notOutMonthPro(date, start, end);
|
|
|
+ // console.log(rs);
|
|
|
+ }
|
|
|
}
|
|
|
return rs;
|
|
|
},
|
|
|
- toColspan(date, month, di, ci) {
|
|
|
+ toColspan(date, month, bi, ci) {
|
|
|
let result = 1;
|
|
|
if (date == '') return result;
|
|
|
date = this.pointToCross(date);
|
|
@@ -206,7 +239,7 @@ export default {
|
|
|
// '.' 日期转换 '-' 日期
|
|
|
pointToCross(date) {
|
|
|
let d = date.split('.');
|
|
|
- return moment(`${this.year}-${d[0]}-${d[1]}`).format('YYYY-MM-DD');
|
|
|
+ return moment(`${this.year}-${d[0]}-${d[1]}`).format(format);
|
|
|
},
|
|
|
//跨月判断
|
|
|
outMonth(start, end) {
|
|
@@ -234,12 +267,12 @@ export default {
|
|
|
} else if (dm == em) {
|
|
|
//该天在结束时间的月份中: 结束时间-这个月开始日期, 只有在这个月开始那天合并,其他的全合并
|
|
|
let esd = moment(end).startOf('month');
|
|
|
- if (date == esd.format('YYYY-MM-DD')) {
|
|
|
+ if (date == esd.format(format)) {
|
|
|
result = moment(end).diff(esd, 'days') + 1;
|
|
|
}
|
|
|
} else {
|
|
|
let ms = moment(date).startOf('month');
|
|
|
- if (date == ms.format('YYYY-MM-DD')) {
|
|
|
+ if (date == ms.format(format)) {
|
|
|
let me = moment(date).endOf('month');
|
|
|
result = me.diff(ms, 'days') + 1;
|
|
|
}
|
|
@@ -285,7 +318,7 @@ export default {
|
|
|
//中间过程时间点,需要判断前一天是否是结束时间点
|
|
|
let yesterday = moment(date)
|
|
|
.subtract(1, 'days')
|
|
|
- .format('YYYY-MM-DD');
|
|
|
+ .format(format);
|
|
|
let yres = ir.find(f => f.end == yesterday);
|
|
|
if (yres) {
|
|
|
let he = this.getNearPoint(date, ir);
|
|
@@ -332,7 +365,7 @@ export default {
|
|
|
if (type == 'start') {
|
|
|
result = moment(result)
|
|
|
.subtract(1, 'days')
|
|
|
- .format('YYYY-MM-DD');
|
|
|
+ .format(format);
|
|
|
}
|
|
|
return result;
|
|
|
},
|
|
@@ -350,8 +383,8 @@ export default {
|
|
|
if (!this.vacation) return res;
|
|
|
for (const vac of this.vacation) {
|
|
|
let start = vac.start;
|
|
|
- let end = _.get(vac, `end`, moment(start).format('YYYY-MM-DD'));
|
|
|
- let r = moment(moment(`${this.year}-${date}`).format('YYYY-MM-DD')).isBetween(start, end, null, '[]');
|
|
|
+ let end = _.get(vac, `end`, moment(start).format(format));
|
|
|
+ let r = moment(moment(`${this.year}-${date}`).format(format)).isBetween(start, end, null, '[]');
|
|
|
if (r) {
|
|
|
res = r;
|
|
|
break;
|
|
@@ -360,25 +393,45 @@ export default {
|
|
|
return res;
|
|
|
},
|
|
|
//查看日期是否在事件中
|
|
|
- checkEvents(date) {
|
|
|
+ checkEvents(date, month, bi) {
|
|
|
let res;
|
|
|
if (!this.events) return res;
|
|
|
- for (const e of this.events) {
|
|
|
- let start = e.startdate;
|
|
|
- let end = _.get(e, `enddate`, moment(start).format('YYYY-MM-DD'));
|
|
|
- let r = moment(moment(`${this.year}-${date}`).format('YYYY-MM-DD')).isBetween(start, end, null, '[]');
|
|
|
- if (r) {
|
|
|
- res = e;
|
|
|
- break;
|
|
|
- }
|
|
|
+ date = this.pointToCross(date);
|
|
|
+ let dml = _.get(this.list, month, []);
|
|
|
+ // let r = dml.find(f => f.find(ff => moment(date).isBetween(ff.start, ff.end, null, '[]')));
|
|
|
+ let bInfo = dml[bi];
|
|
|
+ let r = bInfo.find(ff => moment(date).isBetween(ff.start, ff.end, null, '[]'));
|
|
|
+ if (r) {
|
|
|
+ res = r;
|
|
|
}
|
|
|
return res;
|
|
|
},
|
|
|
- getContent(date, month, di, ci) {
|
|
|
+ //行列获取数据
|
|
|
+ getEventsRowCol(date, month, data) {
|
|
|
+ let { start, end, term, batch } = data;
|
|
|
+ //TODO 需要确定这个格子合不合并
|
|
|
+ //需要确定:1该天是这个批次的开始日期;2该格子是这个批次的第一行第一列
|
|
|
+ date = this.pointToCross(date);
|
|
|
+ let dml = _.get(this.list, month, []);
|
|
|
+ //行合并数 = 所有数据按 期+批次分组 找到对应数量的班级
|
|
|
+ let row = 1;
|
|
|
+ //列合并数 = 该时间的班级的 开始时间 - 结束时间
|
|
|
+ let col = 1;
|
|
|
+ //行处理
|
|
|
+ let r = dml.flat().filter(f => f.batch == batch && f.term == term);
|
|
|
+ row = r.length || 0;
|
|
|
+ //列处理
|
|
|
+ let omr = this.outMonth(start, end);
|
|
|
+ if (omr) col = this.outLotsMonth(date, start, end, omr);
|
|
|
+ //没跨月
|
|
|
+ else col = this.notOutMonthPro(date, start, end);
|
|
|
+ return { row, col };
|
|
|
+ },
|
|
|
+ getContent(date, month, bi, ci) {
|
|
|
let res = this.vacation.filter(f => {
|
|
|
let start = f.start;
|
|
|
- let end = _.get(f, `end`, moment(start).format('YYYY-MM-DD'));
|
|
|
- return moment(moment(`${this.year}-${date}`).format('YYYY-MM-DD')).isBetween(start, end, null, '[]');
|
|
|
+ let end = _.get(f, `end`, moment(start).format(format));
|
|
|
+ return moment(moment(`${this.year}-${date}`).format(format)).isBetween(start, end, null, '[]');
|
|
|
});
|
|
|
if (res.length > 0 && date != '') {
|
|
|
let r = res.map(i => i.title);
|