<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--机构数据-->
      <el-col :span="4" :xs="24">
        <org-tree
          v-model="queryParams.orgId"
          @defaultKey="getDefaultKey"
          @checkChange="checkChange"
          @click="clickTreeNode"
        ></org-tree>
      </el-col>

      <el-col :span="20" :xs="24">
        <!--    搜索条件    -->
        <el-form
          :model="queryParams"
          ref="search"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="100px"
        >
          <el-form-item prop="name" label="履职库名称">
            <el-input
              v-model="queryParams.name"
              :maxlength="50"
              placeholder="请输入履职库名称"
              clearable
            />
          </el-form-item>
          <el-form-item prop="type" label="履职库类型">
            <el-select
              prop="ruleTypeId"
              label="履职库类型"
              v-model="queryParams.type"
              placeholder="请选择履职库类型"
              clearable
            >
              <el-option
                v-for="dict in dict.type.rule_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item prop="orgType" label="履职机构类型">
            <el-select
              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>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="refresh"
              v-hasPermi="['resumption:rule:query']"
              >搜索</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="['resumption:rule:add']"
              >新增</el-button
            >
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:user:edit']"
              >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:user:remove']"
              >删除</el-button
            > 
          </el-col>-->

          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
            :columns="columns"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="pageData"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="index"
            label="序号"
            v-if="columns[0].visible"
          ></el-table-column>
          <el-table-column
            prop="name"
            label="履职库名称"
            v-if="columns[1].visible"
          ></el-table-column>
          <el-table-column
            prop="typeName"
            label="履职库类型"
            v-if="columns[2].visible"
          >
            <template slot-scope="r"
              >{{ getLabel(dict.type.rule_type, r.row.type) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="orgType"
            label="履职机构类型"
            v-if="columns[3].visible"
          >
            <template slot-scope="r"
              >{{ getLabel(dict.type.sys_org_type, r.row.orgType) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="orgName"
            label="发布机构"
            v-if="columns[4].visible"
          ></el-table-column>
          <el-table-column prop="status" label="状态" v-if="columns[5].visible">
            <template slot-scope="r">
              <span>{{ getLabel(dict.type.plan_status,r.row.status) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="remark"
            label="备注"
            v-if="columns[6].visible"
          ></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="r">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="onEdit(r.row.id)"
                v-hasPermi="['resumption:rule:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="onDel(r.row.id)"
                v-hasPermi="['resumption:rule:remove']"
                class="red-btn"
                >删除</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>
    </el-row>
    <dialog-edit
      ref="editDialog"
      @success="getList()"
      :orgTypeOptions="dict.type.sys_org_type"
      :ruleTypeOptions="dict.type.rule_type"
      :statusOptions="dict.type.plan_status"
    ></dialog-edit>
  </div>
</template>

<script>
import OrgTree from "@/components/orgTree";
import { mapState, mapMutations } from "vuex";
import DialogEdit from "./dialog.edit";
import * as api from "@/api/resumption/rule";
import { getLabel } from "./../../commonOption";

export default {
  name: "ruletype",
  dicts: ["sys_org_type", "rule_type","plan_status"],
  components: {
    DialogEdit,
    OrgTree,
  },
  data() {
    const { params, query } = this.$route;
    return {
      isShow: false,
      loading: false,
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      total: 0,
      queryParams: {
        orgId: null,
        name: null,
        type: null,
        orgType: null,
        pageNum: 1,
        pageSize: 10,
        ...query,
      },
      pageData: [],
      // 列信息
      columns: [
        { key: 0, label: `序号`, visible: true },
        { key: 1, label: `履职库名称`, visible: true },
        { key: 2, label: `履职库类型`, visible: true },
        { key: 3, label: `履职机构类型`, visible: true },
        { key: 4, label: `发布机构`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `备注`, visible: true },
      ],
    };
  },
  props: {},
  watch: {},
  computed: {
    ...mapState([]),
  },
  methods: {
    ...mapMutations([]),
    getLabel,
    refresh() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      console.info(this.dict.type);
      api
        .list(this.queryParams)
        .then((response) => {
          this.pageData = response.rows;
          this.total = response.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    getDefaultKey(key) {
      this.queryParams.orgId = key;
      this.getList();
    },
    handleAdd(id, other = {}) {
      this.$refs.editDialog.show(id, other);
    },
    onEdit(id, other = {}) {
      this.$refs.editDialog.show(id, other);
    },
    async onDel(id) {
      await api.delRule(id);
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("search");
      // this.queryParams.orgId = undefined;
      // this.$refs.tree.setCurrentKey(null);
      this.getList();
    },
    //单选框状态改变
    checkChange(state) {
      this.queryParams.checkSub = state;
      this.getList();
    },
    // 节点单击事件
    clickTreeNode(data) {
      this.queryParams.orgId = data.id;
      this.getList();
    }
    //apimark//
  },
  mounted() {},
};
</script>

<style lang="scss" scoped>
.brand {
}
</style>
