weiximei 5 år sedan
förälder
incheckning
5bc8fb14e9
1 ändrade filer med 11 tillägg och 7 borttagningar
  1. 11
    7
      src/components/SelectButton/CitySelect.jsx

+ 11
- 7
src/components/SelectButton/CitySelect.jsx Visa fil

16
 
16
 
17
   useEffect(() => {
17
   useEffect(() => {
18
     getCityList();
18
     getCityList();
19
-  },[])
19
+    getValue();
20
+  },[props.value])
20
 
21
 
21
   const getCityList = (e) => {
22
   const getCityList = (e) => {
22
     request({
23
     request({
29
     })
30
     })
30
   }
31
   }
31
 
32
 
33
+  /**
34
+   * 因为 有个需求是,如果这个城市被删除了,那么就直接展示为空,不能展示 cityId
35
+   */
32
   const getValue = () => {
36
   const getValue = () => {
33
-    const tempData = data.filter(f => f.id == props.value)
34
-    console.log("城市组价:", tempData)
35
-    const va = (tempData.length > 0) ? props.value : undefined
36
-    // props.onChange(va)
37
-    return va
37
+    if (props.value) {
38
+      const tempData = data.filter(f => f.id == props.value)
39
+      const va = (tempData.length > 0) ? props.value : undefined
40
+      props.onChange(va)
41
+    }
38
   }
42
   }
39
 
43
 
40
   return (
44
   return (
41
       <Select 
45
       <Select 
42
       showSearch 
46
       showSearch 
43
-      value={getValue()} 
47
+      value={props.value}
44
       style={{ width: '180px' }}
48
       style={{ width: '180px' }}
45
       placeholder="请选择城市" 
49
       placeholder="请选择城市" 
46
       onChange={props.onChange} 
50
       onChange={props.onChange}