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
<template>
    <view>
        <view class="address-list bg-white">
            <view class="address p30 d-s-c border-b-e" v-for="(item,index) in storeList" :key="index">
                <view class="info flex-1" @click="onSelectedStore(item)">
                    <view class="user f34">
                        <text>{{item.store_name}}</text>
                    </view>
                    <view class="pt10 user f30 gray6">
                        <text>{{item.phone}}</text>
                    </view>
                    <view class="pt10 f24 gray6">
                        <text> {{item.region.province}}{{item.region.city}}{{item.region.region}}{{item.address}}</text>
                    </view>
                    <view>
                        <text class="iconfont icon-dingwei"></text>
                        <text>{{item.distance_unit}}</text>
                    </view>
                    <!-- 选中状态 -->
                    <view v-if="item.store_id == selectedId" class="shop-item__right">
                        <text class="iconfont icon-iconfontduihaocopy"></text>
                    </view>
                </view>
            </view>
            <!-- 无数据提供的页面 -->
            <view v-if="!isLoading && !storeList.length">
                <view class="yoshop-notcont">
                    <text class="iconfont icon-wushuju"></text>
                    <text class="cont">亲,暂无自提门店哦</text>
                </view>
            </view>
        </view>
    </view>
</template>
 
 
<script>
    export default {
        data() {
            return {
                /*数据*/
                listData: [],
                isLoading: true, // 是否正在加载中
                storeList: [], // 门店列表,
                longitude: '',
                latitude: '',
                selectedId: -1,
            }
        },
        onLoad(options) {
            // 记录已选中的id
            this.selectedId = options.store_id;
            /*获取地址列表*/
            //this.getLocation();
            this.getData();
        },
        methods: {
              /**
               * 授权启用定位权限
               */
              onAuthorize() {
                let self = this;
                uni.openSetting({
                  success(res) {
                    if (res.authSetting["scope.userLocation"]) {
                      console.log('授权成功');
                      self.isAuthor = true;
                      setTimeout(() => {
                        // 获取用户坐标
                        self.getLocation((res) => {
                         
                        });
                      }, 1000);
                    }
                  }
                })
              },
            /**
             * 获取用户坐标
             */
            getLocation(callback) {
                let self = this;
                uni.getLocation({
                    type: 'wgs84',
                    success(res) {
                        self.longitude = res.longitude;
                        self.latitude = res.latitude;
                        self.getData();
                    },
                    fail() {
                        uni.showToast({
                            title: '获取定位失败,请点击右下角按钮打开定位权限',
                            duration: 2000
                        });
                        self.isAuthor=false;
                    },
                })
            },
 
            /*获取数据*/
            getData() {
                let self = this;
                self.isLoading = true;
                self._get('store.store/lists', {
                    longitude: self.longitude,
                    latitude: self.latitude
                }, function(res) {
                    self.isLoading = false;
                    self.storeList = res.data.list;
                });
            },
 
            /**
             * 选择门店
             */
            onSelectedStore(e) {
                let self = this;
                self.selectedId = e;
                // 设置上级页面的门店id
                let pages = getCurrentPages();
                if (pages.length < 2) {
                    return false;
                }
                self.$fire.fire('selectStoreId',e);
                // 返回上级页面
                // #ifndef H5
                uni.navigateBack();
                // #endif
                // #ifdef H5
                history.go(-1);
                // #endif
            },
 
 
        }
    }
</script>
 
<style>
    .address-list {
        padding-bottom: 90rpx;
    }
 
    .foot-btns {
        padding: 0;
    }
 
    .foot-btns .btn-red {
        width: 100%;
        height: 90rpx;
        line-height: 90rpx;
        border-radius: 0;
    }
</style>