index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view>
  3. <view>
  4. <up-tabs :list="list" @change="handlTabs" :activeStyle="{
  5. color: 'rgba(221, 94, 69, 1)',
  6. fontWeight: 'bold',
  7. transform: 'scale(1.05)'
  8. }" lineColor="rgba(221, 94, 69, 1)" :current="tabKey" keyName="businessName">
  9. </up-tabs>
  10. </view>
  11. <view scroll-x class="tabs-scroll">
  12. <!-- <view v-for="item in childrenList" :key="item.id"
  13. :class="item.id === childrenKey ? 'childern-item item-active' : 'childern-item'"
  14. @click="childernChange(item)">
  15. {{ item.businessName }}
  16. </view> -->
  17. <up-tabs :list="childrenList" @change="childernChange" :activeStyle="{
  18. color: 'rgba(221, 94, 69, 1)',
  19. fontWeight: 'bold',
  20. transform: 'scale(1.05)'
  21. }" lineColor="rgba(221, 94, 69, 1)" :current="childrenKey" keyName="businessName">
  22. </up-tabs>
  23. </view>
  24. <view class="tabs-scroll-box">
  25. <!-- <view class="tabs-scroll2">
  26. <view v-for="item in children2List" :key="item.id"
  27. :class="item.id === children2Key ? 'childern2-item item2-active' : 'childern2-item'"
  28. @click="childern2Change(item)">
  29. {{ item.businessName }}
  30. </view>
  31. </view> -->
  32. <up-tabs :list="children2List" @change="childern2Change" :activeStyle="{
  33. color: 'rgba(221, 94, 69, 1)',
  34. fontWeight: 'bold',
  35. transform: 'scale(1.05)'
  36. }" lineColor="rgba(221, 94, 69, 1)" :current="children2Key" keyName="businessName">
  37. </up-tabs>
  38. </view>
  39. </view>
  40. </template>
  41. <script setup>
  42. import {
  43. ref,
  44. onMounted,
  45. reactive,
  46. nextTick
  47. } from 'vue';
  48. import {
  49. onLoad,
  50. onShow,
  51. onReachBottom
  52. } from "@dcloudio/uni-app"
  53. const emits = defineEmits(['change'])
  54. const tabKey = ref(0);//tab的下标
  55. const childrenKey = ref(null);//二级的id
  56. const children2Key = ref(null);//三级的id
  57. const list = ref([])
  58. const childrenList = ref([]);//二级的数据
  59. const children2List = ref([]);//三级的数据
  60. const handlTabs = (e, index) => {
  61. console.log('e,index', e, index);
  62. childrenList.value = e.children ? [{
  63. businessName: '全部',
  64. id: e.id
  65. }, ...e.children] : []
  66. tabKey.value = index;//记录下标
  67. childrenKey.value = 0;
  68. children2Key.value = 0;
  69. children2List.value = [];
  70. emits('change', e)
  71. }
  72. const childernChange = (e, index) => {
  73. children2List.value = e.children ? [{
  74. businessName: '全部',
  75. id: e.id
  76. }, ...e.children] : [];
  77. children2Key.value = 0;
  78. childrenKey.value = index;
  79. emits('change', e)
  80. }
  81. const childern2Change = (e, index) => {
  82. children2Key.value = index;
  83. emits('change', e)
  84. }
  85. onMounted(() => {
  86. })
  87. onLoad((options) => {
  88. const dataList = JSON.parse(decodeURIComponent(options.dataList));
  89. list.value = dataList
  90. if (options.id) {
  91. const tab = dataList.find(item => item.id === options.id);
  92. const index = dataList.findIndex(item => item.id === options.id);
  93. handlTabs(tab, index);
  94. } else {
  95. handlTabs(dataList[0])
  96. }
  97. })
  98. </script>
  99. <style scoped lang="scss">
  100. .childern-item {
  101. font-size: 28rpx;
  102. font-weight: 400;
  103. background-color: #f9fafb;
  104. padding: 12rpx 32rpx;
  105. margin-right: 16rpx;
  106. border-radius: 19998rpx;
  107. }
  108. .item-active {
  109. background: rgba(251, 229, 225, 1);
  110. color: rgba(221, 94, 69, 1);
  111. }
  112. .tabs-scroll {
  113. display: flex;
  114. align-items: center;
  115. margin-top: 16rpx;
  116. padding: 0 16rpx;
  117. }
  118. .tabs-scroll-box {
  119. width: 100%;
  120. overflow: hidden;
  121. overflow-x: auto;
  122. }
  123. .tabs-scroll2 {
  124. margin-top: 16rpx;
  125. padding: 0 16rpx;
  126. width: max-content;
  127. display: flex;
  128. align-items: center;
  129. }
  130. .childern2-item {
  131. font-size: 24rpx;
  132. font-weight: 400;
  133. background-color: #f9fafb;
  134. padding: 8rpx 28rpx;
  135. margin-right: 16rpx;
  136. border-radius: 4rpx;
  137. color: #656565;
  138. }
  139. .item2-active {
  140. background: rgba(251, 229, 225, 1);
  141. color: rgba(221, 94, 69, 1);
  142. }
  143. </style>