Files
xdd-uniapp-new/pkg_product/views/experienceCouponOrderDetail.vue
T

639 lines
15 KiB
Vue
Raw 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="coupon-order-detail">
<view class="status-banner" :class="{ 'completed': isCompleted || isExpired }">
<view v-if="isCompleted">
<view class="status-text v12-dark-text">已完成</view>
<view class="status-subtext v12-dark-text">期待再次光临</view>
</view>
<view v-else-if="isExpired">
<view class="status-text v12-dark-text">已过期</view>
<view class="status-subtext v12-dark-text">很遗憾你的体验券已过期</view>
</view>
<text v-else class="status-text">{{ statusText }}</text>
</view>
<view class="qrcode-card" v-if="!isCompleted && !isExpired">
<view class="merchant-header" v-if="orderInfo.merchantName">
<image :src="webUrl + '/orderIcon/shop.png'" class="shop-icon" />
<text class="merchant-name">{{ orderInfo.merchantName }}</text>
<image :src="webUrl + '/orderIcon/arrow.png'" class="arrow-icon" />
</view>
<view class="project-name v12-font-34">
{{ orderInfo.experienceItemInfo.themeName || '' }}
</view>
<view class="qrcode-wrap" v-if="orderInfo.code">
<image :src="orderInfo.code" class="qrcode-image" mode="aspectFit" />
</view>
<view class="verify-code">
<text class="label">核销码</text>
<text class="value">{{ orderInfo.verifyCode || '-' }}</text>
<image :src="webUrl + '/orderIcon/copy.png'" class="copy-icon" @click="copyVerifyCode" v-if="orderInfo.verifyCode" />
</view>
<view v-if="orderInfo.validityPeriod" class="valid-time">
有效期 {{ orderInfo.validityPeriod || '-' }}
</view>
</view>
<view class="merchant-card">
<view class="merchant-card-top">
<image :src="orderInfo.experienceItemInfo.themeImage " class="merchant-avatar" mode="aspectFill" />
<view class="merchant-info">
<view class="merchant-name-large">{{ orderInfo.merchantName }}</view>
<view class="merchant-time" v-if="formattedBusinessTime">营业时间{{ formattedBusinessTime }}</view>
<view class="merchant-actions">
<view class="action-btn" @click="openLocation">
<u-icon :name="webUrl + '/page/qianxian/icon-addr.png'" color="#fff" size="24"></u-icon>
</view>
<view class="action-btn" @click="callMerchant">
<u-icon :name="webUrl + '/page/qianxian/icon-phone.png'" color="#fff" size="24"></u-icon>
</view>
</view>
<view class="merchant-location-wrap one-t v12-mb-2">
<image :src="webUrl + '/orderIcon/map.png'" class="location-icon" />
<text class="distance-text" v-if="distanceText">距该地{{ distanceText }}km</text>
<text class="address-text">{{ orderInfo.address }}</text>
</view>
</view>
</view>
</view>
<view class="detail-section">
<view class="section-title">订单详情</view>
<view class="info-row" v-if="isCompleted || isExpired">
<text class="label"> </text>
<text class="value">{{ orderInfo.experienceItemInfo && orderInfo.experienceItemInfo.themeName ? orderInfo.experienceItemInfo.themeName : '' }}</text>
</view>
<view class="info-row">
<text class="label">订单号</text>
<view class="value with-copy">
<text>{{ orderInfo.orderId || '' }}</text>
<image :src="webUrl + '/orderIcon/copy.png'" class="copy-icon" @click="copyOrderId" v-if="orderInfo.orderId" />
</view>
</view>
<view class="info-row">
<text class="label">订单类型</text>
<text class="value">{{ orderInfo.orderTypeDesc || '免费体验券' }}</text>
</view>
<view class="info-row" v-if="isCompleted">
<text class="label">核销时间</text>
<text class="value">{{ formatTime(orderInfo.verifyTime) || '-' }}</text>
</view>
<view class="info-row" v-if="isCompleted">
<text class="label">订单状态</text>
<text class="value">核销完成</text>
</view>
<view class="info-row" v-if="isExpired && orderInfo.endTime">
<text class="label">到期时间</text>
<text class="value">{{ orderInfo.endTime || '-' }}</text>
</view>
<view class="info-row" v-if="isExpired">
<text class="label">订单状态</text>
<text class="value">已过期</text>
</view>
</view>
<view class="notice-section" v-if="!isCompleted && !isExpired">
<view class="section-title">使用须知</view>
<view class="rich-text-content">
<u-parse :content="orderInfo.experienceItemInfo && orderInfo.experienceItemInfo.useNotice ? orderInfo.experienceItemInfo.useNotice : ''"></u-parse>
</view>
</view>
<view class="bottom-bar" v-if="isCompleted || isExpired">
<view class="home-btn" @click="goHome">
<u-icon name="home" color="#C52733" size="38rpx" class="home-icon"></u-icon>
<text>返回主页</text>
</view>
</view>
</view>
</template>
<script>
import { getExperienceCouponOrderDetail } from '@/api/product'
export default {
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
orderId: '',
orderInfo: {},
userLatitude: null,
userLongitude: null,
distanceText: '',
pollTimer: null
}
},
computed: {
statusText() {
const status = this.orderInfo.experienceOrderStatus
if (status === 0) {
return '待使用'
}
if (status === 1) {
return '已完成'
}
if (status === 2) {
return '已过期'
}
return ''
},
isCompleted() {
return this.orderInfo.experienceOrderStatus === 1
},
isExpired() {
return this.orderInfo.experienceOrderStatus === 2
},
formattedBusinessTime() {
return (this.orderInfo.serviceTime || '00:00') + '~' + (this.orderInfo.serviceEndTime || '23:59')
}
},
onLoad(options) {
if (options && options.orderId) {
this.orderId = options.orderId
this.fetchDetail()
}
this.getUserLocation()
},
onUnload() {
this.stopOrderPoll()
},
onHide() {
this.stopOrderPoll()
},
methods: {
fetchDetail() {
if (!this.orderId) {
return
}
getExperienceCouponOrderDetail(this.orderId).then(({ data }) => {
this.orderInfo = data || {}
this.updateDistance()
if (!this.isCompleted && !this.isExpired) {
this.startOrderPoll()
} else {
this.stopOrderPoll()
}
}).catch(() => {})
},
startOrderPoll() {
if (this.pollTimer || !this.orderId) {
return
}
this.pollTimer = setInterval(() => {
if (this.isCompleted || this.isExpired) {
this.stopOrderPoll()
return
}
this.fetchDetail()
}, 5000)
},
stopOrderPoll() {
if (this.pollTimer) {
clearInterval(this.pollTimer)
this.pollTimer = null
}
},
getUserLocation() {
uni.getLocation({
type: 'gcj02',
success: res => {
this.userLatitude = res.latitude
this.userLongitude = res.longitude
this.updateDistance()
}
})
},
formatTimestamp(timestamp) {
if (!timestamp) return ''
const date = new Date(Number(timestamp))
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
formatTime(timestamp) {
if (!timestamp) return ''
const date = new Date(Number(timestamp))
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return `${year}${month}${day}日`
},
goHome() {
uni.switchTab({
url: '/pages/home/index'
})
},
updateDistance() {
if (
this.userLatitude == null ||
this.userLongitude == null ||
this.orderInfo.latitude == null ||
this.orderInfo.longitude == null
) {
return
}
const lat1 = Number(this.userLatitude)
const lon1 = Number(this.userLongitude)
const lat2 = Number(this.orderInfo.latitude)
const lon2 = Number(this.orderInfo.longitude)
const R = 6371
const dLat = (lat2 - lat1) * Math.PI / 180
const dLon = (lon2 - lon1) * Math.PI / 180
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
Math.sin(dLon / 2) * Math.sin(dLon / 2)
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
const d = R * c
this.distanceText = d.toFixed(1)
},
callMerchant() {
const phone = this.orderInfo.merchantPhone || this.orderInfo.merPhone || (this.orderInfo.experienceItemInfo && this.orderInfo.experienceItemInfo.phone) || this.orderInfo.companyTel;
if (phone) {
uni.makePhoneCall({
phoneNumber: phone
})
} else {
uni.showToast({ title: '暂无商家电话', icon: 'none' })
}
},
openLocation() {
if (this.orderInfo.latitude && this.orderInfo.longitude) {
uni.openLocation({
latitude: Number(this.orderInfo.latitude),
longitude: Number(this.orderInfo.longitude),
name: this.orderInfo.merchantName,
address: this.orderInfo.address
})
} else {
uni.showToast({ title: '暂无位置信息', icon: 'none' })
}
},
copyVerifyCode() {
if (!this.orderInfo.verifyCode) {
return
}
uni.setClipboardData({
data: this.orderInfo.verifyCode,
success: () => {
uni.showToast({
title: '已复制核销码',
icon: 'none'
})
}
})
},
copyOrderId() {
if (!this.orderInfo.orderId) {
return
}
uni.setClipboardData({
data: this.orderInfo.orderId,
success: () => {
uni.showToast({
title: '已复制订单号',
icon: 'none'
})
}
})
}
}
}
</script>
<style scoped lang="less">
.coupon-order-detail {
min-height: 100vh;
padding: 24rpx;
box-sizing: border-box;
background: #f5f5f5;
padding-bottom: 120rpx;
}
.status-banner {
background: #C52733;
border-radius: 16rpx;
padding: 24rpx 32rpx;
margin-bottom: 24rpx;
}
.status-banner.completed {
background: #fff;
padding: 32rpx;
}
.status-text {
color: #fff;
font-size: 32rpx;
font-weight: bold;
}
.status-text.dark-text {
color: #333;
font-size: 36rpx;
margin-bottom: 8rpx;
}
.status-subtext {
font-size: 24rpx;
color: #666;
}
.qrcode-card {
background: #fff;
border-radius: 16rpx;
padding: 32rpx;
margin-bottom: 24rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.merchant-header {
width: 100%;
display: flex;
align-items: center;
margin-bottom: 24rpx;
align-self: flex-start;
}
.shop-icon {
width: 32rpx;
height: 32rpx;
margin-right: 12rpx;
}
.merchant-name {
font-size: 28rpx;
color: #333;
font-weight: 500;
}
.arrow-icon {
width: 24rpx;
height: 24rpx;
margin-left: 8rpx;
}
.project-name {
font-size: 36rpx;
color: #333;
font-weight: bold;
margin-bottom: 24rpx;
text-align: center;
}
.qrcode-wrap {
width: 336rpx;
height: 336rpx;
margin-bottom: 24rpx;
border-radius: 20px;
border: 1px solid #B8B8B8;
padding: 20rpx;
box-sizing: border-box;
}
.qrcode-image {
width: 100%;
height: 100%;
}
.verify-code {
display: flex;
align-items: center;
margin-bottom: 16rpx;
}
.verify-code .label {
font-size: 28rpx;
color: #666;
}
.verify-code .value {
font-size: 40rpx;
color: #333;
font-weight: bold;
margin: 0 16rpx;
}
.copy-icon {
width: 32rpx;
height: 32rpx;
}
.valid-time {
font-size: 24rpx;
color: #999;
}
.merchant-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
display: flex;
flex-direction: column;
}
.merchant-card-top {
display: flex;
position: relative;
margin-bottom: 24rpx;
}
.merchant-avatar {
width: 220rpx;
height: 220rpx;
border-radius: 12rpx;
margin-right: 24rpx;
flex-shrink: 0;
}
.merchant-info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
}
.merchant-name-large {
font-size: 32rpx;
color: #333;
font-weight: bold;
margin-bottom: 8rpx;
}
.merchant-card-bottom {
display: flex;
align-items: center;
justify-content: space-between;
}
.merchant-time {
font-size: 24rpx;
color: #666;
margin-bottom: 0;
line-height: 1.4;
word-break: break-all;
flex: 1;
padding-right: 24rpx;
}
.merchant-location-wrap {
display: flex;
align-items: center;
font-size: 24rpx;
color: #999;
}
.location-icon {
width: 24rpx;
height: 24rpx;
margin-right: 4rpx;
flex-shrink: 0;
}
.distance-text {
margin-right: 12rpx;
flex-shrink: 0;
}
.address-text {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.merchant-actions {
display: flex;
flex-direction: row;
align-items: center;
flex-shrink: 0;
justify-content: flex-end;
margin: 20rpx 0;
}
.action-btn {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
background: #C52733;
display: flex;
align-items: center;
justify-content: center;
margin-left: 16rpx;
}
.detail-section {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
}
.section-title {
font-size: 32rpx;
color: #333;
font-weight: bold;
margin-bottom: 24rpx;
}
.info-row {
display: flex;
margin-bottom: 16rpx;
}
.info-row:last-child {
margin-bottom: 0;
}
.info-row .label {
font-size: 28rpx;
color: #666;
}
.info-row .value {
font-size: 28rpx;
color: #333;
flex: 1;
}
.info-row .value.with-copy {
display: flex;
align-items: center;
}
.info-row .value.with-copy .copy-icon {
margin-left: 16rpx;
}
.notice-section {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
}
.notice-item {
display: flex;
align-items: flex-start;
margin-bottom: 12rpx;
}
.notice-item:last-child {
margin-bottom: 0;
}
.notice-item .dot {
color: #666;
margin-right: 8rpx;
font-size: 24rpx;
}
.notice-item .text {
color: #666;
font-size: 26rpx;
line-height: 1.5;
}
.rich-text-content {
font-size: 26rpx;
color: #666;
line-height: 1.6;
}
.bottom-bar {
position: fixed;
bottom: 40rpx;
left: 0;
right: 0;
display: flex;
justify-content: center;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
.home-btn {
width: 686rpx;
height: 88rpx;
// background: #E8EBF0;
border: 2rpx solid #C52733;
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 32rpx;
color: #C52733;
font-weight: bold;
}
.home-icon {
width: 32rpx;
height: 32rpx;
margin-right: 12rpx;
}
</style>