feat: 门店标点展示
This commit is contained in:
@@ -1,64 +1,79 @@
|
||||
<template>
|
||||
<s-layout :bgStyle="{ color: '#FFF' }" title="选择自提门店">
|
||||
<view class="storeBox" ref="container">
|
||||
<view
|
||||
class="storeBox-box"
|
||||
v-for="(item, index) in state.storeList"
|
||||
:key="index"
|
||||
@tap="checked(item)"
|
||||
>
|
||||
<view class="store-img">
|
||||
<image :src="item.logo" class="img" />
|
||||
<view class="store-page">
|
||||
<view class="search-bar">
|
||||
<view class="search-inner">
|
||||
<image class="search-icon" src="/static/icon/search.svg" mode="aspectFit" />
|
||||
<uni-easyinput
|
||||
class="search-input"
|
||||
v-model="state.keyword"
|
||||
placeholder="搜索自提点..."
|
||||
:inputBorder="false"
|
||||
:clearable="true"
|
||||
/>
|
||||
</view>
|
||||
<view class="store-cent-left">
|
||||
<view class="store-name">{{ item.name }}</view>
|
||||
<view class="store-address line1">
|
||||
{{ item.district }}{{ ', ' + item.description }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="row-right ss-flex-col ss-col-center">
|
||||
<view>
|
||||
<!-- #ifdef H5 -->
|
||||
<a class="store-phone" :href="'tel:' + item.phone">
|
||||
<view class="iconfont">
|
||||
<view class="ss-rest-button">
|
||||
<text class="_icon-forward" />
|
||||
</view>
|
||||
</view>
|
||||
</a>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef MP -->
|
||||
<view class="store-phone" @click="call(item.phone)">
|
||||
<view class="iconfont">
|
||||
<view class="ss-rest-button">
|
||||
<text class="_icon-forward" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="map-card">
|
||||
<map
|
||||
class="map"
|
||||
:latitude="state.mapLatitude"
|
||||
:longitude="state.mapLongitude"
|
||||
:scale="state.mapScale"
|
||||
:markers="markers"
|
||||
show-location
|
||||
@markertap="onMarkerTap"
|
||||
/>
|
||||
<cover-view v-if="selectedStore" class="map-center-marker">
|
||||
<cover-view class="map-center-marker__label">{{ selectedStore.name || '自提门店' }}</cover-view>
|
||||
</cover-view>
|
||||
</view>
|
||||
|
||||
<view class="list-hd">
|
||||
<view class="list-title">附近自提点</view>
|
||||
<view class="list-sub" v-if="filteredStoreList.length">共{{ filteredStoreList.length }}家</view>
|
||||
</view>
|
||||
|
||||
<view class="store-list" ref="container">
|
||||
<view
|
||||
class="store-item"
|
||||
v-for="(item, index) in filteredStoreList"
|
||||
:key="item.id || index"
|
||||
:class="{ 'store-item--active': Number(item.id) === Number(state.selectedStoreId) }"
|
||||
@tap="onSelect(item)"
|
||||
>
|
||||
<view class="store-item__hd">
|
||||
<view class="store-badge">#{{ index + 1 }}</view>
|
||||
<view class="store-name">{{ item.name }}</view>
|
||||
<view class="store-distance" v-if="item.distance !== undefined && item.distance !== null">
|
||||
{{ formatDistance(item.distance) }}
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
<view class="store-distance ss-flex ss-row-center" @tap.stop="showMaoLocation(item)">
|
||||
<text class="addressTxt" v-if="item.distance">
|
||||
距离{{ item.distance.toFixed(2) }}千米
|
||||
</text>
|
||||
<text class="addressTxt" v-else>查看地图</text>
|
||||
<view class="iconfont">
|
||||
<view class="ss-rest-button">
|
||||
<text class="_icon-forward" />
|
||||
</view>
|
||||
<view class="store-address line2">
|
||||
{{ formatAddress(item) || '--' }}
|
||||
</view>
|
||||
<view class="store-item__ft">
|
||||
<view class="store-hours" v-if="formatBusinessHours(item)">
|
||||
营业中 {{ formatBusinessHours(item) }}
|
||||
</view>
|
||||
<view class="store-actions">
|
||||
<view class="btn btn--ghost" @tap.stop="showMaoLocation(item)">导航</view>
|
||||
<view class="btn" @tap.stop="checked(item)">选择</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<canvas canvas-id="storeMarkerCanvas" class="marker-canvas" />
|
||||
</view>
|
||||
</s-layout>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import StoreApi from '@/sheep/api/trade/store';
|
||||
import { onMounted, reactive } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { computed, getCurrentInstance, onMounted, reactive } from 'vue';
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||
import sheep from '@/sheep';
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const LONGITUDE = 'user_longitude';
|
||||
const LATITUDE = 'user_latitude';
|
||||
@@ -70,13 +85,14 @@
|
||||
locationShow: false,
|
||||
user_latitude: 0,
|
||||
user_longitude: 0,
|
||||
mapLatitude: 0,
|
||||
mapLongitude: 0,
|
||||
mapScale: 12,
|
||||
selectedStoreId: 0,
|
||||
keyword: '',
|
||||
markerIconMap: {},
|
||||
});
|
||||
|
||||
const call = (phone) => {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: phone,
|
||||
});
|
||||
};
|
||||
const selfLocation = () => {
|
||||
// #ifdef H5
|
||||
const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
|
||||
@@ -84,6 +100,8 @@
|
||||
jsWxSdk.getLocation((res) => {
|
||||
state.user_latitude = res.latitude;
|
||||
state.user_longitude = res.longitude;
|
||||
state.mapLatitude = res.latitude;
|
||||
state.mapLongitude = res.longitude;
|
||||
uni.setStorageSync(LATITUDE, res.latitude);
|
||||
uni.setStorageSync(LONGITUDE, res.longitude);
|
||||
getList();
|
||||
@@ -96,6 +114,8 @@
|
||||
try {
|
||||
state.user_latitude = res.latitude;
|
||||
state.user_longitude = res.longitude;
|
||||
state.mapLatitude = res.latitude;
|
||||
state.mapLongitude = res.longitude;
|
||||
uni.setStorageSync(LATITUDE, res.latitude);
|
||||
uni.setStorageSync(LONGITUDE, res.longitude);
|
||||
} catch (e) {
|
||||
@@ -147,6 +167,212 @@
|
||||
sheep.$router.back();
|
||||
};
|
||||
|
||||
const onSelect = (item) => {
|
||||
state.selectedStoreId = Number(item?.id || 0);
|
||||
const lat = Number(item?.latitude);
|
||||
const lon = Number(item?.longitude);
|
||||
if (lat && lon) {
|
||||
state.mapLatitude = lat;
|
||||
state.mapLongitude = lon;
|
||||
state.mapScale = 14;
|
||||
}
|
||||
renderMarkerIcon(item, true);
|
||||
};
|
||||
|
||||
const formatDistance = (km) => {
|
||||
const d = Number(km);
|
||||
if (!(d >= 0)) return '';
|
||||
if (d >= 1) return `${d.toFixed(1)}km`;
|
||||
return `${Math.round(d * 1000)}m`;
|
||||
};
|
||||
|
||||
const formatAddress = (item) => {
|
||||
const district = item?.district || '';
|
||||
const description = item?.description || '';
|
||||
const address = item?.address || '';
|
||||
return `${district}${description ? ` ${description}` : ''}${address ? ` ${address}` : ''}`.trim();
|
||||
};
|
||||
|
||||
const formatHm = (hm) => {
|
||||
if (!Array.isArray(hm) || hm.length < 2) return '';
|
||||
const h = String(hm[0]).padStart(2, '0');
|
||||
const m = String(hm[1]).padStart(2, '0');
|
||||
return `${h}:${m}`;
|
||||
};
|
||||
|
||||
const formatBusinessHours = (item) => {
|
||||
const start =
|
||||
item?.openingTime || formatHm(item?.businessHoursStart) || item?.businessHoursStart || '';
|
||||
const end = item?.closingTime || formatHm(item?.businessHoursEnd) || item?.businessHoursEnd || '';
|
||||
if (!start || !end) return '';
|
||||
return `${start}-${end}`;
|
||||
};
|
||||
|
||||
const filteredStoreList = computed(() => {
|
||||
const list = Array.isArray(state.storeList) ? state.storeList : [];
|
||||
const kw = String(state.keyword || '').trim();
|
||||
if (!kw) return list;
|
||||
return list.filter((item) => {
|
||||
const s = `${item?.name || ''} ${formatAddress(item)}`.toLowerCase();
|
||||
return s.includes(kw.toLowerCase());
|
||||
});
|
||||
});
|
||||
|
||||
const selectedStore = computed(() => {
|
||||
const id = Number(state.selectedStoreId || 0);
|
||||
if (!(id > 0)) return filteredStoreList.value?.[0] || null;
|
||||
return (filteredStoreList.value || []).find((o) => Number(o?.id) === id) || filteredStoreList.value?.[0] || null;
|
||||
});
|
||||
|
||||
const sanitizeUrl = (value) => String(value || '').replace(/[`"'\s]/g, '');
|
||||
|
||||
const normalizeImageUrl = (value) => {
|
||||
const raw = sanitizeUrl(value);
|
||||
if (!raw) return '';
|
||||
if (/^https?:\/\//i.test(raw)) return raw;
|
||||
return sheep.$url.cdn(raw);
|
||||
};
|
||||
|
||||
const getMarkerKey = (id, active) => `${id}_${active ? 'active' : 'inactive'}`;
|
||||
|
||||
const getImageTempPath = (url) =>
|
||||
new Promise((resolve) => {
|
||||
if (!url) {
|
||||
resolve('');
|
||||
return;
|
||||
}
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
resolve(url);
|
||||
return;
|
||||
}
|
||||
uni.downloadFile({
|
||||
url,
|
||||
success: (res) => {
|
||||
resolve(res.statusCode === 200 ? res.tempFilePath || '' : '');
|
||||
},
|
||||
fail: () => resolve(''),
|
||||
});
|
||||
});
|
||||
|
||||
const renderMarkerIcon = async (item, active = false) => {
|
||||
const id = Number(item?.id || 0);
|
||||
const key = getMarkerKey(id, active);
|
||||
if (!(id > 0) || state.markerIconMap[key]) return state.markerIconMap[key] || '';
|
||||
const imageUrl = normalizeImageUrl(item?.coverImage || item?.logo);
|
||||
if (!imageUrl) return '';
|
||||
const tempPath = await getImageTempPath(imageUrl);
|
||||
if (!tempPath) return '';
|
||||
const size = 88;
|
||||
const ring = 6;
|
||||
const innerSize = size - ring * 2;
|
||||
const radius = size / 2;
|
||||
const innerRadius = innerSize / 2;
|
||||
const ctx = uni.createCanvasContext('storeMarkerCanvas', proxy);
|
||||
return new Promise((resolve) => {
|
||||
ctx.clearRect(0, 0, size, size);
|
||||
ctx.beginPath();
|
||||
ctx.arc(radius, radius, radius, 0, Math.PI * 2);
|
||||
ctx.setFillStyle(active ? '#2556EC' : '#C8CDD9');
|
||||
ctx.fill();
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.arc(radius, radius, innerRadius, 0, Math.PI * 2);
|
||||
ctx.clip();
|
||||
ctx.drawImage(tempPath, ring, ring, innerSize, innerSize);
|
||||
ctx.restore();
|
||||
ctx.draw(false, () => {
|
||||
uni.canvasToTempFilePath(
|
||||
{
|
||||
canvasId: 'storeMarkerCanvas',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: size,
|
||||
height: size,
|
||||
destWidth: size * 2,
|
||||
destHeight: size * 2,
|
||||
success: (res) => {
|
||||
const path = res?.tempFilePath || '';
|
||||
if (path) {
|
||||
state.markerIconMap[key] = path;
|
||||
}
|
||||
resolve(path);
|
||||
},
|
||||
fail: () => resolve(''),
|
||||
},
|
||||
proxy,
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const prepareMarkerIcons = async (list = []) => {
|
||||
for (const item of list) {
|
||||
await renderMarkerIcon(item, false);
|
||||
}
|
||||
};
|
||||
|
||||
const ensureDefaultSelectedStore = async (list = []) => {
|
||||
const stores = Array.isArray(list) && list.length ? list : filteredStoreList.value;
|
||||
if (!stores.length) return null;
|
||||
let target = null;
|
||||
if (Number(state.selectedStoreId) > 0) {
|
||||
target = stores.find((o) => Number(o?.id || 0) === Number(state.selectedStoreId));
|
||||
}
|
||||
if (!target) {
|
||||
target = stores.find((o) => Number(o?.latitude) && Number(o?.longitude)) || stores[0];
|
||||
state.selectedStoreId = Number(target?.id || 0);
|
||||
}
|
||||
if (target) {
|
||||
const lat = Number(target?.latitude);
|
||||
const lon = Number(target?.longitude);
|
||||
if (lat && lon) {
|
||||
state.mapLatitude = lat;
|
||||
state.mapLongitude = lon;
|
||||
}
|
||||
await renderMarkerIcon(target, true);
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
const markers = computed(() => {
|
||||
return filteredStoreList.value
|
||||
.filter((item) => Number(item?.latitude) && Number(item?.longitude))
|
||||
.map((item) => {
|
||||
const id = Number(item?.id || 0);
|
||||
const active = id === Number(state.selectedStoreId);
|
||||
const inactiveIcon = state.markerIconMap[getMarkerKey(id, false)];
|
||||
const activeIcon = state.markerIconMap[getMarkerKey(id, true)];
|
||||
return {
|
||||
id,
|
||||
latitude: Number(item.latitude),
|
||||
longitude: Number(item.longitude),
|
||||
iconPath: active
|
||||
? activeIcon || '/static/transparent_bg.png'
|
||||
: inactiveIcon || '/static/transparent_bg.png',
|
||||
width: active ? 44 : 32,
|
||||
height: active ? 44 : 32,
|
||||
callout: {
|
||||
content: String(item?.name || ''),
|
||||
display: active ? 'ALWAYS' : 'BYCLICK',
|
||||
padding: 6,
|
||||
borderRadius: 8,
|
||||
bgColor: '#ffffff',
|
||||
color: '#333333',
|
||||
fontSize: 12,
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const onMarkerTap = (e) => {
|
||||
const markerId = Number(e?.markerId || 0);
|
||||
if (!(markerId > 0)) return;
|
||||
const target = (filteredStoreList.value || []).find((o) => Number(o?.id) === markerId);
|
||||
if (target) {
|
||||
onSelect(target);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取门店列表数据
|
||||
*/
|
||||
@@ -167,6 +393,8 @@
|
||||
state.loading = false;
|
||||
state.loaded = hasLocation;
|
||||
state.storeList = Array.isArray(data) ? data : [];
|
||||
await ensureDefaultSelectedStore(state.storeList);
|
||||
prepareMarkerIcons(state.storeList);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
@@ -181,16 +409,24 @@
|
||||
try {
|
||||
state.user_latitude = uni.getStorageSync(LATITUDE);
|
||||
state.user_longitude = uni.getStorageSync(LONGITUDE);
|
||||
state.mapLatitude = state.user_latitude;
|
||||
state.mapLongitude = state.user_longitude;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
ensureDefaultSelectedStore();
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.line1 {
|
||||
.line2 {
|
||||
display: -webkit-box;
|
||||
line-clamp: 2;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.geoPage {
|
||||
@@ -201,85 +437,181 @@
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
.storeBox {
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
padding: 0 30rpx;
|
||||
.store-page {
|
||||
background: #fff;
|
||||
padding: 0 30rpx 30rpx;
|
||||
}
|
||||
|
||||
.storeBox-box {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
.search-bar {
|
||||
padding: 20rpx 0 10rpx;
|
||||
}
|
||||
|
||||
.search-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 23rpx 0;
|
||||
height: 72rpx;
|
||||
padding: 0 20rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f6f7f9;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
margin-right: 12rpx;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.map-card {
|
||||
position: relative;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
background: #f6f7f9;
|
||||
}
|
||||
|
||||
.map {
|
||||
width: 100%;
|
||||
height: 460rpx;
|
||||
}
|
||||
|
||||
.map-center-marker {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, 8rpx);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.map-center-marker__label {
|
||||
margin-top: 0;
|
||||
padding: 8rpx 14rpx;
|
||||
border-radius: 10rpx;
|
||||
background: rgba(0, 0, 0, 0.72);
|
||||
color: #fff;
|
||||
font-size: 22rpx;
|
||||
line-height: 1;
|
||||
max-width: 360rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.marker-canvas {
|
||||
position: fixed;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
width: 88px;
|
||||
height: 88px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.list-hd {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 22rpx 0 10rpx;
|
||||
}
|
||||
|
||||
.store-cent {
|
||||
.list-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.list-sub {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.store-item {
|
||||
position: relative;
|
||||
padding: 22rpx 22rpx 20rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 10rpx 28rpx rgba(0, 0, 0, 0.06);
|
||||
margin-top: 18rpx;
|
||||
border: 2rpx solid transparent;
|
||||
}
|
||||
|
||||
.store-item--active {
|
||||
border-color: rgba(37, 86, 236, 0.35);
|
||||
box-shadow: 0 14rpx 34rpx rgba(37, 86, 236, 0.16);
|
||||
}
|
||||
|
||||
.store-item__hd {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.store-cent-left {
|
||||
//width: 45%;
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.store-img {
|
||||
flex: 1;
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 6rpx;
|
||||
margin-right: 22rpx;
|
||||
}
|
||||
|
||||
.store-img .img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.store-badge {
|
||||
height: 36rpx;
|
||||
padding: 0 12rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(37, 86, 236, 0.12);
|
||||
color: #2556ec;
|
||||
font-size: 22rpx;
|
||||
line-height: 36rpx;
|
||||
margin-right: 14rpx;
|
||||
}
|
||||
|
||||
.store-name {
|
||||
color: #282828;
|
||||
flex: 1;
|
||||
font-size: 30rpx;
|
||||
margin-bottom: 22rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.store-address {
|
||||
color: #666666;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.store-phone {
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
display: block;
|
||||
text-align: center;
|
||||
line-height: 48rpx;
|
||||
background-color: #e83323;
|
||||
margin-bottom: 22rpx;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
color: #222;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.store-distance {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
.store-address {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
line-height: 34rpx;
|
||||
}
|
||||
|
||||
.store-item__ft {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.store-hours {
|
||||
font-size: 22rpx;
|
||||
color: #e83323;
|
||||
color: #12b46b;
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-size: 20rpx;
|
||||
.store-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.row-right {
|
||||
flex: 2;
|
||||
//display: flex;
|
||||
//flex-direction: column;
|
||||
//align-items: flex-end;
|
||||
//width: 33.5%;
|
||||
.btn {
|
||||
height: 56rpx;
|
||||
padding: 0 20rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #2556ec;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
line-height: 56rpx;
|
||||
margin-left: 14rpx;
|
||||
}
|
||||
|
||||
.btn--ghost {
|
||||
background: rgba(37, 86, 236, 0.12);
|
||||
color: #2556ec;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user