plan-create.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="page" :style="{ '--font-scale': fontScale }">
  3. <view class="card">
  4. <view class="form-group">
  5. <text class="label">方案标题 <text class="required">*</text></text>
  6. <input
  7. class="input"
  8. v-model="title"
  9. placeholder="请输入方案标题"
  10. />
  11. </view>
  12. <view class="form-group">
  13. <text class="label">方案描述</text>
  14. <textarea
  15. class="textarea"
  16. v-model="description"
  17. placeholder="请输入方案描述(可选)"
  18. :maxlength="-1"
  19. />
  20. </view>
  21. </view>
  22. <view class="actions">
  23. <button class="btn-primary" :disabled="submitting" @click="submitPlan">
  24. {{ submitting ? '提交中...' : '保存方案' }}
  25. </button>
  26. <button class="btn-cancel" @click="goBack">取消</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { createTrainingPlan } from '@/utils/api.js'
  32. import fontScaleMixin from '@/mixins/font-scale.js'
  33. export default {
  34. mixins: [fontScaleMixin],
  35. data() {
  36. return {
  37. title: '',
  38. description: '',
  39. submitting: false
  40. }
  41. },
  42. methods: {
  43. submitPlan() {
  44. if (!this.title || !this.title.trim()) {
  45. uni.showToast({ title: '请输入方案标题', icon: 'none' })
  46. return
  47. }
  48. this.submitting = true
  49. // 创建方案(memberId 留空,由后端关联当前用户)
  50. createTrainingPlan(null, this.title.trim(), this.description.trim() || '')
  51. .then(res => {
  52. this.submitting = false
  53. if (res && res.code === 200) {
  54. uni.showToast({ title: '创建成功', icon: 'success' })
  55. // 延迟跳转,让用户看到成功提示
  56. setTimeout(() => {
  57. uni.navigateBack()
  58. }, 1000)
  59. } else {
  60. uni.showToast({ title: (res && res.message) || '创建失败', icon: 'none' })
  61. }
  62. })
  63. .catch(err => {
  64. this.submitting = false
  65. console.error('创建方案失败', err)
  66. uni.showToast({ title: '创建失败', icon: 'none' })
  67. })
  68. },
  69. goBack() {
  70. uni.navigateBack()
  71. }
  72. }
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .page {
  77. padding: 24rpx;
  78. background: $facade-fill-blue-ghost;
  79. min-height: 100vh;
  80. }
  81. .card {
  82. background: $app-surface;
  83. border-radius: 16rpx;
  84. padding: $uni-space-page;
  85. margin-bottom: 20rpx;
  86. }
  87. .form-group {
  88. margin-bottom: $uni-space-lg;
  89. }
  90. .form-group:last-child {
  91. margin-bottom: 0;
  92. }
  93. .label {
  94. font-size: calc(28rpx * var(--font-scale, 1));
  95. color: $ink-steel;
  96. display: block;
  97. margin-bottom: 12rpx;
  98. font-weight: 500;
  99. }
  100. .required {
  101. color: $mat-red;
  102. }
  103. .input {
  104. width: 100%;
  105. height: 80rpx;
  106. background: $facade-fill-slate-50-2;
  107. border-radius: 16rpx;
  108. padding: 0 20rpx;
  109. font-size: calc(28rpx * var(--font-scale, 1));
  110. color: $ink-steel;
  111. box-sizing: border-box;
  112. }
  113. .textarea {
  114. width: 100%;
  115. min-height: 200rpx;
  116. background: $facade-fill-slate-50-2;
  117. border-radius: 16rpx;
  118. padding: 20rpx;
  119. font-size: calc(28rpx * var(--font-scale, 1));
  120. color: $ink-steel;
  121. box-sizing: border-box;
  122. }
  123. .actions {
  124. display: flex;
  125. flex-direction: column;
  126. gap: 16rpx;
  127. }
  128. .btn-primary {
  129. width: 100%;
  130. background: $brand-primary;
  131. color: $app-surface;
  132. font-size: calc(30rpx * var(--font-scale, 1));
  133. font-weight: 600;
  134. padding: 24rpx 0;
  135. border-radius: 16rpx;
  136. border: none;
  137. }
  138. .btn-primary:disabled {
  139. background: $facade-text-ghost;
  140. }
  141. .btn-cancel {
  142. width: 100%;
  143. background: $facade-fill-slate-25;
  144. color: $facade-text-slate-600;
  145. font-size: calc(30rpx * var(--font-scale, 1));
  146. padding: 24rpx 0;
  147. border-radius: 16rpx;
  148. border: none;
  149. }
  150. </style>