mall-app-t/pages/order/detail.vue

627 lines
20 KiB
Vue
Raw Normal View History

2024-05-27 18:30:44 +08:00
<!-- 订单详情 -->
<template>
2024-06-03 18:35:53 +08:00
<pb-layout
title="订单详情"
class="goods-detail-wrap"
navbar="inner"
leftIcon="leftIcon"
color="#fff"
iconColor="#fff"
>
2024-05-27 18:30:44 +08:00
<!-- 订单状态 -->
<view
class="state-box ss-flex-col ss-col-center ss-row-right"
:style="[
{
marginTop: '-' + Number(statusBarHeight + 88) + 'rpx',
paddingTop: Number(statusBarHeight + 88) + 'rpx',
},
]"
>
<view class="ss-flex ss-m-t-32 ss-m-b-20">
<image
v-if="
state.orderInfo.status_code == 'unpaid' ||
state.orderInfo.status === 10 || // 待发货
state.orderInfo.status_code == 'nocomment'
"
class="state-img"
2024-06-03 18:35:53 +08:00
:src="peach.$url.static('/static/img/shop/order/order_loading.png')"
2024-05-27 18:30:44 +08:00
>
</image>
<image
v-if="state.orderInfo.status_code == 'completed' || state.orderInfo.status_code == 'refund_agree'"
class="state-img"
2024-06-03 18:35:53 +08:00
:src="peach.$url.static('/static/img/shop/order/order_success.png')"
2024-05-27 18:30:44 +08:00
>
</image>
<image
v-if="state.orderInfo.status_code == 'cancel' || state.orderInfo.status_code == 'closed'"
class="state-img"
2024-06-03 18:35:53 +08:00
:src="peach.$url.static('/static/img/shop/order/order_close.png')"
2024-05-27 18:30:44 +08:00
>
</image>
<image
v-if="state.orderInfo.status_code == 'noget'"
class="state-img"
2024-06-03 18:35:53 +08:00
:src="peach.$url.static('/static/img/shop/order/order_express.png')"
2024-05-27 18:30:44 +08:00
>
</image>
<view class="ss-font-30">{{ formatOrderStatus(state.orderInfo) }}</view>
</view>
<view class="ss-font-26 ss-m-x-20 ss-m-b-70">{{ formatOrderStatusDescription(state.orderInfo) }}</view>
</view>
<!-- 收货地址 -->
2024-06-03 18:35:53 +08:00
<view class="order-address-box" v-if="state.orderInfo.receiverAreaId">
2024-05-27 18:30:44 +08:00
<view class="ss-flex ss-col-center">
<text class="address-username">
{{ state.orderInfo.receiverName }}
</text>
<text class="address-phone">{{ state.orderInfo.receiverMobile }}</text>
</view>
<view class="address-detail">
{{ state.orderInfo.receiverAreaName }} {{ state.orderInfo.receiverDetailAddress }}
</view>
</view>
<view class="detail-goods" :style="[{ marginTop: state.orderInfo.receiverAreaId > 0 ? '0' : '-40rpx' }]">
<!-- 订单信 -->
<view class="order-list" v-for="item in state.orderInfo.items" :key="item.goods_id">
<view class="order-card">
2024-06-03 18:35:53 +08:00
<p-goods-item
2024-05-27 18:30:44 +08:00
@tap="onGoodsDetail(item.spuId)"
:img="item.picUrl"
:title="item.spuName"
:skuText="item.properties.map((property) => property.valueName).join(' ')"
:price="item.price"
:num="item.count"
>
<template #tool>
<view class="ss-flex">
<button
class="ss-reset-button apply-btn"
v-if="[10, 20, 30].includes(state.orderInfo.status) && item.afterSaleStatus === 0"
@tap.stop="
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/order/aftersale/apply', {
2024-05-27 18:30:44 +08:00
orderId: state.orderInfo.id,
itemId: item.id,
})
"
>
申请售后
</button>
<button
class="ss-reset-button apply-btn"
v-if="item.afterSaleStatus === 10"
@tap.stop="
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/order/aftersale/detail', {
2024-05-27 18:30:44 +08:00
id: item.afterSaleId,
})
"
>
退款中
</button>
<button
class="ss-reset-button apply-btn"
v-if="item.afterSaleStatus === 20"
@tap.stop="
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/order/aftersale/detail', {
2024-05-27 18:30:44 +08:00
id: item.afterSaleId,
})
"
>
退款成功
</button>
</view>
</template>
<template #priceSuffix>
<button class="ss-reset-button tag-btn" v-if="item.status_text">
{{ item.status_text }}
</button>
</template>
2024-06-03 18:35:53 +08:00
</p-goods-item>
2024-05-27 18:30:44 +08:00
</view>
</view>
</view>
<!-- 订单信息 -->
<view class="notice-box">
<view class="notice-box__content">
<view class="notice-item--center">
<view class="ss-flex ss-flex-1">
<text class="title">订单编号</text>
<text class="detail">{{ state.orderInfo.no }}</text>
</view>
<button class="ss-reset-button copy-btn" @tap="onCopy">复制</button>
</view>
<view class="notice-item">
<text class="title">下单时间</text>
<text class="detail">
2024-06-03 18:35:53 +08:00
{{ peach.$helper.timeFormat(state.orderInfo.createTime, 'yyyy-mm-dd hh:MM:ss') }}
2024-05-27 18:30:44 +08:00
</text>
</view>
<view class="notice-item" v-if="state.orderInfo.payTime">
<text class="title">支付时间</text>
<text class="detail">
2024-06-03 18:35:53 +08:00
{{ peach.$helper.timeFormat(state.orderInfo.payTime, 'yyyy-mm-dd hh:MM:ss') }}
2024-05-27 18:30:44 +08:00
</text>
</view>
<view class="notice-item">
<text class="title">支付方式</text>
<text class="detail">{{ state.orderInfo.payChannelName || '-' }}</text>
</view>
</view>
</view>
<!-- 价格信息 -->
<view class="order-price-box">
<view class="notice-item ss-flex ss-row-between">
<text class="title">商品总额</text>
<view class="ss-flex">
<text class="detail">{{ fen2yuan(state.orderInfo.totalPrice) }}</text>
</view>
</view>
<view class="notice-item ss-flex ss-row-between">
<text class="title">运费</text>
<text class="detail">{{ fen2yuan(state.orderInfo.deliveryPrice) }}</text>
</view>
<!-- TODO 芋艿优惠劵抵扣积分抵扣 -->
<view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.couponPrice > 0">
<text class="title">优惠劵金额</text>
<text class="detail">-¥{{ fen2yuan(state.orderInfo.couponPrice) }}</text>
</view>
<view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.discountPrice > 0">
<text class="title">活动优惠</text>
<text class="detail">¥{{ fen2yuan(state.orderInfo.discountPrice) }}</text>
</view>
<view class="notice-item ss-flex ss-row-between" v-if="state.orderInfo.vipPrice > 0">
<text class="title">会员优惠</text>
<text class="detail">-¥{{ fen2yuan(state.orderInfo.vipPrice) }}</text>
</view>
<view class="notice-item all-rpice-item ss-flex ss-m-t-20">
<text class="title">{{ state.orderInfo.payStatus ? '已付款' : '需付款' }}</text>
<text class="detail all-price">{{ fen2yuan(state.orderInfo.payPrice) }}</text>
</view>
<view class="notice-item all-rpice-item ss-flex ss-m-t-20" v-if="state.orderInfo.refundPrice > 0">
<text class="title">已退款</text>
<text class="detail all-price">{{ fen2yuan(state.orderInfo.refundPrice) }}</text>
</view>
</view>
<!-- 底部按钮 -->
2024-06-03 18:35:53 +08:00
<pb-fixed bottom placeholder bg="bg-white" v-if="state.orderInfo.buttons?.length">
2024-05-27 18:30:44 +08:00
<view class="footer-box ss-flex ss-col-center ss-row-right">
<button
class="ss-reset-button cancel-btn"
v-if="state.orderInfo.buttons?.includes('cancel')"
@tap="onCancel(state.orderInfo.id)"
>
取消订单
</button>
<button
class="ss-reset-button pay-btn ui-BG-Main-Gradient"
v-if="state.orderInfo.buttons?.includes('pay')"
@tap="onPay(state.orderInfo.payOrderId)"
>
继续支付
</button>
<button
class="ss-reset-button cancel-btn"
v-if="state.orderInfo.buttons?.includes('combination')"
@tap="
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/activity/groupon/detail', {
2024-05-27 18:30:44 +08:00
id: state.orderInfo.combinationRecordId,
})
"
>
拼团详情
</button>
<button
class="ss-reset-button cancel-btn"
v-if="state.orderInfo.buttons?.includes('express')"
@tap="onExpress(state.orderInfo.id)"
>
查看物流
</button>
<button
class="ss-reset-button cancel-btn"
v-if="state.orderInfo.buttons?.includes('confirm')"
@tap="onConfirm(state.orderInfo.id)"
>
确认收货
</button>
<button
class="ss-reset-button cancel-btn"
v-if="state.orderInfo.buttons?.includes('comment')"
@tap="onComment(state.orderInfo.id)"
>
评价
</button>
2024-06-03 18:35:53 +08:00
<button
v-if="state.orderInfo.buttons.includes('verification')"
class="ss-reset-button cancel-btn ui-BG-Main-Gradient"
@tap.stop="onVerification(order.id)"
>
核销订单
</button>
<button
v-if="state.orderInfo.buttons.includes('delivery')"
class="ss-reset-button cancel-btn ui-BG-Main-Gradient"
@tap.stop="onDelivery(order.id)"
>
配送完成
</button>
2024-05-27 18:30:44 +08:00
</view>
2024-06-03 18:35:53 +08:00
</pb-fixed>
</pb-layout>
2024-05-27 18:30:44 +08:00
</template>
<script setup>
2024-06-03 18:35:53 +08:00
import peach from '@/peach'
2024-05-27 18:30:44 +08:00
import { onLoad } from '@dcloudio/uni-app'
import { reactive } from 'vue'
import { isEmpty } from 'lodash'
2024-06-03 18:35:53 +08:00
import { fen2yuan, formatOrderStatus, formatOrderStatusDescription, handleOrderButtons } from '@/peach/hooks/useGoods'
import OrderApi from '@/peach/api/trade/order'
2024-05-27 18:30:44 +08:00
2024-06-03 18:35:53 +08:00
const statusBarHeight = peach.$platform.device.statusBarHeight * 2
2024-05-27 18:30:44 +08:00
const state = reactive({
orderInfo: {},
merchantTradeNo: '', // 商户订单号
comeinType: '', // 进入订单详情的来源类型
})
// 复制
const onCopy = () => {
2024-06-03 18:35:53 +08:00
peach.$helper.copyText(state.orderInfo.sn)
2024-05-27 18:30:44 +08:00
}
// 去支付
function onPay(payOrderId) {
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/pay/index', {
2024-05-27 18:30:44 +08:00
id: payOrderId,
})
}
// 查看商品
function onGoodsDetail(id) {
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/goods/index', {
2024-05-27 18:30:44 +08:00
id,
})
}
// 取消订单
async function onCancel(orderId) {
uni.showModal({
title: '提示',
content: '确定要取消订单吗?',
success: async function (res) {
if (!res.confirm) {
return
}
const { code } = await OrderApi.cancelOrder(orderId)
if (code === 0) {
await getOrderDetail(orderId)
}
},
})
}
// 查看物流
async function onExpress(id) {
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/order/express/log', {
2024-05-27 18:30:44 +08:00
id,
})
}
// 确认收货 TODO 芋艿:待测试
async function onConfirm(orderId, ignore = false) {
// 需开启确认收货组件
// todo: 芋艿:待接入微信
// 1.怎么检测是否开启了发货组件功能如果没有开启的话就不能在这里return出去
// 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
let isOpenBusinessView = true
if (
2024-06-03 18:35:53 +08:00
peach.$platform.name === 'WechatMiniProgram' &&
2024-05-27 18:30:44 +08:00
!isEmpty(state.orderInfo.wechat_extra_data) &&
isOpenBusinessView &&
!ignore
) {
mpConfirm(orderId)
return
}
// 正常的确认收货流程
const { code } = await OrderApi.receiveOrder(orderId)
if (code === 0) {
await getOrderDetail(orderId)
}
}
// #ifdef MP-WEIXIN
// 小程序确认收货组件
function mpConfirm(orderId) {
if (!wx.openBusinessView) {
2024-06-03 18:35:53 +08:00
peach.$helper.toast(`请升级微信版本`)
2024-05-27 18:30:44 +08:00
return
}
wx.openBusinessView({
businessType: 'weappOrderConfirm',
extraData: {
merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
},
success(response) {
console.log('success:', response)
if (response.errMsg === 'openBusinessView:ok') {
if (response.extraData.status === 'success') {
onConfirm(orderId, true)
}
}
},
fail(error) {
console.log('error:', error)
},
complete(result) {
console.log('result:', result)
},
})
}
// #endif
// 评价
function onComment(id) {
2024-06-03 18:35:53 +08:00
peach.$router.go('/pages/goods/comment/add', {
2024-05-27 18:30:44 +08:00
id,
})
}
2024-06-03 18:35:53 +08:00
function onDelivery(id) {
uni.showModal({
title: '提示',
content: '确认完成配送吗?',
success: function (res) {
if (res.confirm) {
}
},
})
}
2024-05-27 18:30:44 +08:00
async function getOrderDetail(id) {
2024-06-03 18:35:53 +08:00
let res = await OrderApi.getOrderDetail({ id: id })
state.orderInfo = res.data
handleOrderButtons(state.orderInfo)
2024-05-27 18:30:44 +08:00
}
onLoad(async (options) => {
2024-06-03 18:35:53 +08:00
await getOrderDetail(options.id)
2024-05-27 18:30:44 +08:00
})
</script>
<style lang="scss" scoped>
.score-img {
width: 36rpx;
height: 36rpx;
margin: 0 4rpx;
}
.apply-btn {
width: 140rpx;
height: 50rpx;
border-radius: 25rpx;
font-size: 24rpx;
border: 2rpx solid #dcdcdc;
line-height: normal;
margin-left: 16rpx;
}
.state-box {
color: rgba(#fff, 0.9);
width: 100%;
2024-06-03 18:35:53 +08:00
background: url('/static/order/order_bg.png') no-repeat,
linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
2024-05-27 18:30:44 +08:00
background-size: 750rpx 100%;
box-sizing: border-box;
.state-img {
width: 60rpx;
height: 60rpx;
margin-right: 20rpx;
}
}
.order-address-box {
background-color: #fff;
border-radius: 10rpx;
margin: -50rpx 20rpx 16rpx 20rpx;
padding: 44rpx 34rpx 42rpx 20rpx;
font-size: 30rpx;
box-sizing: border-box;
font-weight: 500;
color: rgba(51, 51, 51, 1);
.address-username {
margin-right: 20rpx;
}
.address-detail {
font-size: 26rpx;
font-weight: 500;
color: rgba(153, 153, 153, 1);
margin-top: 20rpx;
}
}
.detail-goods {
border-radius: 10rpx;
margin: 0 20rpx 20rpx 20rpx;
.order-list {
margin-bottom: 20rpx;
background-color: #fff;
.order-card {
padding: 20rpx 0;
.order-sku {
font-size: 24rpx;
font-weight: 400;
color: rgba(153, 153, 153, 1);
width: 450rpx;
margin-bottom: 20rpx;
.order-num {
margin-right: 10rpx;
}
}
.tag-btn {
margin-left: 16rpx;
font-size: 24rpx;
height: 36rpx;
color: var(--ui-BG-Main);
border: 2rpx solid var(--ui-BG-Main);
border-radius: 14rpx;
padding: 0 4rpx;
}
}
}
}
// 订单信息。
.notice-box {
background: #fff;
border-radius: 10rpx;
margin: 0 20rpx 20rpx 20rpx;
.notice-box__head {
font-size: 30rpx;
font-weight: 500;
color: rgba(51, 51, 51, 1);
line-height: 80rpx;
border-bottom: 1rpx solid #dfdfdf;
padding: 0 25rpx;
}
.notice-box__content {
padding: 20rpx;
.self-pickup-box {
width: 100%;
.self-pickup--img {
width: 200rpx;
height: 200rpx;
margin: 40rpx 0;
}
}
}
.notice-item,
.notice-item--center {
display: flex;
align-items: center;
line-height: normal;
margin-bottom: 24rpx;
.title {
font-size: 28rpx;
color: #999;
}
.detail {
font-size: 28rpx;
color: #333;
flex: 1;
}
}
}
.copy-btn {
width: 100rpx;
line-height: 50rpx;
border-radius: 25rpx;
padding: 0;
background: rgba(238, 238, 238, 1);
font-size: 22rpx;
font-weight: 400;
color: rgba(51, 51, 51, 1);
}
// 订单价格信息
.order-price-box {
background-color: #fff;
border-radius: 10rpx;
padding: 20rpx;
margin: 0 20rpx 20rpx 20rpx;
.notice-item {
line-height: 70rpx;
.title {
font-size: 28rpx;
color: #999;
}
.detail {
font-size: 28rpx;
color: #333;
font-family: OPPOSANS;
}
}
.all-rpice-item {
justify-content: flex-end;
align-items: center;
.title {
font-size: 26rpx;
font-weight: 500;
color: #333333;
line-height: normal;
}
.all-price {
font-size: 26rpx;
font-family: OPPOSANS;
line-height: normal;
color: $red;
}
}
}
// 底部
.footer-box {
height: 100rpx;
width: 100%;
box-sizing: border-box;
border-radius: 10rpx;
padding-right: 20rpx;
.cancel-btn {
width: 160rpx;
height: 60rpx;
background: #eeeeee;
border-radius: 30rpx;
margin-right: 20rpx;
font-size: 26rpx;
font-weight: 400;
color: #333333;
}
.pay-btn {
width: 160rpx;
height: 60rpx;
font-size: 26rpx;
border-radius: 30rpx;
font-weight: 500;
color: #fff;
}
}
</style>