import { ref, reactive, computed, toRefs, nextTick, inject } from "vue";
import { Table } from "@/hooks/interface";
import { ColumnProps } from "@/components/LjVxeTable/interface";
import { ALLOW_EDIT_STATE, sys_arry_formulatype } from "@/config/index";
import { CommonDynamicSelect } from "@/api/modules/common";
import { GetComputeMattress, GetMattressImportDW2, GetMattressPackagMx } from "@/api/modules/quote";
import { useUserStore } from "@/stores/modules/user";
import MtrldefSelect from "@/views/system/selector/mtrldef/select.vue";
import BednetSelect from "@/views/system/selector/bednet/select.vue";
import { handleRowAccordingToProp } from "@/utils";
import { ElButton, ElMessage, ElPopconfirm, ElMessageBox, ElNotification, ElTag } from "element-plus";
import { Minus, Plus, InfoFilled } from "@element-plus/icons-vue";
import { DwnameEnum } from "@/enums/dwnameEnum";
import { isArray } from "@/utils/is";
import { calculateFormula, formulaPartsFormula, floatAdd, floatMul, formatFixedNumber } from "@/utils/index";
import { cloneDeep, defaultsDeep } from "lodash-es";
import { TYPE, useToast, POSITION } from "vue-toastification";
import ToastFormula from "@/components/ToastWidget/Formula/index.vue";
import ToastHistoryPrice from "@/components/ToastWidget/HistoryPrice/index.vue";
import { useRouter } from "vue-router";
import { useGlobalStore } from "@/stores/modules/global";

interface defaultState {
  vxeTableRef: any;
}

export const useHooks = () => {
  const state = reactive<defaultState>({
    vxeTableRef: null
  });

  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 mtrldefStatus = [
    {
      label: "待审核",
      value: 0
    },
    {
      label: "待终审",
      value: 1
    },
    {
      label: "已审核",
      value: 2
    }
  ];
  // 表格配置项
  const columns: ColumnProps<any>[] = [
    {
      title: "序",
      field: "rowNum",
      width: 50
    },
    {
      title: "物料编码",
      field: "mtrlcode",
      table: "u_mtrldef",
      type: "html"
      // search: {
      //   el: "input"
      // }
    },
    {
      title: "物料名称",
      field: "mtrlname",
      table: "u_mtrldef",
      type: "html"
      // search: {
      //   el: "input"
      // }
    },
    {
      title: "英文名称",
      field: "mtrlengname",
      table: "u_mtrldef"
    },
    {
      title: "物料类别",
      field: "mtrltype",
      table: "u_mtrldef"
    },
    {
      title: "自定义1",
      field: "mtrlsectype",
      table: "u_mtrldef"
    },
    {
      title: "物料规格",
      field: "mtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "自定义2",
      field: "zxmtrlmode",
      table: "u_mtrldef"
    },
    {
      title: "单位",
      field: "unit",
      table: "u_mtrldef"
    },
    {
      title: "建立时间",
      field: "opdate",
      table: "u_mtrldef"
    },
    {
      title: "建立人",
      field: "opemp",
      table: "u_mtrldef"
    },
    {
      title: "修改时间",
      field: "moddate",
      table: "u_mtrldef"
    },
    {
      title: "修改人",
      field: "modemp",
      table: "u_mtrldef"
    },
    {
      title: "状态",
      field: "isuse",
      table: "u_mtrldef",
      datatype: "checkbox",
      width: 80
    },
    {
      title: "自定义3",
      field: "usermtrlmode",
      table: "u_mtrldef"
    }
  ];

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