plan-confirm.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="pc-wrap">
  3. <view class="pc-header">
  4. <text class="pc-title">方案确认</text>
  5. <text class="pc-sub">查看报告方案,确认后生成执行任务</text>
  6. </view>
  7. <view class="pc-loading" v-if="loading">加载中...</view>
  8. <view class="pc-waiting" v-else-if="!reportReady">
  9. <text class="pc-waiting-icon">⏳</text>
  10. <text class="pc-waiting-text">报告尚未生成</text>
  11. <text class="pc-waiting-sub">请耐心等待报告完成,系统会自动通知你</text>
  12. <view class="pc-waiting-btn" @click="refresh">
  13. <text class="pc-waiting-btn-text">刷新</text>
  14. </view>
  15. </view>
  16. <view class="pc-content" v-else>
  17. <view class="pc-report-section">
  18. <text class="pc-section-title">报告摘要</text>
  19. <text class="pc-section-text">{{ reportSummary || '暂无摘要信息' }}</text>
  20. </view>
  21. <view class="pc-report-section" v-if="planItems && planItems.length > 0">
  22. <text class="pc-section-title">建议方案</text>
  23. <view class="pc-plan-item" v-for="(item, i) in planItems" :key="getPlanKey(i)">
  24. <text class="pc-plan-num">{{ i + 1 }}</text>
  25. <view class="pc-plan-body">
  26. <text class="pc-plan-title">{{ item.title }}</text>
  27. <text class="pc-plan-desc" v-if="item.desc">{{ item.desc }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="pc-confirm-btn" @click="confirmPlan">
  32. <text class="pc-confirm-btn-text">确认方案,生成任务</text>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import { getUserIntent } from '../../utils/api.js'
  39. import { confirmProblemPlan } from '../../utils/api.js'
  40. export default {
  41. data() {
  42. return {
  43. code: '',
  44. loading: false,
  45. reportReady: false,
  46. reportSummary: '',
  47. planItems: []
  48. }
  49. },
  50. onLoad(options) {
  51. this.code = (options && options.code) || ''
  52. this.loadPlan()
  53. },
  54. methods: {
  55. getPlanKey: function(i) { return 'p' + i },
  56. loadPlan() {
  57. var self = this
  58. self.loading = true
  59. uni.showLoading({ title: '加载中...', mask: true })
  60. getUserIntent().then(function(res) {
  61. uni.hideLoading()
  62. self.loading = false
  63. var intent = res && res.data
  64. if (intent) {
  65. var stage = intent.journeyStage || 0
  66. self.reportReady = stage >= 5
  67. if (self.reportReady) {
  68. // 从 survey_result_json 获取方案快照
  69. var resultJson = intent.survey_result_json
  70. if (resultJson) {
  71. var parsed = typeof resultJson === 'string' ? JSON.parse(resultJson) : resultJson
  72. self.reportSummary = parsed.summary || parsed.reportSummary || '报告已生成,请查看详情。'
  73. var items = parsed.items || parsed.planItems || parsed.recommendations || []
  74. self.planItems = Array.isArray(items) ? items : []
  75. } else {
  76. self.reportSummary = '报告已生成,建议方案已就绪。'
  77. self.planItems = [
  78. { title: '个性化饮食调整', desc: '根据报告结果调整日常饮食结构' },
  79. { title: '运动计划', desc: '定制运动方案,每周执行' },
  80. { title: '作息优化', desc: '调整作息习惯,改善睡眠质量' }
  81. ]
  82. }
  83. }
  84. } else {
  85. self.reportReady = false
  86. }
  87. }).catch(function() {
  88. uni.hideLoading()
  89. self.loading = false
  90. self.reportReady = false
  91. })
  92. },
  93. confirmPlan() {
  94. var self = this
  95. uni.showLoading({ title: '处理中...', mask: true })
  96. // 方案确认:后端生成方案任务(memberOnly=1)并推进旅程 stage=6
  97. confirmProblemPlan('').then(function(res) {
  98. uni.hideLoading()
  99. if (res && (res.code === 0 || res.code === 200)) {
  100. uni.showToast({ title: '方案已确认,任务已生成', icon: 'success' })
  101. setTimeout(function() {
  102. uni.navigateTo({ url: '/pages/tasks/tasks' })
  103. }, 500)
  104. } else {
  105. uni.showToast({ title: res.message || '确认失败', icon: 'none' })
  106. }
  107. }).catch(function() {
  108. uni.hideLoading()
  109. uni.showToast({ title: '确认失败,请重试', icon: 'none' })
  110. })
  111. },
  112. refresh() {
  113. this.loadPlan()
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. .pc-wrap {
  120. min-height: 100vh;
  121. background: #FFF7ED;
  122. padding: 40rpx 32rpx;
  123. box-sizing: border-box;
  124. }
  125. .pc-header {
  126. margin-bottom: 32rpx;
  127. }
  128. .pc-title {
  129. display: block;
  130. font-size: 38rpx;
  131. font-weight: bold;
  132. color: #333;
  133. text-align: center;
  134. }
  135. .pc-sub {
  136. display: block;
  137. font-size: 26rpx;
  138. color: #999;
  139. text-align: center;
  140. margin-top: 10rpx;
  141. }
  142. .pc-loading {
  143. text-align: center;
  144. font-size: 28rpx;
  145. color: #999;
  146. padding: 80rpx 0;
  147. }
  148. .pc-waiting {
  149. text-align: center;
  150. padding: 80rpx 0;
  151. }
  152. .pc-waiting-icon {
  153. font-size: 80rpx;
  154. display: block;
  155. }
  156. .pc-waiting-text {
  157. display: block;
  158. font-size: 32rpx;
  159. font-weight: 600;
  160. color: #333;
  161. margin-top: 20rpx;
  162. }
  163. .pc-waiting-sub {
  164. display: block;
  165. font-size: 26rpx;
  166. color: #999;
  167. margin-top: 10rpx;
  168. }
  169. .pc-waiting-btn {
  170. display: inline-block;
  171. margin-top: 32rpx;
  172. background: #F97316;
  173. border-radius: 40rpx;
  174. padding: 18rpx 60rpx;
  175. }
  176. .pc-waiting-btn:active {
  177. opacity: 0.9;
  178. }
  179. .pc-waiting-btn-text {
  180. color: #fff;
  181. font-size: 28rpx;
  182. font-weight: 600;
  183. }
  184. .pc-report-section {
  185. background: #fff;
  186. border-radius: 20rpx;
  187. padding: 28rpx 30rpx;
  188. margin-bottom: 24rpx;
  189. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  190. }
  191. .pc-section-title {
  192. display: block;
  193. font-size: 30rpx;
  194. font-weight: 600;
  195. color: #333;
  196. margin-bottom: 16rpx;
  197. }
  198. .pc-section-text {
  199. display: block;
  200. font-size: 26rpx;
  201. color: #666;
  202. line-height: 1.6;
  203. }
  204. .pc-plan-item {
  205. display: flex;
  206. align-items: flex-start;
  207. margin-bottom: 20rpx;
  208. }
  209. .pc-plan-item:last-child {
  210. margin-bottom: 0;
  211. }
  212. .pc-plan-num {
  213. width: 40rpx;
  214. height: 40rpx;
  215. border-radius: 50%;
  216. background: #F97316;
  217. color: #fff;
  218. font-size: 22rpx;
  219. font-weight: bold;
  220. text-align: center;
  221. line-height: 40rpx;
  222. margin-right: 16rpx;
  223. flex-shrink: 0;
  224. }
  225. .pc-plan-body {
  226. flex: 1;
  227. }
  228. .pc-plan-title {
  229. display: block;
  230. font-size: 28rpx;
  231. font-weight: 600;
  232. color: #333;
  233. }
  234. .pc-plan-desc {
  235. display: block;
  236. font-size: 24rpx;
  237. color: #999;
  238. margin-top: 4rpx;
  239. }
  240. .pc-confirm-btn {
  241. background: linear-gradient(135deg, #F97316, #FB923C);
  242. border-radius: 48rpx;
  243. padding: 26rpx 0;
  244. text-align: center;
  245. margin-top: 16rpx;
  246. }
  247. .pc-confirm-btn:active {
  248. opacity: 0.9;
  249. }
  250. .pc-confirm-btn-text {
  251. color: #fff;
  252. font-size: 32rpx;
  253. font-weight: 600;
  254. }
  255. </style>