Blame view

pages/API/add-phone-contact/add-phone-contact.vue 2.36 KB
4b045f7c   刘淇   江阴初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  <template>
  	<view>
  		<page-head :title="title"></page-head>
  		<view class="uni-common-mt">
  			<view class="uni-list">
  				<view class="uni-list-cell">
  					<view class="uni-list-cell-left">
  						<view class="uni-label">名称</view>
  					</view>
  					<view class="uni-list-cell-db">
  						<input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"/>
  					</view>
  				</view>
  				<view class="uni-list-cell">
  					<view class="uni-list-cell-left">
  						<view class="uni-label">手机号</view>
  					</view>
  					<view class="uni-list-cell-db">
  						<input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"/>
  					</view>
  				</view>
  			</view>
  			<view class="uni-padding-wrap">
  				<view class="uni-btn-v">
  					<button type="primary" class="btn-setstorage" @tap="add">添加联系人</button>
  				</view>
  			</view>
  		</view>
  	</view>
  </template>
  <script>
  	// #ifdef APP-PLUS
  	import permision from "@/common/permission.js"
  	// #endif
  	export default {
  		data() {
  			return {
  				title: 'addPhoneContact',
  				name: '',
  				phone: ''
  			}
  		},
  		methods: {
  			nameChange: function(e) {
  				this.name = e.detail.value
  			},
  			phoneChange: function(e) {
  				this.phone = e.detail.value
  			},
  			async add() {
  				// #ifdef APP-PLUS
  				let status = await this.checkPermission();
  				if (status !== 1) {
  				    return;
  				}
  				// #endif
  
  				uni.addPhoneContact({
  					firstName: this.name,
  					mobilePhoneNumber: this.phone,
  					success: function() {
  						uni.showModal({
  							content: '已成功添加联系人!',
  							showCancel: false
  						})
  					},
  					fail: function() {
  						uni.showModal({
  							content: '添加联系人失败!',
  							showCancel: false
  						})
  					}
  				});
  			}
  			// #ifdef APP-PLUS
  			,
  			async checkPermission() {
  				let status = permision.isIOS ? await permision.requestIOS('contact') :
  					await permision.requestAndroid('android.permission.WRITE_CONTACTS');
  
  				if (status === null || status === 1) {
  					status = 1;
  				} else {
  					uni.showModal({
  						content: "需要联系人权限",
  						confirmText: "设置",
  						success: function(res) {
  							if (res.confirm) {
  								permision.gotoAppSetting();
  							}
  						}
  					})
  				}
  				return status;
  			}
  			// #endif
  		}
  	}
  </script>
  
  <style>
  </style>