user-pay-form.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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' || form.leixing === '2' || paymentType == '0'" />
  45. <template>
  46. <el-alert title="缴费设置"
  47. :closable="false"
  48. class="alert"
  49. type="info">
  50. </el-alert>
  51. <el-form ref="payment" :model="payment">
  52. <el-form-item
  53. label-width="160px"
  54. label="缴费方式"
  55. prop="paymentPattern"
  56. :rules="[{required: true, message: '请选择缴费方式', trigger: 'change'}]"
  57. >
  58. <el-select style="width: 100%!important;" v-model="payment.paymentPattern" placeholder="请选择缴费方式">
  59. <el-option
  60. v-for="item in paymentPatternTypeOptions"
  61. :key="item.value"
  62. :label="item.label"
  63. :value="item.value">
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. </el-form>
  68. <template v-if="isMulticycle">
  69. <el-collapse :value="collapse" @change="collapseChange" >
  70. <el-collapse-item
  71. v-for="(item, index) in cycles"
  72. :key="index"
  73. :name="index"
  74. >
  75. <template slot="title">
  76. <div class="collapse-title">
  77. <span>缴费周期 {{index + 1}}</span>
  78. <i v-if="cycles.length > 1" class="el-icon-circle-close" @click.stop="removeCycle(index)"></i>
  79. </div>
  80. </template>
  81. <paymentCycle
  82. ref="cycles"
  83. :form="item"
  84. :hidePaymentPattern="true"
  85. :isCommon="isCommon"
  86. :isUserType="isUserType"
  87. :isDisabled="form.leixing === '1' || form.leixing === '2' || paymentType == '0'"
  88. />
  89. </el-collapse-item>
  90. </el-collapse>
  91. <el-button
  92. icon="el-icon-circle-plus-outline"
  93. plain
  94. type="info"
  95. size="small"
  96. style="width: 100%;margin: 20px 0;"
  97. @click="addCycle"
  98. >新增缴费周期</el-button>
  99. </template>
  100. <paymentCycle
  101. ref="cycle"
  102. :form.sync="cycle"
  103. :isCommon="isCommon"
  104. :hidePaymentPattern="true"
  105. :isUserType="isUserType"
  106. :isDisabled="form.leixing === '1' || form.leixing === '2' || paymentType == '0'"
  107. v-else
  108. />
  109. </template>
  110. <el-alert title="其它"
  111. :closable="false"
  112. class="alert"
  113. type="info">
  114. </el-alert>
  115. <otherform :form="other"
  116. ref="other" />
  117. <div slot="footer"
  118. class="dialog-footer">
  119. <el-button @click="$listeners.close">取 消</el-button>
  120. <el-button type="primary"
  121. @click="submit">确认</el-button>
  122. </div>
  123. <el-dialog :title="nextTitle"
  124. :visible.sync="nextVisible"
  125. width="600px"
  126. append-to-body>
  127. <classrooms @close="closeNext" />
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. import {
  133. chargeTypeList,
  134. musicGroupOrganizationCourseSettingsQueryPage,
  135. } from "@/api/specialSetting";
  136. import { getMusicGroupPaymentCalenderDetail } from '@/api/buildTeam'
  137. import {
  138. musicGroupPaymentCalenderAdd,
  139. musicGroupPaymentCalenderDetailBatchUpdate,
  140. queryByMusicGroupOrganizationCourseSettingsId,
  141. musicGroupPaymentCalenderView,
  142. } from "../api";
  143. import { paymentPatternType } from '@/constant'
  144. import { getTimes, objectToOptions } from "@/utils";
  145. import userBaseinfo from "./user-baseinfo";
  146. import paymentCycle from "./payment-cycle";
  147. import extraClass from "./extra-class";
  148. import classrooms from "./classrooms";
  149. import otherform from "./other";
  150. import baseInfoVue from '../../teamDetail/components/baseInfo.vue';
  151. import merge from 'webpack-merge'
  152. import numeral from 'numeral'
  153. const paymentTypeFormat = {
  154. 0: "MUSIC_APPLY",
  155. 1: "MUSIC_RENEW",
  156. 2: "ADD_COURSE",
  157. 3: "ADD_STUDENT",
  158. };
  159. export default {
  160. props: ["type", "musicGroupId", "baseInfo", "paymentType", "rowDetail", 'organizationCourseUnitPriceSettings'],
  161. components: {
  162. userBaseinfo,
  163. paymentCycle,
  164. extraClass,
  165. classrooms,
  166. otherform,
  167. },
  168. data () {
  169. return {
  170. options: [],
  171. form: {
  172. payUserType: this.type === "user" ? "STUDENT" : "SCHOOL",
  173. leixing: "1",
  174. musicGroupOrganizationCourseSettingId: null,
  175. },
  176. chargeTypeName: '',
  177. other: {},
  178. cycles: [{}],
  179. cycle: {},
  180. eclass: [],
  181. collapse: [0],
  182. nextVisible: false,
  183. typeList: [],
  184. charges: [],
  185. studentIds: '',
  186. payment: {
  187. paymentPattern: null,
  188. },
  189. viewDetail: null,
  190. organizationCourseUnitPriceSettingsByType: {},
  191. paymentPatternTypeOptions: objectToOptions(paymentPatternType),
  192. };
  193. },
  194. computed: {
  195. musicGroup() {
  196. return this.baseInfo?.musicGroup
  197. },
  198. isCommon () {
  199. return this.form.leixing === "1";
  200. },
  201. isDisabled () {
  202. return this.form.leixing === "1" || String(this.paymentType) === "0";
  203. },
  204. isUserType () {
  205. return this.type === "user";
  206. },
  207. nextTitle () {
  208. return this.isCommon ? "乐团课程-班级选择" : "临时加课-班级选择";
  209. },
  210. chargesById () {
  211. const data = {};
  212. for (const item of this.charges) {
  213. data[item.id] = item;
  214. }
  215. return data;
  216. },
  217. paymentAmountDisabled() {
  218. return (this.isUserType || (this.isCommon && this.isUserType)) && this.isDisabled
  219. },
  220. isMulticycle() {
  221. let editMulticycle = false
  222. let paymentType = ''
  223. if (this.viewDetail) {
  224. const { musicGroupPaymentCalenders, auditDto } = this.viewDetail
  225. paymentType = musicGroupPaymentCalenders[0]?.paymentType
  226. editMulticycle = (musicGroupPaymentCalenders.length > 1 || paymentType != 'ADD_COURSE')
  227. if (editMulticycle) {
  228. this.cycles = musicGroupPaymentCalenders.map(item => ({
  229. paymentAmount: item.paymentAmount,
  230. paymentDate: [item?.startPaymentDate, item?.deadlinePaymentDate],
  231. paymentValid: [item?.paymentValidStartDate, item?.paymentValidEndDate]
  232. }))
  233. }
  234. }
  235. return (this.payment.paymentPattern == 0 && this.form.leixing !== '2' && paymentType !== 'ADD_COURSE') || (this.payment.paymentPattern == 0 && editMulticycle)
  236. }
  237. },
  238. watch: {
  239. type () {
  240. this.$set(
  241. this.form,
  242. "payUserType",
  243. this.type === "user" ? "STUDENT" : "SCHOOL"
  244. );
  245. },
  246. baseInfo (val) {
  247. this.formatCourse()
  248. this.getCharges();
  249. },
  250. organizationCourseUnitPriceSettings() {
  251. this.formatCourse()
  252. },
  253. "form.leixing" (val) {
  254. this.cycles = [{}];
  255. this.collapse = [0];
  256. this.cycle = {};
  257. this.$set(this.form, "musicGroupOrganizationCourseSettingId", undefined);
  258. this.$set(this.cycle, "paymentAmount", undefined);
  259. if (val === "1") {
  260. this.eclass = [];
  261. } else if (val === "2") {
  262. this.eclass = [{}];
  263. }
  264. },
  265. async "form.musicGroupOrganizationCourseSettingId" (val) {
  266. if (val) {
  267. try {
  268. const res = await queryByMusicGroupOrganizationCourseSettingsId({
  269. id: val
  270. })
  271. this.eclass = res.data.filter(item => {
  272. return !item.isStudentOptional || this.paymentType !== undefined
  273. }) || [{}];
  274. this.syncAllMoney();
  275. } catch (error) { }
  276. }
  277. },
  278. 'payment.paymentPattern'() {
  279. this.syncAllMoney()
  280. },
  281. },
  282. mounted () {
  283. this.formatCourse()
  284. this.init();
  285. },
  286. activated () {
  287. this.formatCourse()
  288. this.init();
  289. },
  290. methods: {
  291. async init () {
  292. this.getCharges();
  293. if (this.rowDetail) {
  294. for (const key in paymentTypeFormat) {
  295. if (paymentTypeFormat.hasOwnProperty(key)) {
  296. const item = paymentTypeFormat[key];
  297. if (item === this.rowDetail.paymentType) {
  298. this.paymentType = key
  299. }
  300. }
  301. }
  302. this.$set(
  303. this.other,
  304. "isGiveMusicNetwork",
  305. this.rowDetail.isGiveMusicNetwork
  306. );
  307. this.$set(this.other, "memo", this.rowDetail.memo);
  308. try {
  309. const res = await musicGroupPaymentCalenderView({
  310. musicGroupId: this.musicGroupId,
  311. batchNo: this.rowDetail.batchNo,
  312. })
  313. this.viewDetail = res.data
  314. this.eclass = (res.data.musicGroupPaymentCalenderCourseSettings || []).filter(item => {
  315. return !item.isStudentOptional || this.paymentType !== undefined
  316. })
  317. const firstPayment = res.data.musicGroupPaymentCalenders[0] || {}
  318. this.$set(this.payment, 'paymentPattern', String(this.viewDetail.auditDto?.paymentPattern))
  319. if (this.$refs.cycle) {
  320. this.$set(
  321. this.cycle,
  322. "paymentPattern",
  323. firstPayment.paymentPattern + ""
  324. );
  325. let arr = [
  326. firstPayment.paymentValidStartDate,
  327. firstPayment.paymentValidEndDate,
  328. ];
  329. // paymentDate startPaymentDate deadlinePaymentDate
  330. this.$set(this.cycle, "paymentDate", [firstPayment.startPaymentDate, firstPayment.deadlinePaymentDate]);
  331. this.$set(this.cycle, "paymentValid", arr);
  332. }
  333. this.studentIds = firstPayment.studentIds
  334. this.$set(this.form, 'musicGroupOrganizationCourseSettingId', res.data.auditDto?.musicGroupOrganizationCourseSettingsId)
  335. this.syncAllMoney()
  336. } catch (error) {}
  337. }
  338. },
  339. formatCourse() {
  340. const organId = this.musicGroup?.organId
  341. const chargeTypeId = this.musicGroup?.chargeTypeId
  342. const _ = {}
  343. const list = (this.organizationCourseUnitPriceSettings || [])
  344. .filter(item => organId && organId == item.organId && chargeTypeId && chargeTypeId == item.chargeTypeId)
  345. for (const item of list) {
  346. _[item.courseType] = item
  347. }
  348. this.organizationCourseUnitPriceSettingsByType = _
  349. return _
  350. },
  351. priceChange (item, index) {
  352. const _ = [...this.eclass]
  353. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  354. const price = Math.round(numeral(active.unitPrice || 1).multiply((item.courseTotalMinuties || 1)).value())
  355. item.courseCurrentPrice = price
  356. item.courseOriginalPrice = price
  357. _[index] = item
  358. this.eclass = [..._]
  359. this.syncAllMoney()
  360. },
  361. syncAllMoney () {
  362. let money = 0;
  363. let first = 0
  364. let other = 0
  365. for (const item of this.eclass) {
  366. money += item.courseCurrentPrice;
  367. if (this.cycles && this.cycles.length) {
  368. if (item.isStudentOptional) {
  369. first += item.courseCurrentPrice
  370. } else {
  371. const floorMoney = Math.floor(item.courseCurrentPrice / this.cycles.length)
  372. const remainder = item.courseCurrentPrice % this.cycles.length
  373. console.log(remainder)
  374. first += floorMoney + remainder
  375. other += floorMoney
  376. }
  377. }
  378. }
  379. if (this.cycles && this.cycles.length) {
  380. this.cycles = this.cycles.map((item, index) => {
  381. return {
  382. ...item,
  383. paymentAmount: (index === 0 ? first : other)
  384. }
  385. })
  386. }
  387. // if (!money) {
  388. // this.$set(this.cycle, "paymentAmount", undefined);
  389. // } else {
  390. this.$set(this.cycle, "paymentAmount", money);
  391. // }
  392. return money;
  393. },
  394. async getChargeTypeList () {
  395. try {
  396. const res = await chargeTypeList({
  397. row: 9999,
  398. });
  399. this.typeList = res.data.rows;
  400. } catch (error) { }
  401. },
  402. async getCharges () {
  403. const organId = this.musicGroup?.organId;
  404. const chargeTypeId = this.musicGroup?.chargeTypeId;
  405. this.chargeTypeName = this.musicGroup?.chargeTypeName;
  406. try {
  407. const res = await musicGroupOrganizationCourseSettingsQueryPage({
  408. row: 9999,
  409. chargeTypeId,
  410. organId,
  411. });
  412. const ids = res.data.rows.map(item => item.id)
  413. if (!ids.includes(this.form.musicGroupOrganizationCourseSettingId)) {
  414. this.$set(this.form, 'musicGroupOrganizationCourseSettingId', null)
  415. }
  416. this.charges = res.data.rows;
  417. } catch (error) { }
  418. },
  419. addExtraClass () {
  420. this.eclass.push({});
  421. },
  422. removeExtraClass (index) {
  423. this.eclass[index] = null;
  424. this.eclass = this.eclass.filter((item) => !!item);
  425. },
  426. addCycle () {
  427. this.cycles.push({});
  428. this.collapse.push(this.cycles.length - 1);
  429. this.syncAllMoney()
  430. },
  431. removeCycle (index) {
  432. this.cycles[index] = null;
  433. this.cycles = this.cycles.filter((item) => !!item);
  434. if (this.collapse.includes(index)) {
  435. this.collapse.splice(index, 1);
  436. this.collapse = this.collapse.map((item, _index) => _index - 1 >= index ? item -- : item)
  437. }
  438. this.syncAllMoney()
  439. },
  440. collapseChange (val) {
  441. this.collapse = val;
  442. },
  443. closeNext () {
  444. this.nextVisible = false;
  445. },
  446. getForms () {
  447. const { $refs: refs } = this;
  448. return [refs.base, refs.eclass, refs.cycle, ...(refs.cycles || []), refs.other, refs.payment]
  449. .filter((item) => !!item)
  450. .map((item) => item.$refs.form || item);
  451. },
  452. changeActive(val) {
  453. if (this.$listeners.changeActive) {
  454. this.$listeners.changeActive(val)
  455. }
  456. },
  457. async submit() {
  458. const forms = this.getForms();
  459. const valided = [];
  460. for (const form of forms) {
  461. form.validate((valid) => {
  462. if (valid) {
  463. valided.push(form);
  464. }
  465. });
  466. }
  467. if (this.eclass.length < 1) {
  468. return this.$message.error('请至少选择一条加课信息')
  469. }
  470. if (valided.length === forms.length) {
  471. const { leixing, ...rest } = {
  472. ...this.form,
  473. ...this.other,
  474. paymentPattern: this.payment.paymentPattern,
  475. musicGroupPaymentDateRangeList: [...this.cycles.map(item => {
  476. const { paymentDate, paymentValid, ...other } = item
  477. return {
  478. ...other,
  479. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  480. ...getTimes(paymentValid, [
  481. "paymentValidStartDate",
  482. "paymentValidEndDate",
  483. ]),
  484. }
  485. })],
  486. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  487. };
  488. if (this.$refs.cycle) {
  489. const { paymentDate, paymentValid, ...other } = this.cycle
  490. rest.musicGroupPaymentDateRangeList = [{
  491. ...other,
  492. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  493. ...getTimes(paymentValid, [
  494. "paymentValidStartDate",
  495. "paymentValidEndDate",
  496. ]),
  497. }]
  498. }
  499. const data = {
  500. ...rest,
  501. isGiveMusicNetwork: false,
  502. studentIds: this.studentIds,
  503. paymentType:
  504. paymentTypeFormat[
  505. this.paymentType == 0 ? this.paymentType : leixing
  506. ],
  507. musicGroupId: this.musicGroupId,
  508. };
  509. if (!this.rowDetail?.batchNo) {
  510. try {
  511. const res = await musicGroupPaymentCalenderAdd(data);
  512. this.$listeners.close();
  513. this.$listeners.submited(res.data);
  514. // 在这里
  515. if (this.$route.query.type == "teamDraft") {
  516. this.$router.push({
  517. query: merge(this.$route.query, { 'type': 'feeAudit' })
  518. });
  519. }
  520. } catch (error) { }
  521. } else {
  522. try {
  523. data.batchNo = this.rowDetail.batchNo
  524. // 缴费类型无法修改,按照之前覆盖
  525. data.paymentType = this.viewDetail.musicGroupPaymentCalenders[0]?.paymentType
  526. const res = await musicGroupPaymentCalenderDetailBatchUpdate(data);
  527. this.$listeners.close();
  528. this.$listeners.submited(res.data);
  529. if (this.$route.query.type == "teamDraft") {
  530. this.$router.push({
  531. query: merge(this.$route.query, { 'type': 'feeAudit' })
  532. });
  533. }
  534. } catch (error) { }
  535. }
  536. }
  537. },
  538. },
  539. };
  540. </script>
  541. <style lang="less" scoped>
  542. .dialog-footer {
  543. margin-top: 20px;
  544. display: block;
  545. text-align: right;
  546. }
  547. .alert {
  548. margin-bottom: 10px;
  549. }
  550. .collapse-title {
  551. display: flex;
  552. justify-content: space-between;
  553. align-items: center;
  554. width: 100%;
  555. .el-icon-circle-close {
  556. font-size: 16px;
  557. margin-right: 10px;
  558. }
  559. }
  560. /deep/ .el-collapse-item__wrap {
  561. padding-top: 20px;
  562. }
  563. </style>