classroom-setting-merge.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <div>
  3. <el-form
  4. :model="form"
  5. inline
  6. ref="form"
  7. label-suffix=": "
  8. label-width="130px"
  9. >
  10. <el-row v-if="classType == 5">
  11. <el-form-item
  12. label="班级名称"
  13. prop="className"
  14. label-width="88px"
  15. :rules="[{ required: true, message: '请填写班级名称' }]"
  16. >
  17. <el-input
  18. v-model.trim="form.className"
  19. placeholder="请输入班级名称"
  20. style="width: 180px"
  21. ></el-input>
  22. </el-form-item>
  23. </el-row>
  24. <el-form-item
  25. label="主教老师"
  26. prop="coreTeacher"
  27. label-width="88px"
  28. :rules="[{ required: true, message: '请选择主教老师' }]"
  29. >
  30. <el-select
  31. v-model.trim="form.coreTeacher"
  32. placeholder="请选择主教老师"
  33. clearable
  34. filterable
  35. @change="changecoreTeacher"
  36. >
  37. <el-option
  38. v-for="(item, index) in teacherList"
  39. :key="index"
  40. :label="item.realName"
  41. :value="String(item.id)"
  42. >
  43. <span style="float: left">{{ item.realName }}</span>
  44. <span style="float: right; color: #8492a6; font-size: 13px">{{
  45. String(item.id)
  46. }}</span>
  47. </el-option>
  48. </el-select>
  49. <!-- <remote-search :commit="'setTeachers'" v-model="form.coreTeacher" /> -->
  50. </el-form-item>
  51. <el-form-item
  52. label="助教老师"
  53. prop="assistant"
  54. v-if="
  55. activeType != 'HIGH' &&
  56. activeType != 'HIGH_ONLINE' &&
  57. activeType != 'MUSIC_NETWORK'
  58. "
  59. >
  60. <!-- <remote-search :commit="'setTeachers'" v-model="form.assistant" :multiple='true'/> -->
  61. <el-select
  62. v-model.trim="form.assistant"
  63. placeholder="请选择助教老师"
  64. filterable
  65. clearable
  66. multiple
  67. >
  68. <el-option
  69. v-for="(item, index) in cooperationList"
  70. :key="index"
  71. :label="item.realName"
  72. :value="item.id"
  73. >
  74. <span style="float: left">{{ item.realName }}</span>
  75. <span style="float: right; color: #8492a6; font-size: 13px">{{
  76. String(item.id)
  77. }}</span>
  78. </el-option>
  79. </el-select>
  80. </el-form-item>
  81. <!-- <el-form-item
  82. v-if="!!Object.keys(allClasss).length"
  83. style="display: block"
  84. label="排课类型"
  85. label-width="88px"
  86. >
  87. <el-tag
  88. class="tag"
  89. :effect="form.classs[key] ? 'dark' : 'plain'"
  90. v-for="(item, key) in allClasss"
  91. :key="key"
  92. @click="changeTag(key)"
  93. >{{ courseTypeListByName[key] }}</el-tag
  94. >
  95. </el-form-item> -->
  96. <empty v-if="isEmpty" desc="暂无可排课时长" />
  97. <el-collapse v-model="collapses" @change="collapseChange">
  98. <el-collapse-item
  99. v-for="(item, key, index) in form.classs"
  100. :name="index"
  101. :key="key"
  102. >
  103. <template #title>
  104. <p class="title">
  105. {{ courseTypeListByName[key] }},
  106. <span>可排课时长{{ musicCourseSettings[key] }}分钟</span>
  107. </p>
  108. </template>
  109. <courseItem
  110. :surplustime="surplustime[key]"
  111. :type="key"
  112. :form="item"
  113. :prices="prices"
  114. :selectPrice="selectPrices ? selectPrices[key] : ''"
  115. />
  116. </el-collapse-item>
  117. </el-collapse>
  118. </el-form>
  119. <div slot="footer" class="dialog-footer" v-if="classType != 5">
  120. <el-button @click="$listeners.close">取 消</el-button>
  121. <el-button type="primary" :disabled="isEmpty" @click="submit"
  122. >确 定</el-button
  123. >
  124. </div>
  125. </div>
  126. </template>
  127. <script>
  128. import {
  129. getMusicCourseSettingsWithStudents,
  130. classGroupUpdate,
  131. revisionClassGroup,
  132. revisionAddClassGroup,
  133. findClassCourseMinute,
  134. mergeClassSplitClassAffirm,
  135. } from "@/api/buildTeam";
  136. import courseItem from "./classroom-setting-item-merge";
  137. import { classTimeList } from "@/utils/searchArray";
  138. import MusicStore from "@/views/resetTeaming/store";
  139. import { queryByOrganIdAndCourseType } from "@/views/resetTeaming/api";
  140. import { isEmpty } from "lodash";
  141. const classTimeListByType = {};
  142. for (const item of classTimeList) {
  143. classTimeListByType[item.value] = item.label;
  144. }
  145. const formatClassGroupTeacherMapperList = (core, ass) => {
  146. const list = [];
  147. if (core) {
  148. list.push({ userId: core, teacherRole: "BISHOP" });
  149. }
  150. if (ass) {
  151. for (const item of ass) {
  152. list.push({ userId: item, teacherRole: "TEACHING" });
  153. }
  154. }
  155. return list;
  156. };
  157. const plusNum = (items = [], key) => {
  158. let money = 0;
  159. for (const item of items) {
  160. money += parseFloat(parseFloat(item[key] || 0).toFixed(2) || 0);
  161. }
  162. return money;
  163. };
  164. export default {
  165. props: [
  166. "activeType",
  167. "courseTypeList",
  168. "musicGroupId",
  169. "detail",
  170. "studentSubmitedData",
  171. "classType",
  172. "musicGroupPaymentCalenderDtos",
  173. "classIdList",
  174. "classGroupStudents",
  175. "selectPrices",
  176. "classCouresTimeList",
  177. "teacherList",
  178. "cooperationList",
  179. ],
  180. components: {
  181. courseItem,
  182. },
  183. data() {
  184. return {
  185. form: {
  186. coreTeacher: "",
  187. assistant: "",
  188. classs: {},
  189. },
  190. allClasss: {},
  191. prices: {},
  192. collapses: [0],
  193. courseTimes: {},
  194. courseTypeListByName: {},
  195. classTimeListByType,
  196. musicCourseSettings: {},
  197. };
  198. },
  199. watch: {
  200. courseTypeList() {
  201. this.setCourseTypeListByName();
  202. },
  203. studentSubmitedData() {
  204. this.formatClasss();
  205. },
  206. detail() {
  207. this.formatClasss();
  208. },
  209. },
  210. computed: {
  211. surplustime() {
  212. const _ = {};
  213. for (const key in this.form.classs) {
  214. if (this.form.classs.hasOwnProperty(key)) {
  215. const item = this.form.classs[key];
  216. _[key] = item.courseTotalMinuties - plusNum(item.cycle, "time");
  217. }
  218. }
  219. return _;
  220. },
  221. isEmpty() {
  222. return isEmpty(this.form.classs);
  223. },
  224. musicGroup() {
  225. return MusicStore.state.musicGroup;
  226. },
  227. },
  228. async mounted() {
  229. try {
  230. await MusicStore.dispatch("getBaseInfo", {
  231. data: { musicGroupId: this.musicGroupId },
  232. });
  233. const res = await queryByOrganIdAndCourseType({
  234. organId: this.musicGroup.organId,
  235. });
  236. this.prices = res.data;
  237. if (JSON.stringify(this.prices) == "{}") {
  238. // 课程时长
  239. this.$bus.$emit("showguide", ["teamCourseTimer"]);
  240. return;
  241. }
  242. } catch (error) {}
  243. this.setCourseTypeListByName();
  244. this.formatClasss();
  245. },
  246. methods: {
  247. setCourseTypeListByName() {
  248. const courseTypeListByName = {};
  249. for (const item of this.courseTypeList) {
  250. courseTypeListByName[item.value] = item.label;
  251. }
  252. this.courseTypeListByName = courseTypeListByName;
  253. },
  254. async formatClasss() {
  255. if (this.detail) {
  256. let coreid = "";
  257. const assistant = [];
  258. const { classGroupTeacherMapperList } = this.detail;
  259. for (const item of classGroupTeacherMapperList || []) {
  260. if (item.teacherRole === "BISHOP") {
  261. coreid = String(item.userId);
  262. }
  263. if (item.teacherRole === "TEACHING") {
  264. assistant.push(item.userId);
  265. }
  266. }
  267. this.$set(this.form, "coreTeacher", String(coreid));
  268. this.$set(this.form, "assistant", assistant);
  269. }
  270. const studentIds = this.detail
  271. ? undefined
  272. : this.studentSubmitedData?.seleched.join(",");
  273. const classGroupId = this.detail?.id;
  274. if (!studentIds && !classGroupId) {
  275. return;
  276. }
  277. let res = {};
  278. if (this.classType == 5) {
  279. // res = await findClassCourseMinute(this.classIdList);
  280. res.data = this.classCouresTimeList;
  281. } else {
  282. try {
  283. res = await getMusicCourseSettingsWithStudents({
  284. musicGroupId: this.musicGroupId,
  285. studentIds,
  286. classGroupId,
  287. });
  288. } catch (error) {
  289. console.log(error);
  290. }
  291. }
  292. // console.log(res);
  293. if (Object.keys(res).length <= 0) return;
  294. this.musicCourseSettings = res.data;
  295. const classs = {};
  296. for (const item of this.courseTypeList) {
  297. const key = item.value;
  298. if (res.data[key]) {
  299. classs[key] = {
  300. courseTotalMinuties: res.data[key],
  301. cycle: [
  302. {
  303. time: this.selectPrices ? this.selectPrices[key] : undefined,
  304. },
  305. ],
  306. };
  307. }
  308. }
  309. this.allClasss = { ...classs };
  310. this.$set(this.form, "classs", classs);
  311. // this.courseTimes = courseTimes
  312. },
  313. changeTag(key) {
  314. const clas = { ...this.form.classs };
  315. if (clas[key]) {
  316. delete clas[key];
  317. } else {
  318. clas[key] = this.allClasss[key];
  319. }
  320. this.$set(this.form, "classs", clas);
  321. },
  322. submit() {
  323. this.$refs.form.validate(async (valid) => {
  324. if (valid) {
  325. const list = [];
  326. for (const key in this.form.classs) {
  327. if (this.form.classs.hasOwnProperty(key)) {
  328. const item = this.form.classs[key];
  329. list.push({
  330. type: this.detail ? undefined : this.activeType,
  331. courseType: key,
  332. classGroupName:
  333. this.studentSubmitedData?.name ||
  334. this.detail?.name ||
  335. this.form.className,
  336. classGroupId: this.detail?.id,
  337. musicGroupId: this.musicGroupId,
  338. startDate: item.courseTime,
  339. classGroupTeacherMapperList: formatClassGroupTeacherMapperList(
  340. this.form.coreTeacher,
  341. this.form.assistant
  342. ),
  343. holiday: item.holiday,
  344. students: this.studentSubmitedData?.seleched,
  345. courseTimes: item.cycle.length,
  346. courseTimeDtoList: item.cycle.map((_) => ({
  347. courseType: key,
  348. dayOfWeek: _.dayOfWeek,
  349. endClassTime: _.endClassTime,
  350. startClassTime: _.startClassTime,
  351. })),
  352. });
  353. }
  354. }
  355. try {
  356. if (this.detail) {
  357. let result = await classGroupUpdate(list);
  358. if (result.code == 206) {
  359. this.$confirm(`当前课程课酬预计为0,是否继续`, "提示", {
  360. confirmButtonText: "确定",
  361. cancelButtonText: "取消",
  362. type: "warning",
  363. })
  364. .then(async () => {
  365. // obj.allowZeroSalary = true;
  366. list.forEach((item) => {
  367. item.allowZeroSalary = true;
  368. });
  369. await classGroupUpdate(list);
  370. this.$listeners.submited();
  371. this.$listeners.close();
  372. })
  373. .catch(() => {
  374. return;
  375. });
  376. return;
  377. }
  378. this.$message.success("排课修改成功");
  379. } else {
  380. if (this.classType == 1) {
  381. // 0新建班级 2 3 4新增班级修改
  382. await revisionClassGroup(list);
  383. this.$message.success("排课成功");
  384. } else if (
  385. this.classType == 2 ||
  386. this.classType == 3 ||
  387. this.classType == 4
  388. ) {
  389. await revisionAddClassGroup(list);
  390. this.$message.success("排课成功");
  391. } else if (this.classType == 5) {
  392. // 这里是合班拆班
  393. let obj = {};
  394. obj.musicGroupPaymentCalenderDtos =
  395. this.musicGroupPaymentCalenderDtos;
  396. obj.classGroup4MixDtos = list;
  397. obj.classGroupIds = this.classIdList;
  398. obj.studentIds = this.studentSubmitedData.seleched;
  399. obj.classGroupStudents = this.classGroupStudents;
  400. obj.classCourseMinuteMap = this.selectPrices;
  401. await mergeClassSplitClassAffirm(obj);
  402. let grend =
  403. this.$parent.$parent.$parent.$parent.$parent.$parent.$parent;
  404. grend.closeStudentReset();
  405. grend.getList();
  406. return;
  407. }
  408. }
  409. this.$listeners.submited();
  410. this.$listeners.close();
  411. } catch (error) {
  412. console.log(error);
  413. }
  414. } else {
  415. this.$message.error("请先填写所有表单");
  416. }
  417. });
  418. },
  419. collapseChange(val) {
  420. this.collapses = val;
  421. },
  422. changecoreTeacher(val) {},
  423. },
  424. };
  425. </script>
  426. <style lang="less" scoped>
  427. .dialog-footer {
  428. margin-top: 20px;
  429. display: block;
  430. text-align: right;
  431. }
  432. .title {
  433. font-size: 16px;
  434. padding: 10px;
  435. font-weight: normal;
  436. > span {
  437. color: tomato;
  438. font-size: 14px;
  439. }
  440. }
  441. .tag {
  442. margin-right: 5px;
  443. cursor: pointer;
  444. }
  445. </style>