// 风险规则配置
<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="编码名称" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入"
        ></el-input>
      </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 :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="!selectedRows.length"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="table">
      <el-table
        ref="renewalTable"
        v-loading="loading"
        :data="dataList"
        @selection-change="handleSelectionChange"
        row-key="id"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column prop="date" label="序号" width="80" align="center">
          <template slot-scope="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column
          label="编码名称"
          align="center"
          prop="roleName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="编码值"
          align="center"
          prop="roleCode"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="描述"
          prop="roleDes"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="备注"
          prop="remark"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <RiskRoleModel ref="riskRoleModelRef" @refresh="getList()"></RiskRoleModel>
  </div>
</template>

<script>
import { getRiskRolePage, delRiskRole } from "@/api/secure/pdm-risk-role";
import RiskRoleModel from "../components/RiskRoleModel";
export default {
  components: { RiskRoleModel },
  data() {
    return {
      dataList: [],
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: true,
      total: 0,
      // 查询参数
      queryParams: {
        roleName: "",
        pageNum: 1,
        pageSize: 10,
      },
      // 选中数组
      selectedRows: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selectedRows) {
      // 记录选择的行
      this.selectedRows = selectedRows;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.riskRoleModelRef.openModel({ ...row });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.riskRoleModelRef.openModel({});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.id || this.selectedRows.map((ite) => ite.id);
      this.$modal
        .confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？')
        .then(function () {
          return delRiskRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.selectedRows = [];
          this.$refs.renewalTable.clearSelection();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getRiskRolePage({ ...this.queryParams, riskFlag: "1" }).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 150px);
}
::v-deep {
  .el-table {
    height: 100%;
    width: 100%;
    .el-table__body-wrapper {
      width: 100% !important;
      height: calc(100% - 50px) !important; // 表格高度减去表头的高度
      overflow-y: scroll;
    }
  }
}
</style>
