|
@@ -7,7 +7,16 @@
|
|
|
<el-table-column prop="date" label="日期"> </el-table-column>
|
|
|
<el-table-column prop="time" label="时间"> </el-table-column>
|
|
|
<el-table-column prop="name" label="姓名"> </el-table-column>
|
|
|
- <el-table-column prop="status" label="状态"> </el-table-column>
|
|
|
+ <el-table-column align="center" label="类型">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ scope.row.type === '0' ? '上课考勤' : scope.row.type === '1' ? '寝室考勤' : '' }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column align="center" label="状态">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ scope.row.status === '0' ? '未签到' : scope.row.status === '1' ? '已签到' : scope.row.status === '2' ? '迟到' : '' }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
</el-table>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -20,99 +29,18 @@ const moment = require('moment');
|
|
|
export default {
|
|
|
name: 'attendance',
|
|
|
props: {
|
|
|
- classId: {},
|
|
|
+ tableData: { type: Array },
|
|
|
+ options: { type: Array },
|
|
|
},
|
|
|
components: {},
|
|
|
data: () => ({
|
|
|
- tableData: [],
|
|
|
- options: [],
|
|
|
value: '',
|
|
|
- attendList: [],
|
|
|
}),
|
|
|
created() {},
|
|
|
computed: {},
|
|
|
methods: {
|
|
|
- ...attendance(['fetch', 'query']),
|
|
|
- ...classes({ classFetch: 'fetch' }),
|
|
|
- async search() {
|
|
|
- const attendList = await this.query({ classid: this.classId });
|
|
|
- this.$set(this, `attendList`, attendList.data);
|
|
|
- const classInfo = await this.classFetch(this.classId);
|
|
|
- const timeList = await this.getAllDays(classInfo.data.startdate, classInfo.data.enddate);
|
|
|
- this.$set(this, `options`, timeList);
|
|
|
- },
|
|
|
filterDate(time) {
|
|
|
- console.log(this.attendList);
|
|
|
- const data = [];
|
|
|
- for (const attendInfo of this.attendList) {
|
|
|
- let dataInfo = {};
|
|
|
- const attend = attendInfo.attend;
|
|
|
- for (const _attend of attend) {
|
|
|
- dataInfo.name = attendInfo.stuname;
|
|
|
- if (moment(time).isSame(_attend.date)) {
|
|
|
- dataInfo.date = time;
|
|
|
- dataInfo.time = _attend.time;
|
|
|
- console.log(_attend.status);
|
|
|
- dataInfo.status = _attend.status == '0' ? '未签到' : _attend.status == '1' ? '已签到' : _attend.status == '2' ? '迟到' : '';
|
|
|
- data.push(dataInfo);
|
|
|
- }
|
|
|
- dataInfo = {};
|
|
|
- }
|
|
|
- }
|
|
|
- this.$set(this, `tableData`, data);
|
|
|
- this.$emit('initTotal', data.length);
|
|
|
- },
|
|
|
- // 取得日期间所有日期
|
|
|
- async getAllDays(begin_date, end_date) {
|
|
|
- const errArr = [],
|
|
|
- resultArr = [],
|
|
|
- dateReg = /^[2]\d{3}-[01]\d-[0123]\d$/;
|
|
|
- if (typeof begin_date !== 'string' || begin_date === '' || !dateReg.test(begin_date)) {
|
|
|
- return errArr;
|
|
|
- }
|
|
|
- if (typeof end_date !== 'string' || end_date === '' || !dateReg.test(end_date)) {
|
|
|
- return errArr;
|
|
|
- }
|
|
|
- try {
|
|
|
- const beginTimestamp = Date.parse(new Date(begin_date)),
|
|
|
- endTimestamp = Date.parse(new Date(end_date));
|
|
|
- // 开始日期小于结束日期
|
|
|
- if (beginTimestamp > endTimestamp) {
|
|
|
- return errArr;
|
|
|
- }
|
|
|
- // 开始日期等于结束日期
|
|
|
- if (beginTimestamp === endTimestamp) {
|
|
|
- resultArr.push(begin_date);
|
|
|
- return resultArr;
|
|
|
- }
|
|
|
- let tempTimestamp = beginTimestamp,
|
|
|
- tempDate = begin_date;
|
|
|
- // 新增日期是否和结束日期相等, 相等跳出循环
|
|
|
- while (tempTimestamp !== endTimestamp) {
|
|
|
- resultArr.push(tempDate);
|
|
|
- // 增加一天
|
|
|
- tempDate = moment(tempTimestamp)
|
|
|
- .add(1, 'd')
|
|
|
- .format('YYYY-MM-DD');
|
|
|
- // 将增加时间变为时间戳
|
|
|
- tempTimestamp = Date.parse(new Date(tempDate));
|
|
|
- }
|
|
|
- // 将最后一天放入数组
|
|
|
- resultArr.push(end_date);
|
|
|
- return resultArr;
|
|
|
- } catch (err) {
|
|
|
- return errArr;
|
|
|
- }
|
|
|
- },
|
|
|
- },
|
|
|
- watch: {
|
|
|
- classId: {
|
|
|
- handler(val) {
|
|
|
- if (val) {
|
|
|
- this.search();
|
|
|
- }
|
|
|
- },
|
|
|
- immediate: true,
|
|
|
+ this.$emit('filterDate', time);
|
|
|
},
|
|
|
},
|
|
|
};
|