Files
kangyuan-mobile/pages/order/detail.vue
T
2026-08-05 11:10:52 +08:00

914 lines
23 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>
<s-pages title="订单详情" :pink_bg="true">
<!-- 收货地址 -->
<view class="order-address-box flex-row bg24" v-if="state.orderInfo.receiverAreaId > 0">
<view class="cityImg">
<image :src="`${$url}goods/city.png`" mode="scaleToFill" />
</view>
<view class="size32 c0">
<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 size32">
{{ state.orderInfo.receiverAreaName }} {{ state.orderInfo.receiverDetailAddress }}
</view>
</view>
</view>
<view
class="detail-goods"
:style="[{ marginTop: state.orderInfo.receiverAreaId > 0 ? '0' : '0' }]"
>
<card_order
class="order-goods"
v-if="state?.orderInfo?.items?.length > 0"
:data="state.orderInfo"
type="2"
theme="2"
@getOrderDetail="getOrderDetail"
></card_order>
<PickUpVerify
v-if="Number(state.orderInfo.deliveryType) === 2"
ref="pickUpVerifyRef"
:orderInfo="state.orderInfo"
:systemStore="systemStore"
:source="state.source"
:orderType="state.orderType"
detailStyle="order"
/>
<!-- 价格信息 -->
<view class="order-price-box bg24">
<view class="notice-item ss-flex ss-row-between" v-for="(v, i) in priceArr" :key="i">
<text class="title c0">{{ v.title }}</text>
<view class="ss-flex">
<text class="detail c0" :class="{ 'all-price': v.value == 'payPrice' }"
><span>{{ v.type == 2 ? '-' : '' }}</span
>¥{{ fen2yuan(state.orderInfo[v.value]) }}</text
>
</view>
</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>
<!-- 订单信息 -->
<view class="notice-box bg24">
<view class="notice-box__content">
<view class="notice-item--center">
<view class="ss-flex ss-flex-1 flex-row ju-between">
<text class="title c0">订单编号</text>
<text class="detail right c0">{{ state.orderInfo.no }}</text>
</view>
<!-- <button class="ss-reset-button copy-btn" @tap="onCopy">复制</button> -->
<view class="copy" @click.stop="onCopy">
<image :src="`${$url}goods/copy2.svg`" mode="scaleToFill" />
</view>
<truckLine :data="state.orderInfo" :code="1" v-if="state.orderInfo.deliveryTime"></truckLine>
</view>
<view class="notice-item flex-row ju-between">
<text class="title c0">下单时间</text>
<text class="detail right c0">
{{ sheep.$helper.timeFormat(state.orderInfo.createTime, 'yyyy-mm-dd hh:MM:ss') }}
</text>
</view>
<view class="notice-item flex-row ju-between" v-if="state.orderInfo.payTime">
<text class="title c0">支付时间:</text>
<text class="detail right c0">
{{ sheep.$helper.timeFormat(state.orderInfo.payTime, 'yyyy-mm-dd hh:MM:ss') }}
</text>
</view>
<view class="notice-item flex-row ju-between">
<text class="title c0">支付方式</text>
<text class="detail right c0">{{ state.orderInfo.payChannelName || '-' }}</text>
</view>
</view>
</view>
</view>
<su-fixed bottom placeholder bg="bg24" v-if="showBottomBar">
<view class="orderBan flex-column ju-center">
<AiOrderActionBar
v-if="isAiActionOrder"
:status="Number(state.orderInfo.status)"
:disableDelayShipment="isPickUpOrder || !isAiStoreOrder"
@delay="delayShipment"
@now="nowShipment"
@confirm="confirmReceiveOrder"
@pay="goPay"
/>
<card_orderBan v-else :data="state.orderInfo" @downData="getOrderDetail" type="2"></card_orderBan>
</view>
</su-fixed>
<uni-popup ref="delayPopupRef" type="center" background-color="transparent">
<view class="delay-popup" @tap.stop>
<view class="delay-popup__header">
<view>
<view class="delay-popup__title">延迟发货</view>
<view class="delay-popup__order-no">订单号:{{ state.orderInfo.no || '-' }}</view>
<view class="delay-popup__order-time">
下单时间:{{ formatCreateTime(state.orderInfo.createTime) || '-' }}
</view>
</view>
<view class="delay-popup__close" @tap.stop="closeDelayShipmentPopup">×</view>
</view>
<view class="delay-popup__desc">请选择当前商品及延迟发货数量</view>
<scroll-view scroll-y class="delay-popup__content">
<view
class="delay-popup__item"
v-for="(item, index) in delayShipmentItems"
:key="item.orderItemId || index"
>
<image class="delay-popup__item-image" :src="item.picUrl" mode="aspectFill" />
<view class="delay-popup__item-main">
<view class="delay-popup__item-name lineTwo">{{ item.spuName }}</view>
<view class="delay-popup__item-sku">{{ item.skuText || '-' }}</view>
<view class="delay-popup__item-footer flex-center ju-between">
<view class="delay-popup__item-count">最多可选 x{{ item.maxCount }}</view>
<su-number-box
v-model="item.selectedCount"
:min="0"
:max="item.maxCount"
:step="1"
background="#F6F7FB"
color="#333333"
@change="onDelayShipmentCountChange(index, $event)"
/>
</view>
</view>
</view>
</scroll-view>
<view class="delay-popup__actions">
<view class="delay-popup__btn delay-popup__btn--ghost" @tap.stop="closeDelayShipmentPopup">
取消
</view>
<view class="delay-popup__btn delay-popup__btn--primary" @tap.stop="submitDelayShipment">
确认延迟发货
</view>
</view>
</view>
</uni-popup>
</s-pages>
</template>
<script setup>
import sheep from '@/sheep';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { computed, reactive, ref } from 'vue';
import {
fen2yuan,
handleOrderButtons,
} from '@/sheep/hooks/useGoods';
import OrderApi from '@/sheep/api/trade/order';
import {
aiDelayedShipment,
aiPendingShipment,
confirmReceive as aiConfirmReceive,
giftConfirmReceive,
getOrderDetail as getAiOrderDetail,
getOpenOrderDetail,
} from '@/sheep/api/ai';
import StoreApi from '@/sheep/api/trade/store';
import card_order from '@/components/orderItem/card_order.vue';
import AiOrderActionBar from '@/components/orderItem/AiOrderActionBar.vue';
import truckLine from '@/components/truckLine/truckLine.vue'
import PickUpVerify from '@/pages/order/pickUpVerify.vue';
const headerBg = sheep.$url.css('/static/img/shop/order/order_bg.png');
const state = reactive({
orderInfo: {},
merchantTradeNo: '', // 商户订单号
comeinType: '', // 进入订单详情的来源类型
orderType: '',
source: '',
});
// ========== 门店自提(核销) ==========
const systemStore = ref({}); // 门店信息
// 复制
const onCopy = () => {
sheep.$helper.copyText(state.orderInfo.no);
};
const formatCreateTime = (value) => {
if (!value) return '';
const s = sheep?.$helper?.timeFormat
? sheep.$helper.timeFormat(value, 'yyyy-mm-dd hh:MM:ss')
: String(value);
return s || '';
};
const pickUpVerifyRef = ref();
const isAiActionOrder = computed(() => {
return (
String(state.source) === 'aishop' ||
String(state.orderType) === '5' ||
String(state.orderInfo?.__source) === 'aishop' ||
Number(state.orderInfo?.type) === 5
);
});
const isPickUpOrder = computed(() => {
if (Number(state.orderInfo?.deliveryType) === 2) return true;
return Boolean(
state.orderInfo?.pickUpStoreId ||
state.orderInfo?.pickUpStore ||
state.orderInfo?.pickUpStoreVO ||
state.orderInfo?.pickUpVerifyCode,
);
});
const showBottomBar = computed(() => {
if (!isAiActionOrder.value) return true;
const status = Number(state.orderInfo?.status);
if ([0, 20].includes(status)) return true;
if (!isAiStoreOrder.value) return false;
if (isPickUpOrder.value) return false;
return [10, 50].includes(status);
});
const resolvePickUpStoreId = (data = {}) => {
return Number(
data?.pickUpStoreId ||
data?.pickUpStore?.id ||
data?.pickUpStore?.storeId ||
data?.pickUpStoreVO?.id ||
data?.pickUpStoreVO?.storeId ||
data?.store?.id ||
data?.store?.storeId ||
data?.storeId ||
0,
);
};
const resolveAiOrderId = (data) => {
return data?.id || data?.orderId;
};
const resolveDelayOrderItemId = (item) => {
return Number(item?.id || item?.orderItemId || item?.itemId || 0);
};
const formatSkuProperties = (properties) => {
const list = Array.isArray(properties) ? properties : [];
return list
.map((property) => property?.valueName)
.filter(Boolean)
.join(' ');
};
const isAiStoreOrder = computed(() => {
return String(state.source) === 'aishop' || String(state.orderInfo?.__source) === 'aishop';
});
const delayPopupRef = ref();
const delayShipmentItems = ref([]);
const createDelayShipmentItems = (data) => {
const sourceItems = Array.isArray(data?.items) ? data.items : [];
return sourceItems
.map((item) => {
const maxCount = Number(item?.count || 0);
return {
orderItemId: resolveDelayOrderItemId(item),
picUrl: item?.picUrl || '',
spuName: item?.spuName || item?.name || '',
skuText: formatSkuProperties(item?.properties),
maxCount,
selectedCount: maxCount,
};
})
.filter((item) => item.orderItemId > 0 && item.maxCount > 0);
};
const closeDelayShipmentPopup = () => {
delayPopupRef.value?.close();
};
const onDelayShipmentCountChange = (index, value) => {
const current = delayShipmentItems.value[index];
if (!current) return;
const next = Number(value || 0);
current.selectedCount = Math.min(current.maxCount, Math.max(0, next));
};
const openDelayShipmentPopup = () => {
const id = resolveAiOrderId(state.orderInfo);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
const nextItems = createDelayShipmentItems(state.orderInfo);
if (!nextItems.length) {
uni.showToast({
title: '未获取到可延迟商品',
icon: 'none',
});
return;
}
delayShipmentItems.value = nextItems;
delayPopupRef.value?.open();
};
const submitDelayShipment = async () => {
const orderId = resolveAiOrderId(state.orderInfo);
if (!orderId) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
const items = delayShipmentItems.value
.filter((item) => Number(item.selectedCount) > 0)
.map((item) => ({
orderItemId: item.orderItemId,
count: Number(item.selectedCount),
}));
if (!items.length) {
uni.showToast({
title: '请选择延迟发货数量',
icon: 'none',
});
return;
}
const { code } = await aiDelayedShipment({
orderId,
items,
});
if (code === 0) {
closeDelayShipmentPopup();
getOrderDetail();
}
};
function delayShipment() {
if (isPickUpOrder.value) return;
if (isAiStoreOrder.value) {
openDelayShipmentPopup();
return;
}
const id = resolveAiOrderId(state.orderInfo);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
uni.showModal({
title: '延迟发货',
content: '请您确认是否暂时不需要发货,确认后该产品将为您安排延迟发货',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) return;
const { code } = await aiDelayedShipment({
id,
status: 50,
});
if (code === 0) {
getOrderDetail();
}
},
});
}
function nowShipment() {
if (isPickUpOrder.value) return;
const id = resolveAiOrderId(state.orderInfo);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
uni.showModal({
title: '立即发货',
content: '请您确认是否需要立即发货,确认后将尽快为您安排发货',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) return;
const { code } = await aiPendingShipment({
id,
status: 10,
});
if (code === 0) {
getOrderDetail();
}
},
});
}
const confirmReceiveOrder = async () => {
const id = resolveAiOrderId(state.orderInfo);
if (!id) return;
const req = Number(state.orderInfo?.type) === 5 || String(state.orderType) === '5'
? giftConfirmReceive
: aiConfirmReceive;
const { code } = await req({ id });
if (code === 0) {
getOrderDetail();
}
};
const goPay = () => {
const id = resolveAiOrderId(state.orderInfo);
const payOrderId = state.orderInfo?.payOrderId;
if (!id || !payOrderId) {
uni.showToast({
title: '支付信息异常',
icon: 'none',
});
return;
}
sheep.$router.go('/pages/AI/cashierDesk', {
id,
payOrderId,
});
};
async function getOrderDetail() {
let id = state.orderInfo.id;
// 对详情数据进行适配
let res;
if (state.comeinType === 'wechat') {
// TODO 芋艿:【微信物流】微信场景下
res = await OrderApi.getOrderDetail(id, {
merchant_trade_no: state.merchantTradeNo,
});
} else {
if (String(state.source) === 'aishop') {
res = await getAiOrderDetail({ id });
} else if (String(state.orderType) === '5') {
res = await getOpenOrderDetail({ id });
} else {
res = await OrderApi.getOrderDetail(id);
}
}
if (res.code === 0) {
state.orderInfo = res.data;
handleOrderButtons(state.orderInfo);
// 配送方式:门店自提
const isPickUp = Number(res.data?.deliveryType) === 2;
const pickUpStoreId = resolvePickUpStoreId(res.data);
if (isPickUp && pickUpStoreId > 0) {
const { data } = await StoreApi.getStoreById(pickUpStoreId);
systemStore.value = data || {};
} else {
systemStore.value = {};
}
if (state.orderInfo.deliveryType === 2 && state.orderInfo.payStatus) {
pickUpVerifyRef.value && pickUpVerifyRef.value.markCode(res.data.pickUpVerifyCode);
}
} else {
sheep.$router.back();
}
}
onShow(async () => {
//onShow中获取订单列表,保证跳转后页面为最新状态
await getOrderDetail();
});
onLoad(async (options) => {
let id = 0;
if (options.id) {
id = options.id;
}
// TODO 芋艿:【微信物流】下面两个变量,后续接入
state.comeinType = options.comein_type;
if (state.comeinType === 'wechat') {
state.merchantTradeNo = options.merchant_trade_no;
}
if (options.type !== undefined) {
state.orderType = options.type;
}
if (options.source !== undefined) {
state.source = options.source;
}
state.orderInfo.id = id;
});
const priceArr = ref([
{
title: '商品金额',
value: 'totalPrice',
type: 1,
},
{
title: "随机优惠",
value: 'randomDiscountPrice',
type: 1,
},
{
title: '消费金抵扣',
value: 'consumptionPrice',
type: 2,
},
{
title: '运费',
value: 'deliveryPrice',
type: 1,
},
{
title: '实付金额',
value: 'payPrice',
type: 1,
},
]);
</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%;
background: v-bind(headerBg) no-repeat,
linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
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: 12rpx;
margin: 20rpx 32rpx 24rpx 32rpx;
padding: 24rpx 30rpx 24rpx 20rpx;
font-size: 32rpx;
box-sizing: border-box;
color: #1b1b21;
.address-username {
margin-right: 20rpx;
}
.address-detail {
margin-top: 20rpx;
}
}
.detail-goods {
border-radius: 10rpx;
padding: 0 32rpx;
.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: 12rpx;
margin-bottom: 24rpx;
.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: 36rpx;
.title {
font-size: 28rpx;
color: #3b3b3b;
}
.detail {
font-size: 28rpx;
color: #323232;
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: 12rpx;
padding: 20rpx;
margin-bottom: 24rpx;
.notice-item {
line-height: 70rpx;
.title {
font-size: 28rpx;
color: #3b3b3b;
}
.detail {
font-size: 28rpx;
color: #323232;
font-family: OPPOSANS;
}
}
.all-rpice-item {
justify-content: flex-end;
align-items: center;
.title {
font-size: 26rpx;
font-weight: 500;
color: #3b3b3b;
line-height: normal;
}
}
}
.all-price {
color: #ee0a24 !important;
}
// 底部
.footer-box {
height: 170rpx;
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;
}
}
.cityImg {
width: 48rpx;
min-width: 48rpx;
height: 48rpx;
margin-top: 16rpx;
margin-right: 16rpx;
image {
width: 100%;
height: 100%;
}
}
.order-goods {
padding: 24rpx 20rpx;
box-sizing: border-box;
background-color: #fff;
margin-bottom: 24rpx;
border-radius: 12rpx;
}
.right {
text-align: right;
}
.copy {
width: 32rpx;
height: 32rpx;
margin-left: 14rpx;
image {
width: 100%;
height: 100%;
}
}
.orderBan {
height: 100rpx;
width: 100%;
padding: 0 24rpx;
box-sizing: border-box;
box-shadow: 0px -4px 30px 0px rgba(0, 0, 0, 0.1);
}
.delay-popup {
width: 680rpx;
max-height: 78vh;
background: #ffffff;
border-radius: 24rpx;
padding: 32rpx 24rpx;
box-sizing: border-box;
overflow: hidden;
}
.delay-popup__header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.delay-popup__title {
font-size: 34rpx;
font-weight: 600;
color: #333333;
}
.delay-popup__order-no {
margin-top: 8rpx;
font-size: 22rpx;
line-height: 32rpx;
color: #999999;
word-break: break-all;
}
.delay-popup__order-time {
margin-top: 4rpx;
font-size: 22rpx;
line-height: 32rpx;
color: #999999;
}
.delay-popup__close {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background: #f3f4f6;
line-height: 56rpx;
text-align: center;
font-size: 36rpx;
color: #666666;
}
.delay-popup__desc {
font-size: 24rpx;
color: #999999;
margin-bottom: 24rpx;
}
.delay-popup__content {
max-height: 760rpx;
}
.delay-popup__item {
display: flex;
padding: 20rpx 0;
border-bottom: 1rpx solid #f2f2f2;
}
.delay-popup__item-image {
width: 144rpx;
height: 144rpx;
border-radius: 12rpx;
flex-shrink: 0;
margin-right: 20rpx;
background: #f5f5f5;
}
.delay-popup__item-main {
flex: 1;
min-width: 0;
}
.delay-popup__item-name {
font-size: 28rpx;
line-height: 40rpx;
color: #333333;
}
.delay-popup__item-sku {
margin-top: 10rpx;
font-size: 24rpx;
line-height: 34rpx;
color: #999999;
}
.delay-popup__item-footer {
margin-top: 20rpx;
}
.delay-popup__item-count {
font-size: 24rpx;
color: #666666;
}
.delay-popup__actions {
display: flex;
align-items: center;
gap: 20rpx;
margin-top: 32rpx;
}
.delay-popup__btn {
flex: 1;
height: 84rpx;
line-height: 84rpx;
text-align: center;
border-radius: 42rpx;
font-size: 28rpx;
font-weight: 500;
}
.delay-popup__btn--ghost {
background: #f2f3f5;
color: #333333;
}
.delay-popup__btn--primary {
background: linear-gradient(135deg, #fa8735 0%, #fe3b48 100%);
color: #ffffff;
}
</style>