1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, {useMemo, Component} from 'react';
import {List, Picker} from 'antd-mobile';
import styles from './styles.less';
const getItemChildren = (childrenList, parent) => {
if (!childrenList || !childrenList.length) {
return [];
}
for (let item of childrenList) {
if (item.label.indexOf(parent.label) > -1) {
item.label = item.label.replace(parent.label, '');
}
for (let proviceName of ['内蒙古', '广西', '新疆', '香港', '澳门', '西藏', '宁夏']) {
item.label = item.label.replace(proviceName, '');
}
if (item.children) {
item.children = getItemChildren(item.children, parent);
}
}
return childrenList;
}
export default class MobileCascader extends Component{
constructor(props) {
super(props);
}
render() {
const {onChange, options, label, disabled, value, json, otherProps} = this.props;
let opt = options &&
Array.isArray(options) &&
options.map((x) => {
return {
label: x.label,
value: x.value,
children: getItemChildren(x.children, x),
};
});
return (
<div className={styles.mobileFormInput}>
<Picker
data={opt || []}
cascade={true}
// cols={1}
disabled={disabled}
value={value}
extra={disabled ? '' : json.placeholder || '点击选择'}
onChange={(val) => {
onChange(val || undefined);
}}
{...otherProps?.props}
>
<List.Item arrow={disabled ? '' : 'horizontal'}>
{/*{label}*/}
</List.Item>
</Picker>
</div>
);
}
}
//
//
// export default function MobileCascader(props) { // 级联选择
//
// }