<template>
  <div class="list-contain">
    <top-nav title="工作报告"
             @query="onSearch"
             :backFunc="returnLast"></top-nav>
    <van-tabs v-model="activeName">
      <van-tab title="全部报告"
               name="all">
        <detailList class="content"
                    v-if="activeName === 'all'"
                    ref="all"
                    :active-name="activeName" />
      </van-tab>
      <van-tab title="我提交的"
               name="my_submit">
        <detailList class="content"
                    v-if="activeName === 'my_submit'"
                    ref="my_submit"
                    :active-name="activeName" />
      </van-tab>
      <van-tab title="提交给我的"
               name="submit_me">
        <detailList class="content"
                    v-if="activeName === 'submit_me'"
                    ref="submit_me"
                    :active-name="activeName" />
      </van-tab>
      <van-tab title="下属提交的"
               name="subordinate">
        <detailList class="content"
                    v-if="activeName === 'subordinate'"
                    ref="subordinate"
                    :active-name="activeName" />
      </van-tab>
      <van-tab title="知会我的"
               name="notifyMe">
        <detailList class="content"
                    v-if="activeName === 'notifyMe'"
                    ref="notifyMe"
                    :active-name="activeName" />
      </van-tab>
    </van-tabs>

    <van-dialog v-model="showDialog"
                class="new-dialog"
                title="新建工作报告"
                @confirm="handleConfirm"
                show-cancel-button
                close-on-click-overlay
                get-container="#app"> </van-dialog>
    <div @click="clickAdd"
         class="tool-add-btn"></div>
    <search-popup ref="searchRef"
                  @searchClose="searchClose"></search-popup>

  </div>
</template>

<script>
import searchPopup from './components/search-popup.vue'
import detailList from './components/detail-list.vue'
import clearkeepAlive from '../../common/clearkeepAlive'
export default {
  name: 'work-list',
  components: {
    searchPopup,
    detailList
  },
  mixins: [clearkeepAlive],
  activated () {
    this.showDialog = false
  },
  data () {
    return {
      activeName: 'all',
      showDialog: false
    }
  },
  methods: {
    onSearch (val) {
      this.$refs.searchRef.showWorkPopup = true
    },
    searchClose (form) {
      this.$refs.searchRef.showWorkPopup = false
      this.$refs.searchRef.getworkType()
      this.$refs[this.activeName].reLoad(form)
    },
    returnLast () {
      this.clearCache()
      this.$router.back(-1)
    },
    clickAdd () {
      let idObj = this.$store.state.idObj;
      if(idObj.workId){
        this.$dialog.confirm({
          title: '提示',
          message: '是否完成上次未完成的操作',
          className: 'new-dialog',
        })
          .then(() => {// on confirm
            this.$router.push({name: 'newWork', params: {id: idObj.workId} });
          })
          .catch(() => { // on cancel
            this.$router.push('newWork')
          });
      } else {
        this.showDialog = true;
      }
    },
    handleConfirm () {
      this.showDialog = false
      this.$router.push('newWork')
    }

  }
}
</script>
