<template>
  <div class='container'>
    <!--列表-->
    <navigator v-for='(v,i) in lists' :key='i' :url="'../leaveInfo/main?sysNewsId=0&id='+v.id">
      <div class="list">
        <div class="title">
          <span class="reason">请假事由：{{v.cause}}</span>
          <span class="status ongoing" v-if="v.status ==0">律所审核中</span>
          <span class="status ongoing" v-if="v.status ==1">司法审核中</span>
          <span class="status finish" v-if="v.status ==2 || v.status ==3">已审批</span>
        </div>
        <p>开始时间：{{v.start_Date}}</p>
        <p>结束时间：{{v.end_Date}}</p>
      </div>
    </navigator>
    <!--列表-->
    <!--请假申请-->
    <navigator url='../leave/main'>
      <div class="leave">
        <img src='/static/imgs/leave.png'>
        <span>我要请假</span>
      </div>
    </navigator>
    <!--请假申请-->
  </div>
</template>

<script>
  export default {
    data() {
      return {
        lists: [],
        pageNum: 1,
        pageSize: 15,
        isLastPage: false,
        hasNextPage: false,
        Refresh: false,
        loaded: false
      }
    },
    methods: {
      getList(){
        wx.showLoading({ title: '正在加载' })
        wx.request({
          url: this.rootUrl + 'leave/getLatestLeave',
          method: 'get',
          header: {'content-type': 'application/x-www-form-urlencoded'},
          data:{
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            sessionID: wx.getStorageSync('sessionID')
          },
          success: res=> {
            if(res.statusCode=='500'){
              this.service.getUnionId(this.rootAvatar,this.rootUrl).then(res=>{
                console.log(res)
                this.loadArticles()
              })
            }else{
              this.hasNextPage = res.data.hasNextPage
              this.isLastPage = res.data.isLastPage
              this.setLawyerData(res.data.list)
            }
          },
          fail: res=> {
            console.log(res)
          }
        })
      },
      setLawyerData(arr){
        if(this.hasNextPage){
          // console.log('++++')
          const lists = [...this.lists,...arr]
          this.lists = []
          this.lists = lists
        }else{
          // console.log('=====')
          if(this.pageNum === 1){
            this.lists = arr
          }else {
            const lists = [...this.lists,...arr]
            this.lists = []
            this.lists = lists
            // this.pageNum = 1
          }
        }
        console.log(this.pageNum)
        this.loaded = true
        wx.hideLoading()
      }
    },
    onLoad(){
      // this.getList()
    },
    onReachBottom() {
      if(this.hasNextPage){
        this.pageNum = ++this.pageNum
        this.getList()
      }
    },
    onShow() {
      this.lists = []
      this.pageNum = 1
      this.getList()
    },
    onUnload(){
      this.lists = []
      this.pageNum = 1
      this.all_data_loaded = false
      this.loaded = false
    }
  }
</script>
<style lang="stylus" scoped>
.container
  position absolute
  Background()
  width 100%
  min-height 100%
  box-sizing border-box
  padding-bottom 86rpx
.list
  margin 20rpx
  width calc(100% - 40rpx)
  box-sizing border-box
  padding 20rpx
  border-radius 12rpx
  background-color #fff
  position relative
.title
  margin-bottom 15rpx
.reason
  color #333
  white-space nowrap
  overflow hidden
  text-overflow ellipsis
.list p
  margin-top 10rpx
  font-size 28rpx
  color #666
.status
  float right
  display inline-block
  padding 5rpx 10rpx
  border-radius 6rpx
  color #fff
  font-size 26rpx
.ongoing
  background-color #f6b35a
.finish
  background-color #00D49D
.leave
  z-index 100
  position fixed
  left 0
  bottom 0
  width 100%
  padding 25rpx 0
  background-color #fff
  color #1d7bef
  border-top 1rpx solid #dedede
  display flex
  justify-content center
  align-items center
.leave img
  margin-right 15rpx
  width 36rpx
  height 36rpx
</style>

