selfNav.vue
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<div>
<div class="person-bg">
<div class="person-ifo">
<div class="person-pic"></div>
<ul class="person-con">
<li>{{ phoneNum }}</li>
<li>账户余额: <span>¥ {{ acctBalance }}</span></li>
<li>我的卡券:<span>{{couponNum}} 张</span></li>
</ul>
</div>
</div>
<mt-cell title="会员卡" is-link :to="{ name: 'Toast' }"></mt-cell>
<mt-cell title="车辆管理" is-link :to="{ name: 'Toast' }"></mt-cell>
<mt-cell title="停车记录" is-link :to="{ name: 'parkNotes' }"></mt-cell>
<mt-cell title="建议反馈" is-link :to="{ name: 'suggestionBack' }"></mt-cell>
<div class="leftRightPadding" style="margin-top: 34px">
<mt-button type="danger" size="large" @click="toBinDing">退出账户</mt-button>
</div>
</div>
</template>
<script>
import { getOpenIdByCode, getTokenByOpenId, queryUserInfo } from '@/api/selfNav/selfNav'
export default {
name: 'selfNav',
data(){
return {
couponNum:'3', // 卡券数量
acctBalance: '420.00', // 账户余额
phoneNum:'',// 用户手机号
}
},
created() {
if (this.$utils.clientBrowser() == "微信") {
var appID = this.$utils.myVxAppId;
var code = this.getUrlParam('code');
var local = window.location.href;
if (code == null || code === '') {
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appID+'&redirect_uri='+encodeURIComponent(local)+'&response_type=code&scope=snsapi_userinfo&state=1,0#wechat_redirect'
} else {
return code;
}
}
},
mounted() {
if(this.$utils.GetOpenid()){
this.getTokenByOpenId(this.$utils.GetOpenid())
}else{
this.getOpenId()
}
},
methods: {
getUrlParam(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
var r = window.location.search.substr(1).match(reg)
if (r != null) return unescape(r[2])
return null
},
getOpenId: function () { // 第一步获取openid
let getCode = location.href
console.log(getCode)
let dataCode = getCode.split('?')[1]
let wxCode = dataCode.split('&')[0].split('=')[1]
let jsondata = {
appId: this.$utils.myVxAppId,
code: wxCode
};
getOpenIdByCode(jsondata).then(data => {
console.log(data)
// SetOpenid
if(data.code=='0'){
let openid = data.data;
this.$utils.SetOpenid(openid);
// mUrl.setApporWX('wx');
console.log("用户 openid "+openid);
this.getTokenByOpenId(openid)
}
})
},
getTokenByOpenId: function (openid) { // 获取token和手机号
let jsondata = {
openid: 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);
this.$utils.SetToken(data.data.token)
this.$utils.SetPhone(data.data.phoneNum)
this.phoneNum = data.data.phoneNum
// 用户已经绑定手机号,获取用户信息
this.getInfoSelf()
}else{
// 用户未绑定手机号
this.$router.push({
path: 'binDing'
})
}
})
},
getInfoSelf: function () { // 获取用户信息
let salt = this.$utils.myCommonSalt(32);
var jsondata = {
app_id: this.$utils.myVarAppid,
deviceInfo: this.$utils.myDeviceInfo,
salt: salt,
sign_type: "md5",
token: this.$utils.GetToken(),
}
jsondata.sign = this.$utils.signObject(jsondata)
queryUserInfo(jsondata).then(data => {
console.log(data)
if(data.code == '0'){
let datas = data.data
this.couponNum = datas.couponNum;//卡券数量
this.acctBalance = (datas.acctBalance/100).toFixed(2);//账户余额 单位:分
}
})
},
toBinDing: function () { // 退出账户 去绑定页面
this.$router.push({
path:'binDing'
})
}
}
}
</script>
<style scoped lang="scss">
.person-bg {
height: 160px;
background: url("../../assets/images/mySelf/selfNavBg.png") no-repeat;
background-size: 100% 100%;
}
.person-ifo {
padding: $commonLeftRightPadding;
padding-top: 45px;
display: flex;
color: #ffbfbf;
.person-pic {
width: 64px;
height: 64px;
margin-right: 15px;
background: url("../../assets/images/mySelf/photoBG.png") no-repeat;
}
}
.person-con {
span {
font-size: 16px;
font-weight: bold;
}
}
.mint-cell {
border-bottom: 1px solid #EFEDED;
}
</style>