<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-save="createRow"
      @row-del="deleteRow"
      @row-update="updateRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
      :before-open="onBeforeOpen"
    >
    </avue-crud>
  </div>
</template>
<script setup lang="ts">
import {ref, getCurrentInstance} from "vue";
import {useCrud} from "@/hooks/userCrud";

// 传入一个url，后面不带/
const {form, data, option, search, page, toDeleteIds, Methords, Utils} =
  useCrud({
    src: "/api/v1/attendanceStatisticsLog",
  });
const {dataList, createRow, updateRow, deleteRow, searchChange, resetChange} =
  Methords; //增删改查
const {selectionChange, multipleDelete} = Methords; //选中和批量删除事件
const {checkBtnPerm, downloadTemplate, exportData} = Utils; //按钮权限等工具
const deptTypes = ref([]);
const crudRef = ref(null); //crudRef.value 获取avue-crud对象

onMounted(() => {
  // console.log("crudRef", crudRef)
  dataList();
});
const multipleRow = ref(true);
const productionLineRef = ref(null);
const startCreat = () => {
  productionLineRef.value?.mergeOption({
    selection: true,
    reserveSelection: true,
  });
};
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: false,
  selection: false,
  menu: false,
  border: true,
  index: true,
  delBtn: false,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  rowKey: "id",
  column: [
    // {
    //   label: "择班组信息",
    //   prop: "toSelect",
    //   hide: true,
    //   type: "tree",
    //   dicUrl: import.meta.env.VITE_APP_BASE_API + "/api/v1/sys/dept/orgTree",
    //   // dicMethod: "post",
    //   span: 24,
    //   props: {
    //     label: "deptName", // 下拉菜单显示的字段
    //     value: "deptCode", // 下拉菜单值的字段
    //   },
    //   change: (row) => {
    //     if (row && row.item) {
    //       form.value.deptName = row.item.deptName;
    //     }
    //   },
    // },
    {
      label: "班组名称",
      prop: "deptName",
      type: "select",
      dicUrl: import.meta.env.VITE_APP_BASE_API + "/api/v1/sys/dept/deptList?parentId=10",
      props: {
        label: "deptName",
        value: "deptName",
      },
      change: (row) => {
        if (row && row.item) {
          form.value.deptName = row.item.deptName;
          form.value.deptNum = row.item.deptNum;
        }
      },
      search: true,
      overHidden: true,
      rules: [
        {
          required: true,
          message: "请输入deptName",
          trigger: "blur",
        },
      ],
    },
    {
      label: "用户名称",
      prop: "userName",
      search: true,
      overHidden: true,
      disabled: true,
    },
    {
      label: "员工编号",
      prop: "userCode",
      search: true,
      overHidden: true
    },
    {
      label: "打卡时间",
      prop: "created",
      display: false,
    },
  ],
});

const tableData = ref<any[]>([]); //选中的行
const onBeforeOpen = (done) => {
  console.log("before open");
  tableData.value = [];
  form.value.dtos = [];
  done();
};

</script>
