contact-detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="detail-page">
  3. <!-- 头部 -->
  4. <view class="detail-header">
  5. <view class="header-top">
  6. <text class="back-btn" @click="goBack">← 返回</text>
  7. <text class="page-title">关系详情</text>
  8. <text class="edit-btn" @click="toggleEdit">{{ isEditing ? '取消' : '编辑' }}</text>
  9. </view>
  10. <view class="header-avatar" :style="{ background: avatarColor }">
  11. <text class="avatar-text">{{ initial }}</text>
  12. </view>
  13. <text class="header-name">{{ contact.name || '未知' }}</text>
  14. <text class="header-meta">{{ typeLabel }}</text>
  15. <text class="header-known" v-if="contact.knownSinceLabel">{{ contact.knownSinceLabel }}</text>
  16. <view class="header-intimacy">
  17. <text class="intimacy-heart">❤️</text>
  18. <text class="intimacy-num">{{ contact.intimacyLevel || 0 }}</text>
  19. <text class="intimacy-label">亲密度</text>
  20. </view>
  21. </view>
  22. <!-- 基本信息 -->
  23. <view class="info-section">
  24. <text class="section-title">基本信息</text>
  25. <view class="info-row" v-if="!isEditing">
  26. <text class="info-icon">📞</text>
  27. <text class="info-value">{{ contact.phone || '未填写' }}</text>
  28. </view>
  29. <view class="info-row" v-if="!isEditing && contact.birthdayLabel">
  30. <text class="info-icon">🎂</text>
  31. <text class="info-value">{{ contact.birthdayLabel }}
  32. <text v-if="contact.birthdayCountdown" class="countdown"> · {{ contact.birthdayCountdown }}</text>
  33. </text>
  34. </view>
  35. <view class="info-row" v-if="!isEditing && contact.bio">
  36. <text class="info-icon">📝</text>
  37. <text class="info-value">{{ contact.bio }}</text>
  38. </view>
  39. <view class="info-row" v-if="!isEditing && contact.tags">
  40. <text class="info-icon">🏷️</text>
  41. <text class="info-value">{{ contact.tags }}</text>
  42. </view>
  43. <view class="info-row" v-if="!isEditing && contact.notes">
  44. <text class="info-icon">💬</text>
  45. <text class="info-value">{{ contact.notes }}</text>
  46. </view>
  47. <!-- 编辑模式 -->
  48. <view v-if="isEditing">
  49. <view class="edit-row">
  50. <text class="edit-label">姓名</text>
  51. <input class="edit-input" v-model="editForm.name" />
  52. </view>
  53. <view class="edit-row">
  54. <text class="edit-label">手机号</text>
  55. <input class="edit-input" v-model="editForm.phone" />
  56. </view>
  57. <view class="edit-row">
  58. <text class="edit-label">关系类型</text>
  59. <picker mode="selector" :range="typeOptions" @change="onTypeChange">
  60. <view class="edit-picker">{{ editForm.relationshipTypeLabel || '请选择' }}</view>
  61. </picker>
  62. </view>
  63. <view class="edit-row">
  64. <text class="edit-label">认识时间</text>
  65. <picker mode="date" @change="onDateChange">
  66. <view class="edit-picker">{{ editForm.knownSince || '请选择' }}</view>
  67. </picker>
  68. </view>
  69. <view class="edit-row">
  70. <text class="edit-label">生日</text>
  71. <picker mode="date" @change="onBirthdayChange">
  72. <view class="edit-picker">{{ editForm.birthday || '请选择' }}</view>
  73. </picker>
  74. </view>
  75. <view class="edit-row">
  76. <text class="edit-label">个人介绍</text>
  77. <textarea class="edit-textarea" v-model="editForm.bio" placeholder="选填" />
  78. </view>
  79. <view class="edit-row">
  80. <text class="edit-label">备注</text>
  81. <input class="edit-input" v-model="editForm.notes" placeholder="选填" />
  82. </view>
  83. <button class="btn-save" @click="saveEdit">保存</button>
  84. </view>
  85. </view>
  86. <!-- 互动记录 -->
  87. <view class="interaction-section">
  88. <text class="section-title">互动记录</text>
  89. <view class="interaction-item" v-if="contact.lastContactAt">
  90. <text class="interaction-date">{{ formatDate(contact.lastContactAt) }}</text>
  91. <text class="interaction-desc">标记了联系</text>
  92. </view>
  93. <view class="interaction-item" v-if="contact.createdAt">
  94. <text class="interaction-date">{{ formatDate(contact.createdAt) }}</text>
  95. <text class="interaction-desc">添加了联系人</text>
  96. </view>
  97. <view class="interaction-empty" v-if="!contact.lastContactAt && !contact.updatedAt">
  98. <text>暂无互动记录</text>
  99. </view>
  100. <button class="btn-interaction" @click="markInteraction">📞 标记联系</button>
  101. </view>
  102. <!-- 删除 -->
  103. <view class="danger-section">
  104. <button class="btn-delete" @click="confirmDelete">删除联系人</button>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import { getContactDetail, updateContact, deleteContact, recordContactInteraction } from '../../utils/api.js'
  110. export default {
  111. data: function() {
  112. return {
  113. contactId: null,
  114. contact: {},
  115. isEditing: false,
  116. editForm: {},
  117. typeOptions: ['家人', '朋友', '伴侣', '同事', '其他'],
  118. typeValues: { '家人': 'family', '朋友': 'friend', '伴侣': 'partner', '同事': 'colleague', '其他': 'other' },
  119. reverseTypeValues: { 'family': '家人', 'friend': '朋友', 'partner': '伴侣', 'colleague': '同事', 'other': '其他' }
  120. }
  121. },
  122. computed: {
  123. initial: function() {
  124. return this.contact.name ? this.contact.name[0] : '?'
  125. },
  126. avatarColor: function() {
  127. var colors = ['#FF6B35', '#667eea', '#10B981', '#F59E0B', '#8B5CF6', '#EC4899']
  128. var idx = (this.contact.id || 0) % colors.length
  129. return colors[idx]
  130. },
  131. typeLabel: function() {
  132. var map = { family: '家人', friend: '朋友', partner: '伴侣', colleague: '同事', other: '其他' }
  133. return map[this.contact.relationshipType] || '其他'
  134. }
  135. },
  136. onLoad: function(options) {
  137. if (options.id) {
  138. this.contactId = options.id
  139. this.loadDetail()
  140. }
  141. },
  142. methods: {
  143. loadDetail: function() {
  144. var self = this
  145. if (!this.contactId) return
  146. getContactDetail(this.contactId).then(function(res) {
  147. if (res.code === 200 && res.data) {
  148. self.contact = res.data
  149. } else {
  150. uni.showToast({ title: res.message || '加载失败', icon: 'none' })
  151. }
  152. }).catch(function() {
  153. uni.showToast({ title: '网络错误', icon: 'none' })
  154. })
  155. },
  156. toggleEdit: function() {
  157. if (this.isEditing) {
  158. this.isEditing = false
  159. } else {
  160. this.editForm = {
  161. name: this.contact.name || '',
  162. phone: this.contact.phone || '',
  163. relationshipType: this.contact.relationshipType || '',
  164. relationshipTypeLabel: this.reverseTypeValues[this.contact.relationshipType] || '其他',
  165. knownSince: this.contact.knownSince ? this.contact.knownSince.substring(0, 10) : '',
  166. birthday: this.contact.birthday ? this.contact.birthday.substring(0, 10) : '',
  167. bio: this.contact.bio || '',
  168. notes: this.contact.notes || ''
  169. }
  170. this.isEditing = true
  171. }
  172. },
  173. onTypeChange: function(e) {
  174. var label = this.typeOptions[e.detail.value]
  175. this.editForm.relationshipType = this.typeValues[label] || 'other'
  176. this.editForm.relationshipTypeLabel = label
  177. },
  178. onDateChange: function(e) {
  179. this.editForm.knownSince = e.detail.value
  180. },
  181. onBirthdayChange: function(e) {
  182. this.editForm.birthday = e.detail.value
  183. },
  184. saveEdit: function() {
  185. var self = this
  186. var payload = { id: this.contact.id, name: this.editForm.name, phone: this.editForm.phone }
  187. if (this.editForm.relationshipType) payload.relationshipType = this.editForm.relationshipType
  188. if (this.editForm.knownSince) payload.knownSince = this.editForm.knownSince
  189. if (this.editForm.birthday) payload.birthday = this.editForm.birthday
  190. if (this.editForm.bio !== undefined) payload.bio = this.editForm.bio
  191. if (this.editForm.notes !== undefined) payload.notes = this.editForm.notes
  192. updateContact(payload).then(function(res) {
  193. if (res.code === 200) {
  194. uni.showToast({ title: '保存成功', icon: 'success' })
  195. self.isEditing = false
  196. self.loadDetail()
  197. } else {
  198. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  199. }
  200. }).catch(function() {
  201. uni.showToast({ title: '网络错误', icon: 'none' })
  202. })
  203. },
  204. markInteraction: function() {
  205. var self = this
  206. recordContactInteraction(this.contact.id).then(function(res) {
  207. if (res.code === 200) {
  208. uni.showToast({ title: '已标记联系', icon: 'success' })
  209. self.loadDetail()
  210. } else {
  211. uni.showToast({ title: res.message || '操作失败', icon: 'none' })
  212. }
  213. }).catch(function() {
  214. uni.showToast({ title: '网络错误', icon: 'none' })
  215. })
  216. },
  217. confirmDelete: function() {
  218. var self = this
  219. uni.showModal({
  220. title: '确认删除',
  221. content: '确定要删除该联系人吗?',
  222. success: function(r) {
  223. if (r.confirm) {
  224. deleteContact({ id: self.contact.id }).then(function(res) {
  225. if (res.code === 200) {
  226. uni.showToast({ title: '已删除', icon: 'success' })
  227. setTimeout(function() { uni.navigateBack() }, 500)
  228. } else {
  229. uni.showToast({ title: res.message || '删除失败', icon: 'none' })
  230. }
  231. }).catch(function() {
  232. uni.showToast({ title: '网络错误', icon: 'none' })
  233. })
  234. }
  235. }
  236. })
  237. },
  238. formatDate: function(dateStr) {
  239. if (!dateStr) return '-'
  240. return dateStr.substring(0, 10)
  241. },
  242. goBack: function() {
  243. uni.navigateBack()
  244. }
  245. }
  246. }
  247. </script>
  248. <style scoped>
  249. .detail-page {
  250. min-height: 100vh;
  251. background: #f5f7fa;
  252. padding-bottom: 40rpx;
  253. }
  254. .detail-header {
  255. background: linear-gradient(135deg, #667eea, #764ba2);
  256. padding: 60rpx 30rpx 40rpx;
  257. display: flex;
  258. flex-direction: column;
  259. align-items: center;
  260. color: #fff;
  261. }
  262. .header-top {
  263. width: 100%;
  264. display: flex;
  265. justify-content: space-between;
  266. margin-bottom: 30rpx;
  267. }
  268. .back-btn, .edit-btn {
  269. font-size: 28rpx;
  270. padding: 10rpx 20rpx;
  271. }
  272. .page-title { font-size: 32rpx; font-weight: bold; }
  273. .header-avatar {
  274. width: 120rpx;
  275. height: 120rpx;
  276. border-radius: 60rpx;
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. margin-bottom: 16rpx;
  281. border: 4rpx solid rgba(255,255,255,0.4);
  282. }
  283. .avatar-text { font-size: 48rpx; font-weight: bold; color: #fff; }
  284. .header-name { font-size: 36rpx; font-weight: bold; margin-bottom: 8rpx; }
  285. .header-meta { font-size: 26rpx; opacity: 0.9; margin-bottom: 4rpx; }
  286. .header-known { font-size: 24rpx; opacity: 0.7; margin-bottom: 12rpx; }
  287. .header-intimacy { display: flex; align-items: center; gap: 8rpx; }
  288. .intimacy-heart { font-size: 32rpx; }
  289. .intimacy-num { font-size: 40rpx; font-weight: bold; }
  290. .intimacy-label { font-size: 24rpx; opacity: 0.8; }
  291. .info-section, .interaction-section {
  292. background: #fff;
  293. margin: 20rpx;
  294. border-radius: 20rpx;
  295. padding: 30rpx;
  296. }
  297. .section-title {
  298. font-size: 28rpx;
  299. font-weight: bold;
  300. color: #333;
  301. display: block;
  302. margin-bottom: 20rpx;
  303. }
  304. .info-row {
  305. display: flex;
  306. align-items: flex-start;
  307. margin-bottom: 16rpx;
  308. }
  309. .info-icon { font-size: 28rpx; margin-right: 12rpx; width: 40rpx; }
  310. .info-value { font-size: 26rpx; color: #555; flex: 1; }
  311. .countdown { color: #EC4899; }
  312. .edit-row {
  313. margin-bottom: 20rpx;
  314. }
  315. .edit-label {
  316. font-size: 26rpx;
  317. color: #666;
  318. display: block;
  319. margin-bottom: 8rpx;
  320. }
  321. .edit-input {
  322. border: 1rpx solid #ddd;
  323. border-radius: 12rpx;
  324. padding: 24rpx 20rpx;
  325. font-size: 28rpx;
  326. width: 100%;
  327. box-sizing: border-box;
  328. min-height: 80rpx;
  329. }
  330. .edit-textarea {
  331. border: 1rpx solid #ddd;
  332. border-radius: 12rpx;
  333. padding: 24rpx 20rpx;
  334. font-size: 28rpx;
  335. width: 100%;
  336. box-sizing: border-box;
  337. min-height: 160rpx;
  338. }
  339. .edit-picker {
  340. border: 1rpx solid #ddd;
  341. border-radius: 12rpx;
  342. padding: 24rpx 20rpx;
  343. font-size: 28rpx;
  344. min-height: 80rpx;
  345. display: flex;
  346. align-items: center;
  347. }
  348. .btn-save {
  349. width: 100%;
  350. padding: 24rpx;
  351. border-radius: 12rpx;
  352. background: linear-gradient(135deg, #FF6B35, #F97316);
  353. font-size: 30rpx;
  354. color: #fff;
  355. text-align: center;
  356. border: none;
  357. margin-top: 20rpx;
  358. }
  359. .interaction-item {
  360. display: flex;
  361. justify-content: space-between;
  362. padding: 16rpx 0;
  363. border-bottom: 1rpx solid #f0f0f0;
  364. }
  365. .interaction-date { font-size: 24rpx; color: #999; }
  366. .interaction-desc { font-size: 26rpx; color: #555; }
  367. .interaction-empty { text-align: center; padding: 30rpx; color: #999; font-size: 26rpx; }
  368. .btn-interaction {
  369. width: 100%;
  370. padding: 24rpx;
  371. border-radius: 12rpx;
  372. background: linear-gradient(135deg, #667eea, #764ba2);
  373. font-size: 30rpx;
  374. color: #fff;
  375. text-align: center;
  376. border: none;
  377. margin-top: 20rpx;
  378. }
  379. .danger-section { margin: 20rpx; }
  380. .btn-delete {
  381. width: 100%;
  382. padding: 24rpx;
  383. border-radius: 12rpx;
  384. background: #fff;
  385. border: 1rpx solid #ff4d4f;
  386. font-size: 28rpx;
  387. color: #ff4d4f;
  388. text-align: center;
  389. }
  390. </style>