create-user-pay.vue 12 KB

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