<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">id</label>
        <el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">用户</label>
        <el-input v-model="query.userNumber" clearable placeholder="用户" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">卡号</label>
        <el-input v-model="query.cardNumber" clearable placeholder="卡号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">书籍编号</label>
        <el-input v-model="query.bookId" clearable placeholder="书籍编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">借阅书名</label>
        <el-input v-model="query.bookName" clearable placeholder="借阅书名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">借阅金额</label>
        <el-input v-model="query.money" clearable placeholder="借阅金额" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">借阅开始时间</label>
        <el-input v-model="query.startTime" clearable placeholder="借阅开始时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">借阅到期时间</label>
        <el-input v-model="query.expireTime" clearable placeholder="借阅到期时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">借阅归还时间</label>
        <el-input v-model="query.returnTime" clearable placeholder="借阅归还时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">是否逾期(true-已逾期、false-未逾期)</label>
        <el-input v-model="query.isOverdue" clearable placeholder="是否逾期(true-已逾期、false-未逾期)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">逾期天数</label>
        <el-input v-model="query.day" clearable placeholder="逾期天数" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户">
            <el-input v-model="form.userNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="卡号">
            <el-input v-model="form.cardNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="书籍编号">
            <el-input v-model="form.bookId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="借阅书名">
            <el-input v-model="form.bookName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="借阅金额">
            <el-input v-model="form.money" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="借阅开始时间">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="借阅到期时间">
            <el-date-picker v-model="form.expireTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="借阅归还时间">
            <el-date-picker v-model="form.returnTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否逾期(true-已逾期、false-未逾期)">
            <el-select v-model="form.isOverdue" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.information_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="逾期天数">
            <el-input v-model="form.day" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="userNumber" label="用户" />
        <el-table-column prop="cardNumber" label="卡号" />
        <el-table-column prop="bookId" label="书籍编号" />
        <el-table-column prop="bookName" label="借阅书名" />
        <el-table-column prop="money" label="借阅金额" />
        <el-table-column prop="startTime" label="借阅开始时间" />
        <el-table-column prop="expireTime" label="借阅到期时间" />
        <el-table-column prop="returnTime" label="借阅归还时间" />
        <el-table-column prop="isOverdue" label="是否逾期(true-已逾期、false-未逾期)">
          <template slot-scope="scope">
            {{ dict.label.information_status[scope.row.isOverdue] }}
          </template>
        </el-table-column>
        <el-table-column prop="day" label="逾期天数" />
        <el-table-column v-if="checkPer(['admin','dmReadingRecord:edit','dmReadingRecord:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDmReadingRecord from '@/api/dmReadingRecord'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, userNumber: null, cardNumber: null, bookId: null, bookName: null, money: null, startTime: null, expireTime: null, returnTime: null, isOverdue: null, day: null }
export default {
  name: 'DmReadingRecord',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['information_status'],
  cruds() {
    return CRUD({ title: 'reading_record', url: 'api/dmReadingRecord', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDmReadingRecord }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dmReadingRecord:add'],
        edit: ['admin', 'dmReadingRecord:edit'],
        del: ['admin', 'dmReadingRecord:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'userNumber', display_name: '用户' },
        { key: 'cardNumber', display_name: '卡号' },
        { key: 'bookId', display_name: '书籍编号' },
        { key: 'bookName', display_name: '借阅书名' },
        { key: 'money', display_name: '借阅金额' },
        { key: 'startTime', display_name: '借阅开始时间' },
        { key: 'expireTime', display_name: '借阅到期时间' },
        { key: 'returnTime', display_name: '借阅归还时间' },
        { key: 'isOverdue', display_name: '是否逾期(true-已逾期、false-未逾期)' },
        { key: 'day', display_name: '逾期天数' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
