filtrate-list.vue 3.87 KB
<template>
  <div>
    <div class="list-component" v-show="showType" @click="hideClick" @touchmove.prevent>
    </div>

    <div class="container" v-show="showType">
      <div class="list-bg" @touchmove.prevent>
        <Scroll class="scroll-wrapper" ref="scroll">
          <div class="list-item" v-if="list.length" v-for="(item, index) in list" :key="index">
            <div class="item" @click="(e)=> clickItem(e, 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>
        </Scroll>
      </div>

      <div class="list-bottom">
        <div class="bottom-btn clear" @click="(e)=>clear(e)">重置</div>
        <div class="bottom-btn submit" @click="(e)=>submit(e)">确定</div>
      </div>

    </div>
  </div>
</template>

<script>
import { Scroll } from 'cube-ui';
export default {
  components: {
    Scroll,
  },
  data() {
    return {
      showType: false,
      selectParams: {
        id: [],
        name: []
      }
    }
  },
  props: {
    list: Array,
  },
  methods: {
    show() {
      this.showType = true;
      this.$nextTick(()=>{
        this.$refs.scroll.refresh();
      })
    },
    hide() {
      this.showType = false;
    },
    hideClick() {
      this.$parent.updateFilterParams({});
      this.hide();
    },
    setFilterList(params) {
      this.selectParams.id = params.id || [];
      this.selectParams.name = params.name || [];
    },
    submit(event) {
      event.stopPropagation();
      this.$parent.updateFilterParams(this.selectParams);
      this.hide();
    },
    clear(event) {
      event.stopPropagation();
      let params = {
        id: [],
        name: []
      };
      this.selectParams = params;
    },
    clickItem(event, itemId, itemName) {
      event.stopPropagation();
      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: absolute;
  bottom: 0;
  left: 0;
  top: 186px;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9;
}

.container {
  position: absolute;
  left: 0;
  top: 186px;
  width: 100%;
  z-index: 99;
}

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

.scroll-wrapper {
  width: 100%;
  max-height: 480px;
  flex-direction: row;
}

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

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

  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>