Feat:体验项目订单流程对接

This commit is contained in:
linxi
2026-03-17 19:29:13 +08:00
parent 7091d7e124
commit e608382075
6 changed files with 1172 additions and 210 deletions
+489 -203
View File
@@ -1,5 +1,6 @@
<script>
import { getLatestExperienceCoupon } from '@/api/product'
import dayjs from 'dayjs'
import { getLatestExperienceCoupon, getExperienceCouponList, getExperienceCouponItems, createExperienceCouponOrder } from '@/api/product'
import { getExperienceStoreCategoryList } from '@/api/join'
export default {
@@ -10,60 +11,18 @@ export default {
headerImage: webUrl + '/experienceCoupon/header.png',
totalCount: 0,
selectedCount: 0,
initialUsedCount: 0,
remainNum: 0,
startTime: '',
endTime: '',
expireDate: '',
couponList: [],
activeCouponId: null,
categoryList: [
{ id: 'all', name: '全部体验' }
],
activeCategoryId: 'all',
experienceList: [
{
id: 1,
title: 'Wave Restaurant',
subTitle: '一种咖啡 两种体验',
distance: '距选地点1.8km',
businessTime: '09:30-02:00',
tags: '两种体验咖啡',
categoryId: 'all',
image: webUrl + '/experienceCoupon/experience-1.png',
selected: true
},
{
id: 2,
title: '老信食堂',
subTitle: '云南特色卤菜',
distance: '距选地点1.8km',
businessTime: '09:30-02:00',
tags: '云南特色美食',
categoryId: 'all',
image: webUrl + '/experienceCoupon/experience-2.png',
selected: true
},
{
id: 3,
title: '桃矢小馆·缘味小融合',
subTitle: '会员可享受氛围小店',
distance: '距选地点1.8km',
businessTime: '09:30-02:00',
tags: '氛围小店美食',
categoryId: 'all',
image: webUrl + '/experienceCoupon/experience-3.png',
selected: false
},
{
id: 4,
title: '哇猫博物馆',
subTitle: '非遗猫文化体验',
distance: '距选地点1.8km',
businessTime: '09:30-02:00',
tags: '非遗手作体验',
categoryId: 'all',
image: webUrl + '/experienceCoupon/experience-4.png',
selected: false
}
]
experienceList: []
}
},
computed: {
@@ -74,33 +33,76 @@ export default {
return this.experienceList.filter(item => item.categoryId === this.activeCategoryId)
},
remainCount() {
if (this.remainNum != null) {
return this.remainNum
}
return this.totalCount - this.selectedCount
return Math.max(this.totalCount - this.selectedCount, 0)
}
},
onLoad() {
this.initPage()
},
methods: {
formatDateByTimestamp(value) {
if (value == null || value === '') {
return ''
}
if (typeof value === 'number') {
const ts = value > 1000000000000 ? value : value * 1000
return dayjs(ts).format('YYYY-MM-DD')
}
const num = Number(value)
if (!Number.isNaN(num)) {
const ts = num > 1000000000000 ? num : num * 1000
return dayjs(ts).format('YYYY-MM-DD')
}
return value
},
initPage() {
this.fetchExperienceCoupon()
this.fetchCouponList()
this.fetchCategoryList()
},
setActiveCoupon(coupon) {
if (!coupon) {
return
}
this.activeCouponId = coupon.id
this.totalCount = coupon.totalNum || 0
const remain = coupon.remainNum != null ? coupon.remainNum : 0
this.remainNum = remain
this.initialUsedCount = Math.max(this.totalCount - remain, 0)
this.selectedCount = this.initialUsedCount
this.startTime = coupon.startTime || ''
this.endTime = coupon.endTime || ''
this.expireDate = this.endTime || this.expireDate
this.headerImage = coupon.experienceCouponImage || (this.webUrl + '/experienceCoupon/header.png')
this.fetchExperienceItems()
},
fetchExperienceCoupon() {
getLatestExperienceCoupon().then(({ data }) => {
if (!data) {
return
}
this.totalCount = data.totalNum || 0
const remain = data.remainNum != null ? data.remainNum : 0
this.remainNum = remain
this.selectedCount = Math.max(this.totalCount - remain, 0)
this.startTime = data.startTime || ''
this.endTime = data.endTime || ''
this.expireDate = this.endTime || this.expireDate
this.headerImage = data.experienceCouponImage || this.headerImage
const latest = {
...data,
startTime: this.formatDateByTimestamp(data.startTime),
endTime: this.formatDateByTimestamp(data.endTime)
}
this.setActiveCoupon(latest)
if (!this.couponList.length) {
this.couponList = [latest]
}
}).catch(() => {})
},
fetchCouponList() {
getExperienceCouponList().then(({ data }) => {
const list = (data || []).map(item => ({
...item,
startTime: this.formatDateByTimestamp(item.startTime),
endTime: this.formatDateByTimestamp(item.endTime)
}))
this.couponList = list
if (!this.activeCouponId && list.length > 0) {
this.setActiveCoupon(list[0])
}
}).catch(() => {})
},
fetchCategoryList() {
@@ -113,25 +115,42 @@ export default {
name: item.name
}))
]
if (list.length > 0) {
const ids = list.map(item => item.id)
if (this.experienceList[0]) {
this.experienceList[0].categoryId = ids[0]
}
if (this.experienceList[1]) {
this.experienceList[1].categoryId = ids[Math.min(1, ids.length - 1)]
}
if (this.experienceList[2]) {
this.experienceList[2].categoryId = ids[Math.min(2, ids.length - 1)]
}
if (this.experienceList[3]) {
this.experienceList[3].categoryId = ids[Math.min(3, ids.length - 1)]
}
}
}).catch(() => {})
},
fetchExperienceItems() {
if (!this.activeCouponId) {
this.experienceList = []
return
}
const params = {
couponId: this.activeCouponId
}
if (this.activeCategoryId && this.activeCategoryId !== 'all') {
params.experienceStoreCategoryId = this.activeCategoryId
}
getExperienceCouponItems(params).then(({ data }) => {
const list = data || []
this.experienceList = list.map(item => ({
id: item.id != null ? item.id : (item.projectId != null ? item.projectId : item.merId),
title: item.name || '',
subTitle: item.projectName || item.intro || '',
distance: item.cityName && item.areaName ? `${item.cityName}${item.areaName}` : '',
businessTime: item.serviceTime && item.serviceEndTime ? `${item.serviceTime}-${item.serviceEndTime}` : (item.serviceTime || ''),
tags: item.intro || '',
categoryId: this.activeCategoryId === 'all' ? 'all' : this.activeCategoryId,
image: item.image || item.cover || '',
selected: false
}))
}).catch(() => {
this.experienceList = []
})
},
changeCoupon(coupon) {
this.setActiveCoupon(coupon)
},
changeCategory(id) {
this.activeCategoryId = id
this.fetchExperienceItems()
},
toggleSelect(item) {
if (!item.selected && this.remainCount === 0) {
@@ -142,25 +161,67 @@ export default {
return
}
item.selected = !item.selected
this.selectedCount = this.experienceList.filter(it => it.selected).length
const currentSelected = this.experienceList.filter(it => it.selected).length
this.selectedCount = this.initialUsedCount + currentSelected
},
submitOrder() {
if (!this.activeCouponId) {
uni.showToast({
title: '当前无可用体验券',
icon: 'none'
})
return
}
const selected = this.experienceList.filter(it => it.selected)
if (!selected.length) {
uni.showToast({
title: '请先选择体验项目',
icon: 'none'
})
return
}
const projectIds = selected.map(it => it.id)
const data = {
couponId: this.activeCouponId,
projectIds
}
createExperienceCouponOrder(data).then((res) => {
if (res.success || (res.data && res.data.status === 'SUCCESS')) {
uni.showToast({
title: '下单成功',
icon: 'success'
})
setTimeout(() => {
const orderId = res.data && res.data.orderId ? res.data.orderId : (res.orderId || '')
if (orderId) {
uni.navigateTo({
url: `/pkg_product/views/experienceCouponOrderDetail?orderId=${orderId}`
})
} else {
this.initPage()
}
}, 1500)
} else {
uni.showToast({
title: res.msg || '下单失败,请稍后重试',
icon: 'none'
})
}
}).catch(() => {
uni.showToast({
title: '下单失败,请稍后重试',
icon: 'none'
})
})
},
handleContinueSelect() {
uni.showToast({
title: '请继续选择体验券',
icon: 'none'
})
this.submitOrder()
},
handleGoExperience() {
uni.showToast({
title: '请前往体验门店使用',
icon: 'none'
})
this.submitOrder()
},
handleConfirm() {
uni.showToast({
title: '已确认体验券选择',
icon: 'none'
})
this.submitOrder()
}
}
}
@@ -176,47 +237,75 @@ export default {
/>
<view class="header-mask" />
<view class="header-content">
<view class="header-tag">
选择您的免费体验券
<view
v-if="couponList.length > 1"
class="coupon-tabs"
>
<view
v-for="(coupon, index) in couponList"
:key="coupon.id"
class="header-tag-main"
:class="{ active: activeCouponId === coupon.id }"
@click="changeCoupon(coupon)"
>
体验券{{ index + 1}}
</view>
</view>
<view class="header-main">
<view class="line">
根据您的套票,您有
<text class="strong">{{ totalCount }}</text>
张体验券可以选择
<view class="line-info flex ai-center">
根据您的套餐,您有 <view class="num-badge">{{ totalCount }}</view> 张体验券可以选择
</view>
<view class="line flex jc-between ai-center">
<view>
已选清单
<text class="strong">{{ selectedCount }}/{{ totalCount }}</text>
<view class="line-status flex ai-center">
<view class="status-pill flex ai-center">
<view class="icon-check" />
<text class="status-text">已选清单</text>
<view class="count-badge">{{ selectedCount }}/{{ totalCount }}</view>
</view>
<view class="date-info flex ai-center">
<text>请在</text>
<view class="date-badge">{{ expireDate }}</view>
<text>内选择使用</text>
</view>
</view>
<view class="line">
请在
<text class="strong">{{ expireDate }}</text>
内选择使用
<view class="line-library flex ai-center">
<image src="https://img.js.design/assets/img/6784c04289050d2f0997e096.png" class="icon-shop" mode="widthFix" />
<text class="v12-font-32">可用体验券库</text>
</view>
</view>
</view>
</view>
<view class="content">
<view class="section-header flex jc-between ai-center">
<view class="title">
可用体验券库
<scroll-view scroll-x class="tabs-scroll" :show-scrollbar="false">
<view class="tabs flex">
<view
v-for="item in categoryList"
:key="item.id"
class="tab-item"
:class="{ active: activeCategoryId === item.id }"
@click="changeCategory(item.id)"
>
{{ item.name }}
</view>
</view>
</scroll-view>
<view
v-if="filteredList.length === 0"
class="empty-state"
>
<image
:src="webUrl + '/orderIcon/nodata.png'"
class="empty-image"
mode="widthFix"
/>
<view class="empty-text">
暂无数据
</view>
</view>
<view class="tabs flex">
<view
v-for="item in categoryList"
:key="item.id"
class="tab-item"
:class="{ active: activeCategoryId === item.id }"
@click="changeCategory(item.id)"
>
{{ item.name }}
</view>
</view>
<view class="card-list">
<view
v-else
class="card-list"
>
<view
v-for="item in filteredList"
:key="item.id"
@@ -225,7 +314,7 @@ export default {
<image
:src="item.image"
class="card-image"
mode="aspectFill"
mode="widthFix"
/>
<view class="card-body">
<view class="card-title">
@@ -234,20 +323,21 @@ export default {
<view class="card-subtitle more-t">
{{ item.subTitle }}
</view>
<view class="card-meta flex jc-between">
<text class="meta-distance">{{ item.distance }}</text>
<view class="card-meta">
<view class="meta-distance">
<view class="icon-location" />
<text>距该地{{ item.distance }}</text>
</view>
<text class="meta-time">营业时间:{{ item.businessTime }}</text>
</view>
<view class="card-footer flex jc-between ai-center">
<view class="card-tags more-t">
{{ item.tags }}
</view>
<view class="card-footer flex jc-center ai-center">
<view
class="card-btn"
:class="{ selected: item.selected }"
@click.stop="toggleSelect(item)"
>
{{ item.selected ? '取消选择' : '立即选择' }}
<view v-if="item.selected" class="icon-check-circle" />
</view>
</view>
</view>
@@ -296,7 +386,7 @@ export default {
}
.header {
position: relative;
height: 360rpx;
height: 500rpx;
overflow: hidden;
}
.header-bg {
@@ -307,148 +397,344 @@ export default {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
height: 220rpx;
background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
background: linear-gradient(180deg, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.6) 100%);
z-index: 1;
}
.header-blur-transition {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 120rpx;
background: linear-gradient(to bottom, rgba(245, 245, 245, 0) 0%, rgba(245, 245, 245, 0.8) 60%, #f5f5f5 100%);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
z-index: 2;
pointer-events: none;
}
.header-content {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
padding: 32rpx 32rpx 40rpx;
padding: 32rpx;
box-sizing: border-box;
color: #fff;
display: flex;
flex-direction: column;
justify-content: space-between;
z-index: 3;
}
.header-tag {
display: inline-block;
padding: 6rpx 24rpx;
margin-bottom: 16rpx;
border-radius: 40rpx;
background: #C52733;
font-size: 22rpx;
}
.header-main .line {
margin-top: 8rpx;
font-size: 24rpx;
}
.header-main .strong {
margin: 0 4rpx;
.header-tag-main {
align-self: flex-start;
padding: 12rpx 32rpx 12rpx 24rpx;
background: #fff;
font-weight: bold;
color: #333;
font-size: 28rpx;
font-weight: 600;
}
.content {
padding: 24rpx 24rpx 0;
}
.section-header .title {
font-size: 30rpx;
font-weight: 600;
}
.tabs {
margin-top: 24rpx;
padding: 4rpx;
border-radius: 40rpx;
background: #f0f0f0;
}
.tab-item {
flex: 1;
padding: 16rpx 0;
text-align: center;
font-size: 24rpx;
color: #666;
border-radius: 32rpx;
}
.tab-item.active {
.header-tag-main.active {
background: #C52733;
color: #fff;
}
.header-main {
margin-bottom: 20rpx;
}
.coupon-tabs {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
margin-bottom: 20rpx;
}
.coupon-tab-item {
padding: 8rpx 24rpx;
border-radius: 32rpx;
background: rgba(255, 255, 255, 0.2);
border: 1rpx solid rgba(255, 255, 255, 0.4);
font-size: 24rpx;
color: #fff;
&.active {
background: #fff;
color: #C52733;
border-color: #fff;
}
}
.line-info {
font-size: 26rpx;
margin-bottom: 24rpx;
justify-content: flex-end;
}
.num-badge {
background: #C52733;
color: #fff;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 26rpx;
margin: 0 8rpx;
font-weight: bold;
}
.line-status {
justify-content: flex-end;
gap: 16rpx;
margin-bottom: 24rpx;
}
.status-pill {
background: #C52733;
padding: 6rpx 6rpx 6rpx 20rpx;
border-radius: 32rpx;
color: #fff;
font-size: 26rpx;
}
.status-text {
margin-right: 12rpx;
}
.icon-check {
width: 24rpx;
height: 24rpx;
border-radius: 50%;
border: 2rpx solid #fff;
margin-right: 8rpx;
position: relative;
}
.icon-check::after {
content: '';
position: absolute;
left: 6rpx;
top: 4rpx;
width: 8rpx;
height: 4rpx;
border-left: 2rpx solid #fff;
border-bottom: 2rpx solid #fff;
transform: rotate(-45deg);
}
.count-badge {
background: #fff;
color: #333;
padding: 4rpx 16rpx;
border-radius: 24rpx;
font-size: 24rpx;
}
.date-info {
font-size: 26rpx;
color: #fff;
}
.date-badge {
background: #C52733;
padding: 6rpx 16rpx;
border-radius: 100rpx;
margin: 0 8rpx;
font-size: 32rpx;
font-weight: bold;
}
.line-library {
font-size: 28rpx;
font-weight: 500;
.icon-shop {
width: 32rpx;
height: 32rpx;
margin-right: 8rpx;
}
}
.content {
padding: 0 24rpx;
margin-top: -20rpx;
position: relative;
z-index: 4;
}
.tabs-scroll {
width: 100%;
white-space: nowrap;
margin-bottom: 24rpx;
}
.tabs {
display: flex;
gap: 16rpx;
padding-right: 24rpx;
}
.tab-item {
padding: 12rpx 32rpx;
border-radius: 32rpx;
background: #fff;
color: #666;
font-size: 26rpx;
flex-shrink: 0;
font-style: italic;
font-weight: bold;
&.active {
background: #C52733;
color: #fff;
}
}
.card-list {
margin-top: 24rpx;
padding-bottom: 24rpx;
column-count: 2;
column-gap: 20rpx;
}
.card {
margin-bottom: 24rpx;
border-radius: 20rpx;
overflow: hidden;
background: #fff;
break-inside: avoid;
}
.card-image {
width: 100%;
height: 260rpx;
height: auto;
display: block;
}
.card-body {
padding: 20rpx 24rpx 24rpx;
padding: 16rpx;
}
.card-title {
font-size: 30rpx;
font-weight: 600;
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 8rpx;
}
.card-subtitle {
margin-top: 8rpx;
font-size: 24rpx;
color: #666;
font-size: 22rpx;
color: #999;
margin-bottom: 8rpx;
}
.card-meta {
margin-top: 12rpx;
font-size: 22rpx;
color: #999;
color: #666;
margin-bottom: 16rpx;
}
.meta-distance {
display: flex;
align-items: center;
margin-bottom: 4rpx;
}
.icon-location {
width: 20rpx;
height: 20rpx;
border: 2rpx solid #666;
border-radius: 50%;
margin-right: 4rpx;
position: relative;
}
.icon-location::after {
content: '';
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 6rpx;
height: 6rpx;
background: #666;
border-radius: 50%;
}
.meta-time {
display: block;
}
.card-footer {
margin-top: 16rpx;
}
.card-tags {
flex: 1;
margin-right: 16rpx;
font-size: 22rpx;
color: #999;
margin-top: 12rpx;
}
.card-btn {
min-width: 160rpx;
padding: 12rpx 24rpx;
border-radius: 40rpx;
text-align: center;
font-size: 24rpx;
width: 100%;
height: 64rpx;
border-radius: 32rpx;
font-size: 26rpx;
color: #C52733;
border: 1rpx solid #C52733;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
&.selected {
background: #C52733;
color: #fff;
}
}
.card-btn.selected {
background: #C52733;
color: #fff;
.icon-check-circle {
width: 24rpx;
height: 24rpx;
background: #fff;
border-radius: 50%;
margin-left: 8rpx;
position: relative;
}
.icon-check-circle::after {
content: '';
position: absolute;
left: 7rpx;
top: 5rpx;
width: 8rpx;
height: 4rpx;
border-left: 2rpx solid #C52733;
border-bottom: 2rpx solid #C52733;
transform: rotate(-45deg);
}
.bottom-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 16rpx 24rpx 32rpx;
box-sizing: border-box;
padding: 24rpx 32rpx 48rpx;
background: #fff;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
z-index: 10;
}
.bottom-group {
column-gap: 16rpx;
gap: 24rpx;
}
.btn-outline {
flex: 1;
height: 80rpx;
border-radius: 40rpx;
border: 1rpx solid #C52733;
flex: 1.2;
height: 88rpx;
border-radius: 44rpx;
border: 2rpx solid #333;
text-align: center;
font-size: 26rpx;
line-height: 80rpx;
color: #C52733;
font-size: 28rpx;
line-height: 84rpx;
color: #333;
background: #fff;
font-weight: bold;
font-style: italic;
}
.btn-primary {
flex: 1;
height: 80rpx;
border-radius: 40rpx;
height: 88rpx;
border-radius: 44rpx;
text-align: center;
font-size: 28rpx;
line-height: 80rpx;
font-size: 30rpx;
line-height: 88rpx;
color: #fff;
background: #C52733;
font-weight: bold;
font-style: italic;
}
.bottom-single .btn-primary {
width: 100%;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60rpx 0;
}
.empty-image {
width: 320rpx;
height: 320rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
margin-top: 20rpx;
}
</style>