filtrate.vue 5.95 KB
<template>
  <div class="container" v-if="showType">
    <div class="header">
      <div class="back" @click="hide()"></div>
    </div>
    <div class="title">筛选</div>
    <div class="content">
      <div class="item" v-for="(filter,row) in filterData">
        <div class="item-title">{{filter.filterName}}</div>
        <div v-if="filter.itemList && filter.itemList.length" class="item-list">
          <div class="item-img-content" v-if="filter.filterId === 'brand'"
               :class="filterParams.brand.includes(item.itemId) && 'item-img-selected'"
               v-for="(item,i) in filter.itemList" :style="i===0 && 'margin-left:1rem'"
               @click="select({filterId:filter.filterId, itemId:item.itemId, row})">
            <ImgSize class="item-img" :src="item.itemUrl" :width="140" :height="70"/>
            <div class="item-img-text">{{item.itemName}}</div>
          </div>
          <div class="item-text item-size" v-if="filter.filterId === 'size'" :style="i===0 && 'margin-left:1rem'"
               :class="filterParams.size.includes(item.itemId) && 'item-text-selected'"
               v-for="(item,i) in filter.itemList" @click="select({filterId:filter.filterId, itemId:item.itemId, row})">{{item.itemName}}</div>
          <div class="item-text" v-if="filter.filterId === 'sort' || filter.filterId === 'gender'" :style="i===0 && 'margin-left:1rem'"
               :class="(filterParams.sort.includes(item.itemId) || filterParams.gender.includes(item.itemId)) && 'item-text-selected'"
               v-for="(item,i) in filter.itemList" @click="select({filterId:filter.filterId, itemId:item.itemId, row})">{{item.itemName}}</div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div class="clear" @click="clear()">清除</div>
      <div class="submit" @click="submit()">确定</div>
    </div>
  </div>
</template>
<script>
import {createNamespacedHelpers} from 'vuex';

const {mapState, mapActions} = createNamespacedHelpers('list');

import ImgSize from '../../components/img-size';

export default {
  name: 'Filtrate',
  components: {ImgSize},
  data() {
    return {
      showType: false
    };
  },
  mounted() {
  },
  methods: {
    ...mapActions(['setFilterParam','fetchProductList']),
    clear() {
      this.setFilterParam({
        sort: [], // 品类id
        brand: [], // 品牌id
        gender: [], // 性别
        size: [], // 尺码id
      });
    },
    submit() {
      let params = {
        sort: this.filterParams.sort.join(','),
        brand: this.filterParams.brand.join(','), // 品牌id
        gender: this.filterParams.gender.join(','), // 性别
        size: this.filterParams.size.join(','), // 尺码id
      };

      this.filterData.length > 0 && this.filterData.map(row => {
        if (row.itemList && row.itemList.length === 1) {
          params[row.filterId] = row.itemList[0].itemId;
        }
      });
      params.isReset = true;
      this.fetchProductList(params);
      this.hide();
    },
    select({filterId, itemId, row}) {
      let optParams = {...this.filterParams};
      let filterItemArray = optParams[filterId];

      if (filterItemArray.includes(itemId)) {
        filterItemArray = filterItemArray.filter(item => item !== itemId);
      } else {
        if (this.filterData[row].multiSelect) {
          filterItemArray.push(itemId);
        } else {
          filterItemArray = [itemId];
        }
      }
      optParams[filterId] = filterItemArray;
      this.setFilterParam(optParams);
    },
    show() {
      this.showType = true;
    },
    hide() {
      this.showType = false;
    }
  },
  computed: {
    ...mapState(['filterParams', 'filterData']),
  },
};
</script>
<style scoped>
  .header {
    width: 100%;
    height: 45PX;
    padding-left: 20PX;
    padding-right: 20PX;
    background-color: #fff;
    display: flex;
    align-items: stretch;
    box-sizing: border-box;
  }

  .container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 999;
  }

  .title {
    font-size: 68px;
    font-weight: bold;
    color: #000;
    height: 82px;
    line-height: 82px;
    margin-bottom: 50px;
    margin-left: 40px;
  }

  .content {
  }

  .bottom {
    height: 120px;
    position: fixed;
    bottom: 0;
    z-index: 9;
    width: 100%;
  }

  .clear {
    line-height: 120px;
    text-align: center;
    width: 240px;
    height: 120px;
    color: #000;
    font-size: 28px;
    font-weight: bold;
    float: left;
    border-top: 1px solid;
  }

  .submit {
    line-height: 120px;
    margin-left: 240px;
    background-color: #08304B;
    text-align: center;
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    height: 120px;
  }

  .item {
    margin-bottom: 60px;
  }

  .item-title {
    margin-left: 40px;
    margin-bottom: 20px;
    font-size: 40px;
    color: #000;
    letter-spacing: 0;
    font-weight: 500;
  }

  .item-list {
    overflow-y: hidden;
    overflow-x: scroll;
    display: -webkit-box;
    width: 100%;
  }

  .item-list ::-webkit-scrollbar {
    display: none;
  }

  .item-text {
    background: #F5F5F5;
    font-size: 28px;
    color: #222;
    text-align: center;
    width: 200px;
    height: 80px;
    line-height: 80px;
    margin-right: 20px;
  }

  .item-text-selected {
    background: #08304B;
    color: #fff;
  }

  .item-size {
    width: 100px;
    height: 100px;
    line-height: 100px;
  }

  .item-img {
    width: 140px;
    height: 70px;
    margin-bottom: 22px;
  }

  .item-img-selected {
    opacity: 1 !important;
  }

  .item-img-content {
    opacity: 0.2;
    width: 160px;
    height: 140px;
    display: flex;
    justify-content: center;
    flex-direction: column;
    margin-right: 20px;
  }

  .item-img-text {
    font-size: 20px;
    color: #000;
    letter-spacing: 0;
    text-align: center;
    width: 140px;
    height: 64px;
  }

  .back {
    margin-top: 24px;
    width: 24PX;
    height: 24PX;
    background: url(~statics/image/order/back@3x.png) no-repeat;
    background-size: cover;
  }

</style>