<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
    >
      <template #menu-left="{ size }">
        <el-button
          type="primary"
          icon="el-icon-plus"
          :size="size"
          @click="addRow"
          >新增</el-button
        >
        <el-button
          :disabled="toDeleteIds.length < 1"
          type="danger"
          icon="el-icon-delete"
          :size="size"
          @click="multipleDelete"
          >删除</el-button
        ></template
      >
      <template #menu="{ row, index, type }">
        <el-button
          @click="editSkills(row)"
          icon="el-icon-edit"
          text
          type="primary"
          >编辑</el-button
        >
        <el-button
          @click="viewSkills(row)"
          icon="el-icon-view"
          text
          type="primary"
          >查看</el-button
        >
      </template>
    </avue-crud>
    <el-dialog
      v-model="dialog.visible"
      :title="dialog.title"
      width="800px"
      :destroy-on-close="true"
      @close="addClose"
    >
      <user-skill :dialog="dialog" />
    </el-dialog>

    <el-dialog
      v-model="editDialog.visible"
      :title="editDialog.title"
      width="800px"
      :destroy-on-close="true"
      @close="editClose"
    >
      <editSkill
        :editDialog="editDialog"
        :skillId="editUser.id"
        :postId="editUser.postId"
      />
    </el-dialog>
    <el-dialog
      v-model="viewDialog.visible"
      :title="viewDialog.title"
      width="800px"
      :destroy-on-close="true"
      @close="viewDialog.visible = false"
    >
      <viewSkill
        :viewDialog="viewDialog"
        :skillId="viewUser.id"
        :postId="viewUser.postId"
      />
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import { useCommonStoreHook, useDictionaryStore } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
import editSkill from "@/views/base/skill/components/edit-skill.vue";
import viewSkill from "@/views/base/skill/components/view-skill.vue";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
// 数据字典相关
const { dicts } = useDictionaryStore();

const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const dialog = reactive({
  title: "员工技能",
  visible: false,
});

const editDialog = reactive({
  title: "编辑",
  visible: false,
});

const viewDialog = reactive({
  title: "查看",
  visible: false,
});

const addClose = () => {
  dialog.visible = false;
  dataList();
};
const editClose = () => {
  editDialog.visible = false;
  dataList();
};
const addRow = () => {
  dialog.visible = true;
};
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/sys/employeeSkill",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
// checkBtnPerm(ButtonPermKeys.PLAN.BTNS.order_add) :permission="permission"
// const permission = reactive({
//   delBtn: checkPerm(buttonPermission.PLAN.BTNS.order_del),
//   addBtn: checkPerm(buttonPermission.PLAN.BTNS.order_add),
//   editBtn: checkPerm(buttonPermission.PLAN.BTNS.order_edit),
//   menu: true,
// });

const ctableRef = ref(null); //crudRef.value 获取avue-crud对象
const router = useRouter();

onMounted(() => {
  // console.log("crudRef", crudRef)
  dataList();
});

/**
 * 上传excel相关
 */
const uploadRef = ref(null);
const uploadFinished = () => {
  // 上传完成后的刷新操作
  page.currentPage = 1;
  dataList();
};
const importExcelData = () => {
  if (uploadRef.value) {
    uploadRef.value.show("/api/v1/plan/order/import");
  }
};
const editUser = ref(null);
const viewUser = ref(null);
const editSkills = (row) => {
  editDialog.visible = true;
  editUser.value = row;
};
const viewSkills = (row) => {
  viewDialog.visible = true;
  viewUser.value = row;
};
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  selection: true,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  column: [
    {
      label: "所属机构",
      prop: "deptId",
      hide: true,
      search: true,
      filterable: true,
      type: "select",
      overHidden: true,
      dicUrl: dictDataUtil.dept_list_url,
      dicMethod: "post",
      props: { label: "deptName", value: "id" },
    },
    {
      label: "所属机构",
      prop: "deptName",
      width: 200,
      overHidden: true,
      disabled: true,
    },
    {
      label: "员工姓名",
      prop: "userName",
      width: 140,
      overHidden: true,
      search: true,
      rules: [
        {
          required: true,
          search: true,
          message: "请选择员工姓名",
          trigger: "blur",
        },
      ],
    },
    {
      label: "员工编号",
      prop: "employeeCode",
      search: true,
      disabled: true,
    },
    {
      label: "岗位",
      prop: "postId",
      search: true,
      filterable: true,
      type: "select",
      overHidden: true,
      dicUrl: dictDataUtil.post_list_url,
      dicMethod: "post",
      props: { label: "postName", value: "id" },
    },
    //{ label: "部门", prop: "deptName", overHidden: true, disabled: true },
    {
      label: "分数",
      prop: "scopes",
      filterable: true,
    },
  ],
});
const onSelectedFinish = () => {};

// 数据保存成功需要更新列表
</script>
