123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- <template>
- <view style="position: absolute;top:0;right:0;left:0;bottom:0"><view style="height:100%" class="scroll-view-wrapper div common-goods-list">
- <view class="scroll-view-wrapper scroll-view div goodslist-body show-goods-list" >
- <view class="div ui-goodslist-filter">
- <view class="ul filter-list">
- <view class="li item"
- v-for='(item, index) in sortkey'
- v-bind:key='item.id'
- v-on:click='setActiveSortkey(item, index)'
- v-bind:class="{'sortactive': item.id == currentSortKey.id, 'sortnormal' : item.id != currentSortKey.id}">
- <text class="a" v-if='!item.isMore'>{{item.name}}</text>
- <text class="a" v-else>{{sort.name}}</text>
- <text class="span iconfont" :class="isShowMore?'active':''" v-if="item.isMore"></text>
- </view>
- <view class="li item" @click="showPopup('showAttribute')" v-if="attribute.attr_array.length!=0 || attribute.brand_array.length!=0">
- <text class="a">筛选</text>
- </view>
- </view>
- <view class="div sort-model" v-if='isShowMore' >
- <view class="div" v-for='(item, index) in childSort' v-bind:key='item.id' v-on:click='getSortChild(item)' v-bind:class="{'active': item.id == sort.id}">
- <text class="a">{{item.name}}</text>
- <text class="span iconfont" v-if="item.id == sort.id"></text>
- </view>
- </view>
- </view>
- <view class="scroll-view div" style="position:relative">
- <!-- 无限加载滚动列表 -->
- <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0position: absolute;" class="div flex-wrapper" :class="showstate?'goodslist':'goodsimg'" @scrolltolower="getMore" scroll-y="true">
- <view class="product-list">
- <view class="div ui-product-body"
- v-for='(item, index) in goodsList'
- v-bind:key='index'
- >
- <view class="div list" v-on:click='goDetail(item.goods_id)'>
- <view class="div ui-image-wrapper" v-if="showstate == false" :style="'width:'+windowWidth+'px;height:'+windowWidth+'px'">
- <image mode="aspectFit" class="img product-img" :src="item.goods_image_url">
- </view>
- <view class="div ui-image-wrapper" v-else>
- <image mode="aspectFit" class="img product-img" :src="item.goods_image_url">
- </view>
- <view class="div flex-right">
- <view class="div product-header">
- <text class="h3 title clear-bottom">{{ item.goods_name }}</text>
- </view>
- <view class="div goods_salenum">销量:{{ item.goods_salenum }}</view>
- <view class="div p-info">
- <view class="div p-price">
- ¥<text class="span price">{{ item.goods_price }}</text>
- </view>
- <text v-if="item.is_platform_store" class="span platform_store">自营</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="div loading-wrapper" v-if="goodsList.length > 0">
- <view class="p common-no-more" v-if='!isMore'>没有更多了</view>
- <uni-load-more status="loading" color='#e93b3d' v-if='isMore'></uni-load-more>
- </view>
- <empty-record v-if='goodsList.length <= 0 && !isMore'></empty-record>
- </scroll-view>
- </view>
- <view class="show-wrapper" :class="showstate?'showlist':'showimg'" @click='Changeshow()'></view>
- </view>
- <!--属性筛选Begin-->
- <uni-popup background-color="#fff" ref="showAttribute" type="right">
- <view :style="'width:'+(screenWidth*.8)+'px'" class="common-popup-wrapper">
- <view class="div filter-attribute">
- <view class="dl" v-if="attribute.brand_array.length!=0">
- <view class="dt">品牌</view>
- <view class="dd clearfix">
- <text class="a" v-for="(item, index) in attribute.brand_array" :key="index" :class="{'selected':params.b_id==item.brand_id}" @click="checkBrand(item)">{{item.brand_name}}</text>
- </view>
- </view>
- <view class="dl" v-for="(attr_info, attr_info_key, attr_info_index) in attribute.attr_array" :key="attr_info_key">
- <view class="dt">
- {{attr_info.name}}
- </view>
- <view class="dd clearfix">
- <text class="a" v-for="(item,index) in attr_info.value" :key="index" :class="{'selected':checked_attribute[attr_info_index]==item.attrvalue_id}" @click="checkAttribute(attr_info_index,item)">{{item.attrvalue_name}}</text>
- </view>
- </view>
- <view class="div common-btn ds-button-large mt-10" @click="confirmAttribute()">确定</view>
- <view class="div common-btn ds-button-large default mt-10" @click="cancelAttribute()">重置</view>
- </view>
- </view>
- </uni-popup>
- <!--属性筛选End-->
- </view>
- </view>
- </template>
- <script>
- import { urlencode,getFontSize } from '@/util/common'
- import EmptyRecord from '../../EmptyRecord'
- import { mapState } from 'vuex'
- import { searchGoodsList, getAttribute } from '../../../api/homesearch'
- export default {
- name: 'CommonGoodsList',
- props: [],
- components: {
- EmptyRecord
- },
- data(){
- return {
- query:{},
- screenWidth:0,
- sortkey: [
- {
- key: '',
- order: '',
- name: '综合排序',
- isMore: true,
- id: 0,
- child: [
- {
- key: '',
- order: '',
- name: '综合排序',
- isMore: false,
- id: 3
- },
- {
- key: 'goods_click',
- order: '',
- name: '人气最高',
- isMore: false,
- id: 4
- },
- {
- key: 'goods_price',
- order: '',
- name: '价格高到低',
- isMore: false,
- id: 5
- },
- {
- key: 'goods_price',
- order: 'asc',
- name: '价格低到高',
- isMore: false,
- id: 6
- }
- ]
- },
- {
- key: 'goods_salenum',
- order: '',
- name: '销量排序',
- isMore: false,
- id: 1
- },
- {
- key: 'goods_addtime',
- order: '',
- name: '新品',
- isMore: false,
- id: 2
- }
- ], // 排序数据
- showstate: false, //显示状态
- currentSortKey: {}, // 当前选中的排序
- childSort: [], // 综合筛选
- sort: {}, // 综合筛选子集
- isShowMore: false, // 是否显示筛选模态框
- params: {
- b_id: '',
- cate_id: '',
- a_id: '', // 规格属性
- is_exchange: 0,
- is_hot: 0,
- activity: null,
- sort_key: '', // 排序键
- sort_order: '', // 排序键, //排序值
- page: 0,
- keyword: '',
- xianshi: ''
- },
- // 当前商品分类所对应的属性
- attribute: {
- brand_array: [],
- attr_array: []
- },
- checked_attribute: [], // 当前已选择的属性对应的值
- goodsList: [], // 商品列表
- loading: false, // 是否加载更多
- isMore: true // 是否有更多
- }
- },
- computed: {
- windowWidth: function () {
- const res = uni.getSystemInfoSync()
- var width=res.windowWidth
- var size=getFontSize()
- return (width-3*.6*size)/2
- },
- },
- mounted(){
- var pages = getCurrentPages()
- var page = pages[pages.length - 1]
- this.query = page.options
- this.params.b_id=this.query.b_id ? this.query.b_id : ''
- this.params.cate_id=this.query.cate_id ? this.query.cate_id : ''
- this.params.a_id=this.query.a_id ? this.query.a_id : ''
- this.params.sort_key=this.query.sort_key ? this.query.sort_key : ''
- this.params.sort_order=this.query.sort_order ? this.query.sort_order : ''
- this.params.keyword=this.query.keywords ? this.query.keywords : ''
- this.params.xianshi=this.query.xianshi ? this.query.xianshi : ''
-
- this.screenWidth=uni.getSystemInfoSync().screenWidth
-
- this.currentSortKey = this.sortkey[0]
- this.childSort = this.currentSortKey.child
- this.sort = this.childSort[0]
- // 获取属性参数
- getAttribute(this.params).then(res => {
- this.attribute = res.result
- })
- this.getMore()
- },
- methods:{
- showPopup(id){
- this.$refs[id].open()
- },
- hidePopup(id){
- this.$refs[id].close()
- },
- // 品牌筛选
- checkBrand (item) {
- this.params.b_id = item.brand_id
- },
- // 属性筛选
- checkAttribute (index, item) {
- this.checked_attribute.splice(index, 1, item.attrvalue_id)
- this.params.a_id = this.checked_attribute.join('_')
- },
- confirmAttribute () {
- this.hidePopup('showAttribute')
- this.getGoodsList()
- },
- cancelAttribute () {
- this.checked_attribute = []
- this.params.a_id = ''
- this.params.b_id = ''
- },
- // closeFiler: 关闭下拉筛选模态框
- closeFiler () {
- this.isShowMore = false
- },
- // isShowDroupMenu: 点击显示下拉框, 并且显示模态框
- isShowDroupMenu () {
- let item = this.currentSortKey
- if (item.isMore) {
- this.isShowMore = true
- } else {
- this.isShowMore = false
- }
- },
- /**
- * setActiveSortkey: 点击切换数据并设置选中的样式
- * @param: item 当前选中的item
- */
- setActiveSortkey (item, index) {
- this.currentSortKey = item
- if (item.isMore) {
- this.isShowMore = !this.isShowMore
- } else {
- this.closeFiler()
- this.getValue()
- }
- },
- /**
- * getValue: 向父级组件发送改变列表事件, 并传递当前的sort_key, sort_order
- */
- getValue () {
- let data = this.getSortValue()
- let res = data
- this.params.page = 1
- this.goodsList = []
- this.loading = false
- this.isMore = true
- this.setParamsByData(res)
- this.getGoodsList()
- },
- /**
- * getSortValue: 获取排序值
- */
- getSortValue () {
- let sort = this.currentSortKey
- let value = { 'sort_key': '', 'sort_order': '' }
- if (sort.isMore) {
- value.sort_key = this.sort.key
- value.sort_order = this.sort.order
- } else {
- value.sort_key = sort.key
- value.sort_order = sort.order
- }
- return value
- },
- /**
- * getSortChild: 获取综合筛选的子集, 关闭父级的阴影模态框, 关闭子集, 获取列表数据
- * @param: item 模态框的item
- */
- getSortChild (item) {
- this.sort = item
- this.isShowMore = !this.isShowMore
- this.getValue()
- },
- /*
- * getMore: 无限滚动加载
- */
- getMore () {
- this.loading = true
- this.params.page = ++this.params.page
- if (this.isMore) {
- this.loading = false
- this.getGoodsList(true)
- }
- },
- /**
- * getGoodsList: 获取商品列表
- * @param: ispush ? true :false 是否需要向商品列表追加数据
- */
- getGoodsList (ispush) {
- searchGoodsList(
- this.params
- ).then(res => {
- this.buildData(ispush, res)
- })
- },
- /**
- * getList: 构建数据
- * @param: ispush 是否改变向元数据追加数据
- * @param: res 接口请求返回的数据
- */
- buildData (ispush, res) {
- if (res) {
- if (ispush) {
- this.goodsList = this.goodsList.concat(res.result.goods_list)
- } else {
- this.goodsList = res.result.goods_list
- }
- // for (var i=0;i< this.goodsList.length;i++) {
- // console.log("item",this.goodsList[i]);
- // }
- this.isMore = res.result.hasmore
- }
- },
- /**
- * 根据事件传递的值来对请求列表重新赋值
- * @param data 事件传递的参数
- */
- setParamsByData (data) {
- let params = this.params
- for (let item in params) {
- for (let list in data) {
- if (item === list) {
- params[item] = data[list]
- }
- }
- }
- return params
- },
- goDetail (goods_id) {
- uni.navigateTo({url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': goods_id } )})
- },
- //切换商品展示
- Changeshow(){
- if(this.showstate == false){
- this.showstate = true
- }else{
- this.showstate = false
- }
- }
- }
- }
- </script>
- <style lang='scss' scoped>
- .scroll-view-wrapper{display: flex;flex-direction: column;}
- .scroll-view{flex:1}
- .common-goods-list{}
- .ui-goodslist-filter {
- width: auto;
- padding-top:.5rem;
- background: #fff;
- .ul.filter-list{
- display: flex;
- width: auto;
- justify-content: space-around;
- align-content: center;
- align-items: center;
- border: 0;
- .li{
- font-size: $subFontSize;
- color: #333;
- border-bottom: .1rem solid transparent;
- position: relative;
- flex-basis: 4.54rem;
- text-align: center;
- height: 1.9rem;
- padding: 0;
- line-height: 1.9rem;
- .a {
- height: 1.9rem;
- display: inline-block;
- }
- .img {
- height: .18rem;
- width: .36rem;
- vertical-align: middle;
- }
- .iconfont{display: inline-block}
- }
- .li.sortactive {
- .a {
- color:$primaryColor;
- }
- .iconfont{color:$primaryColor;}
- .iconfont.active{transform: rotate(180deg);}
- }
- .li.sortnormal {
- border-bottom-color: transparent;
- .a {
- color: #333;
- }
- }
- .arrow-icon {
- width: .54rem;
- height: .54rem;
- }
- }
- .sort-model {
- position: absolute;
- left: 0;
- width: 100%;
- z-index: 10;
- .div {
- color: #333;
- padding: .68rem;
- font-size: $fontSize;
- background-color: #fff;
- margin: 0;
- border-bottom: .045rem solid #E8EAED;
- cursor: pointer;
- display: flex;
- width: auto;
- justify-content: space-between;
- align-content: center;
- align-items: center;
- .img {
- float: right;
- width: .7rem;
- height: .7rem;
- }
- &.active {
- color: $primaryColor;
- }
- }
- }
- }
- .goodslist-body{background: #fff}
- .flex-wrapper.goodslist{
- .product-list{
- padding-right: .6rem;
- .ui-product-body {
- .list {
- display: flex;
- width: auto;
- align-items: center;
- justify-content: space-between;
- margin: .5rem $pageSpace;
- position: relative;
- box-shadow: 0px 4px 4px #f7f7f7;
- .div.ui-image-wrapper {
- width: 6rem;
- height: 6rem;
- position: relative;
- display: flex;
- justify-content: center;
- align-content: center;
- align-items: center;
- flex-basis: 6rem;
- flex-shrink: 0;
- background-position:center center!important;
- background-size:4.54rem 4.54rem;
- background-repeat:no-repeat;
- -webkit-background-size: cover;
- -moz-background-size: cover;
- -o-background-size: cover;
- background-size: cover;
-
- .img.product-img{
- width: 6rem;
- height: 6rem;
- flex-basis: 6rem;
- flex-shrink: 0;
- border-radius: .4rem;
- }
- .img.product-img[lazy=loading] {
- width: 1.36rem;
- height: 1.36rem;
- }
- .img.product-im[lazy=error] {
- width: 1.36rem;
- height: 1.36rem;
- }
- .img.product-img[lazy=loaded] {
- width: 6rem;
- height: 6rem;
- flex-basis: 6rem;
- flex-shrink: 0;
- background:rgba(255,255,255,1);
- }
- .span {
- position: absolute;
- height:.9rem;
- background:rgba(243,244,245,1);
- line-height: .9rem;
- text-align: center;
- font-size:$fontSize;
- color:$primaryColor;
- width: 6rem;
- bottom: 0;
- left: 0;
- }
- }
- .flex-right {
- padding-left: .63rem;
- width: 100%;
- position:relative;
- .title {
- color: #333;
- font-size:$subFontSize;
- height:2rem;
- line-height:1rem;
- height:2rem;
- font-weight: normal;
- overflow: hidden;
- margin-bottom: .4rem;
- &.clear-bottom {
- margin-bottom: 0;
- }
- }
- .product-header {
- margin-bottom: .5rem;
- display: flex;
- align-items: center;
- }
- .p-price {
- color: $primaryColor;
- font-size:$fontSize;
- flex:1;
- .price{font-size:$mainFontSize}
- }
- .goods_salenum{font-size:$fontSize;color:$descTextColor;}
- .p-info {
- display: flex;
- align-items: center;
- margin-top:.5rem;
- .platform_store{font-size:$h6;color: #fff;background: $primaryColor;border-radius: .13rem;padding:.1rem .2rem;margin-right: .5rem;}
- }
- }
- }
- }
- }
- }
-
- .flex-wrapper.goodsimg{
- .product-list{
- display: flex;
- flex-wrap: wrap;
- padding-right: .6rem;
- .ui-product-body{
- flex-direction: column;
- justify-content: flex-end;
- width:50%;box-sizing:border-box;
- .list{
- box-shadow: 0px 2px 4px #ececec;
- margin-left:$pageSpace;
- margin-bottom:.5rem;
- border-radius:.4rem;
- .ui-image-wrapper{
- .product-img{
- align-self: center;
- width:100%;
- box-sizing:border-box;
- border-radius:.4rem;
- }
- }
- .flex-right{
- padding:0 .3rem;
- .product-header{
- color: $formInputColor;
- font-size: $subFontSize;
- line-height:.8rem;
- height:1.6rem;
- margin-top: 0.4rem;
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- }
- .goods_salenum{
- color: #A2A6AD;
- font-size: 0.6rem;
- margin: .2rem 0;
- }
- .p-info{
- display: flex;
- justify-content: space-between;
- padding-bottom:.5rem;
- .p-price{
- color: $primaryColor;
- font-size:$fontSize;
- .price{
- font-size:$mainFontSize
- }
- }
- .platform_store{
- font-size: 0.5rem;
- color: #fff;
- background: #FB2630;
- border-radius: 0.13rem;
- padding: 0.1rem 0.2rem;
- margin-right: 0.5rem;
- }
- }
- }
- }
- }
- }
-
- }
-
- .filter-attribute{padding:0.5rem;height: 100%;overflow: hidden;overflow-y: scroll}
- .filter-attribute .dl{width:100%;}
- .filter-attribute .dt{height:1.2rem;width:100%;overflow: hidden;font-size:$h2;color: #333;}
- .filter-attribute .dd{}
- .filter-attribute .dd .a{position: relative;display:inline-block;color: #666;font-size:$fontSize;text-align:center;background-color: #f7f7f7;border-radius:0.2rem;height:1.5rem;line-height:1.5rem;margin:0.5rem 1.5%;width:30%;}
- .filter-attribute .dd .a.selected{color: $primaryColor;background-color: #fdf0f0;}
- .filter-attribute .dd .a.selected::after{content: "";position: absolute;right: 0;bottom: 0;width: 15px;height: 15px;border-radius: 0 0 2px 0;background: url("../../../static/image/home/attribute_selected.png") no-repeat;background-size: 15px auto;overflow: hidden;z-index: 1;}
- .loading-wrapper{text-align: center}
- .show-wrapper{
- position: fixed;
- right: 10px;
- bottom: 100px;
- z-index: 101;
- width: 1.6rem;
- height: 1.6rem;
- background: #000;
- line-height: 1.6rem;
- background: hsla(0,0%,100%,.9) no-repeat 50%;
- border: 1px solid #ccc;
- border-radius: 50%;
- overflow: hidden;
- clear: both;
- }
- .showimg{
- background-image: url("../../../static/image/home/row.png");
- background-size: 16px;
- }
- .showlist{
- background-image: url("../../../static/image/home/square.png");
- background-size: 16px;
- }
- </style>
|