<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
            clearable
            v-model="querys[1].value"
            placeholder="请输入试卷名称"
          ></el-input>
        </el-form-item>
        <el-form-item label=" 组卷方式：">
          <el-select
            clearable
            v-model="querys[2].value"
            placeholder="请选择组卷方式"
          >
            <el-option
              v-for="item in zjfsList"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleSearch"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="bbsl-table-content" ref="contentPanel">
      <div class="bbsl-btn-content" ref="btnPanel">
        <el-button type="success" icon="el-icon-plus" @click="handleAdd"
          >新增</el-button
        >
        <el-popconfirm title="确定删除选中数据吗？" @confirm="handleDelete">
          <el-button
            slot="reference"
            type="danger"
            :disabled="!multipleSelection.length"
            icon="el-icon-delete"
            style="margin-left: 10px"
            >删除</el-button
          >
        </el-popconfirm>
      </div>
      <el-table
        size="mini"
        v-loading="loading"
        ref="multipleSelection"
        :data="tableData"
        :style="{width: '100%'}"
        :max-height="tableMaxHeight"
        @row-dblclick="handleDbClick"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="name"
          label="试卷名称"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="wayTypeName"
          label="组卷方式"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="timeLength"
          label="考试时长(分)"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="totalScore" label="总分数" show-overflow-tooltip>
        </el-table-column>

        <el-table-column
          prop="createTime"
          label="创建时间"
          min-width="110"
          show-overflow-tooltip
        ></el-table-column>
        <!-- <el-table-column prop="o" label="状态" show-overflow-tooltip> -->
        <!-- </el-table-column> -->
        <el-table-column label="操作" show-overflow-tooltip>
          <template #default="scope">
            <el-dropdown
              split-button
              @click="preview(scope.row)"
              @command="
                command => {
                  handleClick(command, scope.row)
                }
              "
            >
              开始考试
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="0">复制试卷</el-dropdown-item>
                <el-dropdown-item command="1">模拟成绩</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

            <!-- <el-button @click="preview(scope.row)" size="small">预览试卷</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        align="right"
        background
        class="bbsl-pagination"
        ref="paginationPanel"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParam.pageBean.page"
        :page-sizes="[20, 30, 40, 50]"
        :page-size="queryParam.pageBean.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <mnsjMenuDialog ref="formModal" @loadData="loadData"></mnsjMenuDialog>
    <el-dialog
      title="模拟成绩"
      width="80%"
      style="height: auto;"
      top="1vh"
      :visible.sync="showTest"
      v-if="showTest"
    >
      <xlcjMenu :names="names" />
    </el-dialog>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import {TableMixin} from '@/mixins/tableMixin'
import mnsjMenuDialog from './components/mnsjMenuDialog.vue'
import dictUtils from '@/components/dict/DictSelectUtils.js'
import mnsjMenu from '@/api/examination/mnsjMenu.js'
import xlcjMenu from './xlcjMenu.vue'
export default {
  mixins: [TableMixin],
  name: 'mnsjMenu',
  components: {
    mnsjMenuDialog,
    xlcjMenu
  },
  data() {
    return {
      url: {
        delete: '/exam/paper/base/'
      },
      tableData: [],
      total: 0,
      showTest: false,
      names: '',
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'type_',
          relation: 'AND',
          value: '2'
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'b.name_',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: ' b.way_type_',
          relation: 'AND',
          value: ''
        }
      ],
      multipleSelection: [],
      zjfsList: []
    }
  },
  created() {
    this.ksztList = dictUtils.getDictItemsFromCache('kszt')
    this.zjfsList = dictUtils.getDictItemsFromCache('zjfs')
  },
  computed: {
    ...mapState({
      token: state => state.login.currentUser.token
    })
  },
  methods: {
    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])
      }
      if (this.querys[1].value) {
        this.queryParam.querys.push(this.querys[1])
      }
      if (this.querys[2].value) {
        this.queryParam.querys.push(this.querys[2])
      }
      mnsjMenu.getQuery(this.queryParam, res => {
        this.total = res.total
        this.tableData = res.rows
        this.tableData.forEach(e => {
          this.zjfsList.forEach(z => {
            if (e.wayType == z.value) {
              e.wayTypeName = z.name
            }
          })
        })
        this.$set(this.tableData)
        this.loading = false
      })
    },
    //预览试卷
    preview(val) {
      console.log(val)
      this.$router.push({
        name: 'simulationTestPaper',
        params: val
      })
    },
    handleClick(command, val) {
      if (command === '0') {
        this.$refs.formModal.copy(val)
      } else {
        this.names = val.name
        this.showTest = true
      }
    },
    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>
