Files

659 lines
18 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="order-details">
<!-- 自提商品核销 -->
<view v-if="orderInfo.deliveryType === 2 && orderInfo.payStatus" class="writeOff borRadius14">
<view class="title-row">
<view class="title-left flex-center">
<view class="title">核销信息</view>
<view class="status-tag" :class="statusTagClass">{{ statusTagText }}</view>
</view>
<view class="progress-btn" @tap.stop="goStockProgress">备货进度</view>
</view>
<template v-if="isSorting">
<view class="preparation-placeholder">
<view class="preparation-placeholder__emoji">📦</view>
<view class="preparation-placeholder__title">门店正快马加鞭备货中</view>
<view class="preparation-placeholder__desc">
分拣完成后将生成取货码并发送通知,请耐心等待~
</view>
</view>
<view v-if="isVerifyCompleted" class="num-wrap">
<view class="num num--done">该商品券已完成核销</view>
</view>
<view v-else class="num-wrap">
<view class="num num--pending">— 待备货完成后解锁 —</view>
</view>
</template>
<template v-else>
<view class="grayBg flex-center">
<view class="pictrue">
<image
v-if="!!painterImageUrl"
:src="painterImageUrl"
:style="{ width: `${state.qrcodeSize}px`, height: `${state.qrcodeSize}px` }"
:show-menu-by-longpress="true"
/>
<view v-if="isVerifyCompleted" class="verify-mask">
<view class="verify-mask__icon">
<uni-icons type="checkmarkempty" size="40" color="#ffffff" />
</view>
<view class="verify-mask__text">已核销</view>
</view>
</view>
</view>
<view class="gear">
<image :src="sheep.$url.static('/static/img/shop/writeOff.png')"></image>
</view>
<view v-if="isVerifyCompleted" class="num-wrap">
<view class="num num--done">该商品券已完成核销</view>
</view>
<view v-else class="num-wrap" @tap="copyVerifyCode">
<view class="num">{{ orderInfo.pickUpVerifyCode }}</view>
</view>
</template>
<view class="rules">
<view class="item">
<view class="rulesTitle flex flex-wrap align-center"> 核销时间 </view>
<view class="info">
每日:
<text class="time">{{ openingTimeText }} - {{ closingTimeText }}</text>
</view>
</view>
<view class="item">
<view class="rulesTitle flex flex-wrap align-center">
<text class="iconfont icon-shuoming1"></text>
使用说明
</view>
<view class="info">{{ isSorting ? '分拣完成后将生成核销码,出示给店员扫描即可' : '可将二维码出示给店员扫描或提供数字核销码' }}</view>
</view>
</view>
</view>
<view
v-if="orderInfo.deliveryType === 2 && !isSorting"
class="pickup-card borRadius14"
>
<image v-if="coverImageUrl" class="pickup-cover" :src="coverImageUrl" mode="aspectFill" />
<view class="pickup-hd">
<view class="pickup-title">{{ systemStore.name || '自提门店' }}</view>
<view v-if="distanceText" class="pickup-distance">{{ distanceText }}</view>
</view>
<view class="pickup-address">{{ pickupAddressText || '--' }}</view>
<view class="pickup-hours">
<uni-icons type="clock" size="14" color="#8c8c8c" />
<view class="pickup-hours__text">营业时间:{{ openingTimeText }} - {{ closingTimeText }}</view>
</view>
<view class="pickup-btn" @tap="showMaoLocation">查看位置导航</view>
</view>
<!-- 海报画板:默认隐藏只用来生成海报。生成方式为主动调用 -->
<l-painter
v-if="showPainter"
isCanvasToTempFilePath
pathType="url"
@success="setPainterImageUrl"
hidden
ref="painterRef"
/>
</view>
</template>
<script setup>
import sheep from '@/sheep';
import { computed, reactive, ref } from 'vue';
const props = defineProps({
orderInfo: {
type: Object,
default() {},
},
systemStore: {
type: Object,
default() {},
},
source: {
type: String,
default: '',
},
orderType: {
type: [String, Number],
default: '',
},
detailStyle: {
type: String,
default: 'order',
},
});
const resolvePickUpStoreId = () => {
return Number(
props.orderInfo?.pickUpStoreId ||
props.orderInfo?.pickUpStore?.id ||
props.orderInfo?.pickUpStore?.storeId ||
props.orderInfo?.pickUpStoreVO?.id ||
props.orderInfo?.pickUpStoreVO?.storeId ||
props.orderInfo?.store?.id ||
props.orderInfo?.store?.storeId ||
props.systemStore?.id ||
props.systemStore?.storeId ||
props.orderInfo?.storeId ||
0,
);
};
const goStockProgress = () => {
const id = props.orderInfo?.id || props.orderInfo?.orderId;
const pickUpStoreId = resolvePickUpStoreId();
const source = String(props.source || props.orderInfo?.__source || props.orderInfo?.source || '').trim();
const orderType = String(props.orderType || props.orderInfo?.type || '').trim();
const detailStyle = String(props.detailStyle || '').trim();
if (!id) return;
uni.navigateTo({
url: `/pages/order/stockProgress?id=${id}${
pickUpStoreId > 0 ? `&pickUpStoreId=${pickUpStoreId}` : ''
}${source ? `&source=${encodeURIComponent(source)}` : ''}${
orderType ? `&type=${encodeURIComponent(orderType)}` : ''
}${detailStyle ? `&detailStyle=${encodeURIComponent(detailStyle)}` : ''}`,
});
};
const copyVerifyCode = () => {
const code = String(props.orderInfo?.pickUpVerifyCode || '').trim();
if (!code) {
sheep.$helper.toast('暂无核销码');
return;
}
uni.setClipboardData({
data: code,
success: () => {
sheep.$helper.toast('核销码已复制');
},
});
};
/**
* 打开地图
*/
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 openingTimeText = computed(() => {
return props.systemStore?.openingTime || formatHm(props.systemStore?.businessHoursStart) || '--';
});
const closingTimeText = computed(() => {
return props.systemStore?.closingTime || formatHm(props.systemStore?.businessHoursEnd) || '--';
});
const pickupAddressText = computed(() => {
const s = props.systemStore || {};
const province = s.province || '';
const city = s.city || '';
const district = s.district || '';
const address = s.address || '';
const legacy = `${s.areaName || ''}${s.detailAddress || ''}`;
return `${province}${city}${district}${address}` || legacy || s.description || '';
});
const distanceText = computed(() => {
const d = Number(props.systemStore?.distance);
if (!(d > 0)) return '';
const t = d >= 1000 ? `${(d / 1000).toFixed(1)}km` : `${Math.round(d)}m`;
return `距离${t}`;
});
const sanitizeUrl = (value) => String(value || '').replace(/[`"'\s]/g, '');
const coverImageUrl = computed(() => {
const raw = sanitizeUrl(props.systemStore?.coverImage);
if (!raw) return '';
if (/^https?:\/\//i.test(raw)) return raw;
return sheep.$url.cdn(raw);
});
const isVerifyCompleted = computed(() => {
const info = props.orderInfo || {};
const status = Number(info?.status);
return Boolean(
info?.pickUpVerifyTime ||
info?.verifyTime ||
info?.completedTime ||
status === 30 ||
status === 3,
);
});
const resolveStage = () => {
const data = props.orderInfo || {};
const external = Number(data?.preparationStatus);
const rawStatus = Number.isFinite(external) ? external : Number(data?.preparationStatus ?? data?.status ?? 0);
if (isVerifyCompleted.value) return 'done';
if (rawStatus === 1 || rawStatus === 2) return 'wait';
if (
data?.deliveryTime ||
data?.arriveStoreTime ||
data?.deliveredTime ||
rawStatus === 20
) {
return 'delivered';
}
return 'sorting';
};
const isSorting = computed(() => resolveStage() === 'sorting');
const state = reactive({
qrcodeSize: 145,
});
const statusTagText = computed(() => {
const s = resolveStage();
if (s === 'sorting') return '分拣中';
if (s === 'delivered') return '已送达门店';
if (s === 'wait') return '待取货';
if (s === 'done') return isVerifyCompleted.value ? '已核销' : '已完成';
return '';
});
const statusTagClass = computed(() => {
const s = resolveStage();
if (s === 'sorting') return 'status-tag--sorting';
if (s === 'delivered') return 'status-tag--delivered';
if (s === 'wait') return 'status-tag--wait';
return 'status-tag--done';
});
const addressText = computed(() => {
const s = props.systemStore || {};
const province = s.province || '';
const city = s.city || '';
const district = s.district || '';
const description = s.description || '';
const legacy = `${s.areaName || ''}${s.detailAddress || ''}`;
return `${province}${city}${district}${description}` || legacy || s.address || '';
});
const showMaoLocation = () => {
const latitude = Number(props.systemStore?.latitude);
const longitude = Number(props.systemStore?.longitude);
if (!(latitude && longitude)) {
sheep.$helper.toast('缺少经纬度信息无法查看地图!');
return;
}
uni.openLocation({
latitude,
longitude,
scale: 8,
name: props.systemStore?.name,
address: addressText.value,
});
};
const painterRef = ref(); // 海报画板
const painterImageUrl = ref(); // 海报 url
const showPainter = ref(true);
const lastMarkCodeText = ref('');
// 渲染海报
const renderPoster = async (poster) => {
if (!painterRef.value) return;
await painterRef.value.render(poster);
};
// 获得生成的图片
const setPainterImageUrl = (path) => {
painterImageUrl.value = path;
};
/**
* 生成核销二维码
*/
const markCode = async (text) => {
const code = String(text || '').trim();
if (!code) return;
// 相同取货码无需重复生成,避免重复触发海报组件销毁/重建的空指针
if (lastMarkCodeText.value === code && painterImageUrl.value) return;
lastMarkCodeText.value = code;
// 如果 painterRef 已被销毁(showPainter=false 时 v-if 销毁了组件),先重建组件,等下一个 tick 再渲染
if (!painterRef.value) {
showPainter.value = true;
await new Promise((resolve) => setTimeout(resolve, 0));
}
renderPoster({
css: {
width: `${state.qrcodeSize}px`,
height: `${state.qrcodeSize}px`,
},
views: [
{
type: 'qrcode',
text: code,
css: {
width: `${state.qrcodeSize}px`,
height: `${state.qrcodeSize}px`,
},
},
],
});
};
defineExpose({
markCode,
});
</script>
<style scoped lang="scss">
.borRadius14 {
border-radius: 14rpx !important;
}
.cart-color {
color: #e93323 !important;
border: 1px solid #e93323 !important;
}
.order-details {
border-radius: 10rpx;
margin: 0 20rpx 20rpx 20rpx;
}
.order-details .writeOff {
background-color: #fff;
margin-top: 15rpx;
padding-bottom: 50rpx;
}
.order-details .writeOff .title-row {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 30rpx;
color: #282828;
height: 87rpx;
border-bottom: 1px solid #f0f0f0;
padding: 0 24rpx;
line-height: 87rpx;
box-sizing: border-box;
}
.order-details .writeOff .title-left {
gap: 16rpx;
min-width: 0;
}
.order-details .writeOff .title {
font-size: 30rpx;
color: #282828;
height: 87rpx;
line-height: 87rpx;
}
.order-details .writeOff .status-tag {
flex-shrink: 0;
height: 44rpx;
line-height: 44rpx;
padding: 0 16rpx;
border-radius: 22rpx;
font-size: 22rpx;
font-weight: 500;
}
.order-details .writeOff .status-tag--sorting {
color: #e8852f;
background: rgba(232, 133, 47, 0.12);
}
.order-details .writeOff .status-tag--delivered {
color: #2556ec;
background: rgba(37, 86, 236, 0.1);
}
.order-details .writeOff .status-tag--wait {
color: #12a06a;
background: rgba(18, 160, 106, 0.1);
}
.order-details .writeOff .status-tag--done {
color: #86909c;
background: rgba(134, 144, 156, 0.12);
}
.order-details .writeOff .progress-btn {
height: 52rpx;
line-height: 52rpx;
padding: 0 16rpx;
border-radius: 26rpx;
font-size: 24rpx;
color: #5b4eff;
background: rgba(91, 78, 255, 0.12);
}
.preparation-placeholder {
width: 590rpx;
min-height: 384rpx;
margin: 50rpx auto 0 auto;
border-radius: 20rpx 20rpx 0 0;
background: linear-gradient(180deg, #fff7ea 0%, #ffe9c8 100%);
padding: 72rpx 48rpx 56rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&__emoji {
font-size: 84rpx;
line-height: 1;
margin-bottom: 28rpx;
}
&__title {
font-size: 32rpx;
font-weight: 600;
color: #7a4a00;
line-height: 1.5;
margin-bottom: 14rpx;
}
&__desc {
font-size: 24rpx;
color: #a36d1a;
line-height: 1.7;
text-align: center;
}
}
.order-details .writeOff .num .num--pending {
background: #f7f8fa;
color: #98a2b3;
font-size: 26rpx;
letter-spacing: 2rpx;
}
.order-details .writeOff .grayBg {
background-color: #f2f5f7;
width: 590rpx;
height: 384rpx;
border-radius: 20rpx 20rpx 0 0;
margin: 50rpx auto 0 auto;
padding-top: 55rpx;
}
.order-details .writeOff .grayBg .pictrue {
position: relative;
width: 290rpx;
height: 290rpx;
}
.order-details .writeOff .grayBg .pictrue image {
width: 100%;
height: 100%;
}
.order-details .writeOff .grayBg .pictrue .verify-mask {
position: absolute;
inset: 0;
background: rgba(255, 255, 255, 0.82);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.order-details .writeOff .grayBg .pictrue .verify-mask__icon {
width: 112rpx;
height: 112rpx;
border-radius: 56rpx;
background: #56c33b;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 20rpx rgba(86, 195, 59, 0.24);
}
.order-details .writeOff .grayBg .pictrue .verify-mask__text {
margin-top: 18rpx;
font-size: 40rpx;
line-height: 56rpx;
color: #2a7c1f;
font-weight: 600;
}
.order-details .writeOff .gear {
width: 590rpx;
height: 30rpx;
margin: 0 auto;
}
.order-details .writeOff .gear image {
width: 100%;
height: 100%;
}
.order-details .writeOff .num-wrap {
width: 590rpx;
margin: 0 auto;
}
.order-details .writeOff .num {
background-color: #f0c34c;
width: 100%;
height: 84rpx;
color: #282828;
font-size: 48rpx;
border-radius: 0 0 20rpx 20rpx;
text-align: center;
padding-top: 4rpx;
}
.order-details .writeOff .num--done {
height: auto;
min-height: 84rpx;
padding-top: 0;
padding: 22rpx 24rpx;
box-sizing: border-box;
border-radius: 0 0 20rpx 20rpx;
background: #ffffff;
color: #b5b5b5;
font-size: 28rpx;
line-height: 40rpx;
}
.order-details .writeOff .rules {
margin: 46rpx 30rpx 0 30rpx;
border-top: 1px solid #f0f0f0;
padding-top: 10rpx;
}
.order-details .writeOff .rules .item {
margin-top: 20rpx;
}
.order-details .writeOff .rules .item .rulesTitle {
font-size: 28rpx;
color: #282828;
}
.order-details .writeOff .rules .item .rulesTitle .iconfont {
font-size: 30rpx;
color: #333;
margin-right: 8rpx;
margin-top: 5rpx;
}
.order-details .writeOff .rules .item .info {
font-size: 28rpx;
color: #999;
margin-top: 7rpx;
}
.order-details .writeOff .rules .item .info .time {
margin-left: 20rpx;
}
.order-details .pickup-card {
margin-top: 15rpx;
background-color: #fff;
padding: 22rpx 24rpx 24rpx;
box-sizing: border-box;
}
.order-details .pickup-hd {
display: flex;
align-items: center;
justify-content: space-between;
}
.order-details .pickup-title {
font-size: 30rpx;
color: #282828;
font-weight: 700;
}
.order-details .pickup-distance {
padding: 4rpx 12rpx;
border-radius: 999rpx;
font-size: 22rpx;
color: #2556ec;
background: rgba(37, 86, 236, 0.12);
}
.order-details .pickup-address {
margin-top: 10rpx;
font-size: 26rpx;
color: #666;
line-height: 36rpx;
}
.order-details .pickup-cover {
width: 100%;
height: 168rpx;
border-radius: 16rpx;
display: block;
margin-bottom: 14rpx;
background: #f2f4f7;
}
.order-details .pickup-hours {
margin-top: 10rpx;
display: flex;
align-items: center;
gap: 10rpx;
}
.order-details .pickup-hours__text {
font-size: 24rpx;
color: #8c8c8c;
}
.order-details .pickup-btn {
margin-top: 16rpx;
height: 76rpx;
border-radius: 16rpx;
border: 2rpx solid rgba(37, 86, 236, 0.35);
background: #fff;
color: #2556ec;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
</style>