Showing
2 changed files
with
49 additions
and
9 deletions
| @@ -13,6 +13,7 @@ import { | @@ -13,6 +13,7 @@ import { | ||
| 13 | Modal, | 13 | Modal, |
| 14 | Alert, | 14 | Alert, |
| 15 | AlertIOS, | 15 | AlertIOS, |
| 16 | + AsyncStorage, | ||
| 16 | TouchableHighlight | 17 | TouchableHighlight |
| 17 | } from "react-native"; | 18 | } from "react-native"; |
| 18 | import { StackNavigator, TabNavigator } from "react-navigation"; | 19 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| @@ -23,6 +24,7 @@ export default class Edit extends Component { | @@ -23,6 +24,7 @@ export default class Edit extends Component { | ||
| 23 | super(props); | 24 | super(props); |
| 24 | this.state = { | 25 | this.state = { |
| 25 | USER_ID: "", | 26 | USER_ID: "", |
| 27 | + IS_LOGIN: "", | ||
| 26 | customer_id: this.props.navigation.state.params.item.id, | 28 | customer_id: this.props.navigation.state.params.item.id, |
| 27 | name: "", | 29 | name: "", |
| 28 | age: "", | 30 | age: "", |
| @@ -35,12 +37,28 @@ export default class Edit extends Component { | @@ -35,12 +37,28 @@ export default class Edit extends Component { | ||
| 35 | }; | 37 | }; |
| 36 | } | 38 | } |
| 37 | componentWillMount() { | 39 | componentWillMount() { |
| 40 | + this.getAsyncStorage(); | ||
| 38 | console.log("customer_id", this.state.customer_id); | 41 | console.log("customer_id", this.state.customer_id); |
| 42 | + console.log("回调是啥?", this.props.navigation); | ||
| 39 | this.getItemInfo(); | 43 | this.getItemInfo(); |
| 40 | } | 44 | } |
| 41 | 45 | ||
| 42 | componentDidMount() {} | 46 | componentDidMount() {} |
| 43 | 47 | ||
| 48 | + getAsyncStorage() { | ||
| 49 | + const that = this; | ||
| 50 | + const { USER_ID, customersList } = this.state; | ||
| 51 | + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | ||
| 52 | + if (err) { | ||
| 53 | + console.error(err); | ||
| 54 | + } | ||
| 55 | + that.setState({ | ||
| 56 | + IS_LOGIN: result[0][1], | ||
| 57 | + USER_ID: result[1][1] != null ? result[1][1] : "" | ||
| 58 | + }); | ||
| 59 | + }); | ||
| 60 | + } | ||
| 61 | + | ||
| 44 | getItemInfo() { | 62 | getItemInfo() { |
| 45 | const that = this; | 63 | const that = this; |
| 46 | const { customer_id } = this.state; | 64 | const { customer_id } = this.state; |
| @@ -69,7 +87,7 @@ export default class Edit extends Component { | @@ -69,7 +87,7 @@ export default class Edit extends Component { | ||
| 69 | submit() { | 87 | submit() { |
| 70 | const that = this; | 88 | const that = this; |
| 71 | const { customer_id } = this.state; | 89 | const { customer_id } = this.state; |
| 72 | - const { goBack } = this.props.navigation; | 90 | + const { goBack, state } = this.props.navigation; |
| 73 | post( | 91 | post( |
| 74 | `/test/insurance/contact/update/${customer_id}`, | 92 | `/test/insurance/contact/update/${customer_id}`, |
| 75 | { | 93 | { |
| @@ -94,12 +112,15 @@ export default class Edit extends Component { | @@ -94,12 +112,15 @@ export default class Edit extends Component { | ||
| 94 | delete() { | 112 | delete() { |
| 95 | const that = this; | 113 | const that = this; |
| 96 | const { customer_id } = this.state; | 114 | const { customer_id } = this.state; |
| 115 | + const { state,goBack } = this.props.navigation; | ||
| 97 | post( | 116 | post( |
| 98 | `/test/insurance/contact/del/${customer_id}`, | 117 | `/test/insurance/contact/del/${customer_id}`, |
| 99 | {}, | 118 | {}, |
| 100 | res => { | 119 | res => { |
| 101 | console.log("修改客户个人信息", res); | 120 | console.log("修改客户个人信息", res); |
| 102 | - Alert.alert("删除成功", null, () => goBack()); | 121 | + Alert.alert("删除成功", null, () => { |
| 122 | + goBack(); | ||
| 123 | + }); | ||
| 103 | }, | 124 | }, |
| 104 | err => { | 125 | err => { |
| 105 | Alert.alert(err); | 126 | Alert.alert(err); |
| @@ -299,7 +320,23 @@ export default class Edit extends Component { | @@ -299,7 +320,23 @@ export default class Edit extends Component { | ||
| 299 | </TouchableOpacity> | 320 | </TouchableOpacity> |
| 300 | <TouchableOpacity | 321 | <TouchableOpacity |
| 301 | onPress={() => { | 322 | onPress={() => { |
| 323 | + Alert.alert( | ||
| 324 | + "确认删除该客户?", | ||
| 325 | + "", | ||
| 326 | + [ | ||
| 327 | + { | ||
| 328 | + text: "取消", | ||
| 329 | + onPress: () => {} | ||
| 330 | + }, | ||
| 331 | + { | ||
| 332 | + text: "确认", | ||
| 333 | + onPress: () => { | ||
| 302 | this.delete(); | 334 | this.delete(); |
| 335 | + } | ||
| 336 | + } | ||
| 337 | + ], | ||
| 338 | + { cancelable: false } | ||
| 339 | + ); | ||
| 303 | }} | 340 | }} |
| 304 | style={styles.deleteBtn} | 341 | style={styles.deleteBtn} |
| 305 | > | 342 | > |
| @@ -33,8 +33,7 @@ export default class Customer extends Component { | @@ -33,8 +33,7 @@ export default class Customer extends Component { | ||
| 33 | this.getAsyncStorage(); | 33 | this.getAsyncStorage(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | - componentDidMount() { | 36 | + componentDidMount() {} |
| 37 | - } | ||
| 38 | 37 | ||
| 39 | getAllPhone() { | 38 | getAllPhone() { |
| 40 | const { navigate } = this.props.navigation; | 39 | const { navigate } = this.props.navigation; |
| @@ -58,7 +57,7 @@ export default class Customer extends Component { | @@ -58,7 +57,7 @@ export default class Customer extends Component { | ||
| 58 | 57 | ||
| 59 | getAsyncStorage() { | 58 | getAsyncStorage() { |
| 60 | const that = this; | 59 | const that = this; |
| 61 | - const { USER_ID,customersList } = this.state; | 60 | + const { USER_ID, customersList } = this.state; |
| 62 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | 61 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { |
| 63 | if (err) { | 62 | if (err) { |
| 64 | console.error(err); | 63 | console.error(err); |
| @@ -69,19 +68,19 @@ export default class Customer extends Component { | @@ -69,19 +68,19 @@ export default class Customer extends Component { | ||
| 69 | USER_ID: result[1][1] != null ? result[1][1] : "" | 68 | USER_ID: result[1][1] != null ? result[1][1] : "" |
| 70 | }, | 69 | }, |
| 71 | () => { | 70 | () => { |
| 72 | - console.log(that.state.USER_ID) | 71 | + console.log(that.state.USER_ID); |
| 73 | post( | 72 | post( |
| 74 | `/test/insurance/contact/get/${that.state.USER_ID}`, | 73 | `/test/insurance/contact/get/${that.state.USER_ID}`, |
| 75 | {}, | 74 | {}, |
| 76 | res => { | 75 | res => { |
| 77 | - console.log("通信录返回值", res); | ||
| 78 | that.setState({ | 76 | that.setState({ |
| 79 | hasCustomer: true, | 77 | hasCustomer: true, |
| 80 | customersList: res.data.contacts | 78 | customersList: res.data.contacts |
| 81 | - }) | 79 | + }); |
| 82 | }, | 80 | }, |
| 83 | err => { | 81 | err => { |
| 84 | console.log("通信录err", err); | 82 | console.log("通信录err", err); |
| 83 | + Alert.alert(err); | ||
| 85 | } | 84 | } |
| 86 | ); | 85 | ); |
| 87 | } | 86 | } |
| @@ -160,7 +159,11 @@ export default class Customer extends Component { | @@ -160,7 +159,11 @@ export default class Customer extends Component { | ||
| 160 | <TouchableOpacity | 159 | <TouchableOpacity |
| 161 | key={index} | 160 | key={index} |
| 162 | style={styles.mainCustomerItem} | 161 | style={styles.mainCustomerItem} |
| 163 | - onPress={() => navigate("CustomerEdit",{item: item})} | 162 | + onPress={() => |
| 163 | + navigate("CustomerEdit", { | ||
| 164 | + item: item, | ||
| 165 | + refreshCallback: this.getAsyncStorage | ||
| 166 | + })} | ||
| 164 | > | 167 | > |
| 165 | <Text style={styles.mainCustomerItemText}>{item.name}</Text> | 168 | <Text style={styles.mainCustomerItemText}>{item.name}</Text> |
| 166 | <Image | 169 | <Image |
-
Please register or login to post a comment