GateSelect.vue 3.92 KB
<template>
  <div class="component-gate-wrapper">
    <span class="condition-label" v-show="showLabel">{{ $t('asisTab.inOutLev') }}</span>
    <el-select>
      <!--  -->
    </el-select>
    <span>-</span>
    
  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
export default {
  name: 'ZoneSelect',
  props: {
    isMulti: {
      type: Boolean,
      default: false
    },
    filterable: {
      type: Boolean,
      default: true
    },
    isCollapse: {
      type: Boolean,
      default: true
    },
    isNeedSelectedAll: {
      type: Boolean,
      default: true
    },
    showLabel: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    ...mapGetters(['zoneList']),
    ...mapState({
      accountVal: state => state.app.accountVal,
      cacheConditions: state => state.app.cacheConditions,
      mallVal: state => state.app.mallVal,
      multiMallVal: state => state.app.multiMallVal,
      floorVal: state => state.app.floorVal
    }),
    zoneVal: {
      get() {
        return this.$store.state.app.zoneVal
      },
      set(val) {
        this.$store.commit('app/SET_FLOOR_VAL', val)
      }
    },
    multiZoneVal: {
      get() {
        let storeVal = this.$store.state.app.multiZoneVal
        this.isZoneSelAll = this.zoneList.length && storeVal.length === this.zoneList.length
        return storeVal
      },
      set(val) {
        this.$store.commit('app/SET_MULTI_FLOOR_VAL', val)
      }
    },
  },
  data() {
    return {
      isGateSelAll: false
    }
  },
  watch: {
    mallVal(nVal, oVal) {
      if (nVal) {
        this.storeGate('update')
      }
    },
    floorVal(nVal, oVal) {
      if (nVal) {
        this.storeGate('update')
      }
    },
    multiZoneVal(nVal, oVal) {
      this.isGateSelAll = this.gateList.length && nVal.length === this.gateList.length
    }
  },
  mounted() {
    // if (!this.floorVal || !this.multiZoneVal.length) {
    this.storeGate('update')
    // }
  },
  methods: {
    async storeGate(status) {
      if (!this.gateList.length || status === 'update') {
        // await this.$store.dispatch('app/getGates', {
        //   accountId: this.accountVal.id,
        //   mallId: this.cacheConditions && this.cacheConditions['singleMall'] || this.mallVal,
        //   floorId: this.cacheConditions && this.cacheConditions['singleFloor'] || this.floorVal || null,
        //   status: 1,
        //   sortName: '"floor".name, "zone".name'
        // })
      }

      // if (this.cacheConditions) {
      //   // 单选
      //   if(this.cacheConditions['singleZone']) {
      //     this.$store.commit('app/SET_ZONE_VAL', this.cacheConditions['singleZone'])
      //   }
      //   // 多选
      //   if (this.cacheConditions['multiZone']) {
      //     this.$store.commit('app/SET_MULTI_ZONE_VAL', this.cacheConditions['multiZone'])
      //   }
      // } else {
      //   this.$store.commit('app/SET_CACHE_VAL', { key: 'singleZone', val: this.zoneVal })
      //   this.$store.commit('app/SET_CACHE_VAL', { key: 'multiZone', val: this.multiZoneVal })
      // }
    },
    multiZoneChangeHandle() {
      this.isZoneSelAll = this.checkedAllHandle(this.multiZoneVal, this.zoneList);
    },
    checkedAllHandle(valArr, data) {
      return valArr.length === data.length
    },
    selAllHandle() {
      if(this.isZoneSelAll) {
        this.isZoneSelAll = false
        if(this.multiZoneVal.length == this.zoneList.length) {
          this.multiZoneVal = []
        }
      } else {
        this.isZoneSelAll = true
        if(this.multiZoneVal.length == this.zoneList.length) {
          this.multiZoneVal = []
        } else {
          this.multiZoneVal = []
          this.zoneList.forEach(item => {
            this.multiZoneVal.push(item.id)
          })
        }
      }
    },
  }
}
</script>

<style scoped>
.component-gate-wrapper {
  display: inline-block;
}
.condition-label {
  padding-right: 10px;
  color: #666;
  font-size: 13px;
}
.pl-5 {
  padding-left: 5px;
}
</style>