<template>
  <div class="vacationRecord">
    <van-nav-bar title="申请记录" left-text="返回" left-arrow @click-left="$route_back" />
    <van-search v-model="searchValue" class="leftkep" placeholder="搜索" @input="keyInp()" />
    <div class="typeItems">
      <div class="typeItem" v-for="(item, index) in headfl" :key="index" :class="{ active: type == item.key }" @click="type = item.key">{{ item.name }}</div>
    </div>
    <div class="headAll">
      <scroller  :isInitRefresh="false" noDataText="没有了噢" ref="scroller" :onRefresh="refresh" :onInfinite="infinite" :list="applyList">
        <div class="wraper">
          <van-empty description="暂无数据" v-if="applyList.length == 0" />
          <div v-for="item of applyList" :key="item.id" class="item" @click="$router.push({ name: 'RecordDetail', query: { id: item.id } })">
            <div class="content">
              <div class="title">
                <div class="detail">{{ item.type_mark }}申请</div>
                <div :class="{ wait: item.status == 0, refuse: item.status == -1 }" class="status">{{ filterStatus(item.status) }}</div>
              </div>
              <div v-if="item.type == 4" class="desc">请假类型:{{ item.holiday_name }}</div>
              <div class="desc">申请时间:{{ item.application_time }}</div>
              <div v-if="item.type == 2">
                <div v-for="(innerItem, i) of item.travel_list" :key="i">
                  <div class="desc">出差地点:{{ innerItem.name }}</div>
                  <div class="desc">开始时间:{{ innerItem.start_time.date }}{{ innerItem.start_time.scope=='AM'? '早上':'下午' }}</div>
                  <div class="desc">结束时间:{{ innerItem.end_time.date }}{{ innerItem.end_time.scope=='AM'? '早上':'下午' }}</div>
                </div>
              </div>
              <div v-else>
                <div class="desc">{{ item.type == 0 ? '补卡班次' : '开始时间' }}:{{ item.start_time }}</div>
                <div v-if="item.type != 0" class="desc">结束时间:{{ item.end_time }}</div>
              </div>
            </div>
          </div>
        </div>
        <div style="padding-bottom: 1rem;"></div>
      </scroller>
    </div>

    <!-- 申请搜索 -->
    <div v-show="searchVisibale" class="searchWrapper">
      <div style="display:flex;align-items: center;">
        <van-search v-model="searchValue" class="leftkep" placeholder="搜索" @input="keyInp()" />
        <div @click="getApplyHistroy" v-if="this.searchValue" class="search">搜索</div>
      </div>

      <div class="searchTip">
        <span></span>
        在这里可以搜索到
        <span></span>
      </div>
      <div class="searchItems">
        <div class="searchItem">
          <icon class="searchItemIcon" name="title"></icon>
          <div>审批标题</div>
        </div>
        <div class="searchItem">
          <icon class="searchItemIcon" name="content"></icon>
          <div>正文内容</div>
        </div>
        <div class="searchItem">
          <icon class="searchItemIcon" name="suggess"></icon>
          <div>审批意见</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { _debounce } from '@/utils/auth';
