create-user-pay.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div>
  3. <el-alert title="班级信息" :closable="false" class="alert" type="info">
  4. </el-alert>
  5. <el-form :model="form" label-width="100px">
  6. <el-row>
  7. <el-col :span="12">
  8. <el-form-item label="声部班">
  9. <el-select v-model.trim="form.signClass" filterable clearable>
  10. <el-option
  11. v-for="(item, index) in signList.filter(item => item.lockFlag != 1)"
  12. :key="index"
  13. :value="item.id"
  14. :label="item.name"
  15. ></el-option>
  16. </el-select>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="12">
  20. <el-form-item label="合奏班">
  21. <el-select v-model.trim="form.mixClass" filterable clearable>
  22. <el-option
  23. v-for="(item, index) in mixList.filter(item => item.lockFlag != 1)"
  24. :key="index"
  25. :value="item.id"
  26. :label="item.name"
  27. ></el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="12">
  32. <el-form-item label="基础技能班">
  33. <el-select v-model.trim="form.highClass" filterable clearable>
  34. <el-option
  35. v-for="(item, index) in highList.filter(item => item.lockFlag != 1)"
  36. :key="index"
  37. :value="item.id"
  38. :label="item.name"
  39. ></el-option>
  40. </el-select>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="12">
  44. <el-form-item label="临时班">
  45. <select-all
  46. v-model.trim="form.snapClass"
  47. filterable
  48. clearable
  49. multiple
  50. >
  51. <el-option
  52. v-for="(item, index) in snapList.filter(item => item.lockFlag != 1)"
  53. :key="index"
  54. :value="item.id"
  55. :label="item.name"
  56. ></el-option>
  57. </select-all>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="12">
  61. <el-form-item label="线上基础技能班">
  62. <select-all
  63. v-model.trim="form.highonline"
  64. filterable
  65. clearable
  66. multiple
  67. >
  68. <el-option
  69. v-for="(item, index) in highonlineList.filter(item => item.lockFlag != 1)"
  70. :key="index"
  71. :value="item.id"
  72. :label="item.name"
  73. ></el-option>
  74. </select-all>
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. <!-- highonlineList -->
  79. </el-form>
  80. <el-alert title="课程信息设置" :closable="false" class="alert" type="info">
  81. </el-alert>
  82. <extraClass
  83. :form="eclass"
  84. ref="eclass"
  85. :isUserType="true"
  86. :isCommon="false"
  87. :isDisabled="true"
  88. :courseUnitPriceSettingsByType="organizationCourseUnitPriceSettingsByType"
  89. @priceChange="priceChange"
  90. @moneyChange="syncAllMoney"
  91. />
  92. <el-alert title="缴费设置" :closable="false" class="alert" type="info">
  93. </el-alert>
  94. <el-form ref="payment" :model="payment">
  95. <el-form-item
  96. label="缴费方式"
  97. prop="paymentPattern"
  98. label-width="160px"
  99. :rules="[{required: true, message: '请选择缴费方式', trigger: 'change'}]"
  100. >
  101. <el-select style="width: 100%!important;" v-model="payment.paymentPattern" placeholder="请选择缴费方式">
  102. <el-option
  103. v-for="item in paymentPatternTypeOptions"
  104. :key="item.value"
  105. :label="item.label"
  106. :value="item.value">
  107. </el-option>
  108. </el-select>
  109. </el-form-item>
  110. </el-form>
  111. <template v-if="payment.paymentPattern == 0">
  112. <el-collapse :value="collapse" @change="collapseChange" >
  113. <el-collapse-item
  114. v-for="(item, index) in cycles"
  115. :key="index"
  116. :name="index"
  117. >
  118. <template slot="title">
  119. <div class="collapse-title">
  120. <span>缴费周期 {{index + 1}}</span>
  121. <i v-if="cycles.length > 1" class="el-icon-circle-close" @click.stop="removeCycle(index)"></i>
  122. </div>
  123. </template>
  124. <paymentCycle
  125. ref="cycles"
  126. :form="item"
  127. :hidePaymentPattern="true"
  128. :isUserType="true"
  129. :isCommon="false"
  130. :isDisabled="true"
  131. />
  132. </el-collapse-item>
  133. </el-collapse>
  134. <el-button
  135. icon="el-icon-circle-plus-outline"
  136. plain
  137. type="info"
  138. size="small"
  139. style="width: 100%;margin: 20px 0;"
  140. @click="addCycle"
  141. >新增缴费周期</el-button>
  142. </template>
  143. <paymentCycle
  144. v-else
  145. ref="cycle"
  146. :isUserType="true"
  147. :hidePaymentPattern="true"
  148. :form.sync="cycle"
  149. :isCommon="false"
  150. :isDisabled="true"
  151. />
  152. <el-alert title="其它"
  153. :closable="false"
  154. class="alert"
  155. type="info">
  156. </el-alert>
  157. <otherform :form="other"
  158. ref="other" />
  159. <div slot="footer" class="dialog-footer">
  160. <el-button @click="$listeners.close">取 消</el-button>
  161. <el-button type="primary" @click="submit">确认</el-button>
  162. </div>
  163. </div>
  164. </template>
  165. <script>
  166. import numeral from 'numeral'
  167. import paymentCycle from "../../../resetTeaming/modals/payment-cycle";
  168. import otherform from "../../../resetTeaming/modals/other";
  169. import extraClass from "../../../resetTeaming/modals/extra-class";
  170. import { musicGroupPaymentCalenderAdd } from '../../../resetTeaming/api'
  171. import { queryRemainCourseTypeDuration } from '../../api'
  172. import { courseType } from '@/constant'
  173. import { getTimes, objectToOptions } from "@/utils";
  174. import { paymentPatternType } from '@/constant'
  175. export default {
  176. props: ["snapList", "highList", "mixList", "signList", 'highonlineList','createdUserId', 'organizationCourseUnitPriceSettings', 'musicGroupId', 'baseInfo'],
  177. components: {
  178. paymentCycle,
  179. otherform,
  180. extraClass
  181. },
  182. data() {
  183. return {
  184. courseTypeOptions: courseType,
  185. ids: '',
  186. form: {
  187. signClass: '',
  188. mixClass: '',
  189. highClass: '',
  190. snapClass: '',
  191. highonline:''
  192. },
  193. payment: {
  194. paymentPattern: null,
  195. },
  196. other: {},
  197. cycle: {},
  198. eclass: [],
  199. collapse: [0],
  200. cycles: [{}],
  201. organizationCourseUnitPriceSettingsByType: {},
  202. paymentPatternTypeOptions: objectToOptions(paymentPatternType),
  203. }
  204. },
  205. watch: {
  206. 'form.signClass'() {
  207. this.classChange()
  208. },
  209. 'form.mixClass'() {
  210. this.classChange()
  211. },
  212. 'form.highClass'() {
  213. this.classChange()
  214. },
  215. 'form.snapClass'() {
  216. this.classChange()
  217. },
  218. 'form.highonline'(){
  219. this.classChange()
  220. },
  221. 'payment.paymentPattern'() {
  222. this.syncAllMoney()
  223. },
  224. baseInfo() {
  225. this.formatCourse()
  226. }
  227. },
  228. mounted() {
  229. this.formatCourse()
  230. },
  231. methods: {
  232. addExtraClass() {
  233. this.eclass.push({});
  234. },
  235. priceChange (item, index) {
  236. const _ = [...this.eclass]
  237. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  238. const price = Math.round(numeral(item.courseTotalMinuties || 1).multiply(active.unitPrice || 1).value())
  239. item.courseCurrentPrice = price
  240. item.courseOriginalPrice = price
  241. _[index] = item
  242. this.eclass = [..._]
  243. this.syncAllMoney()
  244. },
  245. syncAllMoney() {
  246. let money = 0;
  247. let first = 0
  248. let other = 0
  249. for (const item of this.eclass) {
  250. money += item.courseCurrentPrice;
  251. if (this.cycles && this.cycles.length) {
  252. if (item.isStudentOptional) {
  253. first += item.courseCurrentPrice
  254. } else {
  255. const floorMoney = Math.floor(item.courseCurrentPrice / this.cycles.length)
  256. const remainder = item.courseCurrentPrice % this.cycles.length
  257. first += floorMoney + remainder
  258. other += floorMoney
  259. }
  260. }
  261. }
  262. if (this.cycles.length) {
  263. const floorMoney = Math.floor(money / this.cycles.length)
  264. const remainder = money % this.cycles.length
  265. this.cycles = this.cycles.map((item, index) => {
  266. return {
  267. ...item,
  268. paymentAmount: (index === 0 ? first : other)
  269. }
  270. })
  271. }
  272. if (this.$refs.cycle) {
  273. this.$set(this.cycle, 'paymentAmount', money)
  274. }
  275. return money;
  276. },
  277. removeExtraClass(index) {
  278. this.eclass[index] = null;
  279. this.eclass = this.eclass.filter((item) => !!item);
  280. },
  281. formatCourse() {
  282. const organId = this.baseInfo?.organId
  283. const chargeTypeId = this.baseInfo?.chargeTypeId
  284. const _ = {}
  285. const list = (this.organizationCourseUnitPriceSettings || [])
  286. .filter(item => organId && organId == item.organId && chargeTypeId && chargeTypeId == item.chargeTypeId)
  287. for (const item of list) {
  288. _[item.courseType] = item
  289. }
  290. this.organizationCourseUnitPriceSettingsByType = _
  291. return _
  292. },
  293. getAllIds() {
  294. return [this.form.signClass, this.form.mixClass, this.form.highClass, this.form.highonline,...this.form.snapClass].filter(item => !!item)
  295. },
  296. async classChange() {
  297. try {
  298. const ids = this.getAllIds().join(',')
  299. if (ids) {
  300. const res = await queryRemainCourseTypeDuration({
  301. classGroupIdList: ids
  302. })
  303. this.ids = ids
  304. const _ = res.data.map(item => {
  305. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  306. const money = Math.round(numeral(active.unitPrice || 1).multiply(item.remainMinutes || 1).value())
  307. return {
  308. courseType: item.courseType,
  309. courseTotalMinuties: item.remainMinutes,
  310. courseOriginalPrice: money,
  311. courseCurrentPrice: money,
  312. }
  313. })
  314. this.eclass = [..._]
  315. this.syncAllMoney()
  316. }
  317. } catch (error) {
  318. console.log(error)
  319. }
  320. },
  321. getForms() {
  322. const { $refs: refs } = this;
  323. return [refs.eclass, refs.cycle, refs.payment, refs.other, ...(refs.cycles || [])]
  324. .filter((item) => !!item)
  325. .map((item) => item.$refs.form || item);
  326. },
  327. addCycle () {
  328. this.cycles.push({});
  329. this.collapse.push(this.cycles.length);
  330. this.syncAllMoney()
  331. },
  332. removeCycle (index) {
  333. this.cycles[index] = null;
  334. this.cycles = this.cycles.filter((item) => !!item);
  335. if (this.collapse.includes(index)) {
  336. this.collapse.splice(index, 1);
  337. this.collapse = this.collapse.map((item, _index) => _index - 1 >= index ? item -- : item)
  338. }
  339. this.syncAllMoney()
  340. },
  341. collapseChange (val) {
  342. this.collapse = val;
  343. },
  344. async submit() {
  345. const forms = this.getForms();
  346. const valided = [];
  347. for (const form of forms) {
  348. form.validate((valid) => {
  349. if (valid) {
  350. valided.push(form);
  351. }
  352. });
  353. }
  354. if (!this.getAllIds().length) {
  355. this.$message.error('请至少选择一个班级')
  356. return
  357. }
  358. if (forms.length === valided.length) {
  359. const cyclelist = this.payment.paymentPattern == 0 ? this.cycles : [this.cycle]
  360. const data = {
  361. attribute1: this.ids,
  362. musicGroupPaymentDateRangeList: cyclelist.map(item => {
  363. const { paymentDate, paymentValid, ...other } = item
  364. return {
  365. ...other,
  366. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  367. ...getTimes(paymentValid, [
  368. "paymentValidStartDate",
  369. "paymentValidEndDate",
  370. ]),
  371. paymentPattern: this.payment.paymentPattern,
  372. }
  373. }),
  374. paymentPattern: this.payment.paymentPattern,
  375. musicGroupId: this.musicGroupId,
  376. paymentType: 'ADD_STUDENT',
  377. payUserType: 'STUDENT',
  378. studentIds: this.createdUserId,
  379. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  380. ...this.other,
  381. }
  382. try {
  383. await musicGroupPaymentCalenderAdd(data)
  384. this.$message.success('提交成功')
  385. this.$listeners.submited()
  386. this.$listeners.close()
  387. } catch (error) {
  388. console.log(error)
  389. }
  390. }
  391. }
  392. },
  393. };
  394. </script>
  395. <style lang="less" scoped>
  396. .dialog-footer {
  397. margin-top: 20px;
  398. display: block;
  399. text-align: right;
  400. }
  401. .alert {
  402. margin-bottom: 10px;
  403. }
  404. .collapse-title {
  405. display: flex;
  406. justify-content: space-between;
  407. align-items: center;
  408. width: 100%;
  409. .el-icon-circle-close {
  410. font-size: 16px;
  411. margin-right: 10px;
  412. }
  413. }
  414. /deep/ .el-collapse-item__wrap {
  415. padding-top: 20px;
  416. }
  417. </style>