feat:网点列表展示、启/停用api

This commit is contained in:
2026-07-15 12:04:29 +08:00
parent df0ae8143a
commit 26c8f721f7
3 changed files with 546 additions and 67 deletions
+140 -12
View File
@@ -10,6 +10,15 @@
</template>
<view class="page">
<view class="top-bar bg24">
<view v-if="storeList.length" class="store-row flex-center ju-between" @tap="openStoreSheet">
<view class="store-left flex-center">
<view class="store-label c_999 size24">当前网点</view>
<view class="store-name lineOne">{{ currentStoreName }}</view>
</view>
<view v-if="storeList.length > 1" class="store-arrow">
<uni-icons type="right" size="16" color="#7b8494" />
</view>
</view>
<view class="tabs">
<view
v-for="item in tabs"
@@ -134,6 +143,7 @@
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 tabs = [
{ label: '全部', value: 'all' },
@@ -148,20 +158,97 @@
const loading = ref(false);
const expandedMap = ref({});
const userStore = sheep.$store('user');
const storeList = ref([]);
const storeIdsKey = ref('');
const selectedStoreId = ref(0);
const storeLoading = ref(false);
const displayList = computed(() => list.value);
const sanitizeText = (value) => String(value || '').replace(/[`"'\s]/g, '');
const pickUpStoreId = computed(() => {
const userInfo = userStore?.userInfo || {};
return Number(userInfo.storeId || 0);
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 currentStore = computed(() => {
const id = Number(selectedStoreId.value || 0);
const list = Array.isArray(storeList.value) ? storeList.value : [];
return list.find((s) => Number(s?.id || 0) === id) || list[0] || {};
});
const ensureStoreId = async () => {
if (pickUpStoreId.value > 0) return pickUpStoreId.value;
const userInfo = await userStore.getInfo();
return Number(userInfo?.storeId || 0);
const currentStoreName = computed(() => getStoreName(currentStore.value) || '请选择网点');
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 ensureStoreList = async () => {
const storeIds = await getUserStoreIds();
if (!storeIds) {
storeList.value = [];
storeIdsKey.value = '';
selectedStoreId.value = 0;
return '';
}
if (storeLoading.value) return storeIds;
if (storeIdsKey.value === storeIds && storeList.value.length) return storeIds;
storeLoading.value = true;
try {
const { code, data } = await StoreApi.getStoreListByStoreIds(storeIds);
if (code !== 0) return storeIds;
storeList.value = Array.isArray(data) ? data : [];
storeIdsKey.value = storeIds;
const currentSelected = Number(selectedStoreId.value || 0);
const existsSelected = storeList.value.some((s) => Number(s?.id || 0) === currentSelected);
if (!existsSelected) {
const preferred = Number(userStore?.userInfo?.storeId || 0);
const nextFromPreferred = storeList.value.find((s) => Number(s?.id || 0) === preferred);
const nextId = Number(nextFromPreferred?.id || storeList.value[0]?.id || 0);
if (nextId > 0) selectedStoreId.value = nextId;
}
return storeIds;
} finally {
storeLoading.value = false;
}
};
const ensurePickUpStoreId = async () => {
await ensureStoreList();
return Number(selectedStoreId.value || 0);
};
const buildParams = (storeId) => {
@@ -176,9 +263,9 @@
const getList = async () => {
if (loading.value) return;
const storeId = await ensureStoreId();
const storeId = await ensurePickUpStoreId();
if (!(storeId > 0)) {
uni.showToast({ title: '缺少门店ID', icon: 'none' });
uni.showToast({ title: '缺少网点信息', icon: 'none' });
return;
}
loading.value = true;
@@ -188,13 +275,28 @@
list.value = Array.isArray(data) ? data : [];
};
onShow(() => {
getList();
const openStoreSheet = () => {
if (storeList.value.length <= 1) return;
const itemList = storeList.value.map((s) => getStoreName(s) || '未命名网点');
uni.showActionSheet({
itemList,
success: ({ tapIndex }) => {
const next = Number(storeList.value?.[tapIndex]?.id || 0);
if (next > 0 && next !== selectedStoreId.value) {
selectedStoreId.value = next;
}
},
});
};
onShow(async () => {
await ensureStoreList();
await getList();
});
let searchTimer = null;
watch(
[currentTab, keyword],
[currentTab, keyword, selectedStoreId],
() => {
if (searchTimer) clearTimeout(searchTimer);
searchTimer = setTimeout(() => {
@@ -288,6 +390,32 @@
margin-bottom: 18rpx;
}
.store-row {
padding: 10rpx 4rpx 14rpx;
border-bottom: 2rpx solid #f1f2f6;
margin-bottom: 14rpx;
}
.store-left {
min-width: 0;
gap: 12rpx;
}
.store-label {
flex-shrink: 0;
}
.store-name {
font-size: 28rpx;
color: #222;
font-weight: 600;
max-width: 520rpx;
}
.store-arrow {
flex-shrink: 0;
}
.tabs {
display: flex;
gap: 12rpx;
+377 -55
View File
@@ -39,23 +39,55 @@
</view>
<view class="table bg24">
<view class="thead flex-center">
<view class="th w1">店名</view>
<view class="th w2">编号</view>
<view class="th w3">状态</view>
<view class="th w4">操作</view>
</view>
<view v-for="row in filteredList" :key="row.id" class="tr flex-center">
<view class="td w1 lineOne">{{ row.name }}</view>
<view class="td w2 c_999">{{ row.code }}</view>
<view class="td w3">
<view class="badge" :class="{ badgeOpen: row.status === 'open' }">
{{ row.status === 'open' ? '营业中' : '休息中' }}
<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-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>
<view class="store-capacity__bar">
<view
class="store-capacity__fill"
:style="{ width: `${row.capacityPercent}%` }"
></view>
</view>
</view>
</view>
</view>
<view class="td w4 flex-center ju-flex-end">
<view class="store-actions flex-center ju-flex-end">
<view class="op opPrimary" @tap="edit(row)">编辑</view>
<view class="op opDanger" @tap="toggle(row)">{{ row.status === 'open' ? '停用' : '启用' }}</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>
@@ -66,29 +98,181 @@
<script setup>
import { computed, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import modeSwitch from '@/components/mode_switch/mode_switch.vue';
const stats = ref({
total: 28,
open: 24,
todayOrders: 156,
});
import sheep from '@/sheep';
import StoreApi from '@/sheep/api/trade/store';
const keyword = ref('');
const list = ref([
{ id: 1, name: '虹桥枢纽自提站', code: 'SP-2024001', status: 'open' },
{ id: 2, name: '静安寺中心站', code: 'SP-2024002', status: 'open' },
{ id: 3, name: '徐家汇社区站', code: 'SP-2024003', status: 'rest' },
{ id: 4, name: '五角场站', code: 'SP-2024004', status: 'open' },
]);
const list = ref([]);
const loading = ref(false);
const updatingStoreId = ref(0);
const userStore = sheep.$store('user');
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 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)));
return {
percent,
text: minSales > 0 ? `${stock} / 最低销量${minSales}` : `${stock}`,
};
};
const normalizeRow = (store) => {
const status = getStoreStatus(store);
const statusConfig = statusMap[status] || { text: '--', className: '' };
const toggleActionText = status === 1 ? '停用' : status === 2 || status === 3 ? '启用' : '';
const capacityInfo = getCapacityInfo(store);
return {
id: Number(store?.id || 0),
name: getStoreName(store),
code: getStoreCode(store),
phone: getStorePhone(store),
address: getStoreAddress(store),
coverImage: getStoreCoverImage(store),
capacityPercent: capacityInfo.percent,
capacityText: capacityInfo.text,
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));
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: 0,
};
});
const getList = async () => {
if (loading.value) return;
loading.value = true;
try {
const storeIds = await getUserStoreIds();
if (!storeIds) {
list.value = [];
return;
}
const { code, data } = await StoreApi.getStoreListByStoreIds(storeIds);
if (code !== 0) return;
const rows = Array.isArray(data) ? data : [];
list.value = rows.map(normalizeRow).filter((r) => r.id > 0);
} finally {
loading.value = false;
}
};
const addStore = () => {
uni.showToast({ title: '功能开发中', icon: 'none' });
};
@@ -98,9 +282,33 @@
};
const toggle = (row) => {
row.status = row.status === 'open' ? 'rest' : 'open';
uni.showToast({ title: '已更新', icon: 'success' });
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();
});
</script>
<style scoped lang="scss">
@@ -173,46 +381,133 @@
box-sizing: border-box;
}
.thead {
padding: 10rpx 0;
border-bottom: 2rpx solid #f1f2f6;
}
.tr {
padding: 18rpx 0;
border-bottom: 2rpx solid #f6f7fb;
}
.th,
.td {
font-size: 24rpx;
color: #333;
}
.w1 {
width: 34%;
}
.w2 {
width: 26%;
}
.w3 {
width: 18%;
.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;
}
.w4 {
width: 22%;
.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-capacity {
margin-top: 14rpx;
}
.store-capacity__head {
margin-bottom: 8rpx;
}
.store-capacity__label,
.store-capacity__value {
font-size: 22rpx;
color: #667085;
}
.store-capacity__bar {
width: 100%;
height: 12rpx;
border-radius: 999rpx;
background: #edf1f7;
overflow: hidden;
}
.store-capacity__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;
color: #ff7a00;
background: rgba(255, 122, 0, 0.12);
flex-shrink: 0;
}
.badgeOpen {
@@ -220,9 +515,28 @@
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;
margin-left: 14rpx;
}
.opPrimary {
@@ -233,6 +547,14 @@
color: #ff4d4f;
}
.opSuccess {
color: #14a44d;
}
.opDisabled {
opacity: 0.6;
}
.empty {
text-align: center;
padding: 80rpx 0;
+29
View File
@@ -29,6 +29,22 @@ const StoreApi = {
}
return res;
},
getStoreListByStoreIds: async (storeIds) => {
const res = await request({
url: '/trade/store/list-by-store-ids',
method: 'GET',
params: {
storeIds,
},
custom: {
showLoading: false,
},
});
if (res?.code === 0) {
res.data = normalizeList(res.data);
}
return res;
},
getStoreById: (storeId) => {
return request({
url: '/trade/store/getStoreById',
@@ -41,6 +57,19 @@ const StoreApi = {
},
});
},
updateStatus: (storeId, status) => {
return request({
url: '/trade/store/update-status',
method: 'PUT',
params: {
storeId,
status,
},
custom: {
showLoading: false,
},
});
},
};
export default StoreApi;