<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--      <div v-if="crud.props.searchToggle">-->
      <!--        &lt;!&ndash; 搜索 &ndash;&gt;-->
      <!--        <label class="el-form-item-label">设置逾期时间id</label>-->
      <!--        <el-input v-model="query.configOverdueId" clearable placeholder="请输入逾期时间id" 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="120px">
          <el-form-item label="逾期提醒方式">
            <el-select
              v-model="isOverdue"
              placeholder="提醒方式"
              style="width: 270px;"
              class="filter-item"
            >
              <el-option
                v-for="item in selectOptionValue"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="逾期时间内容">
            <el-input v-model="form.configOverdueContent" placeholder="请输入天数" style="width: 270px;" />
            <!--            <span> <el-button type="primary">添加</el-button></span>-->
          </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="configOverdueId" label="设置逾期时间" />
        <el-table-column prop="configOverdueLabel" label="设置逾期时间内容" />
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="修改人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="修改时间" />
        <el-table-column v-if="checkPer(['admin','dmReadingRoomConfigOverdue:edit','dmReadingRoomConfigOverdue: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 crudDmReadingRoomConfigOverdue from '@/api/dmReadingRoomConfigOverdue'
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 = { configOverdueId: null, configOverdueContent: null, createBy: null, updateBy: null, createTime: null, updateTime: null, configOverdueLabel: null }
const optShow = {
  add: true,
  edit: true,
  del: false,
  download: false,
  reset: false
}
export default {
  name: 'DmReadingRoomConfigOverdue',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '逾期时间配置', url: 'api/dmReadingRoomConfigOverdue', idField: 'configOverdueId', sort: 'configOverdueId,desc', crudMethod: { ...crudDmReadingRoomConfigOverdue }, optShow })
  },
  data() {
    return {
      selectOptionValue: [{ name: '逾期前配置', value: '0' }, { name: '逾期后配置', value: '1' }],
      isOverdue: '',
      permission: {
        add: ['admin', 'dmReadingRoomConfigOverdue:add'],
        edit: ['admin', 'dmReadingRoomConfigOverdue:edit'],
        del: ['admin', 'dmReadingRoomConfigOverdue:del']
      },
      rules: {
        isOverdue: [
          { required: true, message: '借阅提醒方式不能为空', trigger: 'blur' }
        ],
        configOverdueContent: [
          { required: true, message: '逾期时间天数不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'configOverdueId', display_name: '设置逾期时间id' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    [CRUD.HOOK.beforeSubmit]() {
      if (Number(this.form.configOverdueContent) < 0) {
        this.$message.info('设置天数不能是负数')
        return false
      }
      if (this.isOverdue === '0') {
        this.form.configOverdueLabel = '逾期前' + this.form.configOverdueContent + '天'
        this.form.configOverdueContent = '-' + this.form.configOverdueContent
      } else if (this.isOverdue === '1') {
        this.form.configOverdueLabel = '逾期后' + this.form.configOverdueContent + '天'
        this.form.configOverdueContent = this.form.configOverdueContent
      }
    }
  }
}
</script>

<style scoped>

</style>
