ContactCard.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="contact-card-root" :style="{ '--font-scale': fontScale }">
  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. import { BrandColors } from '../../../utils/brand-colors.js'
  55. import config from '@/config.js'
  56. import { parseDate } from '@/utils/format.js'
  57. import fontScaleMixin from '@/mixins/font-scale.js'
  58. export default {
  59. mixins: [fontScaleMixin],
  60. props: {
  61. contact: { type: Object, required: true }
  62. },
  63. data: function() {
  64. return {
  65. showInviteModal: false,
  66. relationshipTypeList: [
  67. { typeName: '家人', typeKey: 'family' },
  68. { typeName: '朋友', typeKey: 'friend' },
  69. { typeName: '伴侣', typeKey: 'partner' },
  70. { typeName: '同事', typeKey: 'colleague' },
  71. { typeName: '其他', typeKey: 'other' }
  72. ],
  73. selectedRelationshipName: '',
  74. selectedRelationshipKey: '',
  75. generationLevelList: ['父母(+1)', '子女(-1)', '配偶(0)', '兄弟姐妹(0)', '祖父母(+2)', '孙子女(-2)'],
  76. selectedGeneration: ''
  77. }
  78. },
  79. computed: {
  80. initial: function() {
  81. return this.contact.name ? this.contact.name[0] : '?'
  82. },
  83. typeLabel: function() {
  84. var map = { family: '家人', friend: '朋友', partner: '伴侣', colleague: '同事', other: '其他' }
  85. return map[this.contact.relationshipType] || '其他'
  86. },
  87. typeColor: function() {
  88. var map = { family: BrandColors.success, friend: BrandColors.wealth, partner: BrandColors.mindAccent, colleague: BrandColors.infoBlue, other: BrandColors.appTextSubtle }
  89. return map[this.contact.relationshipType] || BrandColors.appTextSubtle
  90. },
  91. avatarColor: function() {
  92. var colors = [BrandColors.mindAccent, '#667eea', BrandColors.success, BrandColors.wealth, BrandColors.violet, BrandColors.pink]
  93. var idx = (this.contact.id || 0) % colors.length
  94. return colors[idx]
  95. },
  96. knownYears: function() {
  97. if (!this.contact.knownSince) return 0
  98. var now = new Date()
  99. var known = parseDate(this.contact.knownSince)
  100. if (!known) return 0
  101. return Math.floor((now - known) / (365.25 * 86400000))
  102. }
  103. },
  104. methods: {
  105. handleInvite: function() {
  106. this.showInviteModal = true
  107. // 预填联系人已有的关系类型
  108. var self = this
  109. this.selectedRelationshipKey = this.contact.relationshipType || 'other'
  110. for (var i = 0; i < this.relationshipTypeList.length; i++) {
  111. if (this.relationshipTypeList[i].typeKey === this.selectedRelationshipKey) {
  112. this.selectedRelationshipName = this.relationshipTypeList[i].typeName
  113. break
  114. }
  115. }
  116. },
  117. onRelationshipChange: function(e) {
  118. var idx = e.detail.value
  119. var item = this.relationshipTypeList[idx]
  120. if (item) {
  121. this.selectedRelationshipName = item.typeName
  122. this.selectedRelationshipKey = item.typeKey
  123. }
  124. },
  125. onGenerationChange: function(e) {
  126. this.selectedGeneration = this.generationLevelList[e.detail.value]
  127. },
  128. confirmInvite: function() {
  129. if (!this.selectedRelationshipName) {
  130. uni.showToast({ title: '请选择关系类型', icon: 'none' })
  131. return
  132. }
  133. var that = this
  134. var generationMap = {
  135. '父母(+1)': 'parent',
  136. '子女(-1)': 'child',
  137. '配偶(0)': 'spouse',
  138. '兄弟姐妹(0)': 'sibling',
  139. '祖父母(+2)': 'grandparent',
  140. '孙子女(-2)': 'grandchild'
  141. }
  142. var generationLevel = generationMap[this.selectedGeneration] || 'child'
  143. uni.request({
  144. url: config.API_BASE_URL + '/api/contact/invite-to-family',
  145. method: 'POST',
  146. header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
  147. data: {
  148. contactId: this.contact.id,
  149. relationshipType: this.selectedRelationshipKey || 'other',
  150. generationLevel: generationLevel
  151. },
  152. success: function(res) {
  153. if (res.data && res.data.code === 200) {
  154. uni.showToast({ title: '邀请成功', icon: 'success' })
  155. that.showInviteModal = false
  156. that.$emit('invited', that.contact.id)
  157. } else {
  158. uni.showToast({ title: res.data && res.data.message || '邀请失败', icon: 'none' })
  159. }
  160. },
  161. fail: function() {
  162. uni.showToast({ title: '网络错误', icon: 'none' })
  163. }
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped lang="scss">
  170. .contact-card {
  171. width: 240rpx;
  172. flex-shrink: 0;
  173. background: $app-surface;
  174. border-radius: 24rpx;
  175. padding: 24rpx;
  176. margin-right: 16rpx;
  177. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  178. display: flex;
  179. flex-direction: column;
  180. align-items: center;
  181. }
  182. .contact-card:active { opacity: 0.7; }
  183. .card-avatar {
  184. width: 80rpx;
  185. height: 80rpx;
  186. border-radius: 24rpx;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. margin-bottom: 12rpx;
  191. }
  192. .avatar-text {
  193. font-size: calc(32rpx * var(--font-scale, 1));
  194. font-weight: bold;
  195. color: $app-surface;
  196. }
  197. .card-name {
  198. font-size: calc(28rpx * var(--font-scale, 1));
  199. font-weight: bold;
  200. color: $facade-text-strong;
  201. margin-bottom: 8rpx;
  202. }
  203. .card-type-tag {
  204. font-size: calc(20rpx * var(--font-scale, 1));
  205. padding: 2rpx 14rpx;
  206. border-radius: 8rpx;
  207. margin-bottom: 8rpx;
  208. }
  209. .card-known { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-bottom: 4rpx; }
  210. .card-phone { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-ghost-light; margin-bottom: 8rpx; }
  211. .card-intimacy {
  212. display: flex;
  213. align-items: center;
  214. margin-bottom: 6rpx;
  215. }
  216. .intimacy-heart { font-size: calc(22rpx * var(--font-scale, 1)); margin-right: 4rpx; }
  217. .intimacy-value {
  218. font-size: calc(28rpx * var(--font-scale, 1));
  219. font-weight: bold;
  220. color: $mind-accent;
  221. }
  222. .card-birthday {
  223. font-size: calc(20rpx * var(--font-scale, 1));
  224. color: $accent-pink;
  225. }
  226. .card-family-status {
  227. margin-top: 8rpx;
  228. }
  229. .family-badge {
  230. font-size: calc(20rpx * var(--font-scale, 1));
  231. color: $status-success;
  232. background: rgba(16, 185, 129, 0.12);
  233. padding: 2rpx 12rpx;
  234. border-radius: 8rpx;
  235. }
  236. .card-invite {
  237. margin-top: 8rpx;
  238. padding: 4rpx 16rpx;
  239. background: $brand-primary;
  240. border-radius: 8rpx;
  241. }
  242. .invite-text {
  243. font-size: calc(20rpx * var(--font-scale, 1));
  244. color: $app-surface;
  245. }
  246. .invite-modal {
  247. position: fixed;
  248. top: 0;
  249. left: 0;
  250. right: 0;
  251. bottom: 0;
  252. z-index: 999;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. }
  257. .modal-mask {
  258. position: absolute;
  259. top: 0;
  260. left: 0;
  261. right: 0;
  262. bottom: 0;
  263. background: rgba(0,0,0,0.5);
  264. }
  265. .modal-content {
  266. position: relative;
  267. width: 600rpx;
  268. background: $app-surface;
  269. border-radius: 24rpx;
  270. padding: 40rpx;
  271. }
  272. .modal-title {
  273. font-size: calc(32rpx * var(--font-scale, 1));
  274. font-weight: bold;
  275. color: $facade-text-strong;
  276. text-align: center;
  277. margin-bottom: $uni-space-lg;
  278. }
  279. .form-row {
  280. margin-bottom: 20rpx;
  281. }
  282. .form-label {
  283. font-size: calc(26rpx * var(--font-scale, 1));
  284. color: $facade-text-body;
  285. margin-bottom: 8rpx;
  286. }
  287. .form-value {
  288. font-size: calc(28rpx * var(--font-scale, 1));
  289. color: $facade-text-strong;
  290. padding: 12rpx 16rpx;
  291. background: $facade-fill-2;
  292. border-radius: 8rpx;
  293. }
  294. .modal-buttons {
  295. display: flex;
  296. justify-content: space-between;
  297. margin-top: $uni-space-lg;
  298. }
  299. .modal-btn {
  300. flex: 1;
  301. text-align: center;
  302. padding: 16rpx 0;
  303. border-radius: 8rpx;
  304. font-size: calc(28rpx * var(--font-scale, 1));
  305. }
  306. .modal-btn.cancel {
  307. background: $facade-fill-2;
  308. color: $facade-text-body;
  309. margin-right: 16rpx;
  310. }
  311. .modal-btn.confirm {
  312. background: $brand-primary;
  313. color: $app-surface;
  314. }
  315. </style>