report-upload.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="upload-container">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <text class="nav-back" @click="goBack">‹ 返回</text>
  6. <text class="nav-title">上传健康报告</text>
  7. <view class="nav-placeholder"></view>
  8. </view>
  9. <!-- 说明提示 -->
  10. <view class="tip-banner">
  11. <text class="tip-icon">📋</text>
  12. <text class="tip-text">上传体检报告或肠道检测报告,以便为您解读并提供个性化营养方案</text>
  13. </view>
  14. <!-- 表单 -->
  15. <view class="form-section">
  16. <!-- 上传方式:并排卡片 -->
  17. <view class="upload-methods">
  18. <view class="upload-card card-file" @click="pickFile">
  19. <view class="upload-card-icon">📄</view>
  20. <text class="upload-card-title">从聊天选择文件</text>
  21. <text class="upload-card-desc">PDF / Word / 图片<br/>体检报告、肠道检测报告</text>
  22. </view>
  23. <view class="upload-card card-photo" @click="takePhoto">
  24. <view class="upload-card-icon">📷</view>
  25. <text class="upload-card-title">拍照上传</text>
  26. <text class="upload-card-desc">拍摄舌象照片<br/>或单页纸质报告</text>
  27. </view>
  28. </view>
  29. <!-- 上传中 -->
  30. <view class="form-item" v-if="uploading">
  31. <text class="form-label">上传中...</text>
  32. <view class="analyzing-status">
  33. <text class="analyzing-text">正在上传文件,即将进入分析页面...</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 底部占位 -->
  38. <view class="bottom-spacer"></view>
  39. <!-- 菌群测评商品 -->
  40. <view class="product-section" v-if="recommendedProducts.length > 0">
  41. <view class="product-header">
  42. <text class="product-header-icon">📦</text>
  43. <text class="product-header-title">为家人购买检测服务</text>
  44. </view>
  45. <view class="product-grid">
  46. <view
  47. class="product-card"
  48. v-for="item in recommendedProducts"
  49. :key="item.id"
  50. @click="goToProduct(item.id)"
  51. >
  52. <image class="product-cover" :src="getImageUrl(item.coverImage) || '/static/default-product.png'" mode="aspectFill" />
  53. <text class="product-name">{{ item.name }}</text>
  54. <text class="product-price">{{ formatPriceWithSymbol(item.price) }}</text>
  55. <view class="product-btn">
  56. <text class="product-btn-text">去购买</text>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import { getProductsByDomain, uploadReportOnly } from '../../utils/api.js'
  65. import config from '@/config.js'
  66. export default {
  67. data() {
  68. return {
  69. memberId: null,
  70. uploading: false,
  71. selectedFile: null,
  72. photoPath: null,
  73. // 购买推荐
  74. recommendedProducts: [],
  75. loadingProducts: false
  76. }
  77. },
  78. onLoad: function(options) {
  79. this.memberId = options.memberId ? parseInt(options.memberId) : null
  80. this.loadRecommendProducts()
  81. },
  82. onShow: function() {
  83. this.loadRecommendProducts()
  84. },
  85. methods: {
  86. // ===== 拍照上传 =====
  87. takePhoto() {
  88. var self = this
  89. uni.chooseImage({
  90. count: 1,
  91. sourceType: ['camera', 'album'],
  92. success: function(res) {
  93. self.photoPath = res.tempFilePaths[0]
  94. // 拍照后直接上传并进入确认页
  95. self.uploadAndGoConfirm(self.photoPath, 'image')
  96. }
  97. })
  98. },
  99. // ===== 文件上传 =====
  100. pickFile() {
  101. var self = this
  102. uni.chooseMessageFile({
  103. count: 1,
  104. type: 'file',
  105. extension: ['pdf'],
  106. success: function(res) {
  107. var files = res.tempFiles
  108. if (files && files.length > 0) {
  109. self.selectedFile = files[0]
  110. // 直接上传并进入确认页(后端会自行处理成员匹配)
  111. self.uploadAndGoConfirm(files[0].path, '')
  112. }
  113. },
  114. fail: function(e) {
  115. console.log('选择文件取消或失败', e)
  116. }
  117. })
  118. },
  119. // 上传文件 → 自动跳转确认页(确认页按 draftId 触发解析并自动刷新显示结果)
  120. uploadAndGoConfirm(filePath, type) {
  121. var self = this
  122. if (!filePath) return
  123. self.uploading = true
  124. uni.showLoading({ title: '上传中...' })
  125. uploadReportOnly(filePath, type).then(function(res) {
  126. uni.hideLoading()
  127. self.uploading = false
  128. var draftId = res.data && res.data.draftId
  129. if (!draftId) {
  130. uni.showToast({ title: (res && res.message) || '上传失败', icon: 'none' })
  131. return
  132. }
  133. // 只传 draftId,确认页自行解析
  134. uni.redirectTo({ url: '/pages/health/report-confirm?draftId=' + draftId })
  135. }).catch(function(err) {
  136. uni.hideLoading()
  137. self.uploading = false
  138. var msg = (err && err.message) || '上传失败,请重试'
  139. uni.showToast({ title: msg, icon: 'none' })
  140. })
  141. },
  142. loadRecommendProducts: function() {
  143. var self = this
  144. self.loadingProducts = true
  145. // 直接按身体维度加载推荐商品(商城已有的 domain 筛选器)
  146. getProductsByDomain('body', 1, 4).then(function(res) {
  147. if (res && res.data && res.data.records) {
  148. self.recommendedProducts = res.data.records
  149. } else {
  150. self.recommendedProducts = []
  151. }
  152. }).catch(function() {
  153. self.recommendedProducts = []
  154. }).finally(function() {
  155. self.loadingProducts = false
  156. })
  157. },
  158. goToProduct: function(productId) {
  159. // 直接进入结算页,跳过商品详情页
  160. var product = this.recommendedProducts.find(function(p) { return p.id === productId })
  161. if (product) {
  162. var productData = {
  163. productId: product.id,
  164. productName: product.name,
  165. coverImage: product.coverImage || '',
  166. unitPrice: product.price || 0,
  167. quantity: 1
  168. }
  169. uni.setStorageSync('checkoutItems', [productData])
  170. uni.navigateTo({ url: '/pages/shop/checkout/checkout?from=report_upload&id=' + productId })
  171. } else {
  172. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + productId })
  173. }
  174. },
  175. formatPriceWithSymbol: function(cents) {
  176. if (cents === null || cents === undefined) return '¥0'
  177. return '¥' + (cents / 100).toFixed(2)
  178. },
  179. goBack() {
  180. uni.navigateBack()
  181. },
  182. getImageUrl: function(path) {
  183. return config.API_BASE_URL + path
  184. }
  185. }
  186. }
  187. </script>
  188. <style scoped>
  189. .upload-container {
  190. min-height: 100vh;
  191. background: #F5F7FA;
  192. }
  193. /* ===== 导航栏 ===== */
  194. .nav-bar {
  195. position: sticky;
  196. top: 0;
  197. background: #fff;
  198. display: flex;
  199. flex-direction: row;
  200. align-items: center;
  201. justify-content: space-between;
  202. padding: 20rpx 30rpx;
  203. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  204. z-index: 100;
  205. }
  206. .nav-back {
  207. font-size: 32rpx;
  208. color: #5B9BD5;
  209. }
  210. .nav-title {
  211. font-size: 32rpx;
  212. font-weight: bold;
  213. color: #333;
  214. }
  215. .nav-placeholder {
  216. width: 80rpx;
  217. }
  218. /* ===== 提示条 ===== */
  219. .tip-banner {
  220. display: flex;
  221. flex-direction: row;
  222. align-items: center;
  223. background: #E3F2FD;
  224. margin: 20rpx 30rpx;
  225. padding: 20rpx 24rpx;
  226. border-radius: 16rpx;
  227. }
  228. .tip-icon {
  229. font-size: 32rpx;
  230. margin-right: 16rpx;
  231. flex-shrink: 0;
  232. }
  233. .tip-text {
  234. font-size: 24rpx;
  235. color: #1565C0;
  236. line-height: 1.5;
  237. }
  238. /* ===== 表单 ===== */
  239. .form-section {
  240. margin: 0 30rpx;
  241. }
  242. .form-item {
  243. background: #fff;
  244. border-radius: 16rpx;
  245. padding: 24rpx;
  246. margin-bottom: 20rpx;
  247. }
  248. .form-label {
  249. font-size: 26rpx;
  250. font-weight: bold;
  251. color: #333;
  252. display: block;
  253. margin-bottom: 16rpx;
  254. }
  255. /* 上传中状态 */
  256. .analyzing-status {
  257. display: flex;
  258. flex-direction: row;
  259. align-items: center;
  260. }
  261. .analyzing-text {
  262. font-size: 26rpx;
  263. color: #5B9BD5;
  264. }
  265. /* ===== 底部 ===== */
  266. .bottom-spacer {
  267. height: 60rpx;
  268. }
  269. /* ===== 上传方式:并排卡片 ===== */
  270. .upload-methods {
  271. display: flex;
  272. flex-direction: row;
  273. gap: 20rpx;
  274. margin-bottom: 20rpx;
  275. }
  276. .upload-card {
  277. flex: 1;
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. justify-content: center;
  282. padding: 40rpx 20rpx;
  283. border-radius: 20rpx;
  284. text-align: center;
  285. min-height: 240rpx;
  286. }
  287. .upload-card:active {
  288. opacity: 0.85;
  289. }
  290. .upload-card-icon {
  291. width: 96rpx;
  292. height: 96rpx;
  293. border-radius: 24rpx;
  294. font-size: 48rpx;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. margin-bottom: 20rpx;
  299. }
  300. .upload-card-title {
  301. font-size: 28rpx;
  302. font-weight: 600;
  303. color: #333;
  304. margin-bottom: 10rpx;
  305. }
  306. .upload-card-desc {
  307. font-size: 22rpx;
  308. color: #94A3B8;
  309. line-height: 1.5;
  310. }
  311. .card-file {
  312. background: #F0F7FF;
  313. border: 2rpx dashed #93C5FD;
  314. }
  315. .card-file .upload-card-icon {
  316. background: linear-gradient(135deg, #3B82F6, #1D4ED8);
  317. color: #fff;
  318. box-shadow: 0 4rpx 12rpx rgba(59, 130, 246, 0.3);
  319. }
  320. .card-photo {
  321. background: #FFF7ED;
  322. border: 2rpx solid #FED7AA;
  323. }
  324. .card-photo .upload-card-icon {
  325. background: linear-gradient(135deg, #FB923C, #EA580C);
  326. color: #fff;
  327. box-shadow: 0 4rpx 12rpx rgba(234, 88, 12, 0.25);
  328. }
  329. /* ===== 菌群测评商品 ===== */
  330. .product-section {
  331. margin: 0 30rpx 30rpx;
  332. }
  333. .product-header {
  334. display: flex;
  335. flex-direction: row;
  336. align-items: center;
  337. margin-bottom: 16rpx;
  338. }
  339. .product-header-icon {
  340. font-size: 28rpx;
  341. margin-right: 8rpx;
  342. }
  343. .product-header-title {
  344. font-size: 26rpx;
  345. font-weight: bold;
  346. color: #333;
  347. }
  348. .product-grid {
  349. display: flex;
  350. flex-direction: row;
  351. flex-wrap: wrap;
  352. gap: 16rpx;
  353. }
  354. .product-card {
  355. width: calc(50% - 8rpx);
  356. background: #fff;
  357. border-radius: 16rpx;
  358. padding: 20rpx;
  359. box-sizing: border-box;
  360. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  361. }
  362. .product-card:active {
  363. opacity: 0.85;
  364. }
  365. .product-cover {
  366. width: 100%;
  367. height: 160rpx;
  368. border-radius: 10rpx;
  369. background: #F1F5F9;
  370. margin-bottom: 12rpx;
  371. }
  372. .product-name {
  373. display: block;
  374. font-size: 24rpx;
  375. color: #333;
  376. font-weight: 500;
  377. line-height: 1.3;
  378. overflow: hidden;
  379. text-overflow: ellipsis;
  380. white-space: nowrap;
  381. margin-bottom: 6rpx;
  382. }
  383. .product-price {
  384. display: block;
  385. font-size: 26rpx;
  386. color: #EF4444;
  387. font-weight: bold;
  388. margin-bottom: 12rpx;
  389. }
  390. .product-btn {
  391. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  392. border-radius: 8rpx;
  393. padding: 12rpx 0;
  394. text-align: center;
  395. }
  396. .product-btn-text {
  397. font-size: 24rpx;
  398. color: #fff;
  399. font-weight: 500;
  400. }
  401. </style>