工单类型
This commit is contained in:
@@ -640,7 +640,7 @@ function CreateWorkOrderForm({ onClose }: { onClose: () => void }) {
|
|||||||
const handleMerchantChange = (merchantId: string) => {
|
const handleMerchantChange = (merchantId: string) => {
|
||||||
console.log('选择商户,ID:', merchantId)
|
console.log('选择商户,ID:', merchantId)
|
||||||
setSelectedMerchant(merchantId)
|
setSelectedMerchant(merchantId)
|
||||||
setFormData({ ...formData, merchantId, equipmentId: "" })
|
setFormData({ ...formData, merchantId, equipmentId: "", type: "" })
|
||||||
|
|
||||||
// 找到选中的商户对象,使用 merchantsId 来获取设备列表
|
// 找到选中的商户对象,使用 merchantsId 来获取设备列表
|
||||||
const selectedMerchantObj = merchants.find(m => m.id === merchantId)
|
const selectedMerchantObj = merchants.find(m => m.id === merchantId)
|
||||||
@@ -652,6 +652,40 @@ function CreateWorkOrderForm({ onClose }: { onClose: () => void }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理设备变化
|
||||||
|
const handleEquipmentChange = (equipmentId: string) => {
|
||||||
|
setFormData({ ...formData, equipmentId, type: "" })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据设备类型获取可用的工单类型
|
||||||
|
const getAvailableWorkOrderTypes = () => {
|
||||||
|
if (!formData.equipmentId) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedEquipment = availableEquipment.find(e => e.equipmentId === formData.equipmentId)
|
||||||
|
if (!selectedEquipment) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const equipmentType = selectedEquipment.equipmentType
|
||||||
|
|
||||||
|
console.log('选择的设备类型:', equipmentType)
|
||||||
|
|
||||||
|
// 厨房自动灭火设备 - kitchen_automatic_fire_extinguisher
|
||||||
|
if (equipmentType === "kitchen_automatic_fire_extinguisher" || equipmentType === "厨房自动灭火设备") {
|
||||||
|
return ["故障检测", "故障维修", "设备安装", "预防性维护", "设备改造", "设备拆除", "更换药剂"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动火离人 - fire_extinguisher
|
||||||
|
if (equipmentType === "fire_extinguisher" || equipmentType === "动火离人") {
|
||||||
|
return ["故障维修", "设备安装", "设备改造", "设备拆除"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认返回所有类型
|
||||||
|
return ["故障检测", "故障维修", "设备安装", "预防性维护", "设备改造", "设备拆除", "更换药剂"]
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
@@ -746,7 +780,7 @@ function CreateWorkOrderForm({ onClose }: { onClose: () => void }) {
|
|||||||
<Label htmlFor="equipment">选择设备</Label>
|
<Label htmlFor="equipment">选择设备</Label>
|
||||||
<Select
|
<Select
|
||||||
value={formData.equipmentId}
|
value={formData.equipmentId}
|
||||||
onValueChange={(value) => setFormData({ ...formData, equipmentId: value })}
|
onValueChange={handleEquipmentChange}
|
||||||
disabled={!selectedMerchant || loadingEquipment}
|
disabled={!selectedMerchant || loadingEquipment}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
@@ -775,15 +809,26 @@ function CreateWorkOrderForm({ onClose }: { onClose: () => void }) {
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="type">工单类型</Label>
|
<Label htmlFor="type">工单类型</Label>
|
||||||
<Select value={formData.type} onValueChange={(value) => setFormData({ ...formData, type: value })}>
|
<Select
|
||||||
|
value={formData.type}
|
||||||
|
onValueChange={(value) => setFormData({ ...formData, type: value })}
|
||||||
|
disabled={!formData.equipmentId}
|
||||||
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className="w-full">
|
||||||
<SelectValue placeholder="选择类型" />
|
<SelectValue placeholder={
|
||||||
|
!formData.equipmentId
|
||||||
|
? "请先选择设备"
|
||||||
|
: getAvailableWorkOrderTypes().length === 0
|
||||||
|
? "无可用工单类型"
|
||||||
|
: "选择类型"
|
||||||
|
} />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent className="max-h-[300px]">
|
<SelectContent className="max-h-[300px]">
|
||||||
<SelectItem value="设备检测">设备检测</SelectItem>
|
{getAvailableWorkOrderTypes().map((type) => (
|
||||||
<SelectItem value="故障维修">故障维修</SelectItem>
|
<SelectItem key={type} value={type}>
|
||||||
<SelectItem value="设备安装">设备安装</SelectItem>
|
{type}
|
||||||
<SelectItem value="预防性维护">预防性维护</SelectItem>
|
</SelectItem>
|
||||||
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user