user-pay-form.vue 20 KB

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