diff --git a/components/apolloTable/component/base/_utils/setFormatter.tsx b/components/apolloTable/component/base/_utils/setFormatter.tsx index 9a6526ffa1288f301d1c74e36eef3a387d89fced..ebf34905cfcacfc8b896330746433b6b959c9056 100644 --- a/components/apolloTable/component/base/_utils/setFormatter.tsx +++ b/components/apolloTable/component/base/_utils/setFormatter.tsx @@ -185,4 +185,14 @@ export const SetFormatter = { } 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('-') }]; + }, }; diff --git a/components/apolloTable/component/base/config.tsx b/components/apolloTable/component/base/config.tsx index 7fb324a4d54d1f80b9c1b00aa061e4a2c6273935..aec65c43b78431d55f83f640205c40f00d3cc6c4 100644 --- a/components/apolloTable/component/base/config.tsx +++ b/components/apolloTable/component/base/config.tsx @@ -20,6 +20,7 @@ import { ApolloUpload, ApolloTextArea, ApolloDateRange, + ApolloRegion, } from './edit'; import { ApolloInputDetail, @@ -40,6 +41,7 @@ import { ApolloUploadDetail, ApolloDateRangeDetail, ApolloTextLinkDetail, + ApolloRegionDetail, } from './detail'; import CellContainer from './edit/container'; @@ -250,4 +252,12 @@ export const config: any = { detailComp: ApolloDateRangeDetail, icon: 'iconziduan-riqi', }, + 22: { + name: '地区选择控件', + editComp: ApolloRegion, + detailComp: ApolloRegionDetail, + setFormatter: SetFormatter.REGION, + // getFormatter: GetFormatter.REGION, + icon: 'iconziduan-lianxiangdanxuan', + }, }; diff --git a/components/apolloTable/component/base/detail/index.tsx b/components/apolloTable/component/base/detail/index.tsx index 20a46c0bf012c761bac7146b247fe17c2816fbb1..b8283dbc2a45077621a21808d3a89f143818a237 100644 --- a/components/apolloTable/component/base/detail/index.tsx +++ b/components/apolloTable/component/base/detail/index.tsx @@ -16,6 +16,7 @@ import { ApolloTreeSelectDetail } from './tree-select'; import { ApolloUploadDetail } from './upload'; import { ApolloDateRangeDetail } from './dateRange'; import { ApolloTextLinkDetail } from './text-link'; +import { ApolloRegionDetail } from './region'; export { ApolloInputDetail, @@ -36,4 +37,5 @@ export { ApolloUploadDetail, ApolloDateRangeDetail, ApolloTextLinkDetail, + ApolloRegionDetail, }; diff --git a/components/apolloTable/component/base/detail/region/index.less b/components/apolloTable/component/base/detail/region/index.less new file mode 100644 index 0000000000000000000000000000000000000000..59c3d5a2e683f6ee5e70fe80f67116810b591e0c --- /dev/null +++ b/components/apolloTable/component/base/detail/region/index.less @@ -0,0 +1,6 @@ +.text { + width: 100%; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} diff --git a/components/apolloTable/component/base/detail/region/index.tsx b/components/apolloTable/component/base/detail/region/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..13abd1d9e3eacd3e3adf9c74fdb6e1658f095184 --- /dev/null +++ b/components/apolloTable/component/base/detail/region/index.tsx @@ -0,0 +1,14 @@ +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
{text}
; + } + } + return '数据错误'; +}; diff --git a/components/apolloTable/component/base/edit/index.ts b/components/apolloTable/component/base/edit/index.ts index a86e78c2212f53c8d81eb3fa9f751f008e88a458..f25cedc89d37be53e9d845a42ed2a642cbaf67ba 100644 --- a/components/apolloTable/component/base/edit/index.ts +++ b/components/apolloTable/component/base/edit/index.ts @@ -15,6 +15,7 @@ import { ApolloTextArea } from './textarea'; import { ApolloTreeSelect } from './tree-select'; import { ApolloUpload } from './upload'; import { ApolloDateRange } from './dateRange'; +import ApolloRegion from './region'; export { ApolloInput, @@ -34,4 +35,5 @@ export { ApolloUpload, ApolloTextArea, ApolloDateRange, + ApolloRegion, }; diff --git a/components/apolloTable/component/base/edit/region/_utils.ts b/components/apolloTable/component/base/edit/region/_utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..2c7cf9ff538056e40dead97091557447da00504f --- /dev/null +++ b/components/apolloTable/component/base/edit/region/_utils.ts @@ -0,0 +1,24 @@ +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, + }; + }); +}; diff --git a/components/apolloTable/component/base/edit/region/index.tsx b/components/apolloTable/component/base/edit/region/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..22a73c09d99c3061267689e4a3ea6e13e3b17ecc --- /dev/null +++ b/components/apolloTable/component/base/edit/region/index.tsx @@ -0,0 +1,42 @@ +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 ( + + ); +}; +export default Picker; diff --git a/components/apolloTable/editFormV3/index.tsx b/components/apolloTable/editFormV3/index.tsx index 19248357adfb5c41214d7ba07d992f0a2d1b9e9d..348fc1096dd5892271014f88351428acf04f3b4e 100644 --- a/components/apolloTable/editFormV3/index.tsx +++ b/components/apolloTable/editFormV3/index.tsx @@ -29,14 +29,15 @@ class FormWrap extends Component { form.validateFieldsAndScroll((err, values) => { if (!err) { const newValues: any[] = []; + debugger _.keys(values).map((key) => { const item = data.find((temp: any) => { return temp.columnName === key; }); const { columnType, renderEditForm, readOnlyFlag, dynamicCellConfigDTO } = item; - if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) { - return; - } + // if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) { + // return; + // } let detailConfig: any; if (typeof renderEditForm === 'function') { detailConfig = renderEditForm({ cellData: values[key], rowData, columnConfig: item });