<template>
  <div class="AppGridManagement">
    <component v-if="refresh" :is="component" @change="onChange" :params="params"> </component>
    <div class="tabs" v-if="isTab">
      <div class="item" @click="tabClick(index, item.component)" v-for="(item, index) in tabs" :key="index">
        <img :src="tabIndex == index ? item.activeImg : item.img" alt="" />
        <p :class="tabIndex == index ? 'color-3267F0' : ''">{{ item.text }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import Statistics from './Statistics.vue'
import Organization from './Organization.vue'
import Map from './Map.vue'

export default {
  name: 'AppGridManagement',
  appName: '网格管理',

  data() {
    return {
      component: 'Organization',
      params: {},
      refresh: true,
      tabIndex: 0,
      tabs: [
        {
          img: require('./components/img/handle-icon.png'),
          activeImg: require('./components/img/handle-icon-active.png'),
          text: '统计',
          component: 'Statistics',
        },
        {
          img: require('./components/img/statistics-icon.png'),
          activeImg: require('./components/img/statistics-icon-active.png'),
          text: '组织',
          component: 'Organization',
        },
        {
          img: require('./components/img/set-icon.png'),
          activeImg: require('./components/img/set-icon-active.png'),
          text: '地图',
          component: 'Map'
        }
      ],
      isTab: true,
    }
  },

  components: {
    Organization,
    Statistics,
    Map,
  },

  methods: {
    onChange(e) {
      this.params = e.params
      this.component = e.type
    },
    tabClick(index, component) {
      this.tabIndex = index
      this.component = component
      this.refresh = false
      this.$nextTick(() => {
        this.refresh = true
      })
    },
  },
  onShow() {
    document.title = '网格管理'
    uni.$on('hideTab', () => {
      this.isTab = false
    })
    uni.$on('showTab', () => {
      this.isTab = true
    })
  },
  onReachBottom() {
    if(!this.tabIndex) {
      uni.$emit('nextList')
    }
  },
}
</script>

<style lang="scss" scoped>
.AppGridManagement {
  height: 100%;
}
.tabs {
  width: 100%;
  height: 98px;
  background: #fff;
  border-top: 1px solid #ddd;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  .item {
    flex: 1;
    text-align: center;
    img {
      width: 56px;
      height: 56px;
      margin-top: 8px;
    }
    p {
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #c4cad4;
      line-height: 8px;
    }
    .color-3267F0 {
      color: #3267f0;
    }
  }
}
</style>