export default {
  data() {
    return {
      applyList: [],
      searchValue: '',
      searchVisibale: false,
      fillterVisibale: false,
      profile: this.$userInfo(),
      applyHistoryList: [],
      status: 'all',
      type: -1,
      page: 1,
      headfl: [{ key: -1, name: '全部' }, { key: 3, name: '外出' }, { key: 2, name: '出差' }, { key: 4, name: '请假' }, { key: 1, name: '加班' }, { key: 0, name: '补卡' }],
      scroller: ''
    };
  },
  watch: {
    type() {
      this.pullDown();
    },
    '$route.query.goSearch'(val) {
      if (!val) {
        this.searchVisibale = false;
      }
    },
    '$route.query.goFillter'(val) {
      if (!val) {
        this.fillterVisibale = false;
      }
    }
  },
  created() {
    if (this.$route.query.type != undefined) {
      this.type = this.$route.query.type;
    }
  },
  activated() {
    this.pullDown();
  },
  methods: {
    pullDown(){
      setTimeout(() => {
        this.$refs.scroller.triggerPullToRefresh();
      }, 50);
    },
    keyInp: _debounce(function() {
      // 搜索
      this.pullDown();
    }),
    filterType(type) {
      switch (type) {
        case 0:
          return '补卡';
        case 1:
          return '加班';
        case 2:
          return '出差';
        case 3:
          return '外出';
        case 4:
          return '请假';
      }
    },
    infinite(done) {
        this.page += 1;
        this.getApplyHistroy(true,done)
    },
    refresh(done) {
      this.page = 1;
      this.getApplyHistroy(false,done)
    },
    filterStatus(status) {
      if (status === 0) {
        return '待审批';
      }
      if (status === 1) {
        return '审批通过';
      }
      if (status === -1) {
        return '审批驳回';
      }
    },
    getApplyHistroy(is,callback) {
      this.$toast.loading({
        mask: true,
        message: '加载中...'
      });
      let hasMore = false
      is? '':this.page=1;
      let data={
        type: this.type,
        page: this.page,
        status: this.status,
        page_size: 10,
        keyword: this.searchValue
      }
      this.$axiosKq('get', '/ad/review/history', data).then(res => {
        let list = res.data.data.review_list;
        if (this.page === 1) {
          this.applyList = list
        } else {
          this.applyList = this.applyList.concat(list)
        }
        hasMore = list.length !== 10
        callback && callback(hasMore)
      }) .finally(() => {
        this.$toast.clear();
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.vacationRecord .search /deep/ .mint-searchbar {
  padding: 0.32rem;
  background: #fff;
}
.vacationRecord .search /deep/ .mint-searchbar-inner {
  background: #f5f7fa;
  border-radius: 0.08rem;
}
.vacationRecord .search /deep/ .mint-searchbar-core {
  background: #f5f7fa;
}
.vacationRecord {
  .typeItems {
    display: flex;
    height: 0.98rem;
    align-items: center;
    justify-content: space-around;
    position: -webkit-sticky;
    position: sticky;
    top: 0.88rem;
    .typeItem {
      width: 0.88rem;
      height: 0.48rem;
      font-size: 0.28rem;
      color: rgba(96, 98, 102, 1);
      line-height: 0.48rem;
      text-align: center;
      &.active {
        color: #fff;
        padding: 0 0.16rem;
        background: rgba(38, 162, 255, 1);
        border-radius: 0.25rem;
      }
    }
  }
  .search {
    height: auto;
  }
}

.fillterWrapper {
  position: fixed;
  top: 0.88rem;
  .confirmBtn {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 1rem;
    line-height: 1rem;
    text-align: center;
    color: #fff;
    background: rgb(55, 171, 254);
    width: 100%;
  }
  background-color: #fff;
  height: 100%;
  .fillterTitle {
    line-height: 0.8rem;
    position: relative;
    padding-left: 0.4rem;
    margin-left: 0.15rem;
    margin-top: 0.2rem;
    font-size: 0.3rem;
    &::after {
      content: '';
      position: absolute;
      top: 0.26rem;
      left: 0;
      width: 0.24rem;
      height: 0.24rem;
      border-radius: 50%;
      background-color: rgb(72, 169, 239);
    }
  }
  .fillter:nth-of-type(2) .fillterTitle::after {
    background-color: rgb(22, 195, 149);
  }
  .fillterItems {
    display: flex;
    flex-wrap: wrap;
    .fillterItem {
      width: 2rem;
      height: 1rem;
      text-align: center;
      line-height: 1rem;
      background: rgb(243, 243, 243);
      border-radius: 0.2rem;
      font-size: 0.28rem;
      margin-left: 0.36rem;
      margin-bottom: 0.36rem;
      &.type {
        width: 3.2rem;
      }
      &.active {
        background-color: rgb(228, 240, 250);
        color: rgb(119, 191, 241);
      }
    }
  }
  .fillter:nth-of-type(2) .fillterItems .fillterItem.active {
    background-color: rgb(220, 245, 239);
    color: rgb(75, 208, 172);
  }
}
.searchItems {
  display: flex;
  padding-top: 0.4rem;
  .searchItem {
    flex: 1;
    font-size: 0.24rem;
    color: #909399;
    text-align: center;
    .searchItemIcon {
      width: 0.5rem;
      margin-bottom: 0.18rem;
    }
  }
}
.searchTip {
  margin-top: 1.2rem;
  padding: 0 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.28rem;
  color: #909399;
  span {
    width: 26%;
    height: 0.02rem;
    background-color: #eee;
  }
}
.searchWrapper {
  background-color: #fff;
  height: 100%;
  position: fixed;
  top: 0.88rem;
  left: 0;
  width: 100%;
  .search {
    flex: 0 0 1rem;
    color: #26a2ff;
    padding-right: 0.2rem;
    text-align: center;
    background-color: #f5f7fa;
    height: 0.96rem;
    line-height: 0.96rem;
    font-size: 0.32rem;
  }
}
.topBar {
  height: 0.88rem;
  background-color: #fff;
  border-bottom: 0.02rem solid #eee;
  display: flex;
  align-items: center;
  font-size: 0.3rem;
  line-height: 0.5rem;
  .left {
    flex: 1;
    text-align: center;
    color: #909399;
    .searchIcon {
      width: 0.4rem;
      margin-right: 0.1rem;
    }
  }
  .right {
    flex: 1;
    text-align: center;
    color: #909399;
    .fillterIcon {
      width: 0.4rem;
      margin-right: 0.1rem;
    }
  }
}
.vacationRecord {
  background-color: #f5f7fa;
  position: relative;
}
.wraper {
  // padding:0 0.32rem;
  // background-color: #fff;
}
.item {
  display: flex;
  padding: 0 0.32rem 0.26rem;
  margin-bottom: 0.24rem;
  background-color: #fff;
}
.avatar {
  width: 0.86rem;
  height: 0.86rem;
  border-radius: 50%;
  margin: 0.4rem 0.2rem 0 0;
  flex-shrink: 0;
}
.content {
  // padding-top: 0.2rem;
  width: 100%;
}
.content .title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  // padding-bottom: 0.12rem;
  margin: 0.32rem 0 0.16rem 0;
  .detail {
    font-size: 0.34rem;
    flex: 0 0 3.6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.content .desc {
  font-size: 0.28rem;
  color: #909399;
  margin-bottom: 0.08rem;
}
.content .status {
  font-size: 0.34rem;
  color: rgb(70, 211, 173);
  // line-height: 0.8rem;
  // padding: 0.1rem 0 0.28rem 0;
}
.content .status.wait {
  color: rgb(235, 179, 102);
}
.content .status.refuse {
  color: rgb(246, 138, 119);
}
.content .status.cancel {
  color: rgb(101, 101, 101);
}
.title .time {
  padding-right: 0.2rem;
  font-size: 0.28rem;
  color: #909399;
}
.leftkep {
  padding: 0.2rem 0.12rem 0.2rem 0.32rem;
  box-sizing: border-box;
}
.headAll {
  height: calc(100% - 3rem) !important;
  position: relative;
}
</style>
<style>
.searchIcon path {
  fill: rgb(51, 51, 51);
}
</style>
