create-user-pay.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. <paymentCycle
  77. ref="cycle"
  78. :isUserType="true"
  79. :form.sync="cycle"
  80. :isCommon="false"
  81. :isDisabled="true"
  82. />
  83. <div slot="footer" class="dialog-footer">
  84. <el-button @click="$listeners.close">取 消</el-button>
  85. <el-button type="primary" @click="submit">确认</el-button>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import paymentCycle from "../../../resetTeaming/modals/payment-cycle";
  91. import extraClass from "../../../resetTeaming/modals/extra-class";
  92. import { musicGroupPaymentCalenderAdd } from '../../../resetTeaming/api'
  93. import { queryRemainCourseTypeDuration } from '../../api'
  94. import { courseType } from '@/constant'
  95. import { getTimes, objectToOptions } from "@/utils";
  96. export default {
  97. props: ["snapList", "highList", "mixList", "signList", 'createdUserId', 'organizationCourseUnitPriceSettings', 'musicGroupId', 'baseInfo'],
  98. components: {
  99. paymentCycle,
  100. extraClass
  101. },
  102. data() {
  103. return {
  104. courseTypeOptions: courseType,
  105. ids: '',
  106. form: {
  107. signClass: '',
  108. mixClass: '',
  109. highClass: '',
  110. snapClass: '',
  111. },
  112. cycle: {},
  113. eclass: [],
  114. organizationCourseUnitPriceSettingsByType: {},
  115. }
  116. },
  117. watch: {
  118. 'form.signClass'() {
  119. this.classChange()
  120. },
  121. 'form.mixClass'() {
  122. this.classChange()
  123. },
  124. 'form.highClass'() {
  125. this.classChange()
  126. },
  127. 'form.snapClass'() {
  128. this.classChange()
  129. },
  130. baseInfo() {
  131. this.formatCourse()
  132. }
  133. },
  134. mounted() {
  135. this.formatCourse()
  136. },
  137. methods: {
  138. addExtraClass() {
  139. this.eclass.push({});
  140. },
  141. priceChange (item, index) {
  142. const _ = [...this.eclass]
  143. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  144. const price = Math.ceil((item.courseTotalMinuties || 1) * (active.unitPrice || 1))
  145. item.courseCurrentPrice = price
  146. item.courseOriginalPrice = price
  147. _[index] = item
  148. this.eclass = [..._]
  149. this.syncAllMoney()
  150. },
  151. syncAllMoney() {
  152. let money = 0;
  153. for (const item of this.eclass) {
  154. money += item.courseCurrentPrice;
  155. }
  156. if (!money) {
  157. this.$set(this.cycle, "paymentAmount", undefined);
  158. } else {
  159. this.$set(this.cycle, "paymentAmount", money);
  160. }
  161. return money;
  162. },
  163. removeExtraClass(index) {
  164. this.eclass[index] = null;
  165. this.eclass = this.eclass.filter((item) => !!item);
  166. },
  167. formatCourse() {
  168. const organId = this.baseInfo?.organId
  169. const chargeTypeId = this.baseInfo?.chargeTypeId
  170. const _ = {}
  171. const list = (this.organizationCourseUnitPriceSettings || [])
  172. .filter(item => organId && organId == item.organId && chargeTypeId && chargeTypeId == item.chargeTypeId)
  173. for (const item of list) {
  174. _[item.courseType] = item
  175. }
  176. console.log(_)
  177. this.organizationCourseUnitPriceSettingsByType = _
  178. return _
  179. },
  180. async classChange() {
  181. try {
  182. const ids = [this.form.signClass, this.form.mixClass, this.form.highClass, ...this.form.snapClass].filter(item => !!item).join(',')
  183. if (ids) {
  184. const res = await queryRemainCourseTypeDuration({
  185. classGroupIdList: ids
  186. })
  187. this.ids = ids
  188. const _ = res.data.map(item => {
  189. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  190. const money = Math.ceil((active.unitPrice || 1) * (item.remainMinutes || 1))
  191. return {
  192. courseType: item.courseType,
  193. courseTotalMinuties: item.remainMinutes,
  194. courseOriginalPrice: money,
  195. courseCurrentPrice: money,
  196. }
  197. })
  198. this.eclass = [..._]
  199. this.syncAllMoney()
  200. }
  201. } catch (error) {
  202. console.log(error)
  203. }
  204. },
  205. getForms() {
  206. const { $refs: refs } = this;
  207. return [refs.eclass, refs.cycle]
  208. .filter((item) => !!item)
  209. .map((item) => item.$refs.form);
  210. },
  211. async submit() {
  212. const forms = this.getForms();
  213. const valided = [];
  214. for (const form of forms) {
  215. form.validate((valid) => {
  216. if (valid) {
  217. valided.push(form);
  218. }
  219. });
  220. }
  221. if (forms.length === valided.length) {
  222. const { paymentDate, paymentValid, ...rest} = this.cycle
  223. const data = {
  224. attribute1: this.ids,
  225. ...rest,
  226. musicGroupId: this.musicGroupId,
  227. paymentType: 'ADD_STUDENT',
  228. studentIds: this.createdUserId,
  229. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  230. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  231. ...getTimes(paymentValid, [
  232. "paymentValidStartDate",
  233. "paymentValidEndDate",
  234. ]),
  235. }
  236. try {
  237. await musicGroupPaymentCalenderAdd(data)
  238. this.$message.success('提交成功')
  239. this.$listeners.submited()
  240. this.$listeners.close()
  241. } catch (error) {
  242. console.log(error)
  243. }
  244. }
  245. }
  246. },
  247. };
  248. </script>
  249. <style lang="less" scoped>
  250. .dialog-footer {
  251. margin-top: 20px;
  252. display: block;
  253. text-align: right;
  254. }
  255. .alert {
  256. margin-bottom: 10px;
  257. }
  258. </style>