ContactCard.vue 8.7 KB

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