index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view>
  3. <view class="tabs-container">
  4. <view class="tabs-row no-gap">
  5. <up-tabs :list="getFirstRowTabs()" @change="handlTabs" :activeStyle="{
  6. color: 'rgba(221, 94, 69, 1)',
  7. fontWeight: 'bold',
  8. transform: 'scale(1.05)',
  9. fontSize: '24rpx'
  10. }"
  11. :inactiveStyle="{
  12. fontSize: '24rpx'
  13. }"
  14. lineColor="rgba(221, 94, 69, 1)" :current="tabKey" keyName="businessName">
  15. </up-tabs>
  16. </view>
  17. <!-- Second row of tabs -->
  18. <view class="tabs-row no-gap">
  19. <up-tabs :list="getSecondRowTabs()" @change="handlSecondRowTabs" :activeStyle="{
  20. color: 'rgba(221, 94, 69, 1)',
  21. fontWeight: 'bold',
  22. transform: 'scale(1.05)',
  23. fontSize: '24rpx'
  24. }"
  25. :inactiveStyle="{
  26. fontSize: '24rpx'
  27. }"
  28. lineColor="rgba(221, 94, 69, 1)" :current="secondRowTabKey" keyName="businessName">
  29. </up-tabs>
  30. </view>
  31. </view>
  32. <view class="tabs-scroll">
  33. <up-tabs :list="childrenList" @change="childernChange" :activeStyle="{
  34. color: 'rgba(221, 94, 69, 1)',
  35. fontWeight: 'bold',
  36. transform: 'scale(1.05)',
  37. fontSize: '22rpx'
  38. }"
  39. :inactiveStyle="{
  40. fontSize: '22rpx'
  41. }"
  42. lineColor="rgba(221, 94, 69, 1)" :current="childrenKey" keyName="businessName">
  43. </up-tabs>
  44. </view>
  45. <view class="tabs-scroll-box">
  46. <up-tabs :list="children2List" @change="childern2Change" :activeStyle="{
  47. color: 'rgba(221, 94, 69, 1)',
  48. fontWeight: 'bold',
  49. transform: 'scale(1.05)',
  50. fontSize: '20rpx'
  51. }"
  52. :inactiveStyle="{
  53. fontSize: '20rpx'
  54. }"
  55. lineColor="rgba(221, 94, 69, 1)" :current="children2Key" keyName="businessName">
  56. </up-tabs>
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import {
  62. ref,
  63. onMounted,
  64. reactive,
  65. nextTick,
  66. computed
  67. } from 'vue';
  68. import {
  69. onLoad,
  70. onShow,
  71. onReachBottom
  72. } from "@dcloudio/uni-app"
  73. const emits = defineEmits(['change'])
  74. const tabKey = ref(0);//tab的下标
  75. const secondRowTabKey = ref(0);//第二行tab的下标
  76. const childrenKey = ref(null);//二级的id
  77. const children2Key = ref(null);//三级的id
  78. const list = ref([])
  79. const splitIndex = computed(() => Math.ceil(list.value.length / 2)); // 计算分割点
  80. // 获取第一行的tabs
  81. const getFirstRowTabs = () => {
  82. return list.value.slice(0, splitIndex.value);
  83. }
  84. // 获取第二行的tabs
  85. const getSecondRowTabs = () => {
  86. return list.value.slice(splitIndex.value);
  87. }
  88. const childrenList = ref([]);//二级的数据
  89. const children2List = ref([]);//三级的数据
  90. // 处理第一行标签点击
  91. const handlTabs = (e, index) => {
  92. childrenList.value = e.children ? [{
  93. businessName: '全部',
  94. id: e.id
  95. }, ...e.children] : []
  96. tabKey.value = index;//记录下标
  97. secondRowTabKey.value = -1; // 重置第二行选中状态
  98. childrenKey.value = 0;
  99. children2Key.value = 0;
  100. children2List.value = [];
  101. emits('change', e)
  102. }
  103. // 处理第二行标签点击
  104. const handlSecondRowTabs = (e, index) => {
  105. childrenList.value = e.children ? [{
  106. businessName: '全部',
  107. id: e.id
  108. }, ...e.children] : []
  109. secondRowTabKey.value = index;//记录下标
  110. tabKey.value = -1; // 重置第一行选中状态
  111. childrenKey.value = 0;
  112. children2Key.value = 0;
  113. children2List.value = [];
  114. emits('change', e)
  115. }
  116. const childernChange = (e, index) => {
  117. children2List.value = e.children ? [{
  118. businessName: '全部',
  119. id: e.id
  120. }, ...e.children] : [];
  121. children2Key.value = 0;
  122. childrenKey.value = index;
  123. emits('change', e)
  124. }
  125. const childern2Change = (e, index) => {
  126. children2Key.value = index;
  127. emits('change', e)
  128. }
  129. onMounted(() => {
  130. })
  131. onLoad((options) => {
  132. const dataList = JSON.parse(decodeURIComponent(options.dataList));
  133. list.value = dataList
  134. if (options.id) {
  135. const tab = dataList.find(item => item.id === options.id);
  136. const index = dataList.findIndex(item => item.id === options.id);
  137. // 判断点击的是第一行还是第二行
  138. if (index < splitIndex.value) {
  139. handlTabs(tab, index);
  140. } else {
  141. // 计算在第二行中的索引
  142. const secondRowIndex = index - splitIndex.value;
  143. handlSecondRowTabs(tab, secondRowIndex);
  144. }
  145. } else {
  146. handlTabs(dataList[0], 0);
  147. }
  148. })
  149. </script>
  150. <style scoped lang="scss">
  151. .tabs-container {
  152. display: flex;
  153. flex-direction: column;
  154. width: 100%;
  155. background-color: #F6F6F6;
  156. padding: 0rpx 35rpx;
  157. }
  158. .tabs-row {
  159. width: 100%;
  160. margin-bottom: 6rpx;
  161. }
  162. /* 添加无间隔样式 */
  163. .no-gap :deep(.u-tabs__wrapper__nav__item) {
  164. margin: 0 !important;
  165. padding-left: 0 !important;
  166. padding-right: 0 !important;
  167. /* 平均分配宽度 */
  168. flex: 1 !important;
  169. text-align: center;
  170. }
  171. .childern-item {
  172. font-size: 26rpx;
  173. font-weight: 400;
  174. background-color: #f9fafb;
  175. padding: 8rpx 24rpx;
  176. margin-right: 10rpx;
  177. border-radius: 19998rpx;
  178. }
  179. .item-active {
  180. background: rgba(251, 229, 225, 1);
  181. color: rgba(221, 94, 69, 1);
  182. }
  183. .tabs-scroll {
  184. display: flex;
  185. align-items: center;
  186. margin-top: 10rpx;
  187. padding: 0 12rpx;
  188. }
  189. .tabs-scroll-box {
  190. width: 100%;
  191. overflow: hidden;
  192. overflow-x: auto;
  193. margin-top: 6rpx;
  194. }
  195. .tabs-scroll2 {
  196. margin-top: 10rpx;
  197. padding: 0 12rpx;
  198. width: max-content;
  199. display: flex;
  200. align-items: center;
  201. }
  202. .childern2-item {
  203. font-size: 22rpx;
  204. font-weight: 400;
  205. background-color: #f9fafb;
  206. padding: 6rpx 20rpx;
  207. margin-right: 10rpx;
  208. border-radius: 4rpx;
  209. color: #656565;
  210. }
  211. .item2-active {
  212. background: rgba(251, 229, 225, 1);
  213. color: rgba(221, 94, 69, 1);
  214. }
  215. </style>