Blame view

src/views/binding/binDing.vue 4.11 KB
94c1e6a3   liuqimichale   微信公众号 个人页面集合
1
2
3
  <template>
    <div>
  
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
4
      <mt-field label="手机号" placeholder="请输入正确的手机号" type="tel" v-model.trim="phone" :attr="{ maxlength: 11 }"></mt-field>
94c1e6a3   liuqimichale   微信公众号 个人页面集合
5
  
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
6
7
      <mt-field label="验证码" v-model.trim="codeText" :attr="{ maxlength: 6 }">
        <div class="getCode" @click="getCodeHandle">{{timeNum}}</div>
94c1e6a3   liuqimichale   微信公众号 个人页面集合
8
9
10
      </mt-field>
  
      <div style="margin-top: 34px" class="leftRightPadding">
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
11
        <mt-button type="danger" size="large" @click="bingUser">绑定</mt-button>
94c1e6a3   liuqimichale   微信公众号 个人页面集合
12
13
14
15
16
      </div>
    </div>
  </template>
  
  <script>
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
17
18
  import { sendverificode, bindCustByOpenId } from '@/api/binDing/binDing'
  
94c1e6a3   liuqimichale   微信公众号 个人页面集合
19
20
21
22
23
24
25
26
  export default {
    name: 'binDing',
    data() {
      return {
        codeText: '',
        phone: '',
        timeText: '获取验证码',
        timeNum: 60,
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
27
        clickFlag: true, // 获取验证码按钮是否可以点击
94c1e6a3   liuqimichale   微信公众号 个人页面集合
28
29
      }
    },
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
30
    created() {
94c1e6a3   liuqimichale   微信公众号 个人页面集合
31
32
33
      this.timeNum = this.timeText
    },
    methods: {
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      getCodeHandle: function () { // 获取验证码事件
        if (!(/^1[3456789]\d{9}$/.test(this.phone))) {  // 先判断手机号是否输入正确
          this.$msgbox('提示', '请输入正确手机号')
        } else {
          if (this.clickFlag) {
            let _this = this
            this.clickFlag = false
  
            _this.getCode()
            // this.timeText = this.timeNum+'S'
            let Num = 5
            var timer = setInterval(function () {
              _this.timeNum = Num-- + 's'
              if (Num == -1) {
                _this.clickFlag = true
                _this.timeNum = _this.timeText
                Num = 5
                clearInterval(timer)
              }
            }, 1000)
94c1e6a3   liuqimichale   微信公众号 个人页面集合
54
          }
49f85de6   liuqimichale   黄石微信公众号 -- 临停支付
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        }
      },
      getCode: function () {  //  获取验证码接口
        let salt = this.$utils.myCommonSalt(32);
        let jsondata = {
          app_id: this.$utils.myVarAppid,
          deviceInfo: this.$utils.myDeviceInfo,
          salt: salt,
          sign_type: "md5",
          phone: this.phone
        }
        jsondata.sign = this.$utils.signObject(jsondata)
        sendverificode(jsondata).then(response => {
          this.$toast({
            message: '获取验证码成功',
            iconClass: 'icon icon-success',
            duration: 1500
          })
        })
      },
  
      bingUser: function () { // 用户绑定
        let openid = this.$utils.GetOpenid();
  
        if (!(/^1[3456789]\d{9}$/.test(this.phone))) {  // 先判断手机号是否输入正确
          this.$toast({
            message: '请输入正常手机号',
            duration: 1500
          });
          return
        }
        if (this.codeText.length < 6) {
          this.$toast({
            message: '请输入正常验证码',
            duration: 1500
          });
          return
        }
  
        let jsondata = {
          phoneNum: this.phone,
          verifyCode: this.codeText,
          openid: openid
        }
  
        bindCustByOpenId(jsondata).then(data => {
          if (data.code == 0 || data.code == '0') {
            // $.alert('亲,您已绑定成功!', '成功', function () {
            //   var datas = data.data;
            //   var urll = document.referrer;
            //   jsajax.gett(openid, function (n) {
            //     window.location.href = document.referrer;
            //   });
            // });
  
            this.$messagebox.alert('亲,您已绑定成功!').then(action => {
              this.$router.push({
                path:'selfNav'
              })
            });
  
          } else {
            if (data.code == 1017 || data.code == '1017') {
              // $.alert('已经绑定过', function () {
              //   var urll = document.referrer;
              //   jsajax.gett(openid, function (n) {
              //     window.location.href = document.referrer;
              //   });
              // });
  
  
              this.$messagebox.alert('亲,您已经绑定过!').then(action => {
  
              });
  
            } else {
              // $.alert('亲,请重新绑定!', '失败', function () {
              //   return false;
              // });
              this.$toast('亲,绑定失败,请重新绑定!')
            }
  
          }
        })
  
94c1e6a3   liuqimichale   微信公众号 个人页面集合
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
      }
    }
  }
  </script>
  
  <style scoped lang="scss">
    .getCode {
      width: 100px;
      height: 48px;
      line-height: 48px;
      background: #ef4f4f;
      color: #fff;
      text-align: center;
    }
  </style>