Commit 2663914e authored by 满振华's avatar 满振华

修改数据

parent ba12ccad
...@@ -185,4 +185,14 @@ export const SetFormatter = { ...@@ -185,4 +185,14 @@ export const SetFormatter = {
} }
return val; return val;
}, },
REGION: (val) => {
if (!val || !Array.isArray(val)) return val;
const textArr: any = [];
const valueArr: any = [];
val.forEach((ls: any) => {
textArr.push(ls.label);
valueArr.push(ls.value);
});
return [{ text: textArr.filter((ls) => { return ls; }).join('-'), value: valueArr.filter((ls) => { return ls; }).join('-') }];
},
}; };
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
ApolloUpload, ApolloUpload,
ApolloTextArea, ApolloTextArea,
ApolloDateRange, ApolloDateRange,
ApolloRegion,
} from './edit'; } from './edit';
import { import {
ApolloInputDetail, ApolloInputDetail,
...@@ -40,6 +41,7 @@ import { ...@@ -40,6 +41,7 @@ import {
ApolloUploadDetail, ApolloUploadDetail,
ApolloDateRangeDetail, ApolloDateRangeDetail,
ApolloTextLinkDetail, ApolloTextLinkDetail,
ApolloRegionDetail,
} from './detail'; } from './detail';
import CellContainer from './edit/container'; import CellContainer from './edit/container';
...@@ -250,4 +252,12 @@ export const config: any = { ...@@ -250,4 +252,12 @@ export const config: any = {
detailComp: ApolloDateRangeDetail, detailComp: ApolloDateRangeDetail,
icon: 'iconziduan-riqi', icon: 'iconziduan-riqi',
}, },
22: {
name: '地区选择控件',
editComp: ApolloRegion,
detailComp: ApolloRegionDetail,
setFormatter: SetFormatter.REGION,
// getFormatter: GetFormatter.REGION,
icon: 'iconziduan-lianxiangdanxuan',
},
}; };
...@@ -16,6 +16,7 @@ import { ApolloTreeSelectDetail } from './tree-select'; ...@@ -16,6 +16,7 @@ import { ApolloTreeSelectDetail } from './tree-select';
import { ApolloUploadDetail } from './upload'; import { ApolloUploadDetail } from './upload';
import { ApolloDateRangeDetail } from './dateRange'; import { ApolloDateRangeDetail } from './dateRange';
import { ApolloTextLinkDetail } from './text-link'; import { ApolloTextLinkDetail } from './text-link';
import { ApolloRegionDetail } from './region';
export { export {
ApolloInputDetail, ApolloInputDetail,
...@@ -36,4 +37,5 @@ export { ...@@ -36,4 +37,5 @@ export {
ApolloUploadDetail, ApolloUploadDetail,
ApolloDateRangeDetail, ApolloDateRangeDetail,
ApolloTextLinkDetail, ApolloTextLinkDetail,
ApolloRegionDetail,
}; };
.text {
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
import React from 'react';
import styles from './index.less';
export const ApolloRegionDetail = (props) => {
const { value } = props;
if (typeof value === 'object') {
if (Array.isArray(value)) {
const text = value[0] && value[0].text;
return <div className={styles.text}>{text}</div>;
}
}
return '数据错误';
};
...@@ -15,6 +15,7 @@ import { ApolloTextArea } from './textarea'; ...@@ -15,6 +15,7 @@ import { ApolloTextArea } from './textarea';
import { ApolloTreeSelect } from './tree-select'; import { ApolloTreeSelect } from './tree-select';
import { ApolloUpload } from './upload'; import { ApolloUpload } from './upload';
import { ApolloDateRange } from './dateRange'; import { ApolloDateRange } from './dateRange';
import ApolloRegion from './region';
export { export {
ApolloInput, ApolloInput,
...@@ -34,4 +35,5 @@ export { ...@@ -34,4 +35,5 @@ export {
ApolloUpload, ApolloUpload,
ApolloTextArea, ApolloTextArea,
ApolloDateRange, ApolloDateRange,
ApolloRegion,
}; };
export const getCityOps = ([pId, cityId, countyId]: any, citys) => {
const priviceObj = citys.find((ls: any) => { return ls.value === pId; }) || {};
const cityObj = (priviceObj.children || []).find((ls: any) => { return ls.value === cityId; }) || {};
const countryObj = (cityObj.children || []).find((ls: any) => { return ls.value === countyId; }) || {};
return [priviceObj, cityObj, countryObj].filter((ls: any) => { return ls && ls.value; }).map((ls) => { return { value: ls.code, label: ls.label }; });
};
export const formateCity = (arr: any) => {
if (!arr || arr.length === 0) return [];
return arr.map((ls: any) => {
if (ls.cityList || ls.areaList) {
return {
...ls,
label: ls.name,
value: ls.code,
children: formateCity(ls.cityList || ls.areaList),
};
}
return {
...ls,
label: ls.name,
value: ls.code,
};
});
};
import React, { useState, useEffect } from 'react';
import { Cascader } from 'antd';
import { getCitys } from '@/services/api';
import { formateCity, getCityOps } from './_utils';
const formateVal = (value) => {
if (!Array.isArray(value)) return [];
return value.map((ls) => { return ls.value; });
};
const Picker = (props) => {
const [citys, saveCitys] = useState([]);
const [val, saveVal] = useState(formateVal(props.value));
useEffect(() => { saveVal(formateVal(props.value)); }, [props.value]);
const getAllCity = async () => {
if (citys && citys.length > 0) return;
let city = await getCitys();
city = Array.isArray(city) ? city : [];
city = formateCity(city);
saveCitys(city);
};
const onChange = (v) => {
const val = getCityOps(v, citys);
if (props.onChange) {
props.onChange(val);
}
};
const onFocus = () => {
getAllCity();
};
return (
<Cascader
placeholder="请选择"
{...props}
value={val}
options={citys}
onChange={onChange}
onFocus={onFocus}
/>
);
};
export default Picker;
...@@ -29,14 +29,15 @@ class FormWrap extends Component { ...@@ -29,14 +29,15 @@ class FormWrap extends Component {
form.validateFieldsAndScroll((err, values) => { form.validateFieldsAndScroll((err, values) => {
if (!err) { if (!err) {
const newValues: any[] = []; const newValues: any[] = [];
debugger
_.keys(values).map((key) => { _.keys(values).map((key) => {
const item = data.find((temp: any) => { const item = data.find((temp: any) => {
return temp.columnName === key; return temp.columnName === key;
}); });
const { columnType, renderEditForm, readOnlyFlag, dynamicCellConfigDTO } = item; const { columnType, renderEditForm, readOnlyFlag, dynamicCellConfigDTO } = item;
if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) { // if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) {
return; // return;
} // }
let detailConfig: any; let detailConfig: any;
if (typeof renderEditForm === 'function') { if (typeof renderEditForm === 'function') {
detailConfig = renderEditForm({ cellData: values[key], rowData, columnConfig: item }); detailConfig = renderEditForm({ cellData: values[key], rowData, columnConfig: item });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment