user-pay-form.vue 15 KB

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