create.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  53. export default {
  54. mixins: [fontScaleMixin],
  55. data() {
  56. return {
  57. form: {
  58. title: '',
  59. description: '',
  60. category: ''
  61. },
  62. categories: [
  63. { label: '玩具', value: '玩具' },
  64. { label: '图书', value: '图书' },
  65. { label: '美食', value: '美食' },
  66. { label: '娱乐', value: '娱乐' },
  67. { label: '活动', value: '活动' },
  68. { label: '其他', value: '其他' }
  69. ],
  70. submitting: false
  71. }
  72. },
  73. methods: {
  74. async submitForm() {
  75. // 验证
  76. if (!this.form.title || !this.form.title.trim()) {
  77. uni.showToast({ title: '请输入心愿名称', icon: 'none' })
  78. return
  79. }
  80. this.submitting = true
  81. try {
  82. await createWish({
  83. title: this.form.title.trim(),
  84. description: this.form.description,
  85. category: this.form.category
  86. })
  87. uni.showToast({ title: '提交成功', icon: 'success' })
  88. // 返回上一页
  89. setTimeout(() => {
  90. uni.navigateBack()
  91. }, 1500)
  92. } catch (e) {
  93. uni.showToast({ title: e.message || '提交失败', icon: 'none' })
  94. } finally {
  95. this.submitting = false
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .container {
  103. padding: $uni-space-page;
  104. min-height: 100vh;
  105. background: $facade-fill-2;
  106. }
  107. .form-card {
  108. background: $app-surface;
  109. border-radius: 24rpx;
  110. padding: 40rpx;
  111. margin-bottom: $uni-space-lg;
  112. }
  113. .form-title {
  114. font-size: calc(36rpx * var(--font-scale, 1));
  115. font-weight: bold;
  116. color: $facade-text-strong;
  117. margin-bottom: 40rpx;
  118. text-align: center;
  119. }
  120. .form-item {
  121. margin-bottom: $uni-space-lg;
  122. }
  123. .form-label {
  124. font-size: calc(28rpx * var(--font-scale, 1));
  125. color: $facade-text-strong;
  126. margin-bottom: 15rpx;
  127. display: block;
  128. }
  129. .required {
  130. color: $brand-primary;
  131. }
  132. .form-item input,
  133. .form-item textarea {
  134. width: 100%;
  135. background: $facade-fill-2;
  136. border-radius: 16rpx;
  137. padding: 20rpx;
  138. font-size: calc(28rpx * var(--font-scale, 1));
  139. border: none;
  140. }
  141. .form-item textarea {
  142. min-height: 150rpx;
  143. }
  144. /* 分类选择 */
  145. .category-list {
  146. display: flex;
  147. flex-wrap: wrap;
  148. gap: 15rpx;
  149. }
  150. .category-item {
  151. padding: 15rpx $uni-space-page;
  152. background: $facade-fill-2;
  153. border-radius: 24rpx;
  154. font-size: calc(26rpx * var(--font-scale, 1));
  155. color: $facade-text-body;
  156. }
  157. .category-item.active {
  158. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  159. color: $app-surface;
  160. }
  161. /* 提示 */
  162. .form-tip {
  163. display: flex;
  164. align-items: center;
  165. background: $status-danger-tint;
  166. padding: 20rpx;
  167. border-radius: 16rpx;
  168. margin-top: 20rpx;
  169. }
  170. .tip-icon {
  171. font-size: calc(32rpx * var(--font-scale, 1));
  172. margin-right: 15rpx;
  173. }
  174. .tip-text {
  175. font-size: calc(24rpx * var(--font-scale, 1));
  176. color: $facade-text-body;
  177. flex: 1;
  178. }
  179. /* 提交按钮 */
  180. .btn-submit {
  181. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  182. color: $app-surface;
  183. font-size: calc(32rpx * var(--font-scale, 1));
  184. padding: 24rpx;
  185. border-radius: 24rpx;
  186. margin-top: 40rpx;
  187. }
  188. </style>