Files
kangyuan-mobile/pages/index/listRecord.vue
T

281 lines
6.5 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>
<s-pages title="列表记录" :pink_bg="false" navPreset="light">
<view class="list-record-page">
<view class="share-btn" :style="{ top: shareTop }" @tap="onShare">
一键分享
</view>
<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">{{ item.statusText }}</view>
</view>
<view class="record-progress">
<view class="progress-bar">
<view class="progress" :style="{ width: `${item.progress}%` }"></view>
</view>
</view>
<view class="record-meta">
<view class="meta-row flex-row-end">
<view class="record-qty">数量 {{ item.qty }}</view>
</view>
<view class="meta-row flex-between">
<view class="record-time">下单时间:{{ item.time }}</view>
<view class="record-total-inline">
<view class="total-label">总计</view>
<view class="total-price">¥{{ formatMoney(item.total) }}</view>
</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';
import { formatOrderStatus } from '@/sheep/hooks/useGoods';
const statusBarHeight = uni.getSystemInfoSync()?.statusBarHeight || 0;
const shareTop = `${statusBarHeight + 8}px`;
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 formatMoney = (value) => {
const num = Number(value);
if (!Number.isFinite(num)) return '0.00';
return num.toFixed(2);
};
const mapOrderToRecord = (order) => {
const items = Array.isArray(order?.items) ? order.items : [];
const firstItem = items[0] || {};
const titleText = firstItem?.spuName || order?.no || '-';
const qty = Number(order?.productCount ?? 0) || 0;
const statusText = formatOrderStatus(order || {});
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,
statusText,
progress: 80,
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 {
position: fixed;
right: 24rpx;
z-index: 99;
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;
}
.hero {
margin-top: 18rpx;
border-radius: 26rpx;
overflow: hidden;
background: #ffffff;
}
.hero-img {
width: 100%;
height: 340rpx;
display: block;
}
.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;
color: #8a8a8a;
}
.record-progress {
margin-top: 18rpx;
}
.progress-bar {
width: 60%;
height: 20rpx;
border-radius: 999rpx;
background: linear-gradient(90deg, #2c63ff 0%, #ff3b30 100%);
overflow: hidden;
}
.progress {
height: 13rpx;
margin: 3rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.92);
}
.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-label {
font-size: 24rpx;
color: #111111;
}
.total-price {
font-size: 34rpx;
font-weight: 800;
color: #ff3b30;
}
</style>