attendance.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div id="index">
  3. <list-frame title="考勤管理" @query="onsearch" :total="total" :needFilter="false" :needAdd="false">
  4. <el-form :inline="true" size="mini">
  5. <el-form-item label="期">
  6. <el-select v-model="form.termid" placeholder="请选择期数" @change="getClasses">
  7. <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i._id"></el-option>
  8. </el-select>
  9. </el-form-item>
  10. <!-- <el-form-item label="批次">
  11. <el-select v-model="form.batchid" placeholder="请先选择期数" @change="getClasses">
  12. <el-option v-for="(i, index) in batchList" :key="index" :label="i.name" :value="i._id"></el-option>
  13. </el-select>
  14. </el-form-item> -->
  15. <el-form-item label="班级">
  16. <el-select v-model="form.classid" placeholder="请先选择班级">
  17. <el-option v-for="(i, index) in classList" :key="index" :label="i.name" :value="i._id"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="">
  21. <el-button type="primary" size="mini" @click="onsearch()"> 查询</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <data-table :fields="fields" :data="list"> </data-table>
  25. </list-frame>
  26. </div>
  27. </template>
  28. <script>
  29. import _ from 'lodash';
  30. import listFrame from '@frame/layout/admin/list-frame';
  31. import dataTable from '@frame/components/data-table';
  32. import { mapState, createNamespacedHelpers } from 'vuex';
  33. const { mapActions: attendance } = createNamespacedHelpers('attendance');
  34. const { mapActions: student } = createNamespacedHelpers('student');
  35. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  36. const { mapActions: classes } = createNamespacedHelpers('classes');
  37. export default {
  38. metaInfo: { title: '考勤管理' },
  39. name: 'attendance',
  40. props: {},
  41. components: {
  42. listFrame,
  43. dataTable,
  44. },
  45. data: () => ({
  46. classList: [],
  47. batchList: [],
  48. termList: [],
  49. fields: [
  50. { label: '学生姓名', prop: 'stuname' },
  51. { label: '日期', prop: 'date' },
  52. { label: '时间', prop: 'time' },
  53. {
  54. label: '类型',
  55. prop: 'type',
  56. format: item => {
  57. return item === '0' ? '上课考勤' : item === '1' ? '上课考勤' : '';
  58. },
  59. },
  60. {
  61. label: '状态',
  62. prop: 'status',
  63. format: item => {
  64. return item === '0' ? '未签到' : item === '1' ? '签到' : '迟到';
  65. },
  66. },
  67. ],
  68. form: {},
  69. list: [],
  70. total: 0,
  71. }),
  72. created() {
  73. this.searchinfo();
  74. },
  75. computed: { ...mapState(['user', 'defaultOption']) },
  76. methods: {
  77. ...attendance(['query', 'delete']),
  78. ...student({ stuquery: 'query' }),
  79. ...trainplan({ planfetch: 'fetch' }),
  80. ...classes({ classesquery: 'query' }),
  81. async searchinfo() {
  82. const res = await this.planfetch(this.defaultOption.planid);
  83. let terms = res.data.termnum;
  84. this.$set(this, `termList`, terms);
  85. if (this.defaultOption.termid) {
  86. this.form.termid = this.defaultOption.termid;
  87. this.getClasses(this.form.termid);
  88. }
  89. },
  90. getBatch(termid) {
  91. let batchs = this.termList.filter(f => f._id === termid);
  92. if (batchs.length > 0) {
  93. let { batchnum } = batchs[0];
  94. this.$set(this, `batchList`, batchnum);
  95. }
  96. },
  97. async getClasses(termid) {
  98. const res = await this.classesquery({ termid });
  99. var arr = res.data.filter(item => item.type == '0');
  100. this.$set(this, `classList`, arr);
  101. },
  102. async onsearch({ skip = 0, limit = 10, ...info } = {}) {
  103. const res = await this.query({ termid: this.form.termid, classid: this.form.classid, ...info });
  104. const newdatas = [];
  105. for (const data of res.data) {
  106. for (const attend of data.attend) {
  107. let newdata = { stuname: data.stuname, ...attend };
  108. newdatas.push(newdata);
  109. }
  110. }
  111. if (this.$checkRes(res)) {
  112. this.$set(this, `total`, newdatas.length);
  113. let _newdatas = newdatas.splice(skip, skip + limit);
  114. this.$set(this, `list`, _newdatas);
  115. }
  116. },
  117. },
  118. watch: {
  119. defaultOption: {
  120. handler(val) {
  121. this.form.termid = this.defaultOption.termid;
  122. this.getBatch(this.form.termid);
  123. },
  124. deep: true,
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="less" scoped></style>