<template>
  <div class="mainPage">
    <slideTabH
      :data="tabList"
      fontSize="16"
      activeColor="red"
      normalColor="#666"
      @slideChange="slideChange"
    >
      <div class="subMain" slot="slideTabH-1">
        <div>
          <div class="noData" v-if="borrowshow && (borrowBooks.list || []).length < 1">
            <img src="../../../../common/icon/kong.png" alt>
            <span>暂无内容</span>
          </div>
          <ul v-if="borrowshow">
            <li v-for="(item, index) in borrowBooks.list" :key="index">
              <libraryListItem :data="item" :type="1" @itemClick="borrowedRecordClick"></libraryListItem>
            </li>
          </ul>
        </div>
      </div>
      <div class="subMain" slot="slideTabH-2">
        <div>
          <span>请在资格保留时间内至案场借阅图书，超出预约时间将取消预约资格</span>
          <div class="noData" v-if="reserveshow && (reserveBooks.list || []).length < 1">
            <img src="../../../../common/icon/kong.png" alt>
            <span>暂无内容</span>
          </div>
          <ul v-if="reserveshow">
            <li v-for="(item, index) in reserveBooks.list" :key="index">
              <libraryListItem :data="item" :type="2"></libraryListItem>
            </li>
          </ul>
        </div>
      </div>
    </slideTabH>
    <van-dialog v-model="showDialog" :show-confirm-button="false">
      <div class="borrowedRecordContent flex-h" @click="showDialog = false">
        <div class="img">
          <a>
            <img :src="currentItem.BookImg" class="centerLabel" alt>
          </a>
        </div>
        <div class="flex-item">
          <div>
            <div>
              <span :class="currentItem.BorrowStatus=='0'?'active':''">{{myBookStatus}}</span>
            </div>
            <span class="title">{{currentItem.BookName}}</span>
            <span>借阅时间：{{toolClass.dateFormat(currentItem.BorrowDate)}}</span>
            <span>应还时间：{{toolClass.dateFormat(currentItem.EndDate, 'yyyy-MM-dd')}}</span>
            <span>归还时间：{{currentItem.BorrowStatus == '2' || currentItem.BorrowStatus == '3' ? '暂未归还' : toolClass.dateFormat(currentItem.ReturnDate)}}</span>
          </div>
        </div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import slideTabH from '../../../../components/slideTabH/index'
import libraryListItem from '../../../../components/libraryListItem/index'
import toolClass from '../../../../util/util'
import { createNamespacedHelpers } from 'vuex'
const { mapState: mapBookState, mapActions: mapBookAction } = createNamespacedHelpers('book')
export default {
  data () {
    return {
      tabList: [{ value: '借阅记录', id: '1' }, { value: '线上预约记录', id: '2' }],
      showDialog: false,
      status: '1',
      page: 1,
      pagesize: 10,
      reserveBooks: {},
      borrowBooks: {},
      currentItem: {},
      borrowshow: false,
      reserveshow: false,
    }
  },
  created () {
    this.getList('1')
    this.getList('2')
  },
  computed: {
    myBookStatus() {
      let status = ''
      switch(this.currentItem.BorrowStatus) {
        case '4':
          status = '已预约'
          break
        case '1':
          status = '借阅中'
          break
        case '0':
          status = '逾期未还'
          break
        case '3':
          status = '逾期归还'
          break
        case '2':
          status = '已归还'
          break
      }
      return status
    },
  },
  components: {
    libraryListItem,
    slideTabH
  },
  methods: {
    ...mapBookAction([
      'getMineBook',
    ]),
    slideChange (e) {
      if (this.status !== this.tabList[e].id) {
        this.status = this.tabList[e].id
        // this.page = 1
        // this.getList()
      }
    },
    borrowedRecordClick (e) { // 借阅记录点击事件
      this.currentItem = e
      this.showDialog = true
    },
    getList (status) {
      const _that = this
      this.getMineBook({
        page: this.page,
        pagesize: this.pagesize,
        status: status == '1'?'1,3,2,0':'4',
      }).then((res) => {
        if(status == '1') {
          _that.borrowBooks = res
          _that.borrowshow = true
        } else {
          _that.reserveBooks = res
          _that.reserveshow = true
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.mainPage {
  .subMain {
    width: 100%;
    height: 100%;
    position: relative;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    .noData {
      width: 100%;
      margin: 0.5rem auto 0;
      position: relative;
      overflow: hidden;
      img {
        width: 0.7rem;
        display: block;
        margin: 0 auto;
      }
      span {
        width: 100%;
        display: block;
        text-align: center;
        line-height: 0.3rem;
        color: #b4b4b4;
        font-size: 0.14rem;
        margin: 0.05rem auto 0;
      }
    }
    > div {
      width: 100%;
      position: relative;
      overflow: hidden;
      > span {
        width: 100%;
        display: block;
        white-space: nowrap;
        overflow: hidden;
        font-size: 0.1rem;
        background: #fdecec;
        color: #fc6243;
        line-height: 0.24rem;
        text-indent: 0.15rem;
        padding-top: 0.02rem;
      }
      > ul {
        padding: 0 0.16rem;
        margin-bottom: 0.1rem;
        position: relative;
        overflow: hidden;
        li {
          margin: 0.1rem auto 0;
        }
      }
    }
  }
  .borrowedRecordContent {
    padding: 0.12rem;
    position: relative;
    overflow: hidden;
    align-items: center;
    .img {
      width: 0.8rem;
      position: relative;
      overflow: hidden;
      a {
        width: 100%;
        display: block;
        height: 0;
        position: relative;
        overflow: hidden;
        padding-bottom: 137.5%;
        border-radius: 0.03rem;
        background: #eee;
      }
    }
    > div.flex-item {
      position: relative;
      overflow: visible;
      margin-left: 0.12rem;
      > div {
        width: 100%;
        position: relative;
        overflow: visible;
        > div {
          text-align: right;
          span {
            display: inline-block;
            line-height: .24rem;
            font-size: .12rem;
            color: #869EC3;
            background: #f2f4f7;
            padding: 0 .1rem 0 .15rem;
            border-radius: .15rem 0 0 .15rem;
            margin-right: -.12rem;
          }
          .active{
            background-color: #fc5534;
            color: #fff;
          }
        }
        > span {
          width: 100%;
          display: block;
          line-height: 0.18rem;
          font-size: 0.11rem;
          color: #666;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          &.title {
            font-size: 0.16rem;
            color: #333;
            line-height: 0.22rem;
          }
        }
      }
    }
  }
}
</style>
