ContactCard.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="contact-card" @click="$emit('click', contact)">
  3. <view class="card-avatar" :style="{ background: avatarColor }">
  4. <text class="avatar-text">{{ initial }}</text>
  5. </view>
  6. <text class="card-name">{{ contact.name }}</text>
  7. <view class="card-type-tag" :style="{ background: typeColor + '20', color: typeColor }">
  8. {{ typeLabel }}
  9. </view>
  10. <text class="card-known" v-if="contact.knownSince">
  11. 认识 {{ knownYears }} 年
  12. </text>
  13. <text class="card-phone" v-if="contact.phone">{{ contact.phone }}</text>
  14. <view class="card-intimacy">
  15. <text class="intimacy-heart">❤️</text>
  16. <text class="intimacy-value">{{ contact.intimacyLevel }}</text>
  17. </view>
  18. <text class="card-birthday" v-if="contact.birthdayCountdown">
  19. 🎂 {{ contact.birthdayLabel }} · {{ contact.birthdayCountdown }}
  20. </text>
  21. <view class="card-family-status" v-if="contact.familyMemberId">
  22. <text class="family-badge">已是家庭成员</text>
  23. </view>
  24. <view class="card-invite" v-else @click.stop="handleInvite">
  25. <text class="invite-text">邀请加入家庭</text>
  26. </view>
  27. </view>
  28. <view class="invite-modal" v-if="showInviteModal" @click.stop>
  29. <view class="modal-mask" @click="showInviteModal = false"></view>
  30. <view class="modal-content">
  31. <text class="modal-title">邀请加入家庭</text>
  32. <view class="form-row">
  33. <text class="form-label">关系类型</text>
  34. <picker :range="relationshipTypeList" range-key="typeName" @change="onRelationshipChange">
  35. <text class="form-value">{{ selectedRelationshipName || '请选择' }}</text>
  36. </picker>
  37. </view>
  38. <view class="form-row">
  39. <text class="form-label">辈分等级</text>
  40. <picker :range="generationLevelList" @change="onGenerationChange">
  41. <text class="form-value">{{ selectedGeneration || '请选择' }}</text>
  42. </picker>
  43. </view>
  44. <view class="modal-buttons">
  45. <view class="modal-btn cancel" @click="showInviteModal = false">取消</view>
  46. <view class="modal-btn confirm" @click="confirmInvite">确认邀请</view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. props: {
  54. contact: { type: Object, required: true }
  55. },
  56. data: function() {
  57. return {
  58. showInviteModal: false,
  59. relationshipTypeList: [],
  60. selectedRelationshipName: '',
  61. generationLevelList: ['父母(+1)', '子女(-1)', '配偶(0)', '兄弟姐妹(0)', '祖父母(+2)', '孙子女(-2)'],
  62. selectedGeneration: ''
  63. }
  64. },
  65. computed: {
  66. initial: function() {
  67. return this.contact.name ? this.contact.name[0] : '?'
  68. },
  69. typeLabel: function() {
  70. var map = { family: '家人', friend: '朋友', partner: '伴侣', colleague: '同事', other: '其他' }
  71. return map[this.contact.relationshipType] || '其他'
  72. },
  73. typeColor: function() {
  74. var map = { family: '#10B981', friend: '#F59E0B', partner: '#FF6B35', colleague: '#3B82F6', other: '#94A3B8' }
  75. return map[this.contact.relationshipType] || '#94A3B8'
  76. },
  77. avatarColor: function() {
  78. var colors = ['#FF6B35', '#667eea', '#10B981', '#F59E0B', '#8B5CF6', '#EC4899']
  79. var idx = (this.contact.id || 0) % colors.length
  80. return colors[idx]
  81. },
  82. knownYears: function() {
  83. if (!this.contact.knownSince) return 0
  84. var now = new Date()
  85. var known = new Date(this.contact.knownSince)
  86. return Math.floor((now - known) / (365.25 * 86400000))
  87. }
  88. },
  89. methods: {
  90. handleInvite: function() {
  91. this.showInviteModal = true
  92. this.loadRelationshipTypes()
  93. },
  94. loadRelationshipTypes: function() {
  95. var that = this
  96. var app = getApp()
  97. if (!app || !app.globalData || !app.globalData.baseUrl) return
  98. uni.request({
  99. url: app.globalData.baseUrl + '/api/family/member/relationship-types',
  100. method: 'POST',
  101. header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
  102. success: function(res) {
  103. if (res.data && res.data.data) {
  104. that.relationshipTypeList = res.data.data
  105. }
  106. }
  107. })
  108. },
  109. onRelationshipChange: function(e) {
  110. var idx = e.detail.value
  111. var item = this.relationshipTypeList[idx]
  112. if (item) {
  113. this.selectedRelationshipName = item.typeName
  114. }
  115. },
  116. onGenerationChange: function(e) {
  117. this.selectedGeneration = this.generationLevelList[e.detail.value]
  118. },
  119. confirmInvite: function() {
  120. if (!this.selectedRelationshipName) {
  121. uni.showToast({ title: '请选择关系类型', icon: 'none' })
  122. return
  123. }
  124. var that = this
  125. var generationMap = {
  126. '父母(+1)': 'parent',
  127. '子女(-1)': 'child',
  128. '配偶(0)': 'spouse',
  129. '兄弟姐妹(0)': 'sibling',
  130. '祖父母(+2)': 'grandparent',
  131. '孙子女(-2)': 'grandchild'
  132. }
  133. var generationLevel = generationMap[this.selectedGeneration] || 'child'
  134. var selectedItem = this.relationshipTypeList.filter(function(item) {
  135. return item.typeName === that.selectedRelationshipName
  136. })[0]
  137. var app = getApp()
  138. if (!app || !app.globalData || !app.globalData.baseUrl) return
  139. uni.request({
  140. url: app.globalData.baseUrl + '/api/contact/invite-to-family',
  141. method: 'POST',
  142. header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
  143. data: {
  144. contactId: this.contact.id,
  145. relationshipType: selectedItem ? selectedItem.typeKey : 'child',
  146. generationLevel: generationLevel
  147. },
  148. success: function(res) {
  149. if (res.data && res.data.code === 200) {
  150. uni.showToast({ title: '邀请成功', icon: 'success' })
  151. that.showInviteModal = false
  152. that.$emit('invited', that.contact.id)
  153. } else {
  154. uni.showToast({ title: res.data && res.data.message || '邀请失败', icon: 'none' })
  155. }
  156. },
  157. fail: function() {
  158. uni.showToast({ title: '网络错误', icon: 'none' })
  159. }
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. .contact-card {
  167. width: 240rpx;
  168. flex-shrink: 0;
  169. background: #fff;
  170. border-radius: 20rpx;
  171. padding: 24rpx;
  172. margin-right: 16rpx;
  173. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. }
  178. .contact-card:active { opacity: 0.7; }
  179. .card-avatar {
  180. width: 80rpx;
  181. height: 80rpx;
  182. border-radius: 40rpx;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. margin-bottom: 12rpx;
  187. }
  188. .avatar-text {
  189. font-size: 32rpx;
  190. font-weight: bold;
  191. color: #fff;
  192. }
  193. .card-name {
  194. font-size: 28rpx;
  195. font-weight: bold;
  196. color: #333;
  197. margin-bottom: 8rpx;
  198. }
  199. .card-type-tag {
  200. font-size: 20rpx;
  201. padding: 2rpx 14rpx;
  202. border-radius: 10rpx;
  203. margin-bottom: 8rpx;
  204. }
  205. .card-known { font-size: 22rpx; color: #999; margin-bottom: 4rpx; }
  206. .card-phone { font-size: 22rpx; color: #bbb; margin-bottom: 8rpx; }
  207. .card-intimacy {
  208. display: flex;
  209. align-items: center;
  210. margin-bottom: 6rpx;
  211. }
  212. .intimacy-heart { font-size: 22rpx; margin-right: 4rpx; }
  213. .intimacy-value {
  214. font-size: 28rpx;
  215. font-weight: bold;
  216. color: #FF6B35;
  217. }
  218. .card-birthday {
  219. font-size: 20rpx;
  220. color: #EC4899;
  221. }
  222. .card-family-status {
  223. margin-top: 8rpx;
  224. }
  225. .family-badge {
  226. font-size: 20rpx;
  227. color: #10B981;
  228. background: rgba(16, 185, 129, 0.12);
  229. padding: 2rpx 12rpx;
  230. border-radius: 8rpx;
  231. }
  232. .card-invite {
  233. margin-top: 8rpx;
  234. padding: 4rpx 16rpx;
  235. background: #F97316;
  236. border-radius: 10rpx;
  237. }
  238. .invite-text {
  239. font-size: 20rpx;
  240. color: #fff;
  241. }
  242. .invite-modal {
  243. position: fixed;
  244. top: 0;
  245. left: 0;
  246. right: 0;
  247. bottom: 0;
  248. z-index: 999;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. .modal-mask {
  254. position: absolute;
  255. top: 0;
  256. left: 0;
  257. right: 0;
  258. bottom: 0;
  259. background: rgba(0,0,0,0.5);
  260. }
  261. .modal-content {
  262. position: relative;
  263. width: 600rpx;
  264. background: #fff;
  265. border-radius: 20rpx;
  266. padding: 40rpx;
  267. }
  268. .modal-title {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #333;
  272. text-align: center;
  273. margin-bottom: 30rpx;
  274. }
  275. .form-row {
  276. margin-bottom: 20rpx;
  277. }
  278. .form-label {
  279. font-size: 26rpx;
  280. color: #666;
  281. margin-bottom: 8rpx;
  282. }
  283. .form-value {
  284. font-size: 28rpx;
  285. color: #333;
  286. padding: 12rpx 16rpx;
  287. background: #f5f5f5;
  288. border-radius: 8rpx;
  289. }
  290. .modal-buttons {
  291. display: flex;
  292. justify-content: space-between;
  293. margin-top: 30rpx;
  294. }
  295. .modal-btn {
  296. flex: 1;
  297. text-align: center;
  298. padding: 16rpx 0;
  299. border-radius: 10rpx;
  300. font-size: 28rpx;
  301. }
  302. .modal-btn.cancel {
  303. background: #f5f5f5;
  304. color: #666;
  305. margin-right: 16rpx;
  306. }
  307. .modal-btn.confirm {
  308. background: #F97316;
  309. color: #fff;
  310. }
  311. </style>