feat: 延迟发货调试
This commit is contained in:
+131
-179
@@ -17,7 +17,7 @@
|
||||
{{ formatAfterSaleStatus(props.data) }}
|
||||
</view>
|
||||
</view>
|
||||
<card_order :data="props.data" :source="props.data.__source" v-if="props.index != 5" type="3"></card_order>
|
||||
<card_order :data="props.data" :source="props.data.__source" :delay-records="state.delayRecords" v-if="props.index != 5" type="3"></card_order>
|
||||
<view v-else class="con_item flex-center ju-between al-flex-start">
|
||||
<view class="order_img shrink">
|
||||
<image :src="`${props.data.picUrl}`" mode="aspectFill" />
|
||||
@@ -82,54 +82,27 @@
|
||||
<card_orderBan :data="props.data" @downData="downData"></card_orderBan>
|
||||
</view>
|
||||
</view>
|
||||
<uni-popup ref="delayPopupRef" type="bottom" background-color="#fff">
|
||||
<view class="delay-popup" @tap.stop>
|
||||
<view class="delay-popup__header">
|
||||
<view>
|
||||
<view class="delay-popup__title">延迟发货</view>
|
||||
<view class="delay-popup__order-no">订单号:{{ props.data.no || '-' }}</view>
|
||||
<view class="delay-popup__order-time">
|
||||
下单时间:{{ formatCreateTime(props.data.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.itemKey || 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>
|
||||
<ShipmentPopup
|
||||
ref="nowShipmentPopupRef"
|
||||
mode="now"
|
||||
popup-type="bottom"
|
||||
:order-no="props.data.no || ''"
|
||||
:order-time="formatCreateTime(props.data.createTime) || ''"
|
||||
:order-data="props.data"
|
||||
:delay-records="state.delayRecords"
|
||||
@close="closeNowShipmentPopup"
|
||||
@submit="handleNowShipmentSubmit"
|
||||
/>
|
||||
<ShipmentPopup
|
||||
ref="delayShipmentPopupRef"
|
||||
mode="delay"
|
||||
popup-type="bottom"
|
||||
:order-no="props.data.no || ''"
|
||||
:order-time="formatCreateTime(props.data.createTime) || ''"
|
||||
:order-data="props.data"
|
||||
@close="closeDelayShipmentPopup"
|
||||
@submit="handleDelayShipmentSubmit"
|
||||
/>
|
||||
</template>
|
||||
<script setup>
|
||||
import {
|
||||
@@ -138,7 +111,9 @@
|
||||
defineEmits,
|
||||
computed,
|
||||
ref,
|
||||
reactive,
|
||||
watch,
|
||||
onMounted,
|
||||
} from 'vue';
|
||||
import {
|
||||
fen2yuan,
|
||||
@@ -149,6 +124,7 @@
|
||||
import card_order from './card_order.vue';
|
||||
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 AfterSaleApi from '@/sheep/api/trade/afterSale';
|
||||
import sheep from '@/sheep';
|
||||
import {
|
||||
@@ -156,6 +132,7 @@
|
||||
aiPendingShipment,
|
||||
confirmReceive as aiConfirmReceive,
|
||||
giftConfirmReceive,
|
||||
getAiOrderDelayRecords,
|
||||
} from '@/sheep/api/ai';
|
||||
let emit = defineEmits(['downData']);
|
||||
let { proxy } = getCurrentInstance();
|
||||
@@ -178,13 +155,6 @@
|
||||
const onCopy = (no) => {
|
||||
proxy.$sheep.$helper.copyText(no);
|
||||
};
|
||||
const formatSkuProperties = (properties) => {
|
||||
const list = Array.isArray(properties) ? properties : [];
|
||||
return list
|
||||
.map((property) => property?.valueName)
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
};
|
||||
const formatCreateTime = (value) => {
|
||||
if (!value) return '';
|
||||
const s = sheep?.$helper?.timeFormat
|
||||
@@ -235,83 +205,52 @@
|
||||
const isDelayedShipmentOrder = () =>
|
||||
currentStatus.value === 50 && !isPickUpOrder.value;
|
||||
|
||||
const state = reactive({
|
||||
delayRecords: [],
|
||||
delayRecordsLoaded: false,
|
||||
});
|
||||
|
||||
const loadDelayRecords = async (force = false) => {
|
||||
if (props.index === 5) return;
|
||||
if (!isAiStoreOrder.value) return;
|
||||
const orderId = resolveAiOrderId(props.data);
|
||||
if (!orderId) return;
|
||||
if (state.delayRecordsLoaded && !force) return;
|
||||
try {
|
||||
const { code, data } = await getAiOrderDelayRecords({ orderId });
|
||||
if (code === 0 && Array.isArray(data)) {
|
||||
state.delayRecords = data;
|
||||
} else {
|
||||
state.delayRecords = [];
|
||||
}
|
||||
} catch (e) {
|
||||
state.delayRecords = [];
|
||||
} finally {
|
||||
state.delayRecordsLoaded = true;
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => resolveAiOrderId(props.data),
|
||||
(value) => {
|
||||
if (!value) return;
|
||||
state.delayRecordsLoaded = false;
|
||||
loadDelayRecords(true);
|
||||
},
|
||||
{ immediate: false },
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
loadDelayRecords();
|
||||
});
|
||||
|
||||
const resolveAiOrderId = (data) => {
|
||||
return data?.id || data?.orderId;
|
||||
};
|
||||
const getDelayFirstValidValue = (...values) =>
|
||||
values.find((value) => value !== undefined && value !== null && String(value).trim() !== '') ?? '';
|
||||
const resolveDelayOrderItemId = (item = {}) => {
|
||||
return getDelayFirstValidValue(
|
||||
item?.id,
|
||||
item?.orderItemId,
|
||||
item?.itemId,
|
||||
item?.orderGoodsId,
|
||||
item?.goodsId,
|
||||
item?.skuId,
|
||||
);
|
||||
};
|
||||
const hasDelayOrderItemId = (value) => value !== undefined && value !== null && String(value).trim() !== '';
|
||||
const resolveDelayMaxCount = (item = {}) => {
|
||||
const candidates = [
|
||||
item?.count,
|
||||
item?.remainingCount,
|
||||
item?.availableCount,
|
||||
item?.canCount,
|
||||
item?.maxCount,
|
||||
];
|
||||
const matched = candidates
|
||||
.map((value) => Number(value))
|
||||
.find((value) => Number.isFinite(value) && value > 0);
|
||||
return matched || 0;
|
||||
};
|
||||
const delayPopupRef = ref();
|
||||
const delayShipmentItems = ref([]);
|
||||
const createDelayShipmentItem = (item, parentItem = {}) => {
|
||||
const maxCount = resolveDelayMaxCount(item);
|
||||
const orderItemId = resolveDelayOrderItemId(item);
|
||||
const parentOrderItemId = resolveDelayOrderItemId(parentItem);
|
||||
const submitOrderItemId = getDelayFirstValidValue(orderItemId, parentOrderItemId);
|
||||
const skuText = formatSkuProperties(item?.properties || parentItem?.properties);
|
||||
return {
|
||||
itemKey: getDelayFirstValidValue(
|
||||
submitOrderItemId,
|
||||
`${item?.spuName || item?.name || parentItem?.spuName || parentItem?.name || ''}_${skuText}_${maxCount}`,
|
||||
),
|
||||
orderItemId,
|
||||
parentOrderItemId,
|
||||
submitOrderItemId,
|
||||
picUrl: item?.picUrl || parentItem?.picUrl || '',
|
||||
spuName: item?.spuName || item?.name || parentItem?.spuName || parentItem?.name || '',
|
||||
skuText,
|
||||
maxCount,
|
||||
selectedCount: maxCount,
|
||||
};
|
||||
};
|
||||
const createDelayShipmentItems = (data) => {
|
||||
const sourceItems = Array.isArray(data?.items) ? data.items : [];
|
||||
return sourceItems
|
||||
.flatMap((item) => {
|
||||
const children = Array.isArray(item?.items) ? item.items : [];
|
||||
if (children.length) {
|
||||
return children.filter(Boolean).map((child) => createDelayShipmentItem(child, item));
|
||||
}
|
||||
return [createDelayShipmentItem(item, item)];
|
||||
})
|
||||
.filter((item) => item.maxCount > 0);
|
||||
};
|
||||
const closeDelayShipmentPopup = () => {
|
||||
delayPopupRef.value?.close();
|
||||
};
|
||||
const onDelayShipmentCountChange = (index, value) => {
|
||||
const current = delayShipmentItems.value[index];
|
||||
if (!current) return;
|
||||
const next = Number(value);
|
||||
if (!Number.isFinite(next)) {
|
||||
current.selectedCount = 0;
|
||||
return;
|
||||
}
|
||||
current.selectedCount = Math.min(current.maxCount, Math.max(0, next));
|
||||
};
|
||||
const nowShipmentPopupRef = ref();
|
||||
const delayShipmentPopupRef = ref();
|
||||
const closeNowShipmentPopup = () => {};
|
||||
const closeDelayShipmentPopup = () => {};
|
||||
const openDelayShipmentPopup = (data) => {
|
||||
const id = resolveAiOrderId(data);
|
||||
if (!id) {
|
||||
@@ -321,36 +260,22 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
const nextItems = createDelayShipmentItems(data);
|
||||
if (!nextItems.length) {
|
||||
return;
|
||||
}
|
||||
delayShipmentItems.value = nextItems;
|
||||
delayPopupRef.value?.open();
|
||||
delayShipmentPopupRef.value?.open();
|
||||
};
|
||||
const submitDelayShipment = async () => {
|
||||
const orderId = resolveAiOrderId(props.data);
|
||||
if (!orderId) {
|
||||
const openNowShipmentPopup = (data) => {
|
||||
const id = resolveAiOrderId(data);
|
||||
if (!id) {
|
||||
uni.showToast({
|
||||
title: '订单信息异常',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
const hasSelectedCount = delayShipmentItems.value.some((item) => Number(item.selectedCount) > 0);
|
||||
const items = delayShipmentItems.value
|
||||
.filter(
|
||||
(item) => Number(item.selectedCount) > 0 && hasDelayOrderItemId(item.submitOrderItemId),
|
||||
)
|
||||
.map((item) => ({
|
||||
orderItemId: item.submitOrderItemId,
|
||||
count: Number(item.selectedCount),
|
||||
}));
|
||||
if (!items.length) {
|
||||
uni.showToast({
|
||||
title: hasSelectedCount ? '订单商品信息异常' : '请选择延迟发货数量',
|
||||
icon: 'none',
|
||||
});
|
||||
nowShipmentPopupRef.value?.open();
|
||||
};
|
||||
const handleDelayShipmentSubmit = async ({ items, close }) => {
|
||||
const orderId = resolveAiOrderId(props.data);
|
||||
if (!orderId || !Array.isArray(items) || items.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { code } = await aiDelayedShipment({
|
||||
@@ -358,8 +283,25 @@
|
||||
items,
|
||||
});
|
||||
if (code === 0) {
|
||||
closeDelayShipmentPopup();
|
||||
close?.();
|
||||
currentStatus.value = 50;
|
||||
await loadDelayRecords(true);
|
||||
emit('downData');
|
||||
}
|
||||
};
|
||||
const handleNowShipmentSubmit = async ({ items, close }) => {
|
||||
const orderId = resolveAiOrderId(props.data);
|
||||
if (!orderId || !Array.isArray(items) || items.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { code } = await aiPendingShipment({
|
||||
orderId,
|
||||
items,
|
||||
});
|
||||
if (code === 0) {
|
||||
close?.();
|
||||
currentStatus.value = 10;
|
||||
await loadDelayRecords(true);
|
||||
emit('downData');
|
||||
}
|
||||
};
|
||||
@@ -373,36 +315,39 @@
|
||||
};
|
||||
|
||||
function delayShipment(data) {
|
||||
if (isPickUpOrder.value) return;
|
||||
openDelayShipmentPopup(data);
|
||||
}
|
||||
|
||||
function nowShipment(data) {
|
||||
if (isPickUpOrder.value) return;
|
||||
const id = resolveAiOrderId(data);
|
||||
if (!id) {
|
||||
if (isPickUpOrder.value) {
|
||||
uni.showToast({
|
||||
title: '订单信息异常',
|
||||
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) {
|
||||
currentStatus.value = 10;
|
||||
emit('downData');
|
||||
}
|
||||
},
|
||||
});
|
||||
if (!isAiStoreOrder.value) {
|
||||
uni.showToast({
|
||||
title: '当前订单不支持延迟发货',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
openDelayShipmentPopup(data);
|
||||
}
|
||||
|
||||
function nowShipment(data) {
|
||||
if (isPickUpOrder.value) {
|
||||
uni.showToast({
|
||||
title: '自提订单不支持立即发货',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!isAiStoreOrder.value) {
|
||||
uni.showToast({
|
||||
title: '当前订单不支持立即发货',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
openNowShipmentPopup(data);
|
||||
}
|
||||
|
||||
const goAiOrderInfo = () => {
|
||||
@@ -614,6 +559,13 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.now-shipment-empty {
|
||||
padding: 40rpx 24rpx;
|
||||
text-align: center;
|
||||
font-size: 26rpx;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.price {
|
||||
color: #ee0a24;
|
||||
font-size: 24rpx;
|
||||
|
||||
Reference in New Issue
Block a user