Authored by 李奇

商品列表筛选组件修改

@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 22
23 .product-item .item-price .price2 { 23 .product-item .item-price .price2 {
24 color: #444; 24 color: #444;
  25 + margin-left: 10rpx;
25 text-decoration: line-through; 26 text-decoration: line-through;
26 } 27 }
27 28
@@ -4,5 +4,65 @@ Component({ @@ -4,5 +4,65 @@ Component({
4 type: Object, 4 type: Object,
5 value: {} 5 value: {}
6 } 6 }
  7 + },
  8 + data: {
  9 + curSortType: 'def',
  10 + curSortField: '',
  11 + curGender: '',
  12 + showSubGender: false,
  13 + subFilterText: '筛选'
  14 + },
  15 + methods: {
  16 + sortChange: function ({target}) {
  17 + const sort = target.dataset.sort;
  18 +
  19 + const setSort = field => {
  20 + if (sort === this.data.curSortType && sort !== 'price') {
  21 + return;
  22 + }
  23 + this.setData({
  24 + curSortType: sort,
  25 + curSortField: field,
  26 + showSubGender: false
  27 + });
  28 + this.triggerEvent('sortchange', {curSort: field, gender: this.data.curGender})
  29 + };
  30 +
  31 + switch (sort) {
  32 + case 'def':
  33 + setSort('');
  34 + break;
  35 + case 'time':
  36 + setSort('s_t_desc');
  37 + break;
  38 + case 'popular':
  39 + setSort('s_n_asc');
  40 + break;
  41 + case 'price':
  42 + setSort(this.data.curSortField === 's_p_asc' ? 's_p_desc' : 's_p_asc');
  43 + break;
  44 + default:
  45 + break;
  46 + }
  47 +
  48 + },
  49 + subFilterGenderTap: function (e) {
  50 + this.setData({
  51 + showSubGender: !this.data.showSubGender
  52 + });
  53 + },
  54 + selectGenderTap: function (e) {
  55 + const gender = e.target.dataset.gender;
  56 +
  57 + if (gender) {
  58 + this.setData({
  59 + curGender: gender,
  60 + showSubGender: false,
  61 + subFilterText: gender === '1,3' ? '男生' : '女生'
  62 + });
  63 + }
  64 +
  65 + this.triggerEvent('sortchange', {curSort: this.data.curSortField, gender})
  66 + }
7 } 67 }
8 }); 68 });
1 <view class="product-list-filter"> 1 <view class="product-list-filter">
2 - <ul class="filter-items">  
3 - <li class="item active">默认</li>  
4 - <li class="item">新品</li>  
5 - <li class="item">人气</li>  
6 - <li class="item">价格</li>  
7 - <li class="item">筛选</li> 2 + <ul class="filter-items" bindtap="sortChange">
  3 + <li class="item {{curSortType == 'def' ? 'active' : ''}}" data-sort="def">默认</li>
  4 + <li class="item {{curSortType == 'time' ? 'active' : ''}}" data-sort="time">新品</li>
  5 + <li class="item {{curSortType == 'popular' ? 'active' : ''}}" data-sort="popular">人气</li>
  6 + <li class="item {{curSortType == 'price' ? 'active' : ''}}" data-sort="price">价格</li>
  7 + <li class="item {{curGender ? 'active' : ''}}" catchtap="subFilterGenderTap">{{subFilterText}}</li>
8 </ul> 8 </ul>
  9 + <view wx:if="{{showSubGender}}" class="sub-gender" bindtap="selectGenderTap">
  10 + <view class="gender-item {{curGender == '1,3' ? 'active' : ''}}" data-gender="1,3">男生/BOYS</view>
  11 + <view class="gender-item {{curGender == '2,3' ? 'active' : ''}}" data-gender="2,3">女生/GIRLS</view>
  12 + </view>
9 </view> 13 </view>
1 .product-list-filter { 1 .product-list-filter {
  2 + position: relative;
2 font-size: 0; 3 font-size: 0;
3 height: 88rpx; 4 height: 88rpx;
4 line-height: 88rpx; 5 line-height: 88rpx;
@@ -9,6 +10,7 @@ @@ -9,6 +10,7 @@
9 } 10 }
10 11
11 .product-list-filter .item { 12 .product-list-filter .item {
  13 + position: relative;
12 flex: 1; 14 flex: 1;
13 font-family: PingFang-SC-Regular; 15 font-family: PingFang-SC-Regular;
14 text-align: center; 16 text-align: center;
@@ -17,6 +19,57 @@ @@ -17,6 +19,57 @@
17 letter-spacing: 0.33px; 19 letter-spacing: 0.33px;
18 } 20 }
19 21
  22 +.product-list-filter .item:after {
  23 + display: inline-block;
  24 + content: '';
  25 + height: 50rpx;
  26 + width: 1rpx;
  27 + position: absolute;
  28 + top: 19rpx;
  29 + right: 0;
  30 + background-color: #eee;
  31 + transform: scaleX(0.5);
  32 +}
  33 +
  34 +.product-list-filter .item:last-child:after {
  35 + display: inline-block;
  36 + content: '';
  37 + height: 0;
  38 + width: 0;
  39 +}
  40 +
20 .product-list-filter .item.active { 41 .product-list-filter .item.active {
21 color: #444; 42 color: #444;
22 } 43 }
  44 +
  45 +.product-list-filter .sub-gender {
  46 + position: absolute;
  47 + top: 88rpx;
  48 + left: 0;
  49 + right: 0;
  50 + font-size: 28rpx;
  51 + background-color: #fff;
  52 + text-align: center;
  53 +}
  54 +
  55 +.product-list-filter .sub-gender .gender-item {
  56 + height: 90rpx;
  57 + color: #b0b0b0;
  58 + position: relative;
  59 +}
  60 +
  61 +.product-list-filter .sub-gender .gender-item.active {
  62 + color: #444;
  63 +}
  64 +
  65 +.product-list-filter .sub-gender .gender-item:after {
  66 + display: inline-block;
  67 + content: '';
  68 + height: 1rpx;
  69 + position: absolute;
  70 + bottom: 0;
  71 + left: 0;
  72 + right: 0;
  73 + background-color: #eee;
  74 + transform: scaleY(0.5);
  75 +}
@@ -237,5 +237,8 @@ Page({ @@ -237,5 +237,8 @@ Page({
237 // wx.navigateTo({ 237 // wx.navigateTo({
238 // url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + '' 238 // url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + ''
239 // }); 239 // });
  240 + },
  241 + sortChange: function (e) {
  242 + console.log(e.detail);
240 } 243 }
241 }); 244 });
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <view class="recommend-product"> 11 <view class="recommend-product">
12 <view-title title="推荐商品" height="88"></view-title> 12 <view-title title="推荐商品" height="88"></view-title>
13 <view class="filter"> 13 <view class="filter">
14 - <product-list-filter></product-list-filter> 14 + <product-list-filter bind:sortchange="sortChange"></product-list-filter>
15 </view> 15 </view>
16 <view class="list"><product-list></product-list></view> 16 <view class="list"><product-list></product-list></view>
17 </view> 17 </view>