普兆健康管家前端代码仓库
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.

379 lines
9.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page__view">
  3. <navbar title="营养方案" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <reportCard>
  6. <view class="section header">
  7. <view>营养师基于你生活习惯和营养目标推荐</view>
  8. <view class="highlight">量身定制的营养方案</view>
  9. </view>
  10. <view class="section" v-for="(step, index) in list" :key="step.key">
  11. <view class="flex section-header">
  12. <view class="section-header-index">
  13. <text>{{ index + 1 }}</text>
  14. <image class="section-header-index-icon" :src="step.url" mode="widthFix"></image>
  15. </view>
  16. <view class="section-header-title">
  17. <view class="section-header-title-name">{{ step.name }}</view>
  18. <view class="section-header-title-desc">{{ step.desc }}</view>
  19. </view>
  20. </view>
  21. <view class="section-content">
  22. <view class="card" v-for="(item, idx) in step.children" :key="item.key" >
  23. <productCard :data="item" @select="onSelect(index, idx, $event)" ></productCard>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="section tips">
  28. *以上是根据你的营养目标以及饮食运动作息状况给出的针对性健康建议可以辅助你达成营养目标同时养成良好的生活习惯
  29. </view>
  30. </reportCard>
  31. </view>
  32. <view class="flex bottom">
  33. <view class="left">
  34. <button class="btn btn-comment" @click="jumpToComment">
  35. <view>查看评价</view>
  36. <view class="flex"><text class="highlight">{{ `${comment}` }}</text><uv-icon name="arrow-right" color="#C6C6C6" size="28rpx"></uv-icon></view>
  37. </button>
  38. </view>
  39. <view class="flex right">
  40. <button
  41. class="flex btn btn-cart"
  42. :disabled="!selectedCount"
  43. :class="[selectedCount ? '' : 'is-disabled']"
  44. @click="onAddCart"
  45. >
  46. <text>加入购物车</text>
  47. </button>
  48. <button
  49. class="flex btn btn-settle"
  50. :class="[selectedCount ? '' : 'is-disabled']"
  51. :disabled="!selectedCount"
  52. @click="onBuy"
  53. >
  54. <text>结算</text>
  55. <text v-if="selectedCount">{{ `(${selectedCount})` }}</text>
  56. </button>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import reportCard from '@/pages_order/components/reportCard.vue';
  63. import productCard from './productCard.vue';
  64. export default {
  65. components: {
  66. reportCard,
  67. productCard,
  68. },
  69. data() {
  70. return {
  71. productId: '',
  72. list: [],
  73. comment: 0,
  74. }
  75. },
  76. computed: {
  77. selectedCount() {
  78. let count = 0
  79. this.list.forEach(step => {
  80. step.children.forEach(item => {
  81. item.selected && count++
  82. })
  83. })
  84. return count
  85. },
  86. },
  87. async onLoad(arg) {
  88. const { id } = arg
  89. await this.fetchReportData(id)
  90. this.fetchCommentNum(this.productId)
  91. },
  92. methods: {
  93. async fetchCommentNum(productId) {
  94. try {
  95. this.comment = await this.$fetch('productEvaluateNum', { productId })
  96. } catch (err) {
  97. }
  98. },
  99. async fetchReportData(id) {
  100. try {
  101. const { productList } = await this.$fetch('getReportDetail', { id })
  102. const detectList = []
  103. const nutrientList = []
  104. const courseList = []
  105. const ids = []
  106. productList.forEach(item => {
  107. // 产品类型(0营养剂,1预约,2课程)
  108. const { id, type, specs, currentPrice } = item
  109. ids.push(id)
  110. const spec = specs?.[0] || {}
  111. const obj = {
  112. ...item,
  113. specId: spec.id,
  114. specName: spec.specName,
  115. currentPrice: spec.price || currentPrice,
  116. selected: true,
  117. }
  118. switch(type) {
  119. case '0':
  120. nutrientList.push(obj)
  121. break;
  122. case '1':
  123. detectList.push(obj)
  124. break;
  125. case '2':
  126. courseList.push(obj)
  127. break;
  128. default:
  129. break;
  130. }
  131. })
  132. this.list = [
  133. {
  134. id: '001',
  135. name: '检测方案',
  136. desc: '刚开始健康检测?专家推荐先做这几项',
  137. url: '/pages_order/static/report/report-nutrition-1.png',
  138. children: detectList
  139. },
  140. {
  141. id: '002',
  142. name: '基础方案',
  143. desc: `刚开始吃维生素?营养师建议从这${nutrientList.length}颗开始`,
  144. url: '/pages_order/static/report/report-nutrition-2.png',
  145. children: nutrientList
  146. },
  147. // todo: check is need?
  148. {
  149. id: '003',
  150. name: '课程方案',
  151. desc: '',
  152. url: '/pages_order/static/report/report-detail-3.png',
  153. children: courseList
  154. },
  155. ]
  156. this.productId = ids.join(',')
  157. console.log('list', this.list)
  158. console.log('productId', this.productId)
  159. } catch (err) {
  160. }
  161. },
  162. onSelect(stepIdx, childIdx, selected) {
  163. this.list[stepIdx].children[childIdx].selected = selected
  164. },
  165. getSelectedList() {
  166. return this.list.reduce((arr, step) => {
  167. const selectedArr = step.children.filter(product => product.selected)
  168. return arr.concat(selectedArr)
  169. }, [])
  170. },
  171. jumpToComment() {
  172. this.$utils.navigateTo(`/pages_order/comment/commentRecordsOfProduct?productId=${this.productId}`)
  173. },
  174. onAddCart() {
  175. const selectedList = this.getSelectedList()
  176. this.$store.dispatch('addCartBatch', selectedList)
  177. },
  178. onBuy() {
  179. const selectedList = this.getSelectedList()
  180. this.$store.commit('createOrder', selectedList)
  181. },
  182. },
  183. }
  184. </script>
  185. <style scoped lang="scss">
  186. .page__view {
  187. width: 100vw;
  188. min-height: 100vh;
  189. background-color: $uni-bg-color;
  190. position: relative;
  191. /deep/ .nav-bar__view {
  192. position: fixed;
  193. top: 0;
  194. left: 0;
  195. }
  196. }
  197. .main {
  198. padding: calc(var(--status-bar-height) + 152rpx) 32rpx 272rpx 32rpx;
  199. }
  200. .section {
  201. & + & {
  202. margin-top: 48rpx;
  203. padding-top: 12rpx;
  204. border-top: 2rpx dashed #989898;
  205. }
  206. &-header {
  207. justify-content: flex-start;
  208. &-index {
  209. position: relative;
  210. font-family: HarmonyOS Sans;
  211. font-weight: 700;
  212. font-size: 96rpx;
  213. line-height: 1.4;
  214. color: #D9D9D9;
  215. &-icon {
  216. position: absolute;
  217. left: 34rpx;
  218. top: 70rpx;
  219. width: 40rpx;
  220. height: 40rpx;
  221. }
  222. }
  223. &-title {
  224. margin-left: 32rpx;
  225. font-family: PingFang SC;
  226. line-height: 1.4;
  227. color: #252545;
  228. &-name {
  229. font-weight: 600;
  230. font-size: 40rpx;
  231. }
  232. &-desc {
  233. font-weight: 400;
  234. font-size: 26rpx;
  235. }
  236. }
  237. }
  238. &-content {
  239. padding-top: 18rpx;
  240. }
  241. }
  242. .section.header {
  243. font-family: PingFang SC;
  244. font-weight: 400;
  245. font-size: 36rpx;
  246. line-height: 1.2;
  247. color: #252545CC;
  248. .highlight {
  249. font-size: 48rpx;
  250. line-height: 1.4;
  251. font-weight: 600;
  252. font-family: PingFang SC;
  253. color: transparent;
  254. background-image: linear-gradient(to right, #4B348F, #845CFA);
  255. background-clip: text;
  256. display: inline-block;
  257. }
  258. }
  259. .tips {
  260. font-family: PingFang SC;
  261. font-weight: 400;
  262. font-size: 18rpx;
  263. line-height: 1.4;
  264. color: #989898;
  265. }
  266. .card {
  267. & + & {
  268. margin-top: 32rpx;
  269. }
  270. }
  271. .bottom {
  272. width: 100%;
  273. position: fixed;
  274. left: 0;
  275. bottom: 0;
  276. padding: 24rpx 40rpx;
  277. padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
  278. box-sizing: border-box;
  279. background: #FFFFFF;
  280. column-gap: 16rpx;
  281. .left {
  282. }
  283. .right {
  284. flex: 1;
  285. column-gap: 32rpx;
  286. }
  287. .btn {
  288. &-comment {
  289. display: inline-block;
  290. width: auto;
  291. text-align: left;
  292. font-family: PingFang SC;
  293. font-weight: 400;
  294. font-size: 24rpx;
  295. line-height: 1.4;
  296. color: #626262;
  297. .highlight {
  298. margin-right: 4rpx;
  299. font-family: 600;
  300. font-size: 30rpx;
  301. color: #252545;
  302. }
  303. }
  304. &-cart {
  305. flex: 1;
  306. padding: 14rpx 0;
  307. font-family: PingFang SC;
  308. font-size: 36rpx;
  309. font-weight: 500;
  310. line-height: 1;
  311. color: #252545;
  312. border: 2rpx solid #252545;
  313. border-radius: 41rpx;
  314. }
  315. &-settle {
  316. flex: 1;
  317. padding: 16rpx 0;
  318. font-family: PingFang SC;
  319. font-size: 36rpx;
  320. font-weight: 500;
  321. line-height: 1;
  322. color: #FFFFFF;
  323. background-image: linear-gradient(to right, #4B348F, #845CFA);
  324. border-radius: 41rpx;
  325. }
  326. &.is-disabled {
  327. opacity: 0.5;
  328. }
  329. }
  330. }
  331. </style>