|
|
@ -1,26 +1,59 @@ |
|
|
|
import { NavBar, Picker } from 'antd-mobile'; |
|
|
|
import { NavBar, Picker, Toast } from 'antd-mobile'; |
|
|
|
import { useNavigate } from 'react-router'; |
|
|
|
import icon_arr_r from '../assets/icon_arr_s_r.svg'; |
|
|
|
// import { railTypes } from '../utils/constant';
|
|
|
|
import { ChangeEvent, useState } from 'react'; |
|
|
|
import { useAppSelector } from '../utils/hooks'; |
|
|
|
import { XB_CODES } from '../utils/constant'; |
|
|
|
import { selectLabeledKtjOrgs } from '../store/features/baseData'; |
|
|
|
import { textsOfKeys } from '../utils/helper'; |
|
|
|
import { SaveMeasureDTO } from '../services/apiTypes'; |
|
|
|
import Bridge from '../utils/bridge'; |
|
|
|
|
|
|
|
export default function MeasureSave() { |
|
|
|
const navigate = useNavigate(); |
|
|
|
const back = () => navigate(-1); |
|
|
|
|
|
|
|
const baseState = useAppSelector(state => state.baseData); |
|
|
|
const contextState = useAppSelector((state) => state.context); |
|
|
|
const baseState = useAppSelector((state) => state.baseData); |
|
|
|
const labeledKtjOrgs = useAppSelector((state) => selectLabeledKtjOrgs(state.baseData)); |
|
|
|
|
|
|
|
const [name, setName] = useState("") |
|
|
|
const [name, setName] = useState(''); |
|
|
|
const [railPickerVisible, setRailPickerVisible] = useState(false); |
|
|
|
const [railId, setRailId] = useState<(number | string | null)[]>([1]); |
|
|
|
// const [railId, setRailId] = useState<(number | string | null)[]>([1]);
|
|
|
|
const [directionCode, setDirectionCode] = useState<string[]>([XB_CODES[0].value]); |
|
|
|
|
|
|
|
const onInputChange = (evt: ChangeEvent<HTMLInputElement>) => { |
|
|
|
setName(evt.target.value) |
|
|
|
} |
|
|
|
setName(evt.target.value); |
|
|
|
}; |
|
|
|
const onSaveBtnClick = () => { |
|
|
|
console.log(name, railId) |
|
|
|
if (!name) { |
|
|
|
Toast.show('请输入测量名称'); |
|
|
|
return; |
|
|
|
} |
|
|
|
const railType = baseState.railTypes.find((r) => r.id === contextState.currRailTypeId); |
|
|
|
const [_, gwd, xm] = orgTextArr(); |
|
|
|
const dto: SaveMeasureDTO = { |
|
|
|
operatorName: '', |
|
|
|
trackShapeCode: railType!.code, |
|
|
|
name, |
|
|
|
lineName: xm, |
|
|
|
location: gwd, |
|
|
|
direction: directionCode[0], |
|
|
|
}; |
|
|
|
Bridge.saveMeasure(dto).then((res) => { |
|
|
|
if (res.success) { |
|
|
|
Toast.show('保存成功'); |
|
|
|
} else { |
|
|
|
Toast.show(res.message); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
function orgTextArr() { |
|
|
|
return textsOfKeys( |
|
|
|
[contextState.currOrgCode, contextState.currGWDCode, contextState.currXMCode], |
|
|
|
labeledKtjOrgs |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
@ -41,9 +74,9 @@ export default function MeasureSave() { |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div className="h-12 flex items-center " onClick={() => setRailPickerVisible(true)}> |
|
|
|
<span>轨型</span> |
|
|
|
<span>行别</span> |
|
|
|
<span className="ml-auto mr-4"> |
|
|
|
{baseState.railTypes.find((r) => r.id === railId[0])?.name || ''} |
|
|
|
{XB_CODES.find((r) => r.value === directionCode[0])?.label || ''} |
|
|
|
</span> |
|
|
|
<img src={icon_arr_r} alt="arr" /> |
|
|
|
</div> |
|
|
@ -57,14 +90,14 @@ export default function MeasureSave() { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<Picker |
|
|
|
columns={[baseState.railTypes.map((t) => ({ ...t, label: t.name, value: t.id }))]} |
|
|
|
columns={[XB_CODES]} |
|
|
|
visible={railPickerVisible} |
|
|
|
onClose={() => { |
|
|
|
setRailPickerVisible(false); |
|
|
|
}} |
|
|
|
value={railId} |
|
|
|
value={directionCode} |
|
|
|
onConfirm={(v) => { |
|
|
|
setRailId(v); |
|
|
|
setDirectionCode(v as string[]); |
|
|
|
}} |
|
|
|
/> |
|
|
|
</> |
|
|
|