<template>
<view>
<button type="primary" @tap="getContacts">获取联系人</button>
<h2>查询到:{{list.length}}</h2>
<scroll-view v-for="item in list" :key="item.id" scroll-x="true">
<view @tap="clickme">
{{item.displayName}}{{item.phoneNumbers[0].value}}{{item.photos[0].value}}
</view>
</scroll-view>
</view>
</template>
<script>
// #ifdef APP-PLUS
var Contacts
export default {
data() {
return {
list: []
}
},
onShow() {
uni.setNavigationBarTitle({
title: '通讯录'
});
},
methods: {
getContacts() {
console.log("直线防范...........")
var that = this
// 获取通讯录对象
plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {
uni.showToast({
title: '获取通讯录对象成功',
duration: 2000
})
// console.log('获取通讯录对象成功---------------------')
// console.log(addressbook)
// var contact = addressbook.create();
// contact.name = {displayName:"王安"};
// contact.phoneNumbers = [{type:"手机",value:"88888888",preferred:true}];
// contact.photos =[{"type":"头像",value="static/logo.png",preferred:true}]
// contact.save();
// console.log('添加通讯录对象成功---------------------')
// 查找联系人
addressbook.find(["displayName","phoneNumbers"],function(contacts){
uni.showToast({
title: '获取联系人成功',
duration: 2000
})
console.log('获取联系人成功')
console.log(JSON.stringify(contacts))
that.list = contacts
}, function () {
uni.showToast({
title: '获取联系人失败',
duration: 2000
})
},{multiple:true});
}, function ( e ) {
uni.showToast({
title: '获取通讯录对象失败:' + e.message,
duration: 2000
})
});
},
clickme:function(){
uni.showModal({
title: '提示',
content: '是否退出uni-app?',
})
}
}
}
// #endif
</script>
<style>
</style>