index.vue 8.8 KB

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