FamilyMemberCard.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. import { BrandColors } from '../utils/brand-colors.js'
  43. export default {
  44. props: {
  45. member: { type: Object, required: true },
  46. isSelected: { type: Boolean, default: false },
  47. energyScore: { type: Number, default: null }
  48. },
  49. computed: {
  50. defaultAvatar: function() {
  51. return '/static/default-avatar.png'
  52. },
  53. relationColor: function() {
  54. var rel = this.member && this.member.relationship
  55. if (rel === '爸爸' || rel === '妈妈' || rel === '父亲' || rel === '母亲') return BrandColors.primary
  56. if (rel === '儿子' || rel === '女儿') return BrandColors.infoSky
  57. if (rel === '爷爷' || rel === '奶奶' || rel === '外公' || rel === '外婆') return BrandColors.textSlate
  58. if (rel === '哥哥' || rel === '姐姐' || rel === '弟弟' || rel === '妹妹') return BrandColors.success
  59. if (this.member && this.member.isSpouse) return BrandColors.pink
  60. var role = this.member && this.member.effectiveRole
  61. if (role === 'parent') return BrandColors.primary
  62. if (role === 'child') return BrandColors.infoSky
  63. if (role === 'teacher') return BrandColors.violet
  64. return '#9CA3AF'
  65. },
  66. // 关系现状三色点颜色:信任/亲密度/沟通(绿≥70 / 黄40-69 / 红<40 / 灰空)
  67. relationDotColors: function() {
  68. var m = this.member
  69. var empty = '#E5E7EB'
  70. if (!m) return [empty, empty, empty]
  71. var keys = ['trustScore', 'intimacyScore', 'communicationScore']
  72. return keys.map(function(k) {
  73. var v = Number(m[k]) || 0
  74. if (v <= 0) return empty
  75. if (v >= 70) return BrandColors.success
  76. if (v >= 40) return BrandColors.wealth
  77. return BrandColors.danger
  78. })
  79. }
  80. },
  81. methods: {
  82. onClick: function() {
  83. this.$emit('select', this.member)
  84. },
  85. onLongPress: function() {
  86. this.$emit('longpress', this.member)
  87. },
  88. onCall: function() {
  89. if (this.member && this.member.phone) {
  90. uni.makePhoneCall({ phoneNumber: this.member.phone })
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. .family-member-card {
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. width: 110rpx;
  102. padding: 10rpx 8rpx;
  103. border-radius: 16rpx;
  104. background: $app-surface;
  105. border: 2rpx solid transparent;
  106. position: relative;
  107. flex-shrink: 0;
  108. }
  109. .family-member-card.selected {
  110. border-color: $brand-primary;
  111. box-shadow: 0 0 0 2rpx rgba(249, 115, 22, 0.15);
  112. }
  113. .card-avatar-wrap {
  114. position: relative;
  115. width: 64rpx;
  116. height: 64rpx;
  117. margin-bottom: 6rpx;
  118. }
  119. .card-avatar {
  120. width: 64rpx;
  121. height: 64rpx;
  122. border-radius: 50%;
  123. background: $facade-fill-gray-100;
  124. }
  125. .card-relation-badge {
  126. position: absolute;
  127. bottom: -4rpx;
  128. left: 50%;
  129. transform: translateX(-50%);
  130. padding: 1rpx 8rpx;
  131. border-radius: 10rpx;
  132. white-space: nowrap;
  133. max-width: 84rpx;
  134. }
  135. .card-relation-text {
  136. font-size: 16rpx;
  137. color: $app-surface;
  138. font-weight: 500;
  139. line-height: 1.4;
  140. }
  141. .card-spouse-mark {
  142. position: absolute;
  143. top: -4rpx;
  144. right: -4rpx;
  145. width: 24rpx;
  146. height: 24rpx;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. }
  151. .spouse-icon {
  152. font-size: 18rpx;
  153. }
  154. .card-relation-dots {
  155. display: flex;
  156. flex-direction: row;
  157. justify-content: center;
  158. margin-top: 4rpx;
  159. height: 12rpx;
  160. }
  161. .relation-dot {
  162. width: 12rpx;
  163. height: 12rpx;
  164. border-radius: 50%;
  165. margin: 0 4rpx;
  166. }
  167. .card-nickname {
  168. font-size: 22rpx;
  169. color: $facade-text-gray-700;
  170. font-weight: 600;
  171. text-align: center;
  172. line-height: 1.3;
  173. max-width: 100rpx;
  174. overflow: hidden;
  175. text-overflow: ellipsis;
  176. white-space: nowrap;
  177. }
  178. .card-generation-line {
  179. margin-top: 2rpx;
  180. }
  181. .card-generation-text {
  182. font-size: 14rpx;
  183. color: $facade-text-gray-400;
  184. }
  185. .card-contact-row {
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. margin-top: 2rpx;
  190. }
  191. .contact-icon {
  192. font-size: 18rpx;
  193. }
  194. .contact-phone {
  195. font-size: 16rpx;
  196. color: $status-info;
  197. margin-left: 2rpx;
  198. }
  199. .card-energy {
  200. display: flex;
  201. align-items: baseline;
  202. justify-content: center;
  203. margin-top: 2rpx;
  204. }
  205. .energy-value {
  206. font-size: 20rpx;
  207. color: $brand-primary;
  208. font-weight: bold;
  209. }
  210. .energy-unit {
  211. font-size: 16rpx;
  212. color: $facade-text-gray-400;
  213. margin-left: 2rpx;
  214. }
  215. .card-selected-mark {
  216. position: absolute;
  217. top: 4rpx;
  218. right: 4rpx;
  219. width: 24rpx;
  220. height: 24rpx;
  221. border-radius: 50%;
  222. background: $brand-primary;
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. }
  227. .mark-icon {
  228. font-size: 16rpx;
  229. color: $app-surface;
  230. font-weight: bold;
  231. }
  232. </style>