user-pay-form.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <div>
  3. <el-alert title="课程信息设置"
  4. :closable="false"
  5. class="alert"
  6. type="info">
  7. </el-alert>
  8. <userBaseinfo :form.sync="form"
  9. :isCommon="isCommon"
  10. :isUserType="isUserType"
  11. @getCharges="getCharges"
  12. @changeActive="changeActive"
  13. :typeList="typeList"
  14. :charges="charges"
  15. :rowDetail="rowDetail"
  16. :chargeTypeName="chargeTypeName"
  17. :paymentType="paymentType"
  18. ref="base" />
  19. <template v-if="!isCommon">
  20. <el-alert title="加课信息设置"
  21. :closable="false"
  22. class="alert"
  23. type="info">
  24. </el-alert>
  25. <extraClass :form.sync="eclass"
  26. ref="eclass"
  27. @create="addExtraClass"
  28. @remove="removeExtraClass"
  29. :isUserType="isUserType"
  30. :courseUnitPriceSettingsByType="organizationCourseUnitPriceSettingsByType"
  31. @priceChange="priceChange"
  32. :clearable="true"
  33. @moneyChange="syncAllMoney" />
  34. </template>
  35. <extraClass v-else-if="(!isCommon && eclass.length) || isCommon"
  36. :form="eclass"
  37. ref="eclass"
  38. :isCommon="isCommon"
  39. @create="addExtraClass"
  40. @remove="removeExtraClass"
  41. @moneyChange="syncAllMoney"
  42. :courseUnitPriceSettingsByType="organizationCourseUnitPriceSettingsByType"
  43. :isUserType="isUserType"
  44. :isDisabled="form.leixing === '1' || paymentType == '0'" />
  45. <template>
  46. <el-alert title="缴费设置"
  47. :closable="false"
  48. class="alert"
  49. type="info">
  50. </el-alert>
  51. <paymentCycle ref="cycle"
  52. :isUserType="isUserType"
  53. :form.sync="cycle"
  54. :isCommon="isCommon"
  55. :isDisabled="true" />
  56. </template>
  57. <el-alert title="其它"
  58. :closable="false"
  59. class="alert"
  60. type="info">
  61. </el-alert>
  62. <otherform :form="other"
  63. ref="other" />
  64. <div slot="footer"
  65. class="dialog-footer">
  66. <el-button @click="$listeners.close">取 消</el-button>
  67. <el-button type="primary"
  68. @click="submit">确认</el-button>
  69. </div>
  70. <el-dialog :title="nextTitle"
  71. :visible.sync="nextVisible"
  72. width="600px"
  73. append-to-body>
  74. <classrooms @close="closeNext" />
  75. </el-dialog>
  76. </div>
  77. </template>
  78. <script>
  79. import {
  80. chargeTypeList,
  81. musicGroupOrganizationCourseSettingsQueryPage,
  82. } from "@/api/specialSetting";
  83. import { getMusicGroupPaymentCalenderDetail } from '@/api/buildTeam'
  84. import {
  85. musicGroupPaymentCalenderAdd,
  86. musicGroupPaymentCalenderDetailBatchUpdate,
  87. queryByMusicGroupOrganizationCourseSettingsId,
  88. } from "../api";
  89. import { getTimes } from "@/utils";
  90. import userBaseinfo from "./user-baseinfo";
  91. import paymentCycle from "./payment-cycle";
  92. import extraClass from "./extra-class";
  93. import classrooms from "./classrooms";
  94. import otherform from "./other";
  95. import baseInfoVue from '../../teamDetail/components/baseInfo.vue';
  96. import merge from 'webpack-merge'
  97. const paymentTypeFormat = {
  98. 0: "MUSIC_APPLY",
  99. 1: "MUSIC_RENEW",
  100. 2: "ADD_COURSE",
  101. 3: "ADD_STUDENT",
  102. };
  103. export default {
  104. props: ["type", "musicGroupId", "baseInfo", "paymentType", "rowDetail", 'organizationCourseUnitPriceSettings'],
  105. components: {
  106. userBaseinfo,
  107. paymentCycle,
  108. extraClass,
  109. classrooms,
  110. otherform,
  111. },
  112. data () {
  113. return {
  114. options: [],
  115. form: {
  116. payUserType: this.type === "user" ? "STUDENT" : "SCHOOL",
  117. leixing: "1",
  118. musicGroupOrganizationCourseSettingId: null,
  119. },
  120. chargeTypeName: '',
  121. other: {},
  122. cycles: [{}],
  123. cycle: {},
  124. eclass: [],
  125. collapse: [],
  126. nextVisible: false,
  127. typeList: [],
  128. charges: [],
  129. organizationCourseUnitPriceSettingsByType: {},
  130. };
  131. },
  132. computed: {
  133. isCommon () {
  134. return this.form.leixing === "1";
  135. },
  136. isDisabled () {
  137. return this.form.leixing === "1" || String(this.paymentType) === "0";
  138. },
  139. isUserType () {
  140. return this.type === "user";
  141. },
  142. nextTitle () {
  143. return this.isCommon ? "乐团课程-班级选择" : "临时加课-班级选择";
  144. },
  145. chargesById () {
  146. const data = {};
  147. for (const item of this.charges) {
  148. data[item.id] = item;
  149. }
  150. return data;
  151. },
  152. },
  153. watch: {
  154. type () {
  155. this.$set(
  156. this.form,
  157. "payUserType",
  158. this.type === "user" ? "STUDENT" : "SCHOOL"
  159. );
  160. },
  161. baseInfo (val) {
  162. this.formatCourse()
  163. this.getCharges();
  164. },
  165. organizationCourseUnitPriceSettings() {
  166. this.formatCourse()
  167. },
  168. "form.leixing" (val) {
  169. this.cycles = [{}];
  170. this.collapse = [0];
  171. this.cycle = {};
  172. this.$set(this.form, "musicGroupOrganizationCourseSettingId", undefined);
  173. this.$set(this.cycle, "paymentAmount", undefined);
  174. if (val === "1") {
  175. this.eclass = [];
  176. } else if (val === "2") {
  177. this.eclass = [];
  178. }
  179. },
  180. async "form.musicGroupOrganizationCourseSettingId" (val) {
  181. try {
  182. const res = await queryByMusicGroupOrganizationCourseSettingsId({
  183. id: val
  184. })
  185. this.eclass = res.data.filter(item => {
  186. return !item.isStudentOptional || this.paymentType !== undefined
  187. }) || [{}];
  188. this.syncAllMoney();
  189. } catch (error) { }
  190. },
  191. },
  192. mounted () {
  193. this.formatCourse()
  194. this.init();
  195. },
  196. activated () {
  197. this.formatCourse()
  198. this.init();
  199. },
  200. methods: {
  201. async init () {
  202. this.getCharges();
  203. if (this.rowDetail) {
  204. for (const key in paymentTypeFormat) {
  205. if (paymentTypeFormat.hasOwnProperty(key)) {
  206. const item = paymentTypeFormat[key];
  207. if (item === this.rowDetail.paymentType) {
  208. this.paymentType = key
  209. }
  210. }
  211. }
  212. this.$set(
  213. this.other,
  214. "isGiveMusicNetwork",
  215. this.rowDetail.isGiveMusicNetwork
  216. );
  217. this.$set(this.other, "memo", this.rowDetail.memo);
  218. if (this.rowDetail.musicGroupOrganizationCourseSettingId) {
  219. this.form.musicGroupOrganizationCourseSettingId = this.rowDetail.musicGroupOrganizationCourseSettingId;
  220. } else {
  221. try {
  222. const res = await getMusicGroupPaymentCalenderDetail({
  223. id: this.rowDetail.id
  224. })
  225. this.eclass = res.data.musicGroupPaymentCalenderCourseSettings
  226. this.syncAllMoney()
  227. } catch (error) {}
  228. }
  229. }
  230. },
  231. formatCourse() {
  232. const organId = this.baseInfo?.musicGroup?.organId
  233. const chargeTypeId = this.baseInfo?.musicGroup?.chargeTypeId
  234. const _ = {}
  235. const list = (this.organizationCourseUnitPriceSettings || [])
  236. .filter(item => organId && organId == item.organId && chargeTypeId && chargeTypeId == item.chargeTypeId)
  237. for (const item of list) {
  238. _[item.courseType] = item
  239. }
  240. this.organizationCourseUnitPriceSettingsByType = _
  241. return _
  242. },
  243. priceChange (item, index) {
  244. const _ = [...this.eclass]
  245. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  246. const price = Math.ceil((item.courseTotalMinuties || 1) * (active.unitPrice || 1))
  247. item.courseCurrentPrice = price
  248. item.courseOriginalPrice = price
  249. _[index] = item
  250. this.eclass = [..._]
  251. this.syncAllMoney()
  252. },
  253. syncAllMoney () {
  254. let money = 0;
  255. for (const item of this.eclass) {
  256. money += item.courseCurrentPrice;
  257. }
  258. if (!money) {
  259. this.$set(this.cycle, "paymentAmount", undefined);
  260. } else {
  261. this.$set(this.cycle, "paymentAmount", money);
  262. }
  263. if (this.rowDetail) {
  264. this.$set(
  265. this.cycle,
  266. "paymentPattern",
  267. this.rowDetail?.paymentPattern + ""
  268. );
  269. let arr = [
  270. this.rowDetail?.paymentValidStartDate,
  271. this.rowDetail?.paymentValidEndDate,
  272. ];
  273. // paymentDate startPaymentDate deadlinePaymentDate
  274. this.$set(this.cycle, "paymentDate", [this.rowDetail?.startPaymentDate, this.rowDetail?.deadlinePaymentDate]);
  275. this.$set(this.cycle, "paymentValid", arr);
  276. }
  277. return money;
  278. },
  279. async getChargeTypeList () {
  280. try {
  281. const res = await chargeTypeList({
  282. row: 9999,
  283. });
  284. this.typeList = res.data.rows;
  285. } catch (error) { }
  286. },
  287. async getCharges () {
  288. const organId = this.baseInfo?.musicGroup?.organId;
  289. const chargeTypeId = this.baseInfo?.musicGroup?.chargeTypeId;
  290. this.chargeTypeName = this.baseInfo?.musicGroup?.chargeTypeName;
  291. try {
  292. const res = await musicGroupOrganizationCourseSettingsQueryPage({
  293. row: 9999,
  294. chargeTypeId,
  295. organId,
  296. });
  297. const ids = res.data.rows.map(item => item.id)
  298. if (!ids.includes(this.form.musicGroupOrganizationCourseSettingId)) {
  299. this.$set(this.form, 'musicGroupOrganizationCourseSettingId', null)
  300. }
  301. this.charges = res.data.rows;
  302. } catch (error) { }
  303. },
  304. addExtraClass () {
  305. this.eclass.push({});
  306. },
  307. removeExtraClass (index) {
  308. this.eclass[index] = null;
  309. this.eclass = this.eclass.filter((item) => !!item);
  310. },
  311. addCycle () {
  312. this.cycles.push({});
  313. this.collapse.push(this.collapse.length);
  314. },
  315. removeCycle (index) {
  316. this.cycles[index] = null;
  317. this.cycles = this.cycles.filter((item) => !!item);
  318. this.collapse.pop();
  319. },
  320. collapseChange (val) {
  321. this.collapse = val;
  322. },
  323. closeNext () {
  324. this.nextVisible = false;
  325. },
  326. getForms () {
  327. const { $refs: refs } = this;
  328. return [refs.base, refs.eclass, refs.cycle, refs.other]
  329. .filter((item) => !!item)
  330. .map((item) => item.$refs.form);
  331. },
  332. changeActive(val) {
  333. if (this.$listeners.changeActive) {
  334. this.$listeners.changeActive(val)
  335. }
  336. },
  337. async submit() {
  338. const forms = this.getForms();
  339. const valided = [];
  340. for (const form of forms) {
  341. form.validate((valid) => {
  342. if (valid) {
  343. valided.push(form);
  344. }
  345. });
  346. }
  347. if (this.eclass.length < 1) {
  348. return this.$message.error('请至少选择一条加课信息')
  349. }
  350. if (valided.length === forms.length) {
  351. const { paymentDate, paymentValid, leixing, ...rest } = {
  352. ...this.form,
  353. ...this.other,
  354. ...this.cycle,
  355. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  356. };
  357. const data = {
  358. ...rest,
  359. isGiveMusicNetwork: false,
  360. paymentType:
  361. paymentTypeFormat[
  362. this.paymentType == 0 ? this.paymentType : leixing
  363. ],
  364. musicGroupId: this.musicGroupId,
  365. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  366. ...getTimes(paymentValid, [
  367. "paymentValidStartDate",
  368. "paymentValidEndDate",
  369. ]),
  370. };
  371. if (!this.rowDetail?.id) {
  372. try {
  373. const res = await musicGroupPaymentCalenderAdd(data);
  374. this.$listeners.close();
  375. this.$listeners.submited(res.data);
  376. // 在这里
  377. if (this.$route.query.type == "teamDraft") {
  378. this.$router.push({
  379. query: merge(this.$route.query, { 'type': 'feeAudit' })
  380. });
  381. }
  382. } catch (error) { }
  383. } else {
  384. try {
  385. data.id = this.rowDetail.id
  386. const res = await musicGroupPaymentCalenderDetailBatchUpdate(data);
  387. this.$listeners.close();
  388. this.$listeners.submited(res.data);
  389. if (this.$route.query.type == "teamDraft") {
  390. this.$router.push({
  391. query: merge(this.$route.query, { 'type': 'feeAudit' })
  392. });
  393. }
  394. } catch (error) { }
  395. }
  396. }
  397. },
  398. },
  399. };
  400. </script>
  401. <style lang="less" scoped>
  402. .dialog-footer {
  403. margin-top: 20px;
  404. display: block;
  405. text-align: right;
  406. }
  407. .alert {
  408. margin-bottom: 10px;
  409. }
  410. .collapse-title {
  411. display: flex;
  412. justify-content: space-between;
  413. align-items: center;
  414. width: 100%;
  415. .el-icon-circle-close {
  416. font-size: 16px;
  417. margin-right: 10px;
  418. }
  419. }
  420. /deep/ .el-collapse-item__wrap {
  421. padding-top: 20px;
  422. }
  423. </style>