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;