<template>
  <LjDetail
    name="rpMustPayCrmDetail"
    ref="LjDetailRef"
    v-bind="detailProps"
    :request-api="getData"
    :data-callback="dataCallback"
    :init-param="initParams"
    v-model:order-status="orderStatus"
    :action="orderDefaultAction"
    :after-mound="funcAfterMound"
    :if-layout-editable="false"
    :default-columns-value="defaultColumnsValue"
  >
    <template #rightBtn="scope">
      <el-select v-model="scope.data.dannum_rate" placeholder="大小单" style="width: 80px">
        <el-option label="散单" :value="1" />
        <el-option label="标准" :value="2" />
        <el-option label="大单" :value="3" />
      </el-select>
    </template>
    <!-- @to-pin-detail="emit('toPinDetail')" -->
    <template #fabricMx__tabtitle="scope">
      <template v-if="isTabsBadge_fabric">
        <el-badge :value="isTabsBadge_fabric" :type="isTabsBadge_fabric > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #fabricMx>
      <el-tabs v-model="fabricMxTabs" type="card" class="h-full">
        <el-tab-pane
          class="h-full flx"
          label="裥面"
          name="tabpage_8"
          v-if="mattresstypeEnum && Number(mattresstypeEnum.if_top_side) == 1"
        >
          <LjVxeTable
            ref="fabricMxTab8Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab8"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :auto-load-layout="false"
            collapseButtons
            :request-auto="false"
          >
          </LjVxeTable>
        </el-tab-pane>
        <el-tab-pane
          class="h-full flx"
          label="裥底"
          name="tabpage_9"
          v-if="mattresstypeEnum && Number(mattresstypeEnum.if_button_sdie) == 1"
        >
          <LjVxeTable
            ref="fabricMxTab9Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab9"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :request-auto="false"
            :auto-load-layout="false"
            collapseButtons
          >
          </LjVxeTable>
        </el-tab-pane>
        <el-tab-pane
          class="h-full flx"
          label="裥大恻"
          name="tabpage_10"
          v-if="mattresstypeEnum && Number(mattresstypeEnum.if_big_side) == 1"
        >
          <LjVxeTable
            ref="fabricMxTab10Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab10"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :request-auto="false"
            :auto-load-layout="false"
            collapseButtons
          >
            <template #tableHeader>
              <el-space wrap>
                <el-dropdown placement="bottom-start" @command="val => handleSelFabricMxNewMtrlGroup('tabpage_10', val)">
                  <el-button type="primary">
                    {{ $t("business.detail.addChastr") }}<el-icon class="el-icon--right"><ArrowDown /></el-icon>
                  </el-button>
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item v-for="item in fabricMx10NewMtrlGroup" :key="item.value" :command="item">{{
                        item.label
                      }}</el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
                <el-button type="danger" @click="handleDelFabricMxNewMtrlGroup('tabpage_10')">{{
                  $t("business.detail.delChastr")
                }}</el-button>
              </el-space>
            </template>
          </LjVxeTable>
        </el-tab-pane>
        <el-tab-pane
          class="h-full flx"
          label="裥小恻"
          name="tabpage_11"
          v-if="mattresstypeEnum && Number(mattresstypeEnum.if_small_side) == 1"
        >
          <LjVxeTable
            ref="fabricMxTab11Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab11"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :request-auto="false"
            :auto-load-layout="false"
            collapseButtons
          >
            <template #tableHeader>
              <el-space wrap>
                <el-dropdown placement="bottom-start" @command="val => handleSelFabricMxNewMtrlGroup('tabpage_11', val)">
                  <el-button type="primary">
                    {{ $t("business.detail.addChastr") }}<el-icon class="el-icon--right"><ArrowDown /></el-icon>
                  </el-button>
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item v-for="item in fabricMx11NewMtrlGroup" :key="item.value" :command="item">{{
                        item.label
                      }}</el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
                <el-button type="danger" @click="handleDelFabricMxNewMtrlGroup('tabpage_10')">{{
                  $t("business.detail.delChastr")
                }}</el-button>
              </el-space>
            </template>
          </LjVxeTable>
        </el-tab-pane>
        <el-tab-pane
          class="h-full flx"
          label="裥V恻"
          name="tabpage_12"
          v-if="mattresstypeEnum && Number(mattresstypeEnum.if_v_side) == 1"
        >
          <LjVxeTable
            ref="fabricMxTab12Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab12"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :request-auto="false"
            :auto-load-layout="false"
            collapseButtons
          >
          </LjVxeTable>
        </el-tab-pane>
        <el-tab-pane class="h-full flx" label="拉手刺绣及其他工艺" name="tabpage_13">
          <LjVxeTable
            ref="fabricMxTab13Ref"
            row-key="key"
            table-cls=""
            :data="fabricMxTab13"
            :columns="columnsMx"
            :dwname="DwnameEnum.mattressQuoteMx"
            :table-props="tableProps_mx"
            :tool-button="[]"
            :request-auto="false"
            :auto-load-layout="false"
            collapseButtons
          >
          </LjVxeTable>
        </el-tab-pane>
      </el-tabs>
    </template>

    <template #bednetMx__tabtitle="scope">
      <template v-if="isTabsBadge_bednet">
        <el-badge :value="isTabsBadge_bednet" :type="isTabsBadge_bednet > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #bednetMx>
      <LjVxeTable
        ref="bednetMxRef"
        row-key="key"
        table-cls=""
        :data="bednetMxData"
        :columns="columnsMxBednet"
        :dwname="DwnameEnum.mattressQuoteMxBednet"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :request-auto="false"
        :auto-load-layout="false"
        collapseButtons
      >
        <template #tableHeader>
          <el-space wrap>
            <el-button type="primary">{{ $t("common.add") }}</el-button>
            <el-button type="danger">{{ $t("common.editText") }}</el-button>
          </el-space>
        </template>
      </LjVxeTable>
    </template>

    <template #cushionsMx__tabtitle="scope">
      <template v-if="isTabsBadge_cushions">
        <el-badge :value="isTabsBadge_cushions" :type="isTabsBadge_cushions > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #cushionsMx>
      <LjVxeTable
        ref="cushionsMxRef"
        row-key="key"
        table-cls=""
        :data="cushionsMxData"
        :columns="columnsMxCushions"
        :dwname="DwnameEnum.mattressQuoteMxCushions"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :request-auto="false"
        :auto-load-layout="false"
        collapseButtons
      >
        <template #tableHeader>
          <el-space wrap>
            <el-button type="primary" @click="toAddMx_cushions(0)">{{ $t("common.addText") }}</el-button>
            <el-button type="primary" @click="toAddMx_cushions(1)">{{ $t("common.insert") }}</el-button>
            <el-button type="danger" @click="toDelMx_cushions">{{ $t("common.delText") }}</el-button>
          </el-space>
          <el-space wrap class="ml-24">
            <el-button type="default" @click="toMove(1)">{{ $t("common.moveUp") }}</el-button>
            <el-button type="default" @click="toMove(-1)">{{ t("common.moveDown") }}</el-button>
          </el-space>
        </template>
      </LjVxeTable>
    </template>

    <template #accessoriesMx__tabtitle="scope">
      <template v-if="isTabsBadge_accessories">
        <el-badge :value="isTabsBadge_accessories" :type="isTabsBadge_accessories > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #accessoriesMx>
      <LjVxeTable
        ref="accessoriesMxRef"
        row-key="key"
        table-cls=""
        :data="accessoriesMxData"
        :columns="columnsMxAccessories"
        :dwname="DwnameEnum.mattressQuoteMxAccessories"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :request-auto="false"
        :auto-load-layout="false"
        collapseButtons
      >
        <!-- <template #tableHeader>
          <el-space wrap>
            <el-button type="primary">{{ $t("common.addText") }}</el-button>
            <el-button type="danger">{{ $t("common.delText") }}</el-button>
          </el-space>
        </template> -->
      </LjVxeTable>
    </template>

    <template #packagMx__tabtitle="scope">
      <template v-if="isTabsBadge_packag">
        <el-badge :value="isTabsBadge_packag" :type="isTabsBadge_packag > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #packagMx="scope">
      <LjVxeTable
        ref="packagMxRef"
        row-key="key"
        table-cls=""
        :data="packagMxData"
        :columns="columnsMxPackag"
        :dwname="DwnameEnum.mattressQuoteMxPackag"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :request-auto="false"
        :auto-load-layout="false"
        collapseButtons
      >
        <template #tableHeader>
          <el-space wrap>
            <el-form label-width="70px" inline>
              <el-form-item label="包装方式">
                <el-select v-model="scope.data.packtype" style="width: 120px" @change="funcPacktypeChange">
                  <el-option v-for="item in packtypeOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="卷包直径" v-if="scope.data.packtype == 1">
                <el-input-number v-model="scope.data.diameter" :min="0" :max="1000" />CM
              </el-form-item>
              <el-form-item label="木托方式" v-if="scope.data.packtype == 0">
                <el-select v-model="scope.data.woodpallettype" style="width: 120px">
                  <el-option v-for="item in woodpallettypeOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="压包数量" v-if="scope.data.packtype == 0">
                <el-input-number v-model="scope.data.packqty" :min="0" :max="1000" />
              </el-form-item>
              <el-form-item label="地区">
                <el-select v-model="scope.data.area" style="width: 120px">
                  <el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="柜型">
                <el-select v-model="scope.data.cabinet_type" style="width: 120px">
                  <el-option v-for="item in cabinetTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="体积">
                <el-input-number v-model="scope.data.cubage" :min="0" :max="1000" />
              </el-form-item>
            </el-form>
          </el-space>
        </template>
      </LjVxeTable>
    </template>

    <template #innerClothLayerMx__tabtitle="scope">
      <template v-if="innerClothLayerNum">
        <el-badge :value="innerClothLayerNum" :type="innerClothLayerNum > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #innerClothLayerMx>
      <LjVxeTable
        ref="innerClothLayerMxRef"
        row-key="key"
        table-cls=""
        :request-api="getData_innerClothLayer"
        :data-callback="dataCallbackMx"
        :init-param="initParams"
        :columns="columnsMxInnerClothLayer"
        :dwname="DwnameEnum.mattressQuoteMxInnerClothLayer"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :auto-load-layout="false"
        collapseButtons
      >
      </LjVxeTable>
    </template>

    <template #topCottonMx__tabtitle="scope">
      <template v-if="topCottonNum">
        <el-badge :value="topCottonNum" :type="topCottonNum > 0 ? 'danger' : 'info'">
          {{ scope.props.label }}
        </el-badge>
      </template>
      <template v-else>{{ scope.props.label }}</template>
    </template>
    <template #topCottonMx>
      <LjVxeTable
        ref="topCottonMxRef"
        row-key="key"
        table-cls=""
        :request-api="getData_topCotton"
        :data-callback="dataCallbackMx"
        :init-param="initParams"
        :columns="columnsMx"
        :dwname="DwnameEnum.mattressQuoteMx"
        :table-props="tableProps_mx"
        :tool-button="[]"
        :auto-load-layout="false"
        collapseButtons
      >
        <template #tableHeader>
          <el-space wrap>
            <el-button type="primary">{{ $t("common.addText") }}</el-button>
            <el-button type="danger">{{ $t("common.delText") }}</el-button>
            <el-button type="danger">{{ $t("common.delAllMx") }}</el-button>
          </el-space>
        </template>
      </LjVxeTable>
    </template>
  </LjDetail>

  <el-button v-if="ifAfterMound" class="btn-floating pl-8 pr-8 pt-15 pb-15 h-auto" round v-draggable-btn="oaFlowFloadProp">
    <span class="text-vertical">
      {{ $t("business.detail.formula") }}
    </span>
  </el-button>

  <MtrldefDialog ref="MtrldefDialogRef" v-bind="MtrldefDialogProps" />
  <LjDrawerQuoteList
    ref="QuoteListDrawerRef"
    :data="LjDetailRef && LjDetailRef._mainData"
    :mxdata="isQuoteListMxData"
    :enumMap="LjDetailRef && LjDetailRef.enumMap"
    :fabricMx="fabricMxTabList"
    :formulakindenum="formulaKindEnum"
  />
