<template>
  <div class="app-container">

    <!--用户数据-->
    <el-col>
      <!--    搜索条件    -->
      <div class="main-search-box">
        <el-form
          v-show="showSearch"
          ref="queryForm"
          :inline="true"
          :model="queryParams"
          size="small"
        >
          <el-form-item label="机构类型">
            <el-select
              v-model="queryParams.orgType"
              clearable
              label="机构类型"
              placeholder="请选择机构类型"
              prop="orgType"
              @change="cleanExecOrgList"
            >
              <el-option
                v-for="item in dict.type.sys_org_type"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="指标分类">
            <el-select
              v-model="queryParams.typeCode"
              clearable
              placeholder="请选择指标分类"
              @change="changeTargetList"
            >
              <el-option
                v-for="item in targetList"
                :key="item.id"
                :label="item.name"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="指标项目">
            <el-select
              v-model="queryParams.projectCode"
              clearable
              placeholder="请选择指标项目"
              @change="changeTargetListChild"
            >
              <el-option
                v-for="item in targetListChild"
                :key="item.id"
                :label="item.name"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="指标要点">
            <el-select
              v-model="queryParams.pointCode"
              clearable
              placeholder="请选择指标要点"
            >
              <el-option
                v-for="item in targetListGrandson"
                :key="item.id"
                :label="item.name"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <!--    按纽    -->
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button
              icon="el-icon-search"
              size="mini"
              type="primary"
              @click="handleQuery"
            >搜索
            </el-button
            >
            <el-button icon="el-icon-refresh" size="mini" type="primary" @click="resetQuery"
            >重置
            </el-button
            >
            <el-button
              v-hasPermi="['system:user:add']"

              icon="el-icon-plus"
              size="mini"
              type="primary"
              @click="handleAdd"
            >新增
            </el-button>
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList">
          </right-toolbar>
        </el-row>
      </div>

      <el-table
        v-loading="loading"
        :data="dataList"
        
        border
        height="644"
        size="small"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="100"
        ></el-table-column>
        <el-table-column  align="center" label="机构类型" prop="orgTypeText"/>
        <el-table-column  align="center" label="指标分类" prop="typeCodeText"/>
        <el-table-column  align="center" label="指标项目" prop="projectCodeText"/>
        <el-table-column  align="center" label="指标要点" prop="pointCodeText"/>
        <el-table-column  align="center"
          :formatter="formatterScore"
          label="扣分方式"
          prop="evaluateCycle"
        />
        <el-table-column label="分值" align="center" prop="score"/>

        <el-table-column
          class-name="small-padding fixed-width"
          fixed="right"
          label="操作"
          align="center"
          width="180"
        >
          <template slot-scope="{ row }">
            <el-button
              class="el-icon-edit-outline"
              size="mini"
              type="text"
              @click="editHandler(row)"
            >编辑
            </el-button
            >
            <el-button
              class="el-icon-delete"
              size="mini"
              type="text"
              @click="deleteHandler(row)"
            >删除
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </el-col>


    <editEvaluate ref="Evaluate" :targetList="targetList" @success="getList()"></editEvaluate>
  </div>
</template>
<script>
import {mapGetters} from "vuex";
import {findAllRole} from "@/api/system/role";
import {delelteEvaluate, getTargetList, list} from "@/api/evaluateRule/rule.js";
import {toTree} from "@/api/tool/tree.js";
import editEvaluate from "./editEvaluationRuleDialog.vue";
import {targetChange} from './targetChangeMixins.js'

export default {
  name: "SocWebIndex",
  dicts: ["sys_org_type", "plan_status"],
  mixins: [targetChange],
  components: {
    editEvaluate,
  },
  data() {
    const {params, query} = this.$route;
    return {
      targetList: [],
      targetListChild: [],
      targetListGrandson: [],
      loading: false,
      selectedValues: [],
      planRoles: [],

      queryParams: {
        orgType: null,
        typeCode: null,
        projectCode: null,
        pointCode: null,
        pageNum: 1,
        pageSize: 10,
      },
      // 显示搜索条件
      showSearch: true,
      total: 0,
      dataList: [],
    };
  },
  created() {
    this.getList();
    this.getTargetListHandler();
  },
  mounted() {
  },
  computed: {
    ...mapGetters(["orgId"]),
  },
  methods: {
    formatterScore({deductionType}) {
      switch (deductionType) {
        case 1:
          return "直接扣分";
          break;
        case 2:
          return "最高扣分";
          break;

        default:
          break;
      }
    },
    //获取指标列表
    getTargetListHandler() {
      getTargetList().then((res) => {
        let {msg, code, rows} = res;
        if (code == 200) {
          this.targetList = toTree(rows, {
            id: "code",
            children: "children",
            pid: "parentCode",
          });
        }
      });
    },

    //获取列表
    getList() {
      this.loading = true;
      // this.queryParams.orgId=this.orgId
      list(this.queryParams).then((res) => {
        this.dataList = res?.rows || [];
        this.total = res?.total || [];
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.Evaluate.show();
    },
    editHandler(row) {

      this.$refs.Evaluate.show(row.id);
    },

    deleteHandler(row) {
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
        })
        .then(() => {
          delelteEvaluate(row.id).then((res) => {
            let {code, msg} = res;
            if (code == 200) {
              this.getList();
              this.$modal.msgSuccess("删除成功");
            } else {
              this.$modal.msgSuccess(msg);
            }
          });
        });
    },
    //单选框状态改变
    checkChange(state) {
      this.queryParams.checkSub = state;
      this.getList();
    },
    // 节点单击事件
    clickTreeNode(data) {
      this.queryParams.orgId = data.id;
      this.getList();
    },
    getRolesByOrg() {
      let params = {
        orgType: null,
      };
      findAllRole(params).then((res) => {
        this.planRoles = res.data;
      });
    },
    cleanExecOrgList() {
      this.execOrgIds = null;
      this.queryParams.execOrgList = [];
    },
    handleRolesChange(val) {
      this.selectedValues = val.toString().split(",");
    },
    getDefaultKey(key) {
      this.queryParams.orgId = key;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        orgType: null,
        typeCode: null,
        projectCode: null,
        pointCode: null,
        pageNum: 1,
        pageSize: 10,
      };

      this.getList();
    },
    //树形数据点击事件
    handleNodeClick() {
    },

  },
};
</script>
<style lang="scss" scoped></style>
