<script setup lang="ts">
import ahTable from "@/components/hTable/index.vue";
import { TableConfig } from "@/components/hTable/hTable";
import { onMounted, ref } from "vue";
import { fa } from "element-plus/es/locales.mjs";
defineOptions({
  name: "School"
});

onMounted(() => {});
function searchCallback(data) {
  let c = data.Conditions.find(s => s.FieldName === "Enable");
  if (c) {
    if (c.FieldValue == "true") {
      c.FieldValue = 1;
    } else {
      c.FieldValue = 0;
    }
  }
}
const table = ref<{ initTable: (config: TableConfig) => void }>(null);
const tableData: TableConfig = {
  apiUrl: "School",
  selectColumn: false, // 列表选择
  border: false, // 是否显示表格边框
  searchCallback: searchCallback,
  search: {
    // 查询条件
    show: true,
    PageIndex: 0,
    PageSize: 20,
    OrderBy: "CreateTime", // 排序
    defaultConditions: [], // 默认查询条件
    Conditions: []
  },
  operationColumn: true, // 显示操作按钮
  operationColumnData: [
    {
      // 操作按钮
      topBtn: false, // 是头部按钮
      label: "修改",
      btnType: "edit" // 按钮类型 add edit del custom
    },
    {
      topBtn: true, // 头部按钮
      label: "新增学校",
      btnType: "custom", // 按钮类型 add edit del custom
      btnStyle: "success", // topBtn: true才生效 success danger
      custom: {
        // 按钮类型 custom 专用
        title: "新增学校", // 弹出框title
        src: "school/SchoolEdit", // 组件路径
        width: "550px", // 弹框宽度
        height: "300px" // 弹框高度
      }
    },
    {
      topBtn: false, // 头部按钮
      show: true,
      label: "删除",
      btnType: "del", // 按钮类型 add edit del 不设置则 自定义按钮
      btnStyle: "danger" // topBtn: true才生效 success danger
    }
  ],
  column: {
    // 行数据
    id: {
      label: "编号",
      search: true,
      add: false, // 字段允许添加
      edit: false, // 字段允许修改
      width: "150px"
    },
    name: {
      label: "学校名称",
      width: "300px",
      search: true,
      searchType: "Like",
      add: true, // 字段允许添加
      edit: true // 字段允许修改
    },
    loc: {
      label: "地区",
      width: "300px",
      search: true,
      custom: row => `${row.pname}-${row.cname}-${row.rname}`,
      add: true, // 字段允许添加
      edit: true // 字段允许修改
    },
    enable: {
      label: "启用",
      type: "dropdown",
      search: true,
      add: true, // 字段允许添加
      edit: true, // 字段允许修改
      setting: {
        datasource: [
          { value: "true", text: "√" },
          { value: "false", text: "X" }
        ]
      }
    }
  },
  data: [],
  pageData: {
    total: 0
  },
  selectRows: []
};
</script>

<template>
  <div><ahTable ref="table" :tableConfig="tableData" /></div>
</template>
