<template>
  <transition name="slide">
    <div class="index-container">
      <!--标题-->
      <mt-header class="header" title="工单管理" fixed>
      </mt-header>
      <!--列表主体-->
      <div class="listbody">
        <mt-navbar v-model="selected" fixed>
          <mt-tab-item id="1">超时未接单</mt-tab-item>
          <mt-tab-item id="2">超时未处理</mt-tab-item>
        </mt-navbar>
        <!-- tab-container -->
        <mt-tab-container v-model="selected" swipeable>
          <mt-tab-container-item id="1">
            <overtime-get-job ref="waitTab"></overtime-get-job>
          </mt-tab-container-item>
          <mt-tab-container-item id="2">
            <overtime-handle ref="confirmTab"></overtime-handle>
          </mt-tab-container-item>
        </mt-tab-container>
      </div>
      <tabbottom activeTabItem="JOB"/>
    </div>
  </transition>
</template>

<script>
  import OvertimeGetJob from './modules/OvertimeGetJob'
  import OvertimeHandle from './modules/OvertimeHandle'
  let isFromDetail = false
  export default {
    name: "OvertimeJobManage",
    components: {
      OvertimeGetJob,
      OvertimeHandle
    },
    data() {
      return {
        selected: '1'
      }
    },
    beforeRouteEnter(to, from, next) {
      console.log('overtimeJobManage beforeRoute')
      if (from.name) {
        if (from.name.indexOf('jobDetail') === -1) {
          isFromDetail = false
        } else {
          isFromDetail = true
        }
      } else {
        isFromDetail = false
      }
      next()
    },
    activated(){
      console.log('activated JobManage')
      if (isFromDetail) { // 来自详情页面
        //  不做处理
      }else{// 否则需要刷新页面
        if(this.$route.query && this.$route.query.tab){
          this.selected = this.$route.query.tab
        }
        const val = this.selected
        if(val=='1'){
          this.$refs.waitTab.loadTop()
        }else if(val=='2'){
          this.$refs.confirmTab.loadTop()
        }
      }
    },
    watch:{
      selected(val){
        console.log('watch selected val:'+val)
        if(val=='1'){
          this.$refs.waitTab.loadTop()
        }else if(val=='2'){
          this.$refs.confirmTab.loadTop()
        }
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .index-container {
    .listbody {
      margin-top 40px
      margin-bottom 50px
      .mint-navbar .mint-tab-item {
        font-size: 0.9rem
      }
    }
    .mint-tab-container-item {
      background-color #f0f0f0
      min-height: calc(100vh - 136px)
    }
  }

</style>
