user-pay-form.vue 11 KB

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