<template>
  <div>
    <div class="detailItem">
      <div class="imgparent">
        <van-nav-bar
          title="请假记录"
          left-text="返回"
          left-arrow
          @click-left="onClickLeft"
        />
      </div>
      <div class="approva_header ecord_header ">
        <van-tabs @click="onClick">
          <van-tab title="全部申请">
            <p
              class="ijeud"
              @click="showPicker = true"
            >
              <img
                src="../assets/img/icon_rqxz.png"
                alt=""
              >
              <span>{{text}}</span>
              <!-- <img
                src="../assets/img/icon_xl.png"
                alt=""
              > -->
            </p>
            <van-list
              v-model="loading"
              :finished="finished"
              :finished-text="finishedText"
              @load="onLoad"
            >
              <div
                class="approba_nave"
                v-for="(item,index) in allHouseDetail"
                :key="index"
                @click="lkju"
              >
                <p>
                  <span class="soei"><i>{{item.leavefrom_user_name == null? "暂无数据" : item.leavefrom_user_name}}</i>的请假申请</span>
                  <span>{{item.leavefrom_start_time == null? "暂无数据" : item.leavefrom_start_time}}</span>
                </p>
                <p>请假类型:{{item.leavefrom_leave_type == null ? '暂无数据' : item.leavefrom_leave_type}}</p>
                <p>开始时间：{{item.leavefrom_start_time == null? '暂无数据':item.leavefrom_start_time}}</p>
                <p>结束时间：{{item.leavefrom_end_time == null? '暂无数据' : item.leavefrom_end_time == null }}</p>
                <img
                  src="../assets/img/pic_zt_shtg.png"
                  alt=""
                  class="ecord_img"
                >
              </div>
            </van-list>
          </van-tab>
          <van-tab title="已通过申请">
            <p
              class="ijeud"
              @click="showPicker = true"
            >
              <img
                src="../assets/img/icon_rqxz.png"
                alt=""
              >
              <span>{{text}}</span>
              <img
                src="../assets/img/icon_xl.png"
                alt=""
              >
            </p>
            <van-list
              v-model="loading"
              :finished="finished"
              :finished-text="finishedText"
              @load="onLoad"
            >
              <div
                class="approba_nave"
                v-for="(item,index) in allHouseDetail"
                :key="index"
              >
                <p>
                  <span class="soei"><i>王明</i>的请假申请</span>
                  <span>2021-04-24</span>
                </p>
                <p>请假类型:事假</p>
                <p>开始时间：2021-04-25 13:00</p>
                <p>结束时间：2021-04-25 18:00</p>
                <img
                  src="../assets/img/pic_zt_shtg.png"
                  alt=""
                  class="ecord_img"
                >
              </div>
            </van-list>
          </van-tab>
          <van-tab title="已驳回申请">
            <p
              class="ijeud"
              @click="showPicker = true"
            >
              <img
                src="../assets/img/icon_rqxz.png"
                alt=""
              >
              <span>{{text}}</span>
              <img
                src="../assets/img/icon_xl.png"
                alt=""
              >
            </p>
            <van-list
              v-model="loading"
              :finished="finished"
              :finished-text="finishedText"
              @load="onLoad"
            >
              <div
                class="approba_nave"
                v-for="(item,index) in allHouseDetail"
                :key="index"
              >
                <p>
                  <span class="soei"><i>王明</i>的请假申请</span>
                  <span>2021-04-24</span>
                </p>
                <p>请假类型:事假</p>
                <p>开始时间：2021-04-25 13:00</p>
                <p>结束时间：2021-04-25 18:00</p>
                <img
                  src="../assets/img/pic_zt_shtg.png"
                  alt=""
                  class="ecord_img"
                >
              </div>
            </van-list>
          </van-tab>
        </van-tabs>
      </div>
      <div>

      </div>
      <van-popup
        v-model="showPicker"
        position="bottom"
      >
        <van-datetime-picker
          type="date"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      message: "",
      uploader: [{ url: "https://img01.yzcdn.cn/vant/leaf.jpg" }],
      allHouseDetail: [],
      text: "选择日期",
      loading: false,
      finished: false,
      showPicker: false,
       qurmond: {
        table: "leavefrom",
        pageNo: 1,
        pageSize: 4,
        orderBy: "create_time desc",
        fixedData: {
          condition: {
            status: undefined
          }
        },
      },
       page: 1, // 当前页码
       page_size: 100, // 每页多少条
        total: 0, // 总条数
        error: false, // 错误提示
        refreshing: false ,// 下拉刷新
        finishedText:''
    };
  },
  props: ["detailitem"],
  created(){
   this.appList()
  },

  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    lkju() {
      this.$router.push("/ord");
    },
    onConfirm(value) {
      const month = value;
      this.formatDateTime(month);
      this.showPicker = false;
    },
    onClick(name, title) {
      //   Toast(title);
      console.log(title,name) 
      if(name ==0){
        this.qurmond.fixedData.condition.status =undefined
      }else if(name ==1){
        this.qurmond.fixedData.condition.status = 2
      }else{
        this.qurmond.fixedData.condition.status = 3
      }
      this.appList()
      console.log(this.qurmond.fixedData.condition.status)
    },
    async appList() {
      const res = await this.$http.post(
        "/boman-web-core/p/cs/queryList",
        this.qurmond
      );
      console.log(res);
      if (res.data.code !== 200) {
        this.$msg.fail(res.data.msg);
        return false;
      }
      // this.allHouseDetail = res.data.data.rows;
       if (this.qurmond.pageNo == 1) {
      this.loading = false
      this.allHouseDetail = res.data.data.rows;
      this.total = res.total;
    } else {
      this.loading = false
      this.allHouseDetail = this.allHouseDetail.concat(res.data.data.rows)
      this.total = res.data.total;
    }
    
    if ( res.data.data.rows==null) {
      this.finished = true;
      this.finishedText = '暂无数据';
      console.log(34)
    } else if (res.data.data.rows.length < this.qurmond.pageSize) {
      console.log(12)
      this.finished = true;
      this.finishedText = '没有更多啦';
    }
    console.log(this.allHouseDetail)
    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      
    },
    formatDateTime(inputTime) {
      
     let date = new Date(inputTime);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      const time = y + "-" + m + "-" + d;
      this.text = time
      console.log(time);

      return this.text;
      console.log(second);
      // return this.shoutime
    }
  }
};
</script>

