<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model="form"
      v-model:search="search"
      :data="data"
      :page="page"
      :option="option"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @row-save="createRow"
      @row-update="updateRow"
      @row-del="deleteRow"
    >
    </avue-crud>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { getUserList } from "@/api/user/index";

// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/syn/message/org",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

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

const usersList = ref([]); //人员列表
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  editBtn: true, //是否显示编辑按钮
  delBtn: true, //是否显示删除按钮
  addBtn: true, //是否显示新增按钮
  viewBtn: false, //是否显示查看按钮
  menu: true, //是否显示操作列
  column: [
    {
      label: "组织编码",
      prop: "messageOrgCode",
      search: true,
      type: "input", //类型为单选框
      rules: [
        {
          required: true,
          message: "请输入组织编码",
          trigger: "blur",
        },
      ],
    },
    {
      label: "组织名称",
      prop: "messageOrgName",
      search: true,
      type: "input", //类型为单选框
      rules: [
        {
          required: true,
          message: "请输入组织名称",
          trigger: "blur",
        },
      ],
    },
    {
      label: "状态",
      prop: "state",
      type: "select", //类型为单选框
      search: true,
      dicData: [
        {
          label: "启用",
          value: 0,
        },
        {
          label: "禁用",
          value: 1,
        },
      ],
      value: 0,
      rules: [
        {
          required: true,
          message: "请选择状态",
          trigger: "blur",
        },
      ],
    },
    {
      label: "人员",
      prop: "receivers", // 这里是接收者的字段
      type: "select", //类型为单选框
      multiple: true, //是否多选
      filterable: true, //是否可搜索
      clearable: true, //是否可清空
      dicData: usersList, //人员列表
      props: {
        label: "nickName", //标签字段
        value: "id", //值字段
      },
      valueformat: "array", //确保值是数组格式
      overHidden: true,
    },
  ],
});

const getUsersList = async () => {
  const res = await getUserList();
  usersList.value = res.data;
};

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