</template>

<script setup lang="ts" name="mattressQuoteDetail">
import { ref, watch, reactive, inject, nextTick, computed, onMounted, getCurrentInstance } from "vue";
import { DwnameEnum } from "@/enums/dwnameEnum";
import LjDetail from "@/components/LjDetail/index.vue";
import { DetailProp } from "@/components/LjDetail/interface";
import { useI18n } from "vue-i18n";
import { useHooks } from "./hooks/index";
import { useHooksCpQuote } from "./hooks/cpQuote";
import { useAuthButtons } from "@/hooks/useAuthButtons";
import LjVxeTable from "@/components/LjVxeTable/index.vue";
// import { cloneDeep } from "lodash-es";
import { useRoute, useRouter } from "vue-router";
import { CommonDynamicSelect, GetFormulaCompute } from "@/api/modules/common";
import { SaveMattress, SaveMattressAuditing, DelMattress } from "@/api/modules/quote";
// import ToastFormula from "@/components/ToastWidget/Formula/index.vue";
import { TYPE, useToast, POSITION } from "vue-toastification";
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
import { ArrowDown } from "@element-plus/icons-vue";
// import { calculateFormula } from "@/utils/index";
import MtrldefDialog from "@/views/system/selector/mtrldef/index.vue";
import LjDrawerQuoteList from "./components/QuoteList.vue";
import mittBus from "@/utils/mittBus";
import { MittEnum } from "@/enums/mittEnum";
import { getCurrentRecords } from "@/utils/index";
import { useUserStore } from "@/stores/modules/user";

