add-phone-contact.vue 2.4 KB

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