liyongli 3 years ago
parent
commit
8e0a3fcf7f
2 changed files with 21 additions and 9 deletions
  1. 12 0
      src/api/vote/vote.js
  2. 9 9
      src/pages/vote/Index.vue

+ 12 - 0
src/api/vote/vote.js

@@ -24,3 +24,15 @@ export function saveVote(params) {
     data: params
   });
 }
+
+/**
+ * 获取投票
+ * @param params
+ * @returns {AxiosPromise}
+ */
+export function isVote() {
+  return request({
+    url: "/app/vote/list?source=智慧融媒",
+    method: "get"
+  });
+}

+ 9 - 9
src/pages/vote/Index.vue

@@ -15,7 +15,6 @@
             size="large"
           >
             <template #title>
-              <!-- :disabled="disable" -->
               <van-checkbox
                 :disabled="disable"
                 checked-color="#e42417"
@@ -79,7 +78,7 @@ import "vant/lib/button/style";
 import "vant/lib/progress/style";
 import "vant/lib/checkbox-group/style";
 
-import { voteList, saveVote } from "@/api/vote/vote.js";
+import { voteList, saveVote, isVote } from "@/api/vote/vote.js";
 import { isIphone, isAndroid } from "@/utils/isTerminal.js";
 import { setToken } from "@/utils/common.js";
 
@@ -108,12 +107,6 @@ export default {
         this.appNameList.push(...(res || []));
         data.total = this.appNameList.length;
         let checkboxGroup = [];
-        this.appNameList.map(v => {
-          if (v.voted) {
-            checkboxGroup.push(v.infoId);
-            if (!this.disable) this.disable = true;
-          }
-        });
         this.checkboxGroup = checkboxGroup;
         this.$nextTick(() => {
           res.length && (getload = true);
@@ -167,6 +160,10 @@ export default {
           saveVote({ source: "智慧融媒", items: r })
             .then(() => {
               this.disable = true;
+              Toast({
+                message: "投票成功",
+                position: "bottom"
+              });
             })
             .catch(err => {
               console.log(err);
@@ -192,9 +189,12 @@ export default {
       console.log("-->", this.$user);
       if (this.$user) setToken(this.$user.accessToken);
       else setToken("");
+      isVote().then(res => {
+        this.disable = (res || []).length === 0;
+        this.addList();
+      });
     };
     window.voteNext();
-    this.addList();
     let height = document.body.offsetHeight || 0;
     let width = document.body.offsetWidth || 0;
     this.$refs.vote.style.minHeight = height - (856 / 1500) * width + "px";