|
@@ -2,23 +2,17 @@
|
|
|
<view class='productSort'>
|
|
<view class='productSort'>
|
|
|
<view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
|
|
<view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
|
|
|
<scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
|
|
<scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
|
|
|
- <view class='item acea-row row-center-wrapper'
|
|
|
|
|
- :class='index==navActive?"on":""'
|
|
|
|
|
- v-for="(item,index) in productList"
|
|
|
|
|
- :key="index"
|
|
|
|
|
- @click='tap(index,"b"+index)'>
|
|
|
|
|
|
|
+ <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
|
|
|
|
|
+ v-for="(item,index) in productList" :key="index" @click='tap(index,"b"+index)'>
|
|
|
<text>{{item.name}}</text>
|
|
<text>{{item.name}}</text>
|
|
|
</view>
|
|
</view>
|
|
|
</scroll-view>
|
|
</scroll-view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class='conter'>
|
|
<view class='conter'>
|
|
|
- <scroll-view scroll-y="true"
|
|
|
|
|
- :scroll-into-view="toView"
|
|
|
|
|
- :style='"height:"+height+"rpx;"'
|
|
|
|
|
- @scroll="scroll"
|
|
|
|
|
|
|
+ <scroll-view scroll-y="true" :scroll-into-view="toView" :style='"height:"+height+"rpx;"' @scroll="scroll"
|
|
|
scroll-with-animation='true'>
|
|
scroll-with-animation='true'>
|
|
|
<view v-for="(item,index) in productList" :key="index">
|
|
<view v-for="(item,index) in productList" :key="index">
|
|
|
- <view class='listw' :id="'b'+index">
|
|
|
|
|
|
|
+ <view class='listw'>
|
|
|
<view class='title acea-row row-center-wrapper'>
|
|
<view class='title acea-row row-center-wrapper'>
|
|
|
<view class='line'></view>
|
|
<view class='line'></view>
|
|
|
<view class='name'>{{item.name}}</view>
|
|
<view class='name'>{{item.name}}</view>
|
|
@@ -27,7 +21,7 @@
|
|
|
<view class='list acea-row'>
|
|
<view class='list acea-row'>
|
|
|
<view v-for="(itemn,indexn) in item.child" :key="indexn">
|
|
<view v-for="(itemn,indexn) in item.child" :key="indexn">
|
|
|
<navigator hover-class='none'
|
|
<navigator hover-class='none'
|
|
|
- :url='"/pages/goods/goods_search/index?cid="+itemn.id+"&title="+itemn.name+"&merchantId="+props.merchantId'
|
|
|
|
|
|
|
+ :url='"/pages/goods_search/index?cid="+itemn.id+"&title="+itemn.name+"&merchantId="+props.merchantId'
|
|
|
class='item acea-row row-column row-middle'>
|
|
class='item acea-row row-column row-middle'>
|
|
|
<view class='name line1'>{{itemn.name}}</view>
|
|
<view class='name line1'>{{itemn.name}}</view>
|
|
|
</navigator>
|
|
</navigator>
|
|
@@ -41,10 +35,21 @@
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onMounted, nextTick,watch} from 'vue';
|
|
|
|
|
-import { onLoad, onShow } from '@dcloudio/uni-app';
|
|
|
|
|
-import { productCategory } from '@/api/merchant.js';
|
|
|
|
|
-
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ ref,
|
|
|
|
|
+ onMounted,
|
|
|
|
|
+ nextTick,
|
|
|
|
|
+ watch,
|
|
|
|
|
+ getCurrentInstance
|
|
|
|
|
+} from 'vue';
|
|
|
|
|
+import {
|
|
|
|
|
+ onLoad,
|
|
|
|
|
+ onShow
|
|
|
|
|
+} from '@dcloudio/uni-app';
|
|
|
|
|
+import {
|
|
|
|
|
+ productCategory
|
|
|
|
|
+} from '@/api/merchant.js';
|
|
|
|
|
+const instance = getCurrentInstance();
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
merchantId: {
|
|
merchantId: {
|
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
@@ -70,7 +75,9 @@ const getAllCategory = async () => {
|
|
|
type: 1,
|
|
type: 1,
|
|
|
status: 1
|
|
status: 1
|
|
|
}
|
|
}
|
|
|
- const { data }= await productCategory(obj);
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ data
|
|
|
|
|
+ } = await productCategory(obj);
|
|
|
const newArr = []
|
|
const newArr = []
|
|
|
data.forEach((value, index) => {
|
|
data.forEach((value, index) => {
|
|
|
newArr[index] = value
|
|
newArr[index] = value
|
|
@@ -80,51 +87,36 @@ const getAllCategory = async () => {
|
|
|
productList.value = listArr.sort((a, b) => a.sort - b.sort);
|
|
productList.value = listArr.sort((a, b) => a.sort - b.sort);
|
|
|
|
|
|
|
|
// 使用 nextTick 确保 DOM 已更新
|
|
// 使用 nextTick 确保 DOM 已更新
|
|
|
- nextTick(() => {
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- infoScroll();
|
|
|
|
|
- }, 500);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // nextTick(() => {
|
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
|
+ // infoScroll();
|
|
|
|
|
+ // }, 500);
|
|
|
|
|
+ // });
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('获取分类列表失败:', error);
|
|
console.error('获取分类列表失败:', error);
|
|
|
- uni.showToast({ title: '加载分类失败' });
|
|
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '加载分类失败'
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
// 计算滚动相关数据
|
|
// 计算滚动相关数据
|
|
|
const infoScroll = () => {
|
|
const infoScroll = () => {
|
|
|
- console.log('infoScroll++++++++')
|
|
|
|
|
- let len = productList.value.length;
|
|
|
|
|
- let child = productList.value[len - 1] && productList.value[len - 1].child
|
|
|
|
|
- ? productList.value[len - 1].child
|
|
|
|
|
- : [];
|
|
|
|
|
- number.value = child ? child.length : 0;
|
|
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ const len = productList.value.length;
|
|
|
|
|
|
|
|
- // 设置商品列表高度
|
|
|
|
|
- uni.getSystemInfo({
|
|
|
|
|
- success: (res) => {
|
|
|
|
|
- height.value = (res.windowHeight) * (750 / res.windowWidth) - 98;
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- let heightTemp = 0;
|
|
|
|
|
- let hightArrTemp = [];
|
|
|
|
|
|
|
+ // 创建查询对象,并指定在当前组件实例中查询
|
|
|
|
|
+ const query = uni.createSelectorQuery().in(instance);
|
|
|
|
|
|
|
|
- for (let i = 0; i < len; i++) {
|
|
|
|
|
- // 获取元素所在位置
|
|
|
|
|
- let query = uni.createSelectorQuery();
|
|
|
|
|
- let idView = "#b" + i;
|
|
|
|
|
- query.select(idView).boundingClientRect();
|
|
|
|
|
- query.exec((res) => {
|
|
|
|
|
- if (res && res[0]) {
|
|
|
|
|
- let top = res[0].top;
|
|
|
|
|
- hightArrTemp.push(top);
|
|
|
|
|
- hightArr.value = hightArrTemp;
|
|
|
|
|
- console.log('hightArr.value======')
|
|
|
|
|
- console.log(hightArr.value)
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 先查询所有元素
|
|
|
|
|
+ query.selectAll('.listw').boundingClientRect((rects) => {
|
|
|
|
|
+ if (rects) {
|
|
|
|
|
+ hightArr.value = rects.map(rect => rect.top);
|
|
|
|
|
+ console.log('hightArr:', hightArr.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).exec();
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 点击左侧导航
|
|
// 点击左侧导航
|
|
@@ -138,32 +130,17 @@ const scroll = (e) => {
|
|
|
let scrollTop = e.detail.scrollTop;
|
|
let scrollTop = e.detail.scrollTop;
|
|
|
let scrollArr = hightArr.value;
|
|
let scrollArr = hightArr.value;
|
|
|
|
|
|
|
|
- console.log('scrollTop:', scrollTop, 'scrollArr:', scrollArr);
|
|
|
|
|
-
|
|
|
|
|
- if (!scrollArr || scrollArr.length === 0 || scrollArr.length < 2) return;
|
|
|
|
|
-
|
|
|
|
|
- // 修正逻辑:减去第一个元素的高度作为偏移量
|
|
|
|
|
- const baseOffset = scrollArr[0] || 0;
|
|
|
|
|
- const adjustedScrollTop = scrollTop + baseOffset;
|
|
|
|
|
|
|
+ if (!scrollArr || scrollArr.length === 0) return;
|
|
|
|
|
|
|
|
- // 找到当前应该激活的索引
|
|
|
|
|
- let currentIndex = 0;
|
|
|
|
|
for (let i = 0; i < scrollArr.length; i++) {
|
|
for (let i = 0; i < scrollArr.length; i++) {
|
|
|
- if (i === 0 && adjustedScrollTop < scrollArr[0]) {
|
|
|
|
|
- currentIndex = 0;
|
|
|
|
|
- break;
|
|
|
|
|
- } else if (i === scrollArr.length - 1 && adjustedScrollTop >= scrollArr[i]) {
|
|
|
|
|
- currentIndex = i;
|
|
|
|
|
- break;
|
|
|
|
|
- } else if (adjustedScrollTop >= scrollArr[i] && adjustedScrollTop < scrollArr[i + 1]) {
|
|
|
|
|
- currentIndex = i;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
|
|
|
|
|
+ navActive.value = 0;
|
|
|
|
|
+ } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
|
|
|
|
|
+ navActive.value = i;
|
|
|
|
|
+ } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
|
|
|
|
|
+ navActive.value = scrollArr.length - 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (navActive.value !== currentIndex) {
|
|
|
|
|
- navActive.value = currentIndex;
|
|
|
|
|
- }
|
|
|
|
|
};
|
|
};
|
|
|
// 监听 merchantId 变化
|
|
// 监听 merchantId 变化
|
|
|
watch(() => props.merchantId, (newVal) => {
|
|
watch(() => props.merchantId, (newVal) => {
|
|
@@ -171,7 +148,9 @@ watch(() => props.merchantId, (newVal) => {
|
|
|
if (newVal) {
|
|
if (newVal) {
|
|
|
getAllCategory();
|
|
getAllCategory();
|
|
|
}
|
|
}
|
|
|
-}, { immediate: true }); // 立即执行一次
|
|
|
|
|
|
|
+}, {
|
|
|
|
|
+ immediate: true
|
|
|
|
|
+}); // 立即执行一次
|
|
|
|
|
|
|
|
// 页面加载
|
|
// 页面加载
|
|
|
onLoad(() => {
|
|
onLoad(() => {
|
|
@@ -181,7 +160,17 @@ onLoad(() => {
|
|
|
// 页面显示
|
|
// 页面显示
|
|
|
onShow(() => {
|
|
onShow(() => {
|
|
|
getAllCategory();
|
|
getAllCategory();
|
|
|
|
|
+ // // 设置商品列表高度
|
|
|
|
|
+ uni.getSystemInfo({
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ height.value = (res.windowHeight) * (750 / res.windowWidth) - (88 + 30 + 30);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+defineExpose({
|
|
|
|
|
+ infoScroll
|
|
|
|
|
+})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|
|
@@ -189,7 +178,7 @@ onShow(() => {
|
|
|
position: absolute;
|
|
position: absolute;
|
|
|
width: 180rpx;
|
|
width: 180rpx;
|
|
|
left: 0;
|
|
left: 0;
|
|
|
- top:0;
|
|
|
|
|
|
|
+ top: 0;
|
|
|
background-color: #fff;
|
|
background-color: #fff;
|
|
|
overflow-y: scroll;
|
|
overflow-y: scroll;
|
|
|
overflow-x: hidden;
|
|
overflow-x: hidden;
|
|
@@ -260,7 +249,8 @@ onShow(() => {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
height: 100%;
|
|
height: 100%;
|
|
|
border-radius: 50%;
|
|
border-radius: 50%;
|
|
|
- div{
|
|
|
|
|
|
|
+
|
|
|
|
|
+ div {
|
|
|
background-color: #f7f7f7;
|
|
background-color: #f7f7f7;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|