// interface detailProp {
//   // /**
//   //  * @argument any 页面数据
//   //  */
//   // data1?: any;
//   // /**
//   //  * @argument string 请求数据的api ==> 非必传
//   //  */
//   // requestApi?: (params: any) => Promise<any>;
//   // /**
//   //  * @argument any 基础信息，表格展示数据
//   //  */
//   // // columns?: any;
//   // /**
//   //  * @description 是否可编辑
//   //  */
//   // status: "edit" | "new" | string;
// }

// const props = withDefaults(defineProps<detailProp>(), {});
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const {
  columns,
  columnsMx,
  columnsMxBednet,
  columnsMxCushions,
  columnsMxAccessories,
  columnsMxPackag,
  columnsMxInnerClothLayer,
  LjDetailRef,
  summaryData,
  fieldParams,
  MtrldefDialogRef,
  MtrldefDialogProps,
  fabricMxTabList,
  mattresstypeEnum,
  fabricMxTabs,
  fabricMxTab8Ref,
  fabricMxTab9Ref,
  fabricMxTab10Ref,
  fabricMxTab11Ref,
  fabricMxTab12Ref,
  fabricMxTab13Ref,
  fabricMxTab8,
  fabricMxTab9,
  fabricMxTab10,
  fabricMxTab11,
  fabricMxTab12,
  fabricMxTab13,
  fabricMx10NewMtrlGroup,
  fabricMx11NewMtrlGroup,
  initParams,
  cushionsMxData,
  fabricMxData,
  accessoriesMxData,
  bednetMxData,
  packagMxData,
  oriMxData,
  orderStatus,
  showFormula,
  QuoteListDrawerRef,
  formulaKindEnum,
  bednetMxRef,
  cushionsMxRef,
  accessoriesMxRef,
  packagMxRef,
  innerClothLayerMxRef,
  topCottonMxRef,
  packtypeOptions,
  woodpallettypeOptions,
  areaOptions,
  cabinetTypeOptions,
  funcAddMxSide,
  funcChaifenTab,
  getData_mx,
  dataCallback,
  dataCallbackMx,
  getMattressType,
  gotoSummy,
  gotoHisprice,
  getFormulakindEnum,
  funcPacktypeChange,
  dynamicRef,
  wf_cmp_cb
} = useHooks(t);
const { toExcelQuote } = useHooksCpQuote();
const { CheckPower, CheckOption, buttonNew, buttonDefault } = useAuthButtons(t);
const { userInfo } = useUserStore();
// const toast = useToast();

// const orderStatus = ref("");
// const mainData = ref([]);
const tabRemove: Function = inject("tabRemove") as Function;

const defaultColumnsValue = ref<any>({});

/**
 * @description 明细表格组件基础配置
 */
const tableProps_mx = ref({
  height: "auto",
  align: "left",
  // height: "",
  minHeight: "300px",
  editConfig: { trigger: "click", mode: "cell", enabled: false },
  // exportConfig: {
  //   filename: t("menu.saleTaskCrmDetail") + formatToDate(new Date(), "YYYY-MM-DDHH:mm:ss")
  // }
  keyboardConfig: {
    isEdit: true,
    isArrow: true,
    isEnter: true,
    isTab: true,
    isDel: true,
    isBack: true,
    isEsc: true,
    editMethod({ $table, row, column }) {
      // 先清空原先的值
      row[column.field] = "";
      // 再激活编辑状态并输入新值
      $table.setEditCell(row, column);
    }
  },
  mouseConfig: {
    selected: true
  }
});

const keyboardConfig = ref<any>({
  isEdit: true,
  isArrow: true,
  isEnter: true,
  isTab: true,
  isDel: true,
  isBack: true,
  isEsc: true,
  editMethod({ $table, row, column }) {
    // 先清空原先的值
    row[column.field] = "";
    // 再激活编辑状态并输入新值
    $table.setEditCell(row, column);
  }
});

const isTabsBadge_packag = computed(() => {
  let arr = [];
  arr = packagMxData.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
  return arr.length;
});

