code.vue
8.38 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<template>
<div class="bg" v-loading="loading">
<van-field v-model="form.area" readonly label="" placeholder="请选择所在地区" @click="addressShow = true" />
<van-field readonly clickable :value="currentItem.storeName" placeholder="请选择门店" @click="showPicker = true" />
<template v-if="!columns.length">
<div class="tip">
{{ data.outOfRangeTip }}
</div>
<div class="code_content">
<img class="code_img" v-if="data.codeState === 1" src="../../assets/no_code.svg" alt="" />
<img class="code_img" v-else :src="data.customerServiceUrl" alt="" />
</div>
<div class="sub-des" v-if="data.codeState !== 1">
长按识别二维码添加客服
</div>
</template>
<template v-else>
<div class="tip">
{{ welcomeMsg }}
</div>
<div class="code_content">
<img
class="code_img"
@touchstart="setStart"
@touchend="setEnd"
v-if="currentItem.groupCodeUrl"
:src="currentItem.groupCodeUrl"
alt=""
/>
<img class="code_img" v-else src="../../assets/no_code.svg" alt="" />
<!-- <img class="code_img" v-else src="../../../assets/drainageCode/code.png" alt=""> -->
</div>
<div class="sub-des">
长按识别二维码添加添加门店群
</div>
<div class="tip" style="margin-top: 20px; font-size: 16px;">
<van-icon name="location-o" /> {{ currentItem.address }}
</div>
</template>
<van-popup v-model="showPicker" round position="bottom">
<van-picker
value-key="storeName"
show-toolbar
:columns="columns"
@cancel="showPicker = false"
@confirm="onConfirm"
/>
</van-popup>
<van-popup v-model="addressShow" round position="bottom">
<van-cascader
v-model="area"
title="请选择所在地区"
:options="addressOptions"
:field-names="{
text: 'name',
value: 'name'
}"
@close="addressShow = false"
@finish="selectedArea"
/>
</van-popup>
</div>
</template>
<script>
import { getWxCode, getQueryValue, baiduMapError, splitName } from '@/utils/index'
import { getAreaList, getWxTicket } from '@/api/common'
import { getCodeInStore, getCodeBase, recordCode } from '@/api/groupCode'
export default {
name: 'store-group-code',
data() {
return {
loading: false,
area: '',
userInfo: {},
tenantId: '',
addressOptions: [],
addressShow: false,
welcomeMsg: '',
form: {
area: '',
areaId: '',
latitude: '',
longitude: ''
},
showPicker: false,
columns: [],
value: '',
data: {
outOfRangeTip: '',
codeState: 1,
customerServiceUrl: ''
},
currentItem: {
storeName: '',
address: ''
},
showTip: false,
query: {
currentLat: '',
currentLng: '',
storeCodeId: '',
unionid: '',
source: 2,
tenantId: ''
}
}
},
methods: {
setStart() {
this.timer = setTimeout(() => {
this.query.storeCodeId = this.currentItem.id
this.query.unionid = this.userInfo.unionId
this.query.tenantId = sessionStorage.getItem('tenantId')
recordCode(this.query)
}, 500)
},
setEnd() {
clearTimeout(this.timer)
},
selectedArea({ selectedOptions }) {
this.addressShow = false
delete this.form.latitude
delete this.form.longitude
this.form.area = selectedOptions.map((option) => option.name).join('')
this.getStoreList()
},
getAreaList() {
getAreaList().then(({ data }) => {
this.addressOptions = data
})
},
onConfirm(data, index) {
if (data) {
this.currentItem = data
}
this.showPicker = false
},
getStoreList(type) {
this.loading = true
getCodeInStore({
storeCodeType: 2,
unionid: this.userInfo.unionId,
longitude: this.form.longitude,
latitude: this.form.latitude,
area: this.form.area,
tenantId: sessionStorage.getItem('tenantId')
}).then((res) => {
if (res.code === 200) {
this.welcomeMsg = res.data.welcomeMsg
this.columns = res.data.weStoreCodes
if (!this.columns || this.columns.length === 0) {
this.currentItem = {
storeName: '',
address: ''
}
this.getNullFn()
} else {
if (type) {
this.currentItem = this.columns[0]
this.form.area = this.currentItem.area
let arr = splitName(this.currentItem.area)
if (arr[2]) {
this.area = [2]
}
} else {
this.currentItem = this.columns[0]
}
}
}
this.loading = false
})
},
getNullFn() {
getCodeBase({ storeCodeType: 2, tenantId: sessionStorage.getItem('tenantId') }).then((res) => {
if (res.code === 200 && res.data) {
this.data = res.data
}
})
},
back() {
document.addEventListener(
'WeixinJSBridgeReady',
function () {
WeixinJSBridge.call('closeWindow')
},
false
)
WeixinJSBridge.call('closeWindow')
}
},
async mounted() {
await getWxCode()
if (getQueryValue('code') && getQueryValue('state')) {
this.userInfo = JSON.parse(sessionStorage.getItem('userinfo'))
this.getAreaList()
let _that = this
this.loading = true
getWxTicket(window.location.href.split('#')[0]).then((res) => {
if (res.code === 200) {
let { timestamp, nonceStr, signature } = res.data
wx.config({
beta: true,
// debug: true,
appId: sessionStorage.getItem('weAppId'),
timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['getLocation'], //必填
success: function (res) {},
fail: (res) => {
_that.loading = false
alert('config失败:' + JSON.stringify(res))
if (res.errMsg.indexOf('function not exist') > -1) {
alert('版本过低请升级')
}
}
})
wx.ready(function () {
wx.getLocation({
type: 'wgs84', //默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (dd) {
_that.form.latitude = dd.latitude
_that.form.longitude = dd.longitude
_that.query.currentLat = dd.latitude
_that.query.currentLng = dd.longitude
_that.getStoreList('init')
},
fail: function (ff) {
alert('获取定位位置信息失败')
_that.loading = false
_that.back()
},
cancel: function (ff) {
_that.back()
}
})
})
}
})
}
// else {
// if (getQueryValue('state')) {
// this.back()
// }
// }
},
created() {
this.tenantId = this.$route.query.tenantId
sessionStorage.setItem('tenantId', this.tenantId)
}
}
</script>
<style lang="less" scoped>
.bg {
background: linear-gradient(180deg, #eaf5ff 0%, rgba(253, 253, 253, 0) 100%);
border-radius: 0px 0px 0px 0px;
}
.tip {
padding: 0 20px;
font-size: 12px;
margin-top: 30px;
text-align: center;
}
.code_content {
margin-top: 10px;
text-align: center;
.code_img {
height: 180px;
width: 180px;
margin: 10px auto;
}
}
.sub-des {
text-align: center;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
}
</style>