interaction-log.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="container">
  3. <view class="page-header">
  4. <text class="page-title">记录互动</text>
  5. </view>
  6. <!-- 选择互动对象 -->
  7. <view class="form-section">
  8. <text class="section-label">互动对象</text>
  9. <view class="member-select">
  10. <view class="member-item" v-for="m in members" :key="m.id"
  11. :class="{selected: selectedMemberId === m.id}"
  12. @click="selectMember(m)">
  13. <text class="member-name">{{ m.nickname }}</text>
  14. <text class="member-rel">{{ m.relationshipTypeName || m.relationshipType }}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 选择互动类型 -->
  19. <view class="form-section">
  20. <text class="section-label">互动类型</text>
  21. <view class="type-grid">
  22. <view class="type-item" v-for="(name, key) in interactionTypes" :key="key"
  23. :class="{selected: selectedType === key}"
  24. @click="selectedType = key">
  25. <text class="type-icon">{{ typeIcons[key] || '💬' }}</text>
  26. <text class="type-name">{{ name }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 互动描述 -->
  31. <view class="form-section">
  32. <text class="section-label">描述(选填)</text>
  33. <textarea class="desc-input" v-model="description"
  34. placeholder="简单描述一下这次互动..." maxlength="256"></textarea>
  35. </view>
  36. <!-- 互动时间 -->
  37. <view class="form-section">
  38. <text class="section-label">互动时间</text>
  39. <view class="time-selector">
  40. <view class="time-option" :class="{selected: timeType === 'now'}" @click="timeType = 'now'">现在</view>
  41. <view class="time-option" :class="{selected: timeType === 'custom'}" @click="timeType = 'custom'">选择时间</view>
  42. </view>
  43. <view v-if="timeType === 'custom'" class="custom-time">
  44. <picker mode="dateTime" :value="customTime" @change="onTimeChange">
  45. <view class="time-display">{{ customTime || '选择时间' }}</view>
  46. </picker>
  47. </view>
  48. </view>
  49. <!-- 提交按钮 -->
  50. <view class="submit-bar">
  51. <button class="btn-submit" @click="onSubmit" :disabled="!canSubmit">保存记录</button>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { listFamilyMembers, addInteraction, getInteractionTypes } from '../../utils/api.js'
  57. export default {
  58. data() {
  59. return {
  60. members: [],
  61. selectedMemberId: null,
  62. selectedType: '',
  63. description: '',
  64. timeType: 'now',
  65. customTime: '',
  66. interactionTypes: {
  67. dining: '一起用餐',
  68. outgoing: '外出活动',
  69. call: '电话联系',
  70. video: '视频通话',
  71. chat: '聊天交流',
  72. play: '一起游戏',
  73. gift: '赠送礼物'
  74. },
  75. typeIcons: {
  76. dining: '🍽️',
  77. outgoing: '🚗',
  78. call: '📞',
  79. video: '📹',
  80. chat: '💬',
  81. play: '🎮',
  82. gift: '🎁'
  83. }
  84. }
  85. },
  86. computed: {
  87. canSubmit() {
  88. return this.selectedMemberId && this.selectedType
  89. }
  90. },
  91. onLoad(options) {
  92. if (options.memberId) {
  93. this.selectedMemberId = Number(options.memberId)
  94. }
  95. this.loadMembers()
  96. },
  97. methods: {
  98. async loadMembers() {
  99. try {
  100. var res = await listFamilyMembers()
  101. if (res.code === 200 && res.data) {
  102. this.members = res.data || []
  103. }
  104. } catch (e) {
  105. uni.showToast({ title: '加载成员失败', icon: 'none' })
  106. }
  107. },
  108. selectMember(member) {
  109. this.selectedMemberId = member.id
  110. },
  111. onTimeChange(e) {
  112. this.customTime = e.detail.value
  113. },
  114. async onSubmit() {
  115. if (!this.canSubmit) {
  116. uni.showToast({ title: '请选择对象和类型', icon: 'none' })
  117. return
  118. }
  119. try {
  120. var happenedAt = ''
  121. if (this.timeType === 'custom' && this.customTime) {
  122. happenedAt = this.customTime
  123. }
  124. var res = await addInteraction({
  125. fromMemberId: this.selectedMemberId,
  126. toMemberId: this.selectedMemberId,
  127. interactionType: this.selectedType,
  128. description: this.description,
  129. happenedAt: happenedAt
  130. })
  131. if (res.code === 200) {
  132. uni.showToast({ title: '记录成功', icon: 'success' })
  133. setTimeout(function() {
  134. uni.navigateBack()
  135. }, 1500)
  136. } else {
  137. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  138. }
  139. } catch (e) {
  140. uni.showToast({ title: '保存失败', icon: 'none' })
  141. }
  142. }
  143. }
  144. }
  145. </script>
  146. <style scoped>
  147. .container {
  148. min-height: 100vh;
  149. background: #f5f5f5;
  150. padding: 24rpx;
  151. }
  152. .page-header {
  153. padding: 20rpx 0 30rpx;
  154. }
  155. .page-title {
  156. font-size: 36rpx;
  157. font-weight: bold;
  158. color: #333;
  159. }
  160. .form-section {
  161. background: #fff;
  162. border-radius: 16rpx;
  163. padding: 24rpx;
  164. margin-bottom: 20rpx;
  165. }
  166. .section-label {
  167. font-size: 28rpx;
  168. color: #333;
  169. font-weight: 500;
  170. display: block;
  171. margin-bottom: 16rpx;
  172. }
  173. .member-select {
  174. display: flex;
  175. flex-wrap: wrap;
  176. gap: 16rpx;
  177. }
  178. .member-item {
  179. padding: 16rpx 24rpx;
  180. border: 2rpx solid #e0e0e0;
  181. border-radius: 12rpx;
  182. background: #fafafa;
  183. }
  184. .member-item.selected {
  185. border-color: #F97316;
  186. background: #FFF7ED;
  187. }
  188. .member-name {
  189. font-size: 28rpx;
  190. color: #333;
  191. display: block;
  192. }
  193. .member-rel {
  194. font-size: 22rpx;
  195. color: #999;
  196. }
  197. .type-grid {
  198. display: flex;
  199. flex-wrap: wrap;
  200. gap: 16rpx;
  201. }
  202. .type-item {
  203. width: calc(25% - 12rpx);
  204. padding: 20rpx 0;
  205. text-align: center;
  206. border: 2rpx solid #e0e0e0;
  207. border-radius: 12rpx;
  208. background: #fafafa;
  209. }
  210. .type-item.selected {
  211. border-color: #F97316;
  212. background: #FFF7ED;
  213. }
  214. .type-icon {
  215. font-size: 40rpx;
  216. display: block;
  217. margin-bottom: 8rpx;
  218. }
  219. .type-name {
  220. font-size: 22rpx;
  221. color: #666;
  222. }
  223. .desc-input {
  224. width: 100%;
  225. height: 160rpx;
  226. background: #fafafa;
  227. border-radius: 12rpx;
  228. padding: 20rpx;
  229. font-size: 28rpx;
  230. box-sizing: border-box;
  231. }
  232. .time-selector {
  233. display: flex;
  234. gap: 16rpx;
  235. margin-bottom: 16rpx;
  236. }
  237. .time-option {
  238. padding: 16rpx 32rpx;
  239. border: 2rpx solid #e0e0e0;
  240. border-radius: 12rpx;
  241. font-size: 28rpx;
  242. color: #666;
  243. }
  244. .time-option.selected {
  245. border-color: #F97316;
  246. color: #F97316;
  247. background: #FFF7ED;
  248. }
  249. .custom-time {
  250. margin-top: 12rpx;
  251. }
  252. .time-display {
  253. padding: 20rpx;
  254. background: #fafafa;
  255. border-radius: 12rpx;
  256. font-size: 28rpx;
  257. color: #333;
  258. }
  259. .submit-bar {
  260. margin-top: 40rpx;
  261. }
  262. .btn-submit {
  263. width: 100%;
  264. background: #F97316;
  265. color: #fff;
  266. border: none;
  267. border-radius: 12rpx;
  268. padding: 24rpx 0;
  269. font-size: 32rpx;
  270. }
  271. .btn-submit[disabled] {
  272. background: #ccc;
  273. }
  274. </style>