index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="form" ref="form" :rules="rules" label-width="auto" v-loading="loading" :disabled="checkPermi(['registration:regConfig:change']) ? false : true">
  4. <el-form-item label="签到标题:" prop="signTitle">
  5. <el-input v-model="form.signTitle" placeholder="请输入签到标题" maxlength="50" show-word-limit />
  6. </el-form-item>
  7. <el-form-item label="签到周期:" prop="signDay">
  8. <el-input-number v-model="form.signDay" :min="1" :max="99" placeholder="请输入签到周期" :controls="false"
  9. @change="changeSignDay" />
  10. <span class="span">天</span>
  11. </el-form-item>
  12. <el-form-item label="基础积分:" prop="baseRewardPoint">
  13. <el-input-number v-model="form.baseRewardPoint" :min="0" :controls="false" placeholder="请输入基础积分" />
  14. <span class="span">积分</span>
  15. </el-form-item>
  16. <el-form-item label="连续签到奖励:">
  17. <el-popover placement="top" content="连续签到一定天数后,可以额外获得积分" trigger="hover">
  18. <el-checkbox v-model="form.isContinueReward" :true-label="0" :false-label="1" slot="reference">
  19. 开启
  20. </el-checkbox>
  21. </el-popover>
  22. <el-table v-if="form.isContinueReward === 0" :data="form.pointConfigContinueRList">
  23. <el-table-column label="连续签到天数 / 天" align="center">
  24. <template slot-scope="scope">
  25. <el-input-number class="input-number" v-model="scope.row.signDay" :min="1" :max="99"
  26. :controls="false" @blur="checkSignDay(scope.row.signDay, scope.$index)" />
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="奖励积分 / 积分" align="center">
  30. <template slot-scope="scope">
  31. <el-input-number class="input-number" v-model="scope.row.rewardPoint" :min="0"
  32. :controls="false" />
  33. </template>
  34. </el-table-column>
  35. <el-table-column align="center">
  36. <template #header>
  37. <el-button type="text" icon="el-icon-plus" @click="handlerPush('签到奖励')" :disabled="continuePush">添加</el-button>
  38. </template>
  39. <template slot-scope="scope">
  40. <el-button type="delete" @click="getDeleteContinue(scope)">
  41. 删除
  42. </el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </el-form-item>
  47. <el-form-item label="收听播放奖励:">
  48. <el-popover placement="top" content="播放一定时间后,可以获得相应奖励" trigger="hover">
  49. <el-select v-model="form.notifyRewardType" placeholder="请选择奖励类型" slot="reference"
  50. style="width: 150px; margin-bottom: 10px">
  51. <el-option v-for="item in rewardOptions" :key="item.value" :value="item.value"
  52. :label="item.label" />
  53. </el-select>
  54. </el-popover>
  55. <el-table v-if="form.notifyRewardType" :data="form.pointConfigListenGoodList">
  56. <el-table-column label="播放时间 / 小时" align="center">
  57. <template slot-scope="scope">
  58. <el-input-number class="input-number" v-model="scope.row.listenTime" :max="99" :controls="false"
  59. @blur="checkListenTime(scope.row.listenTime, scope.$index)" />
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="奖励积分 / 积分" align="center">
  63. <template slot-scope="scope">
  64. <el-input-number class="input-number" v-model="scope.row.rewardPoint" :min="0"
  65. :controls="false" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column align="center">
  69. <template #header>
  70. <el-button type="text" icon="el-icon-plus" @click="handlerPush('播放奖励')"
  71. :disabled="listenGoodPush">添加</el-button>
  72. </template>
  73. <template slot-scope="scope">
  74. <el-button type="delete" @click="getDeleteListenGood(scope)">
  75. 删除
  76. </el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </el-form-item>
  81. <el-form-item label="手机通知奖励:">
  82. <el-input-number v-model="form.notifyRewardPoint" :min="0" :controls="false" />
  83. <span class="span">积分</span>
  84. </el-form-item>
  85. <el-form-item label="签到规则:" prop="signRule">
  86. <el-input v-model="form.signRule" type="textarea" :autosize="{minRows: 5, maxRows: 10}"
  87. placeholder="请输入签到规则" />
  88. </el-form-item>
  89. <el-form-item>
  90. <el-button type="primary" @click="getSubmit">确定
  91. </el-button>
  92. </el-form-item>
  93. </el-form>
  94. </div>
  95. </template>
  96. <script>
  97. import { list, submit, removeContinue, removeListenGood } from '@/api/registration/regConfig'
  98. import { checkPermi } from '@/utils/permission'
  99. export default {
  100. data() {
  101. return {
  102. // 遮罩层
  103. loading: false,
  104. // 表单
  105. form: {
  106. pointConfigContinueRList: []
  107. },
  108. // 连续签到奖励 添加按钮禁止
  109. continuePush: false,
  110. // 收听播放奖励 添加按钮禁止
  111. listenGoodPush: false,
  112. // 校验
  113. rules: {
  114. signTitle: [{
  115. required: true, message: '请输入签到标题', trigger: 'blur'
  116. }],
  117. signDay: [{
  118. required: true, message: '请输入签到周期', trigger: 'blur'
  119. }],
  120. baseRewardPoint: [{
  121. required: true, message: '请输入基础积分', trigger: 'blur'
  122. }],
  123. signRule: [{
  124. required: true, message: '请输入签到规则', trigger: 'blur'
  125. }]
  126. },
  127. // 奖励类型
  128. rewardOptions: [{
  129. value: 4,
  130. label: '积分'
  131. }],
  132. // 是否只读
  133. disabled: false
  134. }
  135. },
  136. watch: {
  137. 'form.pointConfigContinueRList': {
  138. handler(val) {
  139. // 当连续签到已达基础签到周期上限则禁止添加新数据
  140. this.continuePush = val.length < this.form.signDay ? val.findIndex(i => i.signDay === this.form.signDay) !== -1 ? true : false : true
  141. },
  142. deep: true
  143. },
  144. 'form.pointConfigListenGoodList'(val) {
  145. this.listenGoodPush = val.length >= 10 ? true : false
  146. }
  147. },
  148. mounted() {
  149. this.getList()
  150. },
  151. methods: {
  152. // 详情
  153. getList() {
  154. this.loading = true
  155. list().then(res => {
  156. if (res.code === 0) {
  157. this.form = res.data
  158. this.loading = false
  159. }
  160. })
  161. },
  162. // 签到周期改变 连续签到列表重置
  163. changeSignDay() {
  164. let ids = ''
  165. let arr = []
  166. this.form.pointConfigContinueRList.map(i => {
  167. if (i.id) {
  168. arr.push(i.id)
  169. }
  170. })
  171. ids = arr.join(',')
  172. if (ids) {
  173. removeContinue(ids).then(res => { })
  174. }
  175. this.form.pointConfigContinueRList = []
  176. },
  177. // 添加
  178. handlerPush(key) {
  179. if (key === '签到奖励') {
  180. this.form.pointConfigContinueRList.push({
  181. signDay: undefined,
  182. rewardPoint: undefined,
  183. status: 1,
  184. })
  185. } else {
  186. this.form.pointConfigListenGoodList.push({
  187. listenTime: undefined,
  188. rewardPoint: undefined,
  189. type: this.form.notifyRewardType
  190. })
  191. }
  192. },
  193. // 判断连续签到天数是否大于签到周期天数
  194. checkSignDay(e, index) {
  195. if (e > this.form.signDay) {
  196. this.$message.error('连续签到天数不可大于签到周期!')
  197. this.form.pointConfigContinueRList[index].signDay = undefined
  198. }
  199. if (this.form.pointConfigContinueRList.filter(i => i.signDay === e).length === 2) {
  200. this.$message.error('此天数已存在!')
  201. this.form.pointConfigContinueRList[index].signDay = undefined
  202. }
  203. },
  204. // 判断收听播放奖励时是否填写重复的时间
  205. checkListenTime(e, index) {
  206. if (this.form.pointConfigListenGoodList.filter(i => i.listenTime === e).length === 2) {
  207. this.$message.error('此时间已存在!')
  208. this.form.pointConfigListenGoodList[index].listenTime = undefined
  209. }
  210. },
  211. // 删除连续签到奖励
  212. getDeleteContinue(scope) {
  213. let title = scope.row.signDay ? scope.row.signDay : '空'
  214. this.$confirm(`是否删除 连续签到天数为${title} 的数据?`, '提示', {
  215. type: 'warning'
  216. }).then(() => {
  217. if (scope.row.id) {
  218. removeContinue(scope.row.id).then(res => {
  219. if (res.code !== 0) {
  220. return false
  221. }
  222. })
  223. }
  224. this.$message.success('删除成功!')
  225. this.form.pointConfigContinueRList.splice(scope.$index, 1)
  226. }).catch(() => { })
  227. },
  228. // 删除收听播放奖励
  229. getDeleteListenGood(scope) {
  230. let title = scope.row.listenTime ? scope.row.listenTime : '空'
  231. this.$confirm(`是否删除 播放时间为${title} 的数据?`, '提示', {
  232. type: 'warning'
  233. }).then(() => {
  234. if (scope.row.id) {
  235. removeListenGood({
  236. id: scope.row.id
  237. }).then(res => {
  238. if (res.code !== 0) {
  239. return false
  240. }
  241. })
  242. }
  243. this.$message.success('删除成功!')
  244. this.form.pointConfigListenGoodList.splice(scope.$index, 1)
  245. }).catch(() => { })
  246. },
  247. // 确定
  248. getSubmit() {
  249. this.$refs.form.validate((valid) => {
  250. if (valid) {
  251. submit(this.form).then(res => {
  252. if (res.code === 0) {
  253. this.$message.success('修改成功!')
  254. this.getList()
  255. }
  256. })
  257. } else {
  258. return false
  259. }
  260. })
  261. },
  262. // 监控权限
  263. checkPermi
  264. }
  265. }
  266. </script>
  267. <style lang="scss" scoped>
  268. .el-form {
  269. width: 500px;
  270. }
  271. .input-number {
  272. width: 110px;
  273. }
  274. .span {
  275. margin-left: 10px;
  276. }
  277. </style>