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 { 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 } 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;
  LjDetailRef: any;
  initParams: any;
  initParamsMx: any;
  initParamsMxSpring: any;
  bednetMxData: any;
  bednetMxSprintData: any;
  vxeTableMxRef: any;
  vxeTableMxSpringRef: any;
  MtrldefDialogRef: any;
  MtrldefDialogProps: any;
  SpringDialogRef: any;
  SpringDialogProps: any;
  currentArea: any;
  AreaList: any;
  bednetVarList: any;
}

/**
 * @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
};

export const useHooks = (t?: any) => {
  const state = reactive<defaultState>({
    orderStatus: "",
    LjDetailRef: null,
    vxeTableMxRef: null,
    vxeTableMxSpringRef: null,
    initParams: {},
    initParamsMx: {},
    initParamsMxSpring: {},
    bednetMxData: [],
    bednetMxSprintData: [],
    MtrldefDialogRef: null,
    MtrldefDialogProps: {},
    SpringDialogRef: null,
    SpringDialogProps: {},
    currentArea: null,
    AreaList: [],
    bednetVarList: []
  });
  state.orderStatus = inject("orderStatus", "");

  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 rModelSetSpring = (data: any, item: any) => {
    console.log("rModelSetSpring data, item :>> ", data, item);
    if (item) {
      data.springid = item.springid;
      data.springname = item.name;
    }
  };

  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 _params = {
        arg_search: 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_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_price = item.pricelistprice;
    }
  };

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

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

      let _params = {
        keyword: "",
        arg_mtrltype: params.mtrltype,
        arg_pricelistid: params.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.bednetMxSprintData = [];
    let res = await getDataMxAdd(state.initParamsMx);
    let result = dataCallbackMx(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);
    // cb && cb(result);

    let res2 = await getDataMxSpring(state.initParamsMx);
    let result2 = dataCallbackMx(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);

    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.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 = 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 = 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;

    reload_dw2(rBednetType, () => {
      state.bednetMxData = [dw_bednet_define_add_mx];
    });

    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 = (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 CommonDynamicSelect(newParams, DwnameEnum.bednetQuoteMxSpring);
  };

  const dataCallback = (data: any) => {
    console.log("dataCallback data :>> ", data);
    let _list = data.datatable.map(t => {
      t.ifsaleout = Boolean(t.ifsaleout);
      return t;
    });
    return {
      list: _list,
      tableinfo: data.tableinfo,
      total: data.totalcnt,
      pageNum: data.pageindex,
      pageSize: data.pagesize
    };
  };

  const dataCallbackMx = (data: any) => {
    console.log("dataCallback data :>> ", data);
    data.datatable.length > 0 && (state.initParamsMxSpring.arg_bednetmxid = data.datatable[0].bednetmxid);
    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 = parseInt(value, 10).toString();
    data[field] = value;
  };

  const columns: ColumnProps<any>[] = [
    { type: "checkbox", width: 50, fixed: "left" },
    { title: "#", field: "pid", fixed: "left", width: 80 },
    {
      title: "审核",
      field: "flag"
    },
    {
      field: "deptid",
      title: "部门",
      search: {
        el: "select",
        key: "arg_deptid",
        props: {
          filterable: true
        },
        order: 1
      },
      basicinfo: {
        el: "select",
        editable: ALLOW_EDIT_STATE,
        rules: [{ required: true, message: "请先选择部门", trigger: "change" }],
        props: {
          filterable: true,
          clearable: false
        },
        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: ALLOW_EDIT_STATE,
        rules: [{ validator: numCheck, trigger: "blur" }]
      }
    },
    {
      title: "床垫长/CM",
      field: "mattress_length",
      basicinfo: {
        el: "input",
        editable: ALLOW_EDIT_STATE,
        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} label="双簧" class="mr-8" />
              <el-checkbox v-model={scope.searchParam.if_rsorwa} disabled={_disabled} label="胶条 包角" class="mr-8" />
              <el-checkbox v-model={scope.searchParam.if_sponge_drilling} disabled={_disabled} label="海绵打孔" />
              <el-checkbox v-model={scope.searchParam.iffork} disabled={_disabled} label="弹叉" />
              <el-checkbox v-model={scope.searchParam.if_jb} disabled={_disabled} label="卷包" />
            </>
          );
        }
      }
    },
    {
      title: "蛇线线径MM",
      field: "snake_wire_diameter",
      basicinfo: {
        el: "input",
        rules: [{ validator: numCheck, trigger: "blur" }],
        editable: (scope: any) => {
          if (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) => {
          console.log("mtrlname hooks render scope :>> ", scope);
          console.log("mtrl_sponge_name hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
          const { column, row, status } = scope;
          let field = column.field;
          let _label = column.title;
          // if (column?.format) {
          //   _label = handleRowAccordingToProp(searchParam, field, column?.format);
          // }
          let _deptid = state.LjDetailRef._mainData.deptid;
          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);
            }
          }
          // console.log("_pricelistid :>> ", _pricelistid, row);

          let params = {
            mtrltype: 1,
            pricelistid: _pricelistid
          };

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.sponge_mtrlid}
                {...params}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, params, 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) => {
          console.log("mtrlname hooks render scope :>> ", scope);
          console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
          const { column, row, status } = scope;
          let field = column.field;
          let _label = column.title;
          // if (column?.format) {
          //   _label = handleRowAccordingToProp(searchParam, field, column?.format);
          // }
          let _deptid = state.LjDetailRef._mainData.deptid;
          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);
            }
          }
          // console.log("_pricelistid :>> ", _pricelistid, row);

          let params = {
            mtrltype: 1,
            pricelistid: _pricelistid
          };

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.sponge_tc_mtrlid}
                {...params}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, params, 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) => {
          console.log("mtrlname hooks render scope :>> ", scope);
          console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
          const { column, row, status } = scope;
          let field = column.field;
          let _label = column.title;
          // if (column?.format) {
          //   _label = handleRowAccordingToProp(searchParam, field, column?.format);
          // }
          let _deptid = state.LjDetailRef._mainData.deptid;
          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);
            }
          }
          // console.log("_pricelistid :>> ", _pricelistid, row);

          let params = {
            mtrltype: 7,
            pricelistid: _pricelistid
          };

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.edge_mtrlid}
                {...params}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, params, 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;
          let _deptid = state.LjDetailRef._mainData.deptid;
          let deptEnum = state.LjDetailRef.enumMap.get("deptid");
          let _pricelistid = 0;
          if (deptEnum) {
            let depItem = deptEnum.find((item: any) => item.value == _deptid);
            if (depItem) {
              _pricelistid = Number(depItem.pricelistid);
            }
          }

          let params = {
            mtrltype: 7,
            pricelistid: _pricelistid
          };

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.felt_mtrlid}
                {...params}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, params, 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;
          let _deptid = state.LjDetailRef._mainData.deptid;
          let deptEnum = state.LjDetailRef.enumMap.get("deptid");
          let _pricelistid = 0;
          if (deptEnum) {
            let depItem = deptEnum.find((item: any) => item.value == _deptid);
            if (depItem) {
              _pricelistid = Number(depItem.pricelistid);
            }
          }

          let params = {
            mtrltype: 7,
            pricelistid: _pricelistid
          };

          return (
            <>
              <MtrldefSelect
                value={scope.searchParam.felt_x_mtrlid}
                {...params}
                disabled={!ALLOW_EDIT_STATE.includes(status)}
                clearable
                placeholder={_label}
                onOpenModal={() => fModelChoseMtrl(scope.searchParam, params, 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
      }
    },
    {
      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>
                <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>
              </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;
        }
      }
    },
    {
      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>
            </>
          );
        }
      }
    }
  ];

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

    let item = enumArr.find((item: any) => item.value == val);
    let arr = getDuoquVal(item);

    console.log("state.vxeTableMxRef.element.get :>> ", state.vxeTableMxRef.element.getTableData());
    let { fullData } = state.vxeTableMxRef.element.getTableData();
    let num = arr.length;
    fullData[0].if_part = Number(num > 1);

    if (num > 1) {
      fullData[0].springid = 0;
      fullData[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(fullData[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 => {
    let arr = [];
    for (const key in item) {
      if (key.indexOf("area_") > -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;
  };

  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 arr = getDuoquVal(item);

    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-number v-model={row.bednet_height} 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")}
              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: "if_part",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;

        console.log("if_part row :>> ", row);

        if (Number(row.if_part) == 1) {
          row.springid = 0;
          row.springname = "";
        }

        return (
          <>
            <el-checkbox v-model={row.if_part} style="display: block"></el-checkbox>
          </>
        );
      }
    },
    {
      field: "springname",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <SpringSelect
              value={row.springid}
              disabled={Number(row.if_part) == 1}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseSpring(row, row.springid, rModelSetSpring)}
              onSelect={(val: any) => rModelSetSpring(row, val)}
              onClear={() => rModelClearSpring(row)}
            />
          </>
        );
      }
    },
    {
      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} style="display: block"></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} style="display: block"></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) => {
        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, row.hard_around_springid, rModelSetSpring)}
              onSelect={(val: any) => rModelSetSpring(row, val)}
              onClear={() => rModelClearSpring(row)}
            />
          </>
        );
      }
    },
    {
      field: "if_15strip",
      editRender: {},
      editColRender: (scope: any) => {
        const { column, row, status } = scope;

        return (
          <>
            <el-checkbox v-model={row.if_15strip} style="display: block"></el-checkbox>
          </>
        );
      }
    },
    {
      field: "fabrics2_mtrlid",
      editRender: {},
      editColRender: (scope: any) => {
        console.log("mtrlname hooks render scope :>> ", scope);
        console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
        const { column, row, status } = scope;
        let field = column.field;
        let _label = column.title;
        // if (column?.format) {
        //   _label = handleRowAccordingToProp(searchParam, field, column?.format);
        // }
        let _deptid = state.LjDetailRef._mainData.deptid;
        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);
          }
        }
        console.log("_pricelistid :>> ", _pricelistid, row.formulakind);

        let params = {
          mtrltype: 2,
          pricelistid: _pricelistid
        };

        return (
          <>
            <MtrldefSelect
              value={row.fabrics2_mtrlid}
              {...params}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseMtrl(row, params, rModelSetMtrlFabrisc2)}
              onSelect={(val: any) => rModelSetMtrlFabrisc2(row, val)}
              onClear={() => rModelClearMtrlFabrisc2(row)}
            />
          </>
        );
      }
    },
    {
      field: "fabrics1_mtrlid",
      editRender: {},
      editColRender: (scope: any) => {
        console.log("mtrlname hooks render scope :>> ", scope);
        console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
        const { column, row, status } = scope;
        let _label = column.title;
        let _deptid = state.LjDetailRef._mainData.deptid;
        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);
          }
        }
        console.log("_pricelistid :>> ", _pricelistid, row.formulakind);

        let params = {
          mtrltype: 2,
          pricelistid: _pricelistid
        };

        return (
          <>
            <MtrldefSelect
              value={row.fabrics1_mtrlid}
              {...params}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseMtrl(row, params, rModelSetMtrlFabrisc1)}
              onSelect={(val: any) => rModelSetMtrlFabrisc1(row, val)}
              onClear={() => rModelClearMtrlFabrisc1(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) => {
        const { column, row, status } = scope;
        let _label = column.title;

        return (
          <>
            <SpringSelect
              value={row.springid}
              disabled={Number(row.if_part) == 1}
              clearable
              placeholder={_label}
              onOpenModal={() => fModelChoseSpring(row, row.springid, rModelSetSpring)}
              onSelect={(val: any) => rModelSetSpring(row, val)}
              onClear={() => rModelClearSpring(row)}
            />
          </>
        );
      }
    },
    {
      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;
  };

  const wf_replace_expression = (arg_str: string, mx: any) => {
    const { _mainData, enumMap } = state.LjDetailRef;

    // 替换中文符号
    arg_str = arg_str.replace(/（/g, " ( ").replace(/）/g, " ) ");
    arg_str = arg_str.replace(/，/g, " , ");

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

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

    // 四周加硬逻辑
    if (mx.if_hard_around + 0 === 1) {
      let ls_temp_str = 0;
      if (typeItem.label.indexOf("袋装") > -1) {
        ls_temp_str = (mx.hard_around_row + 0) * 2;
      } else {
        ls_temp_str = mx.hard_around_row + 0;
      }

      let ls_temp_str_all = ` ( 【弹簧排列个数-宽】 - ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧排列个数-宽】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧计算个数(宽)】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧计算个数(宽)】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧排列个数-长】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧排列个数-长】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧计算个数(长)】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧计算个数(长)】", ls_temp_str_all);
    }

    // 四周口袋逻辑
    if (mx.if_pocket_around + 0 === 1) {
      let ls_temp_str = 0;
      if (typeItem.label.indexOf("袋装") > -1) {
        ls_temp_str = (mx.pocket_around_row + 0) * 2;
      } else {
        ls_temp_str = mx.pocket_around_row + 0;
      }

      let ls_temp_str_all = ` ( 【弹簧排列个数-宽】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧排列个数-宽】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧计算个数(宽)】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧计算个数(宽)】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧排列个数-长】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧排列个数-长】", ls_temp_str_all);

      ls_temp_str_all = ` ( 【弹簧计算个数(长)】  -   ${ls_temp_str} ) `;
      arg_str = replaceArgStr(arg_str, "【弹簧计算个数(长)】", ls_temp_str_all);
    }

    return arg_str;
  };

  const wf_cmp_spring_mtrl_cost_dw2 = (arg_str: string, mx: any) => {
    const { _mainData, enumMap } = state.LjDetailRef;
    // 替换中文符号
    arg_str = arg_str.replace(/（/g, " ( ").replace(/）/g, " ) ");
    arg_str = arg_str.replace(/，/g, " , ");

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

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

    arg_str = replaceArgStr(arg_str, "【床垫宽】", _mainData.mattress_width);
    arg_str = replaceArgStr(arg_str, "【床垫长】", _mainData.mattress_length);
    arg_str = replaceArgStr(arg_str, "【床垫高】", _mainData.mattress_height);
    arg_str = replaceArgStr(arg_str, "【双簧】", _mainData.if_doublespring);
    arg_str = replaceArgStr(arg_str, "【床网类别】", typeItem.typename);

    for (let item of state.bednetVarList) {
      if (item.varvalue + 0 <= 0) continue;
      arg_str = replaceArgStr(arg_str, `【${item.varname}】`, item.varvalue + 0);
    }

    arg_str = replaceArgStr(arg_str, "【弹簧排列个数-宽】", mx.spring_qty_width);
    arg_str = replaceArgStr(arg_str, "【弹簧排列个数-长】", mx.spring_qty_length);
    arg_str = replaceArgStr(arg_str, "【弹簧计算个数(宽)】", mx.spring_qty_width);
    arg_str = replaceArgStr(arg_str, "【弹簧计算个数(长)】", mx.spring_qty_length);
    arg_str = replaceArgStr(arg_str, "【边铁条数】", mx.side_iron_qty);
    arg_str = replaceArgStr(arg_str, "【条数】", mx.side_iron_qty);
  };

  // 替换字符串
  const replaceArgStr = (arg_str: string, findStr: string, replaceStr: any) => {
    return arg_str.replace(findStr, replaceStr);
  };

  /**
   * @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);
    }
  };

  const wf_bednet_var = async (varkind: Number, pricelistid: Number, bednettypeid: Number) => {
    let _params = {
      dsname: "web_bednet_var_define_cw",
      queryparams: {
        varkind,
        pricelistid,
        bednettypeid
      }
    };
    let res = await CommonDynamicSelect(_params);
    if (res?.datatable?.length > 0) {
      state.bednetVarList = res?.datatable;
    }
  };

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