| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <template>
- <view class="content">
- <map style="width: 100%; height: 400px;"
- id="wash_map"
- :latitude="state.latitude"
- :longitude="state.longitude"
- :markers="state.covers"
- min-scale="1"
- :scale="12"
- :show-compass="false"
- @regionchange="handleMapRegionChange"
- @updated="handleMapUpdated"
- @labeltap="handleMapTapMarker"
- @markertap="handleMapTapMarker">
- <view class="content_reset-btn" @click="resetLocation">
- <uv-icon name="empty-address" size="28" color="#000" icon="/static/map-re-location.png"></uv-icon>
- </view>
- </map>
- <view class="w100 content_search mt10">
- <uv-search :showAction="true" actionText="搜索" placeholder="请输入站点名称搜索" :animation="true" @search="handleSearchStation"></uv-search>
- </view>
- <!-- 站点清单 start-->
- <view class="w100 content_station">
- <view class="station_item" v-for="item in state.stationList" :key="item.id">
- <view class="station_item-title">
- <text class="font13">{{ item.name }}</text>
- </view>
- <view class="station_item-status">
- <text class="station_item-status-text">营业中</text>
- </view>
- <view class="station_item-content">
- <view class="station_item-content-left">
- <view class="station_item-content-left-label">
- <view class="font12 station_item-content-left-label-left">
- <text class="station_item-content-left-label-left_idle">空闲</text>
- <text class="station_item-content-left-label-left_count">{{ item.idle }}/{{ item.total }}</text>
- </view>
- <!-- <uv-tags size="small" class="station_item-content-left-label_tag" text="洗车机" plain shape="circle"></uv-tags>-->
- <view class="station_item-content-left-label_func">{{ item.funs?.join(" | ") }}</view>
- </view>
- <view class="station_item-content-left-position">
- <uv-icon name="empty-address" size="20" color="#aaa"></uv-icon>
- <text>{{ item.address }}</text>
- </view>
- </view>
- <view class="station_item-content-right">
- <uv-button circle type="primary" size="mini" plain @click="handleNavStation(item)">去洗车</uv-button>
- </view>
- </view>
- <view class="station_item-distance">
- <uv-text type="primary" :text="item.tips" size="12"></uv-text>
- </view>
- </view>
- </view>
- <!-- 站点清单 end-->
- </view>
- </template>
- <script setup lang="ts">
- import {reactive, ref} from 'vue'
- import {onHide, onShow} from "@dcloudio/uni-app";
- const mapCtx = ref(); // 地图上下文
- const initState = () => ({
- latitude: 23.098994,
- longitude: 113.32252,
- covers: [] as any[],
- markers: [] as any[],
- isIgnoreChangeLocation: false,
- loading: false,
- stationList: [
- {
- id: 1,
- name: '河源路洗车场',
- status: 1,
- total: 7,
- idle: 2,
- funs: ['清洁', '泡沫', '吸尘', '消毒', '充电'],
- address: '深圳市宝安区河源路12345号',
- tips: '半小时内免停车费,超时领取停车券免费',
- },
- {
- id: 1,
- name: '河源路洗车场2222',
- status: 1,
- total: 17,
- idle: 2,
- funs: ['清洁', '泡沫', '吸尘', '消毒', '充电'],
- address: '深圳市宝安区河源路12345号',
- tips: '半小时内免停车费,超时领取停车券免费',
- }
- ] as any[]
- })
- const state = reactive(initState())
- onShow(() => {
- let gd = getApp<any>().globalData;
- if (!gd.token) {
- console.error(gd)
- return;
- }
- mapCtx.value = uni.createMapContext("wash_map");
- // refreshCouponList();
- });
- onHide(() => {
- Object.assign(state, initState());
- })
- const handleMapRegionChange = (e: any) => {
- if (state.isIgnoreChangeLocation) {
- return;
- }
- if (e.type === "end" && state.markers.length) {
- // console.log("map change end", {
- // ...e.detail.centerLocation,
- // });
- const current = e.target.centerLocation;
- const {latitude, longitude} = current;
- relocation(longitude, latitude);
- // stationPage.value.page = 1;
- // refreshStation({
- // latitude,
- // longitude,
- // });
- }
- }
- const relocation = (longitude: number, latitude: number) => {
- mapCtx.value?.moveToLocation({
- latitude,
- longitude,
- });
- }
- //重置地图定位
- const resetLocation = () => {
- // if (state.loading) {
- // return;
- // }
- console.log("reset location")
- uni.getLocation({
- type: 'gcj02', //返回可以用于uni.openLocation的经纬度
- success: res=>{
- const latitude = res.latitude;
- const longitude = res.longitude;
- console.log("reset location",res)
- uni.openLocation({
- latitude: latitude,
- longitude: longitude,
- success: function () {
- console.log('success');
- }
- });
- }
- });
- // eslint-disable-next-line promise/catch-or-return
- // fetchLocation().then((res: any) => {
- // const { latitude, longitude } = res;
- // mapCtx.value?.moveToLocation({
- // latitude,
- // longitude,
- // });
- // });
- };
- const handleMapUpdated = (e: any) => {
- setTimeout(() => {
- state.isIgnoreChangeLocation = false;
- }, 500);
- }
- const handleMapTapMarker = (e: any) => {
- if (e.detail.markerId === -1) {
- return;
- }
- let chooseMarker = state.stationList.find((k: any) => k.id == e.detail.markerId);
- if (chooseMarker) {
- // _changeMarker(findIndex);
- }
- }
- const handleSearchStation = (e: any) => {
- console.log("search>>>", e)
- // const { value } = e.detail;
- // if (!value) {
- // return;
- // }
- }
- const handleNavStation = (station: any) => {
- }
- </script>
- <style lang="scss" scoped>
- .content {
- width: 100%;
- //background: #efeffe;
- &_reset-btn {
- position: absolute;
- right: 10rpx;
- bottom: 10rpx;
- }
- &_search {
- }
- &_station {
- height: calc(100vh - 480px);
- }
- }
- .station_item {
- display: flex;
- flex-direction: column;
- border-radius: 10rpx;
- margin-top: 20rpx;
- padding: 15rpx;
- background: #fafafa;
- position: relative;
- &-title {
- display: inline-flex;
- padding-left: 5px;
- }
- &-status {
- position: absolute;
- right: 0;
- top: 0;
- &-text {
- background: $uni-color-primary;
- padding: 6rpx;
- color: white;
- font-size: 12px;
- }
- }
- &-content {
- display: flex;
- justify-content: space-between;
- width: 100%;
- &-left {
- flex: 1;
- display: flex;
- flex-direction: column;
- padding: 5rpx;
- &-label {
- padding: 4rpx 8rpx;
- display: inline-flex;
- margin-top: 8rpx;
- //justify-content: space-between;
- &-left {
- //border: 1px solid $uni-color-primary;
- border-radius: 4rpx;
- &_idle {
- background: $uni-color-primary;
- padding: 6rpx;
- color: white;
- border-radius: 4rpx;
- }
- &_count {
- //border-radius: 4rpx;
- margin-left: 10px;
- color: $uni-color-primary;
- font-size: 13px;
- }
- &_tag {
- width: 30rpx;
- }
- }
- &_func {
- padding-left: 50rpx;
- font-size: 24rpx;
- color: #aaa;
- }
- }
- &-position {
- display: inline-flex;
- font-size: 24rpx;
- margin-top: 8rpx;
- }
- }
- &-right {
- width: 120rpx;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-content: center;
- }
- }
- &-distance {
- font-size: 24rpx;
- padding-left: 5px;
- margin-top: 8rpx;
- }
- }
- </style>
|