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

195 lines
4.6 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  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. @change="onLevel1TabChange"
  29. ></uv-tabs>
  30. <view v-if="tabs[level1] && tabs[level1].children && tabs[level1].children.length"
  31. class="tabs-second"
  32. >
  33. <uv-tabs
  34. :list="tabs[level1].children"
  35. :activeStyle="{
  36. 'font-family': 'PingFang SC',
  37. 'font-weight': 600,
  38. 'font-size': '28rpx',
  39. 'line-height': 1.5,
  40. 'color': '#7451DE',
  41. }"
  42. :inactiveStyle="{
  43. 'font-family': 'PingFang SC',
  44. 'font-weight': 400,
  45. 'font-size': '28rpx',
  46. 'line-height': 1.5,
  47. 'color': '#252545',
  48. }"
  49. lineWidth="0"
  50. lineHeight="0"
  51. @change="onLevel2TabChange"
  52. ></uv-tabs>
  53. </view>
  54. </view>
  55. <view v-if="list.length" class="content">
  56. <view v-for="item in list" :key="item.id" style="min-width: 0;">
  57. <productCard
  58. :data="item"
  59. cardStyle="width: 100%; height: 210px;"
  60. imgStyle="width: 100%; height: 110px;"
  61. ></productCard>
  62. </view>
  63. </view>
  64. <template v-else>
  65. <uv-empty mode="list"></uv-empty>
  66. </template>
  67. </view>
  68. </template>
  69. <script>
  70. import productCard from '@/pages_order/product/productCard.vue'
  71. export default {
  72. components: {
  73. productCard,
  74. },
  75. props: {
  76. type: {
  77. type: Number,
  78. default: 0,
  79. },
  80. list: {
  81. type: Array,
  82. default() {
  83. return []
  84. }
  85. },
  86. },
  87. data() {
  88. return {
  89. tabs: [],
  90. level1: 0,
  91. level2: null,
  92. }
  93. },
  94. mounted() {
  95. this.fetchCategory()
  96. return
  97. this.list = [
  98. {
  99. id: '001',
  100. url: '/pages_order/static/index/recommend-pic.png',
  101. name: '月度装定制营养包',
  102. sales: 24770,
  103. price: 688.00,
  104. originalPrice: 1664,
  105. },
  106. {
  107. id: '002',
  108. url: '/pages_order/static/index/recommend-pic.png',
  109. name: '月度装定制营养包',
  110. sales: 24770,
  111. price: 688.00,
  112. originalPrice: 1664,
  113. },
  114. {
  115. id: '003',
  116. url: '/pages_order/static/index/recommend-pic.png',
  117. name: '月度装定制营养包',
  118. sales: 24770,
  119. price: 688.00,
  120. originalPrice: 1664,
  121. },
  122. ]
  123. let children = [
  124. { name: '草本类' },
  125. { name: '蔬菜类' },
  126. { name: '维生素类' },
  127. { name: '草本类' },
  128. { name: '蔬菜类' },
  129. ]
  130. this.tabs = [
  131. { name: '全部' },
  132. { name: '皮肤', children, },
  133. { name: '身材管理', children, },
  134. { name: '精力', children, },
  135. ]
  136. },
  137. methods: {
  138. async fetchCategory() {
  139. try {
  140. let result = await this.$fetch('getProductCategory', { type: this.type }) // type: 产品类型(0营养剂,1预约,2课程)
  141. this.tabs = result.reduce((arr, item) => {
  142. const { id, name } = item
  143. // todo: check children?
  144. let obj = { id, name }
  145. arr.push(obj)
  146. return arr
  147. }, [{ name: '全部' }])
  148. } catch (err) {
  149. }
  150. },
  151. onLevel1TabChange(e) {
  152. console.log('level1', e.index)
  153. this.level1 = e.index
  154. this.level2 = this.tabs[this.level1].children?.length ? 0 : null
  155. this.$emit('categoryChange', { classId: this.tabs[this.level1].id })
  156. },
  157. onLevel2TabChange(e) {
  158. console.log('level2', e.index)
  159. this.level2 = e.index
  160. // todo
  161. },
  162. },
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .tabs {
  167. margin: 0 5px;
  168. &-second {
  169. margin: 0 11px;
  170. padding-left: 9px;
  171. background: #E5E4EB;
  172. border-radius: 16rpx;
  173. }
  174. }
  175. .content {
  176. padding: 24rpx 32rpx;
  177. display: grid;
  178. grid-template-columns: repeat(2, 1fr);
  179. gap: 32rpx;
  180. }
  181. </style>