This commit is contained in:
menxipeng
2025-11-27 19:51:05 +08:00
parent 7f095044cb
commit a35cba1449
3 changed files with 153 additions and 83 deletions

View File

@@ -44,7 +44,7 @@ export default function LoginPage() {
// 如果接口失败,使用默认角色列表作为备选
setRoles([
{ roleId: "admin", roleName: "总部管理员", roleKey: "admin", remark: "", admin: true },
{ roleId: "dealer", roleName: "经销商", roleKey: "dealer", remark: "", admin: false },
{ roleId: "dealer", roleName: "区域负责人", roleKey: "dealer", remark: "", admin: false },
{ roleId: "mall", roleName: "商场管理员", roleKey: "mall", remark: "", admin: false },
{ roleId: "merchant", roleName: "商户", roleKey: "merchant", remark: "", admin: false },
{ roleId: "worker", roleName: "维修工人", roleKey: "worker", remark: "", admin: false },
@@ -55,7 +55,7 @@ export default function LoginPage() {
// 网络错误时使用默认角色列表
setRoles([
{ roleId: "admin", roleName: "总部管理员", roleKey: "admin", remark: "", admin: true },
{ roleId: "dealer", roleName: "经销商", roleKey: "dealer", remark: "", admin: false },
{ roleId: "dealer", roleName: "区域负责人", roleKey: "dealer", remark: "", admin: false },
{ roleId: "mall", roleName: "商场管理员", roleKey: "mall", remark: "", admin: false },
{ roleId: "merchant", roleName: "商户", roleKey: "merchant", remark: "", admin: false },
{ roleId: "worker", roleName: "维修工人", roleKey: "worker", remark: "", admin: false },

View File

@@ -78,6 +78,13 @@ export default function MerchantsPage() {
const [userRole, setUserRole] = useState<string>("")
const [currentPage, setCurrentPage] = useState(1)
const [pageSize, setPageSize] = useState(10)
const [userEquipmentCount, setUserEquipmentCount] = useState({
count: 0,
totalCount: 0,
countEnd: 0,
countExpire: 0
})
const [loadingUserEquipmentCount, setLoadingUserEquipmentCount] = useState(false)
const [newMerchant, setNewMerchant] = useState({
name: "",
@@ -120,6 +127,26 @@ export default function MerchantsPage() {
}
}
// 获取用户设备统计数量
const fetchUserEquipmentCount = async () => {
setLoadingUserEquipmentCount(true)
try {
const response = await apiGet('/back/equipment/user/count')
if (response.code === 200) {
setUserEquipmentCount({
count: response.data?.count || 0,
totalCount: response.data?.totalCount || 0,
countEnd: response.data?.countEnd || 0,
countExpire: response.data?.countExpire || 0
})
}
} catch (error) {
console.error('获取用户设备统计失败:', error)
} finally {
setLoadingUserEquipmentCount(false)
}
}
// 处理省份变化
const handleProvinceChange = (province: string) => {
setNewMerchant({
@@ -263,6 +290,7 @@ export default function MerchantsPage() {
useEffect(() => {
fetchUserRole()
fetchMerchants()
fetchUserEquipmentCount()
}, [])
const [newEquipment, setNewEquipment] = useState({
@@ -404,6 +432,18 @@ export default function MerchantsPage() {
if (merchant.province) {
fetchMalls(merchant.province)
}
// 加载总商户列表如果为空或者商户有总商户ID但列表中没有对应的项
if (!loadingTotalMerchants) {
if (totalMerchants.length === 0) {
fetchTotalMerchants()
} else if (merchant.totalMerchantId) {
// 如果商户有总商户ID但列表中找不到对应的项重新加载
const found = totalMerchants.find(tm => tm.userId === merchant.totalMerchantId)
if (!found) {
fetchTotalMerchants()
}
}
}
}
// 处理编辑省份变化
@@ -544,10 +584,18 @@ export default function MerchantsPage() {
<SelectValue placeholder="筛选状态" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
<SelectItem value="normal"></SelectItem>
<SelectItem value="expiring"></SelectItem>
<SelectItem value="expired"></SelectItem>
<SelectItem value="all">
{loadingUserEquipmentCount ? '' : `(${userEquipmentCount.totalCount})`}
</SelectItem>
<SelectItem value="normal">
{loadingUserEquipmentCount ? '' : `(${userEquipmentCount.count})`}
</SelectItem>
<SelectItem value="expiring">
{loadingUserEquipmentCount ? '' : `(${userEquipmentCount.countEnd})`}
</SelectItem>
<SelectItem value="expired">
{loadingUserEquipmentCount ? '' : `(${userEquipmentCount.countExpire})`}
</SelectItem>
</SelectContent>
</Select>
@@ -639,11 +687,9 @@ export default function MerchantsPage() {
<Eye className="h-4 w-4 mr-1" />
({merchant.equipmentCount})
</Button>
{userRole !== "merchant" && (
<Button variant="outline" size="sm" onClick={() => handleEditMerchant(merchant)}>
</Button>
)}
<Button variant="outline" size="sm" onClick={() => handleEditMerchant(merchant)}>
</Button>
</div>
</TableCell>
</TableRow>
@@ -679,11 +725,9 @@ export default function MerchantsPage() {
<Eye className="h-3 w-3 mr-1" />
{merchant.equipmentCount}
</Button>
{userRole !== "merchant" && (
<Button variant="outline" size="sm" onClick={() => handleEditMerchant(merchant)}>
<Edit className="h-4 w-4" />
</Button>
)}
<Button variant="outline" size="sm" onClick={() => handleEditMerchant(merchant)}>
<Edit className="h-4 w-4" />
</Button>
</div>
</div>
@@ -891,32 +935,36 @@ export default function MerchantsPage() {
placeholder="请输入联系电话"
/>
</div>
{userRole === "admin" && (
<div className="space-y-2">
<Label htmlFor="totalMerchant"></Label>
<Select
value={newMerchant.totalMerchant}
onValueChange={(value) => setNewMerchant({ ...newMerchant, totalMerchant: value })}
disabled={loadingTotalMerchants}
onOpenChange={(open) => {
if (open && totalMerchants.length === 0 && !loadingTotalMerchants) {
fetchTotalMerchants()
}
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={loadingTotalMerchants ? "加载中..." : "选择总商户(可选)"} />
</SelectTrigger>
<SelectContent className="max-h-[300px]">
{totalMerchants.map((merchant) => (
<div className="space-y-2">
<Label htmlFor="totalMerchant"></Label>
<Select
value={newMerchant.totalMerchant}
onValueChange={(value) => setNewMerchant({ ...newMerchant, totalMerchant: value })}
disabled={loadingTotalMerchants}
onOpenChange={(open) => {
if (open && totalMerchants.length === 0 && !loadingTotalMerchants) {
fetchTotalMerchants()
}
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={loadingTotalMerchants ? "加载中..." : "选择总商户(可选)"} />
</SelectTrigger>
<SelectContent className="max-h-[300px]">
{totalMerchants.length === 0 && !loadingTotalMerchants ? (
<SelectItem value="no-data" disabled>
</SelectItem>
) : (
totalMerchants.map((merchant) => (
<SelectItem key={merchant.userId} value={merchant.userId}>
{merchant.nickName}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}
))
)}
</SelectContent>
</Select>
</div>
<div className="col-span-2 space-y-2">
<Label htmlFor="detailedAddress"></Label>
<Textarea
@@ -1124,32 +1172,54 @@ export default function MerchantsPage() {
placeholder="请输入联系电话"
/>
</div>
{userRole === "admin" && (
<div className="space-y-2">
<Label htmlFor="edit-totalMerchant"></Label>
<Select
value={editMerchant.totalMerchant}
onValueChange={(value) => setEditMerchant({ ...editMerchant, totalMerchant: value })}
disabled={loadingTotalMerchants}
onOpenChange={(open) => {
if (open && totalMerchants.length === 0 && !loadingTotalMerchants) {
fetchTotalMerchants()
}
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={loadingTotalMerchants ? "加载中..." : "选择总商户(可选)"} />
</SelectTrigger>
<SelectContent className="max-h-[300px]">
{totalMerchants.map((merchant) => (
<SelectItem key={merchant.userId} value={merchant.userId}>
{merchant.nickName}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}
<div className="space-y-2">
<Label htmlFor="edit-totalMerchant"></Label>
<Select
value={editMerchant.totalMerchant || undefined}
onValueChange={(value) => {
if (value === "clear") {
setEditMerchant({ ...editMerchant, totalMerchant: "" })
} else {
setEditMerchant({ ...editMerchant, totalMerchant: value })
}
}}
disabled={loadingTotalMerchants}
onOpenChange={(open) => {
if (open && totalMerchants.length === 0 && !loadingTotalMerchants) {
fetchTotalMerchants()
}
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={loadingTotalMerchants ? "加载中..." : editMerchant.totalMerchant ? "已选择总商户" : "选择总商户(可选)"} />
</SelectTrigger>
<SelectContent className="max-h-[300px]">
{editMerchant.totalMerchant && !totalMerchants.find(tm => tm.userId === editMerchant.totalMerchant) && (
<SelectItem value={editMerchant.totalMerchant} disabled>
{editMerchant.totalMerchant} (...)
</SelectItem>
)}
{totalMerchants.length === 0 && !loadingTotalMerchants ? (
<SelectItem value="no-data" disabled>
{editMerchant.totalMerchant ? "当前值: " + editMerchant.totalMerchant : "点击加载总商户数据"}
</SelectItem>
) : (
<>
{editMerchant.totalMerchant && (
<SelectItem value="clear">
</SelectItem>
)}
{totalMerchants.map((merchant) => (
<SelectItem key={merchant.userId} value={merchant.userId}>
{merchant.nickName}
</SelectItem>
))}
</>
)}
</SelectContent>
</Select>
</div>
<div className="col-span-2 space-y-2">
<Label htmlFor="edit-detailedAddress"></Label>
<Textarea

View File

@@ -306,7 +306,7 @@ export default function WorkOrderArchivePage() {
<Eye className="h-4 w-4 mr-1" />
</Button>
{((order.equipmentName?.includes("厨房自动灭火") || order.equipmentName === "厨房自动灭火设备") && (order.workOrderType === "设备安装" || order.workOrderType === "设备检测" || order.workOrderType === "设备改造" || order.workOrderType === "设备维修" || order.workOrderType === "故障维修" || order.workOrderType === "设备拆除" || order.workOrderType === "更换药剂")) && (
{(order.workOrderType === "设备安装" || order.workOrderType === "设备检测" || order.workOrderType === "故障检测") && (
<Button variant="outline" size="sm" onClick={() => handleDownloadReport(order.workOrderNumber)}>
<FileDown className="h-4 w-4 mr-1" />
@@ -341,7 +341,7 @@ export default function WorkOrderArchivePage() {
<Eye className="h-3 w-3 mr-1" />
</Button>
{((order.equipmentName?.includes("厨房自动灭火") || order.equipmentName === "厨房自动灭火设备") && (order.workOrderType === "设备安装" || order.workOrderType === "设备检测" || order.workOrderType === "设备改造" || order.workOrderType === "设备维修" || order.workOrderType === "故障维修" || order.workOrderType === "设备拆除" || order.workOrderType === "更换药剂")) && (
{(order.workOrderType === "设备安装" || order.workOrderType === "设备检测" || order.workOrderType === "故障检测") && (
<Button variant="outline" size="sm" onClick={() => handleDownloadReport(order.workOrderNumber)} className="text-xs">
<FileDown className="h-3 w-3 mr-1" />