<template>
  <LjDrawer
    v-if="visible"
    ref="LjDrawerRef"
    :class="`${prefixCls}`"
    :id="prefixCls"
    direction="rtl"
    size="60%"
    destroy-on-close
    append-to-body
    :show-close="false"
    @close="autoClose"
  >
    <template #header>
      <div class="flx-justify-between">
        <div class="">详细报价</div>
        <!-- <div class="flx flx-center mr-4" id="settingSearchInput">
          <el-input
            v-model="searchField"
            :prefix-icon="Search"
            clearable
            style="width: 240px; height: 34px"
            :placeholder="$t('business.baseMsgSetting.searchPh')"
            @clear="searchEvent"
            @input="disshow(searchField)"
          >
            <template #suffix v-if="searchField.length">
              {{ matchSearchNum }}
            </template>
          </el-input>
          <el-tooltip effect="dark" :content="$t('common.table.sesarhFilter')" placement="top" :show-after="200">
            <el-button
              :type="ifSearchFilter ? 'primary' : 'default'"
              plain
              class="ml-8 pl-10 pr-10"
              @click="
                () => {
                  ifSearchFilter = !ifSearchFilter;
                  disshow(searchField);
                }
              "
            >
              <template #icon>
                <i class="iconfont" :class="ifSearchFilter ? 'iconfilter-funnel-01-fill' : 'iconfilter-funnel-01'"></i>
              </template>
            </el-button>
          </el-tooltip>
        </div> -->
        <div class="flx-shrink">
          <el-button type="danger" :icon="Close" text circle @click="cancelClick"></el-button>
        </div>
      </div>
    </template>
    <template #default>
      <!-- <el-row :gutter="10" class="">
        <el-col> -->
      <LjHeader class="flx-1" title="单据统计" />
      <FormulaGroup :data="isNormalFormulas" :fields="fieldsReplace" />

      <LjHeader class="flx-1 mt-16" title="详细报价" />
      <FormulaGroup :data="isMxFormulas" :fields="fieldsReplace" />

      <LjHeader class="flx-1 mt-16" title="重量" />
      <FormulaGroup :data="isWeigthFormulas" :fields="fieldsReplace" />
      <!-- </el-col>
      </el-row> -->
    </template>
  </LjDrawer>
</template>

<script setup lang="ts" name="bednetQuoteDetail_AllFormula">
import { ref, computed, watch, nextTick } from "vue";
import LjDrawer from "@/components/LjDrawer/index.vue";
import { useI18n } from "vue-i18n";
import { useDesign } from "@/hooks/useDesign";
import { useGlobalStore } from "@/stores/modules/global";
import { Close, Search } from "@element-plus/icons-vue";
import FormulaGroup from "./FormulaGroup.vue";
import LjHeader from "@/components/LjHeader/index.vue";

const { t } = useI18n();
const { prefixCls } = useDesign("bednet-formal-detail");
const globalStore = useGlobalStore();

const visible = ref(false);
const LjDrawerRef = ref();
const formulaList = ref<any>([]);
const fieldsReplace = ref<any>([]);
const mainData = ref<any>({});
const formulaMxList = ref<any>([]);

const isNormalFormulas = computed(() => {
  return formulaList.value.filter((item: any) => item.type == 0);
});

const isMxFormulas = computed(() => {
  return formulaList.value.filter((item: any) => item.type == 2);
});
const isWeigthFormulas = computed(() => {
  return formulaList.value.filter((item: any) => item.type == 3);
});

const autoClose = () => {
  setTimeout(() => {
    visible.value = false;
  }, 200);
};

const cancelClick = () => {
  // searchField.value = "";
  LjDrawerRef.value.hide();
  // selectColumn.value = [];
  // ifAllSelect.value = false;
};

/**
 * @description 显示组件
 */
const open = (formulas: any, replace: any, data: any) => {
  visible.value = true;
  formulaList.value = formulas;
  fieldsReplace.value = replace;
  mainData.value = data;

  formulaMxList.value;

  nextTick(() => {
    //   list.value = cloneDeep(params);
    //   oriList.value = cloneDeep(params);

    //   let arr: string[] = [];
    //   params.map((item: any) => {
    //     if (item.basicinfo && item.basicinfo.hasOwnProperty("group")) {
    //       item.basicinfo.group && !arr.includes(item.basicinfo.group) && arr.push(item.basicinfo.group);
    //     }
    //   });
    //   groupList.value = arr;

    //   selectGroup.value = group;

    LjDrawerRef.value.show();
    //   console.log("open columnsDrag.value :>> ", columnsDrag.value);

    //   nextTick(() => {
    //     initDragSelect();
    //   });
  });
};

defineExpose({
  open
});
</script>

<style lang="scss" scoped>
$prefix-cls: "#{$namespace}-bednet-formal-detail";

.#{$prefix-cls} {
  .summary-wrapper {
    &__label-item {
      position: relative;
      margin-right: $space-a3;

      &::after {
        content: "=";
        position: absolute;
        bottom: 0;
        right: -$space-b3;
        font-size: 24px;
        color: $color-text-disable;
      }
    }
  }
}
</style>
