/* eslint-disable array-callback-return */ import { Button, Form, Input, message, Select, InputNumber } from "antd"; import { useEffect, useState } from "react"; import { useNavigate } from "react-router"; import { saveMeasurement_new } from "../../../services/measure/analysis"; import { useAppSelector } from "../../../utils/hooks"; import { getOrgListService, dictionaryListService, queryStationData } from "../../../services/ktj/org"; import { useAppDispatch } from "../../../utils/hooks"; import { setOrgData } from "../../../store/ktj/orgState"; import type { OrgItem, GwdDicItem, KTJ_BASE_TYPE, options, dataSourceOptions, unitTypesOptions, unitType, extraDescType } from "../../../services/ktjTypes"; import { RAIN_TYPES, XB_CODES, DATA_SOURCE } from "../../../constant/index"; import "./MeasureAction.scss"; export default function MeasureConfig() { const { Option } = Select; const navigate = useNavigate(); const systemState = useAppSelector((store) => store.systemState); const [messageApi, contextHolder] = message.useMessage(); const dispatch = useAppDispatch(); const measureState = useAppSelector((store) => store.measureState); const [extraDesc, setExtraDesc] = useState() const onFinish = (values: any) => { let mtValue = values["meters"] //百米小于100时, 补齐3位。 比如 1 :"001", 10: "010" if (mtValue < 100) { mtValue = String(mtValue).padStart(3, '0'); } const params = { operator: values["operator"],//操作员 name: values["name"],//测量名称 location: values["location"],//位置 direction: values["direction"],//方向 tljCode: values["tljCode"],//铁路局 gwdCode: values["gwdCode"],//铁路段 xmCode: values["xmCode"],//铁路线 lineClassify: values["lineClassify"],//线路分类 dataType: values["dataType"],//采集方式 dataSource: values["dataSource"],//数据来源 railSize: values["railSize"],//轨型 xbCode: values["xbCode"],//行别 unitType: values["unitType"],//股别 mileage: `${values['kilometre']}+${mtValue}`,//里程 stationCode: values['stationCode'],//车站 batch: values['batch'],//批次 radius: values["radius"],//半径 turnoutNum: values["turnoutNum"],//道岔号 sleeperNum: values["sleeperNum"],//枕木号 extraDesc:JSON.stringify(extraDesc), alignPoints:[] }; const orgItem = { tljCode: values["tljCode"],//铁路局 gwdCode: values["gwdCode"],//铁路段 xmCode: values["xmCode"],//铁路线 } localStorage.setItem('orgInfo', JSON.stringify(orgItem)); params.extraDesc = JSON.stringify(extraDesc) let measureData = measureState.measureData; if(measureData && measureData.length){ params.alignPoints = measureData } localStorage.setItem('measureForm', JSON.stringify(params)) saveMeasurement_new(params) .then((res) => { if (res.success) { messageApi.error(res.data.info); } else { message.success("保存成功"); navigate("../action"); } }) .catch((e) => { navigate("../action"); }); }; let user = localStorage.getItem("user") || ""; let userInfo = (user && JSON.parse(user)) || {}; const [form] = Form.useForm(); useEffect(() => { queryKTJOrgList(); queryDictionaryList(); resetDataSource() resetRailTypes() }, []); useEffect(()=>{ }, [measureState.measureData]) //给股别分类 const [unitTypeList, setUnitTypeList] = useState([]) const resetRailTypes = () => { let zxOptions:unitTypesOptions = { label:'直线', options:[] } let qxOptions:unitTypesOptions = { label:'曲线', options:[] } let zxList:unitType[] = [] let qxList:unitType[] = [] RAIN_TYPES.map(item => { if(item.type === 1){ zxList.push({ label: item.name, value: item.code, }) }else{ qxList.push({ label: item.name, value: item.code, }) } }) zxOptions.options = zxList qxOptions.options = qxList setUnitTypeList([zxOptions, qxOptions]) } const [xbCodeOptions, setXbCodeOptions] = useState() const resetDataSource = () => { let options:dataSourceOptions[] = [] DATA_SOURCE.map(item => { let optionMap:any = { label: item.name, value: item.code, options:[] } let childOptions:options[] = [] item.child.map(ele => { childOptions.push({ label: ele.name, value: ele.code }) optionMap.options = childOptions }) options.push(optionMap) }) setXbCodeOptions(options) } //初始化科天健机构数据 let [SJLY_List, setSJLYList] = useState([]); let [WRPS_CJFS_List, setWRPSCJFSList] = useState([]); let [WRPS_GGGX_List, setWRPSGGGXList] = useState([]); let [XLFL_List, setXLFLList] = useState([]); const queryDictionaryList = () => { dictionaryListService().then((res) => { if (res && res.data) { const { WRPS_CJFS, WRPS_GGGX, XLFL } = res.data; const SJLY:KTJ_BASE_TYPE[] = res.data.SJLY if(SJLY && SJLY.length){ let sjlylist = SJLY.filter(item => item.key === 'XLDC' || item.key === 'DCDC') setSJLYList(sjlylist); } if(WRPS_CJFS && WRPS_CJFS.length){ setWRPSCJFSList(WRPS_CJFS); } if(WRPS_GGGX && WRPS_GGGX.length){ setWRPSGGGXList(WRPS_GGGX); } if(XLFL && XLFL.length){ setXLFLList(XLFL); } } }); }; //获取机构数据 const [KTJOrgList, setKTJOrgList] = useState([]); const queryKTJOrgList = () => { getOrgListService() .then((res) => { let list: options[] = []; if (res && res.data) { let resData: OrgItem[] = res.data; setKTJOrgList(resData); dispatch(setOrgData(resData)); resData.map((item) => { list.push({ value: item.key, label: item.value, }); }); } }) .catch((e) => {}); }; //选择机构时change const [gwdDicList, setGwdDicList] = useState([]); const [gwdCodeValue, setGwdCodeValue] = useState(); const [xmCodeValue, setXmCodeValue] = useState(); const [gwdDicOptions, setGwdDicOptions] = useState([]); const [railDicOptions, setRailDicOptions] = useState([]); const [orgGwdDicList, setOrgGwdDicList] = useState([]) const onOrgChange = (value: string, option:any) => { let list = KTJOrgList.filter((item) => item.key === value); form.resetFields(["gwdCode", "xmCode"]); if (list && list.length) { let orgItem: OrgItem = list[0]; setExtraDesc({...extraDesc,orgName:option.label}) if (orgItem && orgItem.gwdDicList) { let listOptoins: options[] = []; setGwdDicList(orgItem.gwdDicList); setOrgGwdDicList(orgItem.gwdDicList) orgItem.gwdDicList.map((item) => { listOptoins.push({ value: item.key, label: item.value, }); }); setGwdDicOptions(listOptoins); setGwdCodeValue(listOptoins[0].value); } } }; const onGwdChange = (value: string, option:any) => { let cloneGwdDicList = [...orgGwdDicList]; form.resetFields(["xmCode"]); let list = cloneGwdDicList.filter((item) => item.key === value); if (list && list.length) { let gwdDicItem: GwdDicItem = list[0]; setExtraDesc({...extraDesc,gwdName:option.label}) if (gwdDicItem && gwdDicItem.railDicList) { let railOptions: options[] = []; gwdDicItem.railDicList.map((item) => { railOptions.push({ value: item.key, label: item.value, }); }); if(railOptions && railOptions.length){ setRailDicOptions(railOptions); setXmCodeValue(railOptions[0].value); } } } }; //车站数据 const [stationList, setStationList] = useState([]) const queryStation = (value:string, option:any) => { form.resetFields(["stationCode"]); let tljCode = form.getFieldValue("tljCode") let gwdCode = form.getFieldValue("gwdCode") let xmCode = form.getFieldValue("xmCode") const params = { tljCode, gwdCode, xmCode } setExtraDesc({...extraDesc,xmName:option.label}) queryStationData(params).then(res => { if(res && res.data){ setStationList(res.data) }else{ setStationList([]) } const measureForm = localStorage.getItem('measureForm') if (measureForm) { form.setFieldsValue({ ...JSON.parse(measureForm) }); } }) } useEffect(()=>{ if(systemState.orgInfo){ const cloneOrgItem = systemState.orgInfo if(cloneOrgItem.value){ const org = JSON.parse(cloneOrgItem.value) onOrgChange(org[0].value, org[0]) onGwdChange(org[1].value, org[1]) form.setFieldsValue({ tljCode:org[0].value, gwdCode: org[1].value, xmCode: org[2].value }); queryStation(org[2].value, org[2]) } } },[KTJOrgList, xmCodeValue, gwdCodeValue, systemState.orgInfo]) useEffect(()=>{ if(systemState.accountInfo){ const cloneAccountItem = systemState.accountInfo if(cloneAccountItem.value){ form.setFieldsValue({ operator:cloneAccountItem.value }) } } },[systemState.accountInfo]) const onRailTypeChange = (value:string, option:any) => { setExtraDesc({...extraDesc,railSizeName:option.label}) } //数据来源change const [dataSource, setDataSource] = useState('') const onDataSourceChange = (value:string, option:any) => { setExtraDesc({...extraDesc,dataSourceName:option.label}) form.resetFields(["xbCode"]); setDataSource(value) } //车站 const onSatioinChange = (value:string, option:any) => { setExtraDesc({...extraDesc,stationName:option.label}) } //股别change const [unitType, setUnitType] = useState() const onUnitTypeChange = (value:string) => { RAIN_TYPES.map(item => { if(item.code === value){ setUnitType(item.type) } }) } useEffect(() => { const initData = { operator: "klj_test", direction: "左", } form.setFieldsValue(initData); }, [userInfo.nickname, form]); return ( <> {contextHolder}
{/* ) : ( )} {dataSource === "XLDC" &&
+
} {unitType === 2 && }
); }