Showing
2 changed files
with
29 additions
and
33 deletions
| @@ -10,6 +10,7 @@ import { | @@ -10,6 +10,7 @@ import { | ||
| 10 | ListView, | 10 | ListView, |
| 11 | Dimensions, | 11 | Dimensions, |
| 12 | AsyncStorage, | 12 | AsyncStorage, |
| 13 | + Alert | ||
| 13 | } from "react-native"; | 14 | } from "react-native"; |
| 14 | import { StackNavigator, TabNavigator } from "react-navigation"; | 15 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 15 | import post from "../../utils/fetch"; | 16 | import post from "../../utils/fetch"; |
| @@ -27,7 +28,7 @@ export default class Import extends Component { | @@ -27,7 +28,7 @@ export default class Import extends Component { | ||
| 27 | }; | 28 | }; |
| 28 | } | 29 | } |
| 29 | componentWillMount() { | 30 | componentWillMount() { |
| 30 | - this.getAsyncStorage() | 31 | + this.getAsyncStorage(); |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | componentDidMount() { | 34 | componentDidMount() { |
| @@ -40,18 +41,15 @@ export default class Import extends Component { | @@ -40,18 +41,15 @@ export default class Import extends Component { | ||
| 40 | 41 | ||
| 41 | getAsyncStorage() { | 42 | getAsyncStorage() { |
| 42 | const that = this; | 43 | const that = this; |
| 43 | - AsyncStorage.multiGet( | 44 | + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { |
| 44 | - ["IS_LOGIN", "USER_ID"], | 45 | + if (err) { |
| 45 | - (err, result) => { | 46 | + console.error(err); |
| 46 | - if (err) { | ||
| 47 | - console.error(err); | ||
| 48 | - } | ||
| 49 | - that.setState({ | ||
| 50 | - IS_LOGIN: result[0][1], | ||
| 51 | - USER_ID: result[1][1] != null ? result[1][1] : "", | ||
| 52 | - }); | ||
| 53 | } | 47 | } |
| 54 | - ); | 48 | + that.setState({ |
| 49 | + IS_LOGIN: result[0][1], | ||
| 50 | + USER_ID: result[1][1] != null ? result[1][1] : "" | ||
| 51 | + }); | ||
| 52 | + }); | ||
| 55 | } | 53 | } |
| 56 | 54 | ||
| 57 | selectItem(item, index) { | 55 | selectItem(item, index) { |
| @@ -99,7 +97,8 @@ export default class Import extends Component { | @@ -99,7 +97,8 @@ export default class Import extends Component { | ||
| 99 | } | 97 | } |
| 100 | 98 | ||
| 101 | import() { | 99 | import() { |
| 102 | - const { customersList,USER_ID } = this.state; | 100 | + const { customersList, USER_ID } = this.state; |
| 101 | + const { goBack } = this.props.navigation; | ||
| 103 | let Temp = []; | 102 | let Temp = []; |
| 104 | for (let i = 0, len = customersList.length; i < len; i++) { | 103 | for (let i = 0, len = customersList.length; i < len; i++) { |
| 105 | if (customersList[i].selected) { | 104 | if (customersList[i].selected) { |
| @@ -107,7 +106,17 @@ export default class Import extends Component { | @@ -107,7 +106,17 @@ export default class Import extends Component { | ||
| 107 | } | 106 | } |
| 108 | } | 107 | } |
| 109 | console.log("发送通信录", Temp); | 108 | console.log("发送通信录", Temp); |
| 110 | - post(`/test/insurance/contact/lot/${USER_ID}`,{'Temp':Temp},res => {console.log('导入成功')},err => {console.log(err)}); | 109 | + post( |
| 110 | + `/test/insurance/contact/lot/${USER_ID}`, | ||
| 111 | + { Temp: Temp }, | ||
| 112 | + res => { | ||
| 113 | + console.log("导入成功"); | ||
| 114 | + Alert.alert("导入成功", null, () => goBack()); | ||
| 115 | + }, | ||
| 116 | + err => { | ||
| 117 | + console.log(err); | ||
| 118 | + } | ||
| 119 | + ); | ||
| 111 | } | 120 | } |
| 112 | 121 | ||
| 113 | render() { | 122 | render() { |
| @@ -25,24 +25,7 @@ export default class Customer extends Component { | @@ -25,24 +25,7 @@ export default class Customer extends Component { | ||
| 25 | NICKNAME: "", | 25 | NICKNAME: "", |
| 26 | PROFESSION: "", | 26 | PROFESSION: "", |
| 27 | hasCustomer: true, | 27 | hasCustomer: true, |
| 28 | - customersList: ["张某某", "周某某", "林某某", "李某某"], | 28 | + customersList: [] |
| 29 | - customersList2: [ | ||
| 30 | - { | ||
| 31 | - name: "Tina", | ||
| 32 | - id: "", | ||
| 33 | - phone: "" | ||
| 34 | - }, | ||
| 35 | - { | ||
| 36 | - name: "aaaa", | ||
| 37 | - id: "", | ||
| 38 | - phone: "" | ||
| 39 | - }, | ||
| 40 | - { | ||
| 41 | - name: "dddd", | ||
| 42 | - id: "", | ||
| 43 | - phone: "" | ||
| 44 | - } | ||
| 45 | - ] | ||
| 46 | }; | 29 | }; |
| 47 | this.getAllPhone = this.getAllPhone.bind(this); | 30 | this.getAllPhone = this.getAllPhone.bind(this); |
| 48 | } | 31 | } |
| @@ -75,7 +58,7 @@ export default class Customer extends Component { | @@ -75,7 +58,7 @@ export default class Customer extends Component { | ||
| 75 | 58 | ||
| 76 | getAsyncStorage() { | 59 | getAsyncStorage() { |
| 77 | const that = this; | 60 | const that = this; |
| 78 | - const { USER_ID } = this.state; | 61 | + const { USER_ID,customersList } = this.state; |
| 79 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | 62 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { |
| 80 | if (err) { | 63 | if (err) { |
| 81 | console.error(err); | 64 | console.error(err); |
| @@ -92,6 +75,10 @@ export default class Customer extends Component { | @@ -92,6 +75,10 @@ export default class Customer extends Component { | ||
| 92 | {}, | 75 | {}, |
| 93 | res => { | 76 | res => { |
| 94 | console.log("通信录返回值", res); | 77 | console.log("通信录返回值", res); |
| 78 | + that.setState({ | ||
| 79 | + hasCustomer: true, | ||
| 80 | + customersList: res.data.contacts | ||
| 81 | + }) | ||
| 95 | }, | 82 | }, |
| 96 | err => { | 83 | err => { |
| 97 | console.log("通信录err", err); | 84 | console.log("通信录err", err); |
-
Please register or login to post a comment