const isTabsBadge_cushions = computed(() => {
  let arr = [];
  arr = cushionsMxData.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
  return arr.length;
});

const isTabsBadge_accessories = computed(() => {
  let arr = [];
  arr = accessoriesMxData.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
  return arr.length;
});

const isTabsBadge_bednet = computed(() => {
  let arr = [];
  arr = bednetMxData.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
  return arr.length;
});

const isTabsBadge_fabric = computed(() => {
  let arr = [];
  arr = fabricMxTab8.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
  arr = arr.concat(fabricMxTab9.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
  arr = arr.concat(fabricMxTab10.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
  arr = arr.concat(fabricMxTab11.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
  arr = arr.concat(fabricMxTab12.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
  arr = arr.concat(fabricMxTab13.value.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
  console.log("isTabsBadge_fabric arr :>> ", arr);
  return arr.length;
});

const isQuoteListMxData = computed(() => {
  return [
    {
      label: "面裥绵",
      field: "tabpage_8",
      replace: "面裥绵-",
      data: fabricMxTab8.value
    },
    {
      label: "底裥绵",
      field: "tabpage_9",
      replace: "底裥绵-",
      data: fabricMxTab9.value
    },
    {
      label: "裥大侧",
      field: "tabpage_10",
      replace: "大侧裥绵-",
      data: fabricMxTab10.value
    },
    {
      label: "裥小侧",
      field: "tabpage_11",
      replace: "小侧裥绵-",
      data: fabricMxTab11.value
    },
    {
      label: "裥V侧",
      field: "tabpage_12",
      replace: "V侧裥绵-",
      data: fabricMxTab12.value
    },
    {
      label: "其他工艺",
      field: "tabpage_13",
      replace: "V侧裥绵-",
      data: fabricMxTab13.value
    },
    {
      label: "垫层",
      field: "cushions",
      data: {
        cushions: cushionsMxData.value,
        bednet: bednetMxData.value
      }
    },
    {
      label: "辅料",
      field: "accessories",
      data: accessoriesMxData.value
    },
    {
      label: "包装",
      field: "packag",
      data: packagMxData.value
    }
  ];
});

/**
 * @description tab 面料
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// /**
//  * @description 面料数据
//  */
// const fabricMxData = ref([]);
// const fabricMxTabData = ref([]);
// const fabricMxTabs = ref("fabricMx");

/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 床网
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// /**
//  * @description 床网数据
//  */
// const bednetMxData = ref([]);

// const getData_cushions = (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_mattress_mx_dianceng";
//   return CommonDynamicSelect(newParams, DwnameEnum.mattressQuoteMxBednet);
// };
/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 垫层
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// /**
//  * @description 垫层数据
//  */
// const cushionsMxData = ref([]);

/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 辅料
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// /**
//  * @description 辅料数据
//  */
// const accessoriesMxData = ref([]);

// const getData_bednet = (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_mattress_mx_bednet";
//   return CommonDynamicSelect(newParams, DwnameEnum.mattressQuoteMxAccessories);
// };
/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 包装
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// /**
//  * @description 包装数据
//  */
// const packagMxData = ref([]);

/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 内布套
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
/**
 * @description 内布套数据
 */
// const innerClothLayerMxData = ref([]);
// const innerClothLayerMxRef = ref();
const innerClothLayerNum = computed(() => {
  return innerClothLayerMxRef.value && innerClothLayerMxRef.value?.tableData ? innerClothLayerMxRef.value.tableData.length : 0;
});

const getData_innerClothLayer = (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;
  newParams.queryParams.arg_formulatype = [101, 102];
  console.log("params :>> ", params);
  newParams.dsname = "web_mattress_mx_neibutao";
  return CommonDynamicSelect(newParams, DwnameEnum.mattressQuoteMxInnerClothLayer);
};
/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

/**
 * @description tab 顶部裥棉
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 */
// const topCottonMxRef = ref();
const topCottonNum = computed(() => {
  return topCottonMxRef.value && topCottonMxRef.value?.tableData ? topCottonMxRef.value.tableData.length : 0;
});

const getData_topCotton = (params: any) => {
  let _params = { ...params, arg_formulatype: [103] };
  return getData_mx(_params);
};
/**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */

const detailProps = reactive<DetailProp>({
  dwname: DwnameEnum.mattressQuote,
  columns: columns,
  // headerstatus: ["status", "ifamt_ok"],
  basicDefault: {},
  header: {
    fieldNames: {
      code: "sptcode",
      codeLabel: t("table.u_spt.sptcode") + "：",
      name: "name"
    },
    // icon: "iconclipboard",
    // tabsProp: {
    //   scrollspy: true,
    //   sticky: true
    // }
    floatbtn: [
      {
        id: "oaFlow",
        originLeft: 100,
        originTop: 50
      }
    ]
  },
  mould: [
    {
      id: "fabricMx",
      type: "table",
      label: t("business.detail.fabric")
    },
    {
      id: "bednetMx",
      type: "table",
      label: t("business.detail.bednet")
    },
    {
      id: "cushionsMx",
      type: "table",
      label: t("business.detail.cushions")
    },
    {
      id: "accessoriesMx",
      type: "table",
      label: t("business.detail.accessories")
    },
    {
      id: "packagMx",
      type: "table",
      label: t("business.detail.packag")
    },
    {
      id: "innerClothLayerMx",
      type: "table",
      label: t("business.detail.innerClothLayer")
      // limited: (params: any) => {
      //   if (!params) return true;
      //   return params?.if_n_butao == "0";
      // }
    },
    {
      id: "topCottonMx",
      type: "table",
      label: t("business.detail.topCotton"),
      limited: (params: any) => {
        console.log("topCottonMx params?.if_w_butao :>> ", params?.if_w_butao);
        if (!params) return true;
        return !params?.if_w_butao || params?.if_w_butao == "0";
      }
    }
  ]
});

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_mattress";
  return CommonDynamicSelect(newParams, DwnameEnum.mattressQuote);
  // return [];
};
const loadingStatus = reactive({
  save: false
});

const orderDefaultAction = [
  buttonDefault({
    label: t("common.cancelText"),
    icon: "iconchevron-left",
    limited: () => {
      return !orderStatus.value;
    },
    clickFunc: item => {
      if (route.path.indexOf("/new") > -1) {
        tabRemove(route.fullPath);
        router.replace("/mattressQuote");
      } else {
        router.replace(
          `/mattressQuote/detail?id=${LjDetailRef.value._mainData.mattressid}&code=${LjDetailRef.value._mainData.mattresscode}`
        );
      }
    }
  }),
  buttonNew({
    label: t("common.saveText"),
    icon: "iconsave-01",
    loading: () => loadingStatus.save,
    limited: () => !orderStatus.value,
    clickFunc: async () => {
      console.log("save LjDetailRef.value._mainData :>> ", LjDetailRef.value._mainData);

      console.log("save------------ :>> ", loadingStatus.save);
      console.log("save cushionsMxData :>> ", cushionsMxData.value);

      try {
        await LjDetailRef.value.toValidateForm();

        wf_cmp_cb();
        loadingStatus.save = true;

        let mattress = LjDetailRef.value._mainData;

        let mattressMx = [];
        fabricMxTabList.value.map(t => {
          if (t.ref) {
            console.log("t.ref?.value :>> ", t.ref, dynamicRef(t.ref));
            if (dynamicRef(t.ref)) {
              let { fullData } = dynamicRef(t.ref)?.element.getTableData();
              console.log("fullData :>> ", fullData);
              fullData = fullData.map((itm, idx) => {
                itm.xu = idx + 1;
                return itm;
              });
              mattressMx = mattressMx.concat(fullData);
            }
          }
        });

        let _param_mf = {
          mattress,
          mattressMx
        };
        try {
          console.log("综合 _param_mf :>> ", _param_mf);
          await SaveMattress(_param_mf)
            .then(res => {
              ElNotification({
                title: "温馨提示",
                message: t("sys.api.sueccessToSave"),
                type: "success"
              });
              if (res.mattressid) {
                router.replace(`/mattressQuote/detail?id=${res.mattressid}`);
              } else {
                router.replace("/mattressQuote");
              }
              loadingStatus.save = false;
            })
            .catch(error => {
              console.log("error !! :>> ", error);
              loadingStatus.save = false;
            });
        } catch (error) {
          ElMessage.error(t("sys.api.operationFailed"));
        }
      } catch (e) {
        loadingStatus.save = false;
        console.log("buttonNew eee :>> ", e, loadingStatus.save);
      }
    }
  }),
  buttonDefault({
    label: t("common.add"),
    power: 72,
    limited: () => {
      return !!orderStatus.value;
    },
    clickFunc: item => {
      router.push(`/mattressQuote/new?id=0`);
    }
  }),
  buttonDefault({
    power: 72,
    label: t("common.editText"),
    limited: () => {
      return !!orderStatus.value;
    },
    clickFunc: item => {
      router.replace(
        `/mattressQuote/edit?id=${LjDetailRef.value._mainData.mattressid}&code=${LjDetailRef.value._mainData.mattresscode}`
      );
    }
  }),
  buttonDefault({
    power: 77,
    label: t("common.delText"),
    limited: () => {
      return !!orderStatus.value;
    },
    disabledTextCallBack: (data: any) => {
      if (!CheckPower(77)) {
        return "你没有【报价单-删除】的使用权限";
      }
      return "";
    },
    clickFunc: item => {
      console.log("dellll clickFunc item :>> ", LjDetailRef.value);
      ElMessageBox.confirm("是否确定要删除床垫报价单吗?", "询问", {
        confirmButtonText: t("common.delText"),
        cancelButtonText: "否",
        type: "error"
      })
        .then(() => {
          DelMattress({ mattressids: [Number(LjDetailRef.value._mainData.mattressid)] }).then(() => {
            ElMessage.success("删除成功！");

            tabRemove(route.fullPath);
            router.replace("/mattressQuote");
            mittBus.emit(MittEnum.MattressList);
          });
        })
        .catch((e: TypeError) => {
          console.log("e :>> ", e);
          ElMessage({
            type: "info",
            message: "操作取消"
          });
        });
    }
  }),
  [
    buttonDefault({
      label: t("common.businessOrder"),
      power: 94,
      limited: () => {
        return !!orderStatus.value;
      },
      disabledTextCallBack: (data: any) => {
        if (!CheckPower(94)) {
          return `你没有【报价单-${t("common.businessOrder")}】的使用权限`;
        }
        return "";
      },
      clickFunc: item => {
        ElMessageBox.confirm("是否确定要业务下单吗?", "询问", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning"
        })
          .then(() => {
            let _params = {
              mattressids: [Number(LjDetailRef.value._mainData.mattressid)],
              xd_flag: 1
            };
            SaveMattressAuditing(_params).then(() => {
              ElMessage.success(t("sys.api.operationSuccess"));

              LjDetailRef.value.refresh();
            });
          })
          .catch((e: TypeError) => {
            ElMessage({
              type: "info",
              message: "操作取消"
            });
          });
      }
    }),
    buttonDefault({
      label: t("common.businessOrderCancel"),
      power: 95,
      limited: () => {
        return !!orderStatus.value;
      },
      disabledTextCallBack: (data: any) => {
        if (!CheckPower(95)) {
          return `你没有【报价单-${t("common.businessOrderCancel")}】的使用权限`;
        }
        return "";
      },
      clickFunc: item => {
        ElMessageBox.confirm(`是否确定要${t("common.businessOrderCancel")}吗?`, "询问", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning"
        })
          .then(() => {
            let _params = {
              mattressids: [Number(LjDetailRef.value._mainData.mattressid)],
              xd_flag: 0
            };
            SaveMattressAuditing(_params).then(() => {
              ElMessage.success(t("sys.api.operationSuccess"));

              LjDetailRef.value.refresh();
            });
          })
          .catch((e: TypeError) => {
            ElMessage({
              type: "info",
              message: "操作取消"
            });
          });
      }
    })
  ],
  [
    buttonDefault({
      label: t("common.auditFinance"),
      power: 73,
      limited: () => {
        return !!orderStatus.value;
      },
      disabledTextCallBack: (data: any) => {
        if (!CheckPower(73)) {
          return `你没有【报价单-${t("common.auditFinance")}】的使用权限`;
        }
        return "";
      },
      clickFunc: item => {
        ElMessageBox.confirm(`是否确定要${t("common.auditFinance")}吗?`, "询问", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning"
        })
          .then(() => {
            let _params = {
              mattressids: [Number(LjDetailRef.value._mainData.mattressid)],
              flag: 1
            };
            SaveMattressAuditing(_params).then(() => {
              ElMessage.success(t("sys.api.operationSuccess"));

              LjDetailRef.value.refresh();
            });
          })
          .catch((e: TypeError) => {
            ElMessage({
              type: "info",
              message: "操作取消"
            });
          });
      }
    }),
    buttonDefault({
      label: t("common.withdrawAuditFinance"),
      power: 74,
      limited: () => {
        return !!orderStatus.value;
      },
      disabledTextCallBack: (data: any) => {
        if (!CheckPower(74)) {
          return `你没有【报价单-${t("common.withdrawAuditFinance")}】的使用权限`;
        }
        return "";
      },
      clickFunc: item => {
        ElMessageBox.confirm(`是否确定要${t("common.withdrawAuditFinance")}吗?`, "询问", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning"
        })
          .then(() => {
            let _params = {
              mattressids: [Number(LjDetailRef.value._mainData.mattressid)],
              flag: 0
            };
            SaveMattressAuditing(_params).then(() => {
              ElMessage.success(t("sys.api.operationSuccess"));

              LjDetailRef.value.refresh();
            });
          })
          .catch((e: TypeError) => {
            ElMessage({
              type: "info",
              message: "操作取消"
            });
          });
      }
    })
  ],
  buttonDefault({
    label: t("common.copyQuote")
  }),
  buttonDefault({
    label: t("common.showFormula"),
    disabledTextCallBack: () => {
      return userInfo.usermode == 1 ? "业务员模式不可以查看！" : "";
    },
    clickFunc: item => gotoSummy()
  }),
  buttonDefault({
    label: t("common.viewHistoricalQuotes"),
    clickFunc: () => {
      console.log("LjDetailRef.value._mainData :>> ", LjDetailRef.value._mainData);
      gotoHisprice(0, { id: LjDetailRef.value._mainData.mattressid, typeid: 1 });
    }
  }),
  buttonDefault({
    label: t("common.showQuoteList"),
    clickFunc: item => {
      QuoteListDrawerRef.value.show();
    }
  }),
  buttonDefault({
    label: t("common.exportQuoteList"),
    power: 72,
    clickFunc: item => {
      let _data = {
        data: LjDetailRef.value._mainData,
        mxdata: isQuoteListMxData.value,
        enumMap: LjDetailRef.value.enumMap,
        fabricMx: fabricMxTabList.value,
        formulakindenum: formulaKindEnum.value
      };
      toExcelQuote(_data, "报价单");
    }
  })
  // buttonDefault({
  //   label: t("common.dataTransmission"),
  //   power: 72,
  //   clickFunc: item => {
  //     router.push(`/mattressQuote/new?id=0`);
  //   }
  // })
];

