<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <el-col :span="7">
          <el-form-item label="物料批次" prop="materialLots">
            <el-input
              v-model="queryParams.materialLots"
              placeholder="请输入物料批次"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="物料编码" prop="materialNo">
            <el-input
              v-model="queryParams.materialNo"
              placeholder="请输入物料编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="物料名称" prop="materialName">
            <el-input
              v-model="queryParams.materialName"
              placeholder="请输入物料名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item prop="qtyFlag" label-width="0px">
            <el-checkbox
              v-model="queryParams.qtyFlag"
              label="过滤0库存条码"
              border
              size="small"
              @change="handleQuery"
            />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <EasyAdvancedQuery
              class="mr10"
              label-width="98px"
              @advQuery="advQuery"
            >
              <template #default="{ model }">
                <el-row :gutter="10" type="flex">
                  <el-col :span="12">
                    <el-form-item label="呆滞料超期天数" prop="qrCode">
                      <el-input
                        v-model="model.overProduceDate"
                        placeholder="请输入呆滞料超期天数"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="物料条码" prop="qrCode">
                      <el-input
                        v-model="model.qrCode"
                        placeholder="请输入物料条码"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="仓库" prop="erpStockId">
                      <StockSelect
                        :ref="`stock1`"
                        v-model="model.erpStockId"
                        filterable
                        @change="
                          ($event) => {
                            stockChange($event);
                          }
                        "
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="区域" prop="wmsStoreAreaId">
                      <AreaSelect
                        :ref="`area1`"
                        v-model="model.wmsStoreAreaId"
                        filterable
                        @change="
                          ($event) => {
                            areaChange($event);
                          }
                        "
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="货位" prop="wmsStoreId">
                      <LocationSelect
                        :ref="`location1`"
                        v-model="model.wmsStoreId"
                        filterable
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label="原条码-合批前"
                      prop="oldQrCodeMerge"
                      label-width="102px"
                    >
                      <el-input
                        v-model="model.oldQrCodeMerge"
                        placeholder="请输入原条码-合批前"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label="原条码-拆批前"
                      prop="oldQrCodeSplit"
                      label-width="102px"
                    >
                      <el-input
                        v-model="model.oldQrCodeSplit"
                        placeholder="请输入原条码-拆批前"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label="合批物料条码"
                      prop="mergeQrCode"
                      label-width="102px"
                    >
                      <el-input
                        v-model="model.mergeQrCode"
                        placeholder="请输入合批物料条码"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="最小长度" prop="minLength">
                      <el-input
                        v-model="model.minLength"
                        placeholder="请输入最小长度"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="最大长度" prop="maxLength">
                      <el-input
                        v-model="model.maxLength"
                        placeholder="请输入最大长度"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="最小宽度" prop="minWidth">
                      <el-input
                        v-model="model.minWidth"
                        placeholder="请输入最小宽度"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="最大宽度" prop="maxWidth">
                      <el-input
                        v-model="model.maxWidth"
                        placeholder="请输入最大宽度"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="数量" prop="inQty">
                      <el-input
                        v-model="model.inQty"
                        placeholder="请输入数量"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="生产日期" prop="produceDate">
                      <el-date-picker
                        v-model="model.produceDate"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="中间仓" prop="midbin">
                      <DictSelect
                        v-model="model.midbin"
                        placeholder="请选择状态"
                        dict-type="YES_NO"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
              </template>
            </EasyAdvancedQuery>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleQuery"
            >
              搜索
            </el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </div>
      </QueryFormWrapper>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['wms:material-demolition-batch:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >
          导出
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-printer"
          size="mini"
          :loading="exportLoading"
          @click="handlePrintRepair()"
        >
          批量补打
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :loading="exportLoading"
          @click="handleAdjustment()"
        >
          仓库调拨
        </el-button>
      </el-col>
      <right-toolbar
        :columns="columnsList"
        :show-search.sync="showSearch"
        @saveSetting="getColumnsList"
        @queryTable="getList"
      />
    </el-row>

    <!-- 列表 -->
    <AutoResizer :given-height="177">
      <template #default="{ height }">
        <el-table
          v-if="columnsList.length > 0"
          ref="table"
          v-loading="loading"
          :height="height"
          :data="list"
          row-key="id"
          :cell-style="getStyle"
          :summary-method="getSummaries"
          show-summary
          border
          @selection-change="handleSelectionExpand"
        >
          <el-table-column
            type="selection"
            width="55"
            :reserve-selection="true"
            fixed="left"
          />
          <!-- <el-table-column
            v-if="columnsList[0].visible"
            :key="columnsList[0].key"
            label="索引号"
            align="center"
            prop="qrCode"
            width="180"
            show-overflow-tooltip
            fixed="left"
          /> -->
          <el-table-column
            v-if="columnsList[1].visible"
            :key="columnsList[1].key"
            label="物料批次"
            align="center"
            prop="materialLots"
            width="160"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[16].visible"
            :key="columnsList[16].key"
            label="条码号"
            align="center"
            prop="batchNumber"
            width="180"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[2].visible"
            :key="columnsList[2].key"
            label="物料编码"
            align="center"
            prop="materialNo"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[3].visible"
            :key="columnsList[3].key"
            label="物料名称"
            align="center"
            prop="materialName"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[21].visible"
            :key="columnsList[21].key"
            label="状态"
            align="center"
            prop="status"
            width="120"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag :type="'in_storage_status'" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[20].visible"
            :key="columnsList[20].key"
            label="呆滞料超期天数"
            align="center"
            prop="overProduceDate"
            width="120"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[19].visible"
            :key="columnsList[19].key"
            label="中间仓"
            align="center"
            prop="midbin"
            width="80"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag :type="DICT_TYPE.YES_NO" :value="scope.row.midbin" />
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[4].visible"
            :key="columnsList[4].key"
            label="仓库"
            align="center"
            prop="erpStockId"
            width="150"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[5].visible"
            :key="columnsList[5].key"
            label="区域"
            align="center"
            prop="wmsStoreAreaId"
            width="120"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[6].visible"
            :key="columnsList[6].key"
            label="货位"
            align="center"
            prop="wmsStoreId"
            width="120"
            show-overflow-tooltip
          />
          <el-table-column
            v-if="columnsList[7].visible"
            :key="columnsList[7].key"
            label="数量"
            align="center"
            width="100"
            sortable
            show-overflow-tooltip
            prop="inQty"
          />
          <el-table-column
            v-if="columnsList[14].visible"
            :key="columnsList[14].key"
            label="长度(m)"
            align="center"
            width="100"
            sortable
            show-overflow-tooltip
            prop="length"
          />
          <el-table-column
            v-if="columnsList[15].visible"
            :key="columnsList[15].key"
            label="宽度(mm)"
            align="center"
            width="120"
            sortable
            show-overflow-tooltip
            prop="width"
          />
          <el-table-column
            v-if="columnsList[17].visible"
            :key="columnsList[17].key"
            label="生产日期"
            align="center"
            width="120"
            sortable
            show-overflow-tooltip
            prop="produceDate"
          />
          <el-table-column
            v-if="columnsList[18].visible"
            :key="columnsList[18].key"
            label="保质期"
            align="center"
            width="120"
            show-overflow-tooltip
            prop="validTill"
          />
          <el-table-column
            v-if="columnsList[8].visible"
            :key="columnsList[8].key"
            label="供应商"
            align="center"
            prop="supplierName"
            width="120"
            show-overflow-tooltip
          />
          <!-- <el-table-column
            v-if="columnsList[9].visible"
            :key="columnsList[9].key"
            label="是否拆批物料"
            align="center"
            prop="splitFlag"
            width="120"
          >
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.WMS_MATERIAL_SPLIT"
                :value="scope.row.splitFlag"
              />
            </template>
          </el-table-column> -->
          <!-- <el-table-column
            v-if="columnsList[10].visible"
            :key="columnsList[10].key"
            label="被拆批物料条码"
            align="center"
            prop="oldQrCodeSplit"
            width="120"
            show-overflow-tooltip
          /> -->
          <!-- <el-table-column
            v-if="columnsList[11].visible"
            :key="columnsList[11].key"
            label="是否合批物料"
            align="center"
            prop="mergeFlag"
            width="120"
          >
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.WMS_MATERIAL_SPLIT"
                :value="scope.row.mergeFlag"
              />
            </template>
          </el-table-column> -->
          <!-- <el-table-column
            v-if="columnsList[12].visible"
            :key="columnsList[12].key"
            label="合批物料条码(已作废)"
            align="center"
            prop="oldQrCodeMerge"
            width="160"
            show-overflow-tooltip
          /> -->
          <!-- <el-table-column
            v-if="columnsList[13].visible"
            :key="columnsList[13].key"
            label="被合批物料条码(已作废)"
            align="center"
            prop="mergeQrCode"
            width="180"
            show-overflow-tooltip
          /> -->
          <!-- <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
            width="240"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-document-delete"
                size="mini"
                @click="handleSplit(scope.row)"
                >物料拆批</el-button
              >
              <el-button
                type="text"
                icon="el-icon-document-checked"
                size="mini"
                @click="handleBatches(scope.row)"
                >物料合批</el-button
              >
              <el-button
                type="text"
                icon="el-icon-printer"
                size="mini"
                @click="handlePrintRepair(scope.row)"
                >标签补打</el-button
              >
            </template>
          </el-table-column> -->
        </el-table>
      </template>
    </AutoResizer>

    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 物料拆分 -->
    <MaterialSplit ref="materialSplit" @complete="getList" />
    <!-- 物料合批 -->
    <MaterialBatch ref="materialBatch" @complete="getList" />
    <!-- 标签补打 -->
    <LabelPrinter ref="labelPrinter" @complete="getList" />

    <!-- 仓库调拨 -->
    <StockDailog
      ref="adjustDialog"
      :current-rows="currentRows"
      @complete="getList"
    />
  </div>
</template>

<script>
import {
  getMaterialDemolitionBatchPage,
  exportMaterialDemolitionBatchExcel,
} from "@/api/wms/inLibrary/materialDemolitionBatch";
import MaterialSplit from "./components/MaterialSplit.vue";
import MaterialBatch from "./components/MaterialBatch.vue";
import StockDailog from "./components/StockDailog.vue";
import LabelPrinter from "./components/LabelPrinter.vue";
import StockSelect from "../incoming/wareHousing/components/StockSelect.vue";
import AreaSelect from "../incoming/wareHousing/components/AreaSelect.vue";
import LocationSelect from "../incoming/wareHousing/components/LocationSelect.vue";
import { getFormColumnsList } from "@/api/system/saveColumns/index";
import { mapGetters } from "vuex";
import { isArray } from "min-dash";
import { DICT_TYPE } from "@/utils/dict";
import DictTag from "@/components/DictTag";

export default {
  name: "MaterialDemolitionBatch",
  components: {
    MaterialSplit,
    MaterialBatch,
    StockDailog,
    StockSelect,
    AreaSelect,
    LabelPrinter,
    LocationSelect,
    DictTag,
  },
  data() {
    return {
      printData: [],
      printStyle: `
        <style>
          table {
            width:100%;
            margin: 0 auto;
            border: 1px solid #000000;
            border-collapse: collapse;
            page-break-after:always;
            font-size: 12px;
            table-layout: fixed;
          }

          th, td {
            border: 1px solid #000000;
          }
          td {
            width:100%;
            word-break:keep-all;/* 不换行 */
            white-space:nowrap;/* 不换行 */
            overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow:ellipsis;
          }
        </style>
      `,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // WMS库内业务-物料拆合批列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        materialLots: null,
        materialNo: null,
        materialName: null,
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        qtyFlag: 0,
        inQty: null,
        produceDate: [],
        splitFlag: null,
        oldLotsSplit: null,
        mergeFlag: null,
        oldLotsMerge: null,
        mergeLots: null,
        remark: null,
        qrCode: null,
        width: null,
        length: null,
        midbin: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        materialLots: [
          { required: true, message: "物料批次不能为空", trigger: "blur" },
        ],
      },
      // 显示隐藏列参数
      columns: [
        { key: 0, label: "物料条码", visible: true },
        { key: 1, label: "物料批次", visible: true },
        { key: 2, label: "物料编码", visible: true },
        { key: 3, label: "物料名称", visible: true },
        { key: 21, label: "状态", visible: true },
        { key: 20, label: "呆滞料超期天数", visible: true },
        { key: 4, label: "仓库", visible: true },
        { key: 5, label: "区域", visible: true },
        { key: 6, label: "货位", visible: true },
        { key: 7, label: "数量", visible: true },
        { key: 8, label: "供应商", visible: true },
        { key: 9, label: "是否拆批物料", visible: true },
        { key: 10, label: "被拆物料条码", visible: true },
        { key: 11, label: "是否合批物料", visible: true },
        { key: 12, label: "合批物料条码(已作废)", visible: true },
        { key: 13, label: "被合批物料条码(已作废)", visible: true },
        { key: 14, label: "长度", visible: true },
        { key: 15, label: "宽度", visible: true },
        { key: 16, label: "批次号", visible: true },
        { key: 17, label: "生产日期", visible: true },
        { key: 18, label: "保质期", visible: true },
        { key: 19, label: "中间仓", visible: true },
      ],
      // 显示隐藏持久化参数
      columnsList: [],
      // 选中的数据
      currentRows: [],
    };
  },
  // 获取当前登录用户id
  computed: {
    ...mapGetters(["userId"]),
  },
  created() {
    // 获取显隐列列表
    this.getColumnsList();
    this.getList();
  },
  beforeUpdate() {
    this.$nextTick(() => {
      if (this.$refs.table) {
        this.$refs.table.doLayout();
      }
    });
  },
  methods: {
    getStyle(v) {
      let text = "";
      switch (v.row.validStatus) {
        case 1:
          text = "background: #ccc";
          break;
        case 2:
          text = "background: #F56c6c;";
          break;
        case 3:
          text = "background: yellow";
          break;
      }
      return text;
    },
    /** 查询列表 */
    getList(flag) {
      if (flag) {
        this.$nextTick(() => {
          if (this.$refs.table) {
            this.$refs.table.clearSelection();
          }
        });
      }
      this.loading = true;
      // 执行查询
      const params = {
        ...this.queryParams,
        qtyFlag: this.queryParams.qtyFlag ? 1 : 0,
        ...this.advParams,
      };
      getMaterialDemolitionBatchPage(params)
        .then((response) => {
          this.list = response.data.list;
          this.total = response.data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 仓库调拨
    handleAdjustment() {
      if (this.currentRows.length <= 0) {
        this.$modal.msgWarning("请选择要进行仓库调拨的数据");
        return;
      }
      this.$refs.adjustDialog.open = true;
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        materialLots: undefined,
        materialNo: undefined,
        materialName: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        produceDate: undefined,
        splitFlag: undefined,
        oldLotsSplit: undefined,
        mergeFlag: undefined,
        oldLotsMerge: undefined,
        mergeLots: undefined,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.advParams = {};
      this.handleQuery();
      this.$refs[`location1`].options = [];
      this.$refs[`area1`].options = [];
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有WMS库内业务-物料拆合批数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportMaterialDemolitionBatchExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "WMS库内业务-物料拆合批.xls");
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 选中的
    handleSelectionExpand(val) {
      this.currentRows = val;
    },
    // 物料拆批
    handleSplit(row) {
      const { inQty, id, qrCode } = row;
      this.$refs.materialSplit.form.id = id;
      this.$refs.materialSplit.form.qrCode = qrCode;
      this.$refs.materialSplit.form.inQty = inQty;
      this.$refs.materialSplit.visible = true;
    },
    // 物料合批
    handleBatches(row) {
      const { inQty, id, qrCode } = row;
      this.$refs.materialBatch.queryParams.id = id;
      this.$refs.materialBatch.queryParams.inQty = inQty;
      this.$refs.materialBatch.queryParams.qrCode = qrCode;
      this.$refs.materialBatch.visible = true;
    },
    // 标签补打
    handlePrintRepair(row) {
      if (row) {
        this.$refs.labelPrinter.form.qrCode = row.qrCode;
      } else {
        if (this.currentRows.length === 0) {
          this.$modal.msgWarning("请先选择您要打印的数据!");
          return;
        }
        const arr = [];
        this.currentRows.forEach((v) => {
          arr.push(v.qrCode);
        });
        this.$refs.labelPrinter.form.qrCode = arr.join(",");
      }
      this.$refs.labelPrinter.visible = true;
    },
    stockChange(item) {
      if (item) {
        const { id } = item;
        this.$refs[`area1`].options = [];
        this.$refs[`area1`].fetchAreaList(id);
      }
    },
    areaChange(item) {
      if (item) {
        const { id } = item;
        this.$refs[`location1`].options = [];
        this.$refs[`location1`].fetchLocationList(id);
      }
    },
    removeDuplicates(arr) {
      const idMap = new Map();
      arr.forEach((item) => {
        idMap.set(item.key, item);
      });
      return Array.from(idMap.values());
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams;
      this.handleQuery();
    },
    // 获取显示隐藏列
    getColumnsList() {
      const { componentName } = this.$route.meta || null;
      const params = {
        userId: this.userId,
        vueForm: componentName,
      };
      getFormColumnsList(params)
        .then((res) => {
          if (isArray(res.data)) {
            this.columnsList = res.data.length === 0 ? this.columns : res.data;
            // 对比默认数据和接口数据，将缺失的列添加到接口数据中
            this.columnsList = this.columns.reduce((acc, defaultColumn) => {
              const found = res.data.find(
                (apiColumn) => apiColumn.key === defaultColumn.key
              );
              if (!found) {
                acc.push({
                  ...defaultColumn,
                  vueForm: componentName,
                  userId: this.userId,
                  id: null,
                });
              }
              return acc;
            }, res.data);
            this.columnsList = this.removeDuplicates(this.columnsList);
          } else {
            this.columnsList = this.columns;
          }
        })
        .catch((err) => {
          if (err) {
            this.columnsList = this.columns;
          }
        });
    },
    // 小数点问题处理
    getHandleNumber(val) {
      return Math.round(parseFloat(val) * 100000000) / 100000000;
    },
    // 数量合计
    getSummaries(param) {
      const { columns } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }

        const values = this.currentRows.map((item) =>
          Number(item[column.property])
        );
        if (
          column.property === "inQty" ||
          column.property === "width" ||
          column.property === "length"
        ) {
          sums[index] = values.reduce((acc, cur) => {
            const value = Number(cur);
            if (!isNaN(value)) {
              return this.getHandleNumber(acc + cur);
            } else {
              return acc;
            }
          }, 0);
          sums[index];
        }
      });
      return sums;
    },
  },
};
</script>
