819527061@qq.com
2024-05-11 f73ed7862edc9c3cb78a2610486643a2fa079fde
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
<template>
    <view class="index-wrap">
        <view class="page-body">
            <view class="page-section page-section-gap">
                <map style="width: 100%;height: 100vh" 
                   id="map"
                   :scale="scale" 
                   :latitude="mymarker.latitude" 
                   :longitude="mymarker.longitude" 
                   :markers="markers"
                   :polyline="polyline">
                </map>
            </view>
        </view>
        <view class="jiayou-box" @click="comeBtn">
            <image class="comeImg" src="../../static/icon/come.png" mode="aspectFill"></image>
            <text>加油助力</text>
        </view>
        <!-- 今日配送订单 -->
        <myHasOrder v-if="myHasOrderVisiable" ref="myHasOrder"></myHasOrder>
 
        <!-- 加油助力弹框 -->
        <comeOn v-if="comeOnVisiable"></comeOn>
 
    </view>
 
</template>
 
<script>
    
    // 引入SDK核心类
    export default {
        data() {
            return {
                flag:true,
                myHasOrderVisiable: false, //今日订单弹框
                comeOnVisiable: false, //加油助力弹框
                id: 0, // 使用 marker点击事件 需要填写id
                title: 'map',
                scale: 14,
                latitude: '',
                longitude: '',
                polyline: [{ //路线
                    points: [],
                    color: '#FF9100',
                    width: 3,
                    arrowLine: true,
                    borderWidth: 0,
                    dottedLine: true
                }],
                mypoints: {
                    latitude: null,
                    longitude: null,
                },
                shoppoints: {
                    latitude: null,
                    longitude: null,
                },
                mymarker: {
                    latitude: 39.635113,
                    longitude: 118.175393,
                    // iconPath: '/static/icon/position.png',
                    // width: 32,
                    // height: 32,
 
                },
                shopmarker: {
                    latitude: null,
                    longitude: null,
                    // iconPath: '/static/icon/car.png',
                    // width: 58,
                    // height: 58,
                    // callout: { //气泡
                    //     content: '',
                    //     color: '#111111',
                    //     fontSize: 14,
                    //     bgColor: '#FFFFFF',
                    //     padding: 10,
                    //     display: "ALWAYS",
                    //     borderRadius: 6,
                    //     anchorX: 114.529311,
                    //     // anchorY:38.047100,
 
                    // }
                },
                markers: []
            }
        },
        onReady() {
            
        },
        onShow() {
            this.login()
            if (this.$store.state.customerId) { //如果不是第一次登录的
                this.refesh()
                this.getMarks() //获取商家位置
                this.getCarInfo() //获取车辆的位置
                this.myHasOrderVisiable = true
                this.$nextTick(() => {
                    this.$refs.myHasOrder.init()
                })
            }
            
        },
        onPullDownRefresh() {
            this.getMarks() //获取商家位置
            this.getCarInfo() //获取车辆的位置
        },
        methods: {
            refesh() {
                this.mymarker = {}
                this.polyline[0].points=[];
                this.markers = []
            },
            getMarks() {
                if(this.$store.state.lat && this.$store.state.lng) {
                    this.mymarker.latitude = this.mypoints.latitude = this.$store.state.lat
                    this.mymarker.longitude = this.mypoints.longitude = this.$store.state.lng
                    let a = this.bd_decrypt(this.mymarker.longitude,this.mymarker.latitude);
                    this.mymarker = {
                        latitude: a.latitude,
                        longitude: a.longitude,
                        iconPath: '/static/icon/position.png',
                        width: 32,
                        height: 32,
                    }
                    this.markers.push(this.mymarker)
                    this.polyline[0].points.push(this.mymarker)
                }
                
            },
 
            getCarInfo() { //获取车辆位置
                let customerId = this.$store.state.customerId
 
                this.$u.api.getCarInfo({
                    customerId: customerId
                }).then(res => {
                    console.log(res.result,'res.result.lng====res.result.lng')
                    if (res.code == 200) {
                        console.log('我进来了')
                        if(res.result.lng && res.result.lat) {
                            this.shopmarker.longitude = this.shoppoints.longitude = Number(res.result.lng)
                            this.shopmarker.latitude = this.shoppoints.latitude = Number(res.result.lat)
                            let a = this.bd_decrypt(this.shopmarker.longitude,this.shopmarker.latitude);
                            console.log('a==========a',a)
                            this.shopmarker = {
                                latitude: a.latitude,
                                longitude: a.longitude,
                                iconPath: '/static/icon/car.png',
                                width: 58,
                                height: 58,
                                callout: { //气泡
                                    content: res.result.content,
                                    color: '#111111',
                                    fontSize: 14,
                                    bgColor: '#FFFFFF',
                                    padding: 10,
                                    display: "ALWAYS",
                                    borderRadius: 6,
                                    anchorX: 0,
                                    // anchorY:38.047100,
                                }
                            },
                            this.markers.push(this.shopmarker)
                            this.polyline[0].points.push(this.shoppoints)
                            uni.stopPullDownRefresh()
                        }
                        
                    } else {
                        console.log(res.message,'无数据')
                    }
                })
            },
            comeBtn() { //加油助力
                let customerId = this.$store.state.customerId
                this.$u.api.likes({
                    customerId: customerId
                }).then(res => {
                    if (res.code == 200) {
                        this.comeOnVisiable = true
                        setTimeout(() => {
                            this.comeOnVisiable = false
                            this.$u.toast(res.message)
                        }, 2000)
                    }
                })
            },
            login() { //判断是否是第一岑登录
                let _this = this
                uni.login({
                    provider: 'weixin',
                    success: function(loginRes) {
                        _this.$u.api.wxlogin({
                            code: loginRes.code
                        }).then(res => {
                            if (res.success) {
                                // if(!_this.flag) {
                                //     return
                                // }
                                // _this.flag = false
                                let re = res.result
                                console.log(re,'re===')
                                /* *******测试数据******* */
                                // re.lat = 38.048800
                                // re.lng =  114.529311
                                _this.$store.commit("login", re)
                                let openId = res.result.openId
                                // _this.$store.commit('setOpenId',openId)
                                _this.getMarks() //获取商家位置
                                _this.getCarInfo() //获取车辆的位置
                                _this.myHasOrderVisiable = true
                                _this.$nextTick(() => {
                                    _this.$refs.myHasOrder.init()
                                })
                
                            } else {
                                let openId = res.message
                                // _this.$store.commit('setOpenId',openId)
                                uni.navigateTo({
                                    url: '/pagesA/login/login?openId=' + openId
                                })
                            }
                        })
                    }
                })
                
                
                
            },
           //百度地图转高德 坐标
            bd_decrypt (bd_lng, bd_lat) {
              var X_PI = Math.PI * 3000.0 / 180.0;
              var x = bd_lng - 0.0065;
              var y = bd_lat - 0.006;
              var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
              var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
              var gg_lng = z * Math.cos(theta);
              var gg_lat = z * Math.sin(theta);
              return { longitude: gg_lng, latitude: gg_lat }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .jiayou-box {
        position: absolute;
        bottom: 40rpx;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background-color: #fff;
        box-shadow: 0rpx 0rpx 20rpx rgba(0, 0, 0, 0.24);
        width: 160rpx;
        height: 160rpx;
        border-radius: 12rpx;
 
        .comeImg {
            width: 80rpx;
            height: 80rpx;
        }
 
        text {
            font-size: 28rpx;
            font-weight: Light;
            color: #E58200;
            line-height: 2;
        }
    }
</style>