onMounted(async () => {
  console.log("route onMounted:>> ", route);
  console.log("route onMounted:>> ", route.params);
  console.log("route onMounted:>> ", route.params.id);

  if (Number(route.query?.id)) {
    // 赋值主表数据
    // mainData.value = res.datatable.length ? res.datatable[0] : {};
    // console.log("mainData.value :>> ", mainData.value);
    // 刷新数据
    initParams.value.arg_mattressid = Number(route.query?.id);
    console.log("detail onMounted initParams.value :>> ", initParams.value);
  } else {
    if (route.query?.deptid) {
      defaultColumnsValue.value.deptid = route.query?.deptid;
    }
  }
  defaultColumnsValue.value.packtype = "0";
  defaultColumnsValue.value.packqty = 1;
  // defaultColumnsValue.value.woodpallettype = "0";
  // defaultColumnsValue.value.total_cost = 0;
  // defaultColumnsValue.value.nottax_factory_cost = 0;
  // defaultColumnsValue.value.nottax_dept_cost = 0;
  // defaultColumnsValue.value.foreign_cost = 0;
  // defaultColumnsValue.value.fob = 0;
  defaultColumnsValue.value.dannum_rate = "1";
  defaultColumnsValue.value.if_moneyrate = "0";
  defaultColumnsValue.value.moneyrate = "1";
  defaultColumnsValue.value.taxrate = 1;
  defaultColumnsValue.value.taxes = 1;
  // defaultColumnsValue.value.flag = 0;

  defaultColumnsValue.value.woodpallettype = "0";
  defaultColumnsValue.value.total_hr_cost = "0";
  defaultColumnsValue.value.total_material_cost = "0";
  defaultColumnsValue.value.total_hr_cost = 0;
  defaultColumnsValue.value.total_material_cost = 0;
  defaultColumnsValue.value.total_fees_cost = 0;
  defaultColumnsValue.value.total_cost = 0;
  defaultColumnsValue.value.commissionrate = 0;
  defaultColumnsValue.value.fob = 0;
  defaultColumnsValue.value.profitrate = 0;
  defaultColumnsValue.value.nottax_factory_cost = 0;
  defaultColumnsValue.value.nottax_dept_cost = 0;
  defaultColumnsValue.value.dept_cost = 0;
  defaultColumnsValue.value.foreign_cost = 0;
  defaultColumnsValue.value.diameter = 0;
  defaultColumnsValue.value.area = 0;
  defaultColumnsValue.value.cabinet_type = 0;
  defaultColumnsValue.value.hrcost = 0;
  defaultColumnsValue.value.biandaicost = 0;
  defaultColumnsValue.value.flag = 0;
  defaultColumnsValue.value.dept_profitrate_rangli = 0;
  defaultColumnsValue.value.profitrate_point = 0;
  defaultColumnsValue.value.chaizhuang_point = 0;
  defaultColumnsValue.value.haimian_point = 0;
  defaultColumnsValue.value.qr_auditingdate = "";
  defaultColumnsValue.value.zhizao_amt = 0;
  defaultColumnsValue.value.foreign_cost_bz = 0;
  defaultColumnsValue.value.cubage = 0;
  defaultColumnsValue.value.discount = 1;
  defaultColumnsValue.value.butao_point = 1;
  defaultColumnsValue.value.guanli_rate = 1;

  console.log("defaultColumnsValue.value :>> ", route.query?.deptid, defaultColumnsValue.value);

  getFormulakindEnum();
});

