Parcourir la source

扫码兑换页面接口对接

natasha il y a 1 semaine
Parent
commit
b681a63ba6
1 fichiers modifiés avec 80 ajouts et 50 suppressions
  1. 80 50
      src/views/scanRedeem.vue

+ 80 - 50
src/views/scanRedeem.vue

@@ -3,25 +3,21 @@
     <div class="header">
       <svg-icon icon-class="logos"></svg-icon>
     </div>
-    <div class="first-step" v-if="flag">
+    <div class="first-step">
       <div class="content-box">
         <p>快递单号:</p>
-        <el-input placeholder="请输入快递单号" v-model="trackingNumber">
+        <el-input
+          placeholder="请输入快递单号"
+          v-model="trackingNumber"
+          @blur="handleTrim('trackingNumber')"
+        >
         </el-input>
-      </div>
-      <el-button
-        class="sure-btn"
-        type="primary"
-        size="medium"
-        @click="sureChange"
-        :loading="loading"
-        >兑 换</el-button
-      >
-    </div>
-    <div class="first-step" v-else>
-      <div class="content-box">
         <p>绑定手机号:</p>
-        <el-input placeholder="请输入需要绑定的手机号" v-model="userPhone">
+        <el-input
+          placeholder="请输入需要绑定的手机号"
+          v-model="userPhone"
+          @blur="handleTrim('userPhone')"
+        >
         </el-input>
         <div class="code-box">
           <el-input
@@ -43,15 +39,13 @@
           </el-button>
         </div>
       </div>
-
       <el-button
         class="sure-btn"
         type="primary"
         size="medium"
-        ref="button"
         @click="surePhone"
         :loading="loading"
-        >确 定</el-button
+        >兑 换</el-button
       >
     </div>
 
@@ -69,6 +63,7 @@
 
 <script>
 import { getLogin } from "@/api/ajax";
+import { setToken } from "@/utils/auth";
 export default {
   name: "scanRedeem",
   components: {},
@@ -77,7 +72,6 @@ export default {
       trackingNumber: "", // 快递单号
       keyCode: "", // 兑换码
       userPhone: "", // 用户手机号
-      flag: true,
       loading: false,
       code: "",
       time: 60, //获取验证码的时间
@@ -88,37 +82,73 @@ export default {
   watch: {},
   methods: {
     // 点击兑换按钮
-    sureChange() {
-      if (this.trackingNumber && this.trackingNumber.trim()) {
-        this.flag = false;
-        this.userPhone = "13717582171";
-      } else {
-        this.$message.warning("请先输入快递单号");
-      }
-    },
-    // 点击确定按钮
     surePhone() {
-      if (this.userPhone && this.userPhone.trim()) {
-        // this.loading = true;
-        let pwd = "123456";
-        let str =
-          "<p>用户名:" +
-          this.userPhone +
-          "</p><p>密码:" +
-          pwd +
-          "</p>请您在<b>【电脑端】</b>浏览器登录https://read.21stcentury.com.cn平台至书架模块自行查看对应电子内容";
-        this.$confirm(str, "兑换成功", {
-          type: "success",
-          customClass: "scanRedeem-model",
-          showClose: false,
-          showCancelButton: false,
-          showConfirmButton: false,
-          dangerouslyUseHTMLString: true,
-          closeOnClickModal: false,
-        }).then(({}) => {});
-      } else {
+      if (!this.trackingNumber) {
+        this.$message.warning("请先输入快递单号");
+        return;
+      } else if (!this.userPhone) {
         this.$message.warning("请输入需要绑定的手机号");
+        return;
+      } else if (!this.code) {
+        this.$message.warning("请输入验证码");
+        return;
       }
+      this.loading = true;
+      let MethodName =
+        "/OrgServer/LoginControl/ScanQRCodeAutoLoginOrRegisterUser";
+      let data = {
+        sms_verification_code: this.code,
+        phone: this.userPhone,
+      };
+      getLogin(MethodName, data)
+        .then((res) => {
+          if (res.status === 1) {
+            setToken(res);
+            getLogin(
+              "/ShopServer/Client/OrderManager/CreateOrder_UseJushuitanWaybillDiscountCode",
+              { logistics_tracking_number: this.trackingNumber }
+            )
+              .then((ress) => {
+                this.loading = false;
+                if (ress.status === 1) {
+                  let str =
+                    "请您在<b>【电脑端】</b>浏览器登录https://read.21stcentury.com.cn平台至书架模块自行查看对应电子内容";
+                  if (res.is_new_register_user === "true") {
+                    str =
+                      "<p>用户名:" +
+                      this.userPhone +
+                      "</p><p>密码:" +
+                      res.password +
+                      "</p>请您在<b>【电脑端】</b>浏览器登录https://read.21stcentury.com.cn平台至书架模块自行查看对应电子内容";
+                  }
+
+                  this.$confirm(str, "兑换成功", {
+                    type: "success",
+                    customClass: "scanRedeem-model",
+                    showClose: false,
+                    showCancelButton: false,
+                    showConfirmButton: false,
+                    dangerouslyUseHTMLString: true,
+                    closeOnClickModal: false,
+                  }).then(({}) => {});
+                }
+              })
+              .catch(() => {
+                this.loading = false;
+                this.verificationCodeShow = false;
+                clearInterval(this.timer);
+                this.timer = null;
+                this.time = 60;
+              });
+          }
+        })
+        .catch(() => {
+          this.loading = false;
+          this.verificationCodeShow = false;
+          clearInterval(this.timer);
+          this.timer = null;
+          this.time = 60;
+        });
     },
     // 发送验证码
     sendCode(time, flag) {
@@ -184,7 +214,7 @@ export default {
     }
   }
   .first-step {
-    padding: 40px 20px 20px 20px;
+    padding: 20px;
   }
   .content-box {
     // display: flex;
@@ -205,7 +235,7 @@ export default {
     border-radius: 4px;
   }
   .tips {
-    margin-top: 50px;
+    margin-top: 10px;
     color: #ee1c24;
     padding: 0 20px;
   }
@@ -223,7 +253,7 @@ export default {
   }
   .code-box {
     display: flex;
-    margin: 10px 0;
+    margin: 16px 0;
     .sendCode {
       border-radius: 0 4px 4px 0;
       width: 92px;