index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="plan-page">
  3. <view class="section-card">
  4. <text class="section-title">7天行动计划</text>
  5. <text class="card-desc">规划您未来7天的学习与实践目标</text>
  6. <view v-if="existingPlan" class="existing-plan">
  7. <text class="plan-status">✅ 已提交</text>
  8. <view class="plan-items">
  9. <view class="plan-item" v-for="(item, idx) in parsedItems" :key="idx">
  10. <text class="day-label">Day {{ idx + 1 }}</text>
  11. <text class="day-content">{{ item }}</text>
  12. </view>
  13. </view>
  14. <text class="plan-time" v-if="existingPlan.submittedAt">提交时间:{{ existingPlan.submittedAt }}</text>
  15. </view>
  16. <view v-else class="plan-form">
  17. <view class="day-input" v-for="day in 7" :key="day">
  18. <text class="day-label">Day {{ day }}</text>
  19. <input class="form-input" v-model="items[day - 1]" :placeholder="'第' + day + '天计划'" />
  20. </view>
  21. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading">提交计划</button>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { submitPlan, getMyPlan } from '@/utils/api.js'
  28. import { guardPage } from '@/utils/guard.js'
  29. export default {
  30. data() {
  31. return {
  32. items: ['', '', '', '', '', '', ''],
  33. existingPlan: null,
  34. loading: false
  35. }
  36. },
  37. computed: {
  38. parsedItems() {
  39. if (!this.existingPlan || !this.existingPlan.items) return []
  40. try {
  41. return JSON.parse(this.existingPlan.items)
  42. } catch (e) {
  43. return [this.existingPlan.items]
  44. }
  45. }
  46. },
  47. onShow() {
  48. if (!guardPage()) return
  49. this.loadPlan()
  50. },
  51. methods: {
  52. loadPlan() {
  53. var self = this
  54. getMyPlan().then(function(resp) {
  55. if (resp.data) {
  56. self.existingPlan = resp.data
  57. }
  58. }).catch(function() {})
  59. },
  60. handleSubmit() {
  61. var filled = this.items.filter(function(i) { return i.trim() })
  62. if (filled.length === 0) {
  63. uni.showToast({ title: '请至少填写一天计划', icon: 'none' })
  64. return
  65. }
  66. if (this.loading) return
  67. this.loading = true
  68. var self = this
  69. submitPlan({ items: JSON.stringify(this.items) }).then(function() {
  70. uni.showToast({ title: '提交成功', icon: 'success' })
  71. self.loadPlan()
  72. }).catch(function(err) {
  73. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  74. }).finally(function() {
  75. self.loading = false
  76. })
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. .plan-page { min-height: 100vh; background: #F5F5F5; padding: 32rpx; }
  83. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  84. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #2A2326; margin-bottom: 8rpx; border-left: 8rpx solid #FC7A57; padding-left: 16rpx; }
  85. .card-desc { display: block; font-size: 26rpx; color: #5A4F4B; margin-bottom: 32rpx; }
  86. .existing-plan { margin-top: 16rpx; }
  87. .plan-status { display: block; font-size: 28rpx; color: #22C55E; font-weight: 500; margin-bottom: 20rpx; }
  88. .plan-items { margin-bottom: 16rpx; }
  89. .plan-item { display: flex; padding: 16rpx 0; border-bottom: 1rpx solid #F1F5F9; }
  90. .day-label { width: 100rpx; font-size: 26rpx; color: #FC7A57; font-weight: 600; flex-shrink: 0; }
  91. .day-content { flex: 1; font-size: 28rpx; color: #2A2326; }
  92. .plan-time { font-size: 24rpx; color: #94877F; }
  93. .day-input { display: flex; align-items: center; margin-bottom: 20rpx; }
  94. .day-input .day-label { width: 100rpx; font-size: 26rpx; color: #FC7A57; font-weight: 600; flex-shrink: 0; }
  95. .form-input { flex: 1; height: 72rpx; border: 2rpx solid #E2E8F0; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #2A2326; background: #F8FAFC; }
  96. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #FC7A57; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 24rpx; }
  97. .submit-btn:active { opacity: 0.85; }
  98. </style>