create-user-pay.vue 12 KB

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