Files
kangyuan-mobile/components/pages_commodity/pages_commodity.vue
T
2026-05-26 15:52:30 +08:00

625 lines
13 KiB
Vue

<template>
<view class="page_right flex-column" :class="{ search: props.source == 'search' }">
<view class="screen flex-center ju-evenly">
<view v-for="(v, i) in dataObj.screenNav" :key="i" class="screenItem flex-center"
:class="{ activeItem: v.status }" @click="screenChange(i)">
<view class="">{{ v.name }}</view>
<view class="c_icon flex-column" v-if="i != 2">
<image class="icon_up" :src="`/static/icon/screenUp${v.status == 1 ? 1 : 0}.svg`"
mode="scaleToFill" />
<image class="icon_down" :src="`/static/icon/screenDown${v.status == 2 ? 1 : 0}.svg`"
mode="scaleToFill" />
</view>
<view class="c_icon flex-column" v-else>
<image v-if="v.status == 1" class="icon_up" :src="`/static/icon/screenUp1.svg`"
mode="scaleToFill" />
<image v-if="v.status == 2 || !v.status" class="icon_down" :src="`/static/icon/screenDown0.svg`" />
</view>
</view>
</view>
<view class="goods w100 flex1">
<mescroll-uni @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback"
:height="props.height">
<view v-for="(v, i) in props.dataList" :key="i" class="goodsItem">
<card_goods :data="v" :type="props.type"></card_goods>
</view>
</mescroll-uni>
</view>
<!-- 筛选条件 -->
<su-popup :show="show" round="10" @close="close">
<view class="screen_popup flex-column ju-between">
<view class="screen_title center">
<view class="size32 f500 c34">全部筛选</view>
<uni-icons class="colse" type="closeempty" color="#333333" size="20" @click="close" />
</view>
<view class="screen_content flex-row flex1">
<view class="screen_left">
<view v-for="(v, i) in screenNav" :key="i" @click="screenNavChange(i, v.id)"
class="screen_nav_item center" :class="{ activeItem: screenIndex == i }">
{{ v.name }}
</view>
</view>
<view class="screen_right flex1" ref="rightRef">
<scroll-view scroll-y="true" style="height: 50vh;" :scroll-into-view="scrollIntoView"
:scroll-with-animation="true">
<view :id="'item' + i" v-for="(v, i) in screenNav" :key="i" class="screen_right_item"
:ref="(ref) => (itemRefs[i] = ref)">
<view>
<view class="screen_title">{{ v.title }}</view>
<view class="screen_data flex-row wrap">
<view v-for="(item, index) in v.data" :key="index"
class="screen_iteem flex-center" @click="screenItemClick(i, index, item)"
:class="{
screen_activeItem: v.ids.includes(item.id),
screen_none: index >= v.colMax - 1 && !v.more,
screen_iteem1: v.col == 2,
screen_iteem2: v.col == 3,
}">
<view class="size28 flex-center lineTwo center">{{ item.name }}</view>
</view>
<view class="screen_moreIteem center flex-center"
v-if="v.data.length >= v.colMax - 1 && !v.more && v.name != '价格区间'"
@click="v.more = true">
<view class="moreText size28">更多</view>
<view class="down"></view>
</view>
<view class="flex-center priceBox ju-between" v-if="v.name == '价格区间'">
<input class="flex1" type="number" placeholder="自定最低价"
placeholder-style="text-align: center;color: #5a6981;font-size: 28rpx;"
v-model="v.arr.minValue" />
<text class="">-</text>
<input class="flex1" type="number" placeholder="自定最高价"
placeholder-style="text-align: center;color: #5a6981;font-size: 28rpx;"
v-model="v.arr.maxValue" />
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
<view class="screen_btns flex-center ju-between">
<view class="screen_clear screen_btn size32 center" @click="screenClear">清空选择</view>
<view class="screen_confirm screen_btn center size32" @click="screenConfirm">确认</view>
</view>
</view>
</su-popup>
</view>
</template>
<script setup>
import SpuApi from '@/sheep/api/product/spu';
import * as api from '@/sheep/api/index/index.js';
import {
getCurrentInstance,
defineProps,
reactive,
ref,
watch,
nextTick
} from 'vue';
import {
onPageScroll,
onReachBottom
} from '@dcloudio/uni-app';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
import card_goods from '@/components/goodsItem/card_goods.vue';
import {
onLoad
} from '@dcloudio/uni-app';
const {
mescrollInit,
downCallback,
getMescroll
} = useMescroll(onPageScroll, onReachBottom); // 调用mescroll的hook
const {
proxy
} = getCurrentInstance();
const props = defineProps({
dataList: {
type: Array,
default: () => [],
},
subclassification: {
type: Array,
default: () => [],
},
height: {
type: String,
default: '50%',
},
source: {
type: String,
default: '',
},
type: {
type: Number,
default: 2,
},
});
const dataObj = reactive({
screenNav: [{
name: '销量',
status: 0,
},
{
name: '价格',
status: 0,
},
{
name: '筛选',
status: 0,
},
],
});
const upOption = {
noMoreSize: 4,
empty: {
tip: '~ 无数据 ~', // 提示
},
};
const changeData = () => {
const mescroll = getMescroll();
if (mescroll) {
mescroll.resetUpScroll();
}
};
let dataParams = ref({});
let screenObj = ref({});
const upCallback = async (mescroll) => {
let params = {
...dataParams.value,
...screenObj.value,
};
proxy.$emit('getData', {
...mescroll,
params,
});
};
const screenChange = (i) => {
let obj = {
sortAsc: true,
sortField: 'salesCount', //salesCount销量 price价格
};
if (i == 0) {
dataObj.screenNav[1].status = 0;
}
if (i == 1) {
dataObj.screenNav[0].status = 0;
}
switch (dataObj.screenNav[i].status) {
case 0:
dataObj.screenNav[i].status = 1;
obj.sortAsc = true;
break;
case 1:
if (i != 2) {
dataObj.screenNav[i].status = 2;
} else {
dataObj.screenNav[i].status = 0;
}
obj.sortAsc = false;
break;
case 2:
dataObj.screenNav[i].status = 1;
break;
}
if (i != 2) {
if (i == 1) {
obj.sortField = 'price';
}
dataParams.value = obj;
changeData();
} else {
show.value = true;
}
};
// 请求结果
const requestResult = (result = true, num = 0) => {
const mescroll = getMescroll();
if (result) {
mescroll.endSuccess(num);
} else {
mescroll.endErr();
}
};
let show = ref(false);
const close = () => {
show.value = false;
dataObj.screenNav[2].status = 0;
};
let screenNav = ref([{
id: 1,
name: '价格区间',
title: '价格区间(元)',
data: [],
ids: [],
arr: {},
multi: false, //是否多选
col: 2,
colMax: 5,
more: false,
},
{
id: 2,
name: '分类',
title: '分类',
data: [],
ids: [],
multi: false,
col: 3,
colMax: 6,
more: false,
},
{
id: 3,
name: '品牌',
title: '品牌',
data: [],
ids: [],
multi: true,
col: 3,
colMax: 6,
more: false,
},
{
id: 4,
name: '优惠',
title: '优惠',
data: [],
ids: [],
multi: true,
col: 3,
colMax: 6,
more: false,
},
]);
let rightRef = ref(null);
let staticHeight = ref(0);
let screenIndex = ref(0);
let itemRefs = ref(screenNav.value.map(() => ref(null)));
let scrollIntoView = ref("")
const screenNavChange = (i, id) => {
screenIndex.value = i;
scrollIntoView.value = 'item' + i;
};
const screenItemClick = (i, index, item) => {
let ids = screenNav.value[i].ids;
let multi = screenNav.value[i].multi;
if (ids.indexOf(item.id) == -1) {
console.log(multi);
if (!multi) {
ids = [];
}
ids.push(item.id);
} else {
ids.splice(ids.indexOf(item.id), 1);
}
screenNav.value[i].ids = ids;
};
const screenClear = () => {
screenNav.value.forEach((e) => {
e.ids = [];
e.arr = {};
});
dataParams.value = {};
changeData();
};
const priceData = (arr, id) => {
return arr.find((item) => item.id === id) || {};
};
const screenConfirm = () => {
let obj = screenNav.value[0];
dataParams.value = {
categoryIds: screenNav.value[1].ids.join(','),
brandIds: screenNav.value[2].ids.join(','),
tagTypeId: screenNav.value[3].ids.join(','),
categoryId: '',
minValue: obj.arr.minValue || obj.arr.minValue == 0 || priceData(obj.data, obj.ids[0]).minValue,
maxValue: obj.arr.maxValue || obj.arr.maxValue == 0 || priceData(obj.data, obj.ids[0]).maxValue,
minPrice: obj.arr.minValue || obj.arr.minValue == 0 || priceData(obj.data, obj.ids[0]).minValue,
maxPrice: obj.arr.maxValue || obj.arr.maxValue == 0 || priceData(obj.data, obj.ids[0]).maxValue,
};
changeData();
close();
};
watch(
() => props.subclassification,
(val) => {
screenNav.value.forEach((e) => {
if (e.name == '分类') {
e.data = props.subclassification;
}
});
}, {
immediate: true,
deep: true,
},
);
let getbrandlist = () => {
api.getbrandlist().then((res) => {
if (res.code != 0) return;
screenNav.value.forEach((e) => {
if (e.name == '品牌') {
e.data = res.data;
}
});
});
};
const getproducttaglist = () => {
api.getproducttaglist({
categoryId: 2
}).then((res) => {
if (res.code != 0) return;
screenNav.value.forEach((e) => {
if (e.name == '优惠') {
e.data = res.data;
}
});
});
};
const getpricerangelist = () => {
api.getpricerangelist().then((res) => {
if (res.code != 0) return;
screenNav.value.forEach((e) => {
if (e.name == '价格区间') {
e.data = res.data;
}
});
});
};
onLoad(() => {
getbrandlist();
getproducttaglist();
// 获取价格
getpricerangelist();
});
const clearAll = () => {
screenNav.value.forEach((e) => {
e.ids = [];
e.arr = {};
e.more = false;
});
dataParams.value = {};
screenObj.value = {};
dataObj.screenNav.forEach((e) => {
e.status = 0;
});
changeData();
};
defineExpose({
changeData,
requestResult,
clearAll,
});
</script>
<style scoped lang="scss">
.page_right {
height: 100%;
background-color: #fff;
// overflow-y: auto;
.screen {
width: 100%;
height: 96rpx;
}
.goods {
// height: calc(100% - 96rpx);
height: calc(100%);
overflow-y: auto;
}
.screenItem {
color: #323233;
font-size: 28rpx;
}
.activeItem {
color: #fa9c31;
}
.icon_up,
.icon_down {
width: 16rpx;
height: 8rpx;
margin-left: 10rpx;
}
.icon_up {
margin-bottom: 4rpx;
}
.icon_down {}
}
.goodsItem {
padding: 0 20rpx;
box-sizing: border-box;
}
.goodsImg {
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
.screen_popup {
padding-top: 46rpx;
/* #ifdef H5 */
padding-bottom: 100rpx;
/* #endif */
box-sizing: border-box;
position: relative;
z-index: 1000;
.screen_title {
box-sizing: border-box;
// margin-bottom: 58rpx;
}
.colse {
position: absolute;
top: 42rpx;
right: 22rpx;
}
.screen_content {
.screen_left {
min-height: 100%;
overflow-y: auto;
background-color: #F3F6F8;
;
.screen_nav_item {
width: 162rpx;
line-height: 86rpx;
}
.activeItem {
color: #FA7E31;
background-color: #F3F6F8;
;
}
}
.screen_right {
padding: 0 18rpx;
box-sizing: border-box;
overflow-y: auto;
.screen_right_item {
margin-bottom: 34rpx;
.screen_title {
margin-bottom: 8rpx;
line-height: 70rpx;
}
.screen_iteem {
line-height: 40rpx;
height: 114rpx;
background-color: #F2F5F7;
margin-bottom: 10rpx;
border-radius: 12rpx;
padding: 16rpx 10rpx;
box-sizing: border-box;
}
.screen_iteem1 {
width: calc((100% - 6rpx) / 2);
margin-right: 6rpx;
&:nth-child(2n) {
margin-right: 0;
}
}
.screen_iteem2 {
&:nth-child(3n) {
// margin-right: 0;
}
width: calc((100% - 12rpx) / 2);
margin-right: 6rpx;
}
.screen_moreIteem {
color: #121212;
width: calc((100% - 12rpx) / 2);
margin-bottom: 10rpx;
line-height: 84rpx;
}
.moreText {
// color: #ffffff;
}
.down {
width: 0rpx;
height: 0;
border-left: 9rpx solid transparent;
border-right: 9rpx solid transparent;
border-top: 12rpx solid #666666;
margin-left: 6rpx;
}
.screen_activeItem {
background-color: #FFEFE5;
color: #FA7E31;
}
.screen_none {
display: none;
}
}
}
}
.screen_btns {
padding: 44rpx 18rpx;
box-sizing: border-box;
.screen_btn {
width: calc(100% - 54rpx);
height: 82rpx;
border-radius: 12rpx;
background-color: #FFEFE5;
color: #FA7E31;
line-height: 82rpx;
margin-right: 18rpx;
}
.screen_clear {}
.screen_confirm {
background: linear-gradient(270deg, #F7772E 0%, #EE0A24 99%);
color: #ffffff;
}
}
}
.priceBox {
height: 84rpx;
border-radius: 12rpx;
background-color: #F2F5F7;
padding: 0 40rpx;
box-sizing: border-box;
input {
width: 30%;
}
.pricePlace {
text-align: center;
color: #333333;
font-size: 24rpx;
}
}
.search {
.screen {
justify-content: space-between;
padding: 0 58rpx;
box-sizing: border-box;
}
.goodsItem {
padding: 0 32rpx;
}
}
</style>