<style lang="less">
.ecord_header {
  .van-tabs__line {
    background: #009fe8;
  }
  .van-tabs__wrap {
    box-shadow: 0px 3px 2px 0px rgba(218, 218, 218, 0.35);
  }
  .van-tab__pane {
    background: #fff;
  }
}
</style>


<style scoped lang="less">
.detailItem {
  background-color: #fff;
  //   height: 100vh;
  p {
    font-size: 3.333vw;
    padding: 0.833vw 0;
  }
  .imgparent {
    position: relative;
    .bottom {
      padding: 0 2.778vw;
      margin-bottom: 1.389vw;
      position: absolute;
      bottom: 0.556vw;
      background: linear-gradient(0deg, rgba(0, 0, 0, 0.85), transparent);
      justify-content: space-between;
      color: white;
      display: flex;
      left: 0;
      right: 0;
    }
  }
  .approba_nave {
    border-bottom: 0.267vw solid #dadada;
    margin: 10px 16px;
    padding: 5px 0;
    position: relative;
    .ecord_img {
      width: 11.2vw;
      height: 11.2vw;
      position: absolute;
      right: 0;
      bottom: 12px;
    }
    p {
      font-size: 2.667vw;
      font-family: PingFang SC;
      font-weight: 400;
      color: #666666;
    }
    p:nth-child(1) {
      display: flex;
      justify-content: space-between;
      margin-bottom: 2.133vw;
      i {
        font-style: normal;
        font-weight: 700;
      }
      .soei {
        font-size: 3.733vw;
        font-family: PingFang SC;
        font-weight: 400;
        color: #343434;
      }
      span:nth-child(2) {
        color: #aaa;
        font-weight: 500;
      }
    }
  }
}
.approva_header {
  height: 40px;
  .ijeud {
    padding: 0 4.267vw;
    display: flex;
    align-items: center;
    height: 40px;
    padding-top: 10px;
    img:nth-child(1) {
      width: 4.267vw;
      height: 4.267vw;
    }
    img:nth-child(3) {
      width: 12px;
      height: 12px;
    }
    span {
      height: 100%;
      line-height:40px;
      font-size: 3.467vw;
      font-family: PingFang SC;
      font-weight: 400;
      color: #343434;
      margin: 0 5px;
    }
  }
}
</style>