feat: 添加页面刷新功能
This commit is contained in:
@@ -74,18 +74,18 @@
|
||||
<view class="store-code c_999">编号:{{ row.code || '--' }}</view>
|
||||
<view class="store-contact c_999 lineOne">联系电话:{{ row.phone || '--' }}</view>
|
||||
<view class="store-address c_999">{{ row.address || '--' }}</view>
|
||||
<!-- <view class="store-capacity">
|
||||
<view class="store-capacity__head flex-center ju-between">
|
||||
<view class="store-capacity__label">库存容量</view>
|
||||
<view class="store-capacity__value">{{ row.capacityText }}</view>
|
||||
<view class="store-progress">
|
||||
<view class="store-progress__head flex-center ju-between">
|
||||
<view class="store-progress__label">销量 / 库存</view>
|
||||
<view class="store-progress__value">{{ row.progressText }}</view>
|
||||
</view>
|
||||
<view class="store-capacity__bar">
|
||||
<view class="store-progress__bar">
|
||||
<view
|
||||
class="store-capacity__fill"
|
||||
:style="{ width: `${row.capacityPercent}%` }"
|
||||
class="store-progress__fill"
|
||||
:style="{ width: `${row.progressPercent}%` }"
|
||||
></view>
|
||||
</view>
|
||||
</view> -->
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="store-actions flex-center ju-flex-end">
|
||||
@@ -111,7 +111,7 @@
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { onPullDownRefresh, onShow } from '@dcloudio/uni-app';
|
||||
import modeSwitch from '@/components/mode_switch/mode_switch.vue';
|
||||
import sheep from '@/sheep';
|
||||
import OrderStoreApi from '@/sheep/api/trade/orderStore';
|
||||
@@ -215,20 +215,16 @@
|
||||
return Number.isFinite(n) ? n : -1;
|
||||
};
|
||||
|
||||
const getCapacityInfo = (store) => {
|
||||
const stock = Math.max(0, Number(store?.stock) || 0);
|
||||
const minSales = Math.max(0, Number(store?.minSales) || 0);
|
||||
if (!(stock > 0)) {
|
||||
return {
|
||||
percent: 0,
|
||||
text: '--',
|
||||
};
|
||||
}
|
||||
// 当前接口仅返回 stock,没有总容量字段,这里用一个可读的梯度进度来表达库存量级
|
||||
const percent = Math.max(8, Math.min(100, Math.round((stock / Math.max(stock, 100)) * 100)));
|
||||
const getStoreProgressInfo = (store) => {
|
||||
const sales = Math.max(0, Number(store?.sales ?? store?.salesCount) || 0);
|
||||
const stock = Math.max(0, Number(store?.stock ?? store?.stocks) || 0);
|
||||
const ratio = stock > 0 ? Math.round((sales / stock) * 100) : 0;
|
||||
const progressPercent = Math.max(0, Math.min(100, ratio));
|
||||
return {
|
||||
percent,
|
||||
text: minSales > 0 ? `${stock} / 最低销量${minSales}` : `${stock}`,
|
||||
sales,
|
||||
stock,
|
||||
progressPercent,
|
||||
progressText: `${sales} / ${stock}`,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -236,7 +232,7 @@
|
||||
const status = getStoreStatus(store);
|
||||
const statusConfig = statusMap[status] || { text: '--', className: '' };
|
||||
const toggleActionText = status === 1 ? '停用' : status === 2 || status === 3 ? '启用' : '';
|
||||
const capacityInfo = getCapacityInfo(store);
|
||||
const progressInfo = getStoreProgressInfo(store);
|
||||
return {
|
||||
id: Number(store?.id || 0),
|
||||
name: getStoreName(store),
|
||||
@@ -244,8 +240,10 @@
|
||||
phone: getStorePhone(store),
|
||||
address: getStoreAddress(store),
|
||||
coverImage: getStoreCoverImage(store),
|
||||
capacityPercent: capacityInfo.percent,
|
||||
capacityText: capacityInfo.text,
|
||||
sales: progressInfo.sales,
|
||||
stock: progressInfo.stock,
|
||||
progressPercent: progressInfo.progressPercent,
|
||||
progressText: progressInfo.progressText,
|
||||
status,
|
||||
statusText: statusConfig.text,
|
||||
statusClass: statusConfig.className,
|
||||
@@ -291,7 +289,10 @@
|
||||
}
|
||||
};
|
||||
|
||||
const getList = async () => {
|
||||
const getList = async (force = false) => {
|
||||
while (force && loading.value) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
if (loading.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -357,6 +358,14 @@
|
||||
onShow(() => {
|
||||
getList();
|
||||
});
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
try {
|
||||
await getList(true);
|
||||
} finally {
|
||||
uni.stopPullDownRefresh();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -549,21 +558,21 @@
|
||||
line-height: 34rpx;
|
||||
}
|
||||
|
||||
.store-capacity {
|
||||
.store-progress {
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.store-capacity__head {
|
||||
.store-progress__head {
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.store-capacity__label,
|
||||
.store-capacity__value {
|
||||
.store-progress__label,
|
||||
.store-progress__value {
|
||||
font-size: 22rpx;
|
||||
color: #667085;
|
||||
}
|
||||
|
||||
.store-capacity__bar {
|
||||
.store-progress__bar {
|
||||
width: 100%;
|
||||
height: 12rpx;
|
||||
border-radius: 999rpx;
|
||||
@@ -571,7 +580,7 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.store-capacity__fill {
|
||||
.store-progress__fill {
|
||||
height: 100%;
|
||||
border-radius: 999rpx;
|
||||
background: linear-gradient(90deg, #2556ec 0%, #5b8cff 100%);
|
||||
|
||||
Reference in New Issue
Block a user