soundSetCore.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <template>
  2. <div>
  3. <div class="soundBtnWrap">
  4. <el-button
  5. type="primary"
  6. @click="allin"
  7. v-if="teamStatus != 'resetTeam' && !basdisabled"
  8. >全选</el-button
  9. >
  10. <el-button
  11. type="danger"
  12. @click="deleteRow"
  13. v-if="teamStatus != 'resetTeam' && !basdisabled"
  14. >删除</el-button
  15. >
  16. <el-button type="primary" @click="soundVisible = true" v-if="!basdisabled"
  17. >添加</el-button
  18. >
  19. </div>
  20. <div class="coreWrap">
  21. <el-checkbox-group v-model="checkList" @change="lookCheck">
  22. <el-collapse v-model="chioseActiveSound">
  23. <el-collapse-item
  24. v-for="(item, index) in activeSoundList"
  25. :name="item.id"
  26. :key="index"
  27. >
  28. <template slot="title">
  29. <div class="coreItemTitle">
  30. <el-checkbox :label="item.id" :disabled="basdisabled">{{
  31. item.sound
  32. }}</el-checkbox>
  33. </div>
  34. </template>
  35. <div class="coreItem">
  36. <div class="coreItemRow">
  37. <p class="title">计划招生人数:</p>
  38. <el-input
  39. :disabled="basdisabled"
  40. style="width: 180px"
  41. v-model="item.expectedStudentNum"
  42. ></el-input>
  43. </div>
  44. </div>
  45. <el-divider></el-divider>
  46. <chioseMusic
  47. :activeSoundList="activeSoundList"
  48. :item="item"
  49. @lookMusic="lookMusic"
  50. :basdisabled="basdisabled"
  51. />
  52. <div class="coreItemRow">
  53. <p class="title">教辅:</p>
  54. <el-select
  55. style="width: 558px !important"
  56. v-model="item.markChioseList"
  57. :disabled="basdisabled"
  58. clearable
  59. filterable
  60. multiple
  61. >
  62. <el-option
  63. v-for="(item, index) in item.markList"
  64. :key="index"
  65. :label="item.name"
  66. :value="item.id"
  67. ></el-option>
  68. </el-select>
  69. </div>
  70. </el-collapse-item>
  71. </el-collapse>
  72. </el-checkbox-group>
  73. </div>
  74. <el-dialog title="声部选择" :visible.sync="soundVisible" destroy-on-close>
  75. <chioseSoundList
  76. :soundList="soundList"
  77. :activeSound="activeSound"
  78. @chioseSound="chioseSound"
  79. />
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script>
  84. import store from "@/store";
  85. import { formatData } from "@/utils/utils";
  86. import {
  87. getSubject,
  88. getDefaultSubject,
  89. getGoods,
  90. createTeam,
  91. getSoundTree,
  92. findMusicGroupSubjectInfo,
  93. updateSubjectInfo,
  94. auditSuccess,
  95. auditFailed,
  96. getSubjectGoods,
  97. } from "@/api/buildTeam";
  98. import dayjs from "dayjs";
  99. import chioseSoundList from "./chioseSoundList";
  100. import chioseMusic from "./chioseMusic";
  101. import { findIndex } from "lodash";
  102. import numeral from "numeral";
  103. export default {
  104. components: { chioseSoundList, chioseMusic },
  105. data() {
  106. return {
  107. soundList: [], // 接口返回的一级二级声部
  108. soundVisible: false, // 设置声部弹窗
  109. childSoundList: [],
  110. activeSoundList: [], //列表上的声部
  111. activeSound: null, // 展开的列表
  112. chioseActiveSound: [],
  113. soundList: [], // 接口返回的一级二级声部
  114. childSoundList: [],
  115. teamStatus: "", // 乐团状态
  116. checkList: [],
  117. basdisabled: false,
  118. };
  119. },
  120. mounted() {
  121. this.init();
  122. },
  123. activated() {
  124. this.init();
  125. },
  126. methods: {
  127. init() {
  128. // 获取第一页的数据
  129. this.topfor = this.$store.getters.topinfo;
  130. let type = this.topfor.type;
  131. let section = this.topfor.section;
  132. this.teamStatus = this.$route.query.type;
  133. if (this.$route.query.search) {
  134. this.Fsearch = this.$route.query.search;
  135. }
  136. if (this.$route.query.rules) {
  137. this.Frules = this.$route.query.rules;
  138. }
  139. if (
  140. this.teamStatus == "look" ||
  141. this.teamStatus == "teamAudit" ||
  142. this.teamStatus == "feeAudit"
  143. ) {
  144. this.basdisabled = true;
  145. } else {
  146. this.basdisabled = false;
  147. }
  148. getSoundTree({ tenantId: 1 }).then((res) => {
  149. if (res.code == 200) {
  150. this.soundList = res.data.rows;
  151. if (this.teamStatus == "newTeam" && type && section) {
  152. getDefaultSubject({
  153. chargeTypeId: type,
  154. organId: section,
  155. number: 1,
  156. }).then((res) => {
  157. if (res.code == 200) {
  158. let activeSound = [];
  159. this.activeSoundList = res.data.map((item) => {
  160. activeSound.push(item.id);
  161. return this.initSound(item);
  162. });
  163. this.activeSound = activeSound;
  164. this.chioseActiveSound = activeSound;
  165. this.changeActiveSound(activeSound.join(","));
  166. }
  167. });
  168. } else {
  169. this.teamid = this.$route.query.id;
  170. if (this.teamid) {
  171. findMusicGroupSubjectInfo({ musicGroupId: this.teamid }).then(
  172. (res) => {
  173. if (res.code == 200) {
  174. let activeSound = [];
  175. this.activeSoundList = res.data?.musicGroupSubjectPlans.map(
  176. (item) => {
  177. activeSound.push(item.subjectId);
  178. return {
  179. id: parseInt(item.subjectId),
  180. sound: item.subName,
  181. expectedStudentNum: item.expectedStudentNum,
  182. chioseMusic: [],
  183. markChioseList: [],
  184. goodsList: [],
  185. markList: [],
  186. };
  187. }
  188. );
  189. this.activeSound = activeSound;
  190. this.chioseActiveSound = activeSound;
  191. this.changeActiveSound(activeSound.join(","));
  192. // 格式化商品和教辅
  193. res.data.musicGroupSubjectGoodsGroups.forEach((shop) => {
  194. let index = findIndex(this.activeSoundList, (o) => {
  195. return o.id == shop.subjectId;
  196. });
  197. if (index != -1) {
  198. if (shop.type == "ACCESSORIES") {
  199. shop.goodsIdList.split(",").forEach((item) => {
  200. this.activeSoundList[index].markChioseList.push(
  201. parseInt(item)
  202. );
  203. });
  204. } else if (shop.type == "INSTRUMENT") {
  205. // 商品
  206. let typeJson = Object.keys(
  207. JSON.parse(shop.kitGroupPurchaseTypeJson)
  208. );
  209. this.activeSoundList[index].chioseMusic.push({
  210. musical: parseInt(shop.goodsIdList),
  211. type: typeJson,
  212. groupPrice: shop.price,
  213. borrowPrice: shop.depositFee,
  214. });
  215. }
  216. }
  217. });
  218. }
  219. }
  220. );
  221. }
  222. }
  223. }
  224. });
  225. getSubject({ tenantId: 1 }).then((res) => {
  226. if (res.code == 200) {
  227. this.childSoundList = res.data;
  228. }
  229. });
  230. },
  231. lookCheck(val) {
  232. this.checkList = [...new Set(val)];
  233. },
  234. chioseSound(activeSound) {
  235. // 同步数据
  236. this.activeSound = [...new Set(activeSound)];
  237. let newSoundList = [];
  238. for (let i in this.childSoundList) {
  239. if (this.activeSound.includes(this.childSoundList[i].id)) {
  240. newSoundList.push(this.initSound(this.childSoundList[i]));
  241. }
  242. }
  243. let idList = this.activeSoundList.map((item) => {
  244. return item.id;
  245. });
  246. for (let x in newSoundList) {
  247. const indexof = idList.indexOf(newSoundList[x]?.id);
  248. if (indexof > -1) {
  249. newSoundList[x] = this.activeSoundList[indexof];
  250. }
  251. }
  252. this.activeSoundList = newSoundList;
  253. let newActiveSound = [];
  254. this.activeSoundList.forEach((item) => {
  255. newActiveSound.push(item.id);
  256. });
  257. this.activeSound = newActiveSound;
  258. this.chioseActiveSound = newActiveSound;
  259. this.changeActiveSound(newActiveSound.join(","));
  260. this.soundVisible = false;
  261. },
  262. initSound(item) {
  263. let obj = {
  264. id: item.id,
  265. sound: item.name,
  266. expectedStudentNum: item.expectedStudentNum,
  267. chioseMusic: [
  268. { musical: "", type: ["GROUP"], groupPrice: 0, borrowPrice: 1500 },
  269. ],
  270. markChioseList: [],
  271. goodsList: [],
  272. markList: [],
  273. };
  274. return obj;
  275. },
  276. changeActiveSound(val) {
  277. // 写入声部商品和辅件
  278. getSubjectGoods({
  279. subjectIds: val,
  280. chargeTypeId: this.topfor.type,
  281. }).then((res) => {
  282. if (res.code == 200) {
  283. if (res.data) {
  284. let keys = Object.keys(res.data);
  285. this.activeSoundList.forEach((item) => {
  286. if (keys.indexOf(item.id + "") != -1) {
  287. let goodList = [];
  288. let markList = [];
  289. res.data[item.id].forEach((shop) => {
  290. if (shop.type == "INSTRUMENT") {
  291. goodList.push(shop);
  292. } else if (shop.type == "ACCESSORIES") {
  293. markList.push(shop);
  294. }
  295. });
  296. item.goodsList = goodList;
  297. item.markList = markList;
  298. }
  299. });
  300. }
  301. }
  302. });
  303. },
  304. lookMusic() {},
  305. submitInfo(type) {
  306. // 计划招生人数
  307. // 可选乐器
  308. // 教辅
  309. if (this.activeSoundList.length <= 0) {
  310. this.$message.error(`请至少设置一个声部`);
  311. return;
  312. }
  313. let flag = true;
  314. this.activeSoundList.forEach((item) => {
  315. if (!item.expectedStudentNum) {
  316. this.$message.error(`请填写${item.sound}的预计招生人数`);
  317. flag = false;
  318. return;
  319. }
  320. if (!item.chioseMusic[0]?.musical) {
  321. this.$message.error(`请至少一个选择${item.sound}的可选乐器`);
  322. flag = false;
  323. return;
  324. }
  325. item.chioseMusic.forEach((music) => {
  326. if (music.type.indexOf("LEASE") != -1) {
  327. if (!music.borrowPrice || parseFloat(music.borrowPrice) <= 0) {
  328. this.$message.error(`请填写正确的${item.sound}租赁押金`);
  329. flag = false;
  330. }
  331. }
  332. });
  333. });
  334. if (!flag) return;
  335. // 新建团
  336. let obj = {};
  337. if (this.teamStatus == "newTeam") {
  338. this.initCreateTeam(obj);
  339. }
  340. // 初始化声部
  341. obj.musicGroupSubjectGoodsGroups = [];
  342. obj.musicGroupSubjectPlans = [];
  343. this.activeSoundList.forEach((active) => {
  344. // 格式化声部数据
  345. let item = {
  346. expectedStudentNum: active.expectedStudentNum,
  347. subName: active.sound,
  348. subjectId: active.id,
  349. };
  350. obj.musicGroupSubjectPlans.push(item);
  351. // 格式化商品数据 chioseMusic: [{ musical: '', type: ["GROUP"], groupPrice: 0, borrowPrice: 1500 }],
  352. active.chioseMusic.forEach((music) => {
  353. let goodsItem = null;
  354. let depositFee = music.borrowPrice;
  355. let price = music.groupPrice;
  356. let index = findIndex(active.goodsList, (o) => {
  357. return o.id == music.musical;
  358. });
  359. if (index != -1) {
  360. goodsItem = active.goodsList[index];
  361. }
  362. let kitGroupPurchaseTypeJson = {};
  363. music.type.forEach((type) => {
  364. kitGroupPurchaseTypeJson[type] = 0;
  365. });
  366. // if (Array.isArray(music.type)) {
  367. // music.type.forEach((type) => {
  368. // kitGroupPurchaseTypeJson[type] = 0;
  369. // });
  370. // }else{
  371. // // 字符串
  372. // let arr = [ music.type]
  373. // arr.forEach((type) => {
  374. // kitGroupPurchaseTypeJson[type] = 0;
  375. // });
  376. // }
  377. kitGroupPurchaseTypeJson = JSON.stringify(kitGroupPurchaseTypeJson);
  378. if (goodsItem) {
  379. let some = {
  380. subjectId: active.id,
  381. type: "INSTRUMENT",
  382. goodsIdList: music.musical,
  383. name: goodsItem.name,
  384. kitGroupPurchaseTypeJson,
  385. depositFee,
  386. price,
  387. };
  388. obj.musicGroupSubjectGoodsGroups.push(some);
  389. }
  390. });
  391. // 格式化辅件
  392. // markChioseList: [],
  393. // goodsList: [],
  394. // markList: [],
  395. active.markChioseList.forEach((ass) => {
  396. let index = findIndex(active.markList, (o) => {
  397. return o.id == ass;
  398. });
  399. let goodsItem = null;
  400. if (index != -1) {
  401. goodsItem = active.markList[index];
  402. }
  403. if (goodsItem) {
  404. let some = {
  405. subjectId: active.id,
  406. type: "ACCESSORIES",
  407. goodsIdList: ass,
  408. name: goodsItem.name,
  409. price: goodsItem.groupPurchasePrice,
  410. };
  411. obj.musicGroupSubjectGoodsGroups.push(some);
  412. }
  413. });
  414. });
  415. if (this.teamStatus == "newTeam") {
  416. createTeam(obj).then((res) => {
  417. if (res.code == 200) {
  418. // 成功 跳转到乐团报名详情
  419. let query = this.$route.query;
  420. query.type = "teamDraft";
  421. this.$router.push({
  422. query: {
  423. ...query,
  424. id: res.data,
  425. },
  426. });
  427. this.$emit("chiosetab", 2);
  428. this.$emit("getBaseInfo", obj);
  429. // zheli
  430. }
  431. });
  432. } else {
  433. obj.musicGroupId = this.teamid;
  434. if (type) {
  435. obj.musicGroupStatus = "AUDIT";
  436. } else {
  437. obj.musicGroupStatus = "DRAFT";
  438. }
  439. updateSubjectInfo(obj).then((res) => {
  440. if (res.code == 200) {
  441. this.$message.success("提交成功");
  442. this.$emit("chiosetab", 2);
  443. }
  444. });
  445. }
  446. },
  447. deleteRow() {
  448. if (this.checkList.length < 1) {
  449. this.$message.error("请至少勾选一个");
  450. return;
  451. }
  452. for (let i = 0; i < this.activeSoundList.length; i++) {
  453. let index = this.checkList.indexOf(this.activeSoundList[i].id);
  454. if (index != -1) {
  455. this.activeSoundList.splice(i, 1);
  456. this.activeSound.splice(i, 1);
  457. i--;
  458. }
  459. }
  460. this.checkList = [];
  461. },
  462. allin() {
  463. this.checkList = [];
  464. this.activeSoundList.forEach((item, index) => {
  465. this.checkList.push(item.id);
  466. });
  467. },
  468. initCreateTeam(obj) {
  469. let enrollClasses;
  470. this.topfor.startClass
  471. ? (enrollClasses = this.topfor.startClass.join(","))
  472. : (enrollClasses = null);
  473. obj.musicGroup = {
  474. settlementType: this.topfor.salary,
  475. applyExpireDate: dayjs(this.topfor.time).format("YYYY-MM-DD HH:mm:ss"),
  476. chargeTypeId: this.topfor.type,
  477. cooperationOrganId: this.topfor.school,
  478. teamTeacherId: this.topfor.boss,
  479. educationalTeacherId: this.topfor.teacher,
  480. enrollClasses,
  481. name: this.topfor.name,
  482. organId: this.topfor.section,
  483. paymentPattern: this.topfor.paymentPattern,
  484. paymentValidStartDate: this.topfor.paymentValidStartDate
  485. ? dayjs(this.topfor.paymentValidStartDate).format("YYYY-MM-DD")
  486. : this.topfor.paymentValidStartDate,
  487. paymentValidEndDate: this.topfor.paymentValidEndDate
  488. ? dayjs(this.topfor.paymentValidEndDate).format("YYYY-MM-DD")
  489. : this.topfor.paymentValidEndDate,
  490. // paymentMonths:obj.months 有待确认
  491. schoolId: this.topfor.address,
  492. expectStartGroupDate: this.topfor.startTime,
  493. isClassroomLessons: this.topfor.isClass,
  494. status: "DRAFT",
  495. ownershipType: this.topfor.ownershipType,
  496. repairUserId: this.topfor.repairUserId,
  497. feeType: this.topfor.feeType,
  498. };
  499. return obj;
  500. },
  501. },
  502. watch: {
  503. activeSoundList: {
  504. immediate: true,
  505. deep: true,
  506. handler(n) {
  507. let chioseSoundNum = 0;
  508. let PlannedCount = 0;
  509. let activeSoundList = this.activeSoundList;
  510. if (n) {
  511. let Count = 0;
  512. if (n.length > 0) {
  513. for (let item in n) {
  514. Count += parseInt(n[item]?.expectedStudentNum) || 0;
  515. }
  516. }
  517. chioseSoundNum = n.length;
  518. PlannedCount = Count;
  519. this.$emit("getNumber", chioseSoundNum, PlannedCount);
  520. }
  521. },
  522. },
  523. },
  524. };
  525. </script>
  526. <style lang="scss" scoped>
  527. .soundBtnWrap {
  528. margin-bottom: 20px;
  529. }
  530. /deep/.el-collapse-item__header {
  531. background-color: #edeef0;
  532. }
  533. .coreItemTitle {
  534. background-color: #edeef0;
  535. height: 46px;
  536. line-height: 46px;
  537. padding: 0 20px;
  538. }
  539. .coreItem {
  540. padding: 25px 0 0;
  541. }
  542. .coreItemRow {
  543. padding: 0 20px;
  544. line-height: 50px;
  545. display: flex;
  546. flex-direction: row;
  547. align-items: center;
  548. p {
  549. margin-right: 10px;
  550. }
  551. .title {
  552. width: 100px;
  553. text-align: right;
  554. }
  555. }
  556. .marginLeft10 {
  557. margin-left: 10px;
  558. }
  559. /deep/.el-collapse-item__header {
  560. border-bottom: 1px solid #fff;
  561. }
  562. </style>