罗广聪

获取通信列表

... ... @@ -8,7 +8,8 @@ import {
TouchableOpacity,
ScrollView,
ListView,
Dimensions
Dimensions,
AsyncStorage,
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
import post from "../../utils/fetch";
... ... @@ -17,13 +18,17 @@ export default class Import extends Component {
constructor(props) {
super(props);
this.state = {
IS_LOGIN: "",
USER_ID: "",
customersList: this.props.navigation.state.params.customersList,
selected_list: [],
selected_all: false,
selected_len: 0,
selected_len: 0
};
}
componentWillMount() {}
componentWillMount() {
this.getAsyncStorage()
}
componentDidMount() {
console.log("导入客户", this.props.navigation.state.params);
... ... @@ -33,6 +38,22 @@ export default class Import extends Component {
post("/test/insurance/article", {}, res => {}, err => {});
}
getAsyncStorage() {
const that = this;
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID"],
(err, result) => {
if (err) {
console.error(err);
}
that.setState({
IS_LOGIN: result[0][1],
USER_ID: result[1][1] != null ? result[1][1] : "",
});
}
);
}
selectItem(item, index) {
const { customersList, selected_all, selected_len } = this.state;
let Temp = customersList;
... ... @@ -56,22 +77,20 @@ export default class Import extends Component {
() => {
if (selected_all) {
this.setState({
selected_list: customersList,
customersList: customersList.map((item,index) => {
customersList: customersList.map((item, index) => {
return {
...item,
selected: false
}
};
})
});
} else {
this.setState({
selected_list: [],
customersList: customersList.map((item,index) => {
customersList: customersList.map((item, index) => {
return {
...item,
selected: true
}
};
})
});
}
... ... @@ -79,6 +98,18 @@ export default class Import extends Component {
);
}
import() {
const { customersList,USER_ID } = this.state;
let Temp = [];
for (let i = 0, len = customersList.length; i < len; i++) {
if (customersList[i].selected) {
Temp.push(customersList[i]);
}
}
console.log("发送通信录", Temp);
post(`/test/insurance/contact/lot/${USER_ID}`,{'Temp':Temp},res => {console.log('导入成功')},err => {console.log(err)});
}
render() {
const { navigate } = this.props.navigation;
const { customersList, selected_all, selected_len } = this.state;
... ... @@ -151,7 +182,12 @@ export default class Import extends Component {
<Text></Text>
</View>
</View>
<TouchableOpacity style={styles.importBtnContaier}>
<TouchableOpacity
style={styles.importBtnContaier}
onPress={() => {
this.import();
}}
>
<Text style={styles.importBtnText}>导入</Text>
</TouchableOpacity>
</View>
... ...
... ... @@ -24,7 +24,7 @@ export default class Customer extends Component {
USER_ID: "",
NICKNAME: "",
PROFESSION: "",
hasCustomer: false,
hasCustomer: true,
customersList: ["张某某", "周某某", "林某某", "李某某"],
customersList2: [
{
... ... @@ -50,11 +50,9 @@ export default class Customer extends Component {
this.getAsyncStorage();
}
componentDidMount() {}
getListData() {
post("/test/insurance/article", {}, res => {}, err => {});
componentDidMount() {
}
getAllPhone() {
const { navigate } = this.props.navigation;
Contacts.getAll((err, contacts) => {
... ... @@ -65,7 +63,7 @@ export default class Customer extends Component {
customersList.push({
name: item.familyName + item.givenName,
phone: item.phoneNumbers[0] ? item.phoneNumbers[0].number : "",
selected: false,
selected: false
});
});
// console.log("通信录", contacts);
... ... @@ -77,20 +75,31 @@ export default class Customer extends Component {
getAsyncStorage() {
const that = this;
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
(err, result) => {
const { USER_ID } = this.state;
AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => {
if (err) {
console.error(err);
}
that.setState({
that.setState(
{
IS_LOGIN: result[0][1],
USER_ID: result[1][1] != null ? result[1][1] : "",
NICKNAME: result[2][1] != null ? result[2][1] : "",
PROFESSION: result[3][1] != null ? result[3][1] : ""
});
USER_ID: result[1][1] != null ? result[1][1] : ""
},
() => {
console.log(that.state.USER_ID)
post(
`/test/insurance/contact/get/${that.state.USER_ID}`,
{},
res => {
console.log("通信录返回值", res);
},
err => {
console.log("通信录err", err);
}
);
}
);
});
}
_renderBegin() {
... ...