report-upload.vue 15 KB

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