MrShi
10 小时以前 ac33a3140ef8ef20dfd2537fce2dfdd0f374f30e
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
284
285
286
287
288
<script>
    var QQMapWX = require('@/utils/qqmap-wx-jssdk.js')
    import { mapState } from 'vuex'
    export default {
        computed: {
            ...mapState(['userInfo', 'token'])
        },
        onLaunch: async function(options) {
            // this.dealRecShopUserBiz(options) 
            // 登录
            var that = this;
            if (!this.token) {
                uni.login({
                    provider: 'weixin',
                    success: async function (loginRes) {
                        let { code } = loginRes;
                        let res = await that.$u.api.wxLogin({ code })
                        if (res.code === 200) {
                            // 判断有无openid
                            if (res.data.openid) {
                                await that.$store.commit('setOpenId', res.data.openid)
                            }
                            // 判断有无token
                            if (res.data.token) {
                                await that.$store.commit('setToken', res.data.token)
                            }
                            // 判断有无用户信息
                            if (res.data.member) {
                                await that.$store.commit('setUserInfo', res.data.member)
                                await that.$store.commit('setOpenId', res.data.member.openId)
                            }
                            // 设置定位
                            await that.checkLocationAuth()
                        }
                    }
                });
            } else {
                // 缓存用户信息
                let res = await that.$u.api.getUserInfo()
                if (res.code === 200) {
                    await that.$store.commit('setUserInfo', res.data)
                    await that.$store.commit('setOpenId', res.data.openId)
                }
                // 设置定位
                await that.checkLocationAuth()
            }
        },
        onShow:async function(options) {
            this.dealRecShopUserBiz(options) 
        },
        onHide: function() {
            console.log('App Hide')
        },
        methods: {
            async dealRecShopUserBiz(options){
                console.error("启动参数",options)
                if(options.query && options.query.userId){
                    if(!this.userInfo || !this.userInfo.id){
                        await this.$store.commit('setRecUserId',options.query.userId)
                    }
                }
                if(options.query && options.query.scene &&  options.query.scene.length){
                    if(options.query.scene.indexOf("sid_")>=0){
                         let s = options.query.scene.indexOf("sid_")+4;
                         var shopId = '';
                         let e = options.query.scene.length
                         let ts =  options.query.scene.slice(s, e)
                         e = ts.length
                         if(ts.indexOf("&")>0){
                             e =ts.indexOf("&")
                         }
                         if(e>0){
                            shopId =ts.slice(0, e)
                         } 
                         if(shopId){
                             if(this.userInfo&& this.userInfo.id){
                                 try{
                                     let res = await this.$u.api.bindShopInfo({ code })
                                     if(res.code != 200){
                                         await this.$store.commit('setRecShopId',shopId)
                                     }
                                 }catch(e){
                                      await this.$store.commit('setRecShopId',shopId)
                                 }
                             }else{
                                 await this.$store.commit('setRecShopId',shopId)
                             }
                             
                         }
                    }
                }
            },
            checkLocationAuth() {
                uni.getSetting({
                    success: (res) => {
                        if (!res.authSetting['scope.userLocation']) {
                            uni.authorize({
                                scope: 'scope.userLocation',
                                success: () => {
                                    this.positioning()
                                },
                                fail: () => {
                                    uni.showModal({
                                        title: '提示',
                                        content: '需要获取您的位置信息,请在设置中开启位置权限',
                                        confirmText: '去设置',
                                        success: (res) => {
                                            if (res.confirm) {
                                                this.goToAppSetting();
                                            } else {
                                                this.$isResolve()
                                            }
                                        }
                                    });
                                }
                            });
                        } else {
                            this.positioning()
                        }
                    }
                });
            },
            goToAppSetting() {
                var that = this;
                uni.openSetting({
                    success: (res) => {
                        if (res.authSetting['scope.userLocation']) {
                            that.positioning()
                        }
                        that.$isResolve()
                    }
                });
            },
            // 定位
            positioning() {
                var that = this;
                uni.getLocation({
                    type: 'gcj02',
                    highAccuracyExpireTime: 3000,
                    isHighAccuracy: true,
                    success: function (addr) {
                        const locParam = { latitude: addr.latitude, longitude: addr.longitude };
                        const qqmapsdk = new QQMapWX({
                            key: 'HEIBZ-QJLLM-SZ36X-6ZBHI-S6Y2J-S6FND'
                        });
                        console.log(locParam)
                        qqmapsdk.reverseGeocoder({
                            locParam,
                            success: function(res) {
                                console.log(res, '==================获取地址');
                                that.$store.commit('setPosition', res.result)
                                that.$isResolve()
                            },
                            fail: (err) => {
                                console.error('获取位置失败===========', err);
                                that.$isResolve()
                            }
                        });
                    }
                });
            }
        }
    }
</script>
 
<style lang="scss">
    @import "uview-ui/index.scss";
    /*每个页面公共css */
    .tc {
        width: calc(100vw - 148rpx);
        .tc-btn {
            width: 100%;
            height: 102rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-top: 1rpx solid #EEEEEE;
            .tc-btn-item {
                flex: 1;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-weight: 400;
                font-size: 32rpx;
                color: #666666;
                border-right: 1rpx solid #EEEEEE;
                &:last-child {
                    border: none !important;
                }
            }
        }
        .tc-contemt {
            width: 100%;
            padding: 40rpx 0;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            .tc-contemt-title {
                width: 100%;
                text-align: center;
                font-weight: 600;
                font-size: 32rpx;
                color: #111111;
            }
            .tc-contemt-nr {
                width: 472rpx;
                text-align: center;
                font-weight: 400;
                font-size: 28rpx;
                color: #333333;
                margin-top: 40rpx;
            }
        }
    }
    .nomore{
        margin-top: 30rpx;
        width: 100%;
        text-align: center;
        font-size: 24rpx;
        color: #666666;
    }
    .phone {
        width: 100%;
        padding-top: 40rpx;
        box-sizing: border-box;
        .phone-botton {
            width: 100%;
            height: 88rpx;
            line-height: 88rpx;
            text-align: center;
            font-weight: 500;
            font-size: 32rpx;
            color: #FFFFFF;
            background: #00BC12;
            border-radius: 44rpx;
            margin-top: 60rpx;
        }
        .phone-head {
            width: 100%;
            text-align: center;
            justify-content: space-between; 
            margin-bottom: 40rpx;
            text {
                font-weight: 800;
                font-size: 32rpx;
                color: #222222;
            }
        }
         
        .phone-item {
            width: 100%;
            text-align: center;
            display: flex;
            justify-content: center;
            flex-direction: column;
            // border-bottom: 1rpx solid #eeeeee;
            line-height: 78rpx;
            button{
                border: 1rpx white solid;
                display: inline;
                width: 300rpx;
                font-weight: 500;
                font-size: 32rpx;
                line-height: 32rpx;
                color: #222222;
            }
            image{
                width: 28rpx;
                height: 28rpx;
                margin-right: 30rpx;
            }
            .line{
                width: 100%;
                height: 1rpx;
                background-color: #f2f2f2
            }
            text {
                font-weight: 500;
                font-size: 28rpx;
                line-height: 28rpx;
                color: #222222;
            }
        }
    }
</style>