/**
 * @description 流转状况悬浮按钮参数
 */
const oaFlowFloadProp = ref<any>({
  id: "oaFlow",
  click: gotoSummy
});

/**
 * @description 详情页是否加载完成
 */
const ifAfterMound = ref(false);
/**
 * @description 页面数据加载完成
 */
const funcAfterMound = async () => {
  console.log("onMounted detail sale start!!!! :>> ");
  // console.log("LjDetailRef.value.currentMould :>> ", LjDetailRef.value.currentMould);
  // console.log(
  //   "Boolean(Number(CheckOption(sysOptionEnum.sys_option_043))) :>> ",
  //   Boolean(Number(CheckOption(sysOptionEnum.sys_option_043)))
  // );
  // // 流转状况
  // if (Boolean(Number(CheckOption(sysOptionEnum.sys_option_043))) && LjDetailRef.value.currentMould.header.floatbtn) {
  let _oaflowbtn = LjDetailRef.value.currentMould.header.floatbtn.find((itm: any) => itm.id == "oaFlow");
  if (_oaflowbtn) {
    _oaflowbtn.originLeft && (oaFlowFloadProp.value.originLeft = _oaflowbtn.originLeft);
    _oaflowbtn.originTop && (oaFlowFloadProp.value.originTop = _oaflowbtn.originTop);
  }
  // oaFlowFloadProp.value.change = LjDetailRef.value.toSetFloatBtnChange;

  //   if (!ALLOW_EDIT_STATE.includes(orderStatus.value)) {
  //     // 非新增、修改时执行
  //     getOaFlowList(initParams.value.scid, initParams.value.taskid).then(() => {
  //       if (oaFlowList.value.length) {
  //         gotoSummy();
  //       }
  //     });
  //   }
  // }

  // if (ALLOW_EDIT_STATE.includes(orderStatus.value)) {
  //   saleTaskMx_tableProps.value.editConfig.enabled = true;
  // }
  // if (orderStatus.value == "new") {
  //   nextTick(async () => {
  //     console.log("SaletaskmxListRef.value onmound new:>> ", SaletaskmxListRef.value);
  //     if (SaletaskmxListRef.value) {
  //       const $table = SaletaskmxListRef.value.element;
  //       if ($table) {
  //         const record = {};
  //         const { row: newRow } = await $table.insertAt(record, null);
  //         await $table.setEditCell(newRow, "mtrlcode");
  //         console.log("onMounted saletask finish :>> ", $table);
  //       }
  //     }
  //   });
  // }
  if (!orderStatus.value) {
    // 详情页
    gotoSummy(8000);
  } else {
    // 新增/编辑
    tableProps_mx.value.editConfig.enabled = true;
  }
  ifAfterMound.value = true;

  console.log("onMounted detail sale start LjDetailRef.value.mainData :>> ", LjDetailRef.value);

  if (orderStatus.value != "new") {
    // const { enumMap, _mainData } = LjDetailRef.value;
    // console.log("enumMap :>> ", enumMap, _mainData);
    // let _enum = enumMap.get("mattresstypeid");
    // console.log("_enum :>> ", _enum);
    // if (_enum) {
    //   mattresstypeEnum.value = _enum.find(t => t.value == _mainData.mattresstypeid);
    //   console.log("mattresstypeEnum :>> ", mattresstypeEnum);
    // }

    // let itmshow = fabricMxTabList.value.find(t => t.visible());
    // fabricMxTabs.value = itmshow.name;

    // let res = await getData_mx(initParams.value);
    // oriMxData.value = dataCallback(res);
    // oriMxData.value.list = oriMxData.value.list.map(t => {
    //   t.formulakind = Number(t.formulakind);
    //   t.thickness = Number(t.thickness);
    //   return t;
    // });

    getMattressType();

    let res = await getData_mx(initParams.value);
    oriMxData.value = dataCallbackMx(res);
    oriMxData.value.list = oriMxData.value.list.map(t => {
      t.formulakind = Number(t.formulakind);
      t.thickness = Number(t.thickness);
      t.qty = Number(t.qty);
      return t;
    });

    funcChaifenTab();
    // funcGetFabricMxShowData(itmshow.name);
    // console.log("funcAfterMound resData :>> ", fabricMxData.value);
  }
};

