feat: 部分确认收货

This commit is contained in:
2026-08-06 16:03:07 +08:00
parent b8bcd46f1d
commit 63d699ca7b
4 changed files with 660 additions and 0 deletions
+580
View File
@@ -0,0 +1,580 @@
<template>
<uni-popup ref="popupRef" type="bottom" background-color="#fff">
<view class="receive-popup" @tap.stop>
<view class="receive-popup__header">
<view>
<view class="receive-popup__title">确认收货</view>
<view class="receive-popup__order-no">订单号:{{ orderNo || '-' }}</view>
<view class="receive-popup__tip">请选择已收到货物的商品</view>
</view>
<view class="receive-popup__close" @tap.stop="handleClose">×</view>
</view>
<scroll-view scroll-y class="receive-popup__content">
<view v-if="renderItems.length === 0" class="receive-popup__empty">
暂无可确认收货的商品
</view>
<view
v-else
class="receive-popup__item"
v-for="(item, index) in renderItems"
:key="item.itemKey || index"
@tap.stop="toggleItem(index)"
>
<view class="receive-popup__checkbox">
<view
class="receive-popup__checkbox-inner"
:class="{ 'receive-popup__checkbox-inner--on': !!item.__checked }"
>
<text v-if="item.__checked" class="receive-popup__checkbox-tick">✓</text>
</view>
</view>
<image class="receive-popup__item-image" :src="item.picUrl" mode="aspectFill" />
<view class="receive-popup__item-main">
<view class="receive-popup__item-name lineTwo">{{ item.spuName }}</view>
<view class="receive-popup__item-sku">{{ item.skuText || '-' }}</view>
<view class="receive-popup__item-count">数量:x{{ item.count }}</view>
</view>
</view>
</scroll-view>
<view class="receive-popup__actions">
<view
class="receive-popup__select-all"
@tap.stop="toggleAll"
>
<view
class="receive-popup__checkbox-inner receive-popup__checkbox-inner--sm"
:class="{ 'receive-popup__checkbox-inner--on': isAllChecked }"
>
<text v-if="isAllChecked" class="receive-popup__checkbox-tick receive-popup__checkbox-tick--sm">✓</text>
</view>
<text class="receive-popup__select-all-text">全选(已选 {{ checkedCount }} 项)</text>
</view>
<view class="receive-popup__action-bar">
<view class="receive-popup__btn receive-popup__btn--ghost" @tap.stop="handleClose">
取消
</view>
<view
class="receive-popup__btn receive-popup__btn--primary"
:class="{ 'receive-popup__btn--disabled': checkedCount === 0 }"
@tap.stop="handleSubmit"
>
确认收货({{ checkedCount }})
</view>
</view>
</view>
</view>
</uni-popup>
</template>
<script setup>
import { computed, ref, watch } from 'vue';
const props = defineProps({
orderNo: {
type: String,
default: '',
},
orderData: {
type: Object,
default: () => ({}),
},
delayRecords: {
type: Array,
default: () => [],
},
});
const emit = defineEmits(['close', 'submit']);
const popupRef = ref();
const innerItems = ref([]);
const getFirstValidValue = (...values) =>
values.find((value) => value !== undefined && value !== null && String(value).trim() !== '') ?? '';
const hasValue = (value) => value !== undefined && value !== null && String(value).trim() !== '';
const formatSkuPropertyItem = (property) => {
const value = getFirstValidValue(
property?.valueName,
property?.value,
property?.specValue,
property?.attrValue,
property?.optionValue,
property?.propertyValue,
typeof property === 'string' ? property : '',
);
const name = getFirstValidValue(
property?.name,
property?.propertyName,
property?.specName,
property?.attrName,
property?.optionName,
property?.propertyKey,
'',
);
if (hasValue(name) && hasValue(value)) return `${name}:${value}`;
if (hasValue(value)) return String(value);
if (hasValue(name)) return String(name);
return '';
};
const formatSkuProperties = (properties) => {
if (!properties) return '';
if (typeof properties === 'string' && properties.trim()) return properties.trim();
if (Array.isArray(properties)) {
return properties.map(formatSkuPropertyItem).filter(Boolean).join(' ');
}
if (typeof properties === 'object') {
return Object.keys(properties)
.map((key) => {
const value = properties[key];
if (typeof value === 'object') return formatSkuPropertyItem(value);
return `${key}:${value}`;
})
.filter(Boolean)
.join(' ');
}
return '';
};
const resolveSpuItems = (data) => {
const items = Array.isArray(data?.items) ? data.items : [];
return items.flatMap((spu) => {
const subItems = Array.isArray(spu?.items) ? spu.items : [];
if (subItems.length > 0) {
return subItems.map((sub) => ({
...sub,
_spuName: getFirstValidValue(
spu?.spuName,
spu?.productName,
spu?.goodsName,
sub?.spuName,
sub?.productName,
sub?.goodsName,
),
_spuPic: getFirstValidValue(
spu?.picUrl,
spu?.imageUrl,
spu?.thumbUrl,
spu?.goodsPic,
sub?.picUrl,
sub?.imageUrl,
sub?.thumbUrl,
sub?.goodsPic,
),
_spuId: getFirstValidValue(spu?.spuId, spu?.productId, sub?.spuId, sub?.productId),
_skuText: getFirstValidValue(
sub?.skuProperties,
sub?.specInfo,
sub?.skuInfo,
sub?.skuText,
formatSkuProperties(sub?.skuProperties || sub?.specs || sub?.properties),
),
}));
}
return [
{
...spu,
_spuName: getFirstValidValue(spu?.spuName, spu?.productName, spu?.goodsName),
_spuPic: getFirstValidValue(
spu?.picUrl,
spu?.imageUrl,
spu?.thumbUrl,
spu?.goodsPic,
),
_spuId: getFirstValidValue(spu?.spuId, spu?.productId),
_skuText: getFirstValidValue(
spu?.skuProperties,
spu?.specInfo,
spu?.skuInfo,
spu?.skuText,
formatSkuProperties(spu?.skuProperties || spu?.specs || spu?.properties),
),
},
];
});
};
const resolveAllDelayRecords = () => {
const orderLevelRecords = Array.isArray(props.delayRecords)
? props.delayRecords
: Array.isArray(props.orderData?.delayRecords)
? props.orderData.delayRecords
: Array.isArray(props.orderData?.delayRecordList)
? props.orderData.delayRecordList
: [];
return orderLevelRecords.filter(Boolean);
};
const resolveCount = (record) =>
Number(
getFirstValidValue(
record?.count,
record?.num,
record?.quantity,
record?.number,
record?.totalCount,
1,
),
) || 1;
const resolveRecordOrderItemId = (record) =>
Number(
getFirstValidValue(
record?.orderItemId,
record?.orderItemVO?.id,
record?.orderItem?.id,
record?.itemId,
0,
),
) || 0;
const resolveRecordSkuText = (record) => {
const direct = getFirstValidValue(
record?.skuProperties,
record?.specInfo,
record?.skuText,
record?.skuInfo,
formatSkuProperties(record?.skuProperties || record?.specs || record?.properties),
);
if (direct) return direct;
const itemSpec = getFirstValidValue(
record?.orderItemVO?.skuProperties,
record?.orderItemVO?.specInfo,
record?.orderItem?.skuProperties,
record?.orderItem?.specInfo,
formatSkuProperties(record?.orderItemVO?.skuProperties || record?.orderItem?.specs),
);
return itemSpec;
};
const resolveRecordSpuName = (record) =>
getFirstValidValue(
record?.spuName,
record?.productName,
record?.goodsName,
record?.orderItemVO?.spuName,
record?.orderItem?.spuName,
record?.orderItemVO?.productName,
record?.orderItem?.productName,
);
const resolveRecordPicUrl = (record) =>
getFirstValidValue(
record?.picUrl,
record?.imageUrl,
record?.thumbUrl,
record?.goodsPic,
record?.orderItemVO?.picUrl,
record?.orderItem?.picUrl,
record?.orderItemVO?.imageUrl,
record?.orderItem?.imageUrl,
);
const buildShippedItemList = () => {
const records = resolveAllDelayRecords();
const shippedRecords = records.filter(
(record) => Number(record?.status) === 3 && Number(record?.delayRecordId || record?.id) > 0,
);
if (shippedRecords.length === 0) return [];
const spuItems = resolveSpuItems(props.orderData);
const findItemByOrderItemId = (id) =>
spuItems.find(
(sku) => Number(sku?.id || sku?.orderItemId || sku?.itemId || 0) === Number(id),
);
const findItemBySkuText = (text) =>
spuItems.find((sku) => {
const skuText = getFirstValidValue(
sku?.skuProperties,
sku?.specInfo,
sku?.skuInfo,
sku?.skuText,
formatSkuProperties(sku?.skuProperties || sku?.specs || sku?.properties),
);
return !!text && !!skuText && String(text).trim() === String(skuText).trim();
});
const singleSpu =
spuItems.length === 1
? spuItems[0]
: new Set(spuItems.map((s) => s?._spuId || s?._spuName)).size === 1
? spuItems[0]
: null;
return shippedRecords.map((record, idx) => {
const orderItemId = resolveRecordOrderItemId(record);
const recordSku = resolveRecordSkuText(record);
let matched = orderItemId ? findItemByOrderItemId(orderItemId) : null;
if (!matched && recordSku) matched = findItemBySkuText(recordSku);
if (!matched && singleSpu) matched = singleSpu;
const count = resolveCount(record);
const spuName = matched
? getFirstValidValue(matched._spuName, matched?.spuName, matched?.productName)
: resolveRecordSpuName(record);
const picUrl = matched
? getFirstValidValue(matched._spuPic, matched?.picUrl, matched?.imageUrl)
: resolveRecordPicUrl(record);
const skuText = matched
? getFirstValidValue(
matched?._skuText,
matched?.skuProperties,
matched?.specInfo,
matched?.skuInfo,
matched?.skuText,
formatSkuProperties(matched?.skuProperties || matched?.specs || matched?.properties),
)
: recordSku;
const delayRecordId = Number(record?.delayRecordId || record?.id) || 0;
return {
itemKey: `${delayRecordId}-${idx}`,
delayRecordId,
spuName: spuName || '商品信息',
skuText: skuText || '单规格',
picUrl: picUrl || '',
count,
__checked: true,
};
});
};
const renderItems = computed(() => innerItems.value || []);
const isAllChecked = computed(() => {
const list = renderItems.value;
return list.length > 0 && list.every((item) => !!item.__checked);
});
const checkedCount = computed(
() => renderItems.value.filter((item) => !!item.__checked).length,
);
const open = () => {
innerItems.value = buildShippedItemList();
popupRef.value?.open?.();
};
const close = () => {
popupRef.value?.close?.();
};
const handleClose = () => {
emit('close');
close();
};
const toggleItem = (index) => {
if (!innerItems.value[index]) return;
innerItems.value[index].__checked = !innerItems.value[index].__checked;
};
const toggleAll = () => {
const target = !isAllChecked.value;
innerItems.value.forEach((item) => (item.__checked = target));
};
const handleSubmit = () => {
const checkedItems = renderItems.value
.filter((item) => !!item.__checked && Number(item.delayRecordId) > 0)
.map((item) => ({ delayRecordId: Number(item.delayRecordId) }));
if (checkedItems.length === 0) {
uni.showToast({
title: '请选择要确认收货的商品',
icon: 'none',
});
return;
}
emit('submit', { items: checkedItems });
};
defineExpose({ open, close });
</script>
<style lang="scss" scoped>
.receive-popup {
width: 100%;
max-height: 80vh;
background: #ffffff;
border-radius: 24rpx 24rpx 0 0;
padding: 32rpx 32rpx 0 32rpx;
display: flex;
flex-direction: column;
box-sizing: border-box;
&__header {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding-bottom: 24rpx;
border-bottom: 1rpx solid #f2f2f2;
}
&__title {
font-size: 32rpx;
font-weight: 600;
color: #111827;
line-height: 44rpx;
}
&__order-no {
margin-top: 8rpx;
font-size: 24rpx;
color: #6b7280;
line-height: 32rpx;
}
&__tip {
margin-top: 8rpx;
font-size: 24rpx;
color: #f97316;
line-height: 32rpx;
}
&__close {
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
color: #9ca3af;
line-height: 1;
}
&__content {
flex: 1;
max-height: 56vh;
margin-top: 20rpx;
box-sizing: border-box;
}
&__empty {
padding: 80rpx 0;
text-align: center;
color: #9ca3af;
font-size: 26rpx;
}
&__item {
display: flex;
align-items: flex-start;
padding: 20rpx 0;
border-bottom: 1rpx solid #f2f2f2;
}
&__checkbox {
flex-shrink: 0;
width: 56rpx;
padding-top: 20rpx;
display: flex;
align-items: center;
justify-content: center;
}
&__checkbox-inner {
width: 40rpx;
height: 40rpx;
border: 2rpx solid #d1d5db;
border-radius: 50%;
background: #ffffff;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.15s;
box-sizing: border-box;
&--sm {
width: 32rpx;
height: 32rpx;
}
&--on {
background: #f97316;
border-color: #f97316;
}
}
&__checkbox-tick {
color: #ffffff;
font-size: 24rpx;
line-height: 1;
font-weight: 600;
&--sm {
font-size: 20rpx;
}
}
&__item-image {
flex-shrink: 0;
width: 140rpx;
height: 140rpx;
border-radius: 12rpx;
background: #f6f7fb;
margin-right: 20rpx;
}
&__item-main {
flex: 1;
min-width: 0;
padding-top: 4rpx;
display: flex;
flex-direction: column;
gap: 10rpx;
}
&__item-name {
font-size: 28rpx;
color: #111827;
line-height: 40rpx;
}
&__item-sku {
font-size: 24rpx;
color: #6b7280;
line-height: 32rpx;
background: #f6f7fb;
padding: 4rpx 12rpx;
border-radius: 8rpx;
align-self: flex-start;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__item-count {
font-size: 26rpx;
color: #111827;
font-weight: 500;
}
&__actions {
padding: 20rpx 0 32rpx 0;
background: #ffffff;
}
&__select-all {
display: flex;
align-items: center;
padding: 8rpx 0 20rpx 0;
}
&__select-all-text {
margin-left: 12rpx;
font-size: 26rpx;
color: #374151;
font-weight: 500;
}
&__action-bar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 20rpx;
}
&__btn {
min-width: 180rpx;
height: 72rpx;
line-height: 72rpx;
text-align: center;
border-radius: 36rpx;
font-size: 28rpx;
font-weight: 500;
padding: 0 28rpx;
}
&__btn--ghost {
border: 2rpx solid #e5e7eb;
color: #4b5563;
background: #ffffff;
}
&__btn--primary {
background: #f97316;
color: #ffffff;
}
&__btn--disabled {
opacity: 0.6;
}
}
</style>
+36
View File
@@ -118,6 +118,14 @@
@close="closeDelayShipmentPopup"
@submit="handleDelayShipmentSubmit"
/>
<ReceiveItemPopup
ref="receiveItemPopupRef"
:order-no="props.data.no || ''"
:order-data="props.data"
:delay-records="state.delayRecords"
@close="closeReceiveItemPopup"
@submit="handleReceiveItemSubmit"
/>
</template>
<script setup>
import {
@@ -140,6 +148,7 @@
import card_orderBan from '@/components/card_orderBan/card_orderBan.vue';
import AiOrderActionBar from '@/components/orderItem/AiOrderActionBar.vue';
import ShipmentPopup from '@/components/orderItem/ShipmentPopup.vue';
import ReceiveItemPopup from '@/components/orderItem/ReceiveItemPopup.vue';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import sheep from '@/sheep';
import {
@@ -150,6 +159,7 @@
cancelOrder as cancelAiOrderRequest,
cancelOpenOrder,
getAiOrderDelayRecords,
receiveItem,
} from '@/sheep/api/ai';
let emit = defineEmits(['downData']);
let { proxy } = getCurrentInstance();
@@ -289,8 +299,10 @@
const nowShipmentPopupRef = ref();
const delayShipmentPopupRef = ref();
const receiveItemPopupRef = ref();
const closeNowShipmentPopup = () => {};
const closeDelayShipmentPopup = () => {};
const closeReceiveItemPopup = () => {};
const openDelayShipmentPopup = async (data) => {
const id = resolveAiOrderId(data);
if (!id) {
@@ -423,6 +435,14 @@
};
const confirmReceiveOrder = async () => {
if (Number(currentStatus.value) === 15) {
const orderId = resolveAiOrderId(props.data);
if (orderId && !state.delayRecordsLoaded) {
await loadDelayRecords(true);
}
receiveItemPopupRef.value?.open?.();
return;
}
const id = resolveAiOrderId(props.data);
if (!id) return;
const req = Number(props.data?.type) === 5 ? giftConfirmReceive : aiConfirmReceive;
@@ -432,6 +452,22 @@
}
};
const handleReceiveItemSubmit = async ({ items }) => {
if (!Array.isArray(items) || items.length === 0) {
uni.showToast({
title: '请选择要确认收货的商品',
icon: 'none',
});
return;
}
const { code } = await receiveItem({ items });
if (code === 0) {
receiveItemPopupRef.value?.close?.();
state.delayRecordsLoaded = false;
emit('downData');
}
};
const goPay = () => {
const id = resolveAiOrderId(props.data);
const payOrderId = props.data?.payOrderId;
+31
View File
@@ -147,6 +147,14 @@
@close="closeDelayShipmentPopup"
@submit="handleDelayShipmentSubmit"
/>
<ReceiveItemPopup
ref="receiveItemPopupRef"
:order-no="state.orderInfo.no || ''"
:order-data="state.orderInfo"
:delay-records="state.delayRecords"
@close="closeReceiveItemPopup"
@submit="handleReceiveItemSubmit"
/>
</s-pages>
</template>
@@ -166,11 +174,13 @@
cancelOrder as cancelAiOrderRequest,
cancelOpenOrder,
getAiOrderDelayRecords,
receiveItem,
} 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 ShipmentPopup from '@/components/orderItem/ShipmentPopup.vue';
import ReceiveItemPopup from '@/components/orderItem/ReceiveItemPopup.vue';
import truckLine from '@/components/truckLine/truckLine.vue';
import PickUpVerify from '@/pages/order/pickUpVerify.vue';
@@ -286,8 +296,10 @@
});
const delayShipmentPopupRef = ref();
const nowShipmentPopupRef = ref();
const receiveItemPopupRef = ref();
const closeDelayShipmentPopup = () => {};
const closeNowShipmentPopup = () => {};
const closeReceiveItemPopup = () => {};
const reloadDelayRecords = async () => {
if (!isAiStoreOrder.value) {
@@ -441,6 +453,10 @@
}
const confirmReceiveOrder = async () => {
if (Number(state.orderInfo.status) === 15) {
receiveItemPopupRef.value?.open?.();
return;
}
const id = resolveAiOrderId(state.orderInfo);
if (!id) return;
const req =
@@ -453,6 +469,21 @@
}
};
const handleReceiveItemSubmit = async ({ items }) => {
if (!Array.isArray(items) || items.length === 0) {
uni.showToast({
title: '请选择要确认收货的商品',
icon: 'none',
});
return;
}
const { code } = await receiveItem({ items });
if (code === 0) {
receiveItemPopupRef.value?.close?.();
getOrderDetail();
}
};
const goPay = () => {
const id = resolveAiOrderId(state.orderInfo);
const payOrderId = state.orderInfo?.payOrderId;
+13
View File
@@ -225,6 +225,19 @@ export function confirmReceive(params: any) {
});
}
// 部分确认收货 /order/update/receiveItem
export function receiveItem(params: { items: Array<{ delayRecordId: number }> }) {
return request({
url: '/order/update/receiveItem',
method: 'post',
data: params,
custom: {
showSuccess: true,
successMsg: '确认收货成功',
},
});
}
// 开通ai店铺aishop/order/createOpen
export function createOpen(params: any) {
return request({