<template>
  <div class="lend-confirm">
    <headSlot>
      <el-button icon="el-icon-plus" size="mini" :disabled="selections.length ? false : true " @click="lendFormVisible = true">借出</el-button>
      <el-button icon="el-icon-edit" size="mini" @click="handelReRecord">重新登记</el-button>
      <el-button icon="el-icon-minus" size="mini" :disabled="selections.length ? false : true " @click="handleRemove">移出</el-button>
      <crudOperation style="margin-left:10px" />
    </headSlot>
    <!--表格渲染-->
    <el-table
      ref="table"
      :data="tableData"
      style="min-width: 100%"
      height="calc(100vh - 355px)"
      :cell-class-name="cell"
      :default-sort="{ prop: 'isOperationTime', order: 'descending' }"
      @selection-change="selectionChangeHandler"
      @row-click="clickRowHandler"
      @row-dblclick="handleDbClick"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" label="序号" width="55" />
      <el-table-column prop="isCategoryName" label="所属门类" min-width="85" />
      <el-table-column prop="isArchivesID" label="档号" min-width="125" />
      <el-table-column prop="isTitleName" label="题名" min-width="120" />
      <el-table-column prop="isFieldName" label="盒名称" min-width="85" />
      <el-table-column prop="isStoragePath" label="存放位置" min-width="130" />
      <el-table-column prop="borrowerName" label="借阅人" min-width="60" />
      <el-table-column prop="borrowDays" label="借阅时间" min-width="115" />
      <el-table-column prop="borrowGoal" label="借阅目的" min-width="60" />
      <el-table-column prop="isLendStatus" label="借阅状态" min-width="60">
        <template slot-scope="scope">
          <!-- 已借 / 待借 -->
          <span class="cell-lend">{{ scope.row.isLendStatus }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable prop="isOperationTime" label="操作时间" min-width="85" />
    </el-table>
    <!--借出弹框-->
    <el-dialog ref="dialogTable" title="借出" :visible.sync="lendFormVisible">
      <span class="dialog-right-top" />
      <span class="dialog-left-bottom" />
      <el-table :data="selections" :cell-class-name="cellWarn">
        <el-table-column type="index" label="序号" width="55" />
        <el-table-column prop="isCategoryName" label="所属门类" />
        <el-table-column prop="isArchivesID" label="档号" min-width="140" />
        <el-table-column prop="isTitleName" label="题名" min-width="140" />
        <el-table-column prop="isWarnState" label="状态" min-width="85">
          <template slot-scope="scope">
            <!-- 已解除 / 未解除/解除失败 -->
            <span class="clear">{{ scope.row.isWarnState }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button disabled>解除警报</el-button>
      </div>
    </el-dialog>
    <!-- 移出确认弹框 -->
    <delConfirm ref="delConfirmDom" :list-name="listName" />
    <!-- 档案详情 -->
    <archiveDetail ref="archiveDetailDom" />
    <!-- 分页 -->
    <pagination />
  </div>
</template>

<script>
import headSlot from '../components/headSlot.vue'
import pagination from '@crud/Pagination'
import CRUD, { presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import delConfirm from '../components/delConfirm.vue'
import archiveDetail from './module/archiveDetail.vue'

import data1 from '../data1.json'
export default {
  components: { headSlot, pagination, crudOperation, archiveDetail, delConfirm },
  mixins: [presenter()],
  cruds() {
    return CRUD({
      // title: '岗位',
      //   url: 'api/job',
      // crudMethod: { ...crudJob },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: true,
        group: false
      }
    })
  },
  data() {
    return {
      tableData: [],
      selections: [],
      lendFormVisible: false,
      lendForm: {},
      listName: '借出确认'
    }
  },
  mounted() {
    this.getData()
    this.dialogTableStyle()
  },
  methods: {
    getData() {
      this.tableData = data1.rows
    },
    selectionChangeHandler(val) {
      this.selections = val
      console.log(val)
    },
    // 档案详情
    handleDbClick(row) {
      this.$refs.archiveDetailDom.detailVisible = true
      this.$refs.archiveDetailDom.rowData = row
    },
    clickRowHandler(row) {
      this.$refs.table.toggleRowSelection(row)
    },
    // 重新登记返回上一级
    handelReRecord() {
      console.log(11)
      this.$emit('callBack', { index: 0 })
    },
    // 移出
    handleRemove() {
      this.$refs.delConfirmDom.deleteVisible = true
    },
    dialogTableStyle() {
      const dialogTableDom = this.$refs.dialogTable
      const targetDialog = dialogTableDom.$refs.dialog
      targetDialog.style.width = '800px'
    },
    cell({ row, columnIndex }) {
      if (row.isLendStatus === '待借' && columnIndex === 10) {
        return 'no-lend'
      } else if (row.isLendStatus === '已借' && columnIndex === 10) {
        return 'have-lend'
      } else if (row.isLendStatus === '' && columnIndex === 10) {
        return 'other-lend'
      }
    },
    cellWarn({ row, columnIndex }) {
      if (row.isWarnState === '已解除' && columnIndex === 4) {
        return 'no-clear'
      } else if (row.isWarnState === '未解除' && columnIndex === 4) {
        return 'have-clear'
      } else if (row.isWarnState === '解除失败' && columnIndex === 4) {
        return 'fail-clear'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/styles/lend-manage.scss';
::v-deep .el-dialog__footer {
  background-color: #031435;
}

.el-dialog .dialog-footer {
  padding: 0;
  margin: 0;
}

</style>
