<template>
  <div class="AppPatrolReport">
    <u-navbar back-icon-color="#000" title="事件上报" title-color="#000" title-width="300" title-size="32" 
      :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44"></u-navbar>
    <div class="header-content-bg">
      <img src="https://cdn.sinoecare.com/i/2024/07/12/6690a1303d423.png" alt="">
    </div>
    <!-- <component v-if="refresh && isGridMember" :is="component" @change="onChange" :params="params" :ref="component"/> -->
    <div class="footer-tabs" v-if="isTab && isGridMember">
      <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 v-if="!isGridMember" class="empty">
      <img src="https://cdn.sinoecare.com/i/2024/07/18/66987e8c5b56b.png" alt="">
      <p>没有网格员权限<br/>无法查看事件上报信息哦~</p>
    </div>
    <List v-if="refresh && isGridMember && component == 'List' " @change="onChange" :params="params" ref="List"  />
    <Statistics v-if="refresh && isGridMember && component == 'Statistics' " @change="onChange" :params="params" ref="Statistics" />
  </div>
</template>

<script>
import List from './List.vue'
import Statistics from './Statistics.vue'
import {mapState} from 'vuex'

export default {
  name: 'AppPatrolReport',
  appName: '事件上报',
  customNavigation: true,
  data() {
    return {
      component: 'List',
      params: {},
      refresh: true,
      tabIndex: 0,
      tabs: [
        {
          img: 'https://cdn.sinoecare.com/i/2024/07/17/6697387277fa3.png',
          activeImg: 'https://cdn.sinoecare.com/i/2024/07/17/66973872e46ed.png',
          text: '办理',
          component: 'List',
        },
        {
          img: 'https://cdn.sinoecare.com/i/2024/07/17/669738737266b.png',
          activeImg: 'https://cdn.sinoecare.com/i/2024/07/17/66973873df9b6.png',
          text: '统计',
          component: 'Statistics',
        },
      ],
      isTab: true,
      backgroundNavbar: {
        background: 'url(https://cdn.sinoecare.com/i/2024/07/12/6690a1309c7d3.png) no-repeat',
        backgroundSize: 'cover',
      },
    }
  },
  computed: {
    ...mapState(['user']),
    isGridMember() {
      return this.user.girdInfos2G != null
    }
  },
  components: {
    List,
    Statistics,
  },

  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
      })
    }
  },
  onLoad() {
    uni.$on('hideTab', () => {
      this.isTab = false
    })
    uni.$on('showTab', () => {
      this.isTab = true
    })
    // if (!this.tabIndex) {
    //   this.$nextTick(() => this.$refs['List'].getListInit())
    // }
  },
  onReachBottom() {
    // if (!this.tabIndex) {
    //   this.$nextTick(() => this.$refs['List'].nextPage())
    // }
  },
}
</script>

<style lang="scss" scoped>
uni-page-body {
  height: 100%;
  background: #F4F5FA;
}
.AppPatrolReport {
  height: 100%;
}

.header-content-bg {
  width: 100%;
  position: fixed;
  z-index: -1;
  img {
    width: 100%;
    height: 592px;
  }
}

.footer-tabs {
  width: 100%;
  height: 100px;
  padding-bottom: 68px;
  background: #fff;
  border-top: 1px solid #ddd;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 9;
  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;
    }
  }
}

.empty {
  text-align: center;

  img {
    width: 282px;
    height: 306px;
    margin: 136px auto 0;
  }

  p {
    font-size: 28px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #999;
    line-height: 40px;
  }
}
</style>
