branchActiveOperation.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class='m-container'>
  3. <h2>
  4. <el-page-header @back="onCancel"
  5. :content="(pageType == 'create' ? '添加' : '修改') + '分部活动'"></el-page-header>
  6. </h2>
  7. <div class="m-core">
  8. <el-form :model="result"
  9. :rules="rules"
  10. ref="form"
  11. label-width="120px">
  12. <el-form-item label="活动名称"
  13. prop="name"
  14. style="width: 500px">
  15. <el-input v-model.trim="result.name"></el-input>
  16. </el-form-item>
  17. <el-form-item prop="rewardMode"
  18. label="活动类型"
  19. style="width: 500px">
  20. <el-radio-group v-model.trim="result.rewardMode">
  21. <el-radio label="STAIR">阶梯奖励</el-radio>
  22. <el-radio label="PER">累计奖励</el-radio>
  23. </el-radio-group>
  24. </el-form-item>
  25. <el-form-item class="moreRule"
  26. style="margin-bottom: 0;">
  27. <span class="min">最小值</span>
  28. <span class="min">最大值</span>
  29. <span class="max">奖励金额</span>
  30. </el-form-item>
  31. <div class="moreRule">
  32. <div class="moreRuleIn"
  33. v-for="(domain, index) in result.domains"
  34. :key="domain.key">
  35. <el-form-item :label="'梯度' + (index + 1)">
  36. <el-input type="number"
  37. v-number
  38. :disabled="domain.disabled"
  39. @mousewheel.native.prevent
  40. v-model.trim="domain.min"></el-input>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-input type="number"
  44. @mousewheel.native.prevent
  45. v-number
  46. :disabled="domain.disabled"
  47. v-model.trim="domain.max"></el-input>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-input style="width: auto;"
  51. type="number"
  52. @mousewheel.native.prevent
  53. :disabled="domain.disabled"
  54. v-model.trim="domain.money"></el-input>
  55. <el-button v-if="index != 0 && !domain.disabled"
  56. @click.prevent="removeDomain(result, domain)">删除</el-button>
  57. </el-form-item>
  58. </div>
  59. <div class="el-form-item__error"
  60. v-if="result.errorText">{{ result.errorText }}</div>
  61. </div>
  62. <el-form-item class="add">
  63. <el-button icon="el-icon-plus"
  64. @click="addDomain(result)">新增梯度</el-button>
  65. </el-form-item>
  66. <el-form-item prop="vipGroupCategoryIdList"
  67. label="课程类型"
  68. style="width: 500px">
  69. <el-select style="width: 100% !important;"
  70. v-model.trim="result.vipGroupCategoryIdList"
  71. filterable
  72. clearable
  73. multiple
  74. placeholder="请选择">
  75. <el-option v-for="item in selects.vipGroupCategory"
  76. :key="item.id"
  77. :label="item.name"
  78. :value="item.id.toString()"> </el-option>
  79. </el-select>
  80. </el-form-item>
  81. <el-form-item prop="organId"
  82. label="所属分部"
  83. style="width: 500px">
  84. <el-select style="width: 100% !important;"
  85. filterable
  86. clearable
  87. @change="onSubjectChange('search')"
  88. v-model.trim="result.organId"
  89. placeholder="请选择">
  90. <el-option v-for="item in selects.branchs"
  91. :key="item.id"
  92. :label="item.name"
  93. :value="item.id.toString()"> </el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-form-item prop="subjectIds"
  97. label="所属声部"
  98. style="width: 500px">
  99. <el-select style="width: 100% !important;"
  100. filterable
  101. clearable
  102. multiple
  103. @change="onSubjectChange('search')"
  104. v-model.trim="result.subjectIds"
  105. placeholder="请选择">
  106. <el-option v-for="(item, i) in selects.subjects"
  107. :key="i"
  108. :label="item.name"
  109. :value="item.id.toString()"></el-option>
  110. </el-select>
  111. </el-form-item>
  112. <el-form-item prop="teacherId"
  113. label="老师"
  114. style="width: 500px">
  115. <el-select style="width: 80% !important;"
  116. v-model.trim="result.teacherId"
  117. filterable
  118. clearable
  119. multiple
  120. placeholder="请选择">
  121. <el-option v-for="(item, index) in teacherList"
  122. :key="index"
  123. :label="item.label"
  124. :value="item.value.toString()"> </el-option>
  125. </el-select>
  126. <el-button @click="onCheckAll">全选</el-button>
  127. </el-form-item>
  128. <el-form-item>
  129. <el-button @click="resetForm">重置</el-button>
  130. <el-button type="primary"
  131. @click="onSubmit('form')">立即{{ pageType == "create" ? '创建' : '修改' }}</el-button>
  132. </el-form-item>
  133. </el-form>
  134. </div>
  135. </div>
  136. </template>
  137. <script>
  138. import { getEmployeeOrgan, getSoundTree } from '@/api/buildTeam'
  139. import { courseScheduleRewardsQuery, getUserRole, courseScheduleRewardsAdd, courseScheduleRewardsUpdate, findTeacherByOrganId } from '@/api/systemManage'
  140. import { vipGroupCategory } from "@/api/vipSeting"
  141. export default {
  142. name: 'branchActiveOperation',
  143. data () {
  144. return {
  145. organId: null,
  146. pageType: this.$route.query.type,
  147. id: this.$route.query.id,
  148. teacherList: [], // 老师列表
  149. result: {
  150. name: null,
  151. rewardMode: null,
  152. vipGroupCategoryIdList: null,
  153. organId: null,
  154. teacherId: null,
  155. subjectIds: null,
  156. courseScheduleType: 'VIP',
  157. domains: [{
  158. min: null,
  159. max: null,
  160. money: null,
  161. disabled: false,
  162. key: Date.now()
  163. }],
  164. errorText: null
  165. },
  166. rules: {
  167. name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
  168. rewardMode: [{ required: true, message: '请选择活动类型', trigger: 'change' }],
  169. vipGroupCategoryIdList: [{ type: 'array', required: true, message: '请选择课程类型', trigger: 'change' }],
  170. organId: [{ required: true, message: '请选择所属分部', trigger: 'change' }],
  171. subjectIds: [{ type: 'array', required: true, message: '请选择所属声部', trigger: 'change' }],
  172. teacherId: [{ type: 'array', required: true, message: '请选择老师', trigger: 'change' }]
  173. }
  174. }
  175. },
  176. mounted () {
  177. this.__init()
  178. },
  179. methods: {
  180. async __init () {
  181. this.$refs.form.resetFields()
  182. // 获取类型
  183. this.$store.dispatch('setVipGroupCategory')
  184. // 获取分部
  185. this.$store.dispatch('setBranchs')
  186. // 获取声部
  187. this.$store.dispatch('setSubjects')
  188. if (this.pageType == 'update') {
  189. let courseScheduleRewards = await courseScheduleRewardsQuery({ id: this.id })
  190. if (courseScheduleRewards.code == 200) {
  191. let data = courseScheduleRewards.data
  192. this.$nextTick(() => {
  193. this.result.organId = data.organId
  194. this.result.subjectIds = data.subjectIds ? data.subjectIds.split(',') : data.subjectIds
  195. this.onSubjectChange('update')
  196. this.result = {
  197. id: data.id,
  198. name: data.name,
  199. rewardMode: data.rewardMode,
  200. organId: data.organId,
  201. subjectIds: data.subjectIds ? data.subjectIds.split(',') : data.subjectIds,
  202. vipGroupCategoryIdList: data.vipGroupCategoryIdList ? data.vipGroupCategoryIdList.split(',') : data.vipGroupCategoryIdList,
  203. teacherId: data.teacherId ? data.teacherId.split(',') : data.teacherId,
  204. courseScheduleType: data.courseScheduleType,
  205. domains: data.rewardsRulesJson ?
  206. JSON.parse(data.rewardsRulesJson) : [{
  207. min: null,
  208. max: null,
  209. money: null,
  210. disabled: false,
  211. key: Date.now()
  212. }],
  213. errorText: null
  214. }
  215. })
  216. }
  217. } else {
  218. this.resetForm()
  219. }
  220. },
  221. async onSubjectChange (type) {
  222. let organId = this.result.organId
  223. let subject = this.result.subjectIds
  224. // 判断是否有分部和声部
  225. if (subject.length <= 0 || !organId || organId == '') {
  226. this.teacherList = []
  227. this.result.teacherId = []
  228. return
  229. }
  230. let subjectIds = Object.assign([], subject).join(',')
  231. await findTeacherByOrganId({ organId: organId, subjectIds: subjectIds, jobNature: 'FULL_TIME' }).then(res => {
  232. if (res.code == 200) {
  233. if (type != 'update') {
  234. this.teacherList = []
  235. this.result.teacherId = []
  236. }
  237. res.data.forEach(item => {
  238. this.teacherList.push({
  239. label: item.realName,
  240. value: item.id
  241. })
  242. })
  243. }
  244. })
  245. },
  246. onCheckAll () { // 全选老师
  247. if (this.teacherList.length <= 0) {
  248. return
  249. }
  250. this.result.teacherId = []
  251. this.teacherList.forEach(item => {
  252. this.result.teacherId.push(item.value.toString())
  253. })
  254. },
  255. onSubmit (formName) {
  256. this.$refs[formName].validate((valid) => {
  257. let result = JSON.parse(JSON.stringify(this.result))
  258. this.addDomain(result, true)
  259. if (valid && !result.errorText) {
  260. // 如果奖励金额为空时,默认为0
  261. result.domains.forEach(item => {
  262. if (!item.money) {
  263. item.money = 0
  264. }
  265. })
  266. let params = {
  267. organId: result.organId,
  268. vipGroupCategoryIdList: result.vipGroupCategoryIdList.join(','),
  269. teacherId: result.teacherId.join(','),
  270. courseScheduleType: result.courseScheduleType,
  271. rewardMode: result.rewardMode,
  272. subjectIds: result.subjectIds.join(','),
  273. rewardsRulesJson: JSON.stringify(result.domains),
  274. name: result.name
  275. }
  276. if (this.pageType == 'update') {
  277. params.id = result.id
  278. courseScheduleRewardsUpdate(params).then(res => {
  279. this.messageTips('修改', res)
  280. })
  281. } else if (this.pageType == 'create') {
  282. // return false
  283. courseScheduleRewardsAdd(params).then(res => {
  284. this.messageTips('添加', res)
  285. })
  286. }
  287. } else {
  288. return false;
  289. }
  290. })
  291. },
  292. messageTips (title, res) {
  293. if (res.code == 200) {
  294. this.$message.success('修改成功')
  295. this.$router.push({ path: '/vipClassSet/branchActive', query: { rules: this.pageInfo, searchForm: this.searchForm } })
  296. } else {
  297. this.$message.error(res.msg)
  298. }
  299. },
  300. onCancel () {
  301. this.$router.push({ path: '/vipClassSet/branchActive', query: { rules: this.pageInfo, searchForm: this.searchForm } })
  302. },
  303. resetForm () {
  304. this.teacherList = []
  305. this.result = {
  306. name: null,
  307. rewardMode: null,
  308. organId: null,
  309. subjectIds: [],
  310. teacherId: [],
  311. courseScheduleType: 'VIP',
  312. domains: [{
  313. min: null,
  314. max: null,
  315. money: null,
  316. disabled: false,
  317. key: Date.now()
  318. }],
  319. errorText: null
  320. }
  321. this.$refs.form.resetFields()
  322. },
  323. removeDomain (form, item) {
  324. var index = form.domains.indexOf(item)
  325. if (index !== -1) {
  326. form.domains.splice(index, 1)
  327. // 取消最后一个数据的禁用状态
  328. form.domains[form.domains.length - 1].disabled = false
  329. form.errorText = null
  330. }
  331. },
  332. addDomain (form, checked) {
  333. // debugger
  334. let domains = form.domains,
  335. singleLength = domains.length,
  336. lastDate = domains[singleLength - 1] // 获取倒数一个对象
  337. if (!lastDate.min) {
  338. form.errorText = '最小值不能为空'
  339. return
  340. }
  341. if (singleLength <= 1 && parseInt(lastDate.min) <= 0) {
  342. form.errorText = '最小值不能小于0'
  343. return
  344. } else if (singleLength > 1 && parseInt(lastDate.min) <= parseInt(domains[singleLength - 2].max)) {
  345. form.errorText = '最小值不能小于或等于上一个梯度的最大值'
  346. return
  347. }
  348. if (!parseInt(lastDate.max)) {
  349. form.errorText = '最大值不能为空'
  350. return
  351. } else if (parseInt(lastDate.max) <= parseInt(lastDate.min)) {
  352. form.errorText = '最大值应大于该梯度的最小值'
  353. return
  354. }
  355. form.errorText = null
  356. if (!checked) {
  357. lastDate.disabled = true
  358. domains.push({
  359. min: null,
  360. max: null,
  361. disabled: false,
  362. key: Date.now()
  363. })
  364. }
  365. }
  366. }
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. .el-button--primary {
  371. background: #14928a;
  372. border-color: #14928a;
  373. color: #fff;
  374. &:hover,
  375. &:active,
  376. &:focus {
  377. background: #14928a;
  378. border-color: #14928a;
  379. color: #fff;
  380. }
  381. }
  382. .el-row {
  383. margin-top: 40px;
  384. }
  385. .el-col {
  386. display: flex;
  387. align-items: center;
  388. margin-bottom: 20px;
  389. justify-content: flex-end;
  390. margin-right: 50%;
  391. }
  392. .el-input-group {
  393. width: 200px;
  394. margin: 0 20px;
  395. }
  396. /deep/.el-tree-node__content {
  397. height: 40px !important;
  398. }
  399. .moreRule {
  400. background: #f0f0f0;
  401. position: relative;
  402. .el-form-item__error {
  403. color: #f56c6c;
  404. font-size: 12px;
  405. line-height: 1;
  406. position: absolute;
  407. left: 120px;
  408. top: 100%;
  409. margin-top: -21px;
  410. }
  411. }
  412. .add {
  413. margin-bottom: 22px;
  414. background: #f0f0f0;
  415. padding-bottom: 22px;
  416. }
  417. .moreRuleIn {
  418. .el-form-item {
  419. display: inline-block;
  420. &:first-child {
  421. /deep/.el-form-item__content {
  422. margin-left: 120px !important;
  423. }
  424. }
  425. /deep/.el-form-item__content {
  426. margin-left: 0 !important;
  427. }
  428. }
  429. }
  430. .min,
  431. .max {
  432. display: inline-block;
  433. width: 180px;
  434. text-align: center;
  435. margin-right: 10px;
  436. }
  437. </style>