// const funcGetFabricMxShowData = (tabname: string) => {
//   let item = fabricMxTabList.value.find(t => t.name == tabname);

//   fabricMxTabData.value = fabricMxData.value.filter(t => item.type.includes(Number(t.formulakind)));
//   // fabricMxRef.value.refresh();
// };

// const handleFabricMxTabsClick = (pane: any, val: any) => {
//   // console.log("handleFabricMxTabsClick pane :>> ", pane.paneName);
//   // console.log("handleFabricMxTabsClick val :>> ", val);
//   // const $table = fabricMxRef.value.element;
//   // const column = $table.getColumnByField("formulakind");
//   // console.log("column :>> ", column);
//   // console.log("column.filters :>> ", column.filters);
//   // console.log("props.enum :>> ", column.filterRender.props.enum);

//   funcGetFabricMxShowData(pane.paneName);

//   // switch (pane.paneName) {
//   //   case 'tabpage_8':
//   //   LjDetailRef.value.element.setFilter('formulakind', )
//   //     break;
//   //   case 'tabpage_9':

//   //     break;
//   //   case 'tabpage_10':

//   //     break;
//   //   case 'tabpage_11':

//   //     break;
//   //   case 'tabpage_12':

//   //     break;
//   //   case 'tabpage_13':

//   //     break;
//   //   default:
//   //     break;
//   // }
// };

