classroom-setting.vue 11 KB

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