<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>
        <el-button
          icon="el-icon-sort"
          plain
          style="margin-left: 10px"
          type="primary"
          @click="savePropertyf"
        >
          保存排序号
        </el-button>
      </div>
      <el-table
        ref="multipleSelection"
        v-loading="loading"
        :data="tableData"
        :max-height="tableMaxHeight"
        :style="{width: '100%'}"
        size="mini"
        @row-dblclick="handleDbClick"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          label="考场编码"
          prop="code"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column label="考场名称" prop="name" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          label="考场位置"
          prop="roomPlace"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="考场状态"
          prop="roomStatusName"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="排序"
          min-width="70"
          prop="sn"
          show-overflow-tooltip
          sortable
        >
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.sn"
              min="1"
              size="small"
              style="width:70px"
              type="number"
              @input="insort(scope.row)"
            >
            </el-input>
          </template>
        </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>
    <roomMenuDialog ref="formModal"></roomMenuDialog>
  </div>
</template>

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

export default {
  mixins: [TableMixin],
  name: 'roomMenu',
  components: {
    roomMenuDialog
  },
  data() {
    return {
      url: {
        delete: '/exam/room/info/'
      },
      sortList: {},
      tableData: [],
      multipleSelection: [],
      total: 0,
      roomStatusList: [],
      querys: [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'name',
          relation: 'AND',
          value: ''
        }
      ]
    }
  },
  created() {
    this.roomStatusList = dictUtils.getDictItemsFromCache('kczt')
  },
  methods: {
    loadData(page) {
      if (page) {
        this.queryParam.pageBean.page = page
      }
      this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }

      roomMenu.pagingQuery(this.queryParam, res => {
        this.total = res.total
        this.tableData = res.rows
        this.tableData.forEach(e => {
          console.log(e)
          this.roomStatusList.forEach(s => {
            console.log(s)
            if (e.roomStatus == s.value) {
              e.roomStatusName = s.name
            }
          })
        })
        this.$set(this.tableData)
        this.loading = false
      })
    },
    insort(val) {
      let id = val.id
      let value = val.sn
      this.sortList[id] = value
    },
    //保存排序号
    savePropertyf() {
      roomMenu.saveSort(this.sortList, res => {
        if (res.state) {
          this.$notify({
            type: 'success',
            message: res.message,
            duration: 2000
          })
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    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>