const handleSelFabricMxNewMtrlGroup = (target: string, item: any) => {
  console.log("handleSelFabricMxNewMtrlGroup target :>> ", target, item, fabricMxTab10.value);
  if (target == "tabpage_10") {
    let hasSame = fabricMxTab10.value.findIndex(t => t.sortcode == item.label);
    if (hasSame > -1) {
      ElMessage.error(item.label + "已存在");
      return false;
    }

    const $table = fabricMxTab10Ref.value.element;
    if ($table) {
      let _arr = [];
      fabricMxTab10.value.map(t => {
        if (t.sortcode == "普通大侧") {
          _arr.push(t);
        }
      });
      $table.remove(_arr);
    }

    let _params = {
      arg_array_formulakind: [2, 42, 52, 62, 72, 82],
      arg_array_formulatype: [0, 1, 2, 3]
    };
    funcAddMxSide(_params, item, fabricMxTab10Ref.value);
  } else if (target == "tabpage_11") {
    let hasSame = fabricMxTab11.value.findIndex(t => t.sortcode == item.label);
    if (hasSame > -1) {
      ElMessage.error(item.label + "已存在");
      return false;
    }

    const $table = fabricMxTab11Ref.value.element;
    if ($table) {
      let _arr = [];
      fabricMxTab11.value.map(t => {
        if (t.sortcode == "小侧1") {
          _arr.push(t);
        }
      });
      $table.remove(_arr);
    }

    let _params = {
      arg_array_formulakind: [3, 83, 43, 53, 63, 73],
      arg_array_formulatype: [0, 1, 2, 3]
    };
    funcAddMxSide(_params, item, fabricMxTab11Ref.value);
  }
};

const handleDelFabricMxNewMtrlGroup = (target: string) => {
  let sameMx = [];
  let $table = null;
  if (target == "tabpage_10") {
    $table = fabricMxTab10Ref.value.element;
  } else if (target == "tabpage_11") {
    $table = fabricMxTab11Ref.value.element;
  }

  if ($table) {
    const curRow = $table.getCurrentRecord();

    if (!curRow) {
      ElMessage.warning("请先选择要删除的行");
      return;
    }

    sameMx = fabricMxTab10.value.filter(t => t.sortcode == curRow.sortcode);
  }

  ElMessageBox.confirm(`是否确定要删除${sameMx.length}条明细吗?`, "询问：" + sameMx[0].sortcode, {
    confirmButtonText: t("common.delText"),
    cancelButtonText: "否",
    type: "error"
  })
    .then(() => {
      if (target == "tabpage_10") {
        let _arr = [];
        let _idx = [];
        fabricMxTab10.value.map((t, idx) => {
          if (t.sortcode == sameMx[0].sortcode) {
            _arr.push(t);
            _idx.push(idx);
          }
        });
        $table.remove(_arr);

        fabricMxTab10.value = fabricMxTab10.value.filter((t, idx) => !_idx.includes(idx));
      } else if (target == "tabpage_11") {
        let _arr = [];
        let _idx = [];
        fabricMxTab11.value.map((t, idx) => {
          if (t.sortcode == sameMx[0].sortcode) {
            _arr.push(t);
            _idx.push(idx);
          }
        });
        $table.remove(_arr);

        fabricMxTab11.value = fabricMxTab11.value.filter((t, idx) => !_idx.includes(idx));
      }
    })
    .catch((e: TypeError) => {
      console.log("e :>> ", e);
      ElMessage({
        type: "info",
        message: "操作取消"
      });
    });
};

const toMove = (action: number) => {
  // console.log('bvtoMove action :>> ', action);
  // const { $table , curRecords } = getCurrentRecords(cushionsMxRef.value)
  // console.log('curRecords :>> ', curRecords);
};

/**
 * @description 垫层：增加明细
 */
const toAddMx_cushions = async (type: number) => {
  const { $table, curRecords } = getCurrentRecords(cushionsMxRef.value);
  const row = curRecords[0];
  let nextRow;
  if (type) {
    // 插入
    const rowIndex = $table.getRowIndex(row);
    nextRow = $table.getData(rowIndex + 1);
  } else {
    // 新增
    nextRow = -1;
  }

  if ($table) {
    const records = {
      chastr: row.chastr,
      formulatype: row.formulatype,
      if_mtrl: row.if_mtrl,
      formulaid: row.formulaid,
      sortcode: row.sortcode,
      formulakind: row.formulakind,
      formula: row.formula,
      thickness: 0,
      mtrlid: 0
    };

    const { row: newRow } = await $table.insertAt(records, nextRow);
    // await $table.setEditCell(newRow, "mtrlname");
    await $table.setCurrentRow(newRow);
  }
};

/**
 * @description 垫层：删除
 */
const toDelMx_cushions = () => {
  ElMessageBox.confirm(`是否确定要删除明细吗?`, "询问", {
    confirmButtonText: t("common.delText"),
    cancelButtonText: "否",
    type: "error"
  })
    .then(() => {
      const $table = cushionsMxRef.value.element;
      $table.removeCurrentRow();
    })
    .catch((e: TypeError) => {
      console.log("e :>> ", e);
      ElMessage({
        type: "info",
        message: "操作取消"
      });
    });
};
</script>

<style lang="scss">
.select-text-right {
  .el-select__wrapper {
    text-align: right;
  }
}
</style>
