interaction-log.vue 6.6 KB

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