669 lines
17 KiB
Vue
669 lines
17 KiB
Vue
<template>
|
||
<s-layout
|
||
title="网店管理"
|
||
:showLeftButton="false"
|
||
tabbar="/pages/merchant/storeManage"
|
||
navPreset="light"
|
||
>
|
||
<template #navRight>
|
||
<modeSwitch />
|
||
</template>
|
||
<view class="page">
|
||
<view class="stats">
|
||
<view class="stat bg24">
|
||
<view class="stat-label c_999 size24">总网店数</view>
|
||
<view class="stat-value">{{ stats.total }}</view>
|
||
</view>
|
||
<view class="stat bg24">
|
||
<view class="stat-label c_999 size24">营业中</view>
|
||
<view class="stat-value cGreen">{{ stats.open }}</view>
|
||
</view>
|
||
<view class="stat bg24">
|
||
<view class="stat-label c_999 size24">今日新增订单</view>
|
||
<view class="stat-value cOrange">{{ stats.todayOrders }}</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="tool-row bg24">
|
||
<view class="search-box flex-center flex1">
|
||
<uni-icons type="search" size="18" color="#8a8a8a" />
|
||
<uni-easyinput
|
||
class="search-input flex1"
|
||
v-model="keyword"
|
||
placeholder="搜索网店名称/编号"
|
||
:inputBorder="false"
|
||
:styles="{ fontSize: '28rpx' }"
|
||
/>
|
||
</view>
|
||
<picker
|
||
mode="selector"
|
||
class="status-picker"
|
||
:value="statusIndex"
|
||
:range="statusOptions"
|
||
range-key="label"
|
||
@change="bindStatusChange"
|
||
>
|
||
<view class="status-picker__inner">
|
||
<text class="status-picker__text">{{ statusOptions[statusIndex].label }}</text>
|
||
<uni-icons type="bottom" size="14" color="#8a8a8a" />
|
||
</view>
|
||
</picker>
|
||
<!-- <view class="btnAdd" @tap="addStore">+ 新增网店</view> -->
|
||
</view>
|
||
|
||
<view class="table">
|
||
<view v-for="(row, index) in filteredList" :key="row.id" class="tr">
|
||
<view class="store-card flex-center">
|
||
<view class="store-rank">#{{ index + 1 }}</view>
|
||
<view class="store-cover">
|
||
<image
|
||
v-if="row.coverImage"
|
||
class="store-cover__img"
|
||
:src="row.coverImage"
|
||
mode="aspectFill"
|
||
/>
|
||
<view v-else class="store-cover__empty">暂无封面</view>
|
||
</view>
|
||
<view class="store-main">
|
||
<view class="store-main__top flex-center ju-between">
|
||
<view class="store-name lineOne">{{ row.name }}</view>
|
||
<view class="badge" :class="row.statusClass">
|
||
{{ row.statusText }}
|
||
</view>
|
||
</view>
|
||
<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-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-progress__bar">
|
||
<view
|
||
class="store-progress__fill"
|
||
:style="{ width: `${row.progressPercent}%` }"
|
||
></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="store-actions flex-center ju-flex-end">
|
||
<view v-if="showEdit" class="op opPrimary" @tap="edit(row)">编辑</view>
|
||
<view
|
||
v-if="row.toggleActionText"
|
||
class="op"
|
||
:class="[
|
||
row.toggleActionText === '停用' ? 'opDanger' : 'opSuccess',
|
||
{ opDisabled: updatingStoreId === row.id },
|
||
]"
|
||
@tap="toggle(row)"
|
||
>
|
||
{{ updatingStoreId === row.id ? '处理中...' : row.toggleActionText }}
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view v-if="filteredList.length === 0" class="empty c_999">暂无数据</view>
|
||
</view>
|
||
</view>
|
||
</s-layout>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, ref } from 'vue';
|
||
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';
|
||
import StoreApi from '@/sheep/api/trade/store';
|
||
|
||
const keyword = ref('');
|
||
const statusIndex = ref(0);
|
||
const showEdit = false;
|
||
|
||
const list = ref([]);
|
||
const loading = ref(false);
|
||
const todayOrders = ref(0);
|
||
const updatingStoreId = ref(0);
|
||
const userStore = sheep.$store('user');
|
||
const statusOptions = [
|
||
{ label: '全部状态', value: '' },
|
||
{ label: '营业中', value: 1 },
|
||
{ label: '休息中', value: 2 },
|
||
];
|
||
|
||
const toStoreIdsString = (raw) => {
|
||
if (raw === null || raw === undefined) return '';
|
||
if (Array.isArray(raw)) {
|
||
return raw.map((v) => String(v).trim()).filter(Boolean).join(',');
|
||
}
|
||
const s = String(raw).trim();
|
||
if (!s) return '';
|
||
if (s.includes(',')) return s.replace(/\s+/g, '');
|
||
const n = Number(s);
|
||
if (Number.isFinite(n) && n > 0) return String(n);
|
||
return s.replace(/\s+/g, '');
|
||
};
|
||
|
||
const getUserStoreIds = async () => {
|
||
const local = userStore?.userInfo || {};
|
||
const fromLocal =
|
||
local.storeIds ??
|
||
local.storeIdList ??
|
||
local.pickUpStoreIds ??
|
||
local.pickUpStoreIdList ??
|
||
local.storeId;
|
||
let storeIds = toStoreIdsString(fromLocal);
|
||
if (storeIds) return storeIds;
|
||
const fetched = await userStore.getInfo();
|
||
const fromFetched =
|
||
fetched?.storeIds ??
|
||
fetched?.storeIdList ??
|
||
fetched?.pickUpStoreIds ??
|
||
fetched?.pickUpStoreIdList ??
|
||
fetched?.storeId;
|
||
storeIds = toStoreIdsString(fromFetched);
|
||
return storeIds;
|
||
};
|
||
|
||
const getStoreName = (store) => {
|
||
const name = String(store?.name || store?.storeName || store?.title || '').trim();
|
||
if (name) return name;
|
||
const id = Number(store?.id || 0);
|
||
return id ? `网点${id}` : '';
|
||
};
|
||
|
||
const getStoreCode = (store) => {
|
||
const v = store?.code ?? store?.storeCode ?? store?.no ?? store?.storeNo ?? store?.id;
|
||
return String(v ?? '').trim();
|
||
};
|
||
|
||
const getStorePhone = (store) => {
|
||
const v = store?.contactPhone ?? '';
|
||
return String(v ?? '').trim();
|
||
};
|
||
|
||
const getStoreAddress = (store) => {
|
||
const province = String(store?.province || '').trim();
|
||
const city = String(store?.city || '').trim();
|
||
const district = String(store?.district || '').trim();
|
||
const address = String(store?.address || '').trim();
|
||
const full = `${province}${city}${district}${address}`.trim();
|
||
if (full) return full;
|
||
return address;
|
||
};
|
||
|
||
const sanitizeUrl = (value) => String(value || '').replace(/[`"'\s]/g, '');
|
||
|
||
const getStoreCoverImage = (store) => {
|
||
const raw = sanitizeUrl(store?.coverImage || store?.image || store?.picUrl || '');
|
||
if (!raw) return '';
|
||
if (/^https?:\/\//i.test(raw)) return raw;
|
||
return sheep.$url.cdn(raw);
|
||
};
|
||
|
||
const statusMap = {
|
||
0: { text: '待审核', className: 'badgePending' },
|
||
1: { text: '营业中', className: 'badgeOpen' },
|
||
2: { text: '休息中', className: 'badgeRest' },
|
||
3: { text: '已关闭', className: 'badgeClosed' },
|
||
4: { text: '审核拒绝', className: 'badgeRejected' },
|
||
};
|
||
|
||
const getStoreStatus = (store) => {
|
||
const n = Number(store?.status);
|
||
return Number.isFinite(n) ? n : -1;
|
||
};
|
||
|
||
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 {
|
||
sales,
|
||
stock,
|
||
progressPercent,
|
||
progressText: `${sales} / ${stock}`,
|
||
};
|
||
};
|
||
|
||
const normalizeRow = (store) => {
|
||
const status = getStoreStatus(store);
|
||
const statusConfig = statusMap[status] || { text: '--', className: '' };
|
||
const toggleActionText = status === 1 ? '停用' : status === 2 || status === 3 ? '启用' : '';
|
||
const progressInfo = getStoreProgressInfo(store);
|
||
return {
|
||
id: Number(store?.id || 0),
|
||
name: getStoreName(store),
|
||
code: getStoreCode(store),
|
||
phone: getStorePhone(store),
|
||
address: getStoreAddress(store),
|
||
coverImage: getStoreCoverImage(store),
|
||
sales: progressInfo.sales,
|
||
stock: progressInfo.stock,
|
||
progressPercent: progressInfo.progressPercent,
|
||
progressText: progressInfo.progressText,
|
||
status,
|
||
statusText: statusConfig.text,
|
||
statusClass: statusConfig.className,
|
||
isOpen: status === 1,
|
||
toggleActionText,
|
||
raw: store,
|
||
};
|
||
};
|
||
|
||
const filteredList = computed(() => {
|
||
const k = String(keyword.value || '').trim();
|
||
if (!k) return list.value;
|
||
return list.value.filter(
|
||
(row) =>
|
||
String(row.name).includes(k) ||
|
||
String(row.code).includes(k) ||
|
||
String(row.phone).includes(k) ||
|
||
String(row.address).includes(k),
|
||
);
|
||
});
|
||
|
||
const stats = computed(() => {
|
||
const total = Array.isArray(list.value) ? list.value.length : 0;
|
||
const open = Array.isArray(list.value) ? list.value.filter((r) => r.isOpen).length : 0;
|
||
return {
|
||
total,
|
||
open,
|
||
todayOrders: todayOrders.value,
|
||
};
|
||
});
|
||
|
||
const updateTodayOrders = async (storeIds = '') => {
|
||
const pickUpStoreId = toStoreIdsString(storeIds);
|
||
if (!pickUpStoreId) {
|
||
todayOrders.value = 0;
|
||
return;
|
||
}
|
||
try {
|
||
const { code, data } = await OrderStoreApi.getTodayNewCount(pickUpStoreId);
|
||
todayOrders.value = code === 0 ? Math.max(0, Number(data) || 0) : 0;
|
||
} catch (error) {
|
||
todayOrders.value = 0;
|
||
}
|
||
};
|
||
|
||
const getList = async (force = false) => {
|
||
while (force && loading.value) {
|
||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||
}
|
||
if (loading.value) return;
|
||
loading.value = true;
|
||
try {
|
||
const storeIds = await getUserStoreIds();
|
||
if (!storeIds) {
|
||
list.value = [];
|
||
todayOrders.value = 0;
|
||
return;
|
||
}
|
||
const status = statusOptions[statusIndex.value]?.value;
|
||
const params = status === '' ? {} : { status };
|
||
const { code, data } = await StoreApi.getStoreListByStoreIds(storeIds, params);
|
||
if (code !== 0) {
|
||
todayOrders.value = 0;
|
||
return;
|
||
}
|
||
const rows = Array.isArray(data) ? data : [];
|
||
list.value = rows.map(normalizeRow).filter((r) => r.id > 0);
|
||
await updateTodayOrders(storeIds);
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
};
|
||
|
||
const addStore = () => {
|
||
uni.showToast({ title: '功能开发中', icon: 'none' });
|
||
};
|
||
|
||
const bindStatusChange = (e) => {
|
||
statusIndex.value = Number(e?.detail?.value || 0);
|
||
getList();
|
||
};
|
||
|
||
const edit = () => {
|
||
uni.showToast({ title: '功能开发中', icon: 'none' });
|
||
};
|
||
|
||
const toggle = (row) => {
|
||
const storeId = Number(row?.id || 0);
|
||
const nextStatus = row?.status === 1 ? 2 : row?.status === 2 || row?.status === 3 ? 1 : 0;
|
||
const actionText = nextStatus === 1 ? '启用' : '停用';
|
||
if (!(storeId > 0) || !(nextStatus === 1 || nextStatus === 2) || updatingStoreId.value === storeId) return;
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: `确认${actionText}该网店吗?`,
|
||
success: async ({ confirm }) => {
|
||
if (!confirm) return;
|
||
updatingStoreId.value = storeId;
|
||
try {
|
||
const { code } = await StoreApi.updateStatus(storeId, nextStatus);
|
||
if (code !== 0) return;
|
||
uni.showToast({ title: `${actionText}成功`, icon: 'success' });
|
||
await getList();
|
||
} catch (error) {
|
||
uni.showToast({ title: `${actionText}失败,请稍后重试`, icon: 'none' });
|
||
} finally {
|
||
updatingStoreId.value = 0;
|
||
}
|
||
},
|
||
});
|
||
};
|
||
|
||
onShow(() => {
|
||
getList();
|
||
});
|
||
|
||
onPullDownRefresh(async () => {
|
||
try {
|
||
await getList(true);
|
||
} finally {
|
||
uni.stopPullDownRefresh();
|
||
}
|
||
});
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.page {
|
||
padding: 24rpx 24rpx 170rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.stats {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr 1fr;
|
||
gap: 16rpx;
|
||
margin-bottom: 18rpx;
|
||
}
|
||
|
||
.stat {
|
||
border-radius: 24rpx;
|
||
padding: 18rpx 18rpx 16rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.stat-value {
|
||
margin-top: 8rpx;
|
||
font-size: 44rpx;
|
||
font-weight: 800;
|
||
color: #222;
|
||
}
|
||
|
||
.cGreen {
|
||
color: #14a44d;
|
||
}
|
||
|
||
.cOrange {
|
||
color: #ff7a00;
|
||
}
|
||
|
||
.tool-row {
|
||
border-radius: 24rpx;
|
||
padding: 16rpx;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 14rpx;
|
||
margin-bottom: 18rpx;
|
||
}
|
||
|
||
.search-box {
|
||
border-radius: 18rpx;
|
||
background: #f6f7fb;
|
||
padding: 6rpx 16rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
:deep(.search-input .uni-easyinput__content) {
|
||
background: transparent !important;
|
||
}
|
||
|
||
.status-picker {
|
||
flex-shrink: 0;
|
||
min-width: 180rpx;
|
||
border-radius: 18rpx;
|
||
background: #f6f7fb;
|
||
padding: 0 18rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.status-picker__inner {
|
||
height: 72rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 10rpx;
|
||
}
|
||
|
||
.status-picker__text {
|
||
font-size: 24rpx;
|
||
color: #333;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.btnAdd {
|
||
padding: 14rpx 18rpx;
|
||
border-radius: 18rpx;
|
||
background: #2556ec;
|
||
color: #fff;
|
||
font-size: 24rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.table {
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
background: transparent;
|
||
}
|
||
|
||
.tr {
|
||
margin-bottom: 18rpx;
|
||
padding: 18rpx 18rpx 20rpx;
|
||
border-radius: 24rpx;
|
||
background: #fff;
|
||
box-shadow: 0 8rpx 24rpx rgba(15, 23, 42, 0.05);
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.tr:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.store-rank {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
min-width: 68rpx;
|
||
height: 36rpx;
|
||
padding: 0 12rpx;
|
||
border-radius: 0 18rpx 18rpx 0;
|
||
background: rgba(37, 86, 236, 0.1);
|
||
color: #2556ec;
|
||
font-size: 22rpx;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.store-card {
|
||
position: relative;
|
||
align-items: flex-start;
|
||
padding-top: 52rpx;
|
||
}
|
||
|
||
.store-cover {
|
||
width: 120rpx;
|
||
height: 120rpx;
|
||
border-radius: 18rpx;
|
||
overflow: hidden;
|
||
flex-shrink: 0;
|
||
background: #f2f4f7;
|
||
}
|
||
|
||
.store-cover__img,
|
||
.store-cover__empty {
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
|
||
.store-cover__img {
|
||
display: block;
|
||
}
|
||
|
||
.store-cover__empty {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #b4bcc8;
|
||
font-size: 22rpx;
|
||
border: 2rpx dashed #e5e7eb;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.store-main {
|
||
min-width: 0;
|
||
flex: 1;
|
||
margin-left: 18rpx;
|
||
}
|
||
|
||
.store-main__top {
|
||
align-items: flex-start;
|
||
gap: 16rpx;
|
||
}
|
||
|
||
.store-name {
|
||
min-width: 0;
|
||
flex: 1;
|
||
font-size: 28rpx;
|
||
color: #222;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.store-code {
|
||
margin-top: 12rpx;
|
||
font-size: 24rpx;
|
||
}
|
||
|
||
.store-contact,
|
||
.store-address {
|
||
margin-top: 8rpx;
|
||
font-size: 24rpx;
|
||
line-height: 34rpx;
|
||
}
|
||
|
||
.store-progress {
|
||
margin-top: 14rpx;
|
||
}
|
||
|
||
.store-progress__head {
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.store-progress__label,
|
||
.store-progress__value {
|
||
font-size: 22rpx;
|
||
color: #667085;
|
||
}
|
||
|
||
.store-progress__bar {
|
||
width: 100%;
|
||
height: 12rpx;
|
||
border-radius: 999rpx;
|
||
background: #edf1f7;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.store-progress__fill {
|
||
height: 100%;
|
||
border-radius: 999rpx;
|
||
background: linear-gradient(90deg, #2556ec 0%, #5b8cff 100%);
|
||
}
|
||
|
||
.store-actions {
|
||
margin-top: 18rpx;
|
||
gap: 18rpx;
|
||
}
|
||
|
||
.badge {
|
||
padding: 6rpx 12rpx;
|
||
border-radius: 999rpx;
|
||
font-size: 22rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.badgeOpen {
|
||
color: #14a44d;
|
||
background: rgba(20, 164, 77, 0.12);
|
||
}
|
||
|
||
.badgePending {
|
||
color: #ff8a00;
|
||
background: rgba(255, 138, 0, 0.12);
|
||
}
|
||
|
||
.badgeRest {
|
||
color: #5b4eff;
|
||
background: rgba(91, 78, 255, 0.12);
|
||
}
|
||
|
||
.badgeClosed {
|
||
color: #8c8c8c;
|
||
background: rgba(140, 140, 140, 0.12);
|
||
}
|
||
|
||
.badgeRejected {
|
||
color: #ff4d4f;
|
||
background: rgba(255, 77, 79, 0.12);
|
||
}
|
||
|
||
.op {
|
||
font-size: 24rpx;
|
||
min-width: 120rpx;
|
||
height: 50rpx;
|
||
padding: 0 24rpx;
|
||
border-radius: 16rpx;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
font-weight: 600;
|
||
border: 2rpx solid #e5e7eb;
|
||
background: #fff;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.opPrimary {
|
||
color: #2556ec;
|
||
border-color: rgba(37, 86, 236, 0.2);
|
||
background: rgba(37, 86, 236, 0.06);
|
||
}
|
||
|
||
.opDanger {
|
||
color: #ff4d4f;
|
||
border-color: rgba(255, 77, 79, 0.28);
|
||
background: #fff5f5;
|
||
}
|
||
|
||
.opSuccess {
|
||
color: #14a44d;
|
||
border-color: rgba(20, 164, 77, 0.28);
|
||
background: #f2fbf5;
|
||
}
|
||
|
||
.opDisabled {
|
||
opacity: 0.6;
|
||
}
|
||
|
||
.empty {
|
||
text-align: center;
|
||
padding: 80rpx 0;
|
||
}
|
||
</style>
|