Blame view

src/views/binding/binDing.vue 4.62 KB
94c1e6a3   liuqimichale   微信公众号 个人页面集合
1
2
3
4
5
  <template>
    <div>
  
      <mt-field label="手机号" placeholder="请输入正确的手机号" type="tel" v-model="phone" :attr="{ maxlength: 13 }"></mt-field>
  
71ca44b6   刘淇   个人中心
6
      <mt-field label="验证码" v-model="codeText">
6e6de4e6   刘淇   修改整体颜色
7
        <button  class="getCode" @click="getCode" :disabled="disabled">{{btntxt}}
71ca44b6   刘淇   个人中心
8
        </button>
94c1e6a3   liuqimichale   微信公众号 个人页面集合
9
10
11
      </mt-field>
  
      <div style="margin-top: 34px" class="leftRightPadding">
6e6de4e6   刘淇   修改整体颜色
12
        <mt-button type="primary" size="large" @click.native="bindphone">绑定</mt-button>
94c1e6a3   liuqimichale   微信公众号 个人页面集合
13
14
15
16
17
      </div>
    </div>
  </template>
  
  <script>
71ca44b6   刘淇   个人中心
18
19
20
21
22
  
  import { sendverificode, bindCustByOpenId } from "@/api/binDing/binding";
  import {
    getTokenByOpenId
  } from "@/api/selfNav/selfNav";
94c1e6a3   liuqimichale   微信公众号 个人页面集合
23
  export default {
71ca44b6   刘淇   个人中心
24
    name: "binDing",
94c1e6a3   liuqimichale   微信公众号 个人页面集合
25
26
    data() {
      return {
71ca44b6   刘淇   个人中心
27
28
29
        codeText: "",
        phone: "",
        btntxt: "获取验证码",
3e498dc1   刘淇   历史记录
30
        time: 0,
71ca44b6   刘淇   个人中心
31
32
        disabled: false
      };
94c1e6a3   liuqimichale   微信公众号 个人页面集合
33
    },
71ca44b6   刘淇   个人中心
34
35
    created() {
      // this.timeNum = this.timeText
94c1e6a3   liuqimichale   微信公众号 个人页面集合
36
37
    },
    methods: {
71ca44b6   刘淇   个人中心
38
      getCode: function() {
4518bc07   刘淇   199号段
39
        var reg = 11 && /^((13|14|15|17|18|19)[0-9]{1}\d{8})$/;
3e498dc1   刘淇   历史记录
40
        //var url="/nptOfficialWebsite/apply/sendSms?mobile="+this.ruleForm.phone;
71ca44b6   刘淇   个人中心
41
42
43
44
45
46
47
        if (this.phone == "") {
          this.$vux.toast.text("请输入手机号码", "top");
        } else if (!reg.test(this.phone)) {
          this.$vux.toast.text("手机格式不正确", "top");
        } else {
          this.time = 60;
          this.disabled = true;
3e498dc1   刘淇   历史记录
48
          this.timer();
71ca44b6   刘淇   个人中心
49
          this.sendverificode();
3e498dc1   刘淇   历史记录
50
51
        }
      },
71ca44b6   刘淇   个人中心
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
      sendverificode: function() {
        let that = this;
        let jsondata = {};
        let obj = {
          phone: this.phone
        };
        jsondata = Object.assign(obj, this.$utils.commonParams());
        jsondata.sign = this.$utils.signObject(jsondata);
        sendverificode(jsondata).then(response => {
          console.log(response);
          if (response.code == 0) {
            this.$vux.toast.text("获取验证码成功", "top");
          } else {
            this.$vux.toast.text(response.message, "top");
          }
        });
      },
3e498dc1   刘淇   历史记录
69
70
71
      timer() {
        if (this.time > 0) {
          this.time--;
71ca44b6   刘淇   个人中心
72
          this.btntxt = this.time + "S后重新获取";
3e498dc1   刘淇   历史记录
73
          setTimeout(this.timer, 1000);
71ca44b6   刘淇   个人中心
74
75
76
77
78
79
80
81
        } else {
          this.time = 0;
          this.btntxt = "获取验证码";
          this.disabled = false;
        }
      },
      bindphone: function() {
        //
1074da8c   刘淇   手机号段
82
        var reg = 11 && /^((13|14|15|17|18|19)[0-9]{1}\d{8})$/;
71ca44b6   刘淇   个人中心
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        //var url="/nptOfficialWebsite/apply/sendSms?mobile="+this.ruleForm.phone;
        if (this.phone == "") {
          this.$vux.toast.text("请输入手机号码", "top");
        } else if (!reg.test(this.phone)) {
          this.$vux.toast.text("手机格式不正确", "top");
        } else {
          if (this.codeText) {
            let jsondata = {
              phoneNum: this.phone,
              verifyCode: this.codeText,
              openid: sessionStorage.getItem("wx_openId"), // o0Moh6eQhTm5bZVqT6wjdSUsZonM
              orgId: this.$utils.myOrgId
            };
            // jsondata = JSON.stringify(jsondata);
            bindCustByOpenId(jsondata).then(data => {
              console.log(data);
              if (data.code == 0 || data.code == "0") {
                this.$vux.toast.text("亲,您已绑定成功!", "top")
                this.$router.push({
                  path:'selfNav'
                })
              } else if (data.code == 1017 || data.code == "1017") {
                this.$vux.toast.text("已经绑定过", "top")
                this.$router.push({
                  path:'selfNav'
                })
              } else {
                this.$vux.toast.text("绑定失败,请重新绑定!", "top")
              }
            });
          } else {
            this.$vux.toast.text("亲!请输入验证码", "top")
          }
3e498dc1   刘淇   历史记录
116
117
        }
      },
71ca44b6   刘淇   个人中心
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
      // 获取token
      getTokenByOpenId() {
        let that = this
        var jsondata = {
          openid: sessionStorage.getItem("wx_openId"),
          deviceInfo: this.$utils.myDeviceInfo
        };
        getTokenByOpenId(jsondata).then(data => {
          console.log("执行获取token的接口  " + JSON.stringify(data));
          if (data.code == 0) {
            console.log("用户 token " + data.data.token);
            let _token = data.data.token;
            console.log('getTokenByOpenId获取到的'+_token)
            sessionStorage.setItem("wx_Token", data.data.token);
            sessionStorage.setItem("WXPhone", data.data.phoneNum);
            this.$router.push({
              path:'selfNav'
            })
          } else {
            this.$vux.toast.text(data.message, "top");
          }
          this.$vux.loading.hide();
        });
      },
94c1e6a3   liuqimichale   微信公众号 个人页面集合
142
    }
71ca44b6   刘淇   个人中心
143
  };
94c1e6a3   liuqimichale   微信公众号 个人页面集合
144
145
146
147
  </script>
  
  <style scoped lang="scss">
    .getCode {
71ca44b6   刘淇   个人中心
148
      width: 120px;
94c1e6a3   liuqimichale   微信公众号 个人页面集合
149
150
      height: 48px;
      line-height: 48px;
6e6de4e6   刘淇   修改整体颜色
151
      background: #26a2ff;
94c1e6a3   liuqimichale   微信公众号 个人页面集合
152
153
      color: #fff;
      text-align: center;
71ca44b6   刘淇   个人中心
154
155
      border: 0;
      margin-right: -10px
94c1e6a3   liuqimichale   微信公众号 个人页面集合
156
157
    }
  </style>