octopus-add-help.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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="c in contacts" :key="c.id"
  11. :class="{selected: selectedContactId === c.id}"
  12. @click="selectContact(c)">
  13. <text class="member-name">{{ c.name }}</text>
  14. <text class="member-rel">{{ c.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 helpTypes" :key="key"
  23. :class="{selected: selectedType === key}"
  24. @click="selectedType = key">
  25. <text class="type-icon">{{ helpTypeIcons[key] }}</text>
  26. <text class="type-name">{{ name }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 金额(仅经济支持) -->
  31. <view class="form-section" v-if="selectedType === 'MONEY'">
  32. <text class="section-label">金额(选填)</text>
  33. <input class="amount-input" type="digit" v-model="amount"
  34. placeholder="请输入金额,单位:元" />
  35. </view>
  36. <!-- 描述 -->
  37. <view class="form-section">
  38. <text class="section-label">描述(选填)</text>
  39. <textarea class="desc-input" v-model="description"
  40. placeholder="简单描述一下这次帮助..." maxlength="256"></textarea>
  41. </view>
  42. <!-- 提交按钮 -->
  43. <view class="submit-bar">
  44. <button class="btn-submit" @click="onSubmit" :disabled="!canSubmit">保存记录</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { getContactList, addOctopusHelpLog } from '../../utils/api.js'
  50. export default {
  51. data() {
  52. return {
  53. contacts: [],
  54. selectedContactId: null,
  55. selectedType: '',
  56. amount: '',
  57. description: '',
  58. helpTypes: {
  59. MONEY: '经济支持',
  60. ITEM: '物质帮助',
  61. EMOTION: '情感支持',
  62. RESOURCE: '资源帮助',
  63. SKILL: '技能帮助',
  64. TIME: '时间帮助',
  65. OTHER: '其他'
  66. },
  67. helpTypeIcons: {
  68. MONEY: '💰',
  69. ITEM: '📦',
  70. EMOTION: '💕',
  71. RESOURCE: '📚',
  72. SKILL: '🛠️',
  73. TIME: '⏰',
  74. OTHER: '🤝'
  75. }
  76. }
  77. },
  78. computed: {
  79. canSubmit() {
  80. return this.selectedContactId && this.selectedType
  81. }
  82. },
  83. onLoad(options) {
  84. if (options.contactId) {
  85. this.selectedContactId = Number(options.contactId)
  86. }
  87. this.loadContacts()
  88. },
  89. methods: {
  90. async loadContacts() {
  91. try {
  92. var res = await getContactList({ page: 1, size: 100 })
  93. if (res.code === 200 && res.data) {
  94. this.contacts = res.data.list || (Array.isArray(res.data) ? res.data : [])
  95. }
  96. } catch (e) {
  97. uni.showToast({ title: '加载联系人失败', icon: 'none' })
  98. }
  99. },
  100. selectContact(contact) {
  101. this.selectedContactId = contact.id
  102. },
  103. async onSubmit() {
  104. if (!this.canSubmit) {
  105. uni.showToast({ title: '请选择对象和类型', icon: 'none' })
  106. return
  107. }
  108. try {
  109. var logData = {
  110. contactId: this.selectedContactId,
  111. helpType: this.selectedType,
  112. amount: this.amount,
  113. description: this.description
  114. }
  115. var res = await addOctopusHelpLog(logData)
  116. if (res.code === 200) {
  117. uni.showToast({ title: '记录成功', icon: 'success' })
  118. setTimeout(function() {
  119. uni.navigateBack()
  120. }, 1500)
  121. } else {
  122. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  123. }
  124. } catch (e) {
  125. uni.showToast({ title: '保存失败', icon: 'none' })
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <style scoped>
  132. .container {
  133. min-height: 100vh;
  134. background: #f5f5f5;
  135. padding: 24rpx;
  136. }
  137. .page-header {
  138. padding: 20rpx 0 30rpx;
  139. }
  140. .page-title {
  141. font-size: 36rpx;
  142. font-weight: bold;
  143. color: #333;
  144. }
  145. .form-section {
  146. background: #fff;
  147. border-radius: 16rpx;
  148. padding: 24rpx;
  149. margin-bottom: 20rpx;
  150. }
  151. .section-label {
  152. font-size: 28rpx;
  153. color: #333;
  154. font-weight: 500;
  155. display: block;
  156. margin-bottom: 16rpx;
  157. }
  158. .member-select {
  159. display: flex;
  160. flex-wrap: wrap;
  161. gap: 16rpx;
  162. }
  163. .member-item {
  164. padding: 16rpx 24rpx;
  165. border: 2rpx solid #e0e0e0;
  166. border-radius: 12rpx;
  167. background: #fafafa;
  168. }
  169. .member-item.selected {
  170. border-color: #F97316;
  171. background: #FFF7ED;
  172. }
  173. .member-name {
  174. font-size: 28rpx;
  175. color: #333;
  176. display: block;
  177. }
  178. .member-rel {
  179. font-size: 22rpx;
  180. color: #999;
  181. }
  182. .type-grid {
  183. display: flex;
  184. flex-wrap: wrap;
  185. gap: 16rpx;
  186. }
  187. .type-item {
  188. width: calc(33.33% - 11rpx);
  189. padding: 20rpx 0;
  190. text-align: center;
  191. border: 2rpx solid #e0e0e0;
  192. border-radius: 12rpx;
  193. background: #fafafa;
  194. }
  195. .type-item.selected {
  196. border-color: #F97316;
  197. background: #FFF7ED;
  198. }
  199. .type-icon {
  200. font-size: 40rpx;
  201. display: block;
  202. margin-bottom: 8rpx;
  203. }
  204. .type-name {
  205. font-size: 22rpx;
  206. color: #666;
  207. }
  208. .amount-input {
  209. width: 100%;
  210. height: 88rpx;
  211. background: #fafafa;
  212. border-radius: 12rpx;
  213. padding: 0 20rpx;
  214. font-size: 28rpx;
  215. box-sizing: border-box;
  216. }
  217. .desc-input {
  218. width: 100%;
  219. height: 160rpx;
  220. background: #fafafa;
  221. border-radius: 12rpx;
  222. padding: 20rpx;
  223. font-size: 28rpx;
  224. box-sizing: border-box;
  225. }
  226. .submit-bar {
  227. margin-top: 40rpx;
  228. }
  229. .btn-submit {
  230. width: 100%;
  231. background: #F97316;
  232. color: #fff;
  233. border: none;
  234. border-radius: 12rpx;
  235. padding: 24rpx 0;
  236. font-size: 32rpx;
  237. }
  238. .btn-submit[disabled] {
  239. background: #ccc;
  240. }
  241. </style>