create-user-pay.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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"
  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"
  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"
  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"
  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 paymentCycle from "../../../resetTeaming/modals/payment-cycle";
  149. import otherform from "../../../resetTeaming/modals/other";
  150. import extraClass from "../../../resetTeaming/modals/extra-class";
  151. import { musicGroupPaymentCalenderAdd } from '../../../resetTeaming/api'
  152. import { queryRemainCourseTypeDuration } from '../../api'
  153. import { courseType } from '@/constant'
  154. import { getTimes, objectToOptions } from "@/utils";
  155. import { paymentPatternType } from '@/constant'
  156. export default {
  157. props: ["snapList", "highList", "mixList", "signList", 'createdUserId', 'organizationCourseUnitPriceSettings', 'musicGroupId', 'baseInfo'],
  158. components: {
  159. paymentCycle,
  160. otherform,
  161. extraClass
  162. },
  163. data() {
  164. return {
  165. courseTypeOptions: courseType,
  166. ids: '',
  167. form: {
  168. signClass: '',
  169. mixClass: '',
  170. highClass: '',
  171. snapClass: '',
  172. },
  173. payment: {
  174. paymentPattern: null,
  175. },
  176. other: {},
  177. cycle: {},
  178. eclass: [],
  179. collapse: [0],
  180. cycles: [{}],
  181. organizationCourseUnitPriceSettingsByType: {},
  182. paymentPatternTypeOptions: objectToOptions(paymentPatternType),
  183. }
  184. },
  185. watch: {
  186. 'form.signClass'() {
  187. this.classChange()
  188. },
  189. 'form.mixClass'() {
  190. this.classChange()
  191. },
  192. 'form.highClass'() {
  193. this.classChange()
  194. },
  195. 'form.snapClass'() {
  196. this.classChange()
  197. },
  198. 'payment.paymentPattern'() {
  199. this.syncAllMoney()
  200. },
  201. baseInfo() {
  202. this.formatCourse()
  203. }
  204. },
  205. mounted() {
  206. this.formatCourse()
  207. },
  208. methods: {
  209. addExtraClass() {
  210. this.eclass.push({});
  211. },
  212. priceChange (item, index) {
  213. const _ = [...this.eclass]
  214. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  215. const price = Math.ceil((item.courseTotalMinuties || 1) * (active.unitPrice || 1))
  216. item.courseCurrentPrice = price
  217. item.courseOriginalPrice = price
  218. _[index] = item
  219. this.eclass = [..._]
  220. this.syncAllMoney()
  221. },
  222. syncAllMoney() {
  223. let money = 0;
  224. let first = 0
  225. let other = 0
  226. for (const item of this.eclass) {
  227. money += item.courseCurrentPrice;
  228. if (this.cycles && this.cycles.length) {
  229. if (item.isStudentOptional) {
  230. first += item.courseCurrentPrice
  231. } else {
  232. const floorMoney = Math.floor(item.courseCurrentPrice / this.cycles.length)
  233. const remainder = item.courseCurrentPrice % this.cycles.length
  234. first += floorMoney + remainder
  235. other += floorMoney
  236. }
  237. }
  238. }
  239. if (this.cycles.length) {
  240. const floorMoney = Math.floor(money / this.cycles.length)
  241. const remainder = money % this.cycles.length
  242. this.cycles = this.cycles.map((item, index) => {
  243. return {
  244. ...item,
  245. paymentAmount: (index === 0 ? first : other)
  246. }
  247. })
  248. }
  249. if (this.$refs.cycle) {
  250. this.$set(this.cycle, 'paymentAmount', money)
  251. }
  252. return money;
  253. },
  254. removeExtraClass(index) {
  255. this.eclass[index] = null;
  256. this.eclass = this.eclass.filter((item) => !!item);
  257. },
  258. formatCourse() {
  259. const organId = this.baseInfo?.organId
  260. const chargeTypeId = this.baseInfo?.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. getAllIds() {
  271. return [this.form.signClass, this.form.mixClass, this.form.highClass, ...this.form.snapClass].filter(item => !!item)
  272. },
  273. async classChange() {
  274. try {
  275. const ids = this.getAllIds().join(',')
  276. if (ids) {
  277. const res = await queryRemainCourseTypeDuration({
  278. classGroupIdList: ids
  279. })
  280. this.ids = ids
  281. const _ = res.data.map(item => {
  282. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  283. const money = Math.ceil((active.unitPrice || 1) * (item.remainMinutes || 1))
  284. return {
  285. courseType: item.courseType,
  286. courseTotalMinuties: item.remainMinutes,
  287. courseOriginalPrice: money,
  288. courseCurrentPrice: money,
  289. }
  290. })
  291. this.eclass = [..._]
  292. this.syncAllMoney()
  293. }
  294. } catch (error) {
  295. console.log(error)
  296. }
  297. },
  298. getForms() {
  299. const { $refs: refs } = this;
  300. return [refs.eclass, refs.cycle, refs.payment, refs.other, ...(refs.cycles || [])]
  301. .filter((item) => !!item)
  302. .map((item) => item.$refs.form || item);
  303. },
  304. addCycle () {
  305. this.cycles.push({});
  306. this.collapse.push(this.cycles.length);
  307. this.syncAllMoney()
  308. },
  309. removeCycle (index) {
  310. this.cycles[index] = null;
  311. this.cycles = this.cycles.filter((item) => !!item);
  312. if (this.collapse.includes(index)) {
  313. this.collapse.splice(index, 1);
  314. this.collapse = this.collapse.map((item, _index) => _index - 1 >= index ? item -- : item)
  315. }
  316. this.syncAllMoney()
  317. },
  318. collapseChange (val) {
  319. this.collapse = val;
  320. },
  321. async submit() {
  322. const forms = this.getForms();
  323. const valided = [];
  324. for (const form of forms) {
  325. form.validate((valid) => {
  326. if (valid) {
  327. valided.push(form);
  328. }
  329. });
  330. }
  331. if (!this.getAllIds().length) {
  332. this.$message.error('请至少选择一个班级')
  333. return
  334. }
  335. if (forms.length === valided.length) {
  336. const cyclelist = this.payment.paymentPattern == 0 ? this.cycles : [this.cycle]
  337. const data = {
  338. attribute1: this.ids,
  339. musicGroupPaymentDateRangeList: cyclelist.map(item => {
  340. const { paymentDate, paymentValid, ...other } = item
  341. return {
  342. ...other,
  343. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  344. ...getTimes(paymentValid, [
  345. "paymentValidStartDate",
  346. "paymentValidEndDate",
  347. ]),
  348. paymentPattern: this.payment.paymentPattern,
  349. }
  350. }),
  351. paymentPattern: this.payment.paymentPattern,
  352. musicGroupId: this.musicGroupId,
  353. paymentType: 'ADD_STUDENT',
  354. payUserType: 'STUDENT',
  355. studentIds: this.createdUserId,
  356. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  357. ...this.other,
  358. }
  359. try {
  360. await musicGroupPaymentCalenderAdd(data)
  361. this.$message.success('提交成功')
  362. this.$listeners.submited()
  363. this.$listeners.close()
  364. } catch (error) {
  365. console.log(error)
  366. }
  367. }
  368. }
  369. },
  370. };
  371. </script>
  372. <style lang="less" scoped>
  373. .dialog-footer {
  374. margin-top: 20px;
  375. display: block;
  376. text-align: right;
  377. }
  378. .alert {
  379. margin-bottom: 10px;
  380. }
  381. .collapse-title {
  382. display: flex;
  383. justify-content: space-between;
  384. align-items: center;
  385. width: 100%;
  386. .el-icon-circle-close {
  387. font-size: 16px;
  388. margin-right: 10px;
  389. }
  390. }
  391. /deep/ .el-collapse-item__wrap {
  392. padding-top: 20px;
  393. }
  394. </style>