修复 xuanz
This commit is contained in:
@@ -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<any>(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})
|
||||
</Button>
|
||||
{userRole !== "merchant" && (
|
||||
<Button variant="outline" size="sm">
|
||||
<Button variant="outline" size="sm" onClick={() => handleEditMerchant(merchant)}>
|
||||
编辑
|
||||
</Button>
|
||||
)}
|
||||
@@ -675,23 +786,6 @@ export default function MerchantsPage() {
|
||||
placeholder="请输入商户名称"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="businessType">业务类型</Label>
|
||||
<Select
|
||||
value={newMerchant.businessType}
|
||||
onValueChange={(value) => setNewMerchant({ ...newMerchant, businessType: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="选择业务类型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="restaurant">餐饮</SelectItem>
|
||||
<SelectItem value="retail">零售</SelectItem>
|
||||
<SelectItem value="entertainment">娱乐</SelectItem>
|
||||
<SelectItem value="service">服务</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="contact">联系人</Label>
|
||||
<Input
|
||||
@@ -734,15 +828,6 @@ export default function MerchantsPage() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="businessLicense">营业执照号</Label>
|
||||
<Input
|
||||
id="businessLicense"
|
||||
value={newMerchant.businessLicense}
|
||||
onChange={(e) => setNewMerchant({ ...newMerchant, businessLicense: e.target.value })}
|
||||
placeholder="请输入营业执照号"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-2 space-y-2">
|
||||
<Label htmlFor="detailedAddress">详细地址</Label>
|
||||
<Textarea
|
||||
@@ -862,6 +947,145 @@ export default function MerchantsPage() {
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 编辑商户对话框 */}
|
||||
<Dialog open={isEditMerchantOpen} onOpenChange={setIsEditMerchantOpen}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑商户</DialogTitle>
|
||||
<DialogDescription>修改商户基本信息和地址详情</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-province">选择省份</Label>
|
||||
<Select
|
||||
value={editMerchant.province}
|
||||
onValueChange={handleEditProvinceChange}
|
||||
disabled={loadingProvinces}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={loadingProvinces ? "加载中..." : "选择省份"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{provinces.map((province) => (
|
||||
<SelectItem key={province.code} value={province.code}>
|
||||
{province.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-mall">所属商场(可选)</Label>
|
||||
<Select
|
||||
value={editMerchant.mallUserId}
|
||||
onValueChange={(value) => {
|
||||
const selectedMall = malls.find(mall => mall.mallUser === value)
|
||||
setEditMerchant({
|
||||
...editMerchant,
|
||||
mall: selectedMall?.mallId || value,
|
||||
mallUserId: value
|
||||
})
|
||||
}}
|
||||
disabled={loadingMalls || !editMerchant.province}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={
|
||||
!editMerchant.province
|
||||
? "请先选择省份"
|
||||
: loadingMalls
|
||||
? "加载中..."
|
||||
: "选择商场(可选)"
|
||||
} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{malls.map((mall) => (
|
||||
<SelectItem key={mall.mallUser || mall.id} value={mall.mallUser}>
|
||||
{mall.mallName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-name">商户名称</Label>
|
||||
<Input
|
||||
id="edit-name"
|
||||
value={editMerchant.name}
|
||||
onChange={(e) => setEditMerchant({ ...editMerchant, name: e.target.value })}
|
||||
placeholder="请输入商户名称"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-contact">联系人</Label>
|
||||
<Input
|
||||
id="edit-contact"
|
||||
value={editMerchant.contact}
|
||||
onChange={(e) => setEditMerchant({ ...editMerchant, contact: e.target.value })}
|
||||
placeholder="请输入联系人姓名"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-phone">联系电话</Label>
|
||||
<Input
|
||||
id="edit-phone"
|
||||
value={editMerchant.phone}
|
||||
onChange={(e) => setEditMerchant({ ...editMerchant, phone: e.target.value })}
|
||||
placeholder="请输入联系电话"
|
||||
/>
|
||||
</div>
|
||||
<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>
|
||||
<SelectValue placeholder={loadingTotalMerchants ? "加载中..." : "选择总商户(可选)"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{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
|
||||
id="edit-detailedAddress"
|
||||
value={editMerchant.detailedAddress}
|
||||
onChange={(e) => setEditMerchant({ ...editMerchant, detailedAddress: e.target.value })}
|
||||
placeholder="请输入详细地址"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end space-x-2 mt-6">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsEditMerchantOpen(false)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleUpdateMerchant}
|
||||
disabled={!editMerchant.name || !editMerchant.contact || !editMerchant.phone || isSubmitting}
|
||||
>
|
||||
{isSubmitting ? '更新中...' : '更新商户'}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 设备详情对话框 */}
|
||||
<Dialog open={isEquipmentDialogOpen} onOpenChange={setIsEquipmentDialogOpen}>
|
||||
<DialogContent className="!w-[1400px] !max-w-[1400px] max-h-[800px] overflow-hidden flex flex-col">
|
||||
|
Reference in New Issue
Block a user