<template>
  <div class="mainContentBox">
    <avue-crud
        ref="crudRef"
        v-model:search="search"
        v-model="form"
        :data="data"
        :option="option"
        v-model:page="page"
        @row-click="rowClick"
        @search-change="searchChange"
        @search-reset="resetChange"
        @size-change="dataList"
        @current-change="dataList"
    >
    </avue-crud>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useCrud } from "@/hooks/userCrud";

import { useCommonStoreHook } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/base/workShop",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } = Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate } = Utils; //按钮权限等工具

const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const emit = defineEmits(["workShopInfo"])
const rowClick = (row)=>{
  emit("workShopInfo", row)
}

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  search: false,
  editBtn: false,
  addBtn: false,
  viewBtn: false,
  menu: false,
  column: [
    {
      label: "车间名称",
      prop: "name",
      search: true,
    },
    {
      label: "车间负责人",
      prop: "manager",
      rules: [{
        required: true,
        message: "请选择厂区负责人",
        trigger: "blur"
      }],
      type: 'select',
      dicUrl:import.meta.env.VITE_APP_BASE_API+"/api/v1/sys/user/list",
      dicMethod:"post",
      props: {
        label: "userName", // 下拉菜单显示的字段
        value: "userName" // 下拉菜单值的字段
      },
    },
    {
      label: "车间位置",
      prop: "position",
    },
    {
      label: "所属工厂",
      prop: "factoryName",
      display:false
    },
    {
      label: "车间描述",
      prop: "remark",
    },
    {
      label: "创建人",
      prop: "creator",
      display:false
    },
    {
      label: "创建时间",
      prop: "created",
      display:false
    },
  ],
});

onMounted(() => {
  dataList();
});
</script>
