| | |
| | | |
| | | const defaultPair = () => ({ stationName: '', stationId: '' }); |
| | | |
| | | const BasStationInitModal = ({ open, setOpen }) => { |
| | | const BasStationInitModal = ({ open, setOpen, initialData = null, onClose }) => { |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | |
| | | request.post('/dictData/page', { dictTypeCode: 'sys_container_type', current: 1, pageSize: 100 }) |
| | | .then((res) => { |
| | | if (res?.data?.code === 200 && res?.data?.data?.records) { |
| | | setContainerTypeOptions(res.data.data.records.map((item) => ({ |
| | | const options = res.data.data.records.map((item) => ({ |
| | | id: item.id, |
| | | value: item.value, |
| | | label: item.label ?? item.value ?? item.id, |
| | | }))); |
| | | })); |
| | | setContainerTypeOptions(options); |
| | | if (initialData?.common?.containerTypes?.length) { |
| | | const list = initialData.common.containerTypes; |
| | | const mapped = list.map((item) => { |
| | | const byId = options.find((o) => Number(o.id) === Number(item) || String(o.id) === String(item)); |
| | | if (byId) return String(byId.value); |
| | | const byVal = options.find((o) => String(o.value) === String(item) || o.value == item); |
| | | if (byVal) return String(byVal.value); |
| | | return item; |
| | | }); |
| | | setCommon((prev) => ({ ...prev, containerTypes: mapped })); |
| | | } |
| | | } |
| | | }) |
| | | .catch(() => {}); |
| | | }, [open]); |
| | | |
| | | useEffect(() => { |
| | | if (!open) return; |
| | | if (initialData?.pairs?.length) { |
| | | setPairs(initialData.pairs); |
| | | } |
| | | if (initialData?.common) { |
| | | setCommon({ |
| | | type: initialData.common.type ?? 0, |
| | | useStatus: initialData.common.useStatus ?? '', |
| | | areaIds: Array.isArray(initialData.common.areaIds) ? [...initialData.common.areaIds] : [], |
| | | containerTypes: Array.isArray(initialData.common.containerTypes) ? [...initialData.common.containerTypes] : [], |
| | | inAble: initialData.common.inAble ?? 0, |
| | | outAble: initialData.common.outAble ?? 0, |
| | | }); |
| | | } |
| | | }, [open, initialData]); |
| | | const handleClose = (event, reason) => { |
| | | if (reason !== "backdropClick") { |
| | | setOpen(false); |
| | | setPairs([defaultPair()]); |
| | | if (typeof onClose === 'function') onClose(); |
| | | } |
| | | }; |
| | | |
| | |
| | | type: common.type, |
| | | useStatus: common.useStatus || undefined, |
| | | areaIds: common.areaIds, |
| | | containerTypes: common.containerTypes, |
| | | inAble: common.inAble, |
| | | outAble: common.outAble, |
| | | containerTypes: (common.containerTypes || []).map((v) => Number(v)), |
| | | inAble: Number(common.inAble), |
| | | outAble: Number(common.outAble), |
| | | }; |
| | | try { |
| | | const res = await request.post('/basStation/save', body); |
| | |
| | | onChange={(e) => setCommon((c) => ({ ...c, containerTypes: e.target.value }))} |
| | | renderValue={(selected) => |
| | | (selected || []) |
| | | .map((id) => containerTypeOptions.find((c) => c.id === id)?.label ?? id) |
| | | .map((val) => containerTypeOptions.find((c) => String(c.value) === String(val))?.label ?? val) |
| | | .join(', ') |
| | | } |
| | | > |
| | | {containerTypeOptions.map((opt) => ( |
| | | <MenuItem key={opt.id} value={opt.id}> |
| | | <MenuItem key={opt.value} value={opt.value}> |
| | | {opt.label} |
| | | </MenuItem> |
| | | ))} |