FamilyMemberCard.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="family-member-card" :class="{ selected: isSelected, ['role-' + member.effectiveRole]: true }" @click="onClick" @longpress="onLongPress">
  3. <!-- 头像区域 -->
  4. <view class="card-avatar-wrap">
  5. <image class="card-avatar" :src="member.avatar || defaultAvatar" mode="aspectFill" />
  6. <!-- 关系标签徽章 -->
  7. <view class="card-relation-badge" :style="{ background: relationColor }">
  8. <text class="card-relation-text">{{ member.relationship || member.relativeLabel || member.roleLabel || '成员' }}</text>
  9. </view>
  10. <!-- 配偶标记 -->
  11. <view class="card-spouse-mark" v-if="member.isSpouse">
  12. <text class="spouse-icon">💍</text>
  13. </view>
  14. </view>
  15. <!-- 关系现状三色点:信任/亲密度/沟通 -->
  16. <view class="card-relation-dots">
  17. <view class="relation-dot" v-for="(color, idx) in relationDotColors" :key="idx" :style="{ background: color }"></view>
  18. </view>
  19. <!-- 昵称 -->
  20. <text class="card-nickname">{{ member.nickname }}</text>
  21. <!-- 辈分标签 -->
  22. <view class="card-generation-line" v-if="member.generation">
  23. <text class="card-generation-text">第{{ member.generation }}代</text>
  24. </view>
  25. <!-- 联系方式 -->
  26. <view class="card-contact-row" v-if="member.phone" @click.stop="onCall">
  27. <text class="contact-icon">📞</text>
  28. <text class="contact-phone">{{ member.phone }}</text>
  29. </view>
  30. <!-- 能量分数 -->
  31. <view class="card-energy" v-if="energyScore !== null && energyScore !== undefined">
  32. <text class="energy-value">{{ energyScore }}</text>
  33. <text class="energy-unit">分</text>
  34. </view>
  35. <!-- 选中标记 -->
  36. <view class="card-selected-mark" v-if="isSelected">
  37. <text class="mark-icon">✓</text>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. member: { type: Object, required: true },
  45. isSelected: { type: Boolean, default: false },
  46. energyScore: { type: Number, default: null }
  47. },
  48. computed: {
  49. defaultAvatar: function() {
  50. return '/static/default-avatar.png'
  51. },
  52. relationColor: function() {
  53. var rel = this.member && this.member.relationship
  54. if (rel === '爸爸' || rel === '妈妈' || rel === '父亲' || rel === '母亲') return '#F97316'
  55. if (rel === '儿子' || rel === '女儿') return '#0EA5E9'
  56. if (rel === '爷爷' || rel === '奶奶' || rel === '外公' || rel === '外婆') return '#6B7280'
  57. if (rel === '哥哥' || rel === '姐姐' || rel === '弟弟' || rel === '妹妹') return '#10B981'
  58. if (this.member && this.member.isSpouse) return '#EC4899'
  59. var role = this.member && this.member.effectiveRole
  60. if (role === 'parent') return '#F97316'
  61. if (role === 'child') return '#0EA5E9'
  62. if (role === 'teacher') return '#8B5CF6'
  63. return '#9CA3AF'
  64. },
  65. // 关系现状三色点颜色:信任/亲密度/沟通(绿≥70 / 黄40-69 / 红<40 / 灰空)
  66. relationDotColors: function() {
  67. var m = this.member
  68. var empty = '#E5E7EB'
  69. if (!m) return [empty, empty, empty]
  70. var keys = ['trustScore', 'intimacyScore', 'communicationScore']
  71. return keys.map(function(k) {
  72. var v = Number(m[k]) || 0
  73. if (v <= 0) return empty
  74. if (v >= 70) return '#10B981'
  75. if (v >= 40) return '#F59E0B'
  76. return '#EF4444'
  77. })
  78. }
  79. },
  80. methods: {
  81. onClick: function() {
  82. this.$emit('select', this.member)
  83. },
  84. onLongPress: function() {
  85. this.$emit('longpress', this.member)
  86. },
  87. onCall: function() {
  88. if (this.member && this.member.phone) {
  89. uni.makePhoneCall({ phoneNumber: this.member.phone })
  90. }
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .family-member-card {
  97. display: flex;
  98. flex-direction: column;
  99. align-items: center;
  100. width: 110rpx;
  101. padding: 10rpx 8rpx;
  102. border-radius: 16rpx;
  103. background: #FFFFFF;
  104. border: 2rpx solid transparent;
  105. position: relative;
  106. flex-shrink: 0;
  107. }
  108. .family-member-card.selected {
  109. border-color: #F97316;
  110. box-shadow: 0 0 0 2rpx rgba(249, 115, 22, 0.15);
  111. }
  112. .card-avatar-wrap {
  113. position: relative;
  114. width: 64rpx;
  115. height: 64rpx;
  116. margin-bottom: 6rpx;
  117. }
  118. .card-avatar {
  119. width: 64rpx;
  120. height: 64rpx;
  121. border-radius: 50%;
  122. background: #F3F4F6;
  123. }
  124. .card-relation-badge {
  125. position: absolute;
  126. bottom: -4rpx;
  127. left: 50%;
  128. transform: translateX(-50%);
  129. padding: 1rpx 8rpx;
  130. border-radius: 10rpx;
  131. white-space: nowrap;
  132. max-width: 84rpx;
  133. }
  134. .card-relation-text {
  135. font-size: 16rpx;
  136. color: #FFFFFF;
  137. font-weight: 500;
  138. line-height: 1.4;
  139. }
  140. .card-spouse-mark {
  141. position: absolute;
  142. top: -4rpx;
  143. right: -4rpx;
  144. width: 24rpx;
  145. height: 24rpx;
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. }
  150. .spouse-icon {
  151. font-size: 18rpx;
  152. }
  153. .card-relation-dots {
  154. display: flex;
  155. flex-direction: row;
  156. justify-content: center;
  157. margin-top: 4rpx;
  158. height: 12rpx;
  159. }
  160. .relation-dot {
  161. width: 12rpx;
  162. height: 12rpx;
  163. border-radius: 50%;
  164. margin: 0 4rpx;
  165. }
  166. .card-nickname {
  167. font-size: 22rpx;
  168. color: #374151;
  169. font-weight: 600;
  170. text-align: center;
  171. line-height: 1.3;
  172. max-width: 100rpx;
  173. overflow: hidden;
  174. text-overflow: ellipsis;
  175. white-space: nowrap;
  176. }
  177. .card-generation-line {
  178. margin-top: 2rpx;
  179. }
  180. .card-generation-text {
  181. font-size: 14rpx;
  182. color: #9CA3AF;
  183. }
  184. .card-contact-row {
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. margin-top: 2rpx;
  189. }
  190. .contact-icon {
  191. font-size: 18rpx;
  192. }
  193. .contact-phone {
  194. font-size: 16rpx;
  195. color: #3B82F6;
  196. margin-left: 2rpx;
  197. }
  198. .card-energy {
  199. display: flex;
  200. align-items: baseline;
  201. justify-content: center;
  202. margin-top: 2rpx;
  203. }
  204. .energy-value {
  205. font-size: 20rpx;
  206. color: #F97316;
  207. font-weight: bold;
  208. }
  209. .energy-unit {
  210. font-size: 16rpx;
  211. color: #9CA3AF;
  212. margin-left: 2rpx;
  213. }
  214. .card-selected-mark {
  215. position: absolute;
  216. top: 4rpx;
  217. right: 4rpx;
  218. width: 24rpx;
  219. height: 24rpx;
  220. border-radius: 50%;
  221. background: #F97316;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. }
  226. .mark-icon {
  227. font-size: 16rpx;
  228. color: #FFFFFF;
  229. font-weight: bold;
  230. }
  231. </style>