plan-detail.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="page" :style="{ '--font-scale': fontScale }">
  3. <view class="card">
  4. <text class="title">{{ planTitle }}</text>
  5. <text class="meta">创建于 {{ formatTime(plan.createdAt) }}</text>
  6. <text class="meta" v-if="plan.teacherId">审核规划师:{{ plan.teacherId }}</text>
  7. <text class="meta" v-else>未分配规划师</text>
  8. </view>
  9. <view class="card">
  10. <text class="label">方案正文</text>
  11. <textarea
  12. class="editor"
  13. v-model="planContent"
  14. :disabled="!editing"
  15. placeholder="方案正文"
  16. />
  17. </view>
  18. <view class="actions">
  19. <view class="btn ghost" @click="toggleEdit">{{ editing ? '取消编辑' : '编辑' }}</view>
  20. <view class="btn ghost" v-if="editing" @click="save">保存</view>
  21. <view class="btn ok" @click="confirmThen('approve')">通过</view>
  22. <view class="btn no" @click="confirmThen('reject')">驳回</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. updateGuidePlanContent,
  29. approveGuidePlan,
  30. rejectGuidePlan,
  31. getGuidePendingPlans
  32. } from '@/utils/api.js'
  33. import fontScaleMixin from '@/mixins/font-scale.js'
  34. export default {
  35. mixins: [fontScaleMixin],
  36. data() {
  37. return {
  38. familyId: null,
  39. planId: null,
  40. plan: {},
  41. planContent: '',
  42. editing: false
  43. }
  44. },
  45. computed: {
  46. planTitle() {
  47. // HealthPlan 实体无 title 字段,只能依次回退到 goal / memberName
  48. return this.plan.goal || this.plan.memberName || '健康方案'
  49. }
  50. },
  51. onLoad(options) {
  52. this.familyId = options.familyId
  53. this.planId = options.planId
  54. this.fetchPlan()
  55. },
  56. methods: {
  57. async fetchPlan() {
  58. try {
  59. const res = await getGuidePendingPlans(this.familyId)
  60. if (res && res.code === 200) {
  61. const list = res.data || []
  62. for (let i = 0; i < list.length; i++) {
  63. if (String(list[i].id) === String(this.planId)) {
  64. this.plan = list[i]
  65. this.planContent = list[i].planContent || ''
  66. return
  67. }
  68. }
  69. uni.showToast({ title: '方案不存在或已被审核', icon: 'none' })
  70. }
  71. } catch (e) {
  72. uni.showToast({ title: '加载失败', icon: 'none' })
  73. }
  74. },
  75. toggleEdit() {
  76. this.editing = !this.editing
  77. },
  78. async save() {
  79. try {
  80. const res = await updateGuidePlanContent(this.familyId, this.planId, this.planContent)
  81. if (res && res.code === 200) {
  82. uni.showToast({ title: '已保存', icon: 'none' })
  83. this.editing = false
  84. } else {
  85. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  86. }
  87. } catch (e) {
  88. uni.showToast({ title: '网络异常', icon: 'none' })
  89. }
  90. },
  91. confirmThen(action) {
  92. uni.showModal({
  93. title: action === 'approve' ? '确认通过?' : '确认驳回?',
  94. content: action === 'approve' ? '通过后将自动生成每日任务' : '驳回后成员需重新提交',
  95. success: (r) => {
  96. if (!r.confirm) return
  97. this.doAction(action, '')
  98. }
  99. })
  100. },
  101. async doAction(action, comment) {
  102. try {
  103. const fn = action === 'approve' ? approveGuidePlan : rejectGuidePlan
  104. const res = await fn(this.familyId, this.planId, comment)
  105. if (res && res.code === 200) {
  106. const d = res.data || {}
  107. // taskGenerated=false 是「已发布但未生成任务」,属部分成功,必须与失败区分开提示
  108. if (action === 'approve' && d.taskGenerated === false) {
  109. uni.showModal({
  110. title: '部分成功',
  111. content: d.message || '方案已发布,但未生成任何任务,请检查方案内容',
  112. showCancel: false
  113. })
  114. } else {
  115. uni.showToast({ title: '操作成功', icon: 'none' })
  116. }
  117. setTimeout(() => uni.navigateBack(), 1200)
  118. } else {
  119. uni.showToast({ title: (res && res.message) || '操作失败', icon: 'none' })
  120. }
  121. } catch (e) {
  122. uni.showToast({ title: '网络异常', icon: 'none' })
  123. }
  124. },
  125. formatTime(t) {
  126. if (!t) return '-'
  127. // 项目统一时间格式:取前19位并把 ISO 的 T 换成空格,避免 toLocaleString 的浏览器差异
  128. return String(t).substring(0, 19).replace('T', ' ')
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped lang="scss">
  134. .page { padding: 24rpx; background: $facade-fill-blue-ghost; min-height: 100vh; }
  135. .card { background: $app-surface; border-radius: 16rpx; padding: 24rpx; margin-bottom: 20rpx; }
  136. .title { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: 600; color: $ink-steel; display: block; margin-bottom: 12rpx; }
  137. .meta { font-size: calc(24rpx * var(--font-scale, 1)); color: $text-steel; display: block; margin-bottom: 6rpx; }
  138. .label { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-slate-600; display: block; margin-bottom: 12rpx; }
  139. .editor { width: 100%; min-height: 400rpx; font-size: calc(28rpx * var(--font-scale, 1)); color: $ink-steel; padding: 16rpx; background: $facade-fill-slate-50-2; border-radius: 16rpx; }
  140. .actions { display: flex; flex-direction: row; flex-wrap: wrap; }
  141. .btn { flex: 1; text-align: center; padding: 20rpx 0; border-radius: 16rpx; font-size: calc(28rpx * var(--font-scale, 1)); margin-right: 16rpx; margin-bottom: 16rpx; min-width: 40%; }
  142. .btn.ghost { background: $app-surface; color: $brand-primary; border: 1rpx solid $brand-primary; }
  143. .btn.ok { background: $brand-primary; color: $app-surface; }
  144. .btn.no { background: $facade-fill-slate-25; color: $facade-text-slate-600; margin-right: 0; }
  145. </style>