From e6255148a4d4ed8740e4658f2165edf664f965df Mon Sep 17 00:00:00 2001 From: menxipeng Date: Sun, 19 Oct 2025 13:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20xuanz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/pages/MerchantsPage.tsx | 280 ++++++++++++++++++++++--- 1 file changed, 252 insertions(+), 28 deletions(-) diff --git a/src/components/pages/MerchantsPage.tsx b/src/components/pages/MerchantsPage.tsx index 201b6e0..0a8072f 100644 --- a/src/components/pages/MerchantsPage.tsx +++ b/src/components/pages/MerchantsPage.tsx @@ -16,7 +16,7 @@ import { DialogTrigger, } from "../ui/dialog" import { Plus, Search, Filter, Download, Calendar, AlertTriangle, Store, Eye, Building2, MapPin } from "lucide-react" -import { apiPost, apiGet } from "../../lib/services/api" +import { apiGet, apiPost, apiPut } from "../../lib/services/api" // 总商户数据类型 interface TotalMerchant { @@ -61,6 +61,7 @@ export default function MerchantsPage() { const [searchTerm, setSearchTerm] = useState("") const [statusFilter, setStatusFilter] = useState("all") const [isAddMerchantOpen, setIsAddMerchantOpen] = useState(false) + const [isEditMerchantOpen, setIsEditMerchantOpen] = useState(false) const [isAddEquipmentOpen, setIsAddEquipmentOpen] = useState(false) const [selectedMerchant, setSelectedMerchant] = useState(null) const [isEquipmentDialogOpen, setIsEquipmentDialogOpen] = useState(false) @@ -90,6 +91,20 @@ export default function MerchantsPage() { detailedAddress: "", }) + const [editMerchant, setEditMerchant] = useState({ + id: "", + name: "", + contact: "", + phone: "", + mall: "", + mallUserId: "", + totalMerchant: "", + province: "", + businessLicense: "", + businessType: "", + detailedAddress: "", + }) + const [isSubmitting, setIsSubmitting] = useState(false) // 获取用户角色 @@ -362,6 +377,102 @@ export default function MerchantsPage() { } } + // 打开编辑对话框 + const handleEditMerchant = (merchant: any) => { + setEditMerchant({ + id: merchant.id, + name: merchant.merchantName || "", + contact: merchant.contactPerson || "", + phone: merchant.contactPhone || "", + mall: merchant.mallId || "", + mallUserId: merchant.mallUserId || "", + totalMerchant: merchant.totalMerchantId || "", + province: merchant.province || "", + businessLicense: merchant.businessLicenseNo || "", + businessType: merchant.businessType || "", + detailedAddress: merchant.detailedAddress || "", + }) + setIsEditMerchantOpen(true) + // 加载省份和商场数据 + if (provinces.length === 0) { + fetchProvinces() + } + if (merchant.province) { + fetchMalls(merchant.province) + } + } + + // 处理编辑省份变化 + const handleEditProvinceChange = (province: string) => { + setEditMerchant({ + ...editMerchant, + province: province, + mall: "", + mallUserId: "" + }) + if (province) { + fetchMalls(province) + } else { + setMalls([]) + } + } + + // 提交编辑 + const handleUpdateMerchant = async () => { + if (!editMerchant.name || !editMerchant.contact || !editMerchant.phone) { + alert('请填写必填信息') + return + } + + setIsSubmitting(true) + + try { + const selectedProvince = provinces.find(p => p.code === editMerchant.province) + const provinceName = selectedProvince ? selectedProvince.name : "" + const fullAddress = `${provinceName}${editMerchant.detailedAddress}` + + const merchantData = { + id: editMerchant.id, + merchantName: editMerchant.name, + businessType: editMerchant.businessType, + contactPerson: editMerchant.contact, + contactPhone: editMerchant.phone, + mallId: editMerchant.mall || "", + mallUserId: editMerchant.mallUserId || "", + mallLocation: "", + dealerId: "", + totalMerchantId: editMerchant.totalMerchant || "", + isTotal: editMerchant.totalMerchant ? 1 : 2, + businessLicenseNo: editMerchant.businessLicense, + province: editMerchant.province, + city: "", + district: "", + detailedAddress: editMerchant.detailedAddress, + fullAddress: fullAddress, + status: 1 + } + + console.log("编辑商户:", merchantData) + + const result = await apiPut('/back/merchants/', merchantData) + + if (result.code === 200) { + console.log('编辑商户成功:', result) + alert('编辑商户成功!') + setIsEditMerchantOpen(false) + fetchMerchants() + } else { + console.error('编辑商户失败:', result) + alert('编辑商户失败:' + (result.msg || '未知错误')) + } + } catch (error) { + console.error('编辑商户请求失败:', error) + alert('网络错误,请稍后重试') + } finally { + setIsSubmitting(false) + } + } + // 打开设备对话框 const handleViewEquipment = (merchant: any) => { setSelectedMerchant(merchant) @@ -582,7 +693,7 @@ export default function MerchantsPage() { 查看设备({merchant.equipmentCount}) {userRole !== "merchant" && ( - )} @@ -675,23 +786,6 @@ export default function MerchantsPage() { placeholder="请输入商户名称" /> -
- - -
-
- - setNewMerchant({ ...newMerchant, businessLicense: e.target.value })} - placeholder="请输入营业执照号" - /> -