import { reactive, toRefs } from "vue";
import { Table } from "@/hooks/interface";
import { ColumnProps, SearchProps } from "@/components/LjVxeTable/interface";
import { formatAmount3 } from "@/utils/index";

/**
 * @description 表格多选数据操作
 * @param {String} rowKey 当表格可以多选时，所指定的 id
 * */
export const useFjFile = (t: any) => {
  const state = reactive<Table.defaultProps>({
    vxeTableRef: null
  });

  // 表格配置项
  const columns: ColumnProps<any>[] = [
    { type: "checkbox", fixed: "left", width: 60 },
    {
      title: "文件名称",
      field: "fileName",
      width: "auto",
      minWidth: 150,
      align: "left",
      editRender: {
        name: "$input"
      }
    },
    {
      title: "类型",
      field: "fileType",
      width: 80
    },
    {
      title: "明细id",
      field: "relidmx",
      width: 100
    },
    {
      title: "大小",
      field: "filekb",
      render: scope => {
        let _size = scope.row.filekb;
        if (_size < 1024) {
          return formatAmount3({ val: _size }) + "b";
        } else if (_size < 1024 * 1024) {
          return formatAmount3({ val: _size / 1024 }) + "Kb";
        } else if (_size < 1024 * 1024 * 1024) {
          return formatAmount3({ val: _size / 1024 / 1024 }) + "Mb";
        } else {
          return formatAmount3({ val: _size / 1024 / 1024 / 1024 }) + "Gb";
        }
      },
      align: "right",
      width: 100
    },
    {
      title: "备注",
      field: "dscrp",
      editRender: {
        name: "$input"
      }
    },
    {
      title: "建立人",
      field: "opemp"
    },
    {
      title: "建立日期",
      field: "opdate",
      format: "yyyy-MM-dd HH:mm",
      width: 150
    },
    { field: "operation", title: "操作", width: 120, fixed: "right" }
  ];

  return {
    ...toRefs(state),
    columns
  };
};
