create-user-pay.vue 10 KB

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