lesson.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div id="lesson">
  3. <transition name="el-zoom-in-center">
  4. <list-frame
  5. v-if="view === 'list'"
  6. returns="/plan/index"
  7. :title="mainTitle"
  8. @query="batchSearch"
  9. :total="total"
  10. :filter="filterFields"
  11. :needAdd="false"
  12. :needPag="false"
  13. >
  14. <template #options="{item}">
  15. <template v-if="item.model === 'term'">
  16. <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i._id"></el-option>
  17. </template>
  18. </template>
  19. <data-table ref="table" :fields="fields" :data="list" :opera="opera" @date="toDate" @msg="toMsg" @bedroom="toBedroom"></data-table>
  20. </list-frame>
  21. <detail-frame v-else title="返回批次列表" :returns="returnList">
  22. <lesson-plan
  23. :startDate="batch.startdate"
  24. :endDate="batch.enddate"
  25. :classes="classes"
  26. :trainplanid="id"
  27. :batchid="batchid"
  28. @save="handleSave"
  29. ></lesson-plan>
  30. </detail-frame>
  31. </transition>
  32. </div>
  33. </template>
  34. <script>
  35. import lessonPlan from './lesson-plan';
  36. import listFrame from '@frame/layout/admin/list-frame';
  37. import detailFrame from '@frame/layout/admin/detail-frame';
  38. import dataTable from '@frame/components/data-table';
  39. import _ from 'lodash';
  40. import { createNamespacedHelpers } from 'vuex';
  41. const { mapActions: trainPlan } = createNamespacedHelpers('trainplan');
  42. const { mapActions: mapClasses } = createNamespacedHelpers('classes');
  43. const { mapActions: lesson } = createNamespacedHelpers('lesson'); //教师申请
  44. const { mapActions: bedroom } = createNamespacedHelpers('bedroom'); //分寝
  45. //教师表,地点表,课程表
  46. export default {
  47. metaInfo: { title: '安排课程' },
  48. name: 'lesson',
  49. props: {},
  50. components: { listFrame, dataTable, detailFrame, lessonPlan },
  51. data: () => ({
  52. view: 'list',
  53. term: '',
  54. termList: [],
  55. opera: [
  56. {
  57. label: '排课',
  58. icon: 'el-icon-date',
  59. method: 'date',
  60. },
  61. {
  62. label: '一键分寝',
  63. icon: 'el-icon-s-home',
  64. method: 'bedroom',
  65. },
  66. {
  67. label: '发送确认通知',
  68. icon: 'el-icon-message-solid',
  69. method: 'msg',
  70. },
  71. ],
  72. fields: [
  73. { label: '', prop: 'name' },
  74. { label: '批数', prop: 'batch' },
  75. ],
  76. filterFields: [{ label: '期数', model: 'term', type: 'select' }],
  77. list: [],
  78. batch: {},
  79. total: 0,
  80. classes: [],
  81. batchid: [],
  82. }),
  83. created() {
  84. this.search();
  85. },
  86. methods: {
  87. ...trainPlan({ getTrainPlan: 'fetch', sendNotice: 'notice' }),
  88. ...mapClasses({ getClass: 'query', updateClass: 'update' }),
  89. ...lesson({ getLessonList: 'query', lessonCreate: 'create', lessonUpdate: 'update' }),
  90. ...bedroom({ bedroomApart: 'apart' }),
  91. async search({ skip = 0, limit = 10, ...info } = {}) {
  92. let res = await this.getTrainPlan(this.id);
  93. if (this.$checkRes(res)) {
  94. this.$set(this, `termList`, res.data.termnum);
  95. }
  96. },
  97. batchSearch({ skip, limit, ...info }) {
  98. let { term } = info;
  99. this.$set(this, `term`, term);
  100. let res = this.termList.find(f => f._id === term);
  101. this.$set(this, `list`, _.sortBy(res.batchnum, ['batch']));
  102. },
  103. async toDate({ data }) {
  104. let res = await this.getClass({ batchid: data._id });
  105. this.$set(this, 'batchid', data._id);
  106. // this.view = 'lesson';
  107. let { startdate, enddate } = data;
  108. this.$set(this.batch, `startdate`, startdate);
  109. this.$set(this.batch, `enddate`, enddate);
  110. //查询到了班级,再查询班级是否有课表
  111. if (this.$checkRes(res)) {
  112. let cArr = [];
  113. for (const tClass of res.data) {
  114. let lesson = await this.getLessonList({ classid: tClass.id });
  115. console.log(lesson);
  116. if (this.$checkRes(lesson)) {
  117. //根据classid查出的课表一定是唯一的,但是需要用query方法查出,所以如果有值只取出第一条,之后修改这条数据
  118. let { name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid } = tClass;
  119. if (lesson.data.length > 0) {
  120. //说明这个班已经排过课了,整理数据
  121. let ldata = JSON.parse(JSON.stringify(lesson.data[0]));
  122. ldata = { ...ldata, name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid };
  123. cArr.push(ldata);
  124. } else {
  125. //没排课,需要动手干下,整理好数据
  126. let object = { name, lyteacherid, yclocationid, kzjhlocationid, kbyslocationid, headteacherid, jslocationid };
  127. object.classid = tClass.id;
  128. object.batchid = tClass.batchid;
  129. object.termid = tClass.termid;
  130. cArr.push(object);
  131. }
  132. }
  133. }
  134. this.$set(this, `classes`, cArr);
  135. }
  136. this.view = 'lesson';
  137. },
  138. returnList() {
  139. this.view = 'list';
  140. },
  141. async handleSave(data) {
  142. //此处需要3个接口:1,课表添加;2,课表修改;3,班级修改
  143. //根据data中是否有id,判断是课表的添加还是修改
  144. //解构出data中class字段,是班级id,将各种地点,礼仪课老师,班主任修改好
  145. let classid = data.classid;
  146. let { lessons, termid, batchid, headteacherid, jslocationid, yclocationid, kzjhlocationid, kbyslocationid, lyteacherid } = data;
  147. let newLessons = { lessons, termid, batchid, classid };
  148. let newClass = { id: classid, headteacherid, jslocationid, yclocationid, kzjhlocationid, kbyslocationid, lyteacherid };
  149. let lid = _.get(data, `id`);
  150. let res;
  151. if (!lid) {
  152. res = await this.lessonCreate(newLessons);
  153. } else {
  154. newLessons.id = lid;
  155. res = await this.lessonUpdate(newLessons);
  156. }
  157. let check = (res, sucMsg, errMsg) => {
  158. if (res.errcode === 0) {
  159. _.isString(sucMsg) ? this.$message.success(sucMsg) : '';
  160. return true;
  161. } else {
  162. this.$message.error(errMsg || '处理失败');
  163. return false;
  164. }
  165. };
  166. if (check(res, null, `课表${lid ? '修改' : '添加'}失败`)) {
  167. newClass.lessonid = res.data._id;
  168. res = await this.updateClass(newClass);
  169. check(res, '班级信息修改成功', '班级信息修改失败');
  170. }
  171. },
  172. async toMsg({ data }) {
  173. let res = await this.getClass({ batchid: data._id });
  174. if (this.$checkRes(res)) {
  175. let arr = res.data.map(i => i.id);
  176. if (arr.length > 0) {
  177. const resNotice = await this.sendNotice({ classids: arr });
  178. this.$checkRes(resNotice, '发送成功', '发送失败');
  179. } else this.$message.warning(`该批次下未分班`);
  180. }
  181. },
  182. async toBedroom({ data }) {
  183. let object = { termid: this.term, trainplanid: this.id, batchid: data._id };
  184. let res = await this.bedroomApart(object);
  185. this.$checkRes(res, '分寝成功', res.errmsg);
  186. },
  187. },
  188. computed: {
  189. mainTitle() {
  190. let meta = this.$route.meta;
  191. let main = meta.title || '';
  192. let sub = meta.sub || '';
  193. return `${main}${sub}`;
  194. },
  195. keyWord() {
  196. let meta = this.$route.meta;
  197. let main = meta.title || '';
  198. return main;
  199. },
  200. id() {
  201. return this.$route.query.id;
  202. },
  203. },
  204. };
  205. </script>
  206. <style lang="less" scoped></style>