<template>
  <div class="app-container">
    
      <!--用户数据-->
      <el-col>
        <!--    搜索条件    -->
        <div class="main-search-box">
          <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          
        >
          <el-form-item label="机构类型">
            <el-select
              @change="cleanExecOrgList"
              prop="orgType"
              label="机构类型"
              v-model="queryParams.orgType"
              placeholder="请选择机构类型"
              clearable
            >
              <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-form-item>
              <el-select
                v-model="queryParams.projectCode"
                placeholder="请选择指标项目"
                clearable
                @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>
          <el-form-item label="指标要点">
            <el-form-item>
              <el-select
                v-model="queryParams.pointCode"
                placeholder="请选择指标要点"
                clearable
              >
                <el-option
                  v-for="item in targetListGrandson"
                  :key="item.id"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </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"
              v-hasPermi="['system:user:add']"
              >新增</el-button
            >
          </el-col>
        </el-row>
        </div>
        
        <el-table
          border
          height="650"
          size="small"
          v-loading="loading"
          :data="dataList"
          align="center"
          fixed
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            label="序号"
            type="index"
            width="100"
          ></el-table-column>
          <el-table-column label="机构类型" prop="orgTypeText" />
          <el-table-column label="指标分类" prop="typeCodeText" />
          <el-table-column label="指标项目" prop="projectCodeText" />
          <el-table-column label="指标要点" prop="pointCodeText" />
          <el-table-column
            label="扣分方式"
            prop="evaluateCycle"
            :formatter="formatterScore"
          />
          <el-table-column label="分值" prop="score" />

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

    <editEvaluate ref="Evaluate" :targetList="targetList" @success="getList()"></editEvaluate>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { findAllRole } from "@/api/system/role";
import { list, getTargetList ,delelteEvaluate} from "@/api/evaluateRule/rule.js";
import OrgTree from "@/components/orgTree";
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: {
    OrgTree,
    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>
