feat: 部分确认收货
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user