import { ColumnProps } from "@/components/LjVxeTable/interface";
import type { uSale } from "@/typings/modules/sale";
import { reactive, ref, computed, toRefs, nextTick } from "vue";

interface mtrlwareSaletaskSeletorProps {
  /**
   * @description 已选列表
   */
  selectList: any[];
  LjTableRef: any;
}

export const useMtrlwareSaletask = (t: any) => {
  const state = reactive<mtrlwareSaletaskSeletorProps>({
    /**
     * @description 已选列表
     */
    selectList: [],
    LjTableRef: null
  });

  // const LjTableRef = ref();

  const columnsSim: ColumnProps<uSale.u_saletask>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    {
      field: "mtrlcode",
      table: "u_mtrldef",
      title: "产品编码"
    },
    {
      field: "mtrlname",
      table: "u_mtrldef",
      title: "产品名称"
    },
    {
      field: "mtrlmode",
      table: "u_mtrldef",
      title: "规格"
    },
    {
      field: "unit",
      table: "u_mtrldef",
      title: "单位"
    },
    {
      field: "noallocqty",
      title: "库存数"
    },
    {
      field: "minqty",
      table: "u_mtrldef",
      title: "库存下限"
    },
    {
      field: "mtrltype",
      table: "u_mtrldef",
      title: "物料类别"
    },
    {
      field: "mtrlsectype",
      table: "u_mtrldef",
      title: "自定义1"
    },
    {
      field: "zxmtrlmode",
      table: "u_mtrldef",
      title: "自定义2"
    },
    {
      field: "prdpackcode",
      table: "u_mtrldef",
      title: "包装单位"
    },
    {
      field: "packqty",
      table: "u_mtrldef",
      title: "包装数量"
    },
    {
      field: "isuse",
      table: "u_mtrldef",
      title: "状态"
    },
    {
      field: "mtrlprp",
      table: "u_mtrldef",
      title: "物料属性"
    },
    {
      field: "ifcustom",
      table: "u_mtrldef",
      title: "特殊订造产品"
    },
    {
      field: "u_cusmtrlname_cusmtrlcode",
      title: "客户物料别名编码"
    },
    {
      field: "u_cusmtrlname_cusmtrlname",
      title: "客户产品别名"
    },
    {
      field: "u_mtrldef_usermtrlmode",
      title: "自定义3"
    },
    {
      field: "mtrlengname",
      title: "英文名称"
    },
    {
      field: "configcode",
      title: "配置码"
    },
    {
      field: "configname",
      title: "配置说明"
    },
    {
      field: "mtrlcolor",
      title: "产品颜色"
    },
    {
      field: "simplename",
      title: "客户简称"
    },
    {
      field: "dscrp",
      title: "产品备注"
    }
  ];

  const columnsCus: ColumnProps<uSale.u_saletask>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    {
      field: "pid",
      title: "序"
    },
    {
      field: "isuse",
      table: "u_mtrldef",
      title: "状态"
    },
    {
      field: "mtrlcode",
      table: "u_mtrldef",
      title: "产品编码"
    },
    {
      field: "mtrlname",
      table: "u_mtrldef",
      title: "产品名称"
    },
    {
      field: "mtrlmode",
      table: "u_mtrldef",
      title: "规格"
    },
    {
      field: "unit",
      table: "u_mtrldef",
      title: "单位"
    },
    {
      field: "noallocqty",
      title: "库存数"
    },
    {
      field: "willinqty",
      title: "计划在产数"
    },
    {
      field: "bhqty",
      title: "订单未发货数"
    },
    {
      field: "real_noallocqty",
      title: "参考库存"
    },
    {
      field: "minqty",
      table: "u_mtrldef",
      title: "库存下限"
    },
    {
      field: "fprice",
      table: "u_cus_price",
      title: "最新销售价"
    },
    {
      field: "zqrate",
      table: "u_cus_price",
      title: "最新销售折扣"
    },
    {
      field: "fprice_bj",
      table: "u_cus_price",
      title: "最新报价"
    },
    {
      field: "zqrate_bj",
      table: "u_cus_price",
      title: "最新报价折扣"
    },
    {
      field: "mtrltype",
      table: "u_mtrldef",
      title: "物料类别"
    },
    {
      field: "mtrlsectype",
      table: "u_mtrldef",
      title: "自定义1"
    },
    {
      field: "zxmtrlmode",
      table: "u_mtrldef",
      title: "自定义2"
    },
    {
      field: "usermtrlmode",
      table: "u_mtrldef",
      title: "自定义3"
    },
    {
      field: "prdpackcode",
      table: "u_mtrldef",
      title: "包装单位"
    },
    {
      field: "packqty",
      table: "u_mtrldef",
      title: "包装数量"
    },
    {
      field: "mtrlprp",
      table: "u_mtrldef",
      title: "物料属性"
    },
    {
      field: "ifcustom",
      table: "u_mtrldef",
      title: "标准化产品"
    },
    {
      field: "dftwrkGrpid",
      table: "u_mtrldef",
      title: "默认生产车间"
    },
    {
      field: "status",
      table: "u_cus_price",
      title: "配置"
    },
    {
      field: "woodcode",
      table: "u_cus_price",
      title: "配置1"
    },
    {
      field: "pcode",
      table: "u_cus_price",
      title: "配置2"
    },
    {
      field: "cusmtrlname",
      table: "u_cusmtrlname",
      title: "客户产品别名"
    },
    {
      field: "qty",
      table: "u_cus_price",
      title: "数量下限"
    },
    {
      field: "qty1",
      table: "u_cus_price",
      title: "数量上限"
    },
    {
      field: "mtrlengname",
      table: "u_mtrldef",
      title: "英文名称"
    },
    {
      field: "configcode",
      table: "u_mtrldef",
      title: "配置码"
    },
    {
      field: "configname",
      table: "u_mtrldef",
      title: "配置说明"
    },
    {
      field: "mtrlcolor",
      table: "u_mtrldef",
      title: "产品颜色"
    },
    {
      field: "simplename",
      table: "u_mtrldef",
      title: "客户简称"
    },
    {
      field: "dscrp",
      table: "u_mtrldef",
      title: "产品备注"
    },
    {
      field: "saleptqty",
      title: "其它订单配套数"
    },
    {
      field: "freeptqty",
      title: "无订单配套数"
    },
    {
      field: "notptqty",
      title: "不配套数"
    }
  ];

  const columnsHis: ColumnProps<uSale.u_saletask>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    {
      title: "序",
      field: "pid"
    },
    {
      title: "订单号",
      field: "taskcode",
      table: "u_saletask"
    },
    {
      title: "订单相关号",
      field: "relcode",
      table: "u_saletask"
    },
    {
      title: "产品编码",
      field: "mtrlcode",
      table: "u_mtrldef"
    },
    {
      title: "产品名称",
      field: "mtrlname"
    },
    {
      title: "物料类别",
      field: "mtrltype"
    },
    {
      title: "规格",
      field: "mtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "配置",
      field: "STATUS",
      table: "u_saletaskmx"
    },
    {
      title: "配置1",
      field: "woodcode",
      table: "u_saletaskmx"
    },
    {
      title: "配置2",
      field: "pcode",
      table: "u_saletaskmx"
    },
    {
      title: "数量",
      field: "saleqty"
    },
    {
      title: "分组",
      field: "outtypestr",
      table: "u_saletaskmx"
    },
    {
      title: "单位",
      field: "unit",
      table: "u_mtrldef"
    },
    {
      title: "辅数",
      field: "addqty",
      table: "u_saletaskmx"
    },
    {
      title: "转换率",
      field: "rate"
    },
    {
      title: "单价",
      field: "enprice",
      table: "u_saletaskmx"
    },
    {
      title: "折扣",
      field: "rebate",
      table: "u_saletaskmx"
    },
    {
      title: "税率",
      field: "taxrate",
      table: "u_saletaskmx"
    },
    {
      title: "交货日期",
      field: "requiredate",
      table: "u_saletaskmx"
    },
    {
      title: "投影面积",
      field: "area"
    },
    {
      title: "原币实价",
      field: "bateprice"
    },
    {
      title: "金额",
      field: "emamt"
    },
    {
      title: "含税折前原币金额",
      field: "tamt"
    },
    {
      title: "人民币单价",
      field: "fprice",
      table: "u_saletaskmx"
    },
    {
      title: "人民币实价",
      field: "price",
      table: "u_saletaskmx"
    },
    {
      title: "人民币金额",
      field: "amt"
    },
    {
      title: "不含税原币单价",
      field: "enprice_tax"
    },
    {
      title: "不含税原币折后单价",
      field: "bateprice_tax"
    },
    {
      title: "税额",
      field: "taxamt_cmp"
    },
    {
      title: "不含税折后原币金额",
      field: "enamt_tax"
    },
    {
      title: "不含税人民币单价",
      field: "fprice_tax"
    },
    {
      title: "不含税人民币金额",
      field: "famt_tax"
    },
    {
      title: "最新售价",
      field: "nprice",
      table: "u_saletaskmx"
    },
    {
      title: "明细备注",
      field: "mxdscrp",
      table: "u_saletaskmx"
    },
    {
      title: "明细备注2",
      field: "mxdscrp2",
      table: "u_saletaskmx"
    },
    {
      title: "生产批号",
      field: "mtrlcuscode",
      table: "u_saletaskmx"
    },
    {
      title: "单价公式(双击编辑)",
      field: "priceformula",
      table: "u_saletaskmx"
    },
    {
      title: "定价",
      field: "dftsaleprice",
      table: "u_saletaskmx"
    },
    {
      title: "已发货数",
      field: "consignedqty"
    },
    {
      title: "已排产数",
      field: "AssignQty",
      table: "u_saletaskmx"
    },
    {
      title: "自定义1",
      field: "mtrlsectype",
      table: "u_mtrldef"
    },
    {
      title: "自定义2",
      field: "zxmtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "自定义3",
      field: "usermtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "净重",
      field: "net_weight",
      table: "u_saletaskmx"
    },
    {
      title: "毛重",
      field: "gross_weight",
      table: "u_saletaskmx"
    },
    {
      title: "体积",
      field: "cubage",
      table: "u_saletaskmx"
    },
    {
      title: "总净重",
      field: "sumnetweight"
    },
    {
      title: "总毛重",
      field: "sumgrossweight"
    },
    {
      title: "总体积",
      field: "sumcubage"
    },
    {
      title: "包装数",
      field: "u_saletaskmx_packqty"
    },
    {
      title: "包装单位",
      field: "prdpackcode",
      table: "u_mtrldef"
    },
    {
      title: "单包装数",
      field: "packqty",
      table: "u_mtrldef"
    },
    {
      title: "总包装数",
      field: "sumpackqty"
    },
    {
      title: "产能总量",
      field: "capacity",
      table: "u_saletaskmx"
    },
    {
      title: "计划价",
      field: "planprice",
      table: "u_mtrldef"
    },
    {
      title: "经验生产周期(天)",
      field: "expday",
      table: "u_mtrldef"
    },
    {
      title: "英文名称",
      field: "mtrlengname",
      table: "u_mtrldef"
    },
    {
      title: "终止数",
      field: "stopqty",
      table: "u_saletaskmx"
    },
    {
      title: "已发货通知数",
      field: "saleoutqty",
      table: "u_saletaskmx"
    },
    {
      title: "终止人",
      field: "stopemp",
      table: "u_saletaskmx"
    },
    {
      title: "终止时间",
      field: "stopdate",
      table: "u_saletaskmx"
    },
    {
      title: "物料清单",
      field: "pfcode",
      table: "u_saletaskmx"
    },
    {
      title: "终止原因",
      field: "stopreason",
      table: "u_saletaskmx"
    },
    {
      title: "补件审",
      field: "bjflag",
      table: "u_saletaskmx"
    },
    {
      title: "补件审人",
      field: "bjemp",
      table: "u_saletaskmx"
    },
    {
      title: "补件审时间",
      field: "bjdate",
      table: "u_saletaskmx"
    },
    {
      title: "调度审",
      field: "ddflag",
      table: "u_saletaskmx"
    },
    {
      title: "调度审人",
      field: "ddemp",
      table: "u_saletaskmx"
    },
    {
      title: "调度审时间",
      field: "dddate",
      table: "u_saletaskmx"
    },
    {
      title: "库存已分配数",
      field: "fpqty",
      table: "u_saletaskmx"
    },
    {
      title: "参考库存分配数",
      field: "mqty",
      table: "u_saletaskmx"
    },
    {
      title: "安排自制生产数",
      field: "pqty",
      table: "u_saletaskmx"
    },
    {
      title: "安排采购数",
      field: "bqty",
      table: "u_saletaskmx"
    },
    {
      title: "安排外协数",
      field: "wqty",
      table: "u_saletaskmx"
    },
    {
      title: "安排来料加工生产数",
      field: "lqty",
      table: "u_saletaskmx"
    },
    {
      title: "配置修改备注",
      field: "changedscrp",
      table: "u_saletaskmx"
    },
    {
      title: "报价单号",
      field: "quotecode",
      table: "u_saletaskmx"
    },
    {
      title: "明细附件数量",
      field: "fjcnt"
    },
    {
      title: "人民币未打折金额",
      field: "amt_norebate"
    },
    {
      title: "人民币打折金额",
      field: "amt_rebate"
    },
    {
      title: "包件产品",
      field: "ifpackpro",
      table: "u_mtrldef"
    },
    {
      title: "包件",
      field: "ifpack",
      table: "u_mtrldef"
    },
    {
      title: "配置码",
      field: "configcode",
      table: "u_mtrldef"
    },
    {
      title: "配置说明",
      field: "configname",
      table: "u_mtrldef"
    },
    {
      title: "颜色",
      field: "mtrlcolor",
      table: "u_mtrldef"
    },
    {
      title: "标准化产品",
      field: "ifcustom",
      table: "u_mtrldef"
    },
    {
      title: "客户简称",
      field: "simplename",
      table: "u_mtrldef"
    },
    {
      title: "发货完成时间",
      field: "accomplishdate",
      table: "u_saletaskmx"
    },
    {
      title: "目标折扣",
      field: "porebate",
      table: "u_saletaskmx"
    },
    {
      title: "备忘摘要",
      field: "remindmxdscrp",
      table: "u_saletaskmx"
    },
    {
      title: "销售限价",
      field: "limitprice",
      table: "u_saletaskmx"
    },
    {
      title: "畅销类型",
      field: "saletype",
      table: "u_mtrldef"
    },
    {
      title: "终止金额",
      field: "stopamt"
    }
  ];

  const columnsMtrlware: ColumnProps<uSale.u_saletask>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    {
      title: "状态",
      field: "isuse",
      table: "u_mtrldef"
    },
    {
      title: "产品编码",
      field: "mtrlcode",
      table: "u_mtrldef"
    },
    {
      title: "产品名称",
      field: "mtrlname",
      table: "u_mtrldef"
    },
    {
      title: "规格",
      field: "mtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "单位",
      field: "unit",
      table: "u_mtrldef"
    },
    {
      title: "订货数",
      field: "taskqty"
    },
    {
      title: "库存数",
      field: "noallocqty"
    },
    {
      title: "可装数",
      field: "canuseqty"
    },
    {
      title: "已分配数",
      field: "allocqty"
    },
    {
      title: "库存下限",
      field: "minqty",
      table: "u_mtrldef"
    },
    {
      title: "物料类别",
      field: "mtrltype",
      table: "u_mtrldef"
    },
    {
      title: "包装单位",
      field: "prdpackcode",
      table: "u_mtrldef"
    },
    {
      title: "包装数量",
      field: "packqty",
      table: "u_mtrldef"
    },
    {
      title: "物料属性",
      field: "mtrlprp",
      table: "u_mtrldef"
    },
    {
      title: "标准化产品",
      field: "ifcustom",
      table: "u_mtrldef"
    },
    {
      title: "默认生产车间",
      field: "dftwrkGrpid",
      table: "u_mtrldef"
    },
    {
      title: "配置",
      field: "u_cus_price_status"
    },
    {
      title: "配置1",
      field: "u_cus_price_woodcode"
    },
    {
      title: "配置2",
      field: "u_cus_price_pcode"
    },
    {
      title: "生产批号",
      field: "plancode"
    },
    {
      title: "自定义1",
      field: "mtrlsectype",
      table: "u_mtrldef"
    },
    {
      title: "自定义2",
      field: "zxmtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "自定义3",
      field: "usermtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "客户产品别名编码",
      field: "u_cusmtrlname_cusmtrlcode"
    },
    {
      title: "客户产品别名",
      field: "u_cusmtrlname_cusmtrlname"
    },
    {
      title: "最新销售价",
      field: "u_cus_price_fprice"
    },
    {
      title: "最新销售折扣",
      field: "u_cus_price_zqrate"
    },
    {
      title: "最新报价",
      field: "u_cus_price_fprice_bj"
    },
    {
      title: "最新报价折扣",
      field: "u_cus_price_zqrate_bj"
    },
    {
      title: "英文名称",
      field: "mtrlengname"
    },
    {
      title: "配置码",
      field: "configcode"
    },
    {
      title: "配置说明",
      field: "configname"
    },
    {
      title: "产品颜色",
      field: "mtrlcolor"
    },
    {
      title: "客户简称",
      field: "simplename"
    },
    {
      title: "产品备注",
      field: "dscrp"
    },
    {
      title: "有订单配套数",
      field: "saleptqty"
    },
    {
      title: "无订单配套数",
      field: "freeptqty"
    },
    {
      title: "不配套数",
      field: "notptqty"
    },
    {
      title: "配置-默认",
      field: "status_config"
    },
    {
      title: "配置1-默认",
      field: "woodcode_config"
    },
    {
      title: "配置2-默认",
      field: "pcode_config"
    },
    {
      title: "来源",
      field: "mtrlorigin"
    },
    {
      title: "产品批号",
      field: "mtrlcuscode"
    }
  ];

  const columnsPrice: ColumnProps<uSale.u_saletask>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    {
      title: "标准",
      field: "dftflag",
      table: "u_sale_price_list"
    },
    {
      title: "价格表名称",
      field: "listname",
      table: "u_sale_price_list"
    },
    {
      title: "客户默认",
      field: "custdft"
    },
    {
      title: "产品类型",
      field: "mtrltype",
      table: "u_mtrldef"
    },
    {
      title: "产品编码",
      field: "mtrlcode",
      table: "u_mtrldef"
    },
    {
      title: "产品名称",
      field: "mtrlname",
      table: "u_mtrldef"
    },
    {
      title: "规格",
      field: "mtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "单位",
      field: "unit",
      table: "u_mtrldef"
    },
    {
      title: "含税价",
      field: "price"
    },
    {
      title: "税率",
      field: "tax",
      table: "u_sale_price_mx"
    },
    {
      title: "不含税价",
      field: "price_notax",
      table: "u_sale_price_mx"
    },
    {
      title: "折扣",
      field: "rebate",
      table: "u_sale_price_mx"
    },
    {
      title: "上次价",
      field: "hisprice",
      table: "u_sale_price_mx"
    },
    {
      title: "设定售价",
      field: "lmsaleprice",
      table: "u_mtrldef"
    },
    {
      title: "配置",
      field: "status",
      table: "u_sale_price_mx"
    },
    {
      title: "配置1",
      field: "woodcode",
      table: "u_sale_price_mx"
    },
    {
      title: "配置2",
      field: "pcode",
      table: "u_sale_price_mx"
    },
    {
      title: "数量下限",
      field: "saleqty",
      table: "u_sale_price_mx"
    },
    {
      title: "数量上限",
      field: "saleqty1",
      table: "u_sale_price_mx"
    },
    {
      title: "备注",
      field: "dscrp",
      table: "u_sale_price_mx"
    },
    {
      title: "单价公式(双击编辑)",
      field: "pricestr",
      table: "u_sale_price_mx"
    },
    {
      title: "折扣公式(双击编辑)",
      field: "rebatestr",
      table: "u_sale_price_mx"
    },
    {
      title: "销售价格限价策略",
      field: "price_ifpz",
      table: "u_mtrldef"
    },
    {
      title: "审核时间",
      field: "auditingdate",
      table: "u_sale_price_mx"
    },
    {
      title: "审核人",
      field: "auditingemp",
      table: "u_sale_price_mx"
    },
    {
      title: "自定义1",
      field: "mtrlsectype",
      table: "u_mtrldef"
    },
    {
      title: "自定义2",
      field: "zxmtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "净重",
      field: "net_weight",
      table: "u_mtrldef"
    },
    {
      title: "毛重",
      field: "gross_weight",
      table: "u_mtrldef"
    },
    {
      title: "体积",
      field: "cubage",
      table: "u_mtrldef"
    },
    {
      title: "包装单位",
      field: "prdpackcode",
      table: "u_mtrldef"
    },
    {
      title: "包装数量",
      field: "packqty",
      table: "u_mtrldef"
    },
    {
      title: "英文名称",
      field: "mtrlengname",
      table: "u_mtrldef"
    },
    {
      title: "修改人",
      field: "updateemp",
      table: "u_sale_price_mx"
    },
    {
      title: "修改时间",
      field: "updatetime",
      table: "u_sale_price_mx"
    },
    {
      title: "有效",
      field: "isuse",
      table: "u_mtrldef"
    },
    {
      title: "客户简称",
      field: "simplename",
      table: "u_mtrldef"
    },
    {
      title: "颜色",
      field: "mtrlcolor",
      table: "u_mtrldef"
    },
    {
      title: "配置说明",
      field: "configname",
      table: "u_mtrldef"
    },
    {
      title: "包件产品",
      field: "ifpackpro",
      table: "u_mtrldef"
    },
    {
      title: "包件",
      field: "ifpack",
      table: "u_mtrldef"
    },
    {
      title: "自定义3",
      field: "usermtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "物料资料备注",
      field: "dscrp",
      table: "u_mtrldef"
    },
    {
      title: "子件备注",
      field: "zj_dscrp"
    },
    {
      title: "财审",
      field: "secflag",
      table: "u_sale_price_mx"
    },
    {
      title: "财审时间",
      field: "secauditdate",
      table: "u_sale_price_mx"
    },
    {
      title: "财审人",
      field: "secauditemp",
      table: "u_sale_price_mx"
    }
  ];

  const mtrloriginOptions = [
    {
      label: "全部来源",
      value: -1
    },
    {
      label: "自制",
      value: 0
    },
    {
      label: "客户来源",
      value: 6
    },
    {
      label: "采购",
      value: 2
    },
    {
      label: "外协",
      value: 3
    }
  ];
  const mtrlprpOptions = [
    {
      label: "全部",
      value: -1
    },
    {
      label: "成品",
      value: 0
    },
    {
      label: "半成品",
      value: 1
    },
    {
      label: "原料",
      value: 2
    },
    {
      label: "其他",
      value: 8
    }
  ];

  const clearCheckbox = () => {
    const $table = state.LjTableRef.element;
    if ($table) {
      $table.clearCheckboxRow();
    }
  };

  return {
    ...toRefs(state),
    columnsSim,
    columnsCus,
    columnsHis,
    columnsMtrlware,
    columnsPrice,
    mtrloriginOptions,
    mtrlprpOptions,
    clearCheckbox
  };
};
