323 lines
7.7 KiB
Vue
323 lines
7.7 KiB
Vue
<template>
|
||
<s-pages title="列表记录" navPreset="light">
|
||
<template #navRight>
|
||
<view class="share-btn" @tap="onShare">一键分享</view>
|
||
</template>
|
||
<view class="list-record-page">
|
||
<view class="hero">
|
||
<image class="hero-img" :src="cover || '/static/home/bc.png'" mode="aspectFill" />
|
||
</view>
|
||
|
||
<view class="record-list">
|
||
<view class="record-card" v-for="(item, i) in recordList" :key="item.id || i">
|
||
<view class="record-head flex-between">
|
||
<view class="record-title lineOne">{{ item.title }}</view>
|
||
<view class="record-status" :class="`status-${item.status}`">{{ item.statusText }}</view>
|
||
</view>
|
||
|
||
<view class="record-progress">
|
||
<view class="progress-bar">
|
||
<view class="progress" :style="{ width: `${item.progress}%` }"></view>
|
||
<view class="progress-percent">{{ formatPercent(item.progress) }}%</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="record-meta">
|
||
<view class="meta-row flex-row-end">
|
||
<view class="record-total-inline">
|
||
<!-- <view class="total-price">¥{{ formatMoney(item.total) }}</view> -->
|
||
</view>
|
||
</view>
|
||
<view class="meta-row flex-between">
|
||
<view class="record-time">下单时间:{{ item.time }}</view>
|
||
<view class="record-qty">数量 {{ item.qty }}</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</s-pages>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { reactive, ref } from 'vue';
|
||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
|
||
import sheep from '@/sheep';
|
||
import { getAiShopPage } from '@/sheep/api/ai';
|
||
|
||
const skuId = ref('');
|
||
const cover = ref('');
|
||
|
||
const recordList = ref([]);
|
||
const state = reactive({
|
||
pageNo: 1,
|
||
pageSize: 10,
|
||
loading: false,
|
||
finished: false,
|
||
});
|
||
|
||
onLoad((query) => {
|
||
skuId.value = query?.skuId ?? query?.shopId ?? '';
|
||
fetchList(true);
|
||
});
|
||
|
||
onPullDownRefresh(() => {
|
||
fetchList(true).finally(() => {
|
||
uni.stopPullDownRefresh();
|
||
});
|
||
});
|
||
|
||
onReachBottom(() => {
|
||
fetchList(false);
|
||
});
|
||
|
||
const formatPercent = (value) => {
|
||
const num = Number(value);
|
||
if (!Number.isFinite(num)) return '0.00';
|
||
return num.toFixed(2);
|
||
};
|
||
|
||
const formatRecordStatus = (status) => {
|
||
const map = {
|
||
1: '已上架',
|
||
2: '进行中',
|
||
3: '已完成',
|
||
};
|
||
return map[Number(status)] || '';
|
||
};
|
||
|
||
const mapOrderToRecord = (order) => {
|
||
const items = Array.isArray(order?.items) ? order.items : [];
|
||
const firstItem = items[0] || {};
|
||
const titleText = firstItem?.spuName || order?.no || '-';
|
||
const qty = Number(firstItem?.count ?? 0) || 0;
|
||
const status = Number(firstItem?.status ?? 0) || 0;
|
||
const statusText = formatRecordStatus(status);
|
||
const sumItemTotalPrice = items.reduce((acc, cur) => acc + (Number(cur?.totalPrice) || 0), 0);
|
||
const sumItemTotalRevenue = items.reduce((acc, cur) => acc + (Number(cur?.totalRevenue) || 0), 0);
|
||
const totalPrice = sumItemTotalPrice || (Number(order?.totalPrice ?? 0) || 0);
|
||
const totalRevenue = sumItemTotalRevenue || (Number(order?.totalRevenue ?? 0) || 0);
|
||
const progress =
|
||
totalPrice > 0
|
||
? Math.max(0, Math.min(100, (totalRevenue / totalPrice) * 100))
|
||
: 0;
|
||
const timeText = sheep.$helper?.timeFormat
|
||
? sheep.$helper.timeFormat(order?.createTime, 'yy-mm-dd hh:MM:ss')
|
||
: String(order?.createTime || '');
|
||
const payPriceFen = Number(order?.payPrice ?? 0) || 0;
|
||
const totalYuan = payPriceFen / 100;
|
||
return {
|
||
id: order?.id,
|
||
title: titleText,
|
||
status,
|
||
statusText,
|
||
progress,
|
||
qty,
|
||
time: timeText,
|
||
total: totalYuan,
|
||
};
|
||
};
|
||
|
||
const fetchList = async (reset = false) => {
|
||
if (state.loading) return;
|
||
if (!skuId.value) {
|
||
uni.showToast({ title: '缺少 skuId', icon: 'none' });
|
||
return;
|
||
}
|
||
if (!reset && state.finished) return;
|
||
state.loading = true;
|
||
try {
|
||
if (reset) {
|
||
state.pageNo = 1;
|
||
state.finished = false;
|
||
}
|
||
const res = await getAiShopPage({
|
||
skuId: String(skuId.value),
|
||
pageNo: String(state.pageNo),
|
||
pageSize: String(state.pageSize),
|
||
}).catch(() => ({ code: -1 }));
|
||
if (res?.code !== 0) return;
|
||
const list = Array.isArray(res?.data?.list) ? res.data.list : [];
|
||
if (!cover.value && list.length) {
|
||
const firstItem = Array.isArray(list?.[0]?.items) ? list[0].items[0] : null;
|
||
const picUrl = firstItem?.picUrl || '';
|
||
if (picUrl) cover.value = sheep.$url.cdn(picUrl);
|
||
}
|
||
const mapped = list.map(mapOrderToRecord);
|
||
if (reset) recordList.value = [];
|
||
recordList.value = recordList.value.concat(mapped);
|
||
if (list.length < state.pageSize) {
|
||
state.finished = true;
|
||
} else {
|
||
state.pageNo += 1;
|
||
}
|
||
} finally {
|
||
state.loading = false;
|
||
}
|
||
};
|
||
|
||
const onShare = () => {
|
||
uni.showToast({ title: '分享功能开发中', icon: 'none' });
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.list-record-page {
|
||
padding: 0 32rpx 32rpx;
|
||
min-height: 100%;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.share-btn {
|
||
height: 56rpx;
|
||
padding: 0 18rpx;
|
||
border-radius: 18rpx;
|
||
background: rgba(255, 106, 74, 0.18);
|
||
color: #ff6a4a;
|
||
font-size: 24rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
position: relative;
|
||
top: -2rpx;
|
||
}
|
||
|
||
.hero {
|
||
margin-top: 18rpx;
|
||
border-radius: 26rpx;
|
||
overflow: hidden;
|
||
background: #ffffff;
|
||
}
|
||
|
||
.hero-img {
|
||
width: 100%;
|
||
height: 340rpx;
|
||
display: block;
|
||
transform: 3s ease-in-out;
|
||
}
|
||
|
||
.record-list {
|
||
margin-top: 18rpx;
|
||
}
|
||
|
||
.record-card {
|
||
background: #ffffff;
|
||
border-radius: 24rpx;
|
||
padding: 24rpx;
|
||
margin-bottom: 18rpx;
|
||
box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.06);
|
||
}
|
||
|
||
.record-head {
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.record-title {
|
||
flex: 1;
|
||
font-size: 34rpx;
|
||
font-weight: 700;
|
||
color: #111111;
|
||
}
|
||
|
||
.record-status {
|
||
flex-shrink: 0;
|
||
font-size: 24rpx;
|
||
padding: 8rpx 16rpx;
|
||
border-radius: 999rpx;
|
||
line-height: 1;
|
||
color: #8a8a8a;
|
||
// background: #f3f4f6;
|
||
}
|
||
|
||
.status-1 {
|
||
color: #2563eb;
|
||
background: rgba(37, 99, 235, 0.1);
|
||
}
|
||
|
||
.status-2 {
|
||
color: #f97316;
|
||
background: rgba(249, 115, 22, 0.12);
|
||
}
|
||
|
||
.status-3 {
|
||
color: #16a34a;
|
||
background: rgba(22, 163, 74, 0.12);
|
||
}
|
||
|
||
.record-progress {
|
||
margin-top: 18rpx;
|
||
}
|
||
|
||
.progress-bar {
|
||
width: 60%;
|
||
height: 20rpx;
|
||
border-radius: 999rpx;
|
||
background: linear-gradient(90deg, #2c63ff 0%, #ff3b30 100%);
|
||
overflow: hidden;
|
||
position: relative;
|
||
}
|
||
|
||
.progress {
|
||
height: 13rpx;
|
||
margin: 3rpx;
|
||
border-radius: 999rpx;
|
||
background: rgba(255, 255, 255, 0.92);
|
||
}
|
||
|
||
.progress-percent {
|
||
position: absolute;
|
||
left: 50%;
|
||
top: 50%;
|
||
transform: translate(-50%, -50%);
|
||
font-size: 18rpx;
|
||
font-weight: 600;
|
||
color: rgba(17, 17, 17, 0.9);
|
||
line-height: 1;
|
||
pointer-events: none;
|
||
text-shadow: 0 0 6rpx rgba(255, 255, 255, 0.9);
|
||
}
|
||
|
||
.record-meta {
|
||
margin-top: 18rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.meta-row {
|
||
align-items: baseline;
|
||
}
|
||
|
||
.record-total-inline {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 10rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.record-time {
|
||
font-size: 24rpx;
|
||
color: #111111;
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.record-qty {
|
||
font-size: 24rpx;
|
||
color: #333333;
|
||
}
|
||
|
||
.record-total {
|
||
margin-top: 18rpx;
|
||
align-items: baseline;
|
||
gap: 10rpx;
|
||
}
|
||
|
||
.total-price {
|
||
font-size: 34rpx;
|
||
font-weight: 800;
|
||
color: #ff3b30;
|
||
}
|
||
</style>
|