branchActiveOperation.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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="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="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. :disabled="domain.disabled"
  38. v-model="domain.min"></el-input>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-input type="number"
  42. :disabled="domain.disabled"
  43. v-model="domain.max"></el-input>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-input style="width: auto;"
  47. type="number"
  48. :disabled="domain.disabled"
  49. v-model="domain.money"></el-input>
  50. <el-button v-if="index != 0 && !domain.disabled"
  51. @click.prevent="removeDomain(result, domain)">删除</el-button>
  52. </el-form-item>
  53. </div>
  54. <div class="el-form-item__error"
  55. v-if="result.errorText">{{ result.errorText }}</div>
  56. </div>
  57. <el-form-item class="add">
  58. <el-button icon="el-icon-plus"
  59. @click="addDomain(result)">新增梯度</el-button>
  60. </el-form-item>
  61. <el-form-item prop="organIdList"
  62. label="适用分部"
  63. style="width: 500px">
  64. <el-select style="width: 100% !important;"
  65. v-model="result.organIdList"
  66. multiple
  67. placeholder="请选择">
  68. <el-option v-for="item in branchList"
  69. :key="item.value"
  70. :label="item.label"
  71. :value="item.value"
  72. :disabled="item.disabled"> </el-option>
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item>
  76. <el-button @click="resetForm">重置</el-button>
  77. <el-button type="primary"
  78. @click="onSubmit('form')">立即{{ pageType == "create" ? '创建' : '修改' }}</el-button>
  79. </el-form-item>
  80. </el-form>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import store from '@/store'
  86. import { branchQueryPage, queryOrganIdList } from '@/api/specialSetting'
  87. import { courseScheduleRewardsQuery, getUserRole, courseScheduleRewardsAdd, courseScheduleRewardsUpdate } from '@/api/systemManage'
  88. export default {
  89. name: 'adminManager',
  90. data () {
  91. return {
  92. organId: store.getters.organ,
  93. pageType: this.$route.query.type,
  94. id: this.$route.query.id,
  95. branchList: [],
  96. useBranchId: [], // 使用的分部编号
  97. result: {
  98. name: null,
  99. rewardMode: null,
  100. organIdList: null,
  101. courseScheduleType: 'VIP',
  102. domains: [{
  103. min: null,
  104. max: null,
  105. money: null,
  106. disabled: false,
  107. key: Date.now()
  108. }],
  109. errorText: null
  110. },
  111. rules: {
  112. name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
  113. rewardMode: [{ required: true, message: '请选择活动类型', trigger: 'change' }],
  114. organIdList: [{ type: 'array', required: true, message: '请选择适用分部', trigger: 'change' }]
  115. }
  116. }
  117. },
  118. mounted () {
  119. this.__init()
  120. },
  121. methods: {
  122. async __init () {
  123. this.$refs.form.resetFields()
  124. // 获取已经配置过的分部编号
  125. let result = await queryOrganIdList()
  126. let branchList = await branchQueryPage({ delFlag: 0, rows: 9999 })
  127. if (result.code == 200) {
  128. this.useBranchId = result.data
  129. }
  130. if (branchList.code == 200) {
  131. branchList.data.rows.forEach(item => {
  132. let tempArr = {}
  133. if (this.useBranchId.indexOf(item.id) != -1) {
  134. tempArr = {
  135. label: item.name,
  136. value: item.id,
  137. disabled: true
  138. }
  139. } else {
  140. tempArr = {
  141. label: item.name,
  142. value: item.id
  143. }
  144. }
  145. this.branchList.push(tempArr)
  146. })
  147. }
  148. if (this.pageType == 'update') {
  149. let courseScheduleRewards = await courseScheduleRewardsQuery({ id: this.id })
  150. if (courseScheduleRewards.code == 200) {
  151. let data = courseScheduleRewards.data
  152. let tempList = []
  153. if (data.organIdList) {
  154. data.organIdList.split(',').forEach(item => {
  155. tempList.push(parseInt(item))
  156. })
  157. }
  158. this.result = {
  159. id: data.id,
  160. name: data.name,
  161. rewardMode: data.rewardMode,
  162. organIdList: tempList,
  163. courseScheduleType: data.courseScheduleType,
  164. domains: data.rewardsRulesJson ?
  165. JSON.parse(data.rewardsRulesJson) : [{
  166. min: null,
  167. max: null,
  168. money: null,
  169. disabled: false,
  170. key: Date.now()
  171. }],
  172. errorText: null
  173. }
  174. // 修改可以取消选中
  175. this.branchList.forEach(item => {
  176. if (tempList.indexOf(item.value) != -1) {
  177. item.disabled = false
  178. }
  179. })
  180. }
  181. }
  182. },
  183. onSubmit (formName) {
  184. this.$refs[formName].validate((valid) => {
  185. let result = this.result
  186. this.addDomain(result, true)
  187. if (valid && !result.errorText) {
  188. let params = {
  189. organIdList: result.organIdList.join(','),
  190. courseScheduleType: result.courseScheduleType,
  191. rewardMode: result.rewardMode,
  192. rewardsRulesJson: JSON.stringify(result.domains),
  193. name: result.name
  194. }
  195. if (this.pageType == 'update') {
  196. params.id = result.id
  197. courseScheduleRewardsUpdate(params).then(res => {
  198. this.messageTips('修改', res)
  199. })
  200. } else if (this.pageType == 'create') {
  201. // return false
  202. courseScheduleRewardsAdd(params).then(res => {
  203. this.messageTips('添加', res)
  204. })
  205. }
  206. } else {
  207. return false;
  208. }
  209. })
  210. },
  211. messageTips (title, res) {
  212. if (res.code == 200) {
  213. this.$message.success('修改成功')
  214. this.$router.push('/vipClassSet/branchActive')
  215. } else {
  216. this.$message.error(res.msg)
  217. }
  218. },
  219. onCancel () {
  220. this.$router.push('/vipClassSet/branchActive')
  221. },
  222. resetForm () {
  223. this.result = {
  224. name: null,
  225. rewardMode: null,
  226. organIdList: [],
  227. courseScheduleType: 'VIP',
  228. domains: [{
  229. min: null,
  230. max: null,
  231. money: null,
  232. disabled: false,
  233. key: Date.now()
  234. }],
  235. errorText: null
  236. }
  237. this.$refs.form.resetFields()
  238. },
  239. removeDomain (form, item) {
  240. var index = form.domains.indexOf(item)
  241. if (index !== -1) {
  242. form.domains.splice(index, 1)
  243. // 取消最后一个数据的禁用状态
  244. form.domains[form.domains.length - 1].disabled = false
  245. form.errorText = null
  246. }
  247. },
  248. addDomain (form, checked) {
  249. // debugger
  250. let domains = form.domains,
  251. singleLength = domains.length,
  252. lastDate = domains[singleLength - 1] // 获取倒数一个对象
  253. if (!lastDate.min) {
  254. form.errorText = '最小值不能为空'
  255. return
  256. }
  257. if (singleLength <= 1 && parseInt(lastDate.min) < 0) {
  258. form.errorText = '最小值不能小于0'
  259. return
  260. } else if (singleLength > 1 && parseInt(lastDate.min) <= parseInt(domains[singleLength - 2].max)) {
  261. form.errorText = '最小值不能小于或等于上一个梯度的最大值'
  262. return
  263. }
  264. if (!parseInt(lastDate.max)) {
  265. form.errorText = '最大值不能为空'
  266. return
  267. } else if (parseInt(lastDate.max) <= parseInt(lastDate.min)) {
  268. form.errorText = '最大值应大于该梯度的最小值'
  269. return
  270. }
  271. form.errorText = null
  272. if (!checked) {
  273. lastDate.disabled = true
  274. domains.push({
  275. min: null,
  276. max: null,
  277. disabled: false,
  278. key: Date.now()
  279. })
  280. }
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. .el-button--primary {
  287. background: #14928a;
  288. border-color: #14928a;
  289. color: #fff;
  290. &:hover,
  291. &:active,
  292. &:focus {
  293. background: #14928a;
  294. border-color: #14928a;
  295. color: #fff;
  296. }
  297. }
  298. .el-row {
  299. margin-top: 40px;
  300. }
  301. .el-col {
  302. display: flex;
  303. align-items: center;
  304. margin-bottom: 20px;
  305. justify-content: flex-end;
  306. margin-right: 50%;
  307. }
  308. .el-input-group {
  309. width: 200px;
  310. margin: 0 20px;
  311. }
  312. /deep/.el-tree-node__content {
  313. height: 40px !important;
  314. }
  315. .moreRule {
  316. background: #f0f0f0;
  317. position: relative;
  318. .el-form-item__error {
  319. color: #f56c6c;
  320. font-size: 12px;
  321. line-height: 1;
  322. position: absolute;
  323. left: 120px;
  324. top: 100%;
  325. margin-top: -21px;
  326. }
  327. }
  328. .add {
  329. margin-bottom: 22px;
  330. background: #f0f0f0;
  331. padding-bottom: 22px;
  332. }
  333. .moreRuleIn {
  334. .el-form-item {
  335. display: inline-block;
  336. &:first-child {
  337. /deep/.el-form-item__content {
  338. margin-left: 120px !important;
  339. }
  340. }
  341. /deep/.el-form-item__content {
  342. margin-left: 0 !important;
  343. }
  344. }
  345. }
  346. .min,
  347. .max {
  348. display: inline-block;
  349. width: 180px;
  350. text-align: center;
  351. margin-right: 10px;
  352. }
  353. </style>