412 lines
9.5 KiB
Vue
412 lines
9.5 KiB
Vue
<template>
|
|
<div class="page-layout navbar store-list">
|
|
<t-navbar
|
|
fixed
|
|
:z-index="20"
|
|
title="门店管理"
|
|
left-arrow
|
|
@left-click="$router.back()"
|
|
>
|
|
<template #right>
|
|
<div
|
|
class="nav-actions"
|
|
v-if="(canShowActionMenu) && pageNavBarActionList.length"
|
|
>
|
|
<t-popover
|
|
v-model:visible="pageNavBarActionVisible"
|
|
placement="bottom-right"
|
|
:show-arrow="false"
|
|
theme="light"
|
|
>
|
|
<t-button
|
|
class="trigger"
|
|
variant="text"
|
|
:aria-label="'更多操作'"
|
|
type="button"
|
|
>
|
|
<template #icon>
|
|
<t-icon name="ellipsis" />
|
|
</template>
|
|
</t-button>
|
|
<template #content>
|
|
<div class="menu">
|
|
<t-button
|
|
v-for="action in pageNavBarActionList"
|
|
:key="action.key"
|
|
class="menu-item"
|
|
variant="text"
|
|
type="button"
|
|
:theme="action.theme"
|
|
:loading="action.loading"
|
|
:disabled="action.disabled || action.loading"
|
|
@click="handlePageNavBarAction(action)"
|
|
>
|
|
<template v-if="action.icon" #icon>
|
|
<t-icon :name="action.icon" />
|
|
</template>
|
|
<span v-text="action.text" />
|
|
</t-button>
|
|
</div>
|
|
</template>
|
|
</t-popover>
|
|
</div>
|
|
</template>
|
|
</t-navbar>
|
|
<main v-can="permissionCodes.store.read" class="page-content scroll list">
|
|
<t-pull-down-refresh
|
|
class="list-wrapper pull-refresh"
|
|
v-model="isRefreshing"
|
|
:refresh-timeout="30000"
|
|
@refresh="refresh"
|
|
@scrolltolower="fetch"
|
|
>
|
|
<t-cell-group theme="card" class="fix-last-cell-line">
|
|
<t-swipe-cell
|
|
v-entrance-transition="{ step: 30 }"
|
|
v-for="item in pageResult.list"
|
|
:key="item.id"
|
|
class="item"
|
|
>
|
|
<t-cell
|
|
class="cell"
|
|
arrow
|
|
@click="toEdit(item)"
|
|
>
|
|
<template #title>
|
|
<div class="header">
|
|
<div class="title text-bold clip-text" v-text="item.name || '未命名门店'"></div>
|
|
<t-tag size="small" :theme="getStoreStatusTheme(item.status)" variant="outline" :content="getStoreStatusText(item.status)" />
|
|
</div>
|
|
</template>
|
|
<template #description>
|
|
<div class="description">
|
|
<span class="gray" v-text="item.telephone ? `电话:${item.telephone}` : '电话:-'" />
|
|
<span class="gray" v-text="item.address ? `地址:${item.address}` : '地址:-'" />
|
|
</div>
|
|
</template>
|
|
</t-cell>
|
|
<template v-if="canDeleteStore" #right>
|
|
<t-button
|
|
class="delete"
|
|
theme="danger"
|
|
:loading="isRemoving && removingStoreId === item.id"
|
|
@click.stop="openRemoveDialog(item)"
|
|
>
|
|
删除
|
|
</t-button>
|
|
</template>
|
|
</t-swipe-cell>
|
|
</t-cell-group>
|
|
<div v-if="!pageResult.list.length" class="center-tips" v-text="isLoading ? '正在加载门店' : '暂无门店'" />
|
|
<div v-if="pageResult.list.length" class="center-tips" v-text="isNoMore ? '已加载全部门店' : '上拉加载更多'" />
|
|
</t-pull-down-refresh>
|
|
</main>
|
|
<store-remove-dialog
|
|
v-model:visible="removeDialogVisible"
|
|
:store="removeTarget"
|
|
:loading="isRemoving"
|
|
@confirm="removeStore"
|
|
/>
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { NavBarAction } from "@/types/NavBarAction";
|
|
import { Message } from "@/utils/message";
|
|
import { Time, WebToolkit } from "timi-web";
|
|
import { type Page, type PageResult, useUserStore } from "timi-web-api";
|
|
import StoreAPI from "@/api/StoreAPI";
|
|
import StoreRemoveDialog from "@/components/StoreRemoveDialog.vue";
|
|
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
|
import { getStoreStatusText, getStoreStatusTheme } from "@/utils/store";
|
|
|
|
const pageNavBarActionVisible = ref(false);
|
|
const pageNavBarActionList = computed<NavBarAction[]>(() => (unref(actionList) as NavBarAction[]).filter(action => action.visible !== false));
|
|
|
|
async function handlePageNavBarAction(action: NavBarAction): Promise<void> {
|
|
pageNavBarActionVisible.value = false;
|
|
await action.action();
|
|
}
|
|
|
|
import type { Store } from "@/types/Store";
|
|
|
|
defineOptions({
|
|
name: "StoreList"
|
|
});
|
|
|
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
|
const isStoreManagerScope = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager) && !userStore.hasRoles(gaoRoleCodes.globalManager));
|
|
const canCreateStore = computed(() => userStore.hasPermissions(permissionCodes.store.create));
|
|
const canSortStore = computed(() => userStore.hasPermissions(permissionCodes.store.update));
|
|
const canDeleteStore = computed(() => !isStoreManagerScope.value && userStore.hasPermissions(permissionCodes.store.delete));
|
|
const canExportStore = computed(() => userStore.hasPermissions(permissionCodes.store.export));
|
|
const canShowActionMenu = computed(() => canCreateStore.value || canSortStore.value || canExportStore.value);
|
|
const isExporting = ref(false);
|
|
const isRemoving = ref(false);
|
|
const removeDialogVisible = ref(false);
|
|
const removeTarget = ref<Store>();
|
|
const removingStoreId = ref("");
|
|
|
|
const actionList = computed<NavBarAction[]>(() => {
|
|
const list: NavBarAction[] = [];
|
|
if (canCreateStore.value) {
|
|
list.push({
|
|
action: toCreate,
|
|
theme: "primary",
|
|
icon: "add",
|
|
key: "create",
|
|
text: "新增门店"
|
|
});
|
|
}
|
|
if (canSortStore.value) {
|
|
list.push({
|
|
action: toSort,
|
|
icon: "order",
|
|
key: "sort",
|
|
text: "排序"
|
|
});
|
|
}
|
|
if (canExportStore.value) {
|
|
list.push({
|
|
action: exportExcel,
|
|
icon: "download",
|
|
key: "export",
|
|
loading: isExporting.value,
|
|
text: "导出 Excel"
|
|
});
|
|
}
|
|
return list;
|
|
});
|
|
|
|
// ---------- 列表数据 ----------
|
|
|
|
const isRefreshing = ref(false);
|
|
const isLoading = ref(false);
|
|
const isNoMore = ref(false);
|
|
const page = reactive<Page<Store>>({
|
|
index: 0,
|
|
size: 20,
|
|
orderMap: {
|
|
sort: "ASC",
|
|
createdAt: "DESC"
|
|
}
|
|
});
|
|
const pageResult = reactive<PageResult<Store>>({
|
|
total: 0,
|
|
list: []
|
|
});
|
|
|
|
async function refresh(): Promise<void> {
|
|
isRefreshing.value = true;
|
|
try {
|
|
page.index = 0;
|
|
pageResult.total = 0;
|
|
pageResult.list = [];
|
|
isNoMore.value = false;
|
|
await fetch();
|
|
} finally {
|
|
isRefreshing.value = false;
|
|
}
|
|
}
|
|
|
|
async function fetch(): Promise<void> {
|
|
if (isLoading.value || isNoMore.value) {
|
|
return;
|
|
}
|
|
isLoading.value = true;
|
|
try {
|
|
const result = await StoreAPI.list(page);
|
|
pageResult.total = result.total || 0;
|
|
pageResult.list = pageResult.list.concat(result.list || []);
|
|
page.index += 1;
|
|
isNoMore.value = pageResult.list.length >= pageResult.total || (result.list || []).length < page.size;
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
// ---------- 操作 ----------
|
|
|
|
async function exportExcel(): Promise<void> {
|
|
if (isExporting.value) {
|
|
return;
|
|
}
|
|
isExporting.value = true;
|
|
try {
|
|
const blob = await StoreAPI.exportXSSF({
|
|
index: 0,
|
|
size: 10000,
|
|
orderMap: page.orderMap
|
|
});
|
|
WebToolkit.downloadBlob(blob, `门店列表-${Time.formatDate(new Date())}.xlsx`);
|
|
Message.success("导出已开始");
|
|
} finally {
|
|
isExporting.value = false;
|
|
}
|
|
}
|
|
|
|
async function toEdit(item: Store): Promise<void> {
|
|
if (!item.id) {
|
|
return;
|
|
}
|
|
await router.push(`/management/stores/${item.id}`);
|
|
}
|
|
|
|
async function toCreate(): Promise<void> {
|
|
await router.push("/management/stores/create");
|
|
}
|
|
|
|
async function toSort(): Promise<void> {
|
|
await router.push("/management/stores/sort");
|
|
}
|
|
|
|
// ---------- 删除门店 ----------
|
|
|
|
function openRemoveDialog(store: Store): void {
|
|
if (!store.id || isRemoving.value) {
|
|
return;
|
|
}
|
|
removeTarget.value = store;
|
|
removeDialogVisible.value = true;
|
|
}
|
|
|
|
async function removeStore(store: Store): Promise<void> {
|
|
const storeId = store.id;
|
|
if (!storeId || isRemoving.value) {
|
|
return;
|
|
}
|
|
|
|
isRemoving.value = true;
|
|
removingStoreId.value = storeId;
|
|
removeDialogVisible.value = false;
|
|
removeTarget.value = undefined;
|
|
try {
|
|
await StoreAPI.remove(storeId);
|
|
pageResult.list = pageResult.list.filter(item => item.id !== storeId);
|
|
pageResult.total = Math.max(0, pageResult.total - 1);
|
|
isNoMore.value = pageResult.list.length >= pageResult.total;
|
|
Message.success("门店已删除");
|
|
} finally {
|
|
isRemoving.value = false;
|
|
removingStoreId.value = "";
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
|
|
try {
|
|
await fetch();
|
|
} catch {
|
|
Message.error("门店列表加载失败");
|
|
}
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
});
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.store-list {
|
|
gap: .75rem;
|
|
display: grid;
|
|
padding: calc(var(--app-nav-height) + 1rem) 0 1rem 0;
|
|
|
|
.list-wrapper {
|
|
min-height: 50vh;
|
|
|
|
.item {
|
|
|
|
:deep(.t-cell__title) {
|
|
flex: 1 1 0;
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
gap: .5rem;
|
|
display: flex;
|
|
overflow: hidden;
|
|
min-width: 0;
|
|
align-items: center;
|
|
}
|
|
|
|
.description {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.delete {
|
|
height: 100%;
|
|
padding: 0 1rem;
|
|
border-radius: 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
:global(html.theme-dark) {
|
|
.store-list {
|
|
.item {
|
|
background: #1e293b;
|
|
|
|
.cell {
|
|
background: #1e293b;
|
|
}
|
|
|
|
.name {
|
|
color: #e2e8f0;
|
|
}
|
|
|
|
.meta {
|
|
color: #94a3b8;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
.nav-actions {
|
|
--td-popover-padding: 0 .5rem;
|
|
|
|
width: 6rem;
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: flex-end;
|
|
|
|
:deep(.t-popover__content) { border-radius: .875rem; }
|
|
|
|
.trigger { padding: 0; }
|
|
|
|
.menu {
|
|
gap: .25rem;
|
|
display: grid;
|
|
padding: .5rem 0;
|
|
min-width: 9rem;
|
|
|
|
.menu-item {
|
|
--td-button-medium-height: 32px;
|
|
--td-button-medium-padding-horizontal: 10px;
|
|
|
|
gap: .25rem;
|
|
width: 100%;
|
|
font-weight: unset;
|
|
justify-content: flex-start;
|
|
}
|
|
}
|
|
}
|
|
|
|
:global(html.theme-dark) {
|
|
.nav-actions {
|
|
:deep(.t-popover__content) {
|
|
color: #e2e8f0;
|
|
background: rgba(30, 41, 59, .98);
|
|
}
|
|
|
|
.menu-item { color: #e2e8f0; }
|
|
}
|
|
}
|
|
</style>
|