report-upload.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <view class="back-btn" @click="goBack">
  5. <text class="back-icon">&#x2190;</text>
  6. <text class="back-text">返回</text>
  7. </view>
  8. <text class="header-title">DAN 报告上传</text>
  9. </view>
  10. <!-- Step 1: 选择维度 + 选择文件 -->
  11. <view class="section" v-if="step === 1">
  12. <view class="dimension-select">
  13. <text class="dimension-label">报告类型</text>
  14. <view class="dimension-options">
  15. <view
  16. :class="['dimension-option', dimension === 'mind' ? 'active' : '']"
  17. @click="selectDimension('mind')">
  18. <text class="dimension-name">&#x2764; 心维度 (A2)</text>
  19. </view>
  20. <view
  21. :class="['dimension-option', dimension === 'wisdom' ? 'active' : '']"
  22. @click="selectDimension('wisdom')">
  23. <text class="dimension-name">&#x1F9E0; 智维度 (B4)</text>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 购买推荐 -->
  28. <view class="purchase-section" v-if="recommendedProducts.length > 0">
  29. <view class="purchase-header">
  30. <text class="purchase-icon">📦</text>
  31. <text class="purchase-title">为家人购买检测服务</text>
  32. </view>
  33. <scroll-view class="purchase-scroll" scroll-x enable-flex show-scrollbar="false">
  34. <view
  35. class="purchase-card"
  36. v-for="item in recommendedProducts"
  37. :key="item.id"
  38. @click="goToProduct(item.id)"
  39. >
  40. <image class="purchase-cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
  41. <text class="purchase-name">{{ item.name }}</text>
  42. <text class="purchase-price">{{ formatPriceWithSymbol(item.price) }}</text>
  43. <view class="purchase-btn">
  44. <text class="purchase-btn-text">去购买</text>
  45. </view>
  46. </view>
  47. </scroll-view>
  48. </view>
  49. <view class="upload-area" @click="chooseFile">
  50. <view class="upload-icon" v-if="!selectedFile">&#x1F4C4;</view>
  51. <view class="upload-icon" v-else>&#x2705;</view>
  52. <text class="upload-text" v-if="!selectedFile">点击上传 PDF 文件</text>
  53. <text class="upload-text" v-else>{{ selectedFile.name }}</text>
  54. <text class="upload-hint">支持 PDF 格式的 DAN 测评报告</text>
  55. </view>
  56. <view class="action-bar">
  57. <view class="upload-btn" @click="startUpload" v-if="selectedFile">
  58. <text class="upload-btn-text">上传并解析</text>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- Step 2: 预览解析结果 -->
  63. <view class="section" v-if="step === 2">
  64. <view class="preview-header">
  65. <text class="preview-title">解析预览</text>
  66. <text class="preview-desc">请确认以下数据是否准确</text>
  67. </view>
  68. <view class="preview-card" v-if="previewData">
  69. <view class="preview-row">
  70. <text class="preview-label">维度</text>
  71. <text class="preview-value">{{ dimension === 'mind' ? '心维度 (A2)' : '智维度 (B4)' }}</text>
  72. </view>
  73. <view class="preview-row">
  74. <text class="preview-label">解析概要</text>
  75. <text class="preview-value">{{ previewData.summary || '无' }}</text>
  76. </view>
  77. </view>
  78. <!-- 解析项列表 -->
  79. <view class="items-section" v-if="previewData && previewData.items && previewData.items.length > 0">
  80. <text class="items-title">数据项 ({{ previewData.items.length }})</text>
  81. <view class="item-card" v-for="(item, idx) in previewData.items" :key="idx">
  82. <view class="item-header">
  83. <text class="item-name">{{ item.name || item.code }}</text>
  84. <text class="item-category">{{ item.category }}</text>
  85. </view>
  86. <view class="item-value-bar">
  87. <view class="item-value-fill" :style="'width:' + item.value + '%'"></view>
  88. </view>
  89. <text class="item-value-text">{{ item.value }}/100</text>
  90. </view>
  91. </view>
  92. <!-- 建议 -->
  93. <view class="suggestions-card" v-if="previewData && previewData.suggestions">
  94. <text class="suggestions-title">成长建议</text>
  95. <text class="suggestions-text">{{ previewData.suggestions }}</text>
  96. </view>
  97. <view class="action-bar">
  98. <view class="confirm-btn" @click="doConfirm" v-if="!confirming">
  99. <text class="confirm-btn-text">确认并保存</text>
  100. </view>
  101. <view class="confirm-btn disabled" v-else>
  102. <text class="confirm-btn-text">保存中...</text>
  103. </view>
  104. <view class="retry-btn" @click="resetUpload">
  105. <text class="retry-btn-text">重新上传</text>
  106. </view>
  107. </view>
  108. </view>
  109. <!-- Step 3: 完成 -->
  110. <view class="section" v-if="step === 3">
  111. <view class="success-card">
  112. <text class="success-icon">&#x2705;</text>
  113. <text class="success-title">报告已保存</text>
  114. <text class="success-desc">DAN 测评数据已更新至五维能量体系</text>
  115. </view>
  116. <view class="action-bar">
  117. <view class="upload-btn" @click="goBack">
  118. <text class="upload-btn-text">返回</text>
  119. </view>
  120. </view>
  121. </view>
  122. <!-- Loading -->
  123. <view class="loading-overlay" v-if="loading">
  124. <view class="loading-box">
  125. <text class="loading-text">解析中...</text>
  126. </view>
  127. </view>
  128. </view>
  129. </template>
  130. <script>
  131. import { danParsePreview, danConfirmReport, productList } from '../../utils/api.js'
  132. var REPORT_DOMAIN_MAP = {
  133. mind: 'mind',
  134. wisdom: 'wisdom'
  135. }
  136. export default {
  137. data() {
  138. return {
  139. step: 1,
  140. dimension: 'mind',
  141. selectedFile: null,
  142. previewData: null,
  143. draftId: null,
  144. loading: false,
  145. confirming: false,
  146. recommendedProducts: [],
  147. loadingProducts: false
  148. }
  149. },
  150. onLoad: function() {
  151. this.loadRecommendProducts(this.dimension)
  152. },
  153. methods: {
  154. goBack: function() {
  155. uni.navigateBack()
  156. },
  157. chooseFile: function() {
  158. var self = this
  159. uni.chooseMessageFile({
  160. count: 1,
  161. type: 'file',
  162. extension: ['pdf'],
  163. success: function(res) {
  164. if (res.tempFiles && res.tempFiles.length > 0) {
  165. self.selectedFile = res.tempFiles[0]
  166. }
  167. },
  168. fail: function() {
  169. // 降级:使用相册/相机
  170. uni.chooseImage({
  171. count: 1,
  172. success: function(res) {
  173. if (res.tempFiles && res.tempFiles.length > 0) {
  174. self.selectedFile = res.tempFiles[0]
  175. }
  176. }
  177. })
  178. }
  179. })
  180. },
  181. startUpload: function() {
  182. if (!this.selectedFile) return
  183. var self = this
  184. self.loading = true
  185. var memberId = this.$store.state && this.$store.state.currentChildId
  186. ? this.$store.state.currentChildId
  187. : uni.getStorageSync('currentChildId')
  188. danParsePreview(self.selectedFile.path || self.selectedFile.tempFilePath, self.dimension, memberId)
  189. .then(function(res) {
  190. self.loading = false
  191. if (res.code === 200 && res.data) {
  192. self.previewData = res.data
  193. self.draftId = res.data.draftId
  194. self.step = 2
  195. } else {
  196. uni.showToast({ title: res.message || '解析失败', icon: 'none' })
  197. }
  198. })
  199. .catch(function(err) {
  200. self.loading = false
  201. uni.showToast({ title: err && err.message ? err.message : '上传失败', icon: 'none' })
  202. })
  203. },
  204. doConfirm: function() {
  205. var self = this
  206. self.confirming = true
  207. var memberId = this.$store.state && this.$store.state.currentChildId
  208. ? this.$store.state.currentChildId
  209. : uni.getStorageSync('currentChildId')
  210. danConfirmReport({
  211. draftId: self.draftId,
  212. dimension: self.dimension,
  213. memberId: memberId
  214. })
  215. .then(function(res) {
  216. self.confirming = false
  217. if (res.code === 200) {
  218. self.step = 3
  219. } else {
  220. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  221. }
  222. })
  223. .catch(function(err) {
  224. self.confirming = false
  225. uni.showToast({ title: '保存失败', icon: 'none' })
  226. })
  227. },
  228. resetUpload: function() {
  229. this.step = 1
  230. this.selectedFile = null
  231. this.previewData = null
  232. this.draftId = null
  233. },
  234. selectDimension: function(dim) {
  235. this.dimension = dim
  236. this.loadRecommendProducts(dim)
  237. },
  238. loadRecommendProducts: function(dimension) {
  239. var domain = REPORT_DOMAIN_MAP[dimension]
  240. if (!domain) {
  241. this.recommendedProducts = []
  242. return
  243. }
  244. var self = this
  245. self.loadingProducts = true
  246. productList({ domain: domain, productType: 'assessment', size: 4 }).then(function(res) {
  247. if (res && res.data && res.data.records) {
  248. self.recommendedProducts = res.data.records
  249. } else {
  250. self.recommendedProducts = []
  251. }
  252. }).catch(function() {
  253. self.recommendedProducts = []
  254. }).finally(function() {
  255. self.loadingProducts = false
  256. })
  257. },
  258. goToProduct: function(productId) {
  259. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + productId })
  260. },
  261. formatPriceWithSymbol: function(cents) {
  262. if (cents === null || cents === undefined) return '¥0'
  263. return '¥' + (cents / 100).toFixed(2)
  264. }
  265. }
  266. }
  267. </script>
  268. <style>
  269. .page {
  270. min-height: 100vh;
  271. background: #F5F5F7;
  272. padding-bottom: 40rpx;
  273. }
  274. .header {
  275. display: flex;
  276. align-items: center;
  277. padding: 88rpx 32rpx 24rpx;
  278. background: linear-gradient(135deg, #667EEA, #764BA2);
  279. }
  280. .back-btn {
  281. display: flex;
  282. align-items: center;
  283. margin-right: 24rpx;
  284. padding: 8rpx 16rpx;
  285. }
  286. .back-icon {
  287. font-size: 36rpx;
  288. color: #fff;
  289. margin-right: 8rpx;
  290. }
  291. .back-text {
  292. font-size: 28rpx;
  293. color: #fff;
  294. }
  295. .header-title {
  296. font-size: 36rpx;
  297. font-weight: 700;
  298. color: #fff;
  299. }
  300. .section {
  301. margin: 24rpx 24rpx 0;
  302. }
  303. .dimension-select {
  304. background: #fff;
  305. border-radius: 16rpx;
  306. padding: 32rpx;
  307. }
  308. .dimension-label {
  309. font-size: 28rpx;
  310. font-weight: 600;
  311. color: #333;
  312. margin-bottom: 20rpx;
  313. display: block;
  314. }
  315. .dimension-options {
  316. display: flex;
  317. gap: 20rpx;
  318. }
  319. .dimension-option {
  320. flex: 1;
  321. padding: 24rpx;
  322. border-radius: 12rpx;
  323. background: #F5F5F7;
  324. text-align: center;
  325. border: 2rpx solid transparent;
  326. }
  327. .dimension-option.active {
  328. background: #EEF2FF;
  329. border-color: #6366F1;
  330. }
  331. .dimension-name {
  332. font-size: 28rpx;
  333. color: #333;
  334. font-weight: 500;
  335. }
  336. .dimension-option.active .dimension-name {
  337. color: #6366F1;
  338. }
  339. .upload-area {
  340. background: #fff;
  341. border-radius: 16rpx;
  342. padding: 60rpx 32rpx;
  343. text-align: center;
  344. margin-top: 24rpx;
  345. border: 2rpx dashed #D1D5DB;
  346. }
  347. .upload-icon {
  348. font-size: 64rpx;
  349. margin-bottom: 16rpx;
  350. }
  351. .upload-text {
  352. font-size: 30rpx;
  353. color: #333;
  354. display: block;
  355. margin-bottom: 8rpx;
  356. }
  357. .upload-hint {
  358. font-size: 24rpx;
  359. color: #999;
  360. }
  361. .action-bar {
  362. margin-top: 32rpx;
  363. display: flex;
  364. gap: 20rpx;
  365. }
  366. .upload-btn {
  367. flex: 1;
  368. background: #6366F1;
  369. border-radius: 12rpx;
  370. padding: 24rpx;
  371. text-align: center;
  372. }
  373. .upload-btn-text {
  374. font-size: 30rpx;
  375. color: #fff;
  376. font-weight: 600;
  377. }
  378. .preview-header {
  379. margin-bottom: 24rpx;
  380. }
  381. .preview-title {
  382. font-size: 32rpx;
  383. font-weight: 700;
  384. color: #333;
  385. display: block;
  386. }
  387. .preview-desc {
  388. font-size: 24rpx;
  389. color: #999;
  390. margin-top: 8rpx;
  391. }
  392. .preview-card {
  393. background: #fff;
  394. border-radius: 16rpx;
  395. padding: 24rpx;
  396. }
  397. .preview-row {
  398. display: flex;
  399. justify-content: space-between;
  400. padding: 12rpx 0;
  401. border-bottom: 1rpx solid #F3F4F6;
  402. }
  403. .preview-row:last-child {
  404. border-bottom: none;
  405. }
  406. .preview-label {
  407. font-size: 26rpx;
  408. color: #666;
  409. }
  410. .preview-value {
  411. font-size: 26rpx;
  412. color: #333;
  413. font-weight: 500;
  414. }
  415. .items-section {
  416. margin-top: 24rpx;
  417. }
  418. .items-title {
  419. font-size: 28rpx;
  420. font-weight: 600;
  421. color: #333;
  422. margin-bottom: 16rpx;
  423. display: block;
  424. }
  425. .item-card {
  426. background: #fff;
  427. border-radius: 12rpx;
  428. padding: 20rpx;
  429. margin-bottom: 12rpx;
  430. }
  431. .item-header {
  432. display: flex;
  433. justify-content: space-between;
  434. margin-bottom: 12rpx;
  435. }
  436. .item-name {
  437. font-size: 26rpx;
  438. color: #333;
  439. font-weight: 500;
  440. }
  441. .item-category {
  442. font-size: 22rpx;
  443. color: #999;
  444. background: #F3F4F6;
  445. padding: 4rpx 12rpx;
  446. border-radius: 8rpx;
  447. }
  448. .item-value-bar {
  449. height: 16rpx;
  450. background: #F3F4F6;
  451. border-radius: 8rpx;
  452. overflow: hidden;
  453. }
  454. .item-value-fill {
  455. height: 100%;
  456. background: linear-gradient(90deg, #667EEA, #764BA2);
  457. border-radius: 8rpx;
  458. }
  459. .item-value-text {
  460. font-size: 24rpx;
  461. color: #666;
  462. margin-top: 8rpx;
  463. display: block;
  464. text-align: right;
  465. }
  466. .suggestions-card {
  467. background: #FFFBEB;
  468. border-radius: 16rpx;
  469. padding: 24rpx;
  470. margin-top: 24rpx;
  471. }
  472. .suggestions-title {
  473. font-size: 28rpx;
  474. font-weight: 600;
  475. color: #92400E;
  476. display: block;
  477. margin-bottom: 12rpx;
  478. }
  479. .suggestions-text {
  480. font-size: 26rpx;
  481. color: #78350F;
  482. line-height: 1.6;
  483. }
  484. .confirm-btn {
  485. flex: 1;
  486. background: #10B981;
  487. border-radius: 12rpx;
  488. padding: 24rpx;
  489. text-align: center;
  490. }
  491. .confirm-btn.disabled {
  492. opacity: 0.6;
  493. }
  494. .confirm-btn-text {
  495. font-size: 30rpx;
  496. color: #fff;
  497. font-weight: 600;
  498. }
  499. .retry-btn {
  500. padding: 24rpx 32rpx;
  501. border-radius: 12rpx;
  502. border: 2rpx solid #D1D5DB;
  503. text-align: center;
  504. }
  505. .retry-btn-text {
  506. font-size: 28rpx;
  507. color: #666;
  508. }
  509. .success-card {
  510. background: #fff;
  511. border-radius: 16rpx;
  512. padding: 60rpx 32rpx;
  513. text-align: center;
  514. margin-top: 120rpx;
  515. }
  516. .success-icon {
  517. font-size: 80rpx;
  518. display: block;
  519. margin-bottom: 24rpx;
  520. }
  521. .success-title {
  522. font-size: 36rpx;
  523. font-weight: 700;
  524. color: #10B981;
  525. display: block;
  526. margin-bottom: 12rpx;
  527. }
  528. .success-desc {
  529. font-size: 28rpx;
  530. color: #666;
  531. }
  532. .loading-overlay {
  533. position: fixed;
  534. top: 0; left: 0; right: 0; bottom: 0;
  535. background: rgba(0,0,0,0.5);
  536. display: flex;
  537. align-items: center;
  538. justify-content: center;
  539. z-index: 999;
  540. }
  541. .loading-box {
  542. background: #fff;
  543. border-radius: 16rpx;
  544. padding: 48rpx 64rpx;
  545. }
  546. .loading-text {
  547. font-size: 30rpx;
  548. color: #333;
  549. }
  550. .purchase-section {
  551. background: #F0F9FF;
  552. border-radius: 16rpx;
  553. padding: 24rpx;
  554. margin-top: 24rpx;
  555. border: 2rpx solid #BAE6FD;
  556. }
  557. .purchase-header {
  558. display: flex;
  559. flex-direction: row;
  560. align-items: center;
  561. margin-bottom: 16rpx;
  562. }
  563. .purchase-icon {
  564. font-size: 28rpx;
  565. margin-right: 8rpx;
  566. }
  567. .purchase-title {
  568. font-size: 26rpx;
  569. font-weight: bold;
  570. color: #0369A1;
  571. }
  572. .purchase-scroll {
  573. display: flex;
  574. flex-direction: row;
  575. white-space: nowrap;
  576. }
  577. .purchase-card {
  578. display: inline-flex;
  579. flex-direction: column;
  580. width: 220rpx;
  581. background: #fff;
  582. border-radius: 12rpx;
  583. padding: 16rpx;
  584. margin-right: 16rpx;
  585. flex-shrink: 0;
  586. }
  587. .purchase-cover {
  588. width: 188rpx;
  589. height: 120rpx;
  590. border-radius: 8rpx;
  591. background: #F1F5F9;
  592. margin-bottom: 8rpx;
  593. }
  594. .purchase-name {
  595. font-size: 22rpx;
  596. color: #333;
  597. line-height: 1.3;
  598. overflow: hidden;
  599. text-overflow: ellipsis;
  600. white-space: nowrap;
  601. margin-bottom: 4rpx;
  602. }
  603. .purchase-price {
  604. font-size: 24rpx;
  605. color: #EF4444;
  606. font-weight: bold;
  607. margin-bottom: 8rpx;
  608. }
  609. .purchase-btn {
  610. background: #3B82F6;
  611. border-radius: 8rpx;
  612. padding: 8rpx 0;
  613. text-align: center;
  614. }
  615. .purchase-btn-text {
  616. font-size: 22rpx;
  617. color: #fff;
  618. font-weight: 500;
  619. }
  620. </style>