filtrate.vue 9.35 KB
<template>
  <div class="container" v-show="showType">
    <div class="content-search">
      <div class="item" v-if="filterData && filterData.length" 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})">
            <div class="item-img" >
              <img  :src="(item.itemUrl || '').replace('http://', '//').replace('{width}', 280).replace('{height}', 140)" />
            </div>
            <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 {mapState, createNamespacedHelpers} from 'vuex';

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

import ImgSize from '../../components/img-size';
import {Scroll} from 'cube-ui';

export default {
  name: 'Filtrate',
  components: {ImgSize, Scroll},
  props: {
    yasParams: Object,
  },
  data() {
    return {
      showType: false,
      filterParams: {
        sort: [], // 品类id
        brand: [], // 品牌id
        gender: [], // 性别
        size: [], // 尺码id
      },
      filterData: [],
    };
  },
  activated() {
    let params = {...this.$route.query};

    // if (this.yoho.direction === 'forword') {
      Object.assign(this.$data, this.$options.data());
      !params.order && (params.order = 'sale_desc');
      this.fetchData(params);
    // }
  },

  computed: {
    ...mapState(['yoho'])
  },

  methods: {
    ...mapActions(['fetchFilterData']),
    clear() {
      let filterParams = {
        sort: [], // 品类id
        brand: [], // 品牌id
        gender: [], // 性别
        size: [], // 尺码id
      };

      for (let item of this.filterData) {
        if (item.itemList && item.itemList.length === 1) {
          filterParams[item.filterId].push(item.itemList[0].itemId);
        }
      }
      this.setFilterParam(filterParams);
    },

    fetchData: async function(params) {
      let filterData = await this.fetchFilterData(params);
      let filterParams = this.filterParams;

      for (let item of filterData) {
        if (item.itemList && item.itemList.length === 1) {
          filterParams[item.filterId].push(item.itemList[0].itemId);
        }
      }
      this.filterData = filterData;
      this.filterParams = filterParams;
    },

    submit() {
      let routeParams = this.$route.query;

      let params = {
        sort: this.filterParams.sort.join(',') || routeParams.sort,
        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;
        }
      });

      let ENT_PARAMS = {}, ENT_ID = [], ENT_NAME = [];

      for (let key in params) {
        if (key === 'sort' && params[key]) {
          ENT_PARAMS.category = params[key];
          ENT_ID.push(params[key]);
          ENT_NAME.push('品类');
        }
        if (key === 'brand' && params[key]) {
          ENT_PARAMS.brand = params[key];
          ENT_ID.push(params[key]);
          ENT_NAME.push('品牌');
        }
        if (key === 'size' && params[key]) {
          ENT_PARAMS.size = params[key];
          ENT_ID.push(params[key]);
          ENT_NAME.push('尺寸');
        }
        if (key === 'gender' && params[key]) {
          ENT_PARAMS.sex = params[key];
          ENT_ID.push(params[key]);
          ENT_NAME.push('性别');
        }
      }
      this.yasParams.ENT_PARAMS = JSON.stringify(ENT_PARAMS);
      this.yasParams.ENT_ID = ENT_ID.toString();
      this.yasParams.ENT_NAME = ENT_NAME.toString();

      params.isReset = true;
      this.yas(this.yasParams);
      this.$parent.fetchList(params);
      this.$parent.$refs.scroll.scrollTo(0, 0, 300);
      this.hide();
    },

    getParams() {
      return this.filterParams;
    },

    select({filterId, itemId, row}) {
      let optParams = this.filterParams;
      let filterItemArray = optParams[filterId];
      let rowData = this.filterData[row];

      if (rowData && rowData.itemList && rowData.itemList.length === 1) {
        return;
      }

      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);
    },

    setFilterParam(filter) {
      let filterParams = this.filterParams;

      if (typeof filter === 'object' && Object.keys(filter).length) {
        for (let key in filter) {
          filterParams[key] = filter[key];
        }
        this.filterParams = filterParams;
      }
    },

    show() {
      this.showType = true;
    },
    hide() {
      this.showType = false;
    },
    yas(param) {
      this.$store.dispatch('reportYas', {
        params: {
          param,
          appop: 'XY_UFO_PRD_LIST_SCREEN_C'
        }
      });
    }
  }
};
</script>
<style lang="scss" 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: 40px;
    flex-direction: row;
    display: flex;
    justify-content: space-between;

    .cancel {
      font-size: 36px;
      color: #888;
    }
  }

  .content-search {
    margin-top: 80px;

    .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;
      border-radius: 40px;
    }

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

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

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

      & > img {
        width: 100%;
        height: 100%;
      }
    }

    .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;
    }
  }

  .bottom {
    height: 120px;
    position: fixed;
    bottom: 0;
    z-index: 9;
    width: 100%;
    background: #fff;
    display: flex;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    justify-content: space-between;
    align-items: center;
  }

  .clear {
    margin-left: 32px;
    line-height: 80px;
    text-align: center;
    width: 330px;
    height: 80px;
    color: #000;
    font-size: 32px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 40px;
  }

  .submit {
    line-height: 80px;
    background-color: #08304B;
    width: 330px;
    height: 80px;
    text-align: center;
    color: #fff;
    font-size: 32px;
    border-radius: 40px;
    margin-right: 32px;
  }

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

</style>