<template>
  <!-- 选择打分规则 -->
  <el-dialog
    title="选择打分规则"
    :visible.sync="visible"
    width="800px"
    top="5vh"
    append-to-body
  >
    <el-form
      @submit.native.prevent
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="评分分类" prop="contentType">
        <el-input
          v-model="queryParams.contentType"
          placeholder="请输入评分分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>
    <el-row>
      <el-table
        ref="ruleTable"
        v-loading="loading"
        stripe
        width="100%"
        :data="ruleList"
        @selection-change="select"
        @row-click="handleCurrentChange"
        @select-all="selectAll"
        height="260px"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="排序" align="center" prop="sort"/>
        <el-table-column label="评分分类" align="center" prop="contentType"/>

        <el-table-column label="备注" align="center" prop="remark"/>
      </el-table>
      <!-- <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_normal_disable"
              :value="scope.row.status"
            />
          </template>
        </el-table-column> -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSelectDetail">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {  listEdu,} from "@/api/smartSchool/studentManage/moralEducationRules/index";
export default {
  name: "RuleSelect",
  data() {
    return {
      // 遮罩层
      visible: false,
      loading: true,
      // 选中数组
      ids: [],
      // 选中数组值
      userIds: [],
      // 总条数
      total: 0,
      // 课堂巡检打分规则表格数据
      ruleList: [],
      // 是否为单个
      isSimple: false,
      // 选中项
      selectedItem: {},
      // 显示搜索条件
      showSearch: true,
      ruleId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: null,
        sort: null,
        contentType:null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //评分详细列表
    schoolPatrolRuleDetails(row) {
      this.$router.push({
        path: "/studentmanage/eduscore/" + row.id,
      });
    },
    // 显示弹框
    show() {
      this.queryParams.ruleId = this.ruleId;
      this.getList();
      this.visible = true;
    },
    
    // 多选
    select(selection) {
      if (selection.length > 1) {
        let del_row = selection.shift(); //删除上一个选项
        this.$refs.ruleTable.toggleRowSelection(del_row, false);
      }
      this.ruleId = selection[0].id;
    },
    selectAll(selection) {
      this.$refs.ruleTable.clearSelection();
    },
    
    //单选
    handleCurrentChange(row) {
      // console.log("不触发也打印？");
      this.ruleId = row.id;
      this.$refs.ruleTable.toggleRowSelection(row, true);
    },
    
    getList() {
      this.loading = true;
      listEdu(this.queryParams).then((response) => {
        this.ruleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 选择添加打分规则操作 */
    handleSelectDetail() {
      // const id = this.ruleId;
      this.visible = false;
      this.$parent.confirmRule(this.ruleId);
    },
  },
};
</script>
