create-user-pay.vue 12 KB

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