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

157 lines
3.8 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">
  58. <view v-for="item in list" :key="item.id" style="min-width: 0;">
  59. <productCard
  60. :data="item"
  61. cardStyle="width: 100%; height: 210px;"
  62. imgStyle="width: 100%; height: 110px;"
  63. ></productCard>
  64. </view>
  65. </view>
  66. <template v-else>
  67. <uv-empty mode="list"></uv-empty>
  68. </template>
  69. </view>
  70. </template>
  71. <script>
  72. import productCard from '@/pages_order/product/productCard.vue'
  73. export default {
  74. components: {
  75. productCard,
  76. },
  77. props: {
  78. type: {
  79. type: Number,
  80. default: 0,
  81. },
  82. list: {
  83. type: Array,
  84. default() {
  85. return []
  86. }
  87. },
  88. },
  89. data() {
  90. return {
  91. tabs: [],
  92. level1: 0,
  93. level2: null,
  94. }
  95. },
  96. mounted() {
  97. this.fetchCategory()
  98. },
  99. methods: {
  100. async fetchCategory() {
  101. try {
  102. let result = await this.$fetch('getProductCategory', { type: this.type }) // type: 产品类型(0营养剂,1预约,2课程)
  103. this.tabs = result.reduce((arr, item) => {
  104. const { id, name, child } = item
  105. let obj = { id, name, children: child }
  106. arr.push(obj)
  107. return arr
  108. }, [{ name: '全部' }])
  109. } catch (err) {
  110. }
  111. },
  112. onLevel1TabChange(e) {
  113. console.log('level1', e.index)
  114. this.level1 = e.index
  115. if (this.tabs[this.level1].children?.length) {
  116. this.level2 = 0
  117. this.$emit('categoryChange', { classId: this.tabs[this.level1].children[this.level2].id })
  118. } else {
  119. this.level2 = null
  120. this.$emit('categoryChange', { classId: this.tabs[this.level1].id })
  121. }
  122. },
  123. onLevel2TabChange(e) {
  124. console.log('level2', e.index)
  125. this.level2 = e.index
  126. this.$emit('categoryChange', { classId: this.tabs[this.level1].children[this.level2].id })
  127. },
  128. },
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .tabs {
  133. margin: 0 5px;
  134. &-second {
  135. margin: 0 11px;
  136. padding-left: 9px;
  137. background: #E5E4EB;
  138. border-radius: 16rpx;
  139. }
  140. }
  141. .content {
  142. padding: 24rpx 32rpx;
  143. display: grid;
  144. grid-template-columns: repeat(2, 1fr);
  145. gap: 32rpx;
  146. }
  147. </style>