print.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div id="print">
  3. <listFrame :title="pageTitle" :needFilter="false" :needPag="false" :needAdd="false">
  4. <el-tabs v-model="active" type="border-card" stretch @tab-click="tabChange">
  5. <el-tab-pane label="打印名签" name="name" :lazy="true">
  6. <el-row type="flex" align="middle" justify="center" v-loading="loading">
  7. <el-col :span="18" style="padding-left:100px; min-height:500px">
  8. <name-card :list="studList"></name-card>
  9. </el-col>
  10. </el-row>
  11. </el-tab-pane>
  12. <el-tab-pane label="打印证书" name="cert" :lazy="true">
  13. <cert-card :list="certstuList" :startdate="startdate" :enddate="enddate" :classname="classname" :term="term"></cert-card>
  14. </el-tab-pane>
  15. <el-tab-pane label="打印报到表" name="sign" :lazy="true">
  16. <sign-card v-loading="loading" :list="studList" :signclass="signclass"></sign-card>
  17. </el-tab-pane>
  18. <el-tab-pane label="打印班级课表" name="lesson" :lazy="true">
  19. <lesson-table v-loading="loading" :data="classInfo" :th="lth" :tr="ltr" :lessons="lessons"></lesson-table>
  20. </el-tab-pane>
  21. </el-tabs>
  22. </listFrame>
  23. </div>
  24. </template>
  25. <script>
  26. import _ from 'lodash';
  27. import axios from 'axios';
  28. import listFrame from '@frame/layout/admin/list-frame';
  29. import signCard from '@frame/parts/print/print-sign';
  30. import nameCard from '@frame/parts/print/namCard.vue';
  31. import certCard from '@frame/parts/print/certCard.vue';
  32. import lessonTable from '@frame/parts/time-table.vue';
  33. import { mapState, createNamespacedHelpers } from 'vuex';
  34. const { mapActions: classes } = createNamespacedHelpers('classes');
  35. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  36. const { mapActions: student } = createNamespacedHelpers('student');
  37. const { mapActions: util } = createNamespacedHelpers('util');
  38. const { mapActions: location } = createNamespacedHelpers('location'); //地点
  39. const { mapActions: teacher } = createNamespacedHelpers('teacher'); //教师
  40. const { mapActions: director } = createNamespacedHelpers('director'); //教师
  41. const { mapActions: cerconfirm } = createNamespacedHelpers('cerconfirm');
  42. export default {
  43. name: 'print',
  44. props: {},
  45. components: { listFrame, nameCard, signCard, lessonTable, certCard },
  46. data: function() {
  47. return {
  48. active: 'name',
  49. loading: false,
  50. studList: [],
  51. classInfo: {},
  52. lth: [], //table表头
  53. ltr: [], //table y轴
  54. lessons: [], //原始课表,取出来什么样就什么样
  55. startdate: '',
  56. enddate: '',
  57. classname: '',
  58. term: '',
  59. certstuList: [],
  60. signclass: {},
  61. };
  62. },
  63. created() {},
  64. methods: {
  65. ...trainplan({ planfetch: 'fetch' }),
  66. ...classes({ classesquery: 'query', getClass: 'fetch' }),
  67. ...student({ getStudentList: 'query' }),
  68. ...util({ modelFetch: 'fetch' }),
  69. ...location({ getLocation: 'fetch' }),
  70. ...teacher({ getTeacher: 'fetch' }),
  71. ...director({ getDirector: 'fetch' }),
  72. ...cerconfirm({ cerconfirmQuery: 'query' }),
  73. tabChange() {
  74. if (this.id) {
  75. if (this.active == 'name') this.nameList();
  76. if (this.active == 'cert') this.certList();
  77. if (this.active == 'sign') this.signList();
  78. if (this.active == 'lesson') this.classLesson();
  79. }
  80. },
  81. async nameList() {
  82. this.loading = true;
  83. let res = await this.getStudentList({ classid: this.id });
  84. if (this.$checkRes(res)) this.$set(this, `studList`, res.data);
  85. this.loading = false;
  86. },
  87. async signList() {
  88. this.loading = true;
  89. let res = await this.getStudentList({ classid: this.id });
  90. let classinfo = await this.getClass(this.id);
  91. if (this.$checkRes(res)) {
  92. this.$set(this, `studList`, res.data);
  93. this.$set(this, `signclass`, classinfo.data);
  94. }
  95. this.loading = false;
  96. },
  97. async classLesson() {
  98. this.loading = true;
  99. let classInfo = {};
  100. let cir = await this.getClass(this.id);
  101. if (!this.$checkRes(cir)) return;
  102. classInfo = cir.data;
  103. let res = await this.modelFetch({ model: 'lesson', classid: this.id });
  104. if (this.$checkRes(res)) {
  105. let { lessons } = res.data;
  106. let { x, y } = this.proLesson(lessons);
  107. this.$set(this, `lth`, x);
  108. this.$set(this, `ltr`, y);
  109. this.$set(this, `lessons`, lessons);
  110. classInfo = await this.getRemarkParts(classInfo);
  111. this.$set(this, `classInfo`, classInfo);
  112. }
  113. this.loading = false;
  114. },
  115. async certList() {
  116. this.loading = true;
  117. let classInfo = {};
  118. let cir = await this.getClass(this.id);
  119. if (!this.$checkRes(cir)) return;
  120. classInfo = cir.data;
  121. let { _id: classid, enddate, startdate, name: classname, term } = classInfo;
  122. let res = await this.cerconfirmQuery({ classid });
  123. if (this.$checkRes(res)) {
  124. this.$set(this, `certstuList`, res.data);
  125. this.$set(this, `startdate`, startdate);
  126. this.$set(this, `enddate`, enddate);
  127. this.$set(this, `classname`, classname);
  128. this.$set(this, `term`, term);
  129. }
  130. this.loading = false;
  131. },
  132. proLesson(data) {
  133. let duplicate = _.cloneDeep(data);
  134. let x = _.uniq(_.orderBy(duplicate, 'date', 'asc').map(i => i.date));
  135. let y = _.uniq(_.orderBy(duplicate, 'time', 'asc').map(i => i.time));
  136. return { x, y };
  137. },
  138. async getRemarkParts(data) {
  139. let { headteacherid, jslocationid, lyteacherid } = data;
  140. let aArr = [];
  141. aArr.push(this.getDirector(headteacherid));
  142. aArr.push(this.getLocation(jslocationid));
  143. axios.all(aArr).then(
  144. axios.spread((r1, r2) => {
  145. if (r1 && r1.errcode == 0) data.headteacher = r1.data.name;
  146. if (r2 && r2.errcode == 0) data.jslocation = r2.data.name;
  147. })
  148. );
  149. let check = data => {
  150. if (!data || data.errcode != 0) return false;
  151. let obj = _.get(data, `data`);
  152. if (!obj) return false;
  153. return obj.name;
  154. };
  155. //单独处理礼仪教师,因为数据可能从2个表来
  156. let res = await this.getDirector(lyteacherid);
  157. let name = check(res);
  158. if (name) data.lyteacher = name;
  159. else res = await this.getTeacher(lyteacherid);
  160. name = check(res);
  161. if (name) data.lyteacher = name;
  162. return data;
  163. },
  164. },
  165. computed: {
  166. ...mapState(['user', 'defaultOption']),
  167. pageTitle() {
  168. return `${this.$route.meta.title}`;
  169. },
  170. id() {
  171. return this.defaultOption.classid;
  172. },
  173. },
  174. watch: {
  175. id: {
  176. handler(val) {
  177. if (val) {
  178. this.tabChange();
  179. } else {
  180. this.studList = [];
  181. this.classInfo = [];
  182. this.lth = [];
  183. this.ltr = [];
  184. this.lessons = [];
  185. }
  186. },
  187. immediate: true,
  188. deep: true,
  189. },
  190. },
  191. metaInfo() {
  192. return { title: this.$route.meta.title };
  193. },
  194. };
  195. </script>
  196. <style lang="less" scoped></style>