<template>
  <div class="subPage">
    <div class="system-table-search">
      <div class="flex-h" style="align-items: flex-start;">
        <div class="flex-item flex-h"></div>
        <ul style="white-space: normal;">
          <li style="margin-bottom: 15px;">
            <el-input placeholder="请输入条形码" v-model="postData.barcode"></el-input>
          </li>
          <li style="margin-bottom: 15px;">
            <el-input placeholder="请输入图书名" v-model="postData.bookname"></el-input>
          </li>
          <li style="margin-bottom: 15px;">
            <el-input placeholder="请输入借阅人" v-model="postData.customername"></el-input>
          </li>
          <li style="margin-bottom: 15px;">
            <el-input placeholder="请输入手机号" v-model="postData.customerphone"></el-input>
          </li>
          <li style="margin-bottom: 15px;">
            <el-select v-model="CaseId" placeholder="请选择案场">
              <el-option key="all" label="所有案场" value="all"></el-option>
              <el-option
                v-for="item in cases"
                :key="item.CaseId"
                :label="item.CaseName"
                :value="item.CaseId"
              ></el-option>
            </el-select>
          </li>
          <li style="margin-bottom: 15px;">
            <el-select v-model="postData.borrowstatus" placeholder="请选择状态">
              <el-option
                v-for="item in statusList"
                :key="item.id"
                :label="item.value"
                :value="item.id"
              ></el-option>
            </el-select>
          </li>
        </ul>
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
      <div class="moreFilter"></div>
    </div>
    <div class="system-table-box">
      <el-table :data="list" stripe style="width: 100%">
        <el-table-column label="案场">
          <template slot-scope="scope">{{returnCaseName(scope.row.CaseId)}}</template>
        </el-table-column>
        <el-table-column label="图片" width="300">
          <template slot-scope="scope">
            <img :src="scope.row.BookImg" style="height: 150px;">
          </template>
        </el-table-column>
        <el-table-column prop="BookBarcode" label="条形码"></el-table-column>
        <el-table-column prop="BookName" label="图书名"></el-table-column>
        <el-table-column prop="CustomerName" label="借阅人"></el-table-column>
        <el-table-column prop="CustomerPhone" label="手机号"></el-table-column>
        <el-table-column label="借阅时间">
          <template slot-scope="scope">{{toolClass.dateFormat(scope.row.BorrowDate)}}</template>
        </el-table-column>
        <el-table-column label="规定归还时间">
          <template slot-scope="scope">{{toolClass.dateFormat(scope.row.EndDate)}}</template>
        </el-table-column>
        <el-table-column label="实际归还时间">
          <template slot-scope="scope">{{toolClass.dateFormat(scope.row.ReturnDate)}}</template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">{{returnStatus(scope.row.BorrowStatus)}}</template>
        </el-table-column>
      </el-table>
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="postData.page"
        :page-size="postData.pagesize"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { createNamespacedHelpers, mapState } from 'vuex'
const { mapState: mapLibSate, mapActions: mapLibActions } = createNamespacedHelpers('library')
export default {
  name: 'borrowList',
  data () {
    return {
      total: 1,
      postData: {
        barcode: '',
        bookname: '',
        customername: '',
        customerphone: '',
        borrowstatus: '',
        caseid: '',
        page: 1,
        pagesize: 10
      },
      statusList: [{
        id: '',
        value: ''
      }, {
        id: '0',
        value: '延期'
      }, {
        id: '1',
        value: '借阅中'
      }, {
        id: '2',
        value: '已归还'
      }, {
        id: '3',
        value: '逾期归还'
      }]
    }
  },
  created () {
    this.getBorrowList({ ...this.postData }).then((res) => {
      this.page = res.page
      this.total = res.pagenum
    })
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default,
      orgid: x => x.app.user.OrgId
    }),
    ...mapLibSate({
      list: x => x.borrow.list
    }),
    CaseId: {
      get () {
        return this.postData.caseid || this.defaultCaseId
      },
      set (val) {
        this.postData.caseid = val
      }
    }
  },
  methods: {
    ...mapLibActions(['getBorrowList']),
    search () {
      this.page = 1
      this.getBorrowList({ ...this.postData }).then((res) => {
        this.page = res.page
        this.total = res.pagenum
      })
    },
    handleCurrentChange (val) {
      this.postData.page = val
      this.getBorrowList({ ...this.postData }).then((res) => {
        this.page = res.page
        this.total = res.pagenum
      })
    },
    returnCaseName (id) {
      var name = ''
      this.cases.map((item) => {
        if (item.CaseId === id) name = item.CaseName
      })
      return name
    },
    returnStatus (id) {
      var status = ''
      this.statusList.map((item) => {
        if (item.id === id) status = item.value
      })
      return status
    }
  }
}
</script>

<style lang="scss">
</style>
