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

177 lines
4.3 KiB

  1. <template>
  2. <view>
  3. <view class="tabs">
  4. <uv-tabs
  5. :list="tabs"
  6. :activeStyle="{
  7. 'font-family': 'PingFang SC',
  8. 'font-weight': 600,
  9. 'font-size': '28rpx',
  10. 'line-height': 1.5,
  11. 'color': '#FFFFFF',
  12. 'background-color': '#252545',
  13. 'border-radius': '32rpx',
  14. 'padding': '9rpx 40rpx',
  15. }"
  16. :inactiveStyle="{
  17. 'font-family': 'PingFang SC',
  18. 'font-weight': 400,
  19. 'font-size': '28rpx',
  20. 'line-height': 1.5,
  21. 'color': '#252545',
  22. 'background-color': '#E5E4EB',
  23. 'border-radius': '32rpx',
  24. 'padding': '9rpx 40rpx',
  25. }"
  26. lineWidth="0"
  27. lineHeight="0"
  28. :current="level1"
  29. @change="onLevel1TabChange"
  30. ></uv-tabs>
  31. <view v-if="tabs[level1] && tabs[level1].children && tabs[level1].children.length"
  32. class="tabs-second"
  33. >
  34. <uv-tabs
  35. :list="tabs[level1].children"
  36. :activeStyle="{
  37. 'font-family': 'PingFang SC',
  38. 'font-weight': 600,
  39. 'font-size': '28rpx',
  40. 'line-height': 1.5,
  41. 'color': '#7451DE',
  42. }"
  43. :inactiveStyle="{
  44. 'font-family': 'PingFang SC',
  45. 'font-weight': 400,
  46. 'font-size': '28rpx',
  47. 'line-height': 1.5,
  48. 'color': '#252545',
  49. }"
  50. lineWidth="0"
  51. lineHeight="0"
  52. :current="level2"
  53. @change="onLevel2TabChange"
  54. ></uv-tabs>
  55. </view>
  56. </view>
  57. <view v-if="list.length" :class="['content', isMeal ? 'is-meal' : '']">
  58. <template v-if="isMeal">
  59. <view v-for="item in list" :key="item.id" style="min-width: 0;">
  60. <detectPackageCard
  61. :data="item"
  62. ></detectPackageCard>
  63. </view>
  64. </template>
  65. <template v-else>
  66. <view v-for="item in list" :key="item.id" style="min-width: 0;">
  67. <productCard
  68. :data="item"
  69. cardStyle="width: 100%; height: 210px;"
  70. imgStyle="width: 100%; height: 110px;"
  71. ></productCard>
  72. </view>
  73. </template>
  74. </view>
  75. <template v-else>
  76. <uv-empty mode="list"></uv-empty>
  77. </template>
  78. </view>
  79. </template>
  80. <script>
  81. import productCard from '@/pages_order/product/productCard.vue'
  82. import detectPackageCard from './detectPackageCard.vue'
  83. export default {
  84. components: {
  85. productCard,
  86. detectPackageCard,
  87. },
  88. props: {
  89. type: {
  90. type: Number,
  91. default: 0,
  92. },
  93. list: {
  94. type: Array,
  95. default() {
  96. return []
  97. }
  98. },
  99. isMeal: {
  100. type: Boolean,
  101. default: false
  102. }
  103. },
  104. data() {
  105. return {
  106. tabs: [],
  107. level1: 0,
  108. level2: null,
  109. }
  110. },
  111. mounted() {
  112. this.fetchCategory()
  113. },
  114. methods: {
  115. async fetchCategory() {
  116. try {
  117. let result = await this.$fetch('getProductCategory', { type: this.type }) // type: 产品类型(0营养剂,1预约,2课程)
  118. this.tabs = result.reduce((arr, item) => {
  119. const { id, name, child } = item
  120. let obj = { id, name, children: child }
  121. arr.push(obj)
  122. return arr
  123. }, [{ name: '全部' }])
  124. } catch (err) {
  125. }
  126. },
  127. onLevel1TabChange(e) {
  128. console.log('level1', e.index)
  129. this.level1 = e.index
  130. if (this.tabs[this.level1].children?.length) {
  131. this.level2 = 0
  132. this.$emit('categoryChange', { classId: this.tabs[this.level1].children[this.level2].id })
  133. } else {
  134. this.level2 = null
  135. this.$emit('categoryChange', { classId: this.tabs[this.level1].id })
  136. }
  137. },
  138. onLevel2TabChange(e) {
  139. console.log('level2', e.index)
  140. this.level2 = e.index
  141. this.$emit('categoryChange', { classId: this.tabs[this.level1].children[this.level2].id })
  142. },
  143. },
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .tabs {
  148. margin: 0 5px;
  149. &-second {
  150. margin: 0 11px;
  151. padding-left: 9px;
  152. background: #E5E4EB;
  153. border-radius: 16rpx;
  154. }
  155. }
  156. .content {
  157. padding: 24rpx 32rpx;
  158. display: grid;
  159. grid-template-columns: repeat(2, 1fr);
  160. gap: 32rpx;
  161. &.is-meal {
  162. grid-template-columns: 1fr;
  163. }
  164. }
  165. </style>