create.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="container">
  3. <view class="form-card">
  4. <view class="form-title">添加心愿</view>
  5. <!-- 心愿名称 -->
  6. <view class="form-item">
  7. <view class="form-label">心愿名称 <text class="required">*</text></view>
  8. <input
  9. v-model="form.title"
  10. placeholder="请输入心愿名称"
  11. maxlength="50"
  12. />
  13. </view>
  14. <!-- 分类 -->
  15. <view class="form-item">
  16. <view class="form-label">分类</view>
  17. <view class="category-list">
  18. <view
  19. v-for="cat in categories"
  20. :key="cat.value"
  21. class="category-item"
  22. :class="{ active: form.category === cat.value }"
  23. @click="form.category = cat.value"
  24. >
  25. {{ cat.label }}
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 详细描述 -->
  30. <view class="form-item">
  31. <view class="form-label">详细描述</view>
  32. <textarea
  33. v-model="form.description"
  34. placeholder="描述一下这个心愿(可选)"
  35. maxlength="200"
  36. />
  37. </view>
  38. <!-- 提示 -->
  39. <view class="form-tip">
  40. <text class="tip-icon">💡</text>
  41. <text class="tip-text">创建心愿后,家长会为它设定所需积分</text>
  42. </view>
  43. </view>
  44. <!-- 提交按钮 -->
  45. <button class="btn-submit" @click="submitForm" :loading="submitting">
  46. 提交心愿
  47. </button>
  48. </view>
  49. </template>
  50. <script>
  51. import { createWish } from '../../utils/api.js'
  52. export default {
  53. data() {
  54. return {
  55. form: {
  56. title: '',
  57. description: '',
  58. category: ''
  59. },
  60. categories: [
  61. { label: '玩具', value: '玩具' },
  62. { label: '图书', value: '图书' },
  63. { label: '美食', value: '美食' },
  64. { label: '娱乐', value: '娱乐' },
  65. { label: '活动', value: '活动' },
  66. { label: '其他', value: '其他' }
  67. ],
  68. submitting: false
  69. }
  70. },
  71. methods: {
  72. async submitForm() {
  73. // 验证
  74. if (!this.form.title || !this.form.title.trim()) {
  75. uni.showToast({ title: '请输入心愿名称', icon: 'none' })
  76. return
  77. }
  78. this.submitting = true
  79. try {
  80. await createWish({
  81. title: this.form.title.trim(),
  82. description: this.form.description,
  83. category: this.form.category
  84. })
  85. uni.showToast({ title: '提交成功', icon: 'success' })
  86. // 返回上一页
  87. setTimeout(() => {
  88. uni.navigateBack()
  89. }, 1500)
  90. } catch (e) {
  91. uni.showToast({ title: e.message || '提交失败', icon: 'none' })
  92. } finally {
  93. this.submitting = false
  94. }
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .container {
  101. padding: 30rpx;
  102. min-height: 100vh;
  103. background: #f5f5f5;
  104. }
  105. .form-card {
  106. background: #fff;
  107. border-radius: 20rpx;
  108. padding: 40rpx;
  109. margin-bottom: 30rpx;
  110. }
  111. .form-title {
  112. font-size: 36rpx;
  113. font-weight: bold;
  114. color: #333;
  115. margin-bottom: 40rpx;
  116. text-align: center;
  117. }
  118. .form-item {
  119. margin-bottom: 30rpx;
  120. }
  121. .form-label {
  122. font-size: 28rpx;
  123. color: #333;
  124. margin-bottom: 15rpx;
  125. display: block;
  126. }
  127. .required {
  128. color: #F97316;
  129. }
  130. .form-item input,
  131. .form-item textarea {
  132. width: 100%;
  133. background: #f5f5f5;
  134. border-radius: 15rpx;
  135. padding: 20rpx;
  136. font-size: 28rpx;
  137. border: none;
  138. }
  139. .form-item textarea {
  140. min-height: 150rpx;
  141. }
  142. /* 分类选择 */
  143. .category-list {
  144. display: flex;
  145. flex-wrap: wrap;
  146. gap: 15rpx;
  147. }
  148. .category-item {
  149. padding: 15rpx 30rpx;
  150. background: #f5f5f5;
  151. border-radius: 30rpx;
  152. font-size: 26rpx;
  153. color: #666;
  154. }
  155. .category-item.active {
  156. background: linear-gradient(135deg, #F97316, #FB923C);
  157. color: #fff;
  158. }
  159. /* 提示 */
  160. .form-tip {
  161. display: flex;
  162. align-items: center;
  163. background: #FFF5F5;
  164. padding: 20rpx;
  165. border-radius: 15rpx;
  166. margin-top: 20rpx;
  167. }
  168. .tip-icon {
  169. font-size: 32rpx;
  170. margin-right: 15rpx;
  171. }
  172. .tip-text {
  173. font-size: 24rpx;
  174. color: #666;
  175. flex: 1;
  176. }
  177. /* 提交按钮 */
  178. .btn-submit {
  179. background: linear-gradient(135deg, #F97316, #FB923C);
  180. color: #fff;
  181. font-size: 32rpx;
  182. padding: 24rpx;
  183. border-radius: 50rpx;
  184. margin-top: 40rpx;
  185. }
  186. </style>