interaction-log.vue 6.8 KB

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