初始项目

This commit is contained in:
liupopo
2023-02-11 12:55:02 +08:00
parent 1748bda84a
commit 0b89e36064
3363 changed files with 506201 additions and 1 deletions

View File

@@ -0,0 +1,352 @@
<template>
<view class="content" style="display: flex;flex-direction: column;">
<!-- #ifdef MP-WEIXIN -->
<nav-bar>分类</nav-bar>
<view class="search" @click="search()">
<input class="search_input" type="text" disabled="true" placeholder="输入关键字搜索" />
</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="category-wrapper" :style="{'height':scroll_height+'px'}">
<!-- #endif -->
<!-- #ifdef APP-PLUS || APP-PLUS-NVUE || H5 -->
<view class="category-wrapper">
<!-- #endif -->
<!-- 左边导航 -->
<scroll-view scroll-y="true" class="left-wrapper" scroll-with-animation="true" :scroll-top="left_scroll">
<view class="left-content column">
<view class="title-content" :class="select_index === index ? 'onSelected' : ''" v-for="(title, index) in catrgoryList" :key="title.id" @tap="choose(index)">
{{ title.name || '分类' + (index + 1) }}
</view>
</view>
</scroll-view>
<!-- 右边内容 -->
<scroll-view scroll-y="true" class="right-wrapper" scroll-with-animation="true" :scroll-top="right_scroll" @scroll="myscroll">
<view class="right-content">
<!-- 产品区 -->
<view class="product-wrapper column with-100">
<view class="category-item column" :id="'list' + c_index" v-for="(c_item, c_index) in catrgoryList" :key="c_item.id">
<!-- 广告图 -->
<view class="banner-item"><image class="banner" :src="c_item.pic == '' || c_item.pic == null ? '' : c_item.pic"></image></view>
<view class="category-content">
<view class="product-item" v-for="(p_item, p_index) in c_item.goodsList" :key="p_item.id" @click="toCategory(p_item)">
<image class="product-img" :src="p_item.pic == '' || p_item.pic == null ? '' : p_item.pic"></image>
<text class="product-title">{{ p_item.name |formatLongText }}</text>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import Api from '@/common/api';
import navBar from "@/components/zhouWei-navBar";
export default {
components:{
navBar
},
data() {
return {
select_index: 0,
windows_height: 0, //屏幕高度
right_height: [], //右侧每个内容的高度集合
right_scroll: 0, //右侧的滑动值
left_height: 0, //左侧总高度
left_scroll: 0, //左侧滑动值
last: 0,
scroll_height: '',
statusBarHeight: '',
catrgoryList: [
]
};
},
onLoad() {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
this.scroll_height = uni.getSystemInfoSync().windowHeight - (this.statusBarHeight + 44 + 40);
console.log('------',this.scroll_height)
this.windows_height = uni.getSystemInfoSync().windowHeight;
this.getData();
},
filters: {
formatCreateTime(time) {
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
formatNull(value) {
if(value===undefined||value===null||value===''){
return '暂无';
}else{
return value;
}
},
formatLongText(value) {
if(value===undefined||value===null||value===''){
return '暂无';
}else if(value.length>4){
return value.substr(0, 4) + '...';
}else{
return value;
}
},
formatPayType(value) {
if (value === 2) {
return '支付宝';
} else if (value === 1) {
return '微信小程序';
} else if (value === 3){
return '余额支付';
} else if (value === 5){
return '积分兑换';
}
},
},
methods: {
search() {
uni.navigateTo({
url: '/pages/search/search'
});
},
async getData() {
let params = {};
this.catrgoryList = await Api.apiCall('get', Api.goods.categoryAndGoodsList, params);
this.$nextTick(function() {
this.getHeightList();
});
console.log('-----', this.catrgoryList);
},
toCategory(item) {
uni.navigateTo({
url: `../../pagesA/product/product?id=${item.id}`
});
},
getHeightList() {
let _this = this;
let selectorQuery = uni.createSelectorQuery();
selectorQuery.select('.left-content').boundingClientRect(function(rects) {
_this.left_height = rects.height;
});
selectorQuery
.selectAll('.category-item')
.boundingClientRect(function(rects) {
_this.right_height = rects.map(item => item.top);
console.log(_this.right_height);
})
.exec();
},
choose(index) {
console.log('--choose--', index);
console.log('--choose--', this.select_index);
if (this.select_index === index) {
return;
}
this.select_index = index;
// 加入防抖
if (this.timeout) {
clearTimeout(this.timeout); //清除计时器
}
this.timeout = setTimeout(() => {
this.right_scroll = this.right_height[index] - 180;
}, 300);
console.log('--this.right_scroll--', this.right_scroll);
},
myscroll(e) {
//引入节流
let right_content_height = e.detail.scrollHeight - this.windows_height;
if (right_content_height == e.detail.scrollTop) {
console.log('--this.myscroll--', this.right_scroll);
return;
}
let scroll_top = e.detail.scrollTop + 110; //110是banner图的高度
//判断当前的scrollTop在哪个区间内;
let now = +new Date();
if (now - this.last > 140) {
this.last = now;
let active_index = this.right_height.findIndex((value, index, arr) => value <= scroll_top && scroll_top < arr[index + 1]);
this.select_index = active_index;
if (this.left_height - this.windows_height) {
//如果有超出部分
let diff = this.left_height - this.windows_height;
this.left_scroll = Math.round((active_index * diff) / (this.catrgoryList.length - 1));
}
}
}
}
};
</script>
<style lang="less">
page,
.content {
height: 100%;
background-color: #f8f8f8;
}
.content {
display: flex;
}
.statusBar {
width: 100%;
position: fixed;
top: 0;
z-index: 99;
background: #ffffff;
}
.getPosition {
height: 90upx;
position: fixed;
z-index: 99;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 32upx;
background-color: #fff;
}
.search {
background: #ffffff;
height: 80upx;
display: flex;
justify-content: center;
align-items: center;
border-bottom: 1upx solid #eeeeee;
}
.search_input {
font-size: 28upx;
background: #f5f5f5;
height: 60upx;
width: 90%;
border-radius: 50upx;
text-align: center;
}
.banner-item {
width: 94%;
height: 180upx;
border-radius: 20upx;
margin-left: 3%;
}
.banner {
width: 100%;
height: 180upx;
border-radius: 20upx;
overflow: hidden;
box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);
}
.category-wrapper {
width: 100%;
display: flex;
flex-direction: row;
// position: absolute;
// top: 100upx;
// bottom: 0;
.left-wrapper {
width: 25%;
flex: 0 0 200rpx;
background-color: #ffffff;
.left-content {
.title-content {
width: 100%;
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
font-size: 30upx;
border-bottom: 1px solid #eeeeee;
cursor: pointer;
&:last-child {
// border-bottom: 0;
}
&.onSelected {
background-color: #fff;
position: relative;
// color: #4aa849;
color: #f44142;
&::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 5upx;
height: 100%;
background: #f44142;
// background: linear-gradient(124deg, #feb436 0%, #fb7c22 100%);
}
}
}
}
}
.right-wrapper {
flex: 1;
width: 75%;
background-color: #ffffff;
.right-content {
width: 100%;
padding-top: 20rpx;
border-left: 1rpx solid #efefef;
box-sizing: border-box;
.banner-wrapper {
padding: 0 20rpx;
.swiper-content {
width: 100%;
height: 180rpx;
margin-bottom: 30rpx;
.swiper-item {
.swiper-img {
width: 100%;
height: 180rpx;
}
}
}
}
.product-wrapper {
.category-item {
.category-title {
height: 60rpx;
font-size: 26rpx;
line-height: 60rpx;
font-weight: 500;
background-color: #f6f6f6;
padding-left: 20rpx;
color: #000;
}
.category-content {
display: flex;
flex-direction: row;
flex-flow: wrap;
padding: 40rpx 20rpx 0;
margin-bottom: 20rpx;
.product-item {
width: 33%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 20rpx;
.product-img {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
margin-bottom: 10rpx;
}
.product-title {
font-size: 28rpx;
}
}
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,408 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">销量优先</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text>
</view>
<view class="goods-list">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPageL(item.url)">
<view class="image-wrapper"><image :src="item.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.name }}</text>
<view class="price-box">
<text class="price">{{ item.price }}</text>
<text>已售 {{ item.clickCount }}</text>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
pageNum: 1,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: []
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
//加载分类
async loadCateList(fid, sid) {
let params = {};
let list = await Api.apiCall('get', Api.goods.typeList, params);
//let list = await this.$api.json('cateList');
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params;
if (this.cateId) {
params = { pageNum: this.pageNum };
if (this.keyword) {
params = { pageNum: this.pageNum ,keyword: this.keyword };
}
}
if (this.keyword) {
params = { pageNum: this.pageNum, keyword: this.keyword };
} else {
params = { pageNum: this.pageNum };
}
let list = await Api.apiCall('get', Api.index.bannerList, params);
let goodsList = list;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.clickCount - a.clickCount);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.clickCount - b.clickCount;
}
return b.clickCount - a.clickCount;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情页
navToDetailPageL(url) {
window.location.href =url;
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
let groupId = item.groupId;
uni.navigateTo({
url: `../../pagesA/product/groupProduct?id=${id}&&groupId=&{groupId}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 0 30upx;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
</style>

View File

@@ -0,0 +1,406 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text>
</view>
<view class="goods-list">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.icon" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.title }}</text>
<view class="price-box">
<text class="price">{{ item.price }}</text>
<text>已售 6</text>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
pageNum: 1,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: []
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
//加载分类
async loadCateList(fid, sid) {
let params = {};
let list = await Api.apiCall('get', Api.goods.typeGiftList, params);
//let list = await this.$api.json('cateList');
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params;
if (this.cateId) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId };
if (this.keyword) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId, keyword: this.keyword };
}
}
if (this.keyword) {
params = { pageNum: this.pageNum, keyword: this.keyword };
} else {
params = { pageNum: this.pageNum };
}
let list = await Api.apiCall('get', Api.goods.giftList, params);
let goodsList = list.records;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
console.log(item.id);
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
uni.navigateTo({
url: `../../pagesA/product/giftProduct?id=${id}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 0 30upx;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
</style>

View File

@@ -0,0 +1,706 @@
<template>
<view class="container">
<view class="carousel">
<view class="image-wrapper"><image :src="detailData.icon" class="loaded" mode="aspectFill"></image></view>
</view>
<view class="introduce-section">
<text class="title">{{ detailData.name }}</text>
<view class="price-box">
<text class="price-tip">¥</text>
<text class="price">{{ detailData.price }}</text>
</view>
<view class="bot-row">
<text>销量: 6</text>
<text>库存: {{ detailData.stock }}</text>
<text>浏览量: {{ detailData.hit }}</text>
</view>
</view>
<!-- 分享 -->
<view class="share-section" @click="share">
<view class="share-icon">
<text class="yticon icon-xingxing"></text>
</view>
<text class="tit">该商品分享可领49减10红包</text>
<text class="yticon icon-bangzhu1"></text>
<view class="share-btn">
立即分享
<text class="yticon icon-you"></text>
</view>
</view>
<view class="c-list">
<view class="c-row b-b">
<text class="tit">服务</text>
<view class="bz-list con">
<text>7天无理由退换货 ·</text>
<text>假一赔十 ·</text>
</view>
</view>
</view>
<view class="detail-desc">
<view class="d-header"><text>图文详情</text></view>
<rich-text :nodes="desc |formatRichText"></rich-text>
</view>
<!-- 底部操作菜单 -->
<view class="page-bottom">
<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
<text class="yticon icon-xiatubiao--copy"></text>
<text>首页</text>
</navigator>
<view class="p-b-btn" :class="{ active: favorite }" @click="toFavorite(detailData)">
<text class="yticon icon-shoucang"></text>
<text>收藏</text>
</view>
<view class="action-btn-group"><button type="primary" class=" action-btn no-border add-cart-btn" @click="jifenPay(detailData)">积分兑换</button></view>
</view>
<!-- 分享 -->
<share ref="share" :contentHeight="580" :shareList="shareList"></share>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import share from '@/components/share';
import { mapState } from 'vuex';
export default {
components: {
share
},
data() {
return {
specClass: 'none',
specSelected: [],
small: null,
sku: [],
detailData: [],
favorite: true,
shareList: [],
desc: `
<div style="width:100%">
<img style="width:100%;display:block;" src="https://gd3.alicdn.com/imgextra/i4/479184430/O1CN01nCpuLc1iaz4bcSN17_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd2.alicdn.com/imgextra/i2/479184430/O1CN01gwbN931iaz4TzqzmG_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd3.alicdn.com/imgextra/i3/479184430/O1CN018wVjQh1iaz4aupv1A_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd4.alicdn.com/imgextra/i4/479184430/O1CN01tWg4Us1iaz4auqelt_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd1.alicdn.com/imgextra/i1/479184430/O1CN01Tnm1rU1iaz4aVKcwP_!!479184430.jpg_400x400.jpg" />
</div>
`,
skuList: []
};
},
async onLoad(ops) {
//接收传值,id里面放的是标题因为测试数据并没写id
let id = ops.id;
if (id) {
this.logining = true;
let params = { id: ops.id };
let data = await Api.apiCall('get', Api.goods.giftDetail, params);
this.logining = false;
if (data) {
let detailData = data.goods;
this.favorite = data.favorite;
this.typeGoodsList = detailData.typeGoodsList;
var subImages = detailData.albumPics;
this.desc = detailData.content;
let shareList = await this.$api.json('shareList');
this.loaded = true;
this.detailData = detailData;
this.shareList = shareList;
uni.setNavigationBarTitle({
title: detailData.name
});
}
}
this.shareList = await this.$api.json('shareList');
},
computed: {
...mapState(['hasLogin', 'userInfo'])
},
filters: {
/**
* 处理富文本里的图片宽度自适应
* 1.去掉img标签里的style、width、height属性
* 2.img标签添加style属性max-width:100%;height:auto
* 3.修改所有style里的width属性为max-width:100%
* 4.去掉<br/>标签
* @param html
* @returns {void|string|*}
*/
formatRichText (html) { //控制小程序中图片大小
if (html) {
let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match;
});
newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
return match;
});
newContent = newContent.replace(/<br[^>]*\/>/gi, '');
newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
return newContent;
} else {
return '暂无商品详情'
}
},
formatCreateTime(time) {
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
},
methods: {
//分享
share() {
this.$refs.share.toggleMask();
},
//收藏
toFavorite(item) {
if (!this.hasLogin) {
let url = '/pages/public/login';
uni.navigateTo({
url
});
} else {
this.favorite = !this.favorite;
let params = { objId: item.id, type: 4, name: item.name, meno1: item.pic, meno2: item.price, meno3: item.sale };
Api.apiCall('post', Api.goods.favoriteSave, params);
}
},
async jifenPay(item) {
if (!this.hasLogin) {
let url = '/pages/public/login';
uni.navigateTo({
url
});
return false;
}
let id = item.id;
let data;
let params = { goodsId: id };
data = await Api.apiCall('post', Api.order.jifenPay, params);
if (data) {
this.$api.msg(data);
}
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page {
background: $page-color-base;
padding-bottom: 160upx;
}
.icon-you {
font-size: $font-base + 2upx;
color: #888;
}
.carousel {
height: 722upx;
position: relative;
swiper {
height: 100%;
}
.image-wrapper {
width: 100%;
height: 100%;
}
.swiper-item {
display: flex;
justify-content: center;
align-content: center;
height: 750upx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
}
/* 标题简介 */
.introduce-section {
background: #fff;
padding: 20upx 30upx;
.title {
font-size: 32upx;
color: $font-color-dark;
height: 50upx;
line-height: 50upx;
}
.price-box {
display: flex;
align-items: baseline;
height: 64upx;
padding: 10upx 0;
font-size: 26upx;
color: $uni-color-primary;
}
.price {
font-size: $font-lg + 2upx;
}
.m-price {
margin: 0 12upx;
color: $font-color-light;
text-decoration: line-through;
}
.coupon-tip {
align-items: center;
padding: 4upx 10upx;
background: $uni-color-primary;
font-size: $font-sm;
color: #fff;
border-radius: 6upx;
line-height: 1;
transform: translateY(-4upx);
}
.bot-row {
display: flex;
align-items: center;
height: 50upx;
font-size: $font-sm;
color: $font-color-light;
text {
flex: 1;
}
}
}
/* 分享 */
.share-section {
display: flex;
align-items: center;
color: $font-color-base;
background: linear-gradient(left, #fdf5f6, #fbebf6);
padding: 12upx 30upx;
.share-icon {
display: flex;
align-items: center;
width: 70upx;
height: 30upx;
line-height: 1;
border: 1px solid $uni-color-primary;
border-radius: 4upx;
position: relative;
overflow: hidden;
font-size: 22upx;
color: $uni-color-primary;
&:after {
content: '';
width: 50upx;
height: 50upx;
border-radius: 50%;
left: -20upx;
top: -12upx;
position: absolute;
background: $uni-color-primary;
}
}
.icon-xingxing {
position: relative;
z-index: 1;
font-size: 24upx;
margin-left: 2upx;
margin-right: 10upx;
color: #fff;
line-height: 1;
}
.tit {
font-size: $font-base;
margin-left: 10upx;
}
.icon-bangzhu1 {
padding: 10upx;
font-size: 30upx;
line-height: 1;
}
.share-btn {
flex: 1;
text-align: right;
font-size: $font-sm;
color: $uni-color-primary;
}
.icon-you {
font-size: $font-sm;
margin-left: 4upx;
color: $uni-color-primary;
}
}
.c-list {
font-size: $font-sm + 2upx;
color: $font-color-base;
background: #fff;
.c-row {
display: flex;
align-items: center;
padding: 20upx 30upx;
position: relative;
}
.tit {
width: 140upx;
}
.con {
flex: 1;
color: $font-color-dark;
.selected-text {
margin-right: 10upx;
}
}
.bz-list {
height: 40upx;
font-size: $font-sm + 2upx;
color: $font-color-dark;
text {
display: inline-block;
margin-right: 30upx;
}
}
.con-list {
flex: 1;
display: flex;
flex-direction: column;
color: $font-color-dark;
line-height: 40upx;
}
.red {
color: $uni-color-primary;
}
}
/* 评价 */
.eva-section {
display: flex;
flex-direction: column;
padding: 20upx 30upx;
background: #fff;
margin-top: 16upx;
.e-header {
display: flex;
align-items: center;
height: 70upx;
font-size: $font-sm + 2upx;
color: $font-color-light;
.tit {
font-size: $font-base + 2upx;
color: $font-color-dark;
margin-right: 4upx;
}
.tip {
flex: 1;
text-align: right;
}
.icon-you {
margin-left: 10upx;
}
}
}
.eva-box {
display: flex;
padding: 20upx 0;
.portrait {
flex-shrink: 0;
width: 80upx;
height: 80upx;
border-radius: 100px;
}
.right {
flex: 1;
display: flex;
flex-direction: column;
font-size: $font-base;
color: $font-color-base;
padding-left: 26upx;
.con {
font-size: $font-base;
color: $font-color-dark;
padding: 20upx 0;
}
.bot {
display: flex;
justify-content: space-between;
font-size: $font-sm;
color: $font-color-light;
}
}
}
/* 详情 */
.detail-desc {
background: #fff;
margin-top: 16upx;
.d-header {
display: flex;
justify-content: center;
align-items: center;
height: 80upx;
font-size: $font-base + 2upx;
color: $font-color-dark;
position: relative;
text {
padding: 0 20upx;
background: #fff;
position: relative;
z-index: 1;
}
&:after {
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%);
width: 300upx;
height: 0;
content: '';
border-bottom: 1px solid #ccc;
}
}
}
/* 规格选择弹窗 */
.attr-content {
padding: 10upx 30upx;
.a-t {
display: flex;
image {
width: 170upx;
height: 170upx;
flex-shrink: 0;
margin-top: -40upx;
border-radius: 8upx;
}
.right {
display: flex;
flex-direction: column;
padding-left: 24upx;
font-size: $font-sm + 2upx;
color: $font-color-base;
line-height: 42upx;
.price {
font-size: $font-lg;
color: $uni-color-primary;
margin-bottom: 10upx;
}
.selected-text {
margin-right: 10upx;
}
}
}
.attr-list {
display: flex;
flex-direction: column;
font-size: $font-base + 2upx;
color: $font-color-base;
padding-top: 30upx;
padding-left: 10upx;
}
.item-list {
padding: 20upx 0 0;
display: flex;
flex-wrap: wrap;
text {
display: flex;
align-items: center;
justify-content: center;
background: #eee;
margin-right: 20upx;
margin-bottom: 20upx;
border-radius: 100upx;
min-width: 60upx;
height: 60upx;
padding: 0 20upx;
font-size: $font-base;
color: $font-color-dark;
}
.selected {
background: #fbebee;
color: $uni-color-primary;
}
}
}
/* 弹出层 */
.popup {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: 99;
&.show {
display: block;
.mask {
animation: showPopup 0.2s linear both;
}
.layer {
animation: showLayer 0.2s linear both;
}
}
&.hide {
.mask {
animation: hidePopup 0.2s linear both;
}
.layer {
animation: hideLayer 0.2s linear both;
}
}
&.none {
display: none;
}
.mask {
position: fixed;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(0, 0, 0, 0.4);
}
.layer {
position: fixed;
z-index: 99;
bottom: 0;
width: 100%;
min-height: 40vh;
border-radius: 10upx 10upx 0 0;
background-color: #fff;
.btn {
height: 66upx;
line-height: 66upx;
border-radius: 100upx;
background: $uni-color-primary;
font-size: $font-base + 2upx;
color: #fff;
margin: 30upx auto 20upx;
}
}
@keyframes showPopup {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes hidePopup {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes showLayer {
0% {
transform: translateY(120%);
}
100% {
transform: translateY(0%);
}
}
@keyframes hideLayer {
0% {
transform: translateY(0);
}
100% {
transform: translateY(120%);
}
}
}
/* 底部操作菜单 */
.page-bottom {
position: fixed;
left: 30upx;
bottom: 30upx;
z-index: 95;
display: flex;
justify-content: center;
align-items: center;
width: 690upx;
height: 100upx;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 0 20upx 0 rgba(0, 0, 0, 0.5);
border-radius: 16upx;
.p-b-btn {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: $font-sm;
color: $font-color-base;
width: 96upx;
height: 80upx;
.yticon {
font-size: 40upx;
line-height: 48upx;
color: $font-color-light;
}
&.active,
&.active .yticon {
color: $uni-color-primary;
}
.icon-fenxiang2 {
font-size: 42upx;
transform: translateY(-2upx);
}
.icon-shoucang {
font-size: 46upx;
}
}
.action-btn-group {
display: flex;
height: 76upx;
border-radius: 100px;
overflow: hidden;
box-shadow: 0 20upx 40upx -16upx #fa436a;
box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
background: linear-gradient(to right, #ffac30, #fa436a, #f56c6c);
margin-left: 20upx;
position: relative;
&:after {
content: '';
position: absolute;
top: 50%;
right: 50%;
transform: translateY(-50%);
height: 28upx;
width: 0;
border-right: 1px solid rgba(255, 255, 255, 0.5);
}
.action-btn {
display: flex;
align-items: center;
justify-content: center;
width: 180upx;
height: 100%;
font-size: $font-base;
padding: 0;
border-radius: 0;
background: transparent;
}
}
}
</style>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,381 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text>
</view>
<view class="goods-list">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.name }}</text>
<view class="price-box">
<text class="price">{{ item.price }}</text>
<text>运费 {{item.transfee}}</text>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
pageNum: 1,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: []
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
//this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params;
if (this.cateId) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId };
if (this.keyword) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId, keyword: this.keyword };
}
}
if (this.keyword) {
params = { pageNum: this.pageNum, keyword: this.keyword };
} else {
params = { pageNum: this.pageNum };
}
let list = await Api.apiCall('get', Api.index.groupActivityList, params);
let goodsList = list.records;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
console.log(item.id);
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
uni.navigateTo({
url: `../../pagesA/product/groupActivityDetail?id=${id}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 20upx 20upx 0 20upx;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
</style>

View File

@@ -0,0 +1,407 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">销量优先</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text>
</view>
<view class="goods-list">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.goods.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.goods.name }}</text>
<view class="price-box">
<text class="price">{{ item.groupPrice }}</text>
<text>原价 {{ item.goods.price }}</text>
</view>
</view>
</view>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
pageNum: 1,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: []
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
//加载分类
async loadCateList(fid, sid) {
let params = {};
let list = await Api.apiCall('get', Api.goods.typeList, params);
//let list = await this.$api.json('cateList');
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params;
if (this.cateId) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId };
if (this.keyword) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId, keyword: this.keyword };
}
}
if (this.keyword) {
params = { pageNum: this.pageNum, keyword: this.keyword };
} else {
params = { pageNum: this.pageNum };
}
let list = await Api.apiCall('get', Api.goods.groupHotGoodsList, params);
let goodsList = list;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.goodsId;
let groupId = item.id;
uni.navigateTo({
url: `../../pagesA/product/groupProduct?id=${id}&&groupId=&{groupId}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 20upx 20upx 0;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
</style>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,528 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">销量优先</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<!-- <text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text> -->
<text class="cate-item yticon icon-fenlei1" v-if="current == 0" @click="toShowMode('false')"></text>
<text class="cate-item cgicon icon-vertical" v-else-if="current == 1" @click="toShowMode('true')"></text>
</view>
<!-- 表格图片显示 -->
<view class="goods-list" v-show="current === 0">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.name }}</text>
<view class="price-box" v-if="item.isFenxiao == 1">
<text class="price">{{ item.price }}</text>
<text>佣金 ¥{{ item.fenxiaoPrice }}</text>
</view>
<view class="price-box" v-if="item.isVip == 1">
<text class="price">会员价{{ item.vipPrice }}</text>
<text>商品价 ¥{{ item.price }}</text>
</view>
<view class="price-box" v-else-if="item.isFenxiao == 0 && item.isVip == 0">
<text class="price">{{ item.price }}</text>
<text>已售 {{ item.sale }}</text>
</view>
</view>
</view>
<!-- 列表显示 -->
<view class="goods-list-vertical" v-show="current === 1">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item-vertical" @click="navToDetailPage(item)">
<view class="image-wrapper-vertical"><image :src="item.pic" mode="aspectFill"></image></view>
<view class="goods-list-right">
<view class="goods-right-top">
<text class="">{{ item.name }}</text>
</view>
<view class="goods-right-bottom">
<text class="price">{{ item.price }}</text>
<text class="sale">已售 {{ item.sale }}</text>
</view>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
productAttributeCategoryId: 0,
pageNum: 1,
isFenxiao: 0,
isVip: 0,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: [],
current: 0 // 1为列表模式
};
},
onLoad(options) {
console.log(options);
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
this.isVip = options.isVip;
this.isFenxiao = options.isFenxiao;
console.log(options);
this.productAttributeCategoryId = options.productAttributeCategoryId;
this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
toShowMode(mode) {
if (this.current == 0) {
this.current = 1;
} else {
this.current = 0;
}
},
//加载分类
async loadCateList(fid, sid) {
let params = {};
let list = await Api.apiCall('get', Api.goods.typeList, params);
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params = { pageNum: this.pageNum, productCategoryId: this.cateId, type: 1, productAttributeCategoryId: this.productAttributeCategoryId };;
if (this.cateId) {
params.productCategoryId = this.cateId;
}
if (this.productAttributeCategoryId) {
params.productAttributeCategoryId = this.productAttributeCategoryId;
}
if (this.keyword) {
params.keyword = this.keyword;
}
if (this.isVip) {
params.isVip = 1;
}
if (this.isFenxiao) {
params.isFenxiao = 1;
}
let list = await Api.apiCall('get', Api.goods.goodsList, params);
let goodsList = list.records;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
uni.navigateTo({
url: `../../pagesA/product/product?id=${id}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
@font-face {
font-family: 'cgicon';
font-weight: normal;
font-style: normal;
src: url('https://at.alicdn.com/t/font_1475801_65jj7c5ss9k.ttf') format('truetype');
}
.cgicon {
font-family: 'cgicon' !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-vertical:before {
content: '\e61b';
}
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 20upx 20upx 0;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
.goods-list-vertical {
display: flex;
flex-wrap: wrap;
padding: 0upx 20upx;
background: #fff;
.goods-item-vertical {
display: flex;
flex-direction: row;
height: 280upx;
align-items: center;
justify-content: center;
border-bottom: 1upx solid #eeeeee;
.image-wrapper-vertical {
width: 240upx;
height: 240upx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 10upx;
image {
width: 240upx;
height: 240upx;
}
}
.goods-list-right {
width: 470upx;
.goods-right-top {
height: 200upx;
text {
font-size: 32upx;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
}
.goods-right-bottom {
display: flex;
align-items: center;
justify-content: space-between;
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
.sale {
color: $font-color-light;
font-size: 28upx;
}
}
}
}
}
</style>

View File

@@ -0,0 +1,726 @@
<template>
<view class="container">
<view class="carousel">
<swiper indicator-dots circular="true" duration="400">
<swiper-item class="swiper-item" v-for="(item, index) in small" :key="index">
<view class="image-wrapper"><image :src="item" class="loaded" mode="aspectFill"></image></view>
</swiper-item>
</swiper>
</view>
<view class="introduce-section">
<text class="title">{{ detailData.name }}</text>
<view class="price-box">
<text class="price-tip">¥</text>
<text class="price">{{ detailData.price }}</text>
</view>
<view class="bot-row">
<text>出价次数: {{buyCount}}</text>
<text>浏览量: {{ detailData.hit }}</text>
</view>
</view>
<view class="share-section" >
<view class="share-btn" v-if="(detailData.type == 2) && detailData.timeSecound">剩余
<uni-countdown :day="detailData.timeSecound.days" :hour="detailData.timeSecound.hour" :minute="detailData.timeSecound.mins" :second="detailData.timeSecound.sc">
</uni-countdown></view>
<view class="goods-salesvolume red-price" v-if="detailData.type == 3">已结束</view>
<view class="goods-salesvolume red-price" v-if="detailData.type == 1">即将开团</view>
</view>
<!-- 分享 -->
<view class="share-section" @click="share">
<view class="share-icon">
<text class="yticon icon-xingxing"></text>
</view>
<text class="tit">该商品分享可领49减10红包</text>
<text class="yticon icon-bangzhu1"></text>
<view class="share-btn">
立即分享
<text class="yticon icon-you"></text>
</view>
</view>
<view class="c-list">
<view class="c-row b-b">
<text class="tit">服务</text>
<view class="bz-list con">
<text>7天无理由退换货 ·</text>
<text>假一赔十 ·</text>
</view>
</view>
</view>
<view class="detail-desc">
<view class="d-header"><text>图文详情</text></view>
<rich-text :nodes="desc |formatRichText"></rich-text>
</view>
<!-- 底部操作菜单 -->
<view class="page-bottom">
<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
<text class="yticon icon-xiatubiao--copy"></text>
<text>首页</text>
</navigator>
<view class="p-b-btn" :class="{ active: favorite }" @click="toFavorite(detailData)">
<text class="yticon icon-shoucang"></text>
<text>收藏</text>
</view>
<view class="action-btn-group"><button type="primary" class=" action-btn no-border add-cart-btn" @click="jifenPay(detailData)">出价竞拍</button></view>
</view>
<!-- 分享 -->
<share ref="share" :contentHeight="580" :shareList="shareList"></share>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import share from '@/components/share';
import { mapState } from 'vuex';
import uniCountdown from "@/components/uni-countdown/uni-countdown.vue"
export default {
components: {
share,uniCountdown
},
data() {
return {
specClass: 'none',
specSelected: [],
small: null,
sku: [],
detailData: [],
paimaiLogList:[],
buyCount : 0,
favorite: true,
shareList: [],
desc: `
<div style="width:100%">
<img style="width:100%;display:block;" src="https://gd3.alicdn.com/imgextra/i4/479184430/O1CN01nCpuLc1iaz4bcSN17_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd2.alicdn.com/imgextra/i2/479184430/O1CN01gwbN931iaz4TzqzmG_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd3.alicdn.com/imgextra/i3/479184430/O1CN018wVjQh1iaz4aupv1A_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd4.alicdn.com/imgextra/i4/479184430/O1CN01tWg4Us1iaz4auqelt_!!479184430.jpg_400x400.jpg" />
<img style="width:100%;display:block;" src="https://gd1.alicdn.com/imgextra/i1/479184430/O1CN01Tnm1rU1iaz4aVKcwP_!!479184430.jpg_400x400.jpg" />
</div>
`,
skuList: []
};
},
async onLoad(ops) {
//接收传值,id里面放的是标题因为测试数据并没写id
let id = ops.id;
if (id) {
this.logining = true;
let params = { id: ops.id };
let data = await Api.apiCall('get', Api.goods.paiMaiDetail, params);
this.logining = false;
if (data) {
let detailData = data.goods;
this.favorite = data.favorite;
this.paimaiLogList = detailData.paimaiLogList;
if(this.paimaiLogList){
this.buyCount=this.paimaiLogList.length;
}
var subImages = detailData.albumPics;
this.small = subImages.split(',');
this.desc = detailData.content;
let shareList = await this.$api.json('shareList');
this.loaded = true;
this.detailData = detailData;
this.shareList = shareList;
uni.setNavigationBarTitle({
title: detailData.name
});
}
}
this.shareList = await this.$api.json('shareList');
},
computed: {
...mapState(['hasLogin', 'userInfo'])
},
filters: {
/**
* 处理富文本里的图片宽度自适应
* 1.去掉img标签里的style、width、height属性
* 2.img标签添加style属性max-width:100%;height:auto
* 3.修改所有style里的width属性为max-width:100%
* 4.去掉<br/>标签
* @param html
* @returns {void|string|*}
*/
formatRichText (html) { //控制小程序中图片大小
if (html) {
let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match;
});
newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
return match;
});
newContent = newContent.replace(/<br[^>]*\/>/gi, '');
newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
return newContent;
} else {
return '暂无商品详情'
}
},
formatCreateTime(time) {
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
},
},
methods: {
//分享
share() {
this.$refs.share.toggleMask();
},
//收藏
toFavorite(item) {
if (!this.hasLogin) {
let url = '/pages/public/login';
uni.navigateTo({
url
});
} else {
this.favorite = !this.favorite;
let params = { objId: item.id, type: 4, name: item.name, meno1: item.pic, meno2: item.price, meno3: item.sale };
Api.apiCall('post', Api.goods.favoriteSave, params);
}
},
async jifenPay(item) {
if (!this.hasLogin) {
let url = '/pages/public/login';
uni.navigateTo({
url
});
return false;
}
let id = item.id;
let data;
let params = { goodsId: id, price: 1 };
data = await Api.apiCall('post', Api.goods.updatePaiMai, params);
if (data) {
this.$api.msg(data);
}
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page {
background: $page-color-base;
padding-bottom: 160upx;
}
.icon-you {
font-size: $font-base + 2upx;
color: #888;
}
.carousel {
height: 722upx;
position: relative;
swiper {
height: 100%;
}
.image-wrapper {
width: 100%;
height: 100%;
}
.swiper-item {
display: flex;
justify-content: center;
align-content: center;
height: 750upx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
}
/* 标题简介 */
.introduce-section {
background: #fff;
padding: 20upx 30upx;
.title {
font-size: 32upx;
color: $font-color-dark;
height: 50upx;
line-height: 50upx;
}
.price-box {
display: flex;
align-items: baseline;
height: 64upx;
padding: 10upx 0;
font-size: 26upx;
color: $uni-color-primary;
}
.price {
font-size: $font-lg + 2upx;
}
.m-price {
margin: 0 12upx;
color: $font-color-light;
text-decoration: line-through;
}
.coupon-tip {
align-items: center;
padding: 4upx 10upx;
background: $uni-color-primary;
font-size: $font-sm;
color: #fff;
border-radius: 6upx;
line-height: 1;
transform: translateY(-4upx);
}
.bot-row {
display: flex;
align-items: center;
height: 50upx;
font-size: $font-sm;
color: $font-color-light;
text {
flex: 1;
}
}
}
/* 分享 */
.share-section {
display: flex;
align-items: center;
color: $font-color-base;
background: linear-gradient(left, #fdf5f6, #fbebf6);
padding: 12upx 30upx;
.share-icon {
display: flex;
align-items: center;
width: 70upx;
height: 30upx;
line-height: 1;
border: 1px solid $uni-color-primary;
border-radius: 4upx;
position: relative;
overflow: hidden;
font-size: 22upx;
color: $uni-color-primary;
&:after {
content: '';
width: 50upx;
height: 50upx;
border-radius: 50%;
left: -20upx;
top: -12upx;
position: absolute;
background: $uni-color-primary;
}
}
.icon-xingxing {
position: relative;
z-index: 1;
font-size: 24upx;
margin-left: 2upx;
margin-right: 10upx;
color: #fff;
line-height: 1;
}
.tit {
font-size: $font-base;
margin-left: 10upx;
}
.icon-bangzhu1 {
padding: 10upx;
font-size: 30upx;
line-height: 1;
}
.share-btn {
flex: 1;
text-align: right;
font-size: $font-sm;
color: $uni-color-primary;
}
.icon-you {
font-size: $font-sm;
margin-left: 4upx;
color: $uni-color-primary;
}
}
.c-list {
font-size: $font-sm + 2upx;
color: $font-color-base;
background: #fff;
.c-row {
display: flex;
align-items: center;
padding: 20upx 30upx;
position: relative;
}
.tit {
width: 140upx;
}
.con {
flex: 1;
color: $font-color-dark;
.selected-text {
margin-right: 10upx;
}
}
.bz-list {
height: 40upx;
font-size: $font-sm + 2upx;
color: $font-color-dark;
text {
display: inline-block;
margin-right: 30upx;
}
}
.con-list {
flex: 1;
display: flex;
flex-direction: column;
color: $font-color-dark;
line-height: 40upx;
}
.red {
color: $uni-color-primary;
}
}
/* 评价 */
.eva-section {
display: flex;
flex-direction: column;
padding: 20upx 30upx;
background: #fff;
margin-top: 16upx;
.e-header {
display: flex;
align-items: center;
height: 70upx;
font-size: $font-sm + 2upx;
color: $font-color-light;
.tit {
font-size: $font-base + 2upx;
color: $font-color-dark;
margin-right: 4upx;
}
.tip {
flex: 1;
text-align: right;
}
.icon-you {
margin-left: 10upx;
}
}
}
.eva-box {
display: flex;
padding: 20upx 0;
.portrait {
flex-shrink: 0;
width: 80upx;
height: 80upx;
border-radius: 100px;
}
.right {
flex: 1;
display: flex;
flex-direction: column;
font-size: $font-base;
color: $font-color-base;
padding-left: 26upx;
.con {
font-size: $font-base;
color: $font-color-dark;
padding: 20upx 0;
}
.bot {
display: flex;
justify-content: space-between;
font-size: $font-sm;
color: $font-color-light;
}
}
}
/* 详情 */
.detail-desc {
background: #fff;
margin-top: 16upx;
.d-header {
display: flex;
justify-content: center;
align-items: center;
height: 80upx;
font-size: $font-base + 2upx;
color: $font-color-dark;
position: relative;
text {
padding: 0 20upx;
background: #fff;
position: relative;
z-index: 1;
}
&:after {
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%);
width: 300upx;
height: 0;
content: '';
border-bottom: 1px solid #ccc;
}
}
}
/* 规格选择弹窗 */
.attr-content {
padding: 10upx 30upx;
.a-t {
display: flex;
image {
width: 170upx;
height: 170upx;
flex-shrink: 0;
margin-top: -40upx;
border-radius: 8upx;
}
.right {
display: flex;
flex-direction: column;
padding-left: 24upx;
font-size: $font-sm + 2upx;
color: $font-color-base;
line-height: 42upx;
.price {
font-size: $font-lg;
color: $uni-color-primary;
margin-bottom: 10upx;
}
.selected-text {
margin-right: 10upx;
}
}
}
.attr-list {
display: flex;
flex-direction: column;
font-size: $font-base + 2upx;
color: $font-color-base;
padding-top: 30upx;
padding-left: 10upx;
}
.item-list {
padding: 20upx 0 0;
display: flex;
flex-wrap: wrap;
text {
display: flex;
align-items: center;
justify-content: center;
background: #eee;
margin-right: 20upx;
margin-bottom: 20upx;
border-radius: 100upx;
min-width: 60upx;
height: 60upx;
padding: 0 20upx;
font-size: $font-base;
color: $font-color-dark;
}
.selected {
background: #fbebee;
color: $uni-color-primary;
}
}
}
/* 弹出层 */
.popup {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: 99;
&.show {
display: block;
.mask {
animation: showPopup 0.2s linear both;
}
.layer {
animation: showLayer 0.2s linear both;
}
}
&.hide {
.mask {
animation: hidePopup 0.2s linear both;
}
.layer {
animation: hideLayer 0.2s linear both;
}
}
&.none {
display: none;
}
.mask {
position: fixed;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(0, 0, 0, 0.4);
}
.layer {
position: fixed;
z-index: 99;
bottom: 0;
width: 100%;
min-height: 40vh;
border-radius: 10upx 10upx 0 0;
background-color: #fff;
.btn {
height: 66upx;
line-height: 66upx;
border-radius: 100upx;
background: $uni-color-primary;
font-size: $font-base + 2upx;
color: #fff;
margin: 30upx auto 20upx;
}
}
@keyframes showPopup {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes hidePopup {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes showLayer {
0% {
transform: translateY(120%);
}
100% {
transform: translateY(0%);
}
}
@keyframes hideLayer {
0% {
transform: translateY(0);
}
100% {
transform: translateY(120%);
}
}
}
/* 底部操作菜单 */
.page-bottom {
position: fixed;
left: 30upx;
bottom: 30upx;
z-index: 95;
display: flex;
justify-content: center;
align-items: center;
width: 690upx;
height: 100upx;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 0 20upx 0 rgba(0, 0, 0, 0.5);
border-radius: 16upx;
.p-b-btn {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: $font-sm;
color: $font-color-base;
width: 96upx;
height: 80upx;
.yticon {
font-size: 40upx;
line-height: 48upx;
color: $font-color-light;
}
&.active,
&.active .yticon {
color: $uni-color-primary;
}
.icon-fenxiang2 {
font-size: 42upx;
transform: translateY(-2upx);
}
.icon-shoucang {
font-size: 46upx;
}
}
.action-btn-group {
display: flex;
height: 76upx;
border-radius: 100px;
overflow: hidden;
box-shadow: 0 20upx 40upx -16upx #fa436a;
box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
background: linear-gradient(to right, #ffac30, #fa436a, #f56c6c);
margin-left: 20upx;
position: relative;
&:after {
content: '';
position: absolute;
top: 50%;
right: 50%;
transform: translateY(-50%);
height: 28upx;
width: 0;
border-right: 1px solid rgba(255, 255, 255, 0.5);
}
.action-btn {
display: flex;
align-items: center;
justify-content: center;
width: 180upx;
height: 100%;
font-size: $font-base;
padding: 0;
border-radius: 0;
background: transparent;
}
}
}
</style>

View File

@@ -0,0 +1,406 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">销量优先</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text>
</view>
<view class="goods-list">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.name }}</text>
<view class="price-box">
<text class="price">{{ item.price }}</text>
<text>已售 {{ item.sale }}</text>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
pageNum: 1,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: []
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.keyword = options.keyword;
this.cateId = options.sid;
// this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
//加载分类
loadCateList(fid, sid) {
let params = {};
let list = Api.apiCall('get', Api.goods.typeList, params);
console.log(list);
//let list = await this.$api.json('cateList');
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
//没有更多直接返回
if (type === 'add') {
if (this.loadingType === 'nomore') {
return;
}
this.loadingType = 'loading';
} else {
this.loadingType = 'more';
}
let params;
if (this.cateId) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId ,type:2};
if (this.keyword) {
params = { pageNum: this.pageNum, productCategoryId: this.cateId, keyword: this.keyword ,type:2};
}
}
if (this.keyword) {
params = { pageNum: this.pageNum, keyword: this.keyword ,type:2};
} else {
params = { pageNum: this.pageNum ,type:2};
}
let list = await Api.apiCall('get', Api.goods.goodsList, params);
let goodsList = list.records;
// let goodsList = await this.$api.json('goodsList');
if (type === 'refresh') {
this.goodsList = [];
}
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = this.goodsList.concat(goodsList);
//判断是否还有下一页有是more 没有是nomore(测试数据判断大于20就没有了)
this.loadingType = this.goodsList.length > list.total ? 'nomore' : 'more';
if (type === 'refresh') {
if (loading == 1) {
uni.hideLoading();
} else {
uni.stopPullDownRefresh();
}
}
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
uni.navigateTo({
url: `../../pagesA/product/paiMaiDetail?id=${id}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 0 30upx;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
</style>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,205 @@
<template>
<view>
<uni-section title="商品标签" type="line"></uni-section>
<view class="example-body">
<view class="tag-view" v-for="(item, index) in goodsTagList" :key="index" @click="navToList(item.id)">
<uni-tag :text="item.name" type="success" />
</view>
</view>
<uni-section title="会员标签" type="line"></uni-section>
<view class="example-body" >
<view class="tag-view" v-for="(item, index) in memberTagList" :key="index" @click="navToList(item.id)">
<uni-tag :circle="true" :text="item.name" type="warning" />
</view>
</view>
<uni-section title="内容标签" type="line"></uni-section>
<view class="example-body">
<view class="tag-view" v-for="(item, index) in cmsTagList" :key="index" @click="navToList(item.id)">
<uni-tag :circle="true" :inverted="inverted" :text="item.name" type="primary" @click="setInverted" />
</view>
</view>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniTag from '@/components/uni-tag/uni-tag.vue';
import uniSection from '@/components/uni-section/uni-section.vue'
export default {
components: {
uniTag,
uniSection
},
data() {
return {
type: 'default',
goodsTagList:[],
memberTagList:[],
cmsTagList:[],
inverted: false
};
},
onLoad(options) {
this.loadGoodsData();
this.loadMemberData();
this.loadCmsData();
},
methods: {
async loadGoodsData() {
let params = {type:2,status:1};
let list = await Api.apiCall('get', Api.member.memberTagList, params);
this.goodsTagList = list.records;
},
async loadMemberData() {
let params = {type:1,status:1};
let list = await Api.apiCall('get', Api.member.memberTagList, params);
this.memberTagList = list.records;
},
async loadCmsData() {
let params = {type:3,status:1};
let list = await Api.apiCall('get', Api.member.memberTagList, params);
this.cmsTagList = list.records;
},
setType() {
let types = ['default', 'primary', 'success', 'warning', 'error'];
let index = types.indexOf(this.type);
types.splice(index, 1);
let randomIndex = Math.floor(Math.random() * 4);
this.type = types[randomIndex];
},
setInverted() {
this.inverted = !this.inverted;
},
navToList(tagId) {
uni.navigateTo({
url: `../../pagesA/product/tagGoodslist?tagId=${tagId}`
});
}
}
};
</script>
<style>
/* 头条小程序组件内不能引入字体 */
/* #ifdef MP-TOUTIAO */
@font-face {
font-family: uniicons;
font-weight: normal;
font-style: normal;
}
/* #endif */
/* #ifndef APP-NVUE */
page {
display: flex;
flex-direction: column;
box-sizing: border-box;
background-color: #efeff4;
min-height: 100%;
height: auto;
}
view {
font-size: 14px;
line-height: inherit;
}
.example {
padding: 0 15px 15px;
}
.example-info {
padding: 15px;
color: #3b4144;
background: #ffffff;
}
.example-body {
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
padding: 0;
font-size: 14px;
background-color: #ffffff;
}
/* #endif */
.example {
padding: 0 15px;
}
.example-info {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
padding: 15px;
color: #3b4144;
background-color: #ffffff;
font-size: 14px;
line-height: 20px;
}
.example-info-text {
font-size: 14px;
line-height: 20px;
color: #3b4144;
}
.example-body {
flex-direction: column;
padding: 15px;
background-color: #ffffff;
}
.word-btn-white {
font-size: 18px;
color: #FFFFFF;
}
.word-btn {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
border-radius: 6px;
height: 48px;
margin: 15px;
background-color: #007AFF;
}
.word-btn--hover {
background-color: #4ca2ff;
}
.example-body {
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: flex-start;
flex-wrap: wrap;
padding: 20rpx;
}
.tag-view {
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
flex-direction: column;
margin: 10rpx 15rpx;
justify-content: center;
}
</style>

View File

@@ -0,0 +1,483 @@
<template>
<view class="content">
<view class="navbar" :style="{ position: headerPosition, top: headerTop }">
<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
<view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">销量优先</view>
<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
<text>价格</text>
<view class="p-box">
<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="yticon icon-shang"></text>
<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="yticon icon-shang xia"></text>
</view>
</view>
<!-- <text class="cate-item yticon icon-fenlei1" @click="toggleCateMask('show')"></text> -->
<text class="cate-item yticon icon-fenlei1" v-if="current == 0" @click="toShowMode('false')"></text>
<text class="cate-item cgicon icon-vertical" v-else-if="current == 1" @click="toShowMode('true')"></text>
</view>
<!-- 表格图片显示 -->
<view class="goods-list" v-show="current === 0">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
<view class="image-wrapper"><image :src="item.pic" mode="aspectFill"></image></view>
<text class="title clamp">{{ item.name }}</text>
<view class="price-box" v-if="item.isFenxiao == 1">
<text class="price">{{ item.price }}</text>
<text>佣金 ¥{{ item.fenxiaoPrice }}</text>
</view>
<view class="price-box" v-if="item.isVip == 1">
<text class="price">会员价{{ item.vipPrice }}</text>
<text>商品价 ¥{{ item.price }}</text>
</view>
<view class="price-box" v-else-if="item.isFenxiao == 0 && item.isVip == 0">
<text class="price">{{ item.price }}</text>
<text>已售 {{ item.sale }}</text>
</view>
</view>
</view>
<!-- 列表显示 -->
<view class="goods-list-vertical" v-show="current === 1">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item-vertical" @click="navToDetailPage(item)">
<view class="image-wrapper-vertical"><image :src="item.pic" mode="aspectFill"></image></view>
<view class="goods-list-right">
<view class="goods-right-top">
<text class="">{{ item.name }}</text>
</view>
<view class="goods-right-bottom">
<text class="price">{{ item.price }}</text>
<text class="sale">已售 {{ item.sale }}</text>
</view>
</view>
</view>
</view>
<uni-load-more :status="loadingType"></uni-load-more>
<view class="cate-mask" :class="cateMaskState === 0 ? 'none' : cateMaskState === 1 ? 'show' : ''" @click="toggleCateMask">
<view class="cate-content" @click.stop.prevent="stopPrevent" @touchmove.stop.prevent="stopPrevent">
<scroll-view scroll-y class="cate-list">
<view v-for="item in cateList" :key="item.id">
<view class="cate-item b-b two">{{ item.name }}</view>
<view v-for="tItem in item.child" :key="tItem.id" class="cate-item b-b" :class="{ active: tItem.id == cateId }" @click="changeCate(tItem)">
{{ tItem.name }}
</view>
</view>
</scroll-view>
</view>
</view>
<mallplusCopyright></mallplusCopyright>
</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
components: {
mallplusCopyright,
uniLoadMore
},
data() {
return {
cateMaskState: 0, //分类面板展开状态
headerPosition: 'fixed',
headerTop: '0px',
keyword: '',
loadingType: 'more', //加载更多状态
filterIndex: 0,
cateId: 0, //已选三级分类id
productAttributeCategoryId: 0,
pageNum: 1,
isFenxiao: 0,
isVip: 0,
cid: null,
priceOrder: 0, //1 价格从低到高 2价格从高到低
cateList: [],
goodsList: [],
current: 0 // 1为列表模式
};
},
onLoad(options) {
// #ifdef H5
this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
// #endif
this.cateId = options.tagId;
// this.loadCateList(options.fid, options.sid);
this.loadData();
},
onPageScroll(e) {
//兼容iOS端下拉时顶部漂移
if (e.scrollTop >= 0) {
this.headerPosition = 'fixed';
} else {
this.headerPosition = 'absolute';
}
},
//下拉刷新
onPullDownRefresh() {
this.pageNum = 1;
this.loadData('refresh');
},
//加载更多
onReachBottom() {
this.pageNum = this.pageNum + 1;
this.loadData();
},
methods: {
toShowMode(mode) {
if (this.current == 0) {
this.current = 1;
} else {
this.current = 0;
}
},
//加载分类
async loadCateList(fid, sid) {
let params = {};
let list = await Api.apiCall('get', Api.goods.typeList, params);
let cateList = list.filter(item => item.pid == null);
cateList.forEach(item => {
let tempList = list.filter(val => val.pid == item.id);
item.child = tempList;
});
this.cateList = cateList;
},
//加载商品 ,带下拉刷新和上滑加载
async loadData(type = 'add', loading) {
let params = { tags: this.cateId };
let list = await Api.apiCall('get', Api.goods.tagGoodsList, params);
let goodsList = list;
//筛选,测试数据直接前端筛选了
if (this.filterIndex === 1) {
goodsList.sort((a, b) => b.sales - a.sales);
}
if (this.filterIndex === 2) {
goodsList.sort((a, b) => {
if (this.priceOrder == 1) {
return a.price - b.price;
}
return b.price - a.price;
});
}
this.goodsList = goodsList;
},
//筛选点击
tabClick(index) {
this.pageNum = 1;
if (this.filterIndex === index && index !== 2) {
return;
}
this.filterIndex = index;
if (index === 2) {
this.priceOrder = this.priceOrder === 1 ? 2 : 1;
} else {
this.priceOrder = 0;
}
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//显示分类面板
toggleCateMask(type) {
let timer = type === 'show' ? 10 : 300;
let state = type === 'show' ? 1 : 0;
this.cateMaskState = 2;
setTimeout(() => {
this.cateMaskState = state;
}, timer);
},
//分类点击
changeCate(item) {
this.pageNum = 1;
this.cateId = item.id;
this.toggleCateMask();
uni.pageScrollTo({
duration: 300,
scrollTop: 0
});
this.loadData('refresh', 1);
},
//详情
navToDetailPage(item) {
//测试数据没有写id用title代替
let id = item.id;
uni.navigateTo({
url: `../../pagesA/product/product?id=${id}`
});
},
stopPrevent() {}
}
};
</script>
<style lang="scss">
@font-face {
font-family: 'cgicon';
font-weight: normal;
font-style: normal;
src: url('https://at.alicdn.com/t/font_1475801_65jj7c5ss9k.ttf') format('truetype');
}
.cgicon {
font-family: 'cgicon' !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-vertical:before {
content: '\e61b';
}
page,
.content {
background: $page-color-base;
}
.content {
padding-top: 96upx;
}
.navbar {
position: fixed;
left: 0;
top: var(--window-top);
display: flex;
width: 100%;
height: 80upx;
background: #fff;
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.06);
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 30upx;
color: $font-color-dark;
position: relative;
&.current {
color: $base-color;
&:after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 120upx;
height: 0;
border-bottom: 4upx solid $base-color;
}
}
}
.p-box {
display: flex;
flex-direction: column;
.yticon {
display: flex;
align-items: center;
justify-content: center;
width: 30upx;
height: 14upx;
line-height: 1;
margin-left: 4upx;
font-size: 26upx;
color: #888;
&.active {
color: $base-color;
}
}
.xia {
transform: scaleY(-1);
}
}
.cate-item {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 80upx;
position: relative;
font-size: 44upx;
&:after {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
border-left: 1px solid #ddd;
width: 0;
height: 36upx;
}
}
}
/* 分类 */
.cate-mask {
position: fixed;
left: 0;
top: var(--window-top);
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0);
z-index: 95;
transition: 0.3s;
.cate-content {
width: 630upx;
height: 100%;
background: #fff;
float: right;
transform: translateX(100%);
transition: 0.3s;
}
&.none {
display: none;
}
&.show {
background: rgba(0, 0, 0, 0.4);
.cate-content {
transform: translateX(0);
}
}
}
.cate-list {
display: flex;
flex-direction: column;
height: 100%;
.cate-item {
display: flex;
align-items: center;
height: 90upx;
padding-left: 30upx;
font-size: 28upx;
color: #555;
position: relative;
}
.two {
height: 64upx;
color: #303133;
font-size: 30upx;
background: #f8f8f8;
}
.active {
color: $base-color;
}
}
/* 商品列表 */
.goods-list {
display: flex;
flex-wrap: wrap;
padding: 20upx 20upx 0;
background: #fff;
.goods-item {
display: flex;
flex-direction: column;
width: 48%;
padding-bottom: 40upx;
&:nth-child(2n + 1) {
margin-right: 4%;
}
}
.image-wrapper {
width: 100%;
height: 330upx;
border-radius: 3px;
overflow: hidden;
image {
width: 100%;
height: 100%;
opacity: 1;
}
}
.title {
font-size: $font-lg;
color: $font-color-dark;
line-height: 80upx;
}
.price-box {
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 10upx;
font-size: 24upx;
color: $font-color-light;
}
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
}
.goods-list-vertical {
display: flex;
flex-wrap: wrap;
padding: 0upx 20upx;
background: #fff;
.goods-item-vertical {
display: flex;
flex-direction: row;
height: 280upx;
align-items: center;
justify-content: center;
border-bottom: 1upx solid #eeeeee;
.image-wrapper-vertical {
width: 240upx;
height: 240upx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 10upx;
image {
width: 240upx;
height: 240upx;
}
}
.goods-list-right {
width: 470upx;
.goods-right-top {
height: 200upx;
text {
font-size: 32upx;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
}
.goods-right-bottom {
display: flex;
align-items: center;
justify-content: space-between;
.price {
font-size: $font-lg;
color: $uni-color-primary;
line-height: 1;
&:before {
content: '¥';
font-size: 26upx;
}
}
.sale {
color: $font-color-light;
font-size: 28upx;
}
}
}
}
}
</style>