report-upload.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. .back-text {
  298. font-size: 28rpx;
  299. color: #fff;
  300. }
  301. .header-title {
  302. font-size: 36rpx;
  303. font-weight: 700;
  304. color: #fff;
  305. }
  306. .section {
  307. margin: 24rpx 24rpx 0;
  308. }
  309. .dimension-select {
  310. background: #fff;
  311. border-radius: 16rpx;
  312. padding: 32rpx;
  313. }
  314. .dimension-label {
  315. font-size: 28rpx;
  316. font-weight: 600;
  317. color: #333;
  318. margin-bottom: 20rpx;
  319. display: block;
  320. }
  321. .dimension-options {
  322. display: flex;
  323. gap: 20rpx;
  324. }
  325. .dimension-option {
  326. flex: 1;
  327. padding: 24rpx;
  328. border-radius: 12rpx;
  329. background: #F5F5F7;
  330. text-align: center;
  331. border: 2rpx solid transparent;
  332. }
  333. .dimension-option.active {
  334. background: #EEF2FF;
  335. border-color: #6366F1;
  336. }
  337. .dimension-name {
  338. font-size: 28rpx;
  339. color: #333;
  340. font-weight: 500;
  341. }
  342. .dimension-option.active .dimension-name {
  343. color: #6366F1;
  344. }
  345. .upload-area {
  346. background: #fff;
  347. border-radius: 16rpx;
  348. padding: 60rpx 32rpx;
  349. text-align: center;
  350. margin-top: 24rpx;
  351. border: 2rpx dashed #D1D5DB;
  352. }
  353. .upload-icon {
  354. font-size: 64rpx;
  355. margin-bottom: 16rpx;
  356. }
  357. .upload-text {
  358. font-size: 30rpx;
  359. color: #333;
  360. display: block;
  361. margin-bottom: 8rpx;
  362. }
  363. .upload-hint {
  364. font-size: 24rpx;
  365. color: #999;
  366. }
  367. .action-bar {
  368. margin-top: 32rpx;
  369. display: flex;
  370. gap: 20rpx;
  371. }
  372. .upload-btn {
  373. flex: 1;
  374. background: #6366F1;
  375. border-radius: 12rpx;
  376. padding: 24rpx;
  377. text-align: center;
  378. }
  379. .upload-btn-text {
  380. font-size: 30rpx;
  381. color: #fff;
  382. font-weight: 600;
  383. }
  384. .preview-header {
  385. margin-bottom: 24rpx;
  386. }
  387. .preview-title {
  388. font-size: 32rpx;
  389. font-weight: 700;
  390. color: #333;
  391. display: block;
  392. }
  393. .preview-desc {
  394. font-size: 24rpx;
  395. color: #999;
  396. margin-top: 8rpx;
  397. }
  398. .preview-card {
  399. background: #fff;
  400. border-radius: 16rpx;
  401. padding: 24rpx;
  402. }
  403. .preview-row {
  404. display: flex;
  405. justify-content: space-between;
  406. padding: 12rpx 0;
  407. border-bottom: 1rpx solid #F3F4F6;
  408. }
  409. .preview-row:last-child {
  410. border-bottom: none;
  411. }
  412. .preview-label {
  413. font-size: 26rpx;
  414. color: #666;
  415. }
  416. .preview-value {
  417. font-size: 26rpx;
  418. color: #333;
  419. font-weight: 500;
  420. }
  421. .items-section {
  422. margin-top: 24rpx;
  423. }
  424. .items-title {
  425. font-size: 28rpx;
  426. font-weight: 600;
  427. color: #333;
  428. margin-bottom: 16rpx;
  429. display: block;
  430. }
  431. .item-card {
  432. background: #fff;
  433. border-radius: 12rpx;
  434. padding: 20rpx;
  435. margin-bottom: 12rpx;
  436. }
  437. .item-header {
  438. display: flex;
  439. justify-content: space-between;
  440. margin-bottom: 12rpx;
  441. }
  442. .item-name {
  443. font-size: 26rpx;
  444. color: #333;
  445. font-weight: 500;
  446. }
  447. .item-category {
  448. font-size: 22rpx;
  449. color: #999;
  450. background: #F3F4F6;
  451. padding: 4rpx 12rpx;
  452. border-radius: 8rpx;
  453. }
  454. .item-value-bar {
  455. height: 16rpx;
  456. background: #F3F4F6;
  457. border-radius: 8rpx;
  458. overflow: hidden;
  459. }
  460. .item-value-fill {
  461. height: 100%;
  462. background: linear-gradient(90deg, #667EEA, #764BA2);
  463. border-radius: 8rpx;
  464. }
  465. .item-value-text {
  466. font-size: 24rpx;
  467. color: #666;
  468. margin-top: 8rpx;
  469. display: block;
  470. text-align: right;
  471. }
  472. .suggestions-card {
  473. background: #FFFBEB;
  474. border-radius: 16rpx;
  475. padding: 24rpx;
  476. margin-top: 24rpx;
  477. }
  478. .suggestions-title {
  479. font-size: 28rpx;
  480. font-weight: 600;
  481. color: #92400E;
  482. display: block;
  483. margin-bottom: 12rpx;
  484. }
  485. .suggestions-text {
  486. font-size: 26rpx;
  487. color: #78350F;
  488. line-height: 1.6;
  489. }
  490. .confirm-btn {
  491. flex: 1;
  492. background: #10B981;
  493. border-radius: 12rpx;
  494. padding: 24rpx;
  495. text-align: center;
  496. }
  497. .confirm-btn.disabled {
  498. opacity: 0.6;
  499. }
  500. .confirm-btn-text {
  501. font-size: 30rpx;
  502. color: #fff;
  503. font-weight: 600;
  504. }
  505. .retry-btn {
  506. padding: 24rpx 32rpx;
  507. border-radius: 12rpx;
  508. border: 2rpx solid #D1D5DB;
  509. text-align: center;
  510. }
  511. .retry-btn-text {
  512. font-size: 28rpx;
  513. color: #666;
  514. }
  515. .success-card {
  516. background: #fff;
  517. border-radius: 16rpx;
  518. padding: 60rpx 32rpx;
  519. text-align: center;
  520. margin-top: 120rpx;
  521. }
  522. .success-icon {
  523. font-size: 80rpx;
  524. display: block;
  525. margin-bottom: 24rpx;
  526. }
  527. .success-title {
  528. font-size: 36rpx;
  529. font-weight: 700;
  530. color: #10B981;
  531. display: block;
  532. margin-bottom: 12rpx;
  533. }
  534. .success-desc {
  535. font-size: 28rpx;
  536. color: #666;
  537. }
  538. .loading-overlay {
  539. position: fixed;
  540. top: 0; left: 0; right: 0; bottom: 0;
  541. background: rgba(0,0,0,0.5);
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. z-index: 999;
  546. }
  547. .loading-box {
  548. background: #fff;
  549. border-radius: 16rpx;
  550. padding: 48rpx 64rpx;
  551. }
  552. .loading-text {
  553. font-size: 30rpx;
  554. color: #333;
  555. }
  556. .purchase-section {
  557. background: #F0F9FF;
  558. border-radius: 16rpx;
  559. padding: 24rpx;
  560. margin-top: 24rpx;
  561. border: 2rpx solid #BAE6FD;
  562. }
  563. .purchase-header {
  564. display: flex;
  565. flex-direction: row;
  566. align-items: center;
  567. margin-bottom: 16rpx;
  568. }
  569. .purchase-icon {
  570. font-size: 28rpx;
  571. margin-right: 8rpx;
  572. }
  573. .purchase-title {
  574. font-size: 26rpx;
  575. font-weight: bold;
  576. color: #0369A1;
  577. }
  578. .purchase-scroll {
  579. display: flex;
  580. flex-direction: row;
  581. white-space: nowrap;
  582. }
  583. .purchase-card {
  584. display: inline-flex;
  585. flex-direction: column;
  586. width: 220rpx;
  587. background: #fff;
  588. border-radius: 12rpx;
  589. padding: 16rpx;
  590. margin-right: 16rpx;
  591. flex-shrink: 0;
  592. }
  593. .purchase-cover {
  594. width: 188rpx;
  595. height: 120rpx;
  596. border-radius: 8rpx;
  597. background: #F1F5F9;
  598. margin-bottom: 8rpx;
  599. }
  600. .purchase-name {
  601. font-size: 22rpx;
  602. color: #333;
  603. line-height: 1.3;
  604. overflow: hidden;
  605. text-overflow: ellipsis;
  606. white-space: nowrap;
  607. margin-bottom: 4rpx;
  608. }
  609. .purchase-price {
  610. font-size: 24rpx;
  611. color: #EF4444;
  612. font-weight: bold;
  613. margin-bottom: 8rpx;
  614. }
  615. .purchase-btn {
  616. background: #3B82F6;
  617. border-radius: 8rpx;
  618. padding: 8rpx 0;
  619. text-align: center;
  620. }
  621. .purchase-btn-text {
  622. font-size: 22rpx;
  623. color: #fff;
  624. font-weight: 500;
  625. }
  626. </style>