liyongli vor 3 Jahren
Ursprung
Commit
b2ea62208c
1 geänderte Dateien mit 133 neuen und 142 gelöschten Zeilen
  1. 133 142
      src/views/Apply.vue

+ 133 - 142
src/views/Apply.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="apply">
-    <van-form @submit="onSubmit">
+    <van-form ref="form">
       <van-field
         v-model="username"
         label="姓名"
@@ -37,28 +37,22 @@
         readonly
         :rules="[{ required: true, message: '未选择预定时间' }]"
       />
-      <div style="margin: 16px">
-        <br />
-        <br />
-        <van-button
-          color="#e42417"
-          round
-          block
-          type="info"
-          native-type="submit"
-        >
-          确认预约
-        </van-button>
-        <br />
-        <van-button round block type="default" @click="toAppointment">
-          查看预约列表
-        </van-button>
-        <br />
-        <!-- <van-button round block type="info" @click="price">
+    </van-form>
+    <br />
+    <br />
+    <div style="margin: 0 16px">
+      <van-button color="#e42417" round block type="info" @click="onSubmit">
+        确认预约
+      </van-button>
+      <br />
+      <van-button round block type="default" @click="toAppointment">
+        查看预约列表
+      </van-button>
+      <br />
+      <!-- <van-button round block type="info" @click="price">
           查看价目表
         </van-button> -->
-      </div>
-    </van-form>
+    </div>
 
     <!-- #2a7ef4 -->
     <van-popup round v-model="dateInput" position="bottom">
@@ -103,17 +97,17 @@ import "vant/lib/field/style/index";
 import "vant/lib/button/style/index";
 import "vant/lib/popup/style/index";
 import "vant/lib/picker/style/index";
