ContactImport.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="overlay" v-if="visible" @click.self="onCancel">
  3. <view class="modal">
  4. <text class="modal-title">添加联系人</text>
  5. <view class="form">
  6. <view class="form-row">
  7. <text class="form-label">姓名</text>
  8. <input class="form-input" v-model="form.name" disabled />
  9. </view>
  10. <view class="form-row">
  11. <text class="form-label">手机号</text>
  12. <input class="form-input" v-model="form.phone" disabled />
  13. </view>
  14. <view class="form-row">
  15. <text class="form-label">关系类型</text>
  16. <picker mode="selector" :range="typeOptions" @change="onTypeChange">
  17. <view class="form-picker">{{ form.relationshipTypeLabel || '请选择' }}</view>
  18. </picker>
  19. </view>
  20. <view class="form-row">
  21. <text class="form-label">认识时间</text>
  22. <picker mode="date" @change="onDateChange">
  23. <view class="form-picker">{{ form.knownSince || '请选择' }}</view>
  24. </picker>
  25. </view>
  26. <view class="form-row">
  27. <text class="form-label">生日</text>
  28. <picker mode="date" @change="onBirthdayChange">
  29. <view class="form-picker">{{ form.birthday || '请选择' }}</view>
  30. </picker>
  31. </view>
  32. <view class="form-row">
  33. <text class="form-label">个人介绍</text>
  34. <input class="form-input" v-model="form.bio" placeholder="选填" />
  35. </view>
  36. </view>
  37. <view class="modal-actions">
  38. <button class="btn-cancel" @click="onCancel">取消</button>
  39. <button class="btn-confirm" @click="onConfirm">确认添加</button>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { importPhoneContact } from '../utils/api.js'
  46. export default {
  47. props: {
  48. visible: { type: Boolean, default: false },
  49. name: { type: String, default: '' },
  50. phone: { type: String, default: '' }
  51. },
  52. data: function() {
  53. return {
  54. form: {
  55. name: '',
  56. phone: '',
  57. relationshipType: '',
  58. relationshipTypeLabel: '',
  59. knownSince: '',
  60. birthday: '',
  61. bio: ''
  62. },
  63. typeOptions: ['家人', '朋友', '伴侣', '同事', '其他'],
  64. typeValues: { '家人': 'family', '朋友': 'friend', '伴侣': 'partner', '同事': 'colleague', '其他': 'other' }
  65. }
  66. },
  67. watch: {
  68. name: function(val) { this.form.name = val },
  69. phone: function(val) { this.form.phone = val }
  70. },
  71. methods: {
  72. onTypeChange: function(e) {
  73. var label = this.typeOptions[e.detail.value]
  74. this.form.relationshipType = this.typeValues[label] || 'other'
  75. this.form.relationshipTypeLabel = label
  76. },
  77. onDateChange: function(e) {
  78. this.form.knownSince = e.detail.value
  79. },
  80. onBirthdayChange: function(e) {
  81. this.form.birthday = e.detail.value
  82. },
  83. onConfirm: function() {
  84. var self = this
  85. var extra = {}
  86. if (this.form.relationshipType) extra.relationshipType = this.form.relationshipType
  87. if (this.form.knownSince) extra.knownSince = this.form.knownSince
  88. if (this.form.birthday) extra.birthday = this.form.birthday
  89. if (this.form.bio) extra.bio = this.form.bio
  90. importPhoneContact({
  91. name: this.form.name,
  92. phone: this.form.phone,
  93. extra: extra
  94. }).then(function(res) {
  95. if (res.code === 200) {
  96. uni.showToast({ title: '添加成功', icon: 'success' })
  97. self.$emit('success')
  98. self.reset()
  99. } else {
  100. uni.showToast({ title: res.message || '添加失败', icon: 'none' })
  101. }
  102. }).catch(function() {
  103. uni.showToast({ title: '网络错误', icon: 'none' })
  104. })
  105. },
  106. onCancel: function() {
  107. this.reset()
  108. this.$emit('close')
  109. },
  110. reset: function() {
  111. this.form = { name: '', phone: '', relationshipType: '', relationshipTypeLabel: '', knownSince: '', birthday: '', bio: '' }
  112. this.$emit('close')
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .overlay {
  119. position: fixed;
  120. top: 0; left: 0; right: 0; bottom: 0;
  121. background: rgba(0,0,0,0.5);
  122. z-index: 999;
  123. display: flex;
  124. align-items: flex-end;
  125. }
  126. .modal {
  127. background: #fff;
  128. border-radius: 24rpx 24rpx 0 0;
  129. padding: 40rpx 30rpx;
  130. width: 100%;
  131. box-sizing: border-box;
  132. max-height: 80vh;
  133. overflow-y: auto;
  134. }
  135. .modal-title {
  136. font-size: 32rpx;
  137. font-weight: bold;
  138. color: #333;
  139. margin-bottom: 30rpx;
  140. display: block;
  141. text-align: center;
  142. }
  143. .form-row {
  144. margin-bottom: 24rpx;
  145. }
  146. .form-label {
  147. font-size: 26rpx;
  148. color: #666;
  149. display: block;
  150. margin-bottom: 8rpx;
  151. }
  152. .form-input {
  153. border: 1rpx solid #ddd;
  154. border-radius: 12rpx;
  155. padding: 16rpx 20rpx;
  156. font-size: 28rpx;
  157. width: 100%;
  158. box-sizing: border-box;
  159. color: #333;
  160. }
  161. .form-picker {
  162. border: 1rpx solid #ddd;
  163. border-radius: 12rpx;
  164. padding: 16rpx 20rpx;
  165. font-size: 28rpx;
  166. color: #333;
  167. }
  168. .modal-actions {
  169. display: flex;
  170. gap: 20rpx;
  171. margin-top: 40rpx;
  172. }
  173. .btn-cancel {
  174. flex: 1;
  175. padding: 20rpx;
  176. border-radius: 12rpx;
  177. border: 1rpx solid #ddd;
  178. background: #fff;
  179. font-size: 28rpx;
  180. color: #666;
  181. text-align: center;
  182. }
  183. .btn-confirm {
  184. flex: 2;
  185. padding: 20rpx;
  186. border-radius: 12rpx;
  187. background: linear-gradient(135deg, #FF6B35, #F97316);
  188. font-size: 28rpx;
  189. color: #fff;
  190. text-align: center;
  191. border: none;
  192. }
  193. </style>