<template>
  <div class="bbsl-common-page">
    <div class="bbsl-table-search">
      <el-form v-model="queryParam" :inline="true">
        <el-form-item label="类别名称：" prop="">
          <el-input
            v-model="querys[0].value"
            clearable
            placeholder="请输入类别名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" @click="handleSearch"
            >搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div ref="contentPanel" class="bbsl-table-content">
      <div ref="btnPanel" class="bbsl-btn-content">
        <el-button icon="el-icon-plus" type="success" @click="handleAdd"
          >新增
        </el-button>
        <el-popconfirm title="确定删除选中数据吗？" @confirm="handleDelete">
          <el-button
            slot="reference"
            :disabled="!multipleSelection.length"
            icon="el-icon-delete"
            style="margin-left: 10px"
            type="danger"
            >删除
          </el-button>
        </el-popconfirm>
      </div>
      <el-table
        ref="multipleSelection"
        v-loading="loading"
        :data="tableData"
        :max-height="tableMaxHeight"
        :style="{width: '100%'}"
        size="mini"
        @selection-change="handleSelectionChange"
        @row-dblclick="handleDbClick"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column
          label="类别名称"
          prop="name"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column label="类别编码" prop="code" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="createTime"
          show-overflow-tooltip
        >
        </el-table-column>
      </el-table>
      <el-pagination
        ref="paginationPanel"
        :current-page="queryParam.pageBean.page"
        :page-size="queryParam.pageBean.pageSize"
        :page-sizes="[20, 30, 40, 50]"
        :total="total"
        align="right"
        background
        class="bbsl-pagination"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
    <userTypeMenuDialog ref="formModal"></userTypeMenuDialog>
  </div>
</template>

<script>
import {TableMixin} from '@/mixins/tableMixin'
import userTypeMenuDialog from './components/userTypeMenuDialog.vue'
import userTypeMenu from '@/api/examination/userTypeMenu.js'
import dictUtils from '@/components/dict/DictSelectUtils.js'

export default {
  mixins: [TableMixin],
  name: 'userTypeMenu',
  components: {
    userTypeMenuDialog
  },
  data() {
    return {
      url: {
        delete: '/api/job/v1/job/deleteJobByIds'
      },
      tableData: [],
      multipleSelection: [],
      total: 0,
      sortList: {},
      querys: [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'name',
          relation: 'AND',
          value: ''
        }
      ],
      typeList: [],
      roomList: []
    }
  },
  created() {
    this.typeList = dictUtils.getDictItemsFromCache('sblx')
  },
  methods: {
    async loadData(page) {
      if (page) {
        this.queryParam.pageBean.page = page
      }
      this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      this.queryParam.sorter = [
        {
          direction: 'DESC',
          property: 'createTime'
        }
      ]
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }

      await userTypeMenu.getJobPage(this.queryParam, res => {
        this.total = res.total
        this.tableData = res.rows
        this.$set(this.tableData)
        this.loading = false
      })
    },
    insort(val) {
      let id = val.id
      let value = val.sn
      this.sortList[id] = value
    },
    tableRowClassName({row, rowIndex}) {
      console.log(rowIndex % 2 == 0)
      if (rowIndex % 2 == 0) {
        return 'warning-row'
      } else {
        return ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .warning-row {
  // background-color: #C1C2C5 !important;
}
</style>