-// import { urlSearchData } from "../utils/tool";
-// import {
-//   getAPPUser,
-//   apply,
-//   getAPPToken,
-//   getAPPUserDetail,
-//   goodsList,
-//   applyrang,
-// } from "../api/index";
-import { goodsList, apply, applyrang } from "../api/index";
-import { isIphone, isAndroid } from "@/utils/isTerminal.js";
+import { urlSearchData } from "../utils/tool";
+import {
+  getAPPUser,
+  apply,
+  getAPPToken,
+  getAPPUserDetail,
+  goodsList,
+  applyrang,
+} from "../api/index";
+// import { goodsList, apply, applyrang } from "../api/index";
+// import { isIphone, isAndroid } from "@/utils/isTerminal.js";
 
 export default {
   name: "Apply",
@@ -137,106 +131,107 @@ export default {
     };
   },
   mounted() {
-    // let search = urlSearchData(),
-    //   that = this;
-    // getAPPUser({
-    //   ticket: search.ticket,
-    // }).then(r => {
-    //   getAPPToken("rest/63bada00-7d01-4acc-ab2b-df8061eeeb8f").then(res => {
-    //     const t = JSON.parse(res || "{}");
-    //     localStorage.token = t.id;
-    //     getAPPUserDetail({
-    //       loginName: r,
-    //     }).then(detail => {
-    //         const obj = JSON.parse(detail || "{}");
-    //         that.userphone = obj.telNumber;
-    //         that.username = obj.name;
-    //       goodsList({
-    //         userPhone: that.userphone || "",
-    //       }).then(res => {
-    //         this.goodsLi = (res || []).map(v => {
-    //           v.name = v.name + "(" + v.price + "元)";
-    //           return v;
-    //         });
-    //         this.radio = (this.goodsLi[0] || {}).id;
-    //       });
-    //       applyrang().then(res => {
-    //         let l = res || [],
-    //           nl = [],
-    //           o = {};
-    //         for (let i = 0; i < l.length; i++) {
-    //           const v = l[i];
-    //           if (v.isOrder === 1) continue;
-    //           let keys = v.startTime.split(" "),
-    //             key = keys[0],
-    //             val = keys[1];
-    //           v.startTime = val.replace(/:00$/, "");
-    //           if (o[key] >= 0) {
-    //             nl[o[key]].children.push(v);
-    //           } else {
-    //             o[key] = nl.length;
-    //             nl[o[key]] = {
-    //               startTime: key,
-    //               children: [v],
-    //             };
-    //           }
-    //         }
-    //         this.tagList = nl;
-    //       });
-    //     });
-    //   });
-    // });
-    window.voteNext = () => {
-      let user = "";
-      var payload = {
-        type: "JSbridge",
-        functionName: "getUserInfo",
-        arguments: {},
-      };
-      if (isAndroid && window.H5Listener && window.H5Listener.getUserInfo)
-        user = window.H5Listener.getUserInfo();
-      if (isIphone) user = window.prompt(JSON.stringify(payload));
-      user && (user = JSON.parse(user || "{}"));
-      this.userphone = user.phone || "";
-      this.username = user.realName || "";
-      if (!this.userphone) {
-        if (isAndroid && window.H5Listener && window.H5Listener.getUserInfo)
-          window.H5Listener.doLogin();
-        if (isIphone && window.webkit && window.webkit.messageHandlers)
-          window.webkit.messageHandlers.doLogin.postMessage("{}");
-      }
-      goodsList().then(res => {
-        this.goodsLi = (res || []).map(v => {
-          v.name = v.name + "(" + v.price + "元)";
-          return v;
+    let search = urlSearchData(),
+      that = this;
+    if (!search.ticket) return;
+    getAPPUser({
+      ticket: search.ticket,
+    }).then(r => {
+      getAPPToken("rest/63bada00-7d01-4acc-ab2b-df8061eeeb8f").then(res => {
+        const t = JSON.parse(res || "{}");
+        localStorage.token = t.id;
+        getAPPUserDetail({
+          loginName: r,
+        }).then(detail => {
+          const obj = JSON.parse(detail || "{}");
+          that.userphone = obj.telNumber;
+          that.username = obj.name;
+          goodsList({
+            userPhone: that.userphone || "",
+          }).then(res => {
+            this.goodsLi = (res || []).map(v => {
+              v.name = v.name + "(" + v.price + "元)";
+              return v;
+            });
+            this.radio = (this.goodsLi[0] || {}).id;
+          });
+          applyrang().then(res => {
+            let l = res || [],
+              nl = [],
+              o = {};
+            for (let i = 0; i < l.length; i++) {
+              const v = l[i];
+              if (v.isOrder === 1) continue;
+              let keys = v.startTime.split(" "),
+                key = keys[0],
+                val = keys[1];
+              v.startTime = val.replace(/:00$/, "");
+              if (o[key] >= 0) {
+                nl[o[key]].children.push(v);
+              } else {
+                o[key] = nl.length;
+                nl[o[key]] = {
+                  startTime: key,
+                  children: [v],
+                };
+              }
+            }
+            this.tagList = nl;
+          });
         });
-        this.radio = (this.goodsLi[0] || {}).id;
       });
-      applyrang().then(res => {
-        let l = res || [],
-          nl = [],
-          o = {};
-        for (let i = 0; i < l.length; i++) {
-          const v = l[i];
-          if (v.isOrder === 1) continue;
-          let keys = v.startTime.split(" "),
-            key = keys[0],
-            val = keys[1];
-          v.startTime = val.replace(/:00$/, "");
-          if (o[key] >= 0) {
-            nl[o[key]].children.push(v);
-          } else {
-            o[key] = nl.length;
-            nl[o[key]] = {
-              startTime: key,
-              children: [v],
-            };
-          }
-        }
-        this.tagList = nl;
-      });
-    };
-    window.voteNext();
+    });
+    // window.voteNext = () => {
+    //   let user = "";
+    //   var payload = {
+    //     type: "JSbridge",
+    //     functionName: "getUserInfo",
+    //     arguments: {},
+    //   };
+    //   if (isAndroid && window.H5Listener && window.H5Listener.getUserInfo)
+    //     user = window.H5Listener.getUserInfo();
+    //   if (isIphone) user = window.prompt(JSON.stringify(payload));
+    //   user && (user = JSON.parse(user || "{}"));
+    //   this.userphone = user.phone || "";
+    //   this.username = user.realName || "";
+    //   if (!this.userphone) {
+    //     if (isAndroid && window.H5Listener && window.H5Listener.getUserInfo)
+    //       window.H5Listener.doLogin();
+    //     if (isIphone && window.webkit && window.webkit.messageHandlers)
+    //       window.webkit.messageHandlers.doLogin.postMessage("{}");
+    //   }
+    //   goodsList().then(res => {
+    //     this.goodsLi = (res || []).map(v => {
+    //       v.name = v.name + "(" + v.price + "元)";
+    //       return v;
+    //     });
+    //     this.radio = (this.goodsLi[0] || {}).id;
+    //   });
+    //   applyrang().then(res => {
+    //     let l = res || [],
+    //       nl = [],
+    //       o = {};
+    //     for (let i = 0; i < l.length; i++) {
+    //       const v = l[i];
+    //       if (v.isOrder === 1) continue;
+    //       let keys = v.startTime.split(" "),
+    //         key = keys[0],
+    //         val = keys[1];
+    //       v.startTime = val.replace(/:00$/, "");
+    //       if (o[key] >= 0) {
+    //         nl[o[key]].children.push(v);
+    //       } else {
+    //         o[key] = nl.length;
+    //         nl[o[key]] = {
+    //           startTime: key,
+    //           children: [v],
+    //         };
+    //       }
+    //     }
+    //     this.tagList = nl;
+    //   });
+    // };
+    // window.voteNext();
   },
   computed: {
     selectTime() {
@@ -266,18 +261,14 @@ export default {
       return options;
     },
     onSubmit() {
-      apply({
-        userName: this.username,
-        userPhone: this.userphone,
-        goodsId: this.radio,
-        orderTime: this.date + ":00",
-      }).then(() => {
-        this.$router.push({
-          name: "Appointment",
-          query: {
-            userName: this.username,
-            phone: this.userphone,
-          },
+      this.$refs.form.validate().then(() => {
+        apply({
+          userName: this.username,
+          userPhone: this.userphone,
+          goodsId: this.radio,
+          orderTime: this.date + ":00",
+        }).then(() => {
+          this.toAppointment();
         });
       });
     },