import { ColumnProps, SearchProps } from "@/components/LjVxeTable/interface";
import type { uSale } from "@/typings/modules/sale";
import { Table } from "@/hooks/interface/index";
import { useUserStore } from "@/stores/modules/user";
import { floatSub, floatAdd, floatMul, floatDiv, formatFixedNumber } from "@/utils/index";
import { reactive, toRefs } from "vue";

export const useOutrep = (t: any) => {
  const state = reactive<any>({
    initParams: {}
  });
  // 表格配置项
  const columns: ColumnProps<any>[] = [
    { title: "#", field: "pid", fixed: "left", width: 80 },
    {
      field: "yw_flag",
      title: "业务审核",
      datatype: "checkbox"
    },
    {
      field: "js1_flag",
      title: "产品补充审核",
      datatype: "checkbox"
    },
    {
      field: "js2_flag",
      title: "清单补充审核",
      datatype: "checkbox"
    },
    {
      field: "creatmtrl_flag",
      title: "生成L1产品",
      datatype: "checkbox"
    },
    {
      field: "creatmtrlqd_flag",
      title: "生成L1清单",
      datatype: "checkbox"
    },
    {
      field: "erp_mtrlcode",
      title: "L1物料编码",
      search: {
        el: "input",
        key: "arg_erp_mtrlcode",
        props: {
          placeholder: "L1物料编码"
        },
        order: 0
      }
    },
    {
      field: "deptid",
      title: "部门",
      search: {
        el: "select",
        key: "arg_deptid",
        props: {
          filterable: true,
          onChange: val => {
            state.initParams.arg_deptid = val;
          }
        },
        order: 1
      }
    },
    {
      field: "mattresscode",
      title: "报价唯一码"
    },
    {
      field: "mattressrelcode",
      title: "床垫编码"
    },
    {
      field: "mattressname",
      title: "床垫名称",
      search: {
        el: "input",
        key: "arg_search",
        titleKey: "searchKw",
        props: {
          placeholder: "唯一码/编码/名称"
        },
        order: 0
      }
    },
    {
      field: "mattresstypeid",
      title: "床垫类别"
    },
    {
      field: "mattress_width",
      title: "床垫宽/CM"
    },
    {
      field: "mattress_length",
      title: "床垫长/CM"
    },
    {
      field: "mattress_height",
      title: "床垫高/CM"
    },
    {
      field: "createby",
      title: "登记人"
    },
    {
      field: "createtime",
      title: "登记时间"
    },
    {
      field: "yw_auditingrep",
      title: "业务审核人"
    },
    {
      field: "yw_auditingdate",
      title: "业务审核时间"
    },
    {
      field: "js1_auditingrep",
      title: "产品补充审核人"
    },
    {
      field: "js1_auditingdate",
      title: "产品补充审核时间"
    },
    {
      field: "js2_auditingrep",
      title: "清单补充审核人"
    },
    {
      field: "js2_auditingdate",
      title: "清单补充审核时间"
    },
    {
      field: "creatmtrl_auditingrep",
      title: "生成L1产品人"
    },
    {
      field: "creatmtrl_auditingdate",
      title: "生成L1产品时间"
    },
    {
      field: "creatmtrlqd_auditingrep",
      title: "生成L1清单人"
    },
    {
      field: "creatmtrlqd_auditingdate",
      title: "生成L1清单时间"
    },
    {
      field: "dijia_cost",
      title: "底价"
    },
    {
      field: "yongjin",
      title: "佣金",
      render: (scope: any) => {
        let result = floatSub(floatDiv(scope.row.dijia_cost, floatSub(1, scope.row.commission - 1)), scope.row.dijia_cost);
        result = formatFixedNumber({ val: result });
        return <>{result}</>;
      }
    },
    {
      field: "taxrate",
      title: "税率"
    },
    {
      field: "fob",
      title: "FOB"
    },
    {
      field: "taxes",
      title: "税金"
    },
    {
      field: "erp_mtrlengname",
      title: "原物料编码"
    },
    {
      field: "erp_configcodetype",
      title: "ERP配置类型"
    }
  ];

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