index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <!-- 签到管理 签到配置-->
  2. <template>
  3. <div class="app-container">
  4. <el-form
  5. :model="form"
  6. ref="form"
  7. :rules="rules"
  8. label-width="auto"
  9. v-loading="loading"
  10. :disabled="checkPermi(['registration:regConfig:change']) ? false : true"
  11. >
  12. <el-form-item label="签到标题:" prop="signTitle">
  13. <el-input
  14. v-model="form.signTitle"
  15. placeholder="请输入签到标题"
  16. maxlength="50"
  17. show-word-limit
  18. />
  19. </el-form-item>
  20. <el-form-item label="签到周期:" prop="signDay">
  21. <el-input-number
  22. v-model="form.signDay"
  23. :min="1"
  24. :max="99"
  25. placeholder="请输入签到周期"
  26. :controls="false"
  27. @change="changeSignDay"
  28. />
  29. <span class="span">天</span>
  30. </el-form-item>
  31. <el-form-item label="基础积分:" prop="baseRewardPoint">
  32. <el-input-number
  33. v-model="form.baseRewardPoint"
  34. :min="0"
  35. :controls="false"
  36. placeholder="请输入基础积分"
  37. />
  38. <span class="span">积分</span>
  39. </el-form-item>
  40. <el-form-item label="连续签到奖励:">
  41. <el-popover
  42. placement="top"
  43. content="连续签到一定天数后,可以额外获得积分"
  44. trigger="hover"
  45. >
  46. <el-checkbox
  47. v-model="form.isContinueReward"
  48. :true-label="0"
  49. :false-label="1"
  50. slot="reference"
  51. >
  52. 开启
  53. </el-checkbox>
  54. </el-popover>
  55. <el-table
  56. v-if="form.isContinueReward === 0"
  57. :data="form.pointConfigContinueRList"
  58. >
  59. <el-table-column label="连续签到天数 / 天" align="center">
  60. <template slot-scope="scope">
  61. <el-input-number
  62. class="input-number"
  63. v-model="scope.row.signDay"
  64. :min="1"
  65. :max="99"
  66. :controls="false"
  67. @blur="checkSignDay(scope.row.signDay, scope.$index)"
  68. />
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="奖励积分 / 积分" align="center">
  72. <template slot-scope="scope">
  73. <el-input-number
  74. class="input-number"
  75. v-model="scope.row.rewardPoint"
  76. :min="0"
  77. :controls="false"
  78. />
  79. </template>
  80. </el-table-column>
  81. <el-table-column align="center">
  82. <template #header>
  83. <el-button
  84. type="text"
  85. icon="el-icon-plus"
  86. @click="handlerPush('签到奖励')"
  87. :disabled="continuePush"
  88. >添加</el-button
  89. >
  90. </template>
  91. <template slot-scope="scope">
  92. <el-button type="delete" @click="getDeleteContinue(scope)">
  93. 删除
  94. </el-button>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. </el-form-item>
  99. <el-form-item label="收听播放奖励:">
  100. <el-popover
  101. placement="top"
  102. content="播放一定时间后,可以获得相应奖励"
  103. trigger="hover"
  104. >
  105. <el-select
  106. v-model="form.notifyRewardType"
  107. placeholder="请选择奖励类型"
  108. slot="reference"
  109. style="width: 150px; margin-bottom: 10px"
  110. >
  111. <el-option
  112. v-for="item in rewardOptions"
  113. :key="item.value"
  114. :value="item.value"
  115. :label="item.label"
  116. />
  117. </el-select>
  118. </el-popover>
  119. <el-table
  120. v-if="form.notifyRewardType"
  121. :data="form.pointConfigListenGoodList"
  122. >
  123. <el-table-column label="播放时间 / 小时" align="center">
  124. <template slot-scope="scope">
  125. <el-input-number
  126. class="input-number"
  127. v-model="scope.row.listenTime"
  128. :max="99"
  129. :controls="false"
  130. @blur="checkListenTime(scope.row.listenTime, scope.$index)"
  131. />
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="奖励积分 / 积分" align="center">
  135. <template slot-scope="scope">
  136. <el-input-number
  137. class="input-number"
  138. v-model="scope.row.rewardPoint"
  139. :min="0"
  140. :controls="false"
  141. />
  142. </template>
  143. </el-table-column>
  144. <el-table-column align="center">
  145. <template #header>
  146. <el-button
  147. type="text"
  148. icon="el-icon-plus"
  149. @click="handlerPush('播放奖励')"
  150. :disabled="listenGoodPush"
  151. >添加</el-button
  152. >
  153. </template>
  154. <template slot-scope="scope">
  155. <el-button type="delete" @click="getDeleteListenGood(scope)">
  156. 删除
  157. </el-button>
  158. </template>
  159. </el-table-column>
  160. </el-table>
  161. </el-form-item>
  162. <el-form-item label="手机通知奖励:">
  163. <el-input-number
  164. v-model="form.notifyRewardPoint"
  165. :min="0"
  166. :controls="false"
  167. />
  168. <span class="span">积分</span>
  169. </el-form-item>
  170. <el-form-item label="签到规则:" prop="signRule">
  171. <el-input
  172. v-model="form.signRule"
  173. type="textarea"
  174. :autosize="{ minRows: 5, maxRows: 10 }"
  175. placeholder="请输入签到规则"
  176. />
  177. </el-form-item>
  178. <el-form-item>
  179. <el-button type="primary" @click="getSubmit">确定 </el-button>
  180. </el-form-item>
  181. </el-form>
  182. </div>
  183. </template>
  184. <script>
  185. import {
  186. list,
  187. removeContinue,
  188. removeListenGood,
  189. submit,
  190. } from "@/api/registration/regConfig";
  191. import { dialogCallBack } from "@/utils/DialogUtil";
  192. import { checkPermi } from "@/utils/permission";
  193. export default {
  194. data() {
  195. return {
  196. // 遮罩层
  197. loading: false,
  198. // 表单
  199. form: {
  200. pointConfigContinueRList: [],
  201. },
  202. // 连续签到奖励 添加按钮禁止
  203. continuePush: false,
  204. // 收听播放奖励 添加按钮禁止
  205. listenGoodPush: false,
  206. // 校验
  207. rules: {
  208. signTitle: [
  209. {
  210. required: true,
  211. message: "请输入签到标题",
  212. trigger: "blur",
  213. },
  214. ],
  215. signDay: [
  216. {
  217. required: true,
  218. message: "请输入签到周期",
  219. trigger: "blur",
  220. },
  221. ],
  222. baseRewardPoint: [
  223. {
  224. required: true,
  225. message: "请输入基础积分",
  226. trigger: "blur",
  227. },
  228. ],
  229. signRule: [
  230. {
  231. required: true,
  232. message: "请输入签到规则",
  233. trigger: "blur",
  234. },
  235. ],
  236. },
  237. // 奖励类型
  238. rewardOptions: [
  239. {
  240. value: 4,
  241. label: "积分",
  242. },
  243. ],
  244. // 是否只读
  245. disabled: false,
  246. };
  247. },
  248. watch: {
  249. "form.pointConfigContinueRList": {
  250. handler(val) {
  251. // 当连续签到已达基础签到周期上限则禁止添加新数据
  252. this.continuePush =
  253. val.length < this.form.signDay
  254. ? val.findIndex((i) => i.signDay === this.form.signDay) !== -1
  255. ? true
  256. : false
  257. : true;
  258. },
  259. deep: true,
  260. },
  261. "form.pointConfigListenGoodList"(val) {
  262. this.listenGoodPush = val.length >= 10 ? true : false;
  263. },
  264. },
  265. mounted() {
  266. this.getList();
  267. },
  268. methods: {
  269. // 详情
  270. getList() {
  271. this.loading = true;
  272. list().then((res) => {
  273. if (res.code === 0) {
  274. this.form = res.data;
  275. this.loading = false;
  276. }
  277. });
  278. },
  279. // 签到周期改变 连续签到列表重置
  280. changeSignDay() {
  281. let ids = "";
  282. let arr = [];
  283. this.form.pointConfigContinueRList.map((i) => {
  284. if (i.id) {
  285. arr.push(i.id);
  286. }
  287. });
  288. ids = arr.join(",");
  289. if (ids) {
  290. removeContinue(ids).then((res) => {});
  291. }
  292. this.form.pointConfigContinueRList = [];
  293. },
  294. // 添加
  295. handlerPush(key) {
  296. if (key === "签到奖励") {
  297. this.form.pointConfigContinueRList.push({
  298. signDay: undefined,
  299. rewardPoint: undefined,
  300. status: 1,
  301. });
  302. } else {
  303. this.form.pointConfigListenGoodList.push({
  304. listenTime: undefined,
  305. rewardPoint: undefined,
  306. type: this.form.notifyRewardType,
  307. });
  308. }
  309. },
  310. // 判断连续签到天数是否大于签到周期天数
  311. checkSignDay(e, index) {
  312. if (e > this.form.signDay) {
  313. this.$message.error("连续签到天数不可大于签到周期!");
  314. this.form.pointConfigContinueRList[index].signDay = undefined;
  315. }
  316. if (
  317. this.form.pointConfigContinueRList.filter((i) => i.signDay === e)
  318. .length === 2
  319. ) {
  320. this.$message.error("此天数已存在!");
  321. this.form.pointConfigContinueRList[index].signDay = undefined;
  322. }
  323. },
  324. // 判断收听播放奖励时是否填写重复的时间
  325. checkListenTime(e, index) {
  326. if (
  327. this.form.pointConfigListenGoodList.filter((i) => i.listenTime === e)
  328. .length === 2
  329. ) {
  330. this.$message.error("此时间已存在!");
  331. this.form.pointConfigListenGoodList[index].listenTime = undefined;
  332. }
  333. },
  334. // 删除连续签到奖励
  335. getDeleteContinue(scope) {
  336. var that = this;
  337. dialogCallBack(that, function () {
  338. let title = scope.row.signDay ? scope.row.signDay : "空";
  339. that
  340. .$confirm(`是否删除 连续签到天数为${title} 的数据?`, "提示", {
  341. type: "warning",
  342. })
  343. .then(() => {
  344. if (scope.row.id) {
  345. removeContinue(scope.row.id).then((res) => {
  346. if (res.code !== 0) {
  347. return false;
  348. }
  349. });
  350. }
  351. that.$message.success("删除成功!");
  352. that.form.pointConfigContinueRList.splice(scope.$index, 1);
  353. })
  354. .catch(() => {});
  355. });
  356. },
  357. // 删除收听播放奖励
  358. getDeleteListenGood(scope) {
  359. var that = this;
  360. dialogCallBack(that, function () {
  361. let title = scope.row.listenTime ? scope.row.listenTime : "空";
  362. that
  363. .$confirm(`是否删除 播放时间为${title} 的数据?`, "提示:", {
  364. type: "warning",
  365. })
  366. .then(() => {
  367. if (scope.row.id) {
  368. removeListenGood({
  369. id: scope.row.id,
  370. }).then((res) => {
  371. if (res.code !== 0) {
  372. return false;
  373. }
  374. });
  375. }
  376. that.$message.success("删除成功!");
  377. that.form.pointConfigListenGoodList.splice(scope.$index, 1);
  378. })
  379. .catch(() => {});
  380. });
  381. },
  382. // 确定
  383. getSubmit() {
  384. this.$refs.form.validate((valid) => {
  385. if (valid) {
  386. submit(this.form).then((res) => {
  387. if (res.code === 0) {
  388. this.$message.success("修改成功!");
  389. this.getList();
  390. }
  391. });
  392. } else {
  393. return false;
  394. }
  395. });
  396. },
  397. // 监控权限
  398. checkPermi,
  399. },
  400. };
  401. </script>
  402. <style lang="scss" scoped>
  403. .el-form {
  404. width: 500px;
  405. }
  406. .input-number {
  407. width: 110px;
  408. }
  409. .span {
  410. margin-left: 10px;
  411. }
  412. </style>