goods_cate.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class='productSort'>
  3. <view class='header acea-row row-center-wrapper'>
  4. <view class='acea-row row-between-wrapper input'>
  5. <text class='iconfont icon-sousuo'></text>
  6. <input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search' name="search"
  7. placeholder-class='placeholder'></input>
  8. </view>
  9. </view>
  10. <view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
  11. <scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
  12. <view class='item acea-row row-center-wrapper'
  13. :class='index==navActive?"on":""'
  14. v-for="(item,index) in productList"
  15. :key="index"
  16. @click='tap(index,"b"+index)'>
  17. <text>{{item.name}}</text>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. <view class='conter'>
  22. <scroll-view scroll-y="true"
  23. :scroll-into-view="toView"
  24. :style='"height:"+height+"rpx;margin-top: 96rpx;"'
  25. @scroll="scroll"
  26. scroll-with-animation='true'>
  27. <view v-for="(item,index) in productList" :key="index">
  28. <view class='listw' :id="'b'+index">
  29. <view class='title acea-row row-center-wrapper'>
  30. <view class='line'></view>
  31. <view class='name'>{{item.name}}</view>
  32. <view class='line'></view>
  33. </view>
  34. <view class='list acea-row'>
  35. <view v-for="(itemn,indexn) in item.child" :key="indexn">
  36. <navigator hover-class='none'
  37. :url='"/pages/goods/goods_search/index?cid="+itemn.id+"&title="+itemn.name'
  38. class='item acea-row row-column row-middle'>
  39. <view class='name line1'>{{itemn.name}}</view>
  40. </navigator>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view :style='"height:"+(height-300)+"rpx;"' v-if="number<15"></view>
  46. </scroll-view>
  47. </view>
  48. </view>
  49. </template>
  50. <script setup>
  51. import { ref, onMounted, nextTick } from 'vue';
  52. import { onLoad, onShow } from '@dcloudio/uni-app';
  53. import { productCategory } from '@/api/merchant.js';
  54. // 响应式数据
  55. const productList = ref([]);
  56. const navActive = ref(0);
  57. const number = ref("");
  58. const height = ref(0);
  59. const hightArr = ref([]);
  60. const toView = ref("");
  61. const tabbarH = ref(0);
  62. // 获取分类列表
  63. const getAllCategory = async () => {
  64. try {
  65. let obj = {
  66. type: 1,
  67. status: -1
  68. }
  69. const { data }= await productCategory(obj);
  70. const newArr = []
  71. data.forEach((value, index) => {
  72. newArr[index] = value
  73. if (value.child) newArr[index].child = value.child.filter(item => item.status === true)
  74. })
  75. productList.value = newArr.filter(item => item.code !== 'bb_mall')
  76. // 使用 nextTick 确保 DOM 已更新
  77. nextTick(() => {
  78. setTimeout(() => {
  79. infoScroll();
  80. }, 500);
  81. });
  82. } catch (error) {
  83. console.error('获取分类列表失败:', error);
  84. uni.showToast({ title: '加载分类失败' });
  85. }
  86. };
  87. // 计算滚动相关数据
  88. const infoScroll = () => {
  89. let len = productList.value.length;
  90. let child = productList.value[len - 1] && productList.value[len - 1].child
  91. ? productList.value[len - 1].child
  92. : [];
  93. number.value = child ? child.length : 0;
  94. // 设置商品列表高度
  95. uni.getSystemInfo({
  96. success: (res) => {
  97. height.value = (res.windowHeight) * (750 / res.windowWidth) - 98;
  98. },
  99. });
  100. let heightTemp = 0;
  101. let hightArrTemp = [];
  102. for (let i = 0; i < len; i++) {
  103. // 获取元素所在位置
  104. let query = uni.createSelectorQuery();
  105. let idView = "#b" + i;
  106. query.select(idView).boundingClientRect();
  107. query.exec((res) => {
  108. if (res && res[0]) {
  109. let top = res[0].top;
  110. hightArrTemp.push(top);
  111. hightArr.value = hightArrTemp;
  112. }
  113. });
  114. }
  115. };
  116. // 点击左侧导航
  117. const tap = (index, id) => {
  118. toView.value = id;
  119. navActive.value = index;
  120. };
  121. // 右侧滚动事件
  122. const scroll = (e) => {
  123. let scrollTop = e.detail.scrollTop;
  124. let scrollArr = hightArr.value;
  125. if (!scrollArr || scrollArr.length === 0) return;
  126. for (let i = 0; i < scrollArr.length; i++) {
  127. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  128. navActive.value = 0;
  129. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
  130. navActive.value = i;
  131. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  132. navActive.value = scrollArr.length - 1;
  133. }
  134. }
  135. };
  136. // 搜索提交
  137. const searchSubmitValue = (e) => {
  138. const searchValue = e.detail.value?.trim();
  139. if (!searchValue) {
  140. return uni.showToast({ title: '请填写要搜索的产品信息' });
  141. }
  142. if (searchValue.length > 0) {
  143. uni.navigateTo({
  144. url: '/pages/goods/goods_search/index?keyword=' + searchValue
  145. });
  146. }
  147. };
  148. // 页面加载
  149. onLoad(() => {
  150. getAllCategory();
  151. });
  152. // 页面显示
  153. onShow(() => {
  154. // 可以在这里添加页面显示时的逻辑
  155. });
  156. </script>
  157. <style scoped lang="scss">
  158. .productSort .header {
  159. width: 100%;
  160. height: 96rpx;
  161. background-color: #fff;
  162. position: fixed;
  163. left: 0;
  164. right: 0;
  165. top: 0;
  166. z-index: 9;
  167. border-bottom: 1rpx solid #f5f5f5;
  168. }
  169. .productSort .header .input {
  170. width: 700rpx;
  171. height: 88rpx;
  172. background-color: #f5f5f5;
  173. border-radius: 16rpx;
  174. box-sizing: border-box;
  175. padding: 0 25rpx;
  176. }
  177. .productSort .header .input .iconfont {
  178. font-size: 26rpx;
  179. color: #555;
  180. }
  181. .productSort .header .input .placeholder {
  182. color: #999;
  183. }
  184. .productSort .header .input input {
  185. font-size: 26rpx;
  186. height: 100%;
  187. width: 597rpx;
  188. }
  189. .productSort .aside {
  190. position: absolute;
  191. width: 180rpx;
  192. left: 0;
  193. top:0;
  194. background-color: #f7f7f7;
  195. overflow-y: scroll;
  196. overflow-x: hidden;
  197. height: auto;
  198. margin-top: 96rpx;
  199. }
  200. .productSort .aside .item {
  201. height: 100rpx;
  202. width: 100%;
  203. font-size: 26rpx;
  204. color: #424242;
  205. }
  206. .productSort .aside .item.on {
  207. background-color: #fff;
  208. border-left: 4rpx solid #F8C008;
  209. width: 100%;
  210. text-align: center;
  211. color: #F8C008;
  212. font-weight: bold;
  213. }
  214. .productSort .conter {
  215. margin: 96rpx 0 0 180rpx;
  216. padding: 0 14rpx;
  217. background-color: #fff;
  218. }
  219. .productSort .conter .listw {
  220. padding-top: 20rpx;
  221. }
  222. .productSort .conter .listw .title {
  223. height: 90rpx;
  224. }
  225. .productSort .conter .listw .title .line {
  226. width: 100rpx;
  227. height: 2rpx;
  228. background-color: #f0f0f0;
  229. }
  230. .productSort .conter .listw .title .name {
  231. font-size: 28rpx;
  232. color: #333;
  233. margin: 0 30rpx;
  234. font-weight: bold;
  235. }
  236. .productSort .conter .list {
  237. flex-wrap: wrap;
  238. }
  239. .productSort .conter .list .item {
  240. width: 177rpx;
  241. margin-top: 26rpx;
  242. }
  243. .productSort .conter .list .item .picture {
  244. width: 120rpx;
  245. height: 120rpx;
  246. border-radius: 50%;
  247. }
  248. .productSort .conter .list .item .picture image {
  249. width: 100%;
  250. height: 100%;
  251. border-radius: 50%;
  252. div{
  253. background-color: #f7f7f7;
  254. }
  255. }
  256. .productSort .conter .list .item .name {
  257. font-size: 24rpx;
  258. color: #333;
  259. height: 56rpx;
  260. line-height: 56rpx;
  261. width: 120rpx;
  262. text-align: center;
  263. }
  264. </style>