移动系统liao
2024-05-15 d7c7a6e9d05eec7b38b41b8ae39f373f650ca891
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="门店列表" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="content">
            <view class="map-body">
                <map style="width: 100%;height: 100%;" id="map"
                     :scale="11"
                     :enable-3D="true"
                     :show-compass="true"
                     :enable-overlooking="true"
                     :enable-traffic="true"
                     :latitude="latitude"
                     :longitude="longitude"
                     :markers="covers">
                </map>
            </view>
            <scroll-view class="store-list" scroll-y>
                <view class="coreshop-margin-top-15" v-if="storeList.length>0">
                    <view class="coreshop-list menu-avatar" v-for="(item, key) in storeList" :key="key">
                        <view class="coreshop-list-item">
                            <image class="coreshop-avatar lg radius" :src="item.logoImage" mode="aspectFill"></image>
                            <view class="content">
                                <view class="coreshop-text-grey coreshop-padding-bottom-5">{{item.storeName|| ''}}</view>
                                <u-icon name="phone" size="16" :label="item.mobile"  @tap="doPhoneCall(item.mobile)"></u-icon>
                                <view class="u-line-2 coreshop-font-xs  coreshop-padding-top-5">
                                    地址:{{item.address}}
                                </view>
                            </view>
                            <view class="action" @click="goMarkers(item.latitude,item.longitude)">
                                <view class="coreshop-text-grey coreshop-font-xs coreshop-margin-bottom-10">{{item.distanceStr|| ''}}</view>
                                <view class="coreshop-width-fit-content coreshop-margin-bottom-10">
                                    <u-button text="上图定位" type="success" size="mini" />
                                </view>
                                <!-- #ifdef MP-WEIXIN  -->
                                <view class="coreshop-width-fit-content" @tap="goShopMap(item.address,item.latitude,item.longitude)">
                                    <u-button text="地图导航" type="success" size="mini" />
                                </view>
                                <!-- #endif  -->
                            </view>
                        </view>
                    </view>
                </view>
                <!-- 无数据时默认显示 -->
                <view class="coreshop-emptybox" v-else>
                    <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/history.png'" icon-size="150" text="暂无门店列表" mode="list"></u-empty>
                </view>
 
            </scroll-view>
        </view>
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                storeList: [],
                longitude: 0,
                latitude: 0,
                covers: [{
                    'longitude': 0,
                    'latitude': 0
                }],
                page: 1,
                limit: 30,
            };
        },
        onLoad() {
            this.getMyLocation();
        },
        methods: {
            // 获取自己的位置信息
            getMyLocation() {
                let _this = this;
                // #ifdef MP-WEIXIN
                wx.getFuzzyLocation({
                    type: 'wgs84',
                    success(res) {
                        _this.longitude = res.longitude;
                        _this.latitude = res.latitude;
                        _this.getStoreList();
                    },
                    fail: function () {
                        _this.$u.toast("获取您的经纬度坐标失败")
                    },
                    complete: function (res) {
                        if (!_this.longitude || !_this.latitude) {
                            _this.longitude = '0';
                            _this.latitude = '0';
                        }
                        _this.getStoreList();
                    }
                })
                // #endif
                // #ifndef MP-WEIXIN
                uni.getLocation({
                    type: 'wgs84',
                    success: function (res) {
                        _this.longitude = res.longitude;
                        _this.latitude = res.latitude;
                        _this.getStoreList();
                    },
                    fail: function () {
                        _this.$u.toast("获取您的经纬度坐标失败")
                    },
                    complete: function (res) {
                        if (!_this.longitude || !_this.latitude) {
                            _this.longitude = '0';
                            _this.latitude = '0';
                        }
                        _this.getStoreList();
                    }
                });
                // #endif
            },
            // 获取店铺列表信息
            getStoreList() {
                let _this = this;
                let data = {
                    'longitude': _this.longitude,
                    'latitude': _this.latitude,
                    'page': _this.page,
                    'limit': _this.limit,
                }
                _this.$u.api.storeList(data).then(res => {
                    if (res.status) {
                        _this.storeList = res.data;
                        let storeList = res.data;
                        if (storeList.length > 0) {
                            _this.longitude = storeList[0].longitude;
                            _this.latitude = storeList[0].latitude;
                            for (let i = 0; i < storeList.length; i++) {
                                let mark = {
                                    id: storeList[i].id,
                                    latitude: storeList[i].latitude,
                                    longitude: storeList[i].longitude,
                                    iconPath: '/static/images/map/location.png',
                                    width: 15,
                                    height: 23,
                                }
                                _this.covers.push(mark);
                            }
                        }
                    } else {
                        _this.$u.toast("门店信息获取失败")
                    }
                });
            },
            //查看所在坐标地图位置
            goShopMap(address,latitude, longitude) {
                let plugin = requirePlugin('routePlan');
 
                // #ifdef MP-WEIXIN
                const txMapkey = this.$store.state.config.qqMapKey; //使用在腾讯位置服务申请的key
                const referer = this.$store.state.config.shopName; //调用插件的app的名称
                let endPoint = JSON.stringify({  //终点
                    'name': address,
                    'latitude': latitude,
                    'longitude': longitude
                });
 
                wx.navigateTo({
                    url: 'plugin://routePlan/index?key=' + txMapkey + '&referer=' + referer + '&endPoint=' + endPoint
 
                });
                // #endif
            },
            doPhoneCall(phome) {
                if (phome != 0) {
                    uni.makePhoneCall({
                        phoneNumber: phome
                    });
                }
            },
            goMarkers(latitude, longitude) {
                this.longitude = longitude;
                this.latitude = latitude;
            }
        }
    };
</script>
 
<style scoped lang="scss">
    @import "storeMap.scss";
</style>