quanwei
2025-10-29 ea6deea758f1c7866c694f63a04730e86a463264
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
<template>
    <view :data-theme='theme()' :class="theme() || ''">
        <chose-city :citydata="citydata" :myCityObj="citySupplierRes" :nowCityObj="locationCityObj" @selectCity="selectCity" @selectCityByLatLng="selectCityByLatLng" v-if="showCity && citydata.cityList.length>0" @closeModal="closeModal"></chose-city>
    </view>
</template>
 
<script>
    import choseCity from "@/pages2/components/chose-city/chose-city";
    export default {
        components: {
            choseCity
        },
        data() {
            return {
                showCity:true,   // 默弹窗显示
                citySupplierRes: {}, // 当前 选择的城市
                locationCityObj: {}, // 自动定位的城市
                citydata:[],
            };
        },
        onLoad() {
            if(uni.getStorageSync('citySupplierRes')){
                this.citySupplierRes = uni.getStorageSync('citySupplierRes');
                uni.setStorageSync('realCityObj', this.citySupplierRes);
                // this.locationCityObj = uni.getStorageSync('locationCityObj');
            }
            this.getData();
        },
        methods: {
            selectCity(item) {
                console.log('-您选择的城市-',item)
                let self = this;
                let city = item.name;
                let url = 'index/getCitySupplierBycity';
                if (item.level == 3) {
                    url = 'index/getCitySupplierByRegion';
                }
                self._get(url, {
                    city: city,
                }, function(res) {
                    let pages = getCurrentPages();  //获取所有页面栈实例列表
                    let nowPage = pages[ pages.length - 1];  //当前页页面实例
                    let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
                    prevPage.$vm.city_supplier_ids = res.data.supplier_ids;   //修改上一页data里面的searchVal参数值为222
                    prevPage.$vm.index_cityname = res.data.city;
                    // 记录当前站点信息
                    self.citySupplierRes = res.data;
                    uni.setStorageSync('citySupplierRes', res.data);
                    uni.navigateBack({  //uni.navigateTo跳转的返回,默认1为返回上一级
                        delta: 1
                    });
                });
            },
            selectCityByLatLng(item, type) {
                var self = this;
                self._get('index/getCitySupplier', {
                    longitude: item.longitude,
                    latitude: item.latitude
                }, function(res) {
                    res.data.city = res.data.name;
                    res.data.level = 2;
                    self.locationCityObj = res.data;
                    console.log(type);
                    // 记录定位的站点信息 by lyzflash
                    // uni.setStorageSync('locationCityObj', res.data);
                    // 记录定位的时间 by lyzflash
                    // uni.setStorageSync('city_expiration', expiration);
                    // 记录当前站点信息
                    if (type) {
                        self.citySupplierRes = res.data;
                        uni.setStorageSync('citySupplierRes', res.data);
                        // 获取区县信息
                        self.getRegionList(res.data.name);
                        uni.navigateBack({  //uni.navigateTo跳转的返回,默认1为返回上一级
                            delta: 1
                        });
                    }
                })
            },
            getRegionList(city) {
                // 获取区县信息
                console.log(city);
                let cityData = this.citydata.cityList;
                for(let i = 0; i < cityData.length; i++) {
                    if (cityData[i].name == city) {
                        uni.setStorageSync('regionObj', cityData[i].regions);
                        break;
                    }
                }
            },
            closeModal() {
                this.showCity = false;
                uni.navigateBack({  //uni.navigateTo跳转的返回,默认1为返回上一级
                    delta: 1
                });
            },
            goback() {
                uni.navigateBack();
            },
            /*获取数据*/
            getData() {
                let self = this;
                self.isloadding = true;
                self._get('index/getCityList', {
                     
                }, function(res) {
                    res.data.cityList = Object.values(res.data.cityList);
                    res.data.alphabet = Object.values(res.data.alphabet);
                    self.citydata = res.data;
                    self.getRegionList(self.citySupplierRes.name);
                });
            },
        }
    }
</script>
 
<style>
    @import '/pages2/common/main.css';
    @import '/pages2/common/icon.css';
    page{
        background: #fff;
    }
    .cu-btn{
        width: 92%;
        border-radius: 10rpx;
    }
    .cu-btn[class*="line"]::after{
        border: 1rpx solid #aaaaaa;
    }
</style>