Files
kangyuan-mobile/pages/order/stockProgress.vue
T

439 lines
12 KiB
Vue

<template>
<s-layout title="备货进度" navPreset="light">
<view class="page">
<view class="card bg24">
<view class="timeline">
<view v-for="(step, i) in steps" :key="step.key" class="step">
<view class="left">
<view class="dot" :class="dotClass(step)">
<uni-icons v-if="step.state === 'done'" type="checkmarkempty" size="16" color="#fff" />
<image
v-else-if="step.key === 'delivered'"
class="dot-icon"
:src="truckIconSrc(step)"
mode="aspectFit"
/>
<uni-icons
v-else-if="step.key === 'sorting'"
type="gift"
size="16"
:color="step.state === 'active' ? '#fff' : '#b9bec8'"
/>
<uni-icons
v-else-if="step.key === 'wait'"
type="cart"
size="16"
:color="step.state === 'active' ? '#fff' : '#b9bec8'"
/>
<uni-icons v-else type="location" size="16" :color="step.state === 'active' ? '#fff' : '#b9bec8'" />
</view>
<view v-if="i !== steps.length - 1" class="line" :class="lineClass(i)"></view>
</view>
<view class="right">
<view class="title" :class="{ titleActive: step.state !== 'todo' }">{{ step.title }}</view>
<view v-if="step.time" class="time">{{ step.time }}</view>
<view v-if="step.desc" class="desc">{{ step.desc }}</view>
<view v-if="step.key === 'sorting' && step.state === 'active'" class="bar-wrap">
<view class="bar">
<view class="bar-fill" :style="{ width: sortingPercent + '%' }"></view>
</view>
</view>
<view v-if="step.key === 'wait'" class="hint">{{ step.hint }}</view>
</view>
</view>
</view>
</view>
<view class="goods-card bg24">
<card_order
v-if="goodsCardData.items.length"
class="order-goods"
:data="goodsCardData"
:type="goodsCardType"
theme="2"
/>
<view v-else class="goods-empty">暂无商品信息</view>
</view>
</view>
<su-fixed bottom placeholder bg="bg24">
<view class="footer">
<button class="btn" @tap="notifyStore">通知门店备货</button>
</view>
</su-fixed>
</s-layout>
</template>
<script setup>
import { computed, reactive, ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import OrderApi from '@/sheep/api/trade/order';
import OrderStoreApi from '@/sheep/api/trade/orderStore';
import { getOrderDetail as getAiOrderDetail, getOpenOrderDetail } from '@/sheep/api/ai';
import card_order from '@/components/orderItem/card_order.vue';
const state = reactive({
orderId: 0,
pickUpStoreId: 0,
preparationStatus: null,
source: '',
orderType: '',
detailStyle: 'order',
orderInfo: {},
loading: false,
});
const sortingPercent = ref(72);
const goodsItems = computed(() => {
const list =
state.orderInfo?.items ||
state.orderInfo?.orderItems ||
state.orderInfo?.itemList ||
state.orderInfo?.productList;
return Array.isArray(list) ? list : [];
});
const goodsCardType = computed(() => (String(state.detailStyle) === 'ai' ? '4' : '2'));
const goodsCardData = computed(() => {
return {
...(state.orderInfo || {}),
items: goodsItems.value,
};
});
const formatTime = (t) => {
if (!t) return '';
return sheep.$helper.timeFormat(t, 'yyyy-mm-dd hh:MM:ss');
};
const hasVerifyCode = computed(() => {
return Boolean(state.orderInfo?.pickUpVerifyCode) && Boolean(state.orderInfo?.payStatus);
});
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 resolveStage = (data = {}, preparationStatus) => {
const external = Number(preparationStatus);
const rawStatus = Number.isFinite(external) ? external : Number(data?.preparationStatus ?? data?.status ?? 0);
if (data?.pickUpVerifyTime || data?.verifyTime || data?.completedTime || rawStatus === 30 || rawStatus === 3) {
return 'done';
}
if (rawStatus === 1 || rawStatus === 2) return 'wait';
if (
data?.deliveryTime ||
data?.arriveStoreTime ||
data?.deliveredTime ||
rawStatus === 20
) {
return 'delivered';
}
return 'sorting';
};
const stage = computed(() => {
return resolveStage(state.orderInfo, state.preparationStatus);
});
const steps = computed(() => {
const createTime = formatTime(state.orderInfo?.createTime);
const s = stage.value;
const sortingState = s === 'sorting' ? 'active' : 'done';
const deliveredState = s === 'delivered' ? 'active' : s === 'sorting' ? 'todo' : 'done';
const waitState = s === 'wait' ? 'active' : s === 'done' ? 'done' : 'todo';
return [
{
key: 'created',
title: '已下单',
time: createTime,
state: 'done',
},
{
key: 'sorting',
title: '商品分拣中',
desc: sortingState === 'active' ? '预计 15 分钟内完成分拣' : '',
state: sortingState,
},
{
key: 'delivered',
title: '已送达门店',
desc: deliveredState === 'todo' ? '等待物流更新' : '',
state: deliveredState,
},
{
key: 'wait',
title: '待取货',
hint: hasVerifyCode.value ? `取货码:${state.orderInfo?.pickUpVerifyCode || ''}` : '到达门店后将发送取货通知',
state: waitState,
},
];
});
const dotClass = (step) => {
if (step.state === 'done') return 'dotDone';
if (step.state === 'active' && step.key === 'delivered') return 'dotDeliveredActive';
if (step.state === 'active' && step.key === 'wait') return 'dotWaitActive';
if (step.state === 'active') return 'dotActive';
return 'dotTodo';
};
const lineClass = (index) => {
const cur = steps.value[index];
if (cur?.state === 'todo') return 'lineTodo';
return 'lineDone';
};
const truckIconSrc = (step) => {
const fill = step?.state === 'active' ? '#ffffff' : '#b9bec8';
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="${fill}" d="M382.507 768a149.333 149.333 0 0 1-295.68 0h-44.16V256a42.667 42.667 0 0 1 42.666-42.667h597.334A42.667 42.667 0 0 1 725.333 256v85.333h128l128 173.056V768h-86.826a149.376 149.376 0 0 1-295.68 0zM640 298.667H128v343.466a149.333 149.333 0 0 1 241.621 40.534h242.091A150.5 150.5 0 0 1 640 642.133zm85.333 256H896v-12.16l-85.675-115.84h-84.992zm21.334 256a64 64 0 1 0 0-128.043 64 64 0 0 0 0 128.043m-448-64a64 64 0 1 0-128 0 64 64 0 0 0 128 0"/></svg>`;
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
};
const getDetail = async () => {
if (!state.orderId || state.loading) return;
if (!state.orderInfo || !Object.keys(state.orderInfo).length || !(state.pickUpStoreId > 0)) {
const detailRes =
String(state.orderType) === '5'
? await getOpenOrderDetail({ id: state.orderId })
: String(state.source) === 'aishop'
? await getAiOrderDetail({ id: state.orderId })
: await OrderApi.getOrderDetail(state.orderId);
if (detailRes?.code === 0) {
const detailData = detailRes.data?.orderInfo || detailRes.data || {};
state.orderInfo = detailData;
state.pickUpStoreId = resolvePickUpStoreId(detailData);
}
}
if (!(state.pickUpStoreId > 0)) {
uni.showToast({
title: '缺少门店信息',
icon: 'none',
});
return;
}
state.loading = true;
const res = await OrderStoreApi.getPreparationStatus(state.pickUpStoreId, state.orderId);
state.loading = false;
if (res?.code !== 0) return;
const data = res.data;
if (data !== null && typeof data === 'object') {
const merged = data?.orderInfo || data;
state.orderInfo = {
...(state.orderInfo || {}),
...(merged || {}),
};
const next = Number(merged?.preparationStatus ?? merged?.status);
if (Number.isFinite(next)) state.preparationStatus = next;
} else {
const next = Number(data);
if (Number.isFinite(next)) state.preparationStatus = next;
}
if (!(state.pickUpStoreId > 0)) state.pickUpStoreId = resolvePickUpStoreId(state.orderInfo);
};
const notifyStore = () => {
uni.showToast({
title: '已通知门店',
icon: 'none',
});
};
onLoad((options) => {
const id = Number(options?.id || 0);
if (id) state.orderId = id;
const pickUpStoreId = Number(options?.pickUpStoreId || options?.storeId || 0);
if (pickUpStoreId > 0) state.pickUpStoreId = pickUpStoreId;
state.source = String(options?.source || '').trim();
state.orderType = String(options?.type || '').trim();
state.detailStyle = String(options?.detailStyle || 'order').trim() || 'order';
});
onShow(() => {
getDetail();
});
</script>
<style scoped lang="scss">
.page {
padding: 24rpx 24rpx 170rpx;
box-sizing: border-box;
}
.card {
border-radius: 24rpx;
padding: 26rpx 22rpx;
box-sizing: border-box;
margin-bottom: 18rpx;
}
.timeline {
display: flex;
flex-direction: column;
gap: 34rpx;
}
.step {
display: flex;
align-items: stretch;
}
.left {
position: relative;
width: 56rpx;
flex-shrink: 0;
display: flex;
justify-content: flex-start;
}
.dot {
width: 40rpx;
height: 40rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
margin: 2rpx auto 0;
position: relative;
z-index: 2;
}
.dotDone {
background: #21c28a;
}
.dotActive {
background: #5b4eff;
}
.dotTodo {
background: #fff;
border: 2rpx solid #e6e8ef;
box-sizing: border-box;
}
.dotDeliveredActive {
background: #fa7e31;
}
.dotWaitActive {
background: #21c28a;
}
.dot-icon {
width: 18rpx;
height: 18rpx;
}
.line {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 46rpx;
bottom: -34rpx;
width: 4rpx;
border-radius: 2rpx;
}
.lineDone {
background: rgba(0, 0, 0, 0.08);
}
.lineTodo {
background: rgba(0, 0, 0, 0.05);
}
.right {
flex: 1;
padding-left: 10rpx;
}
.title {
font-size: 30rpx;
color: #c9c9c9;
font-weight: 600;
line-height: 1.2;
}
.titleActive {
color: #222;
}
.time {
margin-top: 8rpx;
font-size: 24rpx;
color: #9aa0a6;
}
.desc {
margin-top: 8rpx;
font-size: 24rpx;
color: #9aa0a6;
}
.bar-wrap {
margin-top: 14rpx;
}
.bar {
width: 100%;
height: 10rpx;
border-radius: 6rpx;
background: rgba(0, 0, 0, 0.06);
overflow: hidden;
}
.bar-fill {
height: 100%;
border-radius: 6rpx;
background: #21c28a;
}
.hint {
margin-top: 10rpx;
font-size: 24rpx;
color: #9aa0a6;
}
.goods-card {
border-radius: 24rpx;
padding: 22rpx;
box-sizing: border-box;
}
.goods-empty {
padding: 24rpx 0;
text-align: center;
font-size: 26rpx;
color: #9aa0a6;
}
.footer {
padding: 18rpx 24rpx 28rpx;
}
.btn {
width: 100%;
height: 96rpx;
line-height: 96rpx;
border-radius: 20rpx;
background: #5b4eff;
color: #fff;
font-size: 32rpx;
font-weight: 600;
}
</style>