Files
kangyuan-mobile/components/orderItem/orderItem.vue
T

815 lines
20 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>
<view class="card_order bg24 size34" @click="
utils.go('/pages/order/detail', { id: !props.isAfterSale ? props.data.id : props.data.orderId, type: props.data.type, source: props.data.__source })
">
<view class="flex-center ju-between createTime">
<view class="flex-center shrink">
<view class="size28">订单编号: {{ props.data.no }}</view>
<view class="copy flex-center" @tap.stop="onCopy(props.data.no)" style="margin-left: 10px">
<image :src="`${$url}goods/copy2.svg`" mode="scaleToFill" />
</view>
</view>
<view class="stateText size28" style="margin-left: 10px" :class="formatOrderColor(props.data)"
v-if="!props.isAfterSale">
{{ formatOrderStatus(props.data) }}
</view>
<view class="stateText size28" v-else>
{{ formatAfterSaleStatus(props.data) }}
</view>
</view>
<card_order :data="props.data" :source="props.data.__source" :delay-records="state.delayRecords" v-if="!props.isAfterSale" 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" />
</view>
<view class="flex1 flex-column ju-between">
<view class="flex-row ju-between">
<view class="size28 spuName lineTwo c0">{{ props.data.spuName }}</view>
<view class="shrink price">
<span class="size24">¥</span><span class="size36"
style="font-weight: 600">{{ fen2yuan(props.data.refundPrice) }}</span>
</view>
</view>
<view class="flex-row ju-between m-t-10">
<view class="valueName size24">{{
props.data.properties.map((property) => property.valueName).join(' ')
}}</view>
<view class="shrink size24 c0">{{ `x${props.data.count}` }}</view>
</view>
<view class="btn flex-row ju-flex-end">
<button
class="ss-reset-button btnItem btnItem1"
@tap.stop="onApply"
v-if="statusChange(['10', '20', '30', '62', '63'], String(props.data.status))"
>取消售后</button
>
<button
class="ss-reset-button btnItem btnItem1"
style="margin-left: 20rpx"
v-if="statusChange(['20'], String(props.data.status))"
@tap.stop="
sheep.$router.go('/pages/order/aftersale/return-delivery', { id: props.data.id })
">
填写物流信息
</button>
</view>
</view>
</view>
<view class="discount-row flex-between" v-if="!props.isAfterSale">
<view v-if="isDelayedShipmentOrder()" class="delay-notice flex-center">
<view class="delay-notice__icon">!</view>
<view class="delay-notice__text">
延迟发货中,商品已为您锁定,配送需您手动恢复或点击立即发货。
</view>
</view>
<view class="size24 c_999">{{ formatCreateTime(props.data.createTime) }}</view>
<view class="size24 c32">已优惠¥{{ fen2yuan(props.data.randomDiscountPrice) }}</view>
</view>
<view class="flex-row ju-flex-end" v-if="!props.isAfterSale">
<view class="flex-center size24">{{ `共${props.data.productCount}件商品 合计: `
}}
<!-- <view class="price">¥{{ fen2yuan(props.data.payPrice) }}</view> -->
<view class="shrink price"><span class="size24">¥</span><span class="size36"
style="font-weight: 600;">{{ fen2yuan(props.data.payPrice) }}</span></view>
</view>
</view>
<view class="flex-center ju-flex-end m-t-12" v-if="!props.isAfterSale && isAiActionOrder">
<AiOrderActionBar
:status="currentStatus"
:disableDelayShipment="isPickUpOrder || !isAiStoreOrder"
:showView="false"
:hasDelayedItems="hasDelayedItems"
:canDelayItems="canDelayItems"
:canShipItems="canShipItems"
:logisticsId="props.data.logisticsId"
:logisticsNo="props.data.logisticsNo"
:deliveryTime="props.data.deliveryTime"
:hasLogistics="hasLogistics"
@delay="onDelayShipment"
@now="onNowShipment"
@view="goAiOrderInfo"
@confirm="confirmReceiveOrder"
@pay="goPay"
@cancel="cancelAiOrder"
@express="goExpressLog"
/>
</view>
<view class="" style="margin-top: 32rpx" v-else-if="!props.isAfterSale">
<card_orderBan :data="props.data" @downData="downData"></card_orderBan>
</view>
</view>
<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"
:delay-records="state.delayRecords"
@close="closeDelayShipmentPopup"
@submit="handleDelayShipmentSubmit"
/>
<ReceiveItemPopup
ref="receiveItemPopupRef"
:order-no="props.data.no || ''"
:order-data="props.data"
:delay-records="state.delayRecords"
@close="closeReceiveItemPopup"
@submit="handleReceiveItemSubmit"
/>
<ExpressListPopup
ref="expressListPopupRef"
popup-type="bottom"
:order-no="props.data.no || ''"
:order-data="props.data"
:delay-records="state.delayRecords"
:order-id="resolveAiOrderId(props.data)"
@close="closeExpressListPopup"
/>
</template>
<script setup>
import {
getCurrentInstance,
defineProps,
defineEmits,
computed,
ref,
reactive,
watch,
onMounted,
} from 'vue';
import {
fen2yuan,
formatOrderColor,
formatOrderStatus,
formatAfterSaleStatus,
} from '@/sheep/hooks/useGoods';
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 ReceiveItemPopup from '@/components/orderItem/ReceiveItemPopup.vue';
import ExpressListPopup from '@/components/orderItem/ExpressListPopup.vue';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import sheep from '@/sheep';
import {
aiDelayedShipment,
aiPendingShipment,
confirmReceive as aiConfirmReceive,
giftConfirmReceive,
cancelOrder as cancelAiOrderRequest,
cancelOpenOrder,
getAiOrderDelayRecords,
aiReceiveItem,
} from '@/sheep/api/ai';
let emit = defineEmits(['downData']);
let { proxy } = getCurrentInstance();
let props = defineProps({
data: {
type: Object,
default() {
return {};
},
},
index: {
type: Number,
default: 0,
},
isAfterSale: {
type: Boolean,
default: false,
},
});
const downData = () => {
emit('downData');
};
const onCopy = (no) => {
proxy.$sheep.$helper.copyText(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 onApply = () => {
uni.showModal({
title: '提示',
content: '确定要取消此申请吗?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await AfterSaleApi.cancelAfterSale(props.data.id);
if (code === 0) {
emit('downData');
}
},
});
};
const statusChange = (arr, status) => {
return arr.indexOf(status) != -1;
};
const isAiActionOrder =
String(props.data?.__source) === 'aishop' || Number(props.data?.type) === 5;
const isAiStoreOrder = computed(() => String(props.data?.__source) === 'aishop');
const isPickUpOrder = computed(() => {
if (Number(props.data?.deliveryType) === 2) return true;
return Boolean(
props.data?.pickUpStoreId ||
props.data?.pickUpStore ||
props.data?.pickUpStoreVO ||
props.data?.pickUpVerifyCode,
);
});
const currentStatus = ref(Number(props.data?.status));
watch(
() => props.data?.status,
(value) => {
currentStatus.value = Number(value);
},
{ immediate: true },
);
// 顶部提示条「延迟发货中...」仅在待付款/待发货/处理中这些发货流程前的状态展示,
// 待收货(status=50)已经发货完成,不应该再展示这条提醒。
const isDelayedShipmentOrder = () => {
const s = Number(currentStatus.value);
if (s === 50) return false; // 待收货:不再展示延迟发货提示
if (isPickUpOrder.value) return false;
// 其余状态(待付款/待发货/处理中)下,只要有延迟中(status===1)的商品就展示
return Boolean(
getCurrentDelayRecords().some(
(record) => Number(record?.status) === 1,
),
);
};
const hasDelayedItems = computed(() => {
if (!isAiStoreOrder.value) return false;
if (isPickUpOrder.value) return false;
const delayRecords = getCurrentDelayRecords();
return delayRecords.some((record) => Number(record?.status) === 1);
});
const canDelayItems = computed(() => {
if (!isAiStoreOrder.value) return false;
if (isPickUpOrder.value) return false;
const delayRecords = getCurrentDelayRecords();
const hasActivated = delayRecords.some((record) => Number(record?.status) === 2);
if (hasActivated) return true;
if (delayRecords.length === 0) {
const totalCount = Number(props.data?.productCount || props.data?.totalCount || 0) || 0;
if (totalCount > 0) return true;
}
return false;
});
const canShipItems = computed(() => {
if (!isAiStoreOrder.value) return false;
if (isPickUpOrder.value) return false;
const delayRecords = getCurrentDelayRecords();
if (delayRecords.length === 0) {
const totalCount = Number(props.data?.productCount || props.data?.totalCount || 0) || 0;
return totalCount > 0;
}
return delayRecords.some((record) => {
const status = Number(record?.status);
return status === 1 || status === 2;
});
});
const getCurrentDelayRecords = () => {
if (Array.isArray(state.delayRecords) && state.delayRecords.length > 0) return state.delayRecords;
const orderRecords = Array.isArray(props.data?.delayRecords)
? props.data.delayRecords
: Array.isArray(props.data?.delayRecordList)
? props.data.delayRecordList
: [];
return orderRecords.filter(Boolean);
};
const hasLogistics = computed(() => {
const data = props.data || {};
if (Number(data.logisticsId) > 0) return true;
if (data.logisticsNo && String(data.logisticsNo).trim()) return true;
if (data.deliveryTime) return true;
const items = Array.isArray(data.items) ? data.items : [];
for (const item of items) {
if (Number(item?.logisticsId) > 0) return true;
if (item?.logisticsNo && String(item.logisticsNo).trim()) return true;
if (item?.deliveryTime) return true;
const subItems = Array.isArray(item?.items) ? item.items : [];
for (const sub of subItems) {
if (Number(sub?.logisticsId) > 0) return true;
if (sub?.logisticsNo && String(sub.logisticsNo).trim()) return true;
if (sub?.deliveryTime) return true;
}
}
return false;
});
const state = reactive({
delayRecords: [],
delayRecordsLoaded: false,
});
const resolveAiOrderId = (data) => {
return data?.id || data?.orderId;
};
const loadDelayRecords = async (force = false) => {
if (props.isAfterSale) 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;
}
};
const nowShipmentPopupRef = ref();
const delayShipmentPopupRef = ref();
const receiveItemPopupRef = ref();
const expressListPopupRef = ref();
const closeNowShipmentPopup = () => {};
const closeDelayShipmentPopup = () => {};
const closeReceiveItemPopup = () => {};
const closeExpressListPopup = () => {};
const openDelayShipmentPopup = async (data) => {
const id = resolveAiOrderId(data);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
try {
await loadDelayRecords(true);
} catch (e) {
}
delayShipmentPopupRef.value?.open();
};
const openNowShipmentPopup = async (data) => {
const id = resolveAiOrderId(data);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
try {
await loadDelayRecords(true);
} catch (e) {
}
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({
orderId,
items,
});
if (code === 0) {
close?.();
await loadDelayRecords(true);
const records = getCurrentDelayRecords();
const hasDelayed = records.some((r) => Number(r?.status) === 1);
if (hasDelayed && ![15, 20, 30].includes(Number(currentStatus.value))) {
currentStatus.value = 50;
} else if (!hasDelayed && Number(currentStatus.value) === 50) {
currentStatus.value = 10;
}
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?.();
await loadDelayRecords(true);
const records = getCurrentDelayRecords();
const hasDelayed = records.some((r) => Number(r?.status) === 1);
if (hasDelayed && ![15, 20, 30].includes(Number(currentStatus.value))) {
currentStatus.value = 50;
} else if (Number(currentStatus.value) === 50) {
currentStatus.value = 10;
}
emit('downData');
}
};
const onDelayShipment = () => {
delayShipment(props.data);
};
const onNowShipment = () => {
nowShipment(props.data);
};
function delayShipment(data) {
if (isPickUpOrder.value) {
uni.showToast({
title: '自提订单不支持延迟发货',
icon: 'none',
});
return;
}
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 = () => {
if (Number(props.data?.type) === 5) {
const id = props.data?.id;
if (!id) return;
proxy.utils.go('/pages/order/detail', { id, type: props.data?.type });
return;
}
const id = resolveAiOrderId(props.data);
if (!id) return;
proxy.utils.go('/pages/AI/orderInfo', { id });
};
const goExpressLog = () => {
const id = resolveAiOrderId(props.data);
if (!id) {
uni.showToast({
title: '订单信息异常',
icon: 'none',
});
return;
}
if (isAiStoreOrder.value && !isPickUpOrder.value) {
expressListPopupRef.value?.open?.();
return;
}
proxy.utils.go('/pages/order/express/log', { id });
};
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;
const { code } = await req({ id });
if (code === 0) {
emit('downData');
}
};
const handleReceiveItemSubmit = async ({ items }) => {
if (!Array.isArray(items) || items.length === 0) {
uni.showToast({
title: '请选择要确认收货的商品',
icon: 'none',
});
return;
}
const { code } = await aiReceiveItem({ items });
if (code === 0) {
receiveItemPopupRef.value?.close?.();
state.delayRecordsLoaded = false;
emit('downData');
}
};
const goPay = () => {
const id = resolveAiOrderId(props.data);
const payOrderId = props.data?.payOrderId;
if (!id || !payOrderId) {
uni.showToast({
title: '支付信息异常',
icon: 'none',
});
return;
}
proxy.utils.go('/pages/AI/cashierDesk', {
id,
payOrderId,
});
};
const cancelAiOrder = () => {
const id = resolveAiOrderId(props.data);
if (!id) return;
uni.showModal({
title: '提示',
content: '确定要取消订单吗?',
confirmColor: '#FA7E31',
success: async (res) => {
if (!res.confirm) return;
const request = Number(props.data?.type) === 5 ? cancelOpenOrder : cancelAiOrderRequest;
const result = await request({ id });
if (result.code === 0) emit('downData');
},
});
};
</script>
<style lang="scss" scoped>
.card_order {
padding: 24rpx;
box-sizing: border-box;
border-radius: 8rpx;
}
.createTime {
margin-bottom: 32rpx;
}
.discount-row {
margin-top: 8rpx;
flex-wrap: wrap;
row-gap: 12rpx;
}
.delay-notice {
width: 100%;
padding: 18rpx 20rpx;
box-sizing: border-box;
border-radius: 12rpx;
background: #fff4ea;
align-items: flex-start;
}
.delay-notice__icon {
width: 28rpx;
height: 28rpx;
line-height: 28rpx;
text-align: center;
border-radius: 50%;
border: 2rpx solid #fa7e31;
color: #fa7e31;
font-size: 20rpx;
flex-shrink: 0;
margin-right: 12rpx;
margin-top: 2rpx;
}
.delay-notice__text {
color: #fa7e31;
font-size: 24rpx;
line-height: 36rpx;
}
.delay-popup {
background: #ffffff;
border-radius: 24rpx 24rpx 0 0;
padding: 32rpx 24rpx calc(24rpx + env(safe-area-inset-bottom));
box-sizing: border-box;
}
.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: 720rpx;
}
.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;
}
.now-shipment-empty {
padding: 40rpx 24rpx;
text-align: center;
font-size: 26rpx;
color: #999999;
}
.price {
color: #ee0a24;
font-size: 24rpx;
}
.copy {
width: 24rpx;
height: 24rpx;
margin-left: 14rpx;
image {
width: 100%;
height: 100%;
}
}
.con_item {
margin-bottom: 24rpx;
.order_img {
width: 160rpx;
height: 160rpx;
border-radius: 8rpx;
overflow: hidden;
margin-right: 12rpx;
image {
width: 100%;
height: 100%;
}
}
.spuName {
color: #323232;
}
.valueName {
color: #777777;
}
}
.price {
color: #ee0a24;
font-size: 24rpx;
}
.btnItem {
line-height: 50rpx;
padding: 0 20rpx;
box-sizing: border-box;
border-radius: 94px 94px 94px 94px;
margin-top: 12rpx;
font-size: 24rpx;
border: none;
}
.btnItem1 {
background: #f2f2f2;
}
</style>