177 lines
6.9 KiB
Plaintext
177 lines
6.9 KiB
Plaintext
<template>
|
|
<view class="admin-page">
|
|
<view class="filter-card">
|
|
<view class="filter-row">
|
|
<view class="filter-item">
|
|
<text class="label">搜索:</text>
|
|
<input class="filter-input" placeholder="请输入姓名、UID" v-model="searchQuery" @confirm="onSearch" />
|
|
</view>
|
|
<view class="filter-btns">
|
|
<button class="btn primary" @click="onSearch">查询</button>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="content-card">
|
|
<view class="action-bar">
|
|
<button class="btn primary small" @click="onAdd">添加事业部</button>
|
|
</view>
|
|
<view class="table-container">
|
|
<!-- Loading 遮罩 -->
|
|
<view v-if="isLoading" class="loading-mask">
|
|
<text class="loading-text">加载中...</text>
|
|
</view>
|
|
|
|
<view class="table-header">
|
|
<view class="col col-uid"><text>用户UID</text></view>
|
|
<view class="col col-avatar"><text>头像</text></view>
|
|
<view class="col col-name"><text>名称</text></view>
|
|
<view class="col col-code"><text>邀请码</text></view>
|
|
<view class="col col-ratio"><text>分销比例</text></view>
|
|
<view class="col col-count"><text>代理商数量</text></view>
|
|
<view class="col col-time"><text>截止时间</text></view>
|
|
<view class="col col-status"><text>状态</text></view>
|
|
<view class="col col-ops"><text>操作</text></view>
|
|
</view>
|
|
<view class="table-body">
|
|
<view v-if="divisionList.length === 0 && !isLoading" class="empty-row">
|
|
<text>暂无事业部数据</text>
|
|
</view>
|
|
<view v-for="item in divisionList" :key="item.uid" class="table-row">
|
|
<view class="col col-uid"><text class="td-txt-small">{{ item.uid }}</text></view>
|
|
<view class="col col-avatar">
|
|
<image class="avatar-img" :src="item.avatar_url || '/static/logo.png'" mode="aspectFill" />
|
|
</view>
|
|
<view class="col col-name"><text>{{ item.name || item.nickname }}</text></view>
|
|
<view class="col col-code"><text>{{ item.invite_code }}</text></view>
|
|
<view class="col col-ratio"><text>{{ item.ratio }}%</text></view>
|
|
<view class="col col-count"><text>{{ item.agent_count }}</text></view>
|
|
<view class="col col-time"><text>{{ formatTime(item.end_time) }}</text></view>
|
|
<view class="col col-status">
|
|
<switch :checked="item.status" color="#1890ff" scale="0.8" @change="toggleStatus(item)" />
|
|
</view>
|
|
<view class="col col-ops">
|
|
<text class="op-link">查看代理商</text>
|
|
<text class="op-divider">|</text>
|
|
<text class="op-link" @click="onDelete(item.id)">删除</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="pagination">
|
|
<view class="pager-btns">
|
|
<button class="btn small" :disabled="page <= 1" @click="onPrevPage">上一页</button>
|
|
<text class="page-num">第 {{ page }} 页</text>
|
|
<button class="btn small" :disabled="divisionList.length < pageSize" @click="onNextPage">下一页</button>
|
|
</view>
|
|
<text class="page-info">共 {{ total }} 条记录</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
<script setup lang="uts">
|
|
import { ref, onMounted } from 'vue'
|
|
import { fetchDivisions, saveDivision, deleteDivision, DistributionDivision } from '@/services/admin/distributionService.uts'
|
|
|
|
const divisionList = ref<DistributionDivision[]>([])
|
|
const isLoading = ref(false)
|
|
const searchQuery = ref('')
|
|
const total = ref(0)
|
|
const page = ref(1)
|
|
const pageSize = 20
|
|
|
|
onMounted(() => {
|
|
loadData()
|
|
})
|
|
|
|
async function loadData() {
|
|
isLoading.value = true
|
|
try {
|
|
const res = await fetchDivisions({
|
|
search: searchQuery.value,
|
|
page: page.value,
|
|
pageSize: pageSize
|
|
})
|
|
divisionList.value = res.items
|
|
total.value = res.total
|
|
} catch (e) {
|
|
uni.showToast({ title: '加载失败', icon: 'none' })
|
|
} finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
|
|
function onSearch() {
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onAdd() {
|
|
uni.showToast({ title: '添加事业部功能开发中', icon: 'none' })
|
|
}
|
|
|
|
async function toggleStatus(item : DistributionDivision) {
|
|
if (item.id == null) return
|
|
const nextStatus = !item.status
|
|
const success = await saveDivision({ ...item, status: nextStatus } as DistributionDivision)
|
|
if (success) {
|
|
item.status = nextStatus
|
|
uni.showToast({ title: '状态修改成功', icon: 'success' })
|
|
}
|
|
}
|
|
|
|
async function onDelete(id : string | undefined) {
|
|
if (id == null) return
|
|
uni.showModal({
|
|
title: '确认删除',
|
|
content: '确定要删除该事业部吗?',
|
|
success: async (res) => {
|
|
if (res.confirm) {
|
|
const success = await deleteDivision(id!)
|
|
if (success) {
|
|
uni.showToast({ title: '删除成功' })
|
|
loadData()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
function onPrevPage() {
|
|
if (page.value > 1) {
|
|
page.value--
|
|
loadData()
|
|
}
|
|
}
|
|
|
|
function onNextPage() {
|
|
if (divisionList.value.length >= pageSize) {
|
|
page.value++
|
|
loadData()
|
|
}
|
|
}
|
|
|
|
function formatTime(iso : string | null) : string {
|
|
if (!iso) return '-'
|
|
return iso.substring(0, 10)
|
|
}
|
|
</script>
|
|
<style scoped lang="scss">
|
|
.admin-page { padding: 0; }
|
|
.filter-card { background: #fff; padding: 24px; margin-bottom: 16px; border-radius: 4px; }
|
|
.filter-row { display: flex; flex-direction: row; align-items: center; gap: 24px; }
|
|
.label { font-size: 14px; color: #333; }
|
|
.filter-input { border: 1px solid #d9d9d9; height: 32px; width: 220px; padding: 0 12px; font-size: 14px; }
|
|
.btn { height: 32px; padding: 0 16px; font-size: 14px; border: 1px solid #d9d9d9; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
|
|
.btn.primary { background: #1890ff; border-color: #1890ff; color: #fff; }
|
|
.content-card { background: #fff; border-radius: 4px; }
|
|
.action-bar { padding: 16px 24px; }
|
|
.table-container { padding: 0 24px 24px; }
|
|
.table-header { display: flex; flex-direction: row; background: #f8faff; border-bottom: 1px solid #f0f0f0; padding: 12px 0; }
|
|
.table-row { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; padding: 12px 0; align-items: center; &:hover { background: #fafafa; } }
|
|
.col { padding: 0 8px; font-size: 14px; color: #333; display: flex; align-items: center; }
|
|
.col-uid { width: 80px; } .col-avatar { width: 80px; justify-content: center; } .col-name { width: 120px; } .col-code { width: 100px; justify-content: center; } .col-ratio { width: 100px; justify-content: center; } .col-count { width: 100px; justify-content: center; } .col-time { width: 120px; justify-content: center; } .col-status { width: 80px; justify-content: center; } .col-ops { flex: 1; justify-content: flex-end; }
|
|
.avatar-img { width: 32px; height: 32px; border-radius: 2px; }
|
|
.op-link { color: #1890ff; cursor: pointer; }
|
|
.op-divider { color: #e8e8e8; margin: 0 8px; }
|
|
</style> |