report-upload.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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="getImageUrl(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. import config from '@/config.js'
  133. var REPORT_DOMAIN_MAP = {
  134. mind: 'mind',
  135. wisdom: 'wisdom'
  136. }
  137. export default {
  138. data() {
  139. return {
  140. step: 1,
  141. dimension: 'mind',
  142. selectedFile: null,
  143. previewData: null,
  144. draftId: null,
  145. loading: false,
  146. confirming: false,
  147. recommendedProducts: [],
  148. loadingProducts: false
  149. }
  150. },
  151. onLoad: function() {
  152. this.loadRecommendProducts(this.dimension)
  153. },
  154. methods: {
  155. goBack: function() {
  156. uni.navigateBack()
  157. },
  158. chooseFile: function() {
  159. var self = this
  160. uni.chooseMessageFile({
  161. count: 1,
  162. type: 'file',
  163. extension: ['pdf'],
  164. success: function(res) {
  165. if (res.tempFiles && res.tempFiles.length > 0) {
  166. self.selectedFile = res.tempFiles[0]
  167. }
  168. },
  169. fail: function() {
  170. // 降级:使用相册/相机
  171. uni.chooseImage({
  172. count: 1,
  173. success: function(res) {
  174. if (res.tempFiles && res.tempFiles.length > 0) {
  175. self.selectedFile = res.tempFiles[0]
  176. }
  177. }
  178. })
  179. }
  180. })
  181. },
  182. startUpload: function() {
  183. if (this.loading) return
  184. if (!this.selectedFile) return
  185. var self = this
  186. self.loading = true
  187. var memberId = this.$store.state && this.$store.state.currentChildId
  188. ? this.$store.state.currentChildId
  189. : uni.getStorageSync('currentChildId')
  190. danParsePreview(self.selectedFile.path || self.selectedFile.tempFilePath, self.dimension, memberId)
  191. .then(function(res) {
  192. self.loading = false
  193. if (res.code === 200 && res.data) {
  194. self.previewData = res.data
  195. self.draftId = res.data.draftId
  196. self.step = 2
  197. } else {
  198. uni.showToast({ title: res.message || '解析失败', icon: 'none' })
  199. }
  200. })
  201. .catch(function(err) {
  202. self.loading = false
  203. uni.showToast({ title: err && err.message ? err.message : '上传失败', icon: 'none' })
  204. })
  205. },
  206. doConfirm: function() {
  207. if (this.confirming) return
  208. var self = this
  209. self.confirming = true
  210. var memberId = this.$store.state && this.$store.state.currentChildId
  211. ? this.$store.state.currentChildId
  212. : uni.getStorageSync('currentChildId')
  213. danConfirmReport({
  214. draftId: self.draftId,
  215. dimension: self.dimension,
  216. memberId: memberId
  217. })
  218. .then(function(res) {
  219. self.confirming = false
  220. if (res.code === 200) {
  221. self.step = 3
  222. } else {
  223. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  224. }
  225. })
  226. .catch(function(err) {
  227. self.confirming = false
  228. uni.showToast({ title: '保存失败', icon: 'none' })
  229. })
  230. },
  231. resetUpload: function() {
  232. this.step = 1
  233. this.selectedFile = null
  234. this.previewData = null
  235. this.draftId = null
  236. },
  237. selectDimension: function(dim) {
  238. this.dimension = dim
  239. this.loadRecommendProducts(dim)
  240. },
  241. loadRecommendProducts: function(dimension) {
  242. var domain = REPORT_DOMAIN_MAP[dimension]
  243. if (!domain) {
  244. this.recommendedProducts = []
  245. return
  246. }
  247. var self = this
  248. self.loadingProducts = true
  249. productList({ domain: domain, productType: 'assessment', size: 4 }).then(function(res) {
  250. if (res && res.data && res.data.records) {
  251. self.recommendedProducts = res.data.records
  252. } else {
  253. self.recommendedProducts = []
  254. }
  255. }).catch(function() {
  256. self.recommendedProducts = []
  257. }).finally(function() {
  258. self.loadingProducts = false
  259. })
  260. },
  261. goToProduct: function(productId) {
  262. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + productId })
  263. },
  264. formatPriceWithSymbol: function(cents) {
  265. if (cents === null || cents === undefined) return '¥0'
  266. return '¥' + (cents / 100).toFixed(2)
  267. },
  268. getImageUrl: function(path) {
  269. return config.API_BASE_URL + path
  270. }
  271. }
  272. }
  273. </script>
  274. <style>
  275. .page {
  276. min-height: 100vh;
  277. background: #F5F5F7;
  278. padding-bottom: 40rpx;
  279. }
  280. .header {
  281. display: flex;
  282. align-items: center;
  283. padding: 88rpx 32rpx 24rpx;
  284. background: linear-gradient(135deg, #667EEA, #764BA2);
  285. }
  286. .back-btn {
  287. display: flex;
  288. align-items: center;
  289. margin-right: 24rpx;
  290. padding: 8rpx 16rpx;
  291. }
  292. .back-icon {
  293. font-size: 36rpx;
  294. color: #fff;
  295. margin-right: 8rpx;
  296. }
  297. .header-title {
  298. font-size: 36rpx;
  299. font-weight: 700;
  300. color: #fff;
  301. }
  302. .section {
  303. margin: 24rpx 24rpx 0;
  304. }
  305. .dimension-select {
  306. background: #fff;
  307. border-radius: 16rpx;
  308. padding: 32rpx;
  309. }
  310. .dimension-label {
  311. font-size: 28rpx;
  312. font-weight: 600;
  313. color: #333;
  314. margin-bottom: 20rpx;
  315. display: block;
  316. }
  317. .dimension-options {
  318. display: flex;
  319. gap: 20rpx;
  320. }
  321. .dimension-option {
  322. flex: 1;
  323. padding: 24rpx;
  324. border-radius: 12rpx;
  325. background: #F5F5F7;
  326. text-align: center;
  327. border: 2rpx solid transparent;
  328. }
  329. .dimension-option.active {
  330. background: #EEF2FF;
  331. border-color: #6366F1;
  332. }
  333. .dimension-name {
  334. font-size: 28rpx;
  335. color: #333;
  336. font-weight: 500;
  337. }
  338. .dimension-option.active .dimension-name {
  339. color: #6366F1;
  340. }
  341. .upload-area {
  342. background: #fff;
  343. border-radius: 16rpx;
  344. padding: 60rpx 32rpx;
  345. text-align: center;
  346. margin-top: 24rpx;
  347. border: 2rpx dashed #D1D5DB;
  348. }
  349. .upload-icon {
  350. font-size: 64rpx;
  351. margin-bottom: 16rpx;
  352. }
  353. .upload-text {
  354. font-size: 30rpx;
  355. color: #333;
  356. display: block;
  357. margin-bottom: 8rpx;
  358. }
  359. .upload-hint {
  360. font-size: 24rpx;
  361. color: #999;
  362. }
  363. .action-bar {
  364. margin-top: 32rpx;
  365. display: flex;
  366. gap: 20rpx;
  367. }
  368. .upload-btn {
  369. flex: 1;
  370. background: #6366F1;
  371. border-radius: 12rpx;
  372. padding: 24rpx;
  373. text-align: center;
  374. }
  375. .upload-btn-text {
  376. font-size: 30rpx;
  377. color: #fff;
  378. font-weight: 600;
  379. }
  380. .preview-header {
  381. margin-bottom: 24rpx;
  382. }
  383. .preview-title {
  384. font-size: 32rpx;
  385. font-weight: 700;
  386. color: #333;
  387. display: block;
  388. }
  389. .preview-desc {
  390. font-size: 24rpx;
  391. color: #999;
  392. margin-top: 8rpx;
  393. }
  394. .preview-card {
  395. background: #fff;
  396. border-radius: 16rpx;
  397. padding: 24rpx;
  398. }
  399. .preview-row {
  400. display: flex;
  401. justify-content: space-between;
  402. padding: 12rpx 0;
  403. border-bottom: 1rpx solid #F3F4F6;
  404. }
  405. .preview-row:last-child {
  406. border-bottom: none;
  407. }
  408. .preview-label {
  409. font-size: 26rpx;
  410. color: #666;
  411. }
  412. .preview-value {
  413. font-size: 26rpx;
  414. color: #333;
  415. font-weight: 500;
  416. }
  417. .items-section {
  418. margin-top: 24rpx;
  419. }
  420. .items-title {
  421. font-size: 28rpx;
  422. font-weight: 600;
  423. color: #333;
  424. margin-bottom: 16rpx;
  425. display: block;
  426. }
  427. .item-card {
  428. background: #fff;
  429. border-radius: 12rpx;
  430. padding: 20rpx;
  431. margin-bottom: 12rpx;
  432. }
  433. .item-header {
  434. display: flex;
  435. justify-content: space-between;
  436. margin-bottom: 12rpx;
  437. }
  438. .item-name {
  439. font-size: 26rpx;
  440. color: #333;
  441. font-weight: 500;
  442. }
  443. .item-category {
  444. font-size: 22rpx;
  445. color: #999;
  446. background: #F3F4F6;
  447. padding: 4rpx 12rpx;
  448. border-radius: 8rpx;
  449. }
  450. .item-value-bar {
  451. height: 16rpx;
  452. background: #F3F4F6;
  453. border-radius: 8rpx;
  454. overflow: hidden;
  455. }
  456. .item-value-fill {
  457. height: 100%;
  458. background: linear-gradient(90deg, #667EEA, #764BA2);
  459. border-radius: 8rpx;
  460. }
  461. .item-value-text {
  462. font-size: 24rpx;
  463. color: #666;
  464. margin-top: 8rpx;
  465. display: block;
  466. text-align: right;
  467. }
  468. .suggestions-card {
  469. background: #FFFBEB;
  470. border-radius: 16rpx;
  471. padding: 24rpx;
  472. margin-top: 24rpx;
  473. }
  474. .suggestions-title {
  475. font-size: 28rpx;
  476. font-weight: 600;
  477. color: #92400E;
  478. display: block;
  479. margin-bottom: 12rpx;
  480. }
  481. .suggestions-text {
  482. font-size: 26rpx;
  483. color: #78350F;
  484. line-height: 1.6;
  485. }
  486. .confirm-btn {
  487. flex: 1;
  488. background: #10B981;
  489. border-radius: 12rpx;
  490. padding: 24rpx;
  491. text-align: center;
  492. }
  493. .confirm-btn.disabled {
  494. opacity: 0.6;
  495. }
  496. .confirm-btn-text {
  497. font-size: 30rpx;
  498. color: #fff;
  499. font-weight: 600;
  500. }
  501. .retry-btn {
  502. padding: 24rpx 32rpx;
  503. border-radius: 12rpx;
  504. border: 2rpx solid #D1D5DB;
  505. text-align: center;
  506. }
  507. .retry-btn-text {
  508. font-size: 28rpx;
  509. color: #666;
  510. }
  511. .success-card {
  512. background: #fff;
  513. border-radius: 16rpx;
  514. padding: 60rpx 32rpx;
  515. text-align: center;
  516. margin-top: 120rpx;
  517. }
  518. .success-icon {
  519. font-size: 80rpx;
  520. display: block;
  521. margin-bottom: 24rpx;
  522. }
  523. .success-title {
  524. font-size: 36rpx;
  525. font-weight: 700;
  526. color: #10B981;
  527. display: block;
  528. margin-bottom: 12rpx;
  529. }
  530. .success-desc {
  531. font-size: 28rpx;
  532. color: #666;
  533. }
  534. .loading-overlay {
  535. position: fixed;
  536. top: 0; left: 0; right: 0; bottom: 0;
  537. background: rgba(0,0,0,0.5);
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. z-index: 999;
  542. }
  543. .loading-box {
  544. background: #fff;
  545. border-radius: 16rpx;
  546. padding: 48rpx 64rpx;
  547. }
  548. .loading-text {
  549. font-size: 30rpx;
  550. color: #333;
  551. }
  552. .purchase-section {
  553. background: #F0F9FF;
  554. border-radius: 16rpx;
  555. padding: 24rpx;
  556. margin-top: 24rpx;
  557. border: 2rpx solid #BAE6FD;
  558. }
  559. .purchase-header {
  560. display: flex;
  561. flex-direction: row;
  562. align-items: center;
  563. margin-bottom: 16rpx;
  564. }
  565. .purchase-icon {
  566. font-size: 28rpx;
  567. margin-right: 8rpx;
  568. }
  569. .purchase-title {
  570. font-size: 26rpx;
  571. font-weight: bold;
  572. color: #0369A1;
  573. }
  574. .purchase-scroll {
  575. display: flex;
  576. flex-direction: row;
  577. white-space: nowrap;
  578. }
  579. .purchase-card {
  580. display: inline-flex;
  581. flex-direction: column;
  582. width: 220rpx;
  583. background: #fff;
  584. border-radius: 12rpx;
  585. padding: 16rpx;
  586. margin-right: 16rpx;
  587. flex-shrink: 0;
  588. }
  589. .purchase-cover {
  590. width: 188rpx;
  591. height: 120rpx;
  592. border-radius: 8rpx;
  593. background: #F1F5F9;
  594. margin-bottom: 8rpx;
  595. }
  596. .purchase-name {
  597. font-size: 22rpx;
  598. color: #333;
  599. line-height: 1.3;
  600. overflow: hidden;
  601. text-overflow: ellipsis;
  602. white-space: nowrap;
  603. margin-bottom: 4rpx;
  604. }
  605. .purchase-price {
  606. font-size: 24rpx;
  607. color: #EF4444;
  608. font-weight: bold;
  609. margin-bottom: 8rpx;
  610. }
  611. .purchase-btn {
  612. background: #3B82F6;
  613. border-radius: 8rpx;
  614. padding: 8rpx 0;
  615. text-align: center;
  616. }
  617. .purchase-btn-text {
  618. font-size: 22rpx;
  619. color: #fff;
  620. font-weight: 500;
  621. }
  622. </style>