create-user-pay.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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-collapse :value="collapse" @change="collapseChange" >
  77. <el-collapse-item
  78. v-for="(item, index) in cycles"
  79. :key="index"
  80. :name="index"
  81. >
  82. <template slot="title">
  83. <div class="collapse-title">
  84. <span>缴费周期 {{index + 1}}</span>
  85. <i v-if="cycles.length > 1" class="el-icon-circle-close" @click.stop="removeCycle(index)"></i>
  86. </div>
  87. </template>
  88. <paymentCycle
  89. ref="cycles"
  90. :form="item"
  91. :isUserType="true"
  92. :isCommon="false"
  93. :isDisabled="true"
  94. />
  95. </el-collapse-item>
  96. </el-collapse>
  97. <el-button
  98. icon="el-icon-circle-plus-outline"
  99. plain
  100. type="info"
  101. size="small"
  102. style="width: 100%;margin: 20px 0;"
  103. @click="addCycle"
  104. >新增缴费周期</el-button>
  105. <!-- <paymentCycle
  106. ref="cycle"
  107. :isUserType="true"
  108. :form.sync="cycle"
  109. :isCommon="false"
  110. :isDisabled="true"
  111. /> -->
  112. <div slot="footer" class="dialog-footer">
  113. <el-button @click="$listeners.close">取 消</el-button>
  114. <el-button type="primary" @click="submit">确认</el-button>
  115. </div>
  116. </div>
  117. </template>
  118. <script>
  119. import paymentCycle from "../../../resetTeaming/modals/payment-cycle";
  120. import extraClass from "../../../resetTeaming/modals/extra-class";
  121. import { musicGroupPaymentCalenderAdd } from '../../../resetTeaming/api'
  122. import { queryRemainCourseTypeDuration } from '../../api'
  123. import { courseType } from '@/constant'
  124. import { getTimes, objectToOptions } from "@/utils";
  125. export default {
  126. props: ["snapList", "highList", "mixList", "signList", 'createdUserId', 'organizationCourseUnitPriceSettings', 'musicGroupId', 'baseInfo'],
  127. components: {
  128. paymentCycle,
  129. extraClass
  130. },
  131. data() {
  132. return {
  133. courseTypeOptions: courseType,
  134. ids: '',
  135. form: {
  136. signClass: '',
  137. mixClass: '',
  138. highClass: '',
  139. snapClass: '',
  140. },
  141. cycle: {},
  142. eclass: [],
  143. collapse: [0],
  144. cycles: [{}],
  145. organizationCourseUnitPriceSettingsByType: {},
  146. }
  147. },
  148. watch: {
  149. 'form.signClass'() {
  150. this.classChange()
  151. },
  152. 'form.mixClass'() {
  153. this.classChange()
  154. },
  155. 'form.highClass'() {
  156. this.classChange()
  157. },
  158. 'form.snapClass'() {
  159. this.classChange()
  160. },
  161. baseInfo() {
  162. this.formatCourse()
  163. }
  164. },
  165. mounted() {
  166. this.formatCourse()
  167. },
  168. methods: {
  169. addExtraClass() {
  170. this.eclass.push({});
  171. },
  172. priceChange (item, index) {
  173. const _ = [...this.eclass]
  174. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  175. const price = Math.ceil((item.courseTotalMinuties || 1) * (active.unitPrice || 1))
  176. item.courseCurrentPrice = price
  177. item.courseOriginalPrice = price
  178. _[index] = item
  179. this.eclass = [..._]
  180. this.syncAllMoney()
  181. },
  182. syncAllMoney() {
  183. let money = 0;
  184. for (const item of this.eclass) {
  185. money += item.courseCurrentPrice;
  186. }
  187. if (this.cycles.length) {
  188. const floorMoney = Math.floor(money / this.cycles.length)
  189. const remainder = money % this.cycles.length
  190. this.cycles = this.cycles.map((item, index) => {
  191. return {
  192. ...item,
  193. paymentAmount: (index === 0 ? floorMoney + remainder : floorMoney)
  194. }
  195. })
  196. }
  197. return money;
  198. },
  199. removeExtraClass(index) {
  200. this.eclass[index] = null;
  201. this.eclass = this.eclass.filter((item) => !!item);
  202. },
  203. formatCourse() {
  204. const organId = this.baseInfo?.organId
  205. const chargeTypeId = this.baseInfo?.chargeTypeId
  206. const _ = {}
  207. const list = (this.organizationCourseUnitPriceSettings || [])
  208. .filter(item => organId && organId == item.organId && chargeTypeId && chargeTypeId == item.chargeTypeId)
  209. for (const item of list) {
  210. _[item.courseType] = item
  211. }
  212. console.log(_)
  213. this.organizationCourseUnitPriceSettingsByType = _
  214. return _
  215. },
  216. async classChange() {
  217. try {
  218. const ids = [this.form.signClass, this.form.mixClass, this.form.highClass, ...this.form.snapClass].filter(item => !!item).join(',')
  219. if (ids) {
  220. const res = await queryRemainCourseTypeDuration({
  221. classGroupIdList: ids
  222. })
  223. this.ids = ids
  224. const _ = res.data.map(item => {
  225. const active = this.organizationCourseUnitPriceSettingsByType[item.courseType] || {}
  226. const money = Math.ceil((active.unitPrice || 1) * (item.remainMinutes || 1))
  227. return {
  228. courseType: item.courseType,
  229. courseTotalMinuties: item.remainMinutes,
  230. courseOriginalPrice: money,
  231. courseCurrentPrice: money,
  232. }
  233. })
  234. this.eclass = [..._]
  235. this.syncAllMoney()
  236. }
  237. } catch (error) {
  238. console.log(error)
  239. }
  240. },
  241. getForms() {
  242. const { $refs: refs } = this;
  243. return [refs.eclass, refs.cycle, ...refs.cycles]
  244. .filter((item) => !!item)
  245. .map((item) => item.$refs.form);
  246. },
  247. addCycle () {
  248. this.cycles.push({});
  249. this.collapse.push(this.collapse.length);
  250. this.syncAllMoney()
  251. },
  252. removeCycle (index) {
  253. this.cycles[index] = null;
  254. this.cycles = this.cycles.filter((item) => !!item);
  255. this.collapse.pop();
  256. this.syncAllMoney()
  257. },
  258. collapseChange (val) {
  259. this.collapse = val;
  260. },
  261. async submit() {
  262. const forms = this.getForms();
  263. const valided = [];
  264. for (const form of forms) {
  265. form.validate((valid) => {
  266. if (valid) {
  267. valided.push(form);
  268. }
  269. });
  270. }
  271. if (forms.length === valided.length) {
  272. const data = {
  273. attribute1: this.ids,
  274. cycles: [...this.cycles.map(item => {
  275. const { paymentDate, paymentValid, ...other } = item
  276. return {
  277. ...other,
  278. ...getTimes(paymentDate, ["startPaymentDate", "deadlinePaymentDate"]),
  279. ...getTimes(paymentValid, [
  280. "paymentValidStartDate",
  281. "paymentValidEndDate",
  282. ]),
  283. }
  284. })],
  285. musicGroupId: this.musicGroupId,
  286. paymentType: 'ADD_STUDENT',
  287. studentIds: this.createdUserId,
  288. musicGroupPaymentCalenderCourseSettingsList: this.eclass,
  289. }
  290. try {
  291. await musicGroupPaymentCalenderAdd(data)
  292. this.$message.success('提交成功')
  293. this.$listeners.submited()
  294. this.$listeners.close()
  295. } catch (error) {
  296. console.log(error)
  297. }
  298. }
  299. }
  300. },
  301. };
  302. </script>
  303. <style lang="less" scoped>
  304. .dialog-footer {
  305. margin-top: 20px;
  306. display: block;
  307. text-align: right;
  308. }
  309. .alert {
  310. margin-bottom: 10px;
  311. }
  312. .collapse-title {
  313. display: flex;
  314. justify-content: space-between;
  315. align-items: center;
  316. width: 100%;
  317. .el-icon-circle-close {
  318. font-size: 16px;
  319. margin-right: 10px;
  320. }
  321. }
  322. /deep/ .el-collapse-item__wrap {
  323. padding-top: 20px;
  324. }
  325. </style>