plan-confirm.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 { updateUserIntentStage } 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. updateUserIntentStage(6).then(function(res) {
  97. uni.hideLoading()
  98. if (res && (res.code === 0 || res.code === 200)) {
  99. uni.showToast({ title: '方案已确认', icon: 'success' })
  100. setTimeout(function() {
  101. uni.navigateTo({ url: '/pages/tasks/tasks' })
  102. }, 500)
  103. } else {
  104. uni.showToast({ title: res.message || '确认失败', icon: 'none' })
  105. }
  106. }).catch(function() {
  107. uni.hideLoading()
  108. uni.showToast({ title: '确认失败,请重试', icon: 'none' })
  109. })
  110. },
  111. refresh() {
  112. this.loadPlan()
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .pc-wrap {
  119. min-height: 100vh;
  120. background: #FFF7ED;
  121. padding: 40rpx 32rpx;
  122. box-sizing: border-box;
  123. }
  124. .pc-header {
  125. margin-bottom: 32rpx;
  126. }
  127. .pc-title {
  128. display: block;
  129. font-size: 38rpx;
  130. font-weight: bold;
  131. color: #333;
  132. text-align: center;
  133. }
  134. .pc-sub {
  135. display: block;
  136. font-size: 26rpx;
  137. color: #999;
  138. text-align: center;
  139. margin-top: 10rpx;
  140. }
  141. .pc-loading {
  142. text-align: center;
  143. font-size: 28rpx;
  144. color: #999;
  145. padding: 80rpx 0;
  146. }
  147. .pc-waiting {
  148. text-align: center;
  149. padding: 80rpx 0;
  150. }
  151. .pc-waiting-icon {
  152. font-size: 80rpx;
  153. display: block;
  154. }
  155. .pc-waiting-text {
  156. display: block;
  157. font-size: 32rpx;
  158. font-weight: 600;
  159. color: #333;
  160. margin-top: 20rpx;
  161. }
  162. .pc-waiting-sub {
  163. display: block;
  164. font-size: 26rpx;
  165. color: #999;
  166. margin-top: 10rpx;
  167. }
  168. .pc-waiting-btn {
  169. display: inline-block;
  170. margin-top: 32rpx;
  171. background: #F97316;
  172. border-radius: 40rpx;
  173. padding: 18rpx 60rpx;
  174. }
  175. .pc-waiting-btn:active {
  176. opacity: 0.9;
  177. }
  178. .pc-waiting-btn-text {
  179. color: #fff;
  180. font-size: 28rpx;
  181. font-weight: 600;
  182. }
  183. .pc-report-section {
  184. background: #fff;
  185. border-radius: 20rpx;
  186. padding: 28rpx 30rpx;
  187. margin-bottom: 24rpx;
  188. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  189. }
  190. .pc-section-title {
  191. display: block;
  192. font-size: 30rpx;
  193. font-weight: 600;
  194. color: #333;
  195. margin-bottom: 16rpx;
  196. }
  197. .pc-section-text {
  198. display: block;
  199. font-size: 26rpx;
  200. color: #666;
  201. line-height: 1.6;
  202. }
  203. .pc-plan-item {
  204. display: flex;
  205. align-items: flex-start;
  206. margin-bottom: 20rpx;
  207. }
  208. .pc-plan-item:last-child {
  209. margin-bottom: 0;
  210. }
  211. .pc-plan-num {
  212. width: 40rpx;
  213. height: 40rpx;
  214. border-radius: 50%;
  215. background: #F97316;
  216. color: #fff;
  217. font-size: 22rpx;
  218. font-weight: bold;
  219. text-align: center;
  220. line-height: 40rpx;
  221. margin-right: 16rpx;
  222. flex-shrink: 0;
  223. }
  224. .pc-plan-body {
  225. flex: 1;
  226. }
  227. .pc-plan-title {
  228. display: block;
  229. font-size: 28rpx;
  230. font-weight: 600;
  231. color: #333;
  232. }
  233. .pc-plan-desc {
  234. display: block;
  235. font-size: 24rpx;
  236. color: #999;
  237. margin-top: 4rpx;
  238. }
  239. .pc-confirm-btn {
  240. background: linear-gradient(135deg, #F97316, #FB923C);
  241. border-radius: 48rpx;
  242. padding: 26rpx 0;
  243. text-align: center;
  244. margin-top: 16rpx;
  245. }
  246. .pc-confirm-btn:active {
  247. opacity: 0.9;
  248. }
  249. .pc-confirm-btn-text {
  250. color: #fff;
  251. font-size: 32rpx;
  252. font-weight: 600;
  253. }
  254. </style>