startPlanCourse.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="排课"
  5. append-to-body
  6. width="1050px"
  7. :visible.sync="transPlanVisible"
  8. >
  9. <div v-if="myForm && myForm.classs && myForm.classs['HIGH_ONLINE']">
  10. <el-form
  11. :model="myForm"
  12. :inline="true"
  13. ref="planform"
  14. label-suffix=": "
  15. >
  16. <div v-if="!isMoreClass">
  17. <p class="title">
  18. <span style="font-weight: 600">线上基础技能课</span>
  19. 可排课时长:<span style="color: red">{{
  20. form.courseConvertSum.courseMinute
  21. }}</span
  22. >分钟
  23. <span style="color: #333"
  24. >已排课时长:
  25. <span style="color: red"> {{ alltime }}分钟</span></span
  26. >
  27. </p>
  28. <courseItem
  29. :form="myForm.classs['HIGH_ONLINE']"
  30. :teacherList="teacherList"
  31. :surplustime="form.courseConvertSum.courseMinute"
  32. :activeType="'HIGH_ONLINE'"
  33. :coreid="myForm.coreTeacher"
  34. :type="'HIGH_ONLINE'"
  35. :prices="prices"
  36. :holidays="holidays"
  37. @setUserTime="setUserTime"
  38. />
  39. </div>
  40. <div v-else>
  41. <p class="title">
  42. <span style="font-weight: 600">线上基础技能课</span>
  43. 可排课时:<span style="color: red">{{
  44. form.courseConvertSum.courseNum
  45. }}</span
  46. >课时
  47. <span style="color: #333"
  48. >已排课时:
  49. <span style="color: red"> {{ allNum }}课时</span></span
  50. >
  51. </p>
  52. <courseItem
  53. :form="myForm.classs['HIGH_ONLINE']"
  54. :teacherList="teacherList"
  55. :surplustime="form.courseConvertSum.courseMinute"
  56. :surplusCourseNum="form.courseConvertSum.courseNum"
  57. :activeType="'HIGH_ONLINE'"
  58. :coreid="myForm.coreTeacher"
  59. :type="'HIGH_ONLINE'"
  60. :prices="prices"
  61. :holidays="holidays"
  62. @setUserCourse="setUserCourse"
  63. :isCourseNumType="true"
  64. />
  65. <!-- setUserCourse -->
  66. </div>
  67. <!--
  68. :cooperationList="teacherList" -->
  69. </el-form>
  70. </div>
  71. <div slot="footer" class="dialog-footer">
  72. <el-button @click="transPlanVisible = false">取 消</el-button>
  73. <el-button type="primary" @click="submit">确 定</el-button>
  74. </div>
  75. </el-dialog>
  76. </div>
  77. </template>
  78. <script>
  79. import { getSysTenantConfig } from "@/views/courseRulersManager/api";
  80. import { queryByOrganIdAndCourseType } from "@/views/resetTeaming/api";
  81. import courseItem from "../modals/classroom-setting-item.vue";
  82. import { isEmpty } from "lodash";
  83. const formatClassGroupTeacherMapperList = (core, ass) => {
  84. const list = [];
  85. if (core) {
  86. list.push({ userId: core, teacherRole: "BISHOP" });
  87. }
  88. if (ass) {
  89. for (const item of ass) {
  90. list.push({ userId: item, teacherRole: "TEACHING" });
  91. }
  92. }
  93. return list;
  94. };
  95. import { courseScheduleConvert } from "../../api";
  96. export default {
  97. props: ["form", "teacherList", "activeRow"],
  98. data() {
  99. return {
  100. prices: [],
  101. holidays: [],
  102. transPlanVisible: false,
  103. allClasss: {},
  104. courseTypeListByName: {},
  105. courseTypeList: [{ value: "HIGH_ONLINE", label: "线上基础技能课" }],
  106. alltime: 0,
  107. myForm: null,
  108. allNum: 0,
  109. };
  110. },
  111. components: {
  112. courseItem,
  113. },
  114. methods: {
  115. async init() {
  116. try {
  117. const res = await queryByOrganIdAndCourseType({
  118. organId: this.$route.query.organId,
  119. });
  120. const res1 = await getSysTenantConfig({
  121. group: "holiday",
  122. });
  123. this.holidays = JSON.parse(
  124. res1.data[0].paranValue ? res1.data[0].paranValue : "[]"
  125. );
  126. this.prices = res.data;
  127. let arr = [];
  128. if (JSON.stringify(this.prices) == "{}") {
  129. // 课程时长
  130. arr.push("teamCourseTimer");
  131. }
  132. if (this.holidays.length <= 0) {
  133. arr.push("holiday");
  134. }
  135. //
  136. if (arr.length > 0) {
  137. this.$bus.$emit("showguide", arr);
  138. return;
  139. }
  140. } catch (error) {
  141. console.log(error);
  142. }
  143. },
  144. async openDialog() {
  145. // 获取列表
  146. this.init();
  147. // console.log(
  148. // this.activeRow,
  149. // this.form,
  150. // "初始化",
  151. // this.activeRow.classs["HIGH_ONLINE"]
  152. // );
  153. this.myForm = { ...this.activeRow };
  154. this.transPlanVisible = true;
  155. },
  156. setCourseTypeListByName() {
  157. const courseTypeListByName = {};
  158. for (const item of this.courseTypeList) {
  159. courseTypeListByName[item.value] = item.label;
  160. }
  161. this.courseTypeListByName = courseTypeListByName;
  162. },
  163. setUserTime(time, type) {
  164. this.alltime = time;
  165. },
  166. setUserCourse(courseNum, type) {
  167. this.allNum = courseNum;
  168. },
  169. formatTeacher(row) {
  170. let arr = [];
  171. if (row.coreTeacher) {
  172. let obj = {};
  173. obj.teacherRole = "BISHOP";
  174. obj.userId = row.coreTeacher;
  175. arr.push(obj);
  176. }
  177. if (row.assistant?.length > 0) {
  178. row.assistant.forEach((ass) => {
  179. arr.push({ teacherRole: "TEACHING", userId: ass });
  180. });
  181. }
  182. return arr;
  183. },
  184. async submit() {
  185. try {
  186. if (!this.isMoreClass) {
  187. if (this.alltime > this.form.courseConvertSum.courseMinute) {
  188. this.$message.error("课程时长不足");
  189. return;
  190. }
  191. if (this.alltime != this.form.courseConvertSum.courseMinute) {
  192. await this.$alert(
  193. `<b>该班级剩余 <span style="color:red">${parseInt(this.form.courseConvertSum.courseMinute-this.alltime)}</span> 分钟时长未排课</b><br />所有班级排课完成且确认后,剩余时长将被清除,不可再次排课`,
  194. {
  195. confirmButtonText: "确定",
  196. dangerouslyUseHTMLString: true,
  197. }
  198. );
  199. }
  200. } else {
  201. if (this.allNum > this.form.courseConvertSum.courseNum) {
  202. this.$message.error("课程课时不足");
  203. return;
  204. }
  205. if (this.allNum != this.form.courseConvertSum.courseNum) {
  206. await this.$alert(
  207. `<b>该班级剩余 <span style="color:red">${parseInt(this.form.courseConvertSum.courseNum-this.allNum)}</span> 课时未排课</b><br />所有班级排课完成且确认后,剩余课时将被清除,不可再次排课`,
  208. {
  209. confirmButtonText: "确定",
  210. dangerouslyUseHTMLString: true,
  211. }
  212. );
  213. }
  214. }
  215. } catch (e) {
  216. console.log(e);
  217. return;
  218. }
  219. this.$refs.planform.validate(async (valid) => {
  220. let key = "HIGH_ONLINE";
  221. if (valid) {
  222. const item = this.activeRow.classs[key];
  223. const data = {
  224. confirmGenerate: false,
  225. classGroupTeacherMapperList: formatClassGroupTeacherMapperList(
  226. this.myForm.coreTeacher
  227. ),
  228. courseTimeDtoList: item.cycle.map((_) => ({
  229. classGroupTeacherMapperList: this.formatTeacher(_),
  230. courseType: key,
  231. dayOfWeek: _.dayOfWeek,
  232. endClassTime: _.endClassTime,
  233. startClassTime: _.startClassTime,
  234. startDate: _.startDate,
  235. endDate: _.endDate,
  236. holiday: _.holiday,
  237. expectCourseNum: _.expectCourseNum,
  238. })),
  239. ...this.myForm,
  240. userIds: this.myForm.studentList.join(","),
  241. type: key,
  242. };
  243. try {
  244. let arr = [data];
  245. const res = await courseScheduleConvert(arr);
  246. this.activeRow.submitDate = data;
  247. this.activeRow.courseScheduleList = res.data;
  248. this.$emit("submitCourse");
  249. this.transPlanVisible = false;
  250. } catch (e) {
  251. console.log(e);
  252. }
  253. } else {
  254. this.$message.error("请先填写所有表单");
  255. }
  256. });
  257. },
  258. workOut(date, classCount, weekArr, id, startTime = "", endTime = "") {
  259. // 这里是一天排一节课 现在要改成一天排多节
  260. while (classCount && classCount > 0) {
  261. for (let i in weekArr) {
  262. let date1 = new Date(date.getTime());
  263. let num; // 下次上课上几天后
  264. // 星期4 - 当前是星期几 =>
  265. weekArr[i].weekNum - date.getDay() >= 0
  266. ? (num = weekArr[i].weekNum - date.getDay())
  267. : (num = weekArr[i].weekNum - date.getDay() + 7);
  268. let dataStr = this.getThinkDate(date, num);
  269. let monthDay = this.getThinkDate(date1, num, 2);
  270. if (this.isholiday) {
  271. if (this.holidayList.indexOf(monthDay) != -1) {
  272. // 这里说明有节假日
  273. continue;
  274. }
  275. }
  276. // 排的是合奏班
  277. let nowStartTime = this.week[i].startTime || startTime;
  278. let nowEndTime = this.week[i].endTime || endTime;
  279. // date: this.getNowFormatDate(date),
  280. this.tableList.push({
  281. classDate: dataStr,
  282. week: this.weekDay[weekArr[i].weekNum],
  283. type: courseType,
  284. id: id,
  285. name: className,
  286. classTime: nowStartTime + "-" + nowEndTime,
  287. startClassTimeStr: nowStartTime,
  288. endClassTimeStr: nowEndTime,
  289. weekNum: weekArr[i].weekNum,
  290. });
  291. // 这里我排声部课
  292. // date: this.getNowFormatDate(date),
  293. for (let j in this.activeSingleList) {
  294. this.classCardList.push({
  295. classDate: dataStr,
  296. classGroupId: this.activeSingleList[j].id,
  297. startClassTimeStr: nowStartTime,
  298. endClassTimeStr: nowEndTime,
  299. type: courseType,
  300. mixid: this.activeSingleList[j].mixid,
  301. weekNum: weekArr[i].weekNum,
  302. name: this.activeSingleList[j].name,
  303. option: 1,
  304. });
  305. }
  306. classCount--;
  307. if (classCount == 0) break;
  308. }
  309. date.setDate(date.getDate() + 7);
  310. }
  311. // 请求排课
  312. },
  313. },
  314. watch: {
  315. courseTypeList() {
  316. this.setCourseTypeListByName();
  317. },
  318. },
  319. computed: {
  320. isEmpty() {
  321. return isEmpty(this.form.classs);
  322. },
  323. isMoreClass() {
  324. return this.form.classList.length > 1;
  325. },
  326. },
  327. };
  328. </script>
  329. <style lang="scss" scoped>
  330. </style>