Browse Source

省市区默认回显问题

dev01 2 months ago
parent
commit
aaebf66bef

+ 30 - 9
src/components/common/addressPicker/index.jsx

@@ -2,17 +2,35 @@ import React, { Component } from "react";
 import { View, PickerView, PickerViewColumn } from '@tarojs/components'
 import PropTypes from 'prop-types'
 import address from '../../../utils/tools/city.js'
-
+import { addressList } from '../../../utils/tools/config'
 import './index.less'
 
+let provinceList = [];
+let cityObj = {};
+let areaObj = {};
+addressList.map(item => {
+  provinceList.push({ name: item.name, id: item.id });
+  cityObj[item.id] = item.cityList.map(cityItem => {
+    return { provice: item.name, name: cityItem.name, id: cityItem.id }
+  });
+  item.cityList.map(cityItem => {
+    areaObj[cityItem.id] = cityItem.areaList.map(areaItem => {
+      return { city: cityItem.name, name: areaItem.name, id: areaItem.id }
+    });
+  });
+});
+
 class AddressPicker extends Component {
   constructor(props) {
     super(props);
     this.state = {
-      value: [17, 0, 1],
-      provinces: address.provinces || [],
-      citys: address.citys[430000] || {},
-      areas: address.areas[430100] || {},
+      value: [10, 0, 2],
+      // provinces: address.provinces || [],
+      // citys: cityObj[430000] || {},
+      // areas: areaObj[430100] || {},
+      provinces: addressList || [],
+      citys: cityObj[11] || {},
+      areas: areaObj[128] || {},
       areaInfo: {
         province: "湖南省",
         city: "长沙市",
@@ -26,7 +44,10 @@ class AddressPicker extends Component {
   componentDidUpdate(prevProps) {
     if (!!this.props.value && !!prevProps.value && this.props.value instanceof Array && prevProps.value instanceof Array) {
       if (this.props.value.join(',') != prevProps.value.join(',')) {
-        this.setState({ value: this.props.value });
+        console.log(this.props.value)
+        let citys = cityObj[provinceList[this.props.value[0]].id];
+        let areas = areaObj[citys[this.props.value[1]].id];
+        this.setState({ value: this.props.value, citys, areas });
       }
     }
   }
@@ -42,15 +63,15 @@ class AddressPicker extends Component {
       const id = provinces[provinceNum].id
       this.setState({
         value: [provinceNum, 0, 0],
-        citys: address.citys[id],
-        areas: address.areas[address.citys[id][0].id]
+        citys: cityObj[id],
+        areas: areaObj[cityObj[id][0].id]
       })
     } else if (value[1] != cityNum) {
       // 滑动选择了第二项数据,即市,此时区显示省市对应的第一组数据
       const id = citys[cityNum].id
       this.setState({
         value: [provinceNum, cityNum, 0],
-        areas: address.areas[citys[cityNum].id]
+        areas: areaObj[citys[cityNum].id]
       })
     } else {
       // 滑动选择了区

+ 30 - 15
src/pages/customerProfile/index.jsx

@@ -36,13 +36,14 @@ import "taro-ui/dist/style/components/input.scss";
 import "taro-ui/dist/style/components/search-bar.scss";
 
 import MessageNoticebar from "../../components/common/messageNoticebar";
-import { industry, channelTypeList, yearList } from '../../utils/tools/config';
+import { industry, channelTypeList, yearList, addressList } from '../../utils/tools/config';
 import { getChannel } from "../../utils/tools";
 import Superior from "../../components/common/superior";
 import CheckboxPicker from "../../components/common/CheckboxPicker";
 import AddressPicker from "../../components/common/addressPicker"
 import InteractList from "./components/InteractList";
 import CustomerProjectSelect from '../../components/common/CustomerProjectSelect';
+import address from '../../utils/tools/city.js'
 
 class CustomerProfile extends Component {
   $instance = getCurrentInstance();
@@ -119,6 +120,31 @@ class CustomerProfile extends Component {
     return newNum.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
   }
 
+  openAddressPicker() {
+    const { dtails } = this.state;
+    let currAddress = [];
+    if (dtails.locationProvince && dtails.locationCity && dtails.locationArea) {
+      let provIdx = 0, cityIdx = 0, areaIdx = 0;
+      addressList.map((provItem, idx1) => {
+        if (provItem.id == dtails.locationProvince) {
+          provIdx = idx1;
+          provItem.cityList.map((cityItem, idx2) => {
+            if (cityItem.id == dtails.locationCity) {
+              cityIdx = idx2;
+              cityItem.areaList.map((areaItem, idx3) => {
+                if (areaItem.id == dtails.locationArea) {
+                  areaIdx = idx3;
+                }
+              })
+            }
+          })
+        }
+      })
+      currAddress = [provIdx, cityIdx, areaIdx];
+    }
+    this.setState({ addressPickerShow: true, currAddress })
+  }
+
   toggleAddressPicker(e) {
     if (!Object.keys(e).length) {
       this.setState({ addressPickerShow: false });
@@ -954,13 +980,7 @@ class CustomerProfile extends Component {
                         <View className="item-title">企业所在地省市区:</View>
                         <View className="item-value">
 
-                          <View className="link" onClick={() => {
-                            let currAddress = [];
-                            if (dtails.locationProvince && dtails.locationCity && dtails.locationArea) {
-                              currAddress = [dtails.locationProvince, dtails.locationCity, dtails.locationArea];
-                            }
-                            this.setState({ addressPickerShow: true, currAddress })
-                          }}>
+                          <View className="link" onClick={() => this.openAddressPicker()}>
                             {dtails.locationProvince ? `${dtails.locationProvinceName}-${dtails.locationCityName}-${dtails.locationAreaName}` : '请选择'}
                           </View>
 
@@ -1098,13 +1118,7 @@ class CustomerProfile extends Component {
                       <View className="item">
                         <View className="item-title">企业所在地省市区:</View>
                         <View className="item-value">
-                          <View className="link" onClick={() => {
-                            let currAddress = [];
-                            if (dtails.locationProvince && dtails.locationCity && dtails.locationArea) {
-                              currAddress = [dtails.locationProvince, dtails.locationCity, dtails.locationArea];
-                            }
-                            this.setState({ addressPickerShow: true, currAddress })
-                          }}>
+                          <View className="link" onClick={() => this.openAddressPicker()}>
                             {dtails.locationProvince ? `${dtails.locationProvinceName}-${dtails.locationCityName}-${dtails.locationAreaName}` : '请选择'}
                           </View>
                         </View>
@@ -2146,6 +2160,7 @@ class CustomerProfile extends Component {
 
         {/* 省市区选择器 */}
         <AddressPicker
+          value={this.state.currAddress}
           pickerShow={this.state.addressPickerShow}
           onHandleToggleShow={this.toggleAddressPicker.bind(this)}
         />

+ 4 - 4
src/pages/egressDetails/index.jsx

@@ -700,19 +700,19 @@ class EgressDetails extends Component {
                 <View className="value">{["", "是,一同公出", "否,本人不公出"][dtails.alone]}</View>
               </View>}
             {/* 公出目标 */}
-            <View className="item">
+            {dtails.type != 0 && (<View className="item">
               <View className="title">公出目标</View>
               <View className="value">{dtails.remarks}</View>
-            </View>
+            </View>)}
             {/* 公出计划 */}
-            {dtails.type != 2 && (
+            {dtails.type != 2 || dtails.type != 0 && (
               <View className="item">
                 <View className="title">公出计划</View>
                 <View className="value">{dtails.plan}</View>
               </View>
             )}
             {/* 预计效果 */}
-            {dtails.type != 2 && (
+            {dtails.type != 2 || dtails.type != 0 && (
               <View className="item">
                 <View className="title">预计效果</View>
                 <View className="value">{dtails.expectedEffect}</View>

+ 32 - 4
src/pages/interview/index.jsx

@@ -38,7 +38,7 @@ import "taro-ui/dist/style/components/input.scss";
 import "taro-ui/dist/style/components/search-bar.scss";
 
 import MessageNoticebar from "../../components/common/messageNoticebar";
-import { industry, channelTypeList, yearList } from '../../utils/tools/config';
+import { industry, channelTypeList, yearList, addressList } from '../../utils/tools/config';
 import { getChannel } from "../../utils/tools";
 import Superior from "../../components/common/superior";
 import CheckboxPicker from "../../components/common/CheckboxPicker";
@@ -91,7 +91,9 @@ class CustomerProfile extends Component {
       interactList: [],
 
       checkCompShow: false,
-      checkCompList: []
+      checkCompList: [],
+
+      currAddress: []
     };
     this.queryByUidAll = this.queryByUidAll.bind(this);
     this.update = this.update.bind(this);
@@ -126,6 +128,31 @@ class CustomerProfile extends Component {
     return newNum.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
   }
 
+  openAddressPicker() {
+    const { dtails } = this.state;
+    let currAddress = [];
+    if (dtails.locationProvince && dtails.locationCity && dtails.locationArea) {
+      let provIdx = 0, cityIdx = 0, areaIdx = 0;
+      addressList.map((provItem, idx1) => {
+        if (provItem.id == dtails.locationProvince) {
+          provIdx = idx1;
+          provItem.cityList.map((cityItem, idx2) => {
+            if (cityItem.id == dtails.locationCity) {
+              cityIdx = idx2;
+              cityItem.areaList.map((areaItem, idx3) => {
+                if (areaItem.id == dtails.locationArea) {
+                  areaIdx = idx3;
+                }
+              })
+            }
+          })
+        }
+      })
+      currAddress = [provIdx, cityIdx, areaIdx];
+    }
+    this.setState({ addressPickerShow: true, currAddress })
+  }
+
   handlePrevClick() {
     this.props.onPrevClick();
   }
@@ -1055,7 +1082,7 @@ class CustomerProfile extends Component {
                       <View className="item">
                         <View className="item-title">企业所在地省市区:</View>
                         <View className="item-value">
-                          <View className="link" onClick={() => { this.setState({ addressPickerShow: true }) }}>
+                          <View className="link" onClick={() => this.openAddressPicker()}>
                             {dtails.locationProvince ? `${dtails.locationProvinceName}-${dtails.locationCityName}-${dtails.locationAreaName}` : '请选择'}
                           </View>
                         </View>
@@ -1347,7 +1374,7 @@ class CustomerProfile extends Component {
                       <View className="item">
                         <view className="item-title">企业所在地省市区:</view>
                         <view className="item-value">
-                          <View className="link" onClick={() => { this.setState({ addressPickerShow: true }) }}>
+                          <View className="link" onClick={() => this.openAddressPicker()}>
                             {dtails.locationProvince ? `${dtails.locationProvinceName}-${dtails.locationCityName}-${dtails.locationAreaName}` : '请选择'}
                           </View>
                         </view>
@@ -2204,6 +2231,7 @@ class CustomerProfile extends Component {
 
         {/* 省市区选择器 */}
         <AddressPicker
+          value={this.state.currAddress}
           pickerShow={this.state.addressPickerShow}
           onHandleToggleShow={this.toggleAddressPicker.bind(this)}
         />