Liuyi
2024-12-20 d470e67ac1997882502b75cbfdaf359626cfaaa8
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
<template>
    <view class="container">
        <navbar title = '站点列表'></navbar>
        <view class="content">
            <view class="nav">
                    <view class="nav-title">
                        <view @click="switchTo(1)" class="title-text" :style="isNav === 1 ? isActive : {}">送水点</view>
                        <view @click="switchTo(2)" class="title-text" :style="isNav === 2 ? isActive : {}">设备点</view>
                    </view>
            </view>
            <view v-if="isNav === 1" class="main">
                <block v-for="(item,index) in sendWaterSiteList" :key='index'>
                    <view class="item">
                        <view class="item-img">
                            <image v-if="item.image" :src="baseUrl + '/upload' + item.image" alt='' mode="aspectFit"></image>
                            <image v-else src="../../static/images/station/facilityImg.svg" alt='' mode="aspectFit"></image>
                        </view>
                        <view class="item-info">
                            <view class="info-name">{{item.name}}</view>
                            <view class="info-addr" @click="openMap(item.latitude,item.longitude)">
                                <text class="addr-text">地址:{{item.address}}</text>
                                <view>
                                    <image src="../../static/images/index/icon22.svg" alt=''></image>
                                    <text>{{item.distanceValue}}km</text>
                                </view>
                            </view>
                            <view class="info-phone" @click="toCall(item.phone)">电话:{{ item.phone}}</view>
                        </view>
                    </view>
                </block>
            </view>
            
            <view v-if="isNav === 2" class="main">
                <block v-for="(item,index) in facilitySiteList" :key='index'>
                    <view class="item">
                        <view class="item-img">
                            <image v-if="item.image" :src="baseUrl + '/upload' + item.image" alt='' mode="aspectFit"></image>
                            <image v-else src="../../static/images/station/facilityImg.svg" alt='' mode="aspectFit"></image>
                        </view>
                        <view class="item-info">
                            <view class="info-name">{{item.name}}</view>
                            <view class="info-addr">
                                <text class="addr-text">地址:{{item.address}}</text>
                                <view @click="openMap(item.latitude,item.longitude)">
                                    <image src="../../static/images/index/icon22.svg" alt=''></image>
                                    <text>{{item.distanceValue}}km</text>
                                </view>
                            </view>
                            <view class="info-phone" @click="toCall(item.phone)">电话:{{ item.phone}}</view>
                        </view>
                    </view>
                </block>
            </view>
        </view>
    </view>
</template>
 
<script setup>
    import { onMounted, ref } from 'vue'
    import { siteApi } from '../../api/index.js'
    import { BASE_URL } from '../../config/baseUrl.js';
    
    const baseUrl = ref(BASE_URL)
    const isNav = ref(2)//1:送水点;2:设备点
    const isActive = ref({borderBottom:`3px solid #226AC9`})
    const userLocation = ref()
    const sendWaterSiteList = ref([])
    const facilitySiteList = ref([])
    
    //导航切换
    function switchTo(val){
        if((val === 1 && isNav.value === 1) || (val === 2 && isNav.value === 2)){
        }else{
            if(val === 1){
                isNav.value = 1
            }else if(val === 2){
                isNav.value = 2
            }
        }
    }
    //获取送水点及饮水设备点列表
    async function getSiteList(){
        let param1 = {
              type:1,
              latitude: userLocation.value.lat,
              longitude:userLocation.value.lon,
        }
        let param2 = {...param1}
        param2.type = 2
        await siteApi(param1).then((res) =>{
            sendWaterSiteList.value = res.data
        })
        await siteApi(param2).then((res1) =>{
            facilitySiteList.value = res1.data
        })
    }
    //打开地图导航
    function openMap(lat,lon){
        uni.openLocation({
            latitude: parseFloat(lat),
            longitude: parseFloat(lon),
            scale:18
        })
    }
    function toCall(phone){
           // #ifdef MP-WEIXIN
            wx.makePhoneCall({
                phoneNumber: phone,
                success: function() {
                    console.log("拨打电话成功!")
                },
                fail: function() {
                    console.log("拨打电话失败!")
                }
            })
           // #endif
    }
    onMounted(async() =>{
        userLocation.value = JSON.parse(uni.getStorageSync('userLocation'))
        await getSiteList()
    })
</script>
 
<style lang="scss">
.container{
    width: 100%;
    height: 100vh;
    .content{
        width: 100%;
        height:calc(100vh - 176rpx);
        background:linear-gradient(to top,#FFFFFF,#E8EFFF);
        padding:32rpx 0 100rpx;
        box-sizing: border-box;
        .nav{
            height: 100rpx;
            width:100%;
            box-sizing: border-box;
            margin-bottom:32rpx;
            background-color: #FFF;
            .nav-title{
                width: 100%;
                box-sizing: border-box;
                padding: 0 160rpx;
                height: 100rpx;
                display: flex;
                justify-content: space-between;
                align-items: center;
                .title-text{
                    font-weight: 300;
                    font-size: 32rpx;
                    color: #000000;
                    width:120rpx;
                    height:65rpx;
                    text-align: center;
                    line-height:65rpx;
                }
            }
        }
           .main{
               height:calc(100vh - 176rpx - 350rpx);
               width:100%;
               // background-color: #e4f8ff;
               padding:0 32rpx;
               box-sizing: border-box;
               .item{
                   height:230rpx;
                   width:100%;
                   background-color: #FFFFFF;
                   border-radius: 24rpx;
                   padding:36rpx 20rpx;
                   margin-bottom:20rpx;
                   box-sizing: border-box;
                   display: flex;
                   align-items:center;
                   .item-img{
                       image{
                           width:140rpx;
                           height: 140rpx;
                       }
                   }
                   .item-info{
                    height:100%;
                       display: flex;
                       flex-direction: column;
                       margin-left:20rpx;
                       justify-content: space-between;
                    overflow: hidden;
                       .info-name{
                           color:#222c35;
                       }
                       .info-addr{
                           display: flex;
                           justify-content: space-between;
                           align-items:center;
                           .addr-text{
                               width:340rpx;
                               height:80rpx;
                               color: #6a6e75;
                               font-size:26rpx;
                           }
                           view{
                               display: flex;
                               justify-content: space-between;
                               align-items:center;
                               image{
                                   width:50rpx;
                                   height:50rpx;
                               }
                               text{
                                   color: #6a6e75;
                                   font-size:26rpx;
                               }
                           }
                       }
                    .info-phone{
                        font-size:26rpx;
                        color: #778bce;
                    }
                   }
               }
           }
    }
}
</style>