scan-result.js
3.6 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import {
getBindtapData,
getQueryByUrl
} from '../../utils/util';
let app = getApp();
Page({
data: {
authorizeVisible: false,
qrCodeCode: "",
prizeInfo: null, //扫码结果
userInfo: {}, //用户信息
scaning: false,
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onShow() {
wx.setNavigationBarTitle({
title: '积分获取'
})
},
onLoad(options) {
// 手输码
let code = options.code || "";
if (code) {
this.setData({
code: code
})
}
this.initData();
},
initData() {
// 可能要拉授权
this.queryMember().then((result) => {
this.queryScanIntegralQrcode().then((result) => {}).catch((err) => {});
});
},
/**
* 获取会员信息
*/
queryMember() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.member,
data: {}
}).then((result) => {
this.setData({
userInfo: result
})
resolve();
})
});
},
/**
* 扫积分码功能 扫积分码
*/
queryScanIntegralQrcode(c) {
return new Promise((resolve, reject) => {
let {
code
} = this.data;
if (c) code = c;
if (code) {
wx.showLoading({
title: "扫码中",
mask: true,
})
this.setData({
scaning: true,
})
wx.setNavigationBarTitle({
title: '积分获取'
})
app.post({
url: app.api.scanIntegralQrcode,
data: {
qrCodeCode: code
}
}).then((result) => {
wx.hideLoading();
this.setData({
prizeInfo: result,
scaning: false
})
if (result.qrCodeStatus != 1) {
wx.setNavigationBarTitle({
title: '积分获取失败'
})
} else {
wx.setNavigationBarTitle({
title: '积分获取成功'
})
}
}).catch((err) => {
wx.hideLoading();
this.setData({
prizeInfo: {},
scaning: false
})
wx.setNavigationBarTitle({
title: '积分获取失败'
})
});
} else {
this.setData({
prizeInfo: {}
})
wx.setNavigationBarTitle({
title: '积分获取失败'
})
}
});
},
/**
* 点击扫码按钮
*/
onScanHandler() {
let _this = this;
wx.scanCode({
onlyFromCamera: true,
success(res) {
// 扫码结果
let q = res.result;
// 获取积分码
let c = getQueryByUrl("c", q);
if (c) {
_this.queryScanIntegralQrcode(c);
} else {
wx.showModal({
content: '未发现积分码,换一个二维码试试',
showCancel: false,
success(res) {}
})
}
},
fail(err) {
console.log("err:", err);
}
})
},
/**
* 查看我的积分
*/
onMyIntegralHandler(evt) {
app.router.push({
openType: "redirect",
path: "integralDetail"
})
},
// 隐藏蒙层
hideMask() {
this.setData({
authorizeVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
case "_evt_hide_mask":
this.hideMask();
break;
// 授权完毕
case "_evt_auth_complete":
this.initData();
this.hideMask();
break;
default:
break;
}
},
})