reloaded 5 年 前
コミット
a5e5b98e31
3 ファイル変更125 行追加18 行削除
  1. 1 1
      src/router/index.js
  2. 101 8
      src/views/classes/attendance.vue
  3. 23 9
      src/views/classes/qingjia.vue

+ 1 - 1
src/router/index.js

@@ -80,7 +80,7 @@ const routes = [
       {
         path: '/classes/attendance',
         name: 'classes_attendance',
-        meta: { title: '班级', sub: '考勤' },
+        meta: { title: '考勤管理', sub: '考勤' },
         component: () => import('@/views/classes/attendance.vue'),
       },
       {

+ 101 - 8
src/views/classes/attendance.vue

@@ -1,40 +1,133 @@
 <template>
   <div id="attendance">
-    <listFrame :title="pageTitle" @query="search" :total="total" :needFilter="false" :returns="toreturn" :needAdd="false">
-      <attendanceInfo :classId="classId" @initTotal="initTotal"></attendanceInfo>
+    <listFrame :title="pageTitle" @query="skipsearch" :total="total" :needFilter="false" :returns="toreturn" :needAdd="false">
+      <attendanceInfo :tableData="tableData" :options="options" @filterDate="filterDate"></attendanceInfo>
     </listFrame>
   </div>
 </template>
 
 <script>
+import _ from 'lodash';
+var moment = require('moment');
 import attendanceInfo from '@frame/parts/attendance';
 import listFrame from '@frame/layout/admin/list-frame';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: attendance } = createNamespacedHelpers('attendance');
+const { mapActions: classes } = createNamespacedHelpers('classes');
 export default {
   name: 'attendance',
   props: {},
   components: { attendanceInfo, listFrame },
   data: () => ({
-    classId: {},
     total: 0,
+    attendList: [],
+    tableData: [],
+    options: [],
+    dataList: [],
   }),
   created() {
-    this.initId();
+    this.search();
   },
   computed: {
     id() {
       return this.$route.query.id;
     },
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
   },
   methods: {
-    async initId() {
-      this.classId = this.id;
+    ...attendance(['fetch', 'query']),
+    ...classes({ classFetch: 'fetch' }),
+    async search() {
+      const attendList = await this.query({ classid: this.id });
+      this.$set(this, `attendList`, attendList.data);
+      const classInfo = await this.classFetch(this.id);
+      const timeList = await this.getAllDays(classInfo.data.startdate, classInfo.data.enddate);
+      this.$set(this, `options`, timeList);
+    },
+    skipsearch({ skip = 0, limit = 10 } = {}) {
+      const data = _.slice(this.dataList, skip, skip + limit);
+      this.$set(this, `tableData`, data);
+    },
+    filterDate(time) {
+      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;
+            dataInfo.status = _attend.status;
+            dataInfo.type = _attend.type;
+            data.push(dataInfo);
+          }
+          dataInfo = {};
+        }
+      }
+      this.$set(this, `dataList`, data);
+      this.$set(this, `total`, data.length);
+      this.skipsearch();
     },
     toreturn() {
       window.history.go(-1);
     },
-    initTotal(total) {
-      this.$set(this, `total`, total);
+    // 取得日期间所有日期
+    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;
+      }
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  watch: {
+    classId: {
+      handler(val) {
+        if (val) {
+          this.search();
+        }
+      },
+      immediate: true,
     },
   },
 };

+ 23 - 9
src/views/classes/qingjia.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="qingjia">
     <listFrame :title="pageTitle" @query="search" :total="total" :needFilter="false" :returns="toreturn" :needAdd="false">
-      <leaveInfo :classId="classId" @initTotal="initTotal"></leaveInfo>
+      <leaveInfo :tableData="tableData"></leaveInfo>
     </listFrame>
   </div>
 </template>
@@ -11,7 +11,7 @@ import _ from 'lodash';
 import listFrame from '@frame/layout/admin/list-frame';
 import leaveInfo from '@frame/parts/leave';
 import { mapState, createNamespacedHelpers } from 'vuex';
-const { mapActions: mapLeave } = createNamespacedHelpers('leave');
+const { mapActions: leave } = createNamespacedHelpers('leave');
 export default {
   name: 'qingjia',
   props: {},
@@ -20,22 +20,26 @@ export default {
     return {
       classId: {},
       total: 0,
+      tableData: [],
     };
   },
   created() {
-    this.initId();
+    this.search();
   },
   methods: {
-    async initId() {
-      this.classId = this.id;
+    ...leave(['fetch', 'query']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const leaveInfo = await this.query({ skip, limit, ...info, classid: this.id });
+      if (leaveInfo.errcode == 0) {
+        this.$set(this, `tableData`, leaveInfo.data);
+        console.log(this.tableData);
+
+        this.$set(this, 'total', leaveInfo.total);
+      }
     },
-    async search({ skip = 0, limit = 10, ...info } = {}) {},
     toreturn() {
       window.history.go(-1);
     },
-    initTotal(total) {
-      this.$set(this, `total`, total);
-    },
   },
   computed: {
     ...mapState(['user']),
@@ -49,6 +53,16 @@ export default {
   metaInfo() {
     return { title: this.$route.meta.title };
   },
+  watch: {
+    classId: {
+      handler(val) {
+        if (val) {
+          this.search();
+        }
+      },
+      immediate: true,
+    },
+  },
 };
 </script>