普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
7.2 KiB

  1. <template>
  2. <view class="page__view">
  3. <navbar title="检测报告" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <view id="swiper" class="swiper">
  6. <view id="home" :class="['swiper-item', 'swiper-item-home', current == 0 ? 'with-tips' : '']">
  7. <view class="content">
  8. <resultSummary :data="summaryData"></resultSummary>
  9. </view>
  10. <view v-if="current == 0" class="flex footer">
  11. <image class="footer-icon" src="@/pages_order/static/report/arrow-left.png" mode="widthFix"></image>
  12. <text>向左滑动卡片查看推荐补剂及原因</text>
  13. </view>
  14. </view>
  15. <view :id="item.id" :class="['swiper-item', getIsShowTips(index, current) ? 'with-tips' : '']"
  16. v-for="(item, index) in list"
  17. :key="item.id"
  18. >
  19. <view class="content">
  20. <tonicCard :data="item" :index="index"></tonicCard>
  21. </view>
  22. <view v-if="getIsShowTips(index, current)" class="flex footer">
  23. <image class="footer-icon" src="@/pages_order/static/report/arrow-left.png" mode="widthFix"></image>
  24. <text>向左滑动卡片查看推荐补剂及原因</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="bottom">
  30. <indicator :current="current" :length="list.length + 1"></indicator>
  31. <view class="flex bar">
  32. <button class="flex btn" @click="jumpToReportDetail">详细报告</button>
  33. <button class="flex btn highlight" @click="jumpToNutritionProgram">查看营养方案</button>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import indicator from '@/components/home/indicator.vue'
  40. import resultSummary from './resultSummary.vue'
  41. import tonicCard from './tonicCard.vue'
  42. export default {
  43. components: {
  44. indicator,
  45. resultSummary,
  46. tonicCard,
  47. },
  48. props: {
  49. id: {
  50. type: String | Number,
  51. default: null,
  52. }
  53. },
  54. data() {
  55. return {
  56. current: 0,
  57. summaryData: {},
  58. list: [],
  59. observer: null,
  60. }
  61. },
  62. async mounted() {
  63. await this.fetchReportData(this.id)
  64. this.$nextTick(() => {
  65. this.observeElement()
  66. })
  67. },
  68. unmounted() {
  69. console.log('unmounted')
  70. this.observer.disconnect()
  71. },
  72. methods: {
  73. async fetchReportData(id) {
  74. // todo: fetch
  75. this.summaryData = {
  76. score: 77,
  77. gradeDesc: '良好',
  78. scoreDetail: [77, 23, 67, 88, 98],
  79. tags: ['皮肤', '脑力/注意力', '眼睛/视力', '睡眠', '骨骼/关节'],
  80. topPriority: '脑力/注意力',
  81. }
  82. this.list = [
  83. {
  84. id: '001',
  85. url: '',
  86. name: '维生素 D',
  87. nameEn: 'Vitamin D',
  88. use: '推荐使用·每日一粒',
  89. title: '缺乏相应的营养物质会导致生长发育不良',
  90. desc: '维生素D能促进钙的吸收,促进骨骼发育,维生素D3滴剂更利于儿童吸收',
  91. },
  92. {
  93. id: '002',
  94. url: '',
  95. name: '维生素 D',
  96. nameEn: 'Vitamin D',
  97. use: '推荐使用·每日一粒',
  98. title: '缺乏相应的营养物质会导致生长发育不良',
  99. desc: '维生素D能促进钙的吸收,促进骨骼发育,维生素D3滴剂更利于儿童吸收',
  100. },
  101. {
  102. id: '003',
  103. url: '',
  104. name: '维生素 D',
  105. nameEn: 'Vitamin D',
  106. use: '推荐使用·每日一粒',
  107. title: '缺乏相应的营养物质会导致生长发育不良',
  108. desc: '维生素D能促进钙的吸收,促进骨骼发育,维生素D3滴剂更利于儿童吸收',
  109. },
  110. ]
  111. },
  112. observeElement() {
  113. this.observer = uni.createIntersectionObserver(this, { observeAll: true, thresholds: [0.5] });
  114. this.observer.relativeTo('.swiper').observe('.swiper-item', res => {
  115. let current = 0
  116. if (res.intersectionRatio > 0.5) {
  117. current = res.id === 'home' ? 0 : this.list.findIndex(item => item.id === res.id)
  118. } else if (res.intersectionRatio > 0) {
  119. current = res.id === 'home' ? 0 : this.list.findIndex(item => item.id === res.id) + 1
  120. if (res.boundingClientRect.left > 0) {
  121. current -= 1
  122. } else {
  123. current += 1
  124. }
  125. }
  126. this.current = current
  127. })
  128. },
  129. getIsShowTips(index, current) {
  130. return current == index + 1 && current < this.list.length
  131. },
  132. jumpToReportDetail() {
  133. this.$utils.navigateTo(`/pages_order/report/detail/index?id=${this.id}`)
  134. },
  135. jumpToNutritionProgram() {
  136. this.$utils.navigateTo(`/pages_order/report/nutritionProgram/index?id=${this.id}`)
  137. },
  138. },
  139. }
  140. </script>
  141. <style scoped lang="scss">
  142. .page__view {
  143. width: 100vw;
  144. min-height: 100vh;
  145. background-color: $uni-bg-color;
  146. position: relative;
  147. }
  148. .swiper {
  149. display: flex;
  150. overflow: auto;
  151. scroll-snap-type: x mandatory;
  152. width: 100vw;
  153. // height: calc(100vh * 640 / 882);
  154. height: auto;
  155. margin-top: 32rpx;
  156. &::-webkit-scrollbar{
  157. width: 0;
  158. height: 0;
  159. }
  160. }
  161. $tips-height: 108rpx;
  162. .swiper-item {
  163. position: relative;
  164. display: flex;
  165. justify-content: center;
  166. flex-shrink: 0;
  167. scroll-snap-align: center;
  168. scroll-snap-stop: always;
  169. $swiper-width: calc(100vw * 300 / 375);
  170. width: $swiper-width;
  171. // height: 100%;
  172. // height: auto;
  173. // height: 1186rpx;
  174. height: 1162rpx;
  175. margin-left: 32rpx;
  176. padding-bottom: $tips-height;
  177. // box-sizing: border-box;
  178. .content {
  179. position: relative;
  180. width: 100%;
  181. height: 100%;
  182. width: calc(100% - 8rpx * 2);
  183. height: calc(100% - 8rpx * 2);
  184. background-image: linear-gradient(#F2EDFF, #FCFEFE);
  185. border: 8rpx solid #F9F7FF;
  186. border-radius: 64rpx;
  187. }
  188. &.with-tips {
  189. .content {
  190. height: calc(100% - 8rpx);
  191. border-bottom: none;
  192. border-bottom-left-radius: 0;
  193. border-bottom-right-radius: 0;
  194. }
  195. }
  196. &-home {
  197. width: calc(100vw * 322 / 375);
  198. // height: 1320rpx;
  199. // height: auto;
  200. .content {
  201. overflow-y: auto;
  202. }
  203. }
  204. &:last-child {
  205. margin-right: calc((100vw - #{$swiper-width}) / 2);
  206. }
  207. }
  208. .footer {
  209. position: absolute;
  210. left: 0;
  211. bottom: 0;
  212. width: 100%;
  213. height: $tips-height;
  214. font-family: PingFang SC;
  215. font-weight: 400;
  216. font-size: 28rpx;
  217. line-height: 1.5;
  218. color: #252545;
  219. background: #E5E4EB;
  220. border-bottom-left-radius: 64rpx;
  221. border-bottom-right-radius: 64rpx;
  222. &-icon {
  223. width: 40rpx;
  224. height: 40rpx;
  225. margin-right: 16rpx;
  226. }
  227. }
  228. .bottom {
  229. width: 100%;
  230. position: fixed;
  231. left: 0;
  232. bottom: 0;
  233. }
  234. .bar {
  235. padding: 24rpx 40rpx 30rpx 40rpx;
  236. background: #FFFFFF;
  237. column-gap: 32rpx;
  238. margin-top: 16rpx;
  239. .btn {
  240. flex: 1;
  241. font-family: PingFang SC;
  242. font-size: 36rpx;
  243. font-weight: 500;
  244. line-height: 1;
  245. padding: 14rpx 0;
  246. border: 2rpx solid #252545;
  247. border-radius: 41rpx;
  248. &.highlight {
  249. padding: 16rpx 0;
  250. color: #FFFFFF;
  251. background-image: linear-gradient(to right, #4B348F, #845CFA);
  252. border: none;
  253. }
  254. }
  255. }
  256. </style>