You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong_qianduan/pages/goods/list.vue

972 lines
24 KiB

8 months ago
<template>
<view class="container" :style="appThemeStyle">
<mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }"
@down="downCallback" :up="upOption" @up="upCallback">
<!-- 页面头部 -->
<view class="header">
<view class="search">
<search :tips="options.search ? options.search : '搜索商品'" @event="handleSearch" />
</view>
</view>
<view class="store-sort">
8 months ago
<template v-if="options.categoryId">
<view class="goodsban" v-if="tabbar && tabbar.length > 0">
<scroll-view class="typeList" scroll-x="true">
<view v-for="(item,index) in tabbar" :key="index" class="bandsImg" @click="onChage(item,1)"
:style="{'color':item.category_id==isBanrdActive?'#F43B21':'#5A5A5A','border':item.category_id==isBanrdActive?'1rpx solid #F22029':'1rpx solid #E7E7E7'}">
<image :src="item.image" mode=""></image>
<view class="typeItem">{{item.name}}</view>
</view>
</scroll-view>
</view>
8 months ago
<view class="goodsType" v-if="goodsType && goodsType.length > 0">
<scroll-view class="typeList" scroll-x="true">
<view v-for="(item,index) in goodsType" :key="index" class="typeItem"
@click="onChage(item,2)"
:style="{'color':isActive==item.category_id?'#F43B21':'#5A5A5A','background':isActive==item.category_id?'#FEF6F6':'#F7F8FA','border':isActive==item.category_id?'2rpx solid #F22029':'none'}">
{{item.name}}
</view>
</scroll-view>
</view>
</template>
<!-- 排序标签 -->
<view class="store-box">
<view class="sort-item" :class="{ active: sortType === 'all' }" @click="handleSortType('all')">
<text>综合</text>
</view>
<view class="sort-item" :class="{ active: sortType === 'sales' }" @click="handleSortType('sales')">
<text>销量</text>
</view>
<view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }"
@click="handleSortType('price')">
<text>价格</text>
<view class="price-arrow">
<view class="icon up" :class="{ active: sortType === 'price' && !sortPrice }">
<u-icon name="arrow-up-fill"
:color="!sortPrice&&sortType === 'price'?'#F43B21':'#3C3C3C'" size="17"></u-icon>
</view>
<view class="icon down" :class="{ active: sortType === 'price' && sortPrice }">
<u-icon name="arrow-down-fill"
:color="sortPrice&&sortType === 'price'?'#F43B21':'#3C3C3C'" size="17"></u-icon>
</view>
</view>
</view>
8 months ago
<view class="sort-item" :class="{ active: sortType === 'city' }" @click="handleSortType('city')">
<picker mode="selector" @change="multiChange" value="{{multiIndex}}" :range="multiArray"
range-key="name">
<text>类型</text>
</picker>
8 months ago
</view>
<!-- <view class="show-view btnOpera" @click="handleShowView">
<text class="iconfont icon-view-tile" v-if="showView"></text>
<text class="iconfont icon-view-list" v-else></text>
</view> -->
</view>
</view>
<!-- 商品列表 -->
<view class="goods-list clearfix" :class="['column-' + (showView ? '1' : '2')]">
<view v-if="showView">
<view class="goods-item" v-for="(item, index) in list.data" :key="index"
@click="onTargetDetail(item.goods_id)">
<!-- 单列显示 -->
<view v-if="showView" class="dis-flex">
<!-- 商品图片 -->
<view class="goods-item-left">
<image class="image" :src="item.goods_image"></image>
</view>
<view class="goods-item-right">
<!-- 商品名称 -->
<view class="goods-name">
<text class="twoline-hide">{{ item.goods_name }}</text>
</view>
<view class="goods-item-desc">
<!-- 商品卖点 -->
<view class="desc-selling-point dis-flex">
<text class="oneline-hide">{{ item.selling_point }}</text>
</view>
<!-- 商品销量 -->
<view class="desc-goods-sales dis-flex">
<text>已售{{ item.goods_sales }}</text>
</view>
<!-- 商品价格 -->
<view class="desc-footer">
<text
class="price-x">¥{{ item.goods_price_min>0?Number(item.goods_price_min):0.00 }}</text>
<text class="price-y col-9"
v-if="item.line_price_min > 0">¥{{ item.line_price_min>0?Number(item.line_price_min):'' }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
<view v-else>
<u-waterfall v-model="list.data" ref="uWaterfall1">
<template v-slot:left="{leftList}">
<view class="goods-item" v-for="(item, index) in leftList" :key="index"
@click="onTargetDetail(item.goods_id)">
<!-- 多列显示 -->
<view class="">
<!-- 商品图片 -->
<view class="goods-image">
<image class="image" mode="aspectFill" :src="item.goods_image"></image>
</view>
<view class="detail">
<!-- 商品名称 -->
<view class="goods-name">
<text>{{ item.goods_name }}</text>
</view>
<!-- 商品价格 -->
<view class="shenBox">
<view class="detail-price oneline-hide">
<text class="goods-price f-30 col-m"><text
style="font-size: 26rpx;"></text>{{ item.goods_price_min>0?Number(item.goods_price_min):0.00}}
<text class="delPrice"></text></text>
<text v-if="item.line_price_min > 0"
class="line-price col-9 f-24">{{ item.line_price_min>0?Number(item.line_price_min):0.00 }}</text>
</view>
8 months ago
<image :src="$picUrl+'/static/detail/redShen.png'" v-if="item.is_check==1" mode="">
8 months ago
</image>
</view>
<view class="goodsInfo">
<view class="oneTip">
{{item.cmmdty_model}}
</view>
</view>
<view class="goodsSend">
<view class="sendLeft">
<view class="left_1">
{{item.goods_source}}
8 months ago
</view>
<view class="left_2">
{{Number(item.discount)}}
</view>
</view>
<view class="sendRight">
<text v-if="item.delivery_time==0">24小时内发货</text>
<text v-if="item.delivery_time==1">48小时内发货</text>
<text v-if="item.delivery_time==2">72小时内发货</text>
<text v-if="item.delivery_time==3">7天内发货</text>
<text v-if="item.delivery_time==4">15天内发货</text>
<text v-if="item.delivery_time==5">30天内发货</text>
<text v-if="item.delivery_time==6">45天内发货</text>
</view>
</view>
</view>
</view>
</view>
</template>
<template v-slot:right="{rightList}">
<view class="goods-item" v-for="(item, index) in rightList" :key="index"
@click="onTargetDetail(item.goods_id)">
<!-- 多列显示 -->
<view class="">
<!-- 商品图片 -->
<view class="goods-image">
<image class="image" mode="aspectFill" :src="item.goods_image"></image>
</view>
<view class="detail">
<!-- 商品名称 -->
<view class="goods-name">
<text>{{ item.goods_name }}</text>
</view>
<!-- 商品价格 -->
<view class="shenBox">
<view class="detail-price oneline-hide">
<text class="goods-price f-30 col-m"><text
style="font-size: 26rpx;"></text>{{ item.goods_price_min>0?Number(item.goods_price_min):'' }}
<text class="delPrice"></text></text>
<text v-if="item.line_price_min > 0"
class="line-price col-9 f-24">{{ item.line_price_min>0?Number(item.line_price_min):'' }}</text>
</view>
8 months ago
<image :src="$picUrl+'/static/detail/redShen.png'" v-if="item.is_check==1" mode="">
8 months ago
</image>
</view>
<view class="goodsInfo">
<view class="oneTip">
{{item.cmmdty_model}}
</view>
</view>
<view class="goodsSend">
<view class="sendLeft">
<view class="left_1">
{{item.goods_source}}
8 months ago
</view>
<view class="left_2">
{{Number(item.discount)}}
</view>
</view>
<view class="sendRight">
<text v-if="item.delivery_time==0">24小时内发货</text>
<text v-if="item.delivery_time==1">48小时内发货</text>
<text v-if="item.delivery_time==2">72小时内发货</text>
<text v-if="item.delivery_time==3">7天内发货</text>
<text v-if="item.delivery_time==4">15天内发货</text>
<text v-if="item.delivery_time==5">30天内发货</text>
<text v-if="item.delivery_time==6">45天内发货</text>
</view>
</view>
</view>
</view>
</view>
</template>
</u-waterfall>
</view>
9 months ago
<view style="margin-top: 250rpx;" v-if="list.data.length==0 && total == 0">
<u-empty text="暂无数据显示哦~" mode="list"></u-empty>
8 months ago
</view>
</view>
</mescroll-body>
</view>
</template>
<script>
import WxofficialMixin from '@/core/mixins/wxofficial'
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins'
import * as GoodsApi from '@/api/goods'
import {
getEmptyPaginateObj,
getMoreListData
} from '@/core/app'
import Search from '@/components/search'
const pageSize = 15
const showViewKey = 'GoodsList-ShowView';
import * as cstegory from '@/api/category'
export default {
components: {
Search
},
mixins: [MescrollMixin, WxofficialMixin],
data() {
return {
8 months ago
total: 1,
searchText: '',
banrdType: [],
keyName1: '',
isBanrdActive: '',
isActive: '',
goodsType: [],
keyName2: '',
showView: false, // 列表显示方式 (true列表、false平铺)
sortType: 'all', // 排序类型
sortPrice: '', // 价格排序 (true高到低 false低到高)
options: {}, // 当前页面参数
list: getEmptyPaginateObj(), // 商品列表数据
// 上拉加载配置
upOption: {
// 首次自动执行
auto: true,
// 每页数据的数量; 默认10
page: {
size: pageSize
},
// 数量要大于4条才显示无更多数据
9 months ago
// noMoreSize: 4,
empty: {
8 months ago
use: false,
}
},
tabbar: [],
multiArray: [{
value: 'JD',
8 months ago
name: 'JD'
}, {
value: 'SN',
8 months ago
name: 'SN'
}, {
value: 'GC',
8 months ago
name: 'GC'
}, {
value: 'CC',
8 months ago
name: 'CC '
}, {
value: 'ZC',
8 months ago
name: 'ZC'
}],
multiIndex: -1,
8 months ago
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 记录options
this.options = options
this.searchText = options.search
// 设置默认列表显示方式
this.setShowView()
// 设置微信公众号链接分享卡片内容
8 months ago
this.setWxofficialShareData()
8 months ago
if (options.categoryId != 'undefined') {
8 months ago
this.getGoodsTypeList(options.categoryId)
8 months ago
}
},
methods: {
multiChange(e) {
this.multiIndex = Number(e.detail.value)
// 刷新列表数据
this.$refs.uWaterfall1.clear();
this.list.data = []
this.list = getEmptyPaginateObj()
this.mescroll.resetUpScroll()
},
8 months ago
getGoodsTypeList(category_id) {
const that = this;
that.goodsType = []
return new Promise((resolve, reject) => {
cstegory.childrenList({
category_id: category_id
})
.then(res => {
if (res.data.list.length > 0) {
that.tabbar = res.data.list;
res.data.list.forEach(item => {
item.children.forEach(item_1 => {
that.goodsType.push(item_1)
})
});
console.log(that.goodsType, that.tabbar)
}
})
.catch(reject)
})
},
onChage(item, type) {
if (type == 1) {
if (item.category_id == this.isBanrdActive) {
this.isBanrdActive = '';
this.keyName1 = ''
} else {
this.isBanrdActive = item.category_id;
this.keyName1 = item.name
}
}
if (type == 2) {
if (item.category_id == this.isActive) {
this.isActive = '';
this.keyName2 = ''
} else {
this.isActive = item.category_id;
this.keyName2 = item.name
}
9 months ago
}
this.list.data = []
8 months ago
this.$refs.uWaterfall1.clear();
this.getGoodsList()
},
/**
* 上拉加载的回调 (页面初始化时也会执行一次)
* 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
* @param {Object} page
*/
upCallback(page) {
const app = this
// 设置列表数据
app.getGoodsList(page.num)
.then(list => {
const curPageLen = list.data.length
const totalSize = list.data.total
9 months ago
app.mescroll.endBySize(curPageLen, totalSize)
8 months ago
})
.catch(() => app.mescroll.endErr())
},
// 设置默认列表显示方式
setShowView() {
this.showView = uni.getStorageSync(showViewKey) || false
},
//数组对象去重
arrayUnique(arr, name) {
8 months ago
var hash = {};
return arr.reduce(function(item, next) {
hash[next[name]] ?
"" :
(hash[next[name]] = true && item.push(next));
return item;
}, []);
},
/**
* 获取商品列表
* @param {number} pageNo 页码
*/
getGoodsList(pageNo = 1) {
const app = this
let keywords = []
if (this.keyName1) {
keywords.push(this.keyName1)
}
if (this.keyName2) {
keywords.push(this.keyName2)
}
const param = {
sortType: app.sortType != 'city' ? app.sortType : '',
8 months ago
sortPrice: Number(app.sortPrice),
categoryId: (app.options.categoryId || app.options.categoryId != undefined) ? app.options
.categoryId : 0,
// goodsName: app.options.search || '',
page: pageNo,
keywords: keywords.length > 0 ? keywords.join(',') : '',
keyword: app.options.search || '',
goods_source: this.multiIndex > -1 ? this.multiArray[this.multiIndex].value : ''
8 months ago
}
return new Promise((resolve, reject) => {
GoodsApi.list(param)
.then(result => {
// 合并新数据
const newList = result.data.list
let arr = getMoreListData(newList, app.list, pageNo);
8 months ago
app.list.data = app.arrayUnique(arr, 'goods_id')
app.total = result.data.list.total;
8 months ago
resolve(newList)
})
.catch(reject)
})
},
// 切换排序方式
handleSortType(newSortType) {
const app = this
app.sortType = newSortType
// 刷新列表数据
if (newSortType != 'city') {
const newSortPrice = newSortType === 'price' ? !app.sortPrice : true
app.sortPrice = newSortPrice
app.$refs.uWaterfall1.clear();
app.list.data = []
app.list = getEmptyPaginateObj()
app.mescroll.resetUpScroll()
}
8 months ago
},
// 切换列表显示方式
handleShowView() {
const app = this
app.showView = !app.showView
uni.setStorageSync(showViewKey, app.showView)
},
// 跳转商品详情页
onTargetDetail(goodsId) {
this.$navTo('pages/goods/detail', {
goodsId
})
},
/**
* 商品搜索
*/
9 months ago
handleSearch() {
this.isBanrdActive = '';
this.keyName1 = '';
this.isActive = '';
this.keyName2 = '';
8 months ago
this.banrdType = [];
this.goodsType = [];
const searchPageUrl = 'pages/search/index?category_id=' + this.options.categoryId
// 判断来源页面
let pages = getCurrentPages()
if (pages.length > 1 &&
pages[pages.length - 2].route == searchPageUrl) {
uni.navigateBack()
return
}
// 跳转到商品搜索页
this.$navTo(searchPageUrl)
},
// 设置微信公众号链接分享卡片内容
setWxofficialShareData() {
this.updateShareCardData({
title: '商品列表'
})
},
},
/**
* 设置分享内容
*/
onShareAppMessage() {
// 构建分享参数
const app = this
return {
title: "商品列表",
path: "/pages/goods/list?" + this.$getShareUrlParams(app.options)
}
},
/**
* 分享到朋友圈
* 本接口为 Beta 版本暂只在 Android 平台支持详见分享到朋友圈 (Beta)
* https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
*/
onShareTimeline() {
// 构建分享参数
const app = this
return {
title: "商品列表",
path: "/pages/goods/list?" + this.$getShareUrlParams(app.options)
}
}
}
</script>
<style lang="scss" scoped>
::v-deep .u-empty {
padding: 100rpx 0;
}
// 页面头部
.header {
background-color: #fff;
// 搜索框
.search {
width: 100%;
padding: 0 30rpx;
.search-wrapper {
padding: 0;
width: 100%;
}
}
// 切换显示方式
.show-view {
width: 60rpx;
height: 60rpx;
font-size: 36rpx;
color: #505050;
display: flex;
align-items: center;
}
}
// 排序组件
.store-sort {
position: sticky;
top: var(--window-top);
background-color: #fff;
color: #000;
z-index: 99;
.store-box {
display: flex;
padding: 15rpx 0;
font-size: 28rpx;
background: #fff;
.sort-item {
flex-basis: 25%;
display: flex;
justify-content: center;
align-items: center;
height: 50rpx;
&.active {
color: $main-bg;
}
}
.sort-item-price .price-arrow {
margin-left: 20rpx;
font-size: 24rpx;
color: #000;
.icon {
&.active {
color: $main-bg;
}
&.up {
margin-bottom: -16rpx;
}
&.down {
margin-top: -16rpx;
}
}
}
}
}
// 商品列表
.goods-list {
padding: 8rpx 16rpx;
box-sizing: border-box;
}
// 单列显示
.goods-list.column-1 {
.goods-item {
width: 100%;
height: 280rpx;
margin-bottom: 12rpx;
padding: 20rpx;
box-sizing: border-box;
background: #fff;
line-height: 1.6;
&:last-child {
margin-bottom: 0;
}
}
.goods-item-left {
display: flex;
width: 300rpx;
background: #fff;
align-items: center;
.image {
display: block;
width: 240rpx;
height: 240rpx;
}
}
.goods-item-right {
position: relative;
flex: 1;
.goods-name {
margin-top: 10rpx;
min-height: 68rpx;
9 months ago
white-space: normal;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
-webkit-line-clamp: 2;
height: 90rpx;
8 months ago
line-height: 45rpx;
font-weight: bold;
font-size: 30rpx;
color: #1E1E1E;
}
}
.goods-item-desc {
margin-top: 8rpx;
}
.desc-selling-point {
width: 400rpx;
font-size: 24rpx;
color: #e49a3d;
}
.desc-goods-sales {
color: #999;
font-size: 24rpx;
}
.desc-footer {
font-size: 24rpx;
.price-x {
margin-right: 16rpx;
color: $main-bg;
font-size: 30rpx;
}
.price-y {
text-decoration: line-through;
}
}
}
// 平铺显示
.goods-list.column-2 {
.goods-item {
// width: 50%;
}
}
.goods-item {
float: left;
box-sizing: border-box;
padding: 12rpx 9rpx;
.goods-image {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
overflow: hidden;
background: #fff;
&:after {
content: '';
display: block;
margin-top: 100%;
}
.image {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
-o-object-fit: cover;
object-fit: cover;
}
}
.detail {
padding: 20rpx;
background: #fff;
.goods-name {
line-height: 1.3;
white-space: normal;
font-weight: bold;
font-size: 30rpx;
color: #1E1E1E;
9 months ago
margin-bottom: 4rpx;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
-webkit-line-clamp: 2;
height: 90rpx;
8 months ago
line-height: 45rpx;
}
.shenBox {
overflow: hidden;
display: flex;
justify-content: space-between;
align-items: center;
image {
width: 28rpx;
height: 28rpx;
}
}
.detail-price {
.goods-price {
font-family: PingFang SC, PingFang SC;
font-weight: bold;
font-size: 36rpx;
color: #F21A1C;
}
.line-price {
text-decoration: line-through;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
font-size: 24rpx;
color: #949494;
}
}
}
}
.btnOpera {
width: 33rpx;
height: 33rpx;
position: relative;
top: 6rpx;
}
.shipping {
width: 44rpx;
background: #FFFFFF;
border-radius: 4rpx;
opacity: 1;
border: 1rpx solid #F21A1C;
font-size: 16rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #F21A1C;
line-height: 24rpx;
text-align: center;
margin: 6rpx 0 12rpx 0;
}
.goodsInfo {
display: flex;
align-items: center;
margin-bottom: 10rpx;
.oneTip {
padding: 0 16rpx;
height: 42rpx;
background: #F6F6F6;
border-radius: 10rpx 10rpx 10rpx 10rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #333333;
line-height: 42rpx;
text-align: left;
font-style: normal;
text-transform: none;
margin-top: 6rpx;
max-width: 300rpx;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
-webkit-line-clamp: 1;
white-space: nowrap;
}
}
.goodsSend {
display: flex;
justify-content: space-between;
align-items: center;
.sendLeft {
width: 120rpx;
border: 1rpx solid #F21A1C;
border-radius: 10rpx;
height: 42rpx;
display: flex;
justify-content: space-between;
align-items: center;
.left_1 {
height: 100%;
width: 50rpx;
line-height: 36.5rpx;
font-family: PingFang SC, PingFang SC;
font-weight: bold;
font-size: 30rpx;
color: #F21A1C;
text-align: center;
}
.left_2 {
height: 100%;
width: 70rpx;
background-color: #F21A1C;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #FFFFFF;
line-height: 36rpx;
text-align: center;
font-style: normal;
text-transform: none;
}
}
.sendRight {
height: 42rpx;
background: #FDEDED;
padding: 0 10rpx;
border-radius: 10rpx 10rpx 10rpx 10rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #F21A1C;
line-height: 42rpx;
text-align: left;
font-style: normal;
text-transform: none;
}
}
.delPrice {
font-size: 20rpx;
font-weight: 500;
color: #F21A1C;
}
.evaluate {
height: 28rpx;
font-size: 20rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #949494;
line-height: 28rpx;
margin-bottom: 20rpx;
}
.goodsType {
background-color: #fff;
padding: 0 30rpx;
// height: 90rpx;
margin-top: 20rpx;
display: flex;
align-items: center;
.text {
padding-right: 30rpx;
}
.typeList {
white-space: nowrap;
.typeItem {
margin-right: 20rpx;
display: inline-block;
height: 54rpx;
border-radius: 82rpx 82rpx 82rpx 82rpx;
opacity: 1;
padding: 0 20rpx;
font-size: 24rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
line-height: 54rpx;
text-align: center;
}
}
}
.goodsban {
background-color: #fff;
padding: 0 30rpx;
height: 122rpx;
display: flex;
align-items: center;
padding-top: 25rpx;
.typeList {
white-space: nowrap;
.bandsImg {
display: inline-block;
width: 160rpx;
height: 120rpx;
background: #FFFFFF;
border-radius: 10rpx 10rpx 10rpx 10rpx;
border: 1rpx solid #E7E7E7;
margin-right: 18rpx;
image {
margin: 9rpx 5%;
width: 90%;
height: 50rpx;
}
.typeItem {
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 28rpx;
color: #3E3E3E;
line-height: 32rpx;
text-align: center;
font-style: normal;
text-transform: none;
}
}
}
}
8 months ago
</style>