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 { GetComputeBednet, GetComputeSpring } from "@/api/modules/quote";
import { useUserStore } from "@/stores/modules/user";
import MtrldefSelect from "@/views/system/selector/mtrldef/select.vue";
import SpringSelect from "@/views/system/selector/spring/select.vue";
// import { handleRowAccordingToProp } from "@/utils";
import { ElButton, ElMessage, ElPopconfirm, ElMessageBox, ElNotification } 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, formatIntNumber } 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 { numCheck } from "@/utils/rules/index";

interface defaultState {
  /**
   * @description 单据当前状态
   */
  orderStatus: string;
  vxeTableRef: any;
  LjDetailRef: any;
  initParams: any;
  initParamsMx: any;
  initParamsMxSpring: any;
  bednetMxData: any;
  bednetMxSpringData: any;
  vxeTableMxRef: any;
  vxeTableMxSpringRef: any;
  MtrldefDialogRef: any;
  MtrldefDialogProps: any;
  SpringDialogRef: any;
  SpringDialogProps: any;
  currentArea: any;
  AreaList: any;
  bednetVarList: any;
  AllFormulaRef: any;
  cmpFormulas: any;
  cmpFormulaReplace: any;
  dannum_type: number;
}

/**
 * @description 床网明细表-属性默认值
 */
const dw_bednet_define_add_mx = {
  pid: 1,
  bednetmxid: 0,
  bednetid: 0,
  spring_qty_width: 0,
  spring_qty_length: 0,
  bednet_height: 0,
  wire_mtrlid: 0,
  springid: 0,
  springname: 0,
  if_part: 0,
  if_15strip: 0,
  if_pocket_around: 0,
  pocket_around_springid: 0,
  pocket_around_springname: 0,
  pocket_around_row: 0,
  pocket_around_wire_price: 0,
  pocket_around_spring_cost: 0,
  pocket_around_fabrics_cost: 0,
  if_hard_around: 0,
  hard_around_springid: 0,
  hard_around_springname: 0,
  hard_around_row: 0,
  hard_around_wire_price: 0,
  hard_around_mtrl_cost: 0,
  hard_around_hr_cost: 0,
  fabrics1_mtrlid: 0,
  fabrics1_price: 0,
  fabrics1_mtrl_cost: 0,
  fabrics2_mtrlid: 0,
  fabrics2_price: 0,
  fabrics2_mtrl_cost: 0,
  if_side_iron: 0,
  side_iron_qty: 0,
  side_iron_mtrl_cost: 0,
  side_iron_hr_cost: 0,
  pocket_around_spring_cost_replace_formula: "",
  pocket_around_fabrics_cost_replace_formula: "",
  hard_around_mtrl_cost_replace_formula: "",
  hard_around_hr_cost_replace_formula: "",
  fabrics1_mtrl_cost_replace_formula: "",
  fabrics2_mtrl_cost_replace_formula: "",
  side_iron_mtrl_cost_replace_formula: "",
  side_iron_hr_cost_replace_formula: "",
  cnail_mtrl_cost_replace_formula: "",
  cnail_mtrl_cost: 0,
  cnail_hr_cost_replace_formula: "",
  cnail_hr_cost: 0,
  glue_mtrl_cost_replace_formula: "",
  glue_mtrl_cost: 0,
  spring_mtrl_cost: 0,
  spring_hr_cost: 0,
  spring_mtrl_cost_replace_formula: "",
  spring_hr_cost_replace_formula: "",
  spring_weight_replace_formula: ""
};

const dw_bednet_mx_spring = {
  bednetmx_partid: 0,
  bednetmxid: 0,
  springid: 0,
  springname: "",
  spring_qty_width: 0,
  spring_qty_length: 0,
  fabrics1_mtrl_cost: 0
};

const ifsaleout_default = {
  commission: 1.05,
  other_rate: 1.05,
  taxrate: 1.07,
  moneyrate: 6.7
};

/**
 * @description 床网报价hooks
 * @param t
 * @param props 床网入参
 * @returns
 */
