filtrate-list.vue 3.09 KB
<template>
  <div class="list-component" v-show="showType">
    <div class="list-bg">
        <div class="list-item" v-if="list.length" v-for="(item, index) in list" :key="index">
          <div class="item" @click="clickItem(item.itemId, item.itemName)">
            <span :class="selectParams.id.includes(item.itemId) ? 'active-span' : '' ">{{item.itemName}}</span>
            <div v-if="selectParams.id.includes(item.itemId)" class="select-class"></div>
          </div>
        </div>
    </div>
    <div class="list-bottom">
      <div class="bottom-btn clear" @click="clear">重置</div>
      <div class="bottom-btn submit" @click="submit">确定</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showType: false,
      selectParams: {
        id: [],
        name: []
      }
    }
  },
  props: {
    list: Array,
  },
  methods: {
    show() {
      this.showType = true;
    },
    hide() {
      this.showType = false;
    },
    setFilterList(params) {
      this.selectParams.id = params.id || [];
      this.selectParams.name = params.name || [];
    },
    submit() {
      this.$parent.updateFilterParams(this.selectParams);
      this.hide();
    },
    clear() {
      let params = {
        id: [],
        name: []
      };
      this.selectParams = params;
    },
    clickItem(itemId, itemName) {
      let idArray = [].concat(this.selectParams.id);
      let nameArray = [].concat(this.selectParams.name);

      if (idArray.includes(itemId)) {
        idArray = idArray.filter(item => item !== itemId);
        nameArray = nameArray.filter(item => item !== itemName);
      } else {
        idArray.push(itemId);
        nameArray.push(itemName);
      }

      this.selectParams.id = idArray;
      this.selectParams.name = nameArray;
    }
  }
}
</script>

<style lang="scss" scoped>
.list-component {
  position: fixed;
  bottom: 0;
  left: 0;
  top: 186px;
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9;
}

.list-bg {
  display: flex;
  flex-wrap: wrap;
  background: #ffffff;
  max-height: 480px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.list-item {
  width: 50%;
  padding: 0 40px;
  height: 80px;
  border-style: none;
  overflow: hidden;
}

.item {
  display: flex;
  flex-direction: row;
  align-items: center;

  span {
    font-size: 24px;
    color: #999;
    line-height: 80px;
    letter-spacing: 0;
    text-align: left;
    margin-left: 20px;
  }

  .active-span {
    color: #000;
  }
}

.select-class {
  margin-left: 16px;
  width: 24px;
  height: 24px;;
  background: url(~statics/image/list/selected@3x.png) no-repeat;
  background-size: contain;
}

.list-bottom {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 16px 34px;
  background: #fff;
}

.bottom-btn {
  height: 80px;
  width: calc((100% - 24px)/2);
  line-height: 80px;
  text-align: center;
  font-size: 32px;
  border-radius: 40px;
}

.clear {
  color: #333;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.12);
}

.submit {
  margin-left: 24px;
  font-weight: bold;
  color: #fff;
  background: #002B47;
}

</style>