export const useHooks = (t?: any, props?: any) => {
  const state = reactive<defaultState>({
    orderStatus: "",
    vxeTableRef: null,
    LjDetailRef: null,
    vxeTableMxRef: null,
    vxeTableMxSpringRef: null,
    initParams: {},
    initParamsMx: {},
    initParamsMxSpring: {},
    bednetMxData: [],
    bednetMxSpringData: [],
    MtrldefDialogRef: null,
    MtrldefDialogProps: {},
    SpringDialogRef: null,
    SpringDialogProps: {},
    currentArea: null,
    AreaList: [],
    bednetVarList: [],
    AllFormulaRef: null,
    cmpFormulas: null,
    cmpFormulaReplace: null,
    dannum_type: 0
  });
  state.orderStatus = inject("orderStatus", "");

  const { userInfo } = useUserStore();

  const rModelSetFabrics2_mtrlid = (data: any) => {
    data.sponge_tc_mtrlid = 0;
    data.mtrl_sponge_tc_name = "";
    data.sponge_tc_thickness = 0;
    data.sponge_tc_height = 0;
  };

  /**
   * @description 填充明细弹簧
   */
  const rModelSetMxSpring = (data: any, item: any) => {
    console.log("rModelSetSpring data, item :>> ", data, item);
    if (item) {
      data.springid = item.springid;
      data.springname = item.springname;

      setMxSpringQtyWidthAndLength(data);
    }
  };

  /**
   * @description 填充海绵
   */
  const rModelSetSpring = (data: any, item: any) => {
    console.log("rModelSetSpring data, item :>> ", data, item);
    if (item) {
      data.springid = item.springid;
      data.springname = item.springname;
    }
  };

  const rModelClearSpring = (data: any) => {
    data.springid = 0;
    data.springname = "";
  };

  /**
   * @description 弹窗模块：选择弹簧
   * @param data 当前数据
   * @param status 当前订单状态
   * @returns Promise
   */
  const fModelChoseSpring = (data: any, params: any, cb: any) => {
    return new Promise((resolve, reject) => {
      // if (!ALLOW_EDIT_STATE.includes(status)) return;

      let _arg_bedtypeid = -1;
      let _arg_newspring = 0;
      if (params?.arg_bednettypeid) {
        switch (params?.arg_bednettypeid) {
          case 11: // 袋装网
            _arg_bedtypeid = 0;
            _arg_newspring = 1;
            break;
          case 12: // 圆网
            _arg_bedtypeid = 2;
            break;
          case 13: // 拉丝网
            _arg_bedtypeid = 1;
            break;
        }
      }
      let _params = {
        // arg_springtypeid: "11", // 默认选择国内分类
        arg_newspring: _arg_newspring,
        arg_bedtypeid: _arg_bedtypeid,
        ...params
      };
      state.SpringDialogProps = {
        onSubmit: (res: any) => {
          // submit
          console.log("openCustDialog res", res);
          nextTick(() => {
            cb(data, res.value[0]);
            resolve(1);
          });
        },
        onCancel: (error: any) => {
          // cancel 回调
          console.log("openCustDialog error", error);
        }
      };
      state.SpringDialogRef.show(_params);
    });
  };

  const rModelSetMtrlFelt = (data: any, item: any) => {
    if (item) {
      data.felt_mtrlid = item.mtrlid;
      data.felt_price = item.pricelistprice;
      data.mtrl_felt_name = item.mtrlname;
      data.felt_qty = 1;
    }
  };

  const rModelClearMtrlFelt = (data: any) => {
    data.felt_mtrlid = 0;
    data.felt_price = 0;
    data.mtrl_felt_name = "";
    data.felt_qty = 0;
    data.felt_dscrp = "";
  };

  const rModelSetMtrlFeltX = (data: any, item: any) => {
    if (item) {
      data.felt_x_mtrlid = item.mtrlid;
      data.mtrl_felt_x_name = item.mtrlname;
      data.felt_x_qty = 1;
    }
  };

  const rModelClearMtrlFeltX = (data: any) => {
    data.felt_x_mtrlid = 0;
    data.mtrl_felt_x_name = "";
    data.felt_x_qty = 0;
  };

  /**
   * @description 封边
   */
  const rModelSetMtrlEdge = (data: any, item: any) => {
    if (item) {
      data.edge_mtrlid = item.mtrlid;
      data.edge_price = item.pricelistprice;
      data.mtrl_edge_name = item.mtrlname;
    }
  };

  const rModelClearMtrlEdge = (data: any) => {
    data.edge_mtrlid = 0;
    data.edge_price = 0;
    data.mtrl_edge_name = "";
    data.edge_height = 0;
  };

  /**
   * @description 填充海绵
   */
  const rModelSetMtrlSpongeTc = (data: any, item: any) => {
    if (item) {
      data.sponge_tc_mtrlid = item.mtrlid;
      data.mtrl_sponge_tc_name = item.mtrlname;
    }
  };

  const rModelClearMtrlSpongeTc = (data: any) => {
    data.sponge_tc_mtrlid = 0;
    data.mtrl_sponge_tc_name = "";
    data.sponge_tc_thickness = 0;
    data.sponge_tc_height = 0;
  };

  const rModelSetMtrlFabrisc1 = (data: any, item: any) => {
    if (item) {
      data.fabrics1_mtrlid = item.mtrlid;
      data.fabrics1_mtrlname = item.mtrlname;
      data.fabrics1_price = item.pricelistprice;
    }
  };

  const rModelClearMtrlFabrisc1 = (data: any) => {
    data.fabrics1_mtrlid = 0;
    data.fabrics1_price = 0;
  };

  const rModelSetMtrlFabrisc2 = (data: any, item: any) => {
    if (item) {
      data.fabrics2_mtrlid = item.mtrlid;
      data.fabrics2_mtrlname = item.mtrlname;
      data.fabrics2_price = item.pricelistprice;
    }
  };

  const rModelClearMtrlFabrisc2 = (data: any) => {
    data.fabrics2_mtrlid = 0;
    data.fabrics2_price = 0;
  };

  const rModelSetHardAroundSpring = (data: any, item: any) => {
    if (item) {
      data.hard_around_springid = item.springid;
      data.hard_around_springname = item.springname;
    }
  };

  const rModelClearHardAroundSpring = (data: any) => {
    data.hard_around_springid = 0;
    data.hard_around_springname = "";
  };

  const getPriceid = () => {
    let _deptid = state.LjDetailRef?._mainData?.deptid ?? 0;

    console.log("getPriceid   _deptid :>> ", _deptid);
    if (!_deptid) {
      ElMessage.warning("请先选择部门");
      state.LjDetailRef?.baseformRef.element.validateField("deptid");
      return 0;
    }

    let deptEnum = state.LjDetailRef.enumMap.get("deptid");
    let _pricelistid = 0;
    console.log("deptEnum :>> ", deptEnum);
    if (deptEnum) {
      let depItem = deptEnum.find((item: any) => item.value == _deptid);
      console.log("depItem :>> ", depItem);
      if (depItem) {
        _pricelistid = Number(depItem.pricelistid);
      }
    }
    return _pricelistid;
  };

  /**
   * @description 弹窗模块：选择物料
   * @param data 当前数据
   * @param status 当前订单状态
   * @returns Promise
   */
  const fModelChoseMtrl = (data: any, params: any, cb: any) => {
    return new Promise((resolve, reject) => {
      let _pricelistid = getPriceid();
      if (!_pricelistid) return false;

      // if (!ALLOW_EDIT_STATE.includes(status)) return;
      console.log("fModelChoseMtrl fModelChoseMtrl params :>> ", params);
      let _params = {
        keyword: "",
        arg_mtrltype: params.mtrltype,
        arg_pricelistid: _pricelistid
      };
      state.MtrldefDialogProps = {
        onSubmit: (res: any) => {
          // submit
          console.log("openCustDialog res", res);
          nextTick(() => {
            cb(data, res.value[0]);
            resolve(1);
          });
        },
        onCancel: (error: any) => {
          // cancel 回调
          console.log("openCustDialog error", error);
        }
      };
      state.MtrldefDialogRef.show(_params);
    });
  };

  /**
   * @description 数据赋值：包边海绵
   * @param data 当前数据
   * @param item 当前选择的数据
   */
  const rModelSetMtrlSponge = (data: any, item: any) => {
    console.log("rModelSetMtrlSponge data :>> ", data);
    console.log("rModelSetMtrlSponge item :>> ", item);
    if (item) {
      data.sponge_mtrlid = item.mtrlid;
      data.sponge_price = item.pricelistprice;
      data.mtrl_sponge_name = item.mtrlname;
    }
    console.log("rModelSetMtrlSponge after data :>> ", data);
  };

  const rModelClearMtrlSponge = (data: any) => {
    console.log("rModelClearMtrlSponge data :>> ", data);
    data.sponge_mtrlid = 0;
    data.sponge_price = 0;
    data.mtrl_sponge_name = "";
    data.sponge_thickness = 0;
    data.sponge_height = 0;
  };

  const wf_hide_dw2 = (bednetData: any, columns: any) => {
    let hFields = [];

    console.log('bednetData.typename != "袋装网" :>> ', bednetData.typename, bednetData.typename != "袋装网");

    // if (bednetData.typename != "袋装网") {
    if (Number(bednetData.bednettypeid) != 11) {
      hFields.push("if_part");
      // 圆网和拉丝网 没有 入袋无纺布和底面无纺布
      hFields.push("fabrics1_mtrlid");
      hFields.push("fabrics2_mtrlid");
    }

    //四周加硬
    if (Number(bednetData.if_hard_around) == 0) {
      hFields.push("if_hard_around");
      hFields.push("hard_around_wire_price");
      hFields.push("hard_around_mtrl_cost");
      hFields.push("hard_around_hr_cost");
      hFields.push("hard_around_springid");
      hFields.push("hard_around_row");
    }

    //四周口袋
    if (Number(bednetData.if_pocket_around) == 0) {
      hFields.push("pocket_around_springname");
      hFields.push("pocket_around_springid");
      hFields.push("pocket_around_row");
      hFields.push("pocket_around_wire_price");
      hFields.push("pocket_around_spring_cost");
      hFields.push("pocket_around_fabrics_cost");
      hFields.push("if_pocket_around");
    }

    // 边铁？
    if (Number(bednetData.if_side_iron) == 0) {
      hFields.push("if_side_iron");
      hFields.push("side_iron_qty");
      hFields.push("side_iron_mtrl_cost");
      hFields.push("side_iron_hr_cost");
    }

    return columns.map(t => {
      if (hFields.includes(t.field)) {
        return {
          ...t,
          limited: true
        };
      }
      return t;
    });
  };

  /**
   * @description 重载床网明细和多区明细，返回多区明细数据
   * @param bednetData
   * @returns
   */
  const reload_dw2 = async (bednetData: any, cb?: any) => {
    state.bednetMxData = [];
    state.bednetMxSpringData = [];
    let res = await getDataMxAdd(state.initParamsMx);
    console.log("getDataMxAdd res :>> ", res);
    let result = dataCallback(res);

    columnsMx.value = wf_hide_dw2(bednetData, result.tableinfo.columns).map(item => {
      let _default = columnsMx_default.value.find(t => t.field == item.field);
      if (_default) {
        item = defaultsDeep(item, _default);
      }
      return item;
    });
    console.log("reset columnsMx.value :>> ", columnsMx.value, result);
    // cb && cb(result);

    let res2 = await getDataMxSpring(state.initParamsMx);
    let result2 = dataCallback(res2);
    // columnsMxSpring.value = result.tableinfo.columns;
    columnsMxSpring.value = result2.tableinfo.columns.map(item => {
      let _default = columnsMxSpring_default.value.find(t => t.field == item.field);
      if (_default) {
        item = defaultsDeep(item, _default);
      }
      return item;
    });

    console.log("reload_dw2 columnsMxSpring.value :>> ", columnsMxSpring.value, result);

    cb && cb({ mx: result, spring: result2 });
  };

  /**
   * @description 变更床垫分类时，重载明细数据 dw_1 itemchange
   * @author w_mattress_add dw_1 itemchange
   */
  const wf_b_bednet_type_ch = async (val: any) => {
    console.log("wf_b_bednet_type_ch state.LjDetailRef._mainData val:>> ", val, state.LjDetailRef, state.orderStatus);
    const { _mainData, enumMap, baseformRef } = state.LjDetailRef;

    // let mainData = state.orderStatus == "new" ? initParam : _mainData;

    console.log("mainData :>> ", _mainData);
    if (!Number(_mainData.deptid)) {
      ElMessage.warning("请先选择部门");

      console.log("baseformRef.element :>> ", baseformRef.element);
      baseformRef.element.validateField("deptid");
      _mainData.bednettypeid = "";
      return;
    }

    let _params = {
      dsname: "_Mapper_bednet_type_define",
      queryparams: {
        arg_bednettypeid: Number(val)
      }
    };
    let res = await CommonDynamicSelect(_params);
    let rBednetType: any = {};
    if (res?.datatable?.length > 0) {
      rBednetType = res?.datatable[0];
    }

    // _mainData.duo_qv_str = "三区";
    _mainData.bednettypeid = rBednetType.bednettypeid;
    _mainData.snake_wire_diameter = rBednetType.snake_wire_diameter;
    _mainData.snake_wire_mtrl_formula = rBednetType.snake_wire_mtrl_formula;

    _mainData.pocket_around_spring_formula = rBednetType.pocket_around_spring_formula;
    _mainData.pocket_around_fabrics_formula = rBednetType.pocket_around_fabrics_formula;

    _mainData.hard_around_mtrl_formula = rBednetType.hard_around_mtrl_formula;
    _mainData.hard_around_hr_formula = rBednetType.hard_around_hr_formula;
    _mainData.glue_mtrl_formula = rBednetType.glue_mtrl_formula;

    _mainData.if_side_iron = rBednetType.if_side_iron;
    _mainData.side_iron_mtrl_formula = rBednetType.side_iron_mtrl_formula;
    _mainData.side_iron_hr_formula = rBednetType.side_iron_hr_formula;

    _mainData.cnail_mtrl_formula = rBednetType.cnail_mtrl_formula;
    _mainData.cnail_hr_formula = rBednetType.cnail_hr_formula;

    _mainData.if_sponge_drilling = 0; // rBednetType.if_sponge_drilling;
    _mainData.sponge_mtrl_formula = rBednetType.sponge_mtrl_formula;
    _mainData.sponge_hr_formula = rBednetType.sponge_hr_formula;

    _mainData.edge_mtrl_formula = rBednetType.edge_mtrl_formula;
    _mainData.edge_hr_formula = rBednetType.edge_hr_formula;

    _mainData.fork_mtrl_formula = rBednetType.fork_mtrl_formula;
    _mainData.fork_hr_formula = rBednetType.fork_hr_formula;

    _mainData.if_rsorwa = 0; // rBednetType.if_rsorwa;
    _mainData.rsorwa_mtrl_formula = rBednetType.rsorwa_mtrl_formula;
    _mainData.rsorwa_hr_formula = rBednetType.rsorwa_hr_formula;
    _mainData.sponge_drilling_hr_formula = rBednetType.sponge_drilling_hr_formula;

    _mainData.spring_mtrl_formula = rBednetType.spring_mtrl_formula;
    _mainData.spring_hr_formula = rBednetType.spring_hr_formula;
    _mainData.fabrics1_mtrl_formula = rBednetType.fabrics1_mtrl_formula;
    _mainData.fabrics2_mtrl_formula = rBednetType.fabrics2_mtrl_formula;

    _mainData.felt_mtrl_formula = rBednetType.felt_mtrl_formula;
    _mainData.felt_hr_formula = rBednetType.felt_hr_formula;

    _mainData.packet_mtrl_formula = rBednetType.packet_mtrl_formula;
    _mainData.packet_hr_formula = rBednetType.packet_hr_formula;

    _mainData.sponge_mtrl_tc_formula = rBednetType.sponge_mtrl_tc_formula;

    _mainData.spring_weight_formula = rBednetType.spring_weight_formula;
    _mainData.side_iron_weight_formula = rBednetType.side_iron_weight_formula;
    _mainData.hard_around_weight_formula = rBednetType.hard_around_weight_formula;
    _mainData.fabrics1_weight_formula = rBednetType.fabrics1_weight_formula;
    _mainData.fabrics2_weight_formula = rBednetType.fabrics2_weight_formula;
    _mainData.felt_weight_formula = rBednetType.felt_weight_formula;
    _mainData.cnail_weight_formula = rBednetType.cnail_weight_formula;
    _mainData.sponge_weight_formula = rBednetType.sponge_weight_formula;
    _mainData.sponge_weight_tc_formula = rBednetType.sponge_weight_tc_formula;
    _mainData.edge_weight_formula = rBednetType.edge_weight_formula;
    _mainData.fork_weight_formula = rBednetType.fork_weight_formula;

    console.log("wf_b_bednet_type_ch _mainData :>> ", _mainData);

    let _default = cloneDeep(dw_bednet_define_add_mx);
    // 袋网
    if (Number(rBednetType.bednettypeid) == 11) {
      _default.fabrics2_mtrlid = 8760;
      _default.fabrics1_mtrlid = 8759;
    }

    reload_dw2(rBednetType, ({ mx }) => {
      console.log("reload_dw2reload_dw2reload_dw2 mx :>> ", mx);
      let fabrics2Col = mx.tableinfo.columns.find(item => item.field == "fabrics2_mtrlid");
      let fabrics2Item = fabrics2Col.enum.find(item => item.value == _default.fabrics2_mtrlid);
      if (fabrics2Item) {
        _default.fabrics2_price = fabrics2Item.pricelistprice;
      }

      let fabrics1Col = mx.tableinfo.columns.find(item => item.field == "fabrics1_mtrlid");
      let fabrics1Item = fabrics1Col.enum.find(item => item.value == _default.fabrics1_mtrlid);
      if (fabrics1Item) {
        _default.fabrics1_price = fabrics1Item.pricelistprice;
      }

      state.bednetMxData = [_default];
    });

    nextTick(() => {
      console.log("wf_b_bednet_type_ch state.vxeTableMxRef :>> ", state.vxeTableMxRef);
      state.vxeTableMxRef && state.vxeTableMxRef.refresh();
    });
  };

  const getData = (params: any) => {
    console.log("getData params :>> ", params);
    let newParams: any = {};
    params.pageNum && (newParams.pageindex = params.pageNum);
    params.pageSize && (newParams.pagesize = params.pageSize);
    delete params.pageNum;
    delete params.pageSize;
    newParams.queryParams = params;
    console.log("params :>> ", params);
    newParams.dsname = "web_bednet_define";
    return CommonDynamicSelect(newParams, DwnameEnum.bednetQuote);
    // return [];
  };

  /**
   * @description 获取明细数据
   * @param params
   * @returns
   */
  const getDataMx = (params: any) => {
    console.log("getData beatad params :>> ", params);
    let newParams: any = {};
    params.pageNum && (newParams.pageindex = params.pageNum);
    params.pageSize && (newParams.pagesize = params.pageSize);
    delete params.pageNum;
    delete params.pageSize;
    newParams.queryParams = params;
    console.log("params :>> ", params);
    newParams.dsname = "web_bednet_mx";
    return CommonDynamicSelect(newParams, DwnameEnum.bednetQuoteMx);
  };

  /**
   * @description 获取弹簧明细
   * @param params
   * @returns
   */
  const getDataMxSpring = (params: any) => {
    console.log("getData params :>> ", params);
    let newParams: any = {};
    params.pageNum && (newParams.pageindex = params.pageNum);
    params.pageSize && (newParams.pagesize = params.pageSize);
    delete params.pageNum;
    delete params.pageSize;
    newParams.queryParams = params;
    console.log("params :>> ", params);
    newParams.dsname = "web_bednet_mx_spring";
    return CommonDynamicSelect(newParams, DwnameEnum.bednetQuoteMxSpring);
  };

  const getDataMxAdd = async (params: any) => {
    console.log("getData params :>> ", params);
    let newParams: any = {};
    params.pageNum && (newParams.pageindex = params.pageNum);
    params.pageSize && (newParams.pagesize = params.pageSize);
    delete params.pageNum;
    delete params.pageSize;
    newParams.queryParams = params;
    console.log("params :>> ", params);
    newParams.dsname = "web_bednet_mx_add";
    return await CommonDynamicSelect(newParams, DwnameEnum.bednetQuoteMx);
  };

  const dataCallback = (data: any) => {
    return {
      list: data.datatable,
      tableinfo: data.tableinfo,
      total: data.totalcnt,
      pageNum: data.pageindex,
      pageSize: data.pagesize
    };
  };

  const handleBlur = (value: any, data: any, field: string) => {
    //保留小数点和-号
    value = (value + "").replace(/[^-\d.]/g, "");
    console.log(value);
    // 保留整数部分
    value = value == "" ? 0 : parseInt(value, 10).toString();
    data[field] = value;
  };

  /**
   * @description 获取部门汇率 和  折扣率
   */
  const wf_get_moneyrate_discount = (val: any, data) => {
    const { _mainData, enumMap } = state.LjDetailRef;

    let deptEnum = enumMap.get("deptid");
    console.log("deptEnum :>> ", deptEnum);
    if (deptEnum) {
      let depItem = deptEnum.find((item: any) => item.value == _mainData.deptid);
      if (depItem) {
        let _moneyrate = !depItem.moneyrate || Number(depItem.moneyrate) == 0 ? 1 : depItem.moneyrate;
        if (val == 0 || !_mainData.if_moneyrate) {
          data.moneyrate = 1;
        } else {
          data.moneyrate = _moneyrate;
        }
        data.discount = depItem.discount;
      }
    }
  };

  const columns: ColumnProps<any>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    { title: "#", field: "pid", fixed: "left", width: 80 },
    {
      title: "审核",
      field: "flag",
      basicinfo: {
        props: {
          trueValue: "1",
          falseValue: "0"
        }
      }
    },
    {
      field: "deptid",
      title: "部门",
      search: {
        el: "select",
        key: "arg_deptid",
        props: {
          filterable: true,
          onChange: val => {
            state.initParams.arg_deptid = val;
          }
        },
        order: 1
      },
      basicinfo: {
        // el: "select",
        // editable: ALLOW_EDIT_STATE,
        // rules: [{ required: true, message: "请先选择部门", trigger: "change" }],
        // props: {
        //   filterable: true,
        //   clearable: false
        // },
        editvisible: (scope: any) => {
          return !state.initParams?.deptid || state.initParams?.deptid == scope.searchParam.deptid;
        },
        order: 1,
        group: "单据信息"
      }
    },
    {
      title: "床网编码",
      field: "bednetcode",
      table: "u_bednet_define"
    },
    {
      title: "床网名称",
      field: "bednetname",
      table: "u_bednet_define",
      search: {
        el: "input",
        titleKey: "keyword",
        key: "arg_search",
        props: {
          filterable: true
        },
        order: 2
      },
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE
      }
    },
    {
      title: "部门售价",
      field: "dept_cost"
    },
    {
      title: "外币价",
      field: "foreign_cost"
    },
    {
      title: "床网类别",
      field: "bednettypeid",
      basicinfo: {
        el: "select",
        editable: ALLOW_EDIT_STATE,
        rules: [{ required: true, message: "请先选择床网类别", trigger: "change" }],
        props: {
          clearable: false,
          filterable: true,
          onChange: val => wf_b_bednet_type_ch(val)
        }
      }
    },
    {
      title: "床垫宽/CM",
      field: "mattress_width",
      basicinfo: {
        el: "input",
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && !Boolean(props.mattressWidth)) {
            return true;
          }
          return false;
        },
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "床垫长/CM",
      field: "mattress_length",
      basicinfo: {
        el: "input",
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && !Boolean(props.mattressLength)) {
            return true;
          }
          return false;
        },
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "床垫高/CM",
      field: "mattress_height",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "双网？",
      field: "if_doublenet"
    },
    {
      title: "双簧？",
      field: "if_doublespring",
      basicinfo: {
        labelHidden: true,
        render: (scope: any) => {
          let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
          return (
            <>
              <el-checkbox
                v-model={scope.searchParam.if_doublespring}
                disabled={_disabled}
                true-value={1}
                false-value={0}
                label="双簧"
                class="mr-8"
              />
              <el-checkbox
                v-model={scope.searchParam.if_rsorwa}
                disabled={_disabled}
                true-value={1}
                false-value={0}
                label="胶条 包角"
                class="mr-8"
              />
              <el-checkbox
                v-model={scope.searchParam.if_sponge_drilling}
                disabled={_disabled}
                true-value={1}
                false-value={0}
                label="海绵打孔"
              />
              <el-checkbox v-model={scope.searchParam.iffork} disabled={_disabled} true-value={1} false-value={0} label="弹叉" />
              <el-checkbox v-model={scope.searchParam.if_jb} disabled={_disabled} true-value={1} false-value={0} label="卷包" />
            </>
          );
        }
      }
    },
    {
      title: "蛇线线径MM",
      field: "snake_wire_diameter",
      basicinfo: {
        el: "input",
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.bednettypeid) > 11) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.bednettypeid) > 11) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "边铁？",
      field: "if_side_iron"
    },
    {
      title: "边铁损耗率",
      field: "side_iron_lossrate"
    },
    {
      title: "海绵包边物料",
      field: "mtrl_sponge_name",
      basicinfo: {
        editable: ALLOW_EDIT_STATE,
        render: (scope: any) => {
          const { column, row, status } = scope;
          let _label = column.title;

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.sponge_mtrlid}
                pricelistidfn={() => getPriceid()}
                mtrltype={1}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, { mtrltype: 1 }, rModelSetMtrlSponge)}
                onSelect={(val: any) => rModelSetMtrlSponge(scope.searchParam, val)}
                onClear={() => rModelClearMtrlSponge(scope.searchParam)}
              >
                {{
                  label: () => scope.searchParam.mtrl_sponge_name
                }}
              </MtrldefSelect>
            </>
          );
        }
      }
    },
    {
      title: "海绵厚度CM",
      field: "sponge_thickness",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "海绵高CM",
      field: "sponge_height",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "填充海绵物料",
      field: "mtrl_sponge_tc_name",
      basicinfo: {
        editable: ALLOW_EDIT_STATE,
        render: (scope: any) => {
          const { column, row, status } = scope;
          let _label = column.title;

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.sponge_tc_mtrlid}
                pricelistidfn={() => getPriceid()}
                mtrltype={1}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, { mtrltype: 1 }, rModelSetMtrlSpongeTc)}
                onSelect={(val: any) => rModelSetMtrlSpongeTc(scope.searchParam, val)}
                onClear={() => rModelClearMtrlSpongeTc(scope.searchParam)}
              >
                {{
                  label: () => scope.searchParam.mtrl_sponge_tc_name
                }}
              </MtrldefSelect>
            </>
          );
        }
      }
    },
    {
      title: "填充海绵厚度CM",
      field: "sponge_tc_thickness",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "填充海绵高CM",
      field: "sponge_tc_height",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "封边物料",
      field: "mtrl_edge_name",
      basicinfo: {
        editable: ALLOW_EDIT_STATE,
        render: (scope: any) => {
          const { column, row, status } = scope;
          let _label = column.title;

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.edge_mtrlid}
                pricelistidfn={() => getPriceid()}
                mtrltype={7}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, { mtrltype: 7 }, rModelSetMtrlEdge)}
                onSelect={(val: any) => rModelSetMtrlEdge(scope.searchParam, val)}
                onClear={() => rModelClearMtrlEdge(scope.searchParam)}
              >
                {{
                  label: () => scope.searchParam.mtrl_edge_name
                }}
              </MtrldefSelect>
            </>
          );
        }
      }
    },
    {
      title: "封边高",
      field: "edge_height",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "上垫层材料",
      field: "mtrl_felt_name",
      basicinfo: {
        editable: ALLOW_EDIT_STATE,
        render: (scope: any) => {
          const { column, row, status } = scope;
          let _label = column.title;

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.felt_mtrlid}
                pricelistidfn={() => getPriceid()}
                mtrltype={7}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, { mtrltype: 7 }, rModelSetMtrlFelt)}
                onSelect={(val: any) => rModelSetMtrlFelt(scope.searchParam, val)}
                onClear={() => rModelClearMtrlFelt(scope.searchParam)}
              >
                {{
                  label: () => scope.searchParam.mtrl_felt_name
                }}
              </MtrldefSelect>
            </>
          );
        }
      }
    },
    {
      field: "felt_qty",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "下垫层材料",
      field: "mtrl_felt_x_name",
      basicinfo: {
        editable: ALLOW_EDIT_STATE,
        render: (scope: any) => {
          const { column, row, status } = scope;
          let _label = column.title;

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.felt_x_mtrlid}
                pricelistidfn={() => getPriceid()}
                mtrltype={7}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, { mtrltype: 7 }, rModelSetMtrlFeltX)}
                onSelect={(val: any) => rModelSetMtrlFeltX(scope.searchParam, val)}
                onClear={() => rModelClearMtrlFeltX(scope.searchParam)}
              >
                {{
                  label: () => scope.searchParam.mtrl_felt_x_name
                }}
              </MtrldefSelect>
            </>
          );
        }
      }
    },
    {
      field: "felt_x_qty",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "弹叉数量",
      field: "fork_qty",
      basicinfo: {
        el: "input",
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.iffork)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.iffork)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "做法",
      field: "felt_dscrp",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        props: { type: "textarea", rows: 2 }
      }
    },
    {
      title: "胶条？包角？",
      field: "if_rsorwa"
    },
    {
      title: "海绵打孔？",
      field: "if_sponge_drilling"
    },
    {
      title: "登记人",
      field: "createby"
    },
    {
      title: "登记时间",
      field: "createtime"
    },
    {
      title: "总重量",
      field: "sum_weight"
    },
    {
      title: "计划价",
      field: "planprice"
    },
    // {
    //   title: "Bednetid",
    //   field: "bednetid"
    // },
    {
      title: "床网独立销售",
      field: "ifsaleout",
      basicinfo: {
        el: "checkbox",
        editable: ALLOW_EDIT_STATE,
        props: {
          trueValue: 1,
          falseValue: 0
        }
      }
    },
    {
      title: "包装",
      field: "packtype",
      // enum: [
      //   {
      //     label: "压包",
      //     value: "压包"
      //   },
      //   {
      //     label: "卷包",
      //     value: "卷包"
      //   },
      //   {
      //     label: "不压不卷",
      //     value: "不压不卷"
      //   },
      //   {
      //     label: "裸包装",
      //     value: "裸包装"
      //   }
      // ],
      basicinfo: {
        el: "select",
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        render: scope => {
          return (
            <>
              <div class="flx w-full">
                <el-select
                  v-model={scope.searchParam.packtype}
                  placeholder="方式"
                  clearable
                  disabled={!ALLOW_EDIT_STATE.includes(scope.status)}
                >
                  <el-option label="压包" value="压包" />
                  <el-option label="卷包" value="卷包" />
                  <el-option label="不压不卷" value="不压不卷" />
                  <el-option label="裸包装" value="裸包装" />
                </el-select>
                {["卷包", "不压不卷"].includes(scope.searchParam.packtype) ? (
                  <el-select
                    v-model={scope.searchParam.packmtrl}
                    class="ml-4"
                    placeholder="材料"
                    clearable
                    disabled={!ALLOW_EDIT_STATE.includes(scope.status)}
                  >
                    <el-option label="编织袋" value="编织袋" />
                    <el-option label="牛皮纸" value="牛皮纸" />
                    <el-option label="胶袋" value="胶袋" />
                    <el-option label="牛皮纸袋" value="牛皮纸袋" />
                  </el-select>
                ) : null}
              </div>
            </>
          );
        }
      }
    },
    {
      title: "包装数量",
      field: "packqty",
      basicinfo: {
        el: "input",
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    // {
    //   title: "包装材料",
    //   field: "packmtrl",
    //   enum: [
    //     {
    //       label: "编辑袋",
    //       value: "编辑袋"
    //     },
    //     {
    //       label: "牛皮纸",
    //       value: "牛皮纸"
    //     },
    //     {
    //       label: "胶袋",
    //       value: "胶袋"
    //     },
    //     {
    //       label: "牛皮纸袋",
    //       value: "牛皮纸袋"
    //     }
    //   ],
    //   basicinfo: {
    //     el: "select",
    //     editable: (scope: any) => {
    //       if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
    //         return true;
    //       }
    //       return false;
    //     },
    //     editvisible: (scope: any) => {
    //       if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
    //         return true;
    //       }
    //       return false;
    //     }
    //   }
    // },
    {
      title: "运输方式",
      field: "transport_type",
      enum: [
        {
          label: "装车送货(装柜)",
          value: "装车送货(装柜)"
        },
        {
          label: "装车送货(送货运站)",
          value: "装车送货(送货运站)"
        }
      ],
      basicinfo: {
        el: "select",
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "佣金点数",
      field: "commission",
      basicinfo: {
        el: "input",
        props: {
          placeholder: ifsaleout_default.commission + ""
        },
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "额外点数",
      field: "other_rate",
      basicinfo: {
        el: "input",
        props: {
          placeholder: ifsaleout_default.other_rate + ""
        },
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "FOB",
      field: "fob",
      basicinfo: {
        el: "input",
        props: {
          slots: {
            suffix: () => {
              return <>元</>;
            },
            append: () => {
              return <>元</>;
            }
          }
        },
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "税率",
      field: "taxrate",
      basicinfo: {
        el: "input",
        props: {
          placeholder: ifsaleout_default.taxrate + ""
        },
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "额外费用",
      field: "extras_cost",
      basicinfo: {
        el: "input",
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      title: "币种",
      field: "moneyrate",
      basicinfo: {
        el: "input",
        // props: {
        //   placeholder: ifsaleout_default.moneyrate + ""
        // },
        // rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        // editvisible: (scope: any) => {
        //   if (Number(scope.searchParam.ifsaleout)) {
        //     return true;
        //   }
        //   return false;
        // }
        render: (scope: any) => {
          let optionRender = [];
          let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
          scope.enum.map(item => {
            optionRender.push(<el-option label={item.label} value={item.value} />);
          });
          let slotprefix = {
            prefix: () => {
              return <>{scope.searchParam.moneyrate}</>;
            }
          };

          return (
            <el-select
              v-model={scope.searchParam.if_moneyrate}
              v-slots={slotprefix}
              class="select-text-right"
              disabled={_disabled}
              onChange={val => wf_get_moneyrate_discount(val, scope.searchParam)}
            >
              {optionRender}
            </el-select>
          );
        }
      }
    },
    {
      title: "额外费用备注",
      field: "extras_cost_dscrp",
      basicinfo: {
        el: "input",
        span: 2,
        props: { type: "textarea", rows: 2 },
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.ifsaleout)) {
            return true;
          }
          return false;
        }
      }
    },
    {
      field: "duo_qv_str",
      basicinfo: {
        el: "select",
        editable: (scope: any) => {
          if (ALLOW_EDIT_STATE.includes(scope.status) && Number(scope.searchParam.bednettypeid) == 11) {
            return true;
          }
          return false;
        },
        editvisible: (scope: any) => {
          if (Number(scope.searchParam.bednettypeid) == 11) {
            return true;
          }
          return false;
        },
        render: (scope: any) => {
          console.log("duo_qv_str scope :>> ", scope);
          let optionRender = [];
          scope.enum.map(item => {
            optionRender.push(<el-option label={item.label} value={item.value + ""} />);
          });
          return (
            <>
              <el-select
                v-model={scope.searchParam.duo_qv_str}
                disabled={!ALLOW_EDIT_STATE.includes(scope.status)}
                clearable
                onChange={val => handelChangeDuoqv(val, scope.enum)}
              >
                {optionRender}
              </el-select>
            </>
          );
        }
      }
    },
    {
      title: "是否备货",
      field: "if_stock_up",
      basicinfo: {
        el: "checkbox",
        editable: ALLOW_EDIT_STATE,
        props: {
          trueValue: 1,
          falseValue: 0
        }
      }
    }
  ];

  /**
   * @description 多区select，控制多区明细条数
   * @param val
   */
  const handelChangeDuoqv = (val: any, enumArr: any) => {
    console.log("duo_qv_str val :>> ", val);
    const { _mainData } = state.LjDetailRef;

    let item = enumArr.find((item: any) => item.value + "" == val);
    let attrKey = "area_";
    if (_mainData.sponge_mtrlid > 0) {
      attrKey = "sponge_";
    }
    let arr = getDuoquVal(item, attrKey);

    let num = arr.length;
    state.bednetMxData[0].if_part = Boolean(num > 1);
    console.log("fullData bednetMxData :>> ", state.bednetMxData);

    if (num > 1) {
      state.bednetMxData[0].springid = 0;
      state.bednetMxData[0].springname = "";
      nextTick(() => {
        setTimeout(async () => {
          console.log(
            "state.vxeTableMxSpringRef, state.vxeTableMxSpringRef.getTableData() :>> ",
            state.vxeTableMxSpringRef
            // state.vxeTableMxSpringRef.getTableData()
          );
          const $table = state.vxeTableMxSpringRef.element;
          if ($table) {
            const { fullData: springData } = $table.getTableData();
            console.log("handleAreaChange fullData :>> ", springData, num > 0 && springData.length < num);

            if (springData.length < num) {
              let arr = [];
              // let sum = Number(fullData[0].spring_qty_length);
              // let lengthValSum = 0;
              for (let i = 0; i < num - springData.length; i++) {
                // let lengthVal = 0;
                // if (i < num - springData.length - 1) {
                //   if (sum > 0) {
                //     lengthVal = (areaArr[i] / total) * sum;
                //     lengthValSum += lengthVal;
                //   }
                // } else {
                //   lengthVal = sum - lengthValSum;
                // }
                // console.log("lengthVal :>> ", lengthVal);

                let _data = {
                  ...dw_bednet_mx_spring,
                  spring_qty_width: Number(state.bednetMxData[0].spring_qty_width),
                  spring_qty_length: 0
                };
                arr.push(_data);
              }
              console.log("$table :>> ", $table, arr);
              await $table.insertAt(arr, -1);
            } else if (springData.length > num) {
              let arrs = springData.filter((item, index) => index + 1 > num);
              await $table.remove(arrs);
            }

            setMxSpringLength();
          }
        }, 200);
      });
    } else {
      // 1
    }
  };

  /**
   * @description 获取多区数据，数组化
   * @param item
   * @returns
   */
  const getDuoquVal = (item: any, attr = "area_") => {
    let arr = [];
    for (const key in item) {
      if (key.indexOf(attr) > -1) {
        arr.push(Number(item[key]));
      }
    }
    // 忽略数组中尾部出现的多个0
    let i = arr.length - 1;
    while (arr[i] === 0) {
      i--;
    }
    arr = arr.slice(0, i + 1);

    return arr;
  };

  /**
   * @description 设置床网高度，自动计算宽度，长度
   */
  const setMxSpringQtyWidthAndLength = async row => {
    if (row?.springid && Number(row.springid) > 0) {
      const { _mainData, enumMap } = state.LjDetailRef;
      let _pricelistid = getPriceid();
      let bednet = cloneDeep(_mainData);
      bednet.if_doublenet = Number(bednet.if_doublenet);
      bednet.if_doublespring = Number(bednet.if_doublespring);
      bednet.if_side_iron = Number(bednet.if_side_iron);
      bednet.if_rsorwa = Number(bednet.if_rsorwa);
      bednet.if_sponge_drilling = Number(bednet.if_sponge_drilling);
      bednet.iffork = Number(bednet.iffork);
      bednet.ifsaleout = Number(bednet.ifsaleout);
      bednet.if_jb = Number(bednet.if_jb);
      bednet.flag = Number(bednet.flag);
      bednet.pricelistid = _pricelistid;

      let _bednetMx = state.vxeTableMxRef?.element.getTableData().fullData ?? [];
      _bednetMx.forEach(itm => {
        itm.if_part = Number(itm.if_part);
      });

      let _params: any = {
        bednet: bednet,
        bednetMx: _bednetMx,
        spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
      };
      let res = await GetComputeSpring(_params);

      console.log("setMxSpringQtyWidthAndLength res :>> ", res);
      if (!res?.message) {
        row.spring_qty_width = res.bednetMx[0].spring_qty_width;
        row.spring_qty_length = res.bednetMx[0].spring_qty_length;
      }
    }
  };
  /**
   * @description 设置多区弹簧宽度
   */
  const setMxSpringWidth = row => {
    console.log("setMxSpringWidth val :>> ", row);

    // if (Number(row.if_part)) {
    //   state.bednetMxSpringData = state.bednetMxSpringData.map(item => {
    //     item.spring_qty_width = row.spring_qty_width;
    //     return item;
    //   });
    // }
    if (state.vxeTableMxSpringRef) {
      let { fullData: springData } = state.vxeTableMxSpringRef?.element.getTableData();

      springData.forEach((item, index) => {
        item.spring_qty_width = row.spring_qty_width;
      });
      console.log("state.vxeTableMxSpringRef.element :>> ", state.vxeTableMxSpringRef.element);

      state.vxeTableMxSpringRef.element.updateFooter();
    }
  };

  /**
   * @description 设置多区弹簧长度
   */
  const setMxSpringLength = () => {
    const { _mainData, enumMap } = state.LjDetailRef;

    console.log("setMxSpringLength object :>> ", _mainData, enumMap);
    let duoEnum = enumMap.get("duo_qv_str");
    let item = {};
    if (duoEnum) {
      item = duoEnum.find(t => t.value == _mainData.duo_qv_str);
    }
    console.log("setMxSpringLength item :>> ", item);

    let attrKey = "area_";
    if (_mainData.sponge_mtrlid > 0) {
      attrKey = "sponge_";
    }
    let arr = getDuoquVal(item, attrKey);

    let totality = arr.reduce((a, b) => a + b, 0);

    let { fullData } = state.vxeTableMxRef.element.getTableData();
    let sum = Number(fullData[0].spring_qty_length);
    console.log("arr, totality  :>> ", arr, totality, sum);

    if (state.vxeTableMxSpringRef) {
      let { fullData: springData } = state.vxeTableMxSpringRef?.element.getTableData();
      let lengthValSum = 0;

      springData.forEach((item, index) => {
        let lengthVal = 0;
        if (arr.length >= index + 1) {
          console.log("index, arr.length  :>> ", index, arr.length);
          if (index <= arr.length - 1) {
            console.log("index == arr.length - 1 :>> ", index, arr.length - 1);
            if (index == arr.length - 1) {
              lengthVal = sum - lengthValSum;
              console.log("lengthVal end:>> ", lengthVal, lengthValSum, sum);
            } else {
              lengthVal = formatIntNumber({ val: (arr[index] / totality) * sum });
              lengthValSum += Number(lengthVal);
            }
          } else {
            lengthVal = 0;
          }
          console.log("lengthVal :>> ", lengthVal);
        }
        item.spring_qty_length = lengthVal;
      });
      console.log("state.vxeTableMxSpringRef.element :>> ", state.vxeTableMxSpringRef.element);

      state.vxeTableMxSpringRef.element.updateFooter();
    }
  };

  const columnsMx_default = ref<ColumnProps<any>[]>([
    {
      field: "bednet_height",
      // editRender: {
      //   name: "input"
      // }
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input
              v-model={row.bednet_height}
              onBlur={() => handleBlur(row.bednet_height, row, "bednet_height")}
              onChange={() => setMxSpringQtyWidthAndLength(row)}
              style="width: unset"
            />
          </>
        );
      }
    },
    {
      field: "spring_qty_width",
      datatype: "integer",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input
              v-model={row.spring_qty_width}
              onBlur={() => handleBlur(row.spring_qty_width, row, "spring_qty_width")}
              onChange={() => setMxSpringWidth(row)}
              style="width: unset"
            />
          </>
        );
      }
    },
    {
      field: "spring_qty_length",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input
              v-model={row.spring_qty_length}
              onBlur={() => handleBlur(row.spring_qty_length, row, "spring_qty_length")}
              onChange={() => setMxSpringLength()}
              style="width: unset"
            />
          </>
        );
      }
    },
    {
      field: "springname",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <SpringSelect
              value={row.springid}
              argHeight={row.bednet_height}
              argBednettypeid={state.LjDetailRef._mainData.bednettypeid}
              disabled={Number(row.if_part) == 1}
              clearable
              placeholder={_label}
              onOpenModal={() =>
                fModelChoseSpring(
                  row,
                  { arg_height: row.bednet_height, arg_bednettypeid: state.LjDetailRef._mainData.bednettypeid },
                  rModelSetMxSpring
                )
              }
              onSelect={(val: any) => rModelSetMxSpring(row, val)}
              onClear={() => rModelClearSpring(row)}
            >
              {{
                label: () => row.springname
              }}
            </SpringSelect>
          </>
        );
      }
    },
    {
      field: "if_side_iron",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        if (Number(row.if_side_iron) == 0) {
          row.side_iron_qty = 0;
        }

        return (
          <>
            <el-checkbox v-model={row.if_side_iron} class="vxe-edit-col-middle"></el-checkbox>
          </>
        );
      }
    },
    {
      field: "side_iron_qty",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input v-model={row.side_iron_qty} disabled={Number(row.if_side_iron) == 0} />
          </>
        );
      }
    },
    {
      field: "if_hard_around",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        if (Number(row.if_hard_around) == 0) {
          row.hard_around_springid = 0;
          row.hard_around_springname = "";
          row.hard_around_row = 0;
        }

        return (
          <>
            <el-checkbox v-model={row.if_hard_around} class="vxe-edit-col-middle"></el-checkbox>
          </>
        );
      }
    },
    {
      field: "hard_around_row",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input v-model={row.hard_around_row} disabled={Number(row.if_hard_around) == 0} />
          </>
        );
      }
    },
    {
      field: "hard_around_springname",
      editRender: {},
      editColRender: (scope: any) => {
        console.log("hard_around_springname editColRender scope :>> ", scope);
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <SpringSelect
              value={row.hard_around_springid}
              disabled={Number(row.if_hard_around) == 0}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseSpring(row, {}, rModelSetHardAroundSpring)}
              onSelect={(val: any) => rModelSetHardAroundSpring(row, val)}
              onClear={() => rModelClearHardAroundSpring(row)}
            />
          </>
        );
      }
    },
    {
      field: "if_15strip",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;

        return (
          <>
            <el-checkbox v-model={row.if_15strip} class="vxe-edit-col-middle"></el-checkbox>
          </>
        );
      }
    },
    {
      field: "fabrics2_mtrlid",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <MtrldefSelect
              value={row.fabrics2_mtrlid}
              pricelistidfn={() => getPriceid()}
              mtrltype={2}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseMtrl(row, { mtrltype: 2 }, rModelSetMtrlFabrisc2)}
              onSelect={(val: any) => rModelSetMtrlFabrisc2(row, val)}
              onClear={() => rModelClearMtrlFabrisc2(row)}
            />
          </>
        );
      }
    },
    {
      field: "fabrics1_mtrlid",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <MtrldefSelect
              value={scope.row.fabrics1_mtrlid}
              pricelistidfn={() => getPriceid()}
              mtrltype={2}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseMtrl(scope.row, { mtrltype: 2 }, rModelSetMtrlFabrisc1)}
              onSelect={(val: any) => rModelSetMtrlFabrisc1(scope.row, val)}
              onClear={() => rModelClearMtrlFabrisc1(scope.row)}
            />
          </>
        );
      }
    }
  ]);
  const columnsMx = ref<ColumnProps<any>[]>();
  const columnsMxSpring = ref<ColumnProps<any>[]>([]);
  const columnsMxSpring_default = ref<ColumnProps<any>[]>([
    { title: "#", field: "pid", fixed: "left", width: 80 },
    {
      field: "springname",
      editRender: {},
      editColRender: (scope: any) => {
        console.log("springname editColRender scope :>> ", scope);
        const { column, row, status } = scope;
        let _label = column.title;
        let { fullData: mxlist } = state.vxeTableMxRef.element.getTableData();

        return (
          <>
            <SpringSelect
              value={row.springid}
              disabled={Number(row.if_part) == 1}
              clearable
              placeholder={_label}
              onOpenModal={() =>
                fModelChoseSpring(
                  scope.row,
                  { arg_height: mxlist[0]?.bednet_height, arg_bednettypeid: state.LjDetailRef._mainData.bednettypeid },
                  rModelSetSpring
                )
              }
              onSelect={(val: any) => rModelSetSpring(scope.row, val)}
              onClear={() => rModelClearSpring(scope.row)}
            >
              {{
                label: () => row.springname
              }}
            </SpringSelect>
          </>
        );
      }
    },
    {
      field: "spring_qty_width",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input
              v-model={row.spring_qty_width}
              onBlur={() => handleBlur(row.spring_qty_width, row, "spring_qty_width")}
              style="width: unset"
            />
          </>
        );
      }
    },
    {
      field: "spring_qty_length",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        return (
          <>
            <el-input
              v-model={row.spring_qty_length}
              onBlur={() => handleBlur(row.spring_qty_length, row, "spring_qty_length")}
              style="width: unset"
            />
          </>
        );
      }
    }
  ]);

  const columnsBednet = ref<ColumnProps<any>[]>([{}]);

  /**
   * @description 计算价格
   */
  const wf_cmp_cb = async () => {
    const { _mainData, enumMap, baseformRef } = state.LjDetailRef;

    wf_clear();

    wf_set_if_doublespring();

    if (!wf_check_rule()) return false;

    if (!(await wf_check_required())) return false;

    return true;
  };

  /**
   * @description 清除运算结果
   */
  const wf_clear = () => {
    const { _mainData } = state.LjDetailRef;

    _mainData.spring_mtrl_cost = 0;
    _mainData.spring_hr_cost = 0;
    _mainData.total_mtrl_cost = 0;
    _mainData.total_hr_cost = 0;
    _mainData.total_fees_cost = 0;
    _mainData.total_cost = 0;
    _mainData.nottax_factory_cost = 0;
    _mainData.nottax_dept_cost = 0;
    _mainData.dept_cost = 0;
    _mainData.foreign_cost = 0;
    _mainData.taxes = 0;
    _mainData.snake_wire_mtrl_cost = 0;
    _mainData.pocket_around_spring_cost = 0;
    _mainData.pocket_around_fabrics_cost = 0;
    _mainData.hard_around_mtrl_cost = 0;
    _mainData.hard_around_hr_cost = 0;
    _mainData.glue_price = 0;
    _mainData.felt_price = 0;
    _mainData.felt_mtrl_cost = 0;
    _mainData.felt_hr_cost = 0;
    _mainData.glue_mtrl_cost = 0;
    _mainData.fabrics1_mtrl_cost = 0;
    _mainData.fabrics2_mtrl_cost = 0;
    _mainData.side_iron_mtrl_cost = 0;
    _mainData.side_iron_hr_cost = 0;
    _mainData.side_iron_price = 0;
    _mainData.side_iron_lossrate = 0;
    _mainData.cnail_price = 0;
    _mainData.cnail_mtrl_cost = 0;
    _mainData.cnail_hr_cost = 0;
    _mainData.sponge_mtrl_cost = 0;
    _mainData.sponge_hr_cost = 0;
    _mainData.edge_mtrl_cost = 0;
    _mainData.edge_hr_cost = 0;
    _mainData.fork_mtrl_cost = 0;
    _mainData.fork_hr_cost = 0;
    _mainData.rsorwa_mtrl_cost = 0;
    _mainData.rsorwa_hr_cost = 0;
    _mainData.sponge_drilling_hr_cost = 0;
    _mainData.sponge_price = 0;
    _mainData.edge_price = 0;
    _mainData.fork_price = 0;
    _mainData.rsorwa_price = 0;
    _mainData.felt_mtrl_x_cost = 0;
    _mainData.packet_mtrl_cost = 0;
    _mainData.packet_hr_cost = 0;
    _mainData.sum_weight = 0;
    _mainData.spring_weight_qty = 0;
    _mainData.side_iron_weight_qty = 0;
    _mainData.hard_around_weight_qty = 0;
    _mainData.fabrics1_weight_qty = 0;
    _mainData.fabrics2_weight_qty = 0;
    _mainData.felt_weight_qty = 0;
    _mainData.cnail_weight_qty = 0;
    _mainData.sponge_weight_qty = 0;
    _mainData.sponge_weight_tc_qty = 0;
    _mainData.fork_weight_qty = 0;
    _mainData.edge_weight_qty = 0;
  };

  const wf_set_if_doublespring = () => {
    const { _mainData, enumMap } = state.LjDetailRef;

    const deptEnum = enumMap.get("deptid");
    const bednettypeEnum = enumMap.get("bednettypeid");

    let deptItem = deptEnum.find((item: any) => Number(item.value) == _mainData.deptid);
    let typeItem = bednettypeEnum.find((item: any) => Number(item.value) == _mainData.bednettypeid);

    console.log("typeItem :>> ", typeItem, deptItem);
    if (
      typeItem &&
      deptItem &&
      typeItem.label.indexOf("圆网") > -1 &&
      deptItem.label.indexOf("外贸") === -1 &&
      deptItem.label.indexOf("国外") === -1
    ) {
      _mainData.if_doublespring = 1;
    }
  };

  const wf_check_rule = (): boolean => {
    let { fullData: mxlist } = state.vxeTableMxRef.element.getTableData();
    if (!state.vxeTableMxSpringRef) {
      return true;
    }
    let { fullData: springlist } = state.vxeTableMxSpringRef.element.getTableData();

    for (let mx of mxlist) {
      //1.如果没有四周加硬   左边 弹簧个数排列宽   等于   右边每行  弹簧个数排列宽      ， 左边 弹簧个数排列长  等于  右边每行合计  弹簧个数排列长
      if (Number(mx.if_hard_around) === 0) {
        // 左边 弹簧个数排列宽   等于   右边每行  弹簧个数排列宽
        let sum_length = 0;
        for (let spring of springlist) {
          sum_length += parseFloat(spring.spring_qty_length);

          if (Number(mx.spring_qty_width) != Number(spring.spring_qty_width)) {
            throw new Error(`多区袋装明细列表,第${spring.pid}行,弹簧个数排列宽填写错误！`);
          }
        }

        if (parseFloat(mx.spring_qty_length) != sum_length) {
          throw new Error(
            `床网明细列表 弹簧个数排列长${parseFloat(
              mx.spring_qty_length
            )}不等于 多区袋装明细列表 弹簧个数排列长合计${sum_length}！`
          );
        }
      } else if (Number(mx.if_hard_around) === 1) {
        // 左边 弹簧个数排列宽   小于   右边每行  弹簧个数排列宽
        let sum_length = 0;
        for (let spring of springlist) {
          sum_length += parseFloat(spring.spring_qty_length);

          if (Number(mx.spring_qty_width) < Number(spring.spring_qty_width)) {
            throw new Error(`多区袋装明细列表,第${spring.pid}行,弹簧个数排列宽填写错误！`);
          }
        }

        //左边 弹簧个数排列长  小于  右边每行合计  弹簧个数排列长
        if (parseFloat(mx.spring_qty_length) < sum_length) {
          throw new Error(
            `床网明细列表 弹簧个数排列长${parseFloat(
              mx.spring_qty_length
            )}小于 多区袋装明细列表 弹簧个数排列长合计${sum_length}！`
          );
        }
      }
    }

    return true;
  };

  const wf_check_required = async (): Promise<boolean> => {
    const { _mainData, enumMap } = state.LjDetailRef;
    let { fullData: mxlist } = state.vxeTableMxRef.element.getTableData();

    //检查有没有填写床网高
    for (let mx of mxlist) {
      if (mx.bednet_height + 0 == 0) {
        throw new Error("请填写床网高");
      } else {
        _mainData.mattress_height = parseFloat(mx.bednet_height);
      }
    }

    // 检查有没有 填写 填充海绵高
    if (_mainData.sponge_tc_mtrlid + 0 > 0) {
      if (_mainData.sponge_tc_thickness + 0 == 0) {
        throw new Error("请填写填充海绵厚度!");
      }

      if (_mainData.sponge_tc_height + 0 == 0) {
        throw new Error("请填写填充海绵厚度!");
      }

      if ((_mainData.sponge_tc_thickness + 0 > 0 || _mainData.sponge_tc_height + 0 > 0) && _mainData.sponge_tc_mtrlid + 0 == 0) {
        throw new Error("请选择填充海绵物料!");
      }
    }

    // 如果 没有填写 海绵高和封边高  自动等于 床网高
    if (_mainData.sponge_mtrlid > 0 && _mainData.sponge_height + 0 <= 0) _mainData.sponge_height = _mainData.mattress_height;
    if (_mainData.edge_mtrlid > 0 && _mainData.edge_height + 0 <= 0) _mainData.edge_height = _mainData.mattress_height;

    _mainData.commission = _mainData.commission && Number(_mainData.commission) !== 0 ? _mainData.commission : 1;
    _mainData.taxrate = _mainData.taxrate && Number(_mainData.taxrate) !== 0 ? _mainData.taxrate : 1;
    _mainData.other_rate = _mainData.other_rate && Number(_mainData.other_rate) !== 0 ? _mainData.other_rate : 1;
    _mainData.moneyrate = _mainData.moneyrate && Number(_mainData.moneyrate) !== 0 ? _mainData.moneyrate : 1;

    if (Number(_mainData.commission) < 1) {
      throw new Error("佣金点数不能小于1!");
    }

    if (Number(_mainData.taxrate) < 1) {
      throw new Error("税率不能小于1!");
    }

    if (Number(_mainData.other_rate) < 1) {
      throw new Error("额外点数不能小于1!");
    }

    if (_mainData.packtype && _mainData.packtype.length > 0) {
      _mainData.packtype = _mainData.packtype.trim();

      if (_mainData.packtype != "不压不卷" && _mainData.packqty + 0 == 0) {
        throw new Error("请填写包装数量!");
      }

      if (_mainData.packtype != "不压不卷" && _mainData.packtype != "裸包装" && _mainData.transport_type + "" == "") {
        throw new Error("请选择运输方式!");
      }

      if (_mainData.packtype == "卷包" && _mainData.packmtrl + "" == "") {
        throw new Error("请选择包装材料!");
      }
    }

    await wf_factory_profitrate();

    if (_mainData.dept_profitrate + 0 == 0) {
      throw new Error("部门利润率不能为0!");
    }

    if (_mainData.bednettypeid + 0 == 0) {
      throw new Error("请选择床网类别!");
    }

    if (_mainData.sponge_mtrlid + 0 > 0 && _mainData.sponge_thickness + 0 == 0) {
      throw new Error("请填写海绵厚度!");
    }

    if (_mainData.sponge_mtrlid + 0 == 0 && _mainData.sponge_thickness + 0 > 0) {
      throw new Error("请选择海绵物料!");
    }

    const bednettypeEnum = enumMap.get("bednettypeid");
    let typeItem = bednettypeEnum.find((item: any) => Number(item.value) == _mainData.bednettypeid);

    for (let mx of mxlist) {
      if (mx.bednet_height + 0 == 0) {
        throw new Error(`第${mx.pid}行,请填写床网高!`);
      }
      if (mx.spring_qty_width + 0 == 0) {
        throw new Error(`第${mx.pid}行,请填写弹簧排列个数-宽!`);
      }
      if (mx.spring_qty_length + 0 == 0) {
        throw new Error(`第${mx.pid}行,请填写弹簧排列个数-长!`);
      }

      if (typeItem.label.indexOf("袋装网") > -1 && mx.fabrics1_mtrlid + 0 == 0) {
        throw new Error(`第${mx.pid}行,请选择入袋无纺布!`);
      }

      if (mx.if_side_iron > 0 && mx.side_iron_qty + 0 == 0) {
        throw new Error(`第${mx.pid}行,请填写边铁条数!`);
      }
    }

    return true;
  };

  /**
   * @description 获取部门利润率
   */
  const wf_factory_profitrate = async () => {
    const { _mainData, enumMap } = state.LjDetailRef;

    console.log("wf_factory_profitrate enumMap :>> ", enumMap);

    let deptEnum = enumMap.get("deptid");
    console.log("deptEnum :>> ", deptEnum);
    if (deptEnum) {
      let depItem = deptEnum.find((item: any) => item.value == _mainData.deptid);
      console.log("depItem :>> ", depItem);
      if (depItem) {
        _mainData.dept_profitrate = parseFloat(depItem.profitrate);
      }
    }

    let _params = {
      dsname: "web_factory_profitratelist",
      queryparams: {
        arg_deptid: _mainData.deptid,
        arg_bednettypeid_mattresstypeid: _mainData.mattresstypeid,
        kind: 0
      }
    };
    let res = await CommonDynamicSelect(_params);
    if (res?.datatable?.length > 0) {
      _mainData.profitrate = parseFloat(res?.datatable[0].profitrate);
    }
  };

  /**
   * @description 展示计算公式
   * @param timeout
   */
  const gotoSummy = async (timeout = 0, ifdrawer?: boolean) => {
    // if (userInfo.usermode == 1) {
    //   ElMessage.error("'业务员模式不可以查看计算公式！'");
    //   return false;
    // }
    console.log(
      "state.vxeTableMxRef?.element.getTableData().fullData :>> ",
      state.vxeTableMxRef?.element.getTableData().fullData,
      state.vxeTableMxRef
    );
    let bednet = cloneDeep(state.LjDetailRef._mainData);
    bednet.if_doublenet = Number(bednet.if_doublenet);
    bednet.if_doublespring = Number(bednet.if_doublespring);
    bednet.if_side_iron = Number(bednet.if_side_iron);
    bednet.if_rsorwa = Number(bednet.if_rsorwa);
    bednet.if_sponge_drilling = Number(bednet.if_sponge_drilling);
    bednet.iffork = Number(bednet.iffork);
    bednet.ifsaleout = Number(bednet.ifsaleout);
    bednet.if_jb = Number(bednet.if_jb);
    bednet.flag = Number(bednet.flag);

    if (state.initParams?.deptid > 0 && state.initParams?.deptid != bednet.deptid) {
      bednet.deptid = state.initParams.deptid;
    }

    let _params: any = {
      dannum_type: state.dannum_type,
      bednet: bednet,
      bednetMx: state.vxeTableMxRef?.element.getTableData().fullData ?? [],
      spring: state.vxeTableMxSpringRef?.element.getTableData().fullData ?? []
    };
    let res = await GetComputeBednet(_params);
    console.log("GetComputeBednet res :>> ", res);
    let summaryData = [];
    let fieldParams = [];
    let cpData = {};
    if (!res.message) {
      // summaryData = res.formulas;
      // fieldParams = res.replace;
      // cpData = res.bednet;
      state.cmpFormulas = res.formulas;
      state.cmpFormulaReplace = res.replace;
    } else {
      setTimeout(() => {
        if (res.message) {
          ElNotification({
            title: "计算失败",
            message: res.message,
            type: "warning"
          });
        }
      }, 100);
      return false;
    }

    console.log("summaryData :>> ", summaryData, fieldParams);

    // const toast = useToast();
    // if (ifdrawer) {
    //   state.AllFormulaRef.open(summaryData, fieldParams, cpData);
    //   toast.clear();
    // } else {
    //   toast(
    //     {
    //       component: ToastFormula,
    //       props: {
    //         t: t,
    //         formulas: summaryData,
    //         // data: cpData,
    //         fields: fieldParams
    //       },
    //       listeners: {
    //         tomore: () => {
    //           console.log("tomore summaryData :>> ", summaryData);
    //           state.AllFormulaRef.open(summaryData, fieldParams, cpData);
    //           toast.clear();
    //         },
    //         refresh: () => {
    //           gotoSummy();
    //         }
    //       }
    //     },
    //     {
    //       position: POSITION.BOTTOM_RIGHT,
    //       icon: false,
    //       timeout: timeout,
    //       closeButton: false,
    //       toastClassName: "longjoe-toast"
    //     }
    //   );
    // }
  };

  return {
    ...toRefs(state),
    columns,
    columnsMx,
    columnsMxSpring,
    columnsBednet,
    dw_bednet_mx_spring,
    reload_dw2,
    getData,
    getDataMx,
    getDataMxSpring,
    getDataMxAdd,
    dataCallback,
    wf_cmp_cb,
    setMxSpringLength,
    gotoSummy
  };
};
