<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="60px" style="margin-top: 0px;">
      <el-form-item :label="'BU:'">
        <el-select v-model="searchData.buNo" placeholder="请选择"  style="width: 80px">
          <el-option label="全部" value=""></el-option>
        <el-option
          v-for = "i in buList"
          :key = "i.buNo"
          :label = "i.buDesc"
          :value = "i.buNo">
        </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'发货通知单:'">
        <el-input v-model="searchData.delNo"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'CMC Invoice:'">
        <el-input v-model="searchData.cmcInvoice"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'通知单状态:'">
        <el-select filterable v-model="searchData.notifyStatus" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="已计划" value="已计划"></el-option>
          <el-option label="已下达" value="已下达"></el-option>
          <el-option label="仓库已确认" value="仓库已确认"></el-option>
          <el-option label="已报关" value="已报关"></el-option>
          <el-option label="订单取消" value="订单取消"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'ReadyDate'" >
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'To'" >
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="改单">
        <el-checkbox v-model="searchData.modifyData" true-label="true" false-label="false" @change="searchTable()"></el-checkbox>
      </el-form-item>
      <el-form-item label="FSC">
        <el-checkbox v-model="searchData.fscFlag" true-label="true" false-label="false" @change="searchTable()"></el-checkbox>
      </el-form-item>
      <el-form-item label="沃尔玛订单">
        <el-checkbox v-model="searchData.walMartOrderFlag" true-label="true" false-label="false" @change="searchTable()"></el-checkbox>
      </el-form-item>
      <el-form-item label="维护箱尺寸">
        <el-checkbox v-model="searchData.boxSizeFlag" true-label="true" false-label="false" @change="searchTable()"></el-checkbox>
      </el-form-item>
      <el-form-item :label="' '" >
        <el-button @click="searchTable()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'查询'}}</el-button>
      </el-form-item>
      <el-form-item :label="' '" >
        <el-button @click="importModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'导入'}}</el-button>
        <el-button @click="exportExcel()" type="primary" style="margin-left: 2px">{{'导出'}}</el-button>
      </el-form-item><br>
      <el-form-item label=" ">
        <el-button @click="exportInvoiceList()" type="primary" style="margin-left: 2px">{{'导出发票'}}</el-button>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="exportGoodsList()" type="primary" style="margin-left: 2px">{{'导出出口货物委托书'}}</el-button>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="openCustomerInfoDialog()" type="primary" style="margin-left: 2px">{{'客户信息'}}</el-button>
      </el-form-item>
    </el-form>

    <el-table
      @row-click="changeData"
      highlight-current-row
      :height="height"
      :data="dataList"
      ref="mainTable" :cell-style="cellStyle"
      border :row-class-name="tableRowClassName"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="140"
        fixed="left"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="updateHeaderModelDo(scope.row)">修改</a>
          <a type="text" style="color: green" size="small" v-if="scope.row.notifyStatus==='已计划' && scope.row.notifyStatus!=='订单取消' && !xiadaLoading" @click="xiadaChoose(scope.row)">下达</a>
          <a type="text" style="color: orange" size="small" v-if="scope.row.notifyStatus==='已下达'&& scope.row.notifyStatus!=='订单取消'" @click="jihuaEcssDel(scope.row)">取消下达</a>
          <a type="text" style="color: green" size="small" v-if="scope.row.notifyStatus==='已下达' && scope.row.walMartOrderFlag==='Y'" @click="declarationCompleted(scope.row)">一键结单</a>
          <a type="text" style="color: red" size="small" v-if="scope.row.notifyStatus!=='订单取消'" @click="cancelDelHeader(scope.row)">废弃</a>
          <a type="text" style="color: green" size="small" v-if="scope.row.notifyStatus==='订单取消'" @click="recoverDelHeader(scope.row)">取消废弃</a>
          <a type="text" style="color: red" size="small" v-if="scope.row.notifyStatus==='已计划'&& scope.row.notifyStatus!=='订单取消'" @click="deleteDelHeader(scope.row)">删除</a>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-tabs style="font-size: 12px;min-height: 200px" class="customer-tab" v-model="activeName"   type="border-card" @tab-click="tabClick" >
      <el-tab-pane :label="currentRow.cmcInvoice+'明细'" name="detail">
        <el-button v-show="currentRow.notifyStatus!=='订单取消'" @click="openCreateDetailModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'新增'}}</el-button>
        <el-button v-show="currentRow.notifyStatus!=='订单取消'" @click="importDetailModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'改单导入'}}</el-button>
        <el-button v-show="currentRow.notifyStatus!=='订单取消'" @click="importUpcModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'UPC导入'}}</el-button>
        <el-button v-show="currentRow.notifyStatus!=='订单取消'" @click="fixTtlAmountHandle()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'TTL Amount修正'}}</el-button>
        <el-table ref="detailTable"
          :height="height"
          :data="dataList2" :cell-style="cellStyleDetail"
          border show-summary :summary-method="getSummaries"
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in columnList2" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <template v-if="item.columnProp === 'ttlAmount' || item.columnProp === 'sumPrice'">
                <span>{{!!scope.row[item.columnProp]?scope.row[item.columnProp].toFixed(2):''}}</span>
              </template>
              <!-- PN字段特殊处理，添加提示信息 -->
              <template v-else-if="item.columnProp === 'pn'">
                <el-tooltip
                  v-if="isPnDataIncomplete(scope.row)"
                  content="品名未维护，点击跳转到维护页面"
                  placement="top">
                  <span
                    v-if="!item.columnHidden"
                    class="clickable-pn"
                    @click="navigateToPartHsCode(scope.row.pn)">
                    {{ scope.row[item.columnProp] }}
                  </span>
                </el-tooltip>
                <span v-else-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
              </template>
              <template v-else>
                <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
              </template>
            </template>
          </el-table-column>
          <el-table-column
            fixed="left"
            header-align="center"
            align="center"
            width="100" v-if="currentRow.notifyStatus!=='订单取消'"
            label="操作">
            <template slot-scope="scope">
              <a v-if="currentRow.notifyStatus!=='订单取消'&& scope.row.qty!==0" type="text" size="small" @click="openUpdateDetailModel(scope.row)">修改</a>
              <a v-if="currentRow.notifyStatus!=='订单取消' && scope.row.qty!==0" style="color: red" type="text" size="small" @click="deleteDelDetail(scope.row)">取消</a>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="装箱明细" name="pallet">
        <packing-detail-tab
          ref="packingDetailTab"
          :current-row="currentRow"
          :height="height"
          :show-actions="false">
        </packing-detail-tab>
      </el-tab-pane>
      <el-tab-pane label="UPC明细" name="upcDetail" v-if="dataList3.length > 0">
        <el-button
          @click="deleteAllUpcData()"
          type="danger"
          style="margin-bottom: 2px;">
          一键删除
        </el-button>
        <el-table
          ref="upcTable"
          :height="height"
          :data="dataList3"
          :span-method="arraySpanMethod"
          border
          style="width: 100%;">
          <el-table-column
            prop="cartonNo"
            label="箱号"
            width="120"
            align="center"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="so"
            label="SO"
            width="120"
            align="center"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="pn"
            label="P/N"
            min-width="150"
            align="left"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="description"
            label="Description"
            min-width="200"
            align="left"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="upc"
            label="UPC"
            width="150"
            align="center"
            header-align="center">
          </el-table-column>
          <el-table-column
            prop="qty"
            label="Qty"
            width="100"
            align="center"
            header-align="center">
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="相关文档" name="codelnotifyDocument">
        <oss-components label="申请单号" style="margin-top: 5px" height="44vh" :columns="ossColumns"
                        :order-ref1="currentRow.site" :order-ref2="currentRow.delNo" :codelnotifyFlag="'1'"
                        :rfq-no="currentRow.delNo">
        </oss-components>
      </el-tab-pane>
    </el-tabs>
    <el-dialog title="编辑发货通知单" :close-on-click-modal="false" v-drag :visible.sync="updateHeaderModelFlag" width="672px">
      <el-form  label-position="top"  style="margin-left: 5px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'BU'" >
              <el-input v-model="updateHeaderModel.buDesc" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'CMC Invoice'" >
              <el-input v-model="updateHeaderModel.cmcInvoice" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'发货通知单号'" >
              <el-input v-model="updateHeaderModel.delNo" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'ReadyDate'" >
              <el-date-picker
                style="width: 145px"
                v-model="updateHeaderModel.readyDate"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'ShippingMode'" >
              <el-input v-model="updateHeaderModel.shippingMode"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'Destination'" >
              <el-input v-model="updateHeaderModel.destination"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'发货日期'" >
              <el-date-picker
                style="width: 145px"
                v-model="updateHeaderModel.notifyDate"
                disabled
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item :label="'Remark'" >
              <el-input v-model="updateHeaderModel.remark"  ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="doUpdateHeader()">保存</el-button>
        <el-button type="primary" @click="updateHeaderModelFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="编辑发货通知单明细" :close-on-click-modal="false" v-drag :visible.sync="updateDetailModelFlag" width="750px">
      <el-form  label-position="top"  style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="'行号'" >
              <el-input v-model="updateDetailModel.itemNo" style="text-align: right" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  :label="'PN'">
              <span slot="label" @click="queryComponentPartModal"><a herf="#">PN</a></span>
              <el-input v-model="updateDetailModel.pn"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'Description'" >
              <el-input v-model="updateDetailModel.partDescription"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Qty (pcs)'" >
              <el-input v-model="updateDetailModel.qty" type="number" @input="calculateAmounts"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'销售订单号'" >
              <el-input v-model="updateDetailModel.salesOrder"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'客户采购单号'" >
              <el-input v-model="updateDetailModel.customerPO"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Version'" >
              <el-input v-model="updateDetailModel.version"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Status'" >
              <el-input v-model="updateDetailModel.status"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Family'" >
              <el-input v-model="updateDetailModel.family"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'LT (wks)'" >
              <el-input v-model="updateDetailModel.lt" type="number" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'CMC Comment'" >
              <el-input v-model="updateDetailModel.cmcComment"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'内外销方式'" >
              <el-input v-model="updateDetailModel.saleType"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'AWB/ BL#'" >
              <el-input v-model="updateDetailModel.awbBl"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'ShippingNumber'" >
              <el-input v-model="updateDetailModel.shippingNumber"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Forwarder Info'" >
              <el-input v-model="updateDetailModel.forwarderInfo"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Currency'" >
              <el-input v-model="updateDetailModel.currency"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'TP'" >
              <el-input v-model="updateDetailModel.tp" type="number" @input="calculateAmounts"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'TTL Amount'" >
              <el-input v-model="updateDetailModel.ttlAmount" type="number" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'VAT'" >
              <el-input v-model="updateDetailModel.vat" @input="calculateAmounts"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'价税合计'" >
              <el-input v-model="updateDetailModel.sumPrice" type="number" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'SO'" >
              <el-input v-model="updateDetailModel.so"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'UPC'" >
              <el-input v-model="updateDetailModel.upc"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Roll'" >
              <el-input v-model="updateDetailModel.roll"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'Carton'" >
              <el-input v-model="updateDetailModel.carton"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item :label="'Remark'" >
              <el-input v-model="updateDetailModel.remark"  ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="doUpdateDetail()" :loading="updateDetailLoading" :disabled="updateDetailLoading">
          {{ updateDetailLoading ? '保存中...' : '保存' }}
        </el-button>
        <el-button type="primary" @click="updateDetailModelFlag=false" :disabled="updateDetailLoading">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="订单确认" :close-on-click-modal="false" v-drag :visible.sync="walMartOrderDialog" width="200px">
      <el-form label-position="top"  style="margin-left: 36px;margin-top: 10px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item v-if="currentRow.buNo=='03-RFID'" :label="'沃尔玛订单'" >
              <el-radio v-model="walMartOrderFlag" label="Y">是</el-radio>
              <el-radio v-model="walMartOrderFlag" label="N">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item v-if="currentRow.buNo=='03-RFID'" :label="'FSC'" >
              <el-radio v-model="fscFlag" label="Y">是</el-radio>
              <el-radio v-model="fscFlag" label="N">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="'维护箱尺寸'" >
              <el-radio v-model="boxSizeFlag" label="Y">是</el-radio>
              <el-radio v-model="boxSizeFlag" label="N">否</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="xiadaEcssDel" :loading="xiadaLoading">
          {{ xiadaLoading ? '下达中...' : '确定' }}
        </el-button>
        <el-button type="primary" @click="walMartOrderDialog=false" :disabled="xiadaLoading">关闭</el-button>
      </el-footer>
    </el-dialog>
    <!-- 导入 -->
    <del-upload-excel ref="delUploadExcel" @refreshTable="searchTable" v-drag></del-upload-excel>
    <!-- 导入 -->
    <del-detail-upload-excel ref="delDetailUploadExcel" @refreshTable="searchTable" v-drag></del-detail-upload-excel>
    <!-- UPC导入 -->
    <upc-upload-excel ref="upcUploadExcel" @refreshTable="searchTable" v-drag></upc-upload-excel>
    <!--列表的组件-->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
    <el-dialog title="物料清单" top="17vh" :close-on-click-modal="false" v-drag :visible.sync="componentPartModelFlag" width="700px">
      <el-form :inline="true" label-position="top" :model="componentPartData">
        <el-form-item :label="'PN'">
          <el-input v-model="componentPartData.sku" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料编码'">
          <el-input v-model="componentPartData.partNo" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料描述'">
          <el-input v-model="componentPartData.partDesc" clearable style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="queryComponentPartList">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="250"
        :data="componentPartList"
        @row-dblclick="getComponentRowData"
        border
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in componentPartColumnList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <el-pagination
        @size-change="sizeChangeHandle3"
        @current-change="currentChangeHandle3"
        :current-page="pageIndex3"
        :page-sizes="[20, 50, 100, 200, 500]"
        :page-size="pageSize3"
        :total="totalPage3"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <el-footer style="height:35px;margin-top:10px;text-align:center">
        <el-button type="primary" @click="componentPartModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="导出发票" :close-on-click-modal="false" v-drag :visible.sync="exportInvoiceFlag" width="450px">
      <el-form label-position="top"  style="margin-left: 2px;margin-top: 10px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item :label="''" >
              <template #label>
                <span slot="label" style="" class="big-label">
                  <a href="#" @click="openTemplate('发票')">发票模版</a>
                </span>
              </template>
              <el-input v-model="exportInvoice.templateName" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item :label="''" >
              <el-checkbox v-model="exportInvoice.hsCodeDesc">品名</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item :label="''" >
              <el-checkbox v-model="exportInvoice.hsCodeFlag">Hs Code</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item :label="''" >
              <el-checkbox v-model="exportInvoice.contractFlag">合同</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item :label="''" >
              <el-checkbox v-model="exportInvoice.goodsLabel">货物明细</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'品名类型'" >
              <el-radio v-model="exportInvoice.hsCodeDescType" label="Y">中文</el-radio>
              <el-radio v-model="exportInvoice.hsCodeDescType" label="N">英文</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="' '" >
              <el-checkbox v-model="exportInvoice.showWeight">显示毛净重</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'RFID Base Material'" >
              <el-checkbox v-model="exportInvoice.material"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'HS Code'" >
              <el-input :disabled="!exportInvoice.material" v-model="exportInvoice.hsCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'Non-reusable plastic packaging'" >
              <el-checkbox v-model="exportInvoice.packaging"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'plastic packaging'" >
              <el-input :disabled="!exportInvoice.packaging" v-model="exportInvoice.kgs"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="currentRow.buNo==='01-Label' || currentRow.buNo==='03-RFID'">
            <el-form-item :label="'制造地'" >
              <el-input  v-model="exportInvoice.origin"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" style="">
            <el-form-item :label="'备注'" >
              <el-input type="textarea" :rows="3" v-model="exportInvoice.fpremark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table v-show="currentRow.buNo==='03-RFID'"
                :height="240"
                :data="notifyPartDetailList"
                stripe
                highlight-current-row
                border :row-style="{ height: '30px' }"
                style="width: 100%;margin-top: 60px" class="zxClass">
        <el-table-column
          prop="pn"
          header-align="center"
          align="center"
          label="PN">
        </el-table-column>
        <el-table-column
          prop="ehundred"
          header-align="center"
          align="center"
          label="E100">
          <template slot-scope="scope">
            <el-input v-model="scope.row.ehundred" style="width: 100px;"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="lossratio"
          header-align="center"
          align="center"
          label="纯FSC纸重量损耗">
          <template slot-scope="scope">
            <el-input v-model="scope.row.lossratio" style="width: 100px;"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
        <el-button type="primary" @click="downloadInvoice()">确定</el-button>
        <el-button type="primary" @click="exportInvoiceFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="导出出口货物委托书" :close-on-click-modal="false" v-drag :visible.sync="exportGoodsFlag" width="500px">
      <el-form label-position="top"  style="margin-left: 7px;margin-top: 10px;">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="'品名类型'" >
              <el-radio v-model="exportGoods.hsCodeDescType" label="Y">中文</el-radio>
              <el-radio v-model="exportGoods.hsCodeDescType" label="N">英文</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'贸易方式'" >
              <el-input v-model="exportGoods.salesMethod"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'币制'" >
              <el-input  v-model="exportGoods.currency"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'货物产地'" >
              <el-input  v-model="exportGoods.madeArea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'发货港'" >
              <el-input v-model="exportGoods.sendPort"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'唛头'" >
              <el-input v-model="exportGoods.voyage"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'提/送货日期'" >
              <el-input v-model="exportGoods.deliveryGoodsDate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'船期'" >
              <el-input v-model="exportGoods.shippingDate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="'发货人'" >
              <el-input type="textarea"
                        :rows="4" v-model="exportGoods.shipper"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 80px;text-align:center">
        <el-button type="primary" @click="downloadExportGoods()">确定</el-button>
        <el-button type="primary" @click="exportGoodsFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="模版" @close="closeTemplateDialog" @open="openTemplateDialog" :visible.sync="templateFlag" width="559px" v-drag>
      <el-form inline="inline" label-position="top" :model="templateData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="模版名称">
          <el-input v-model="templateData.name" clearable style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" style="padding: 3px 12px" @click="searchTemplateList()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="height + 110"
        :data="templateList"
        stripe
        highlight-current-row
        border
        @row-dblclick="templateRowDblclick"
        style="width: 100%;">
        <el-table-column
          prop="buNo"
          header-align="center"
          align="center"
          label="BuNo">
        </el-table-column>
        <el-table-column
          prop="name"
          header-align="center"
          align="center"
          label="模版名称">
        </el-table-column>
        <el-table-column
          prop="shippingMode"
          header-align="center"
          align="center"
          label="运输方式">
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button @click="templateFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 客户信息编辑对话框 -->
    <el-dialog title="编辑客户信息" :close-on-click-modal="false" v-drag :visible.sync="customerInfoDialogFlag" width="600px">
      <el-form label-position="top" style="margin-left: 7px; margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="16">
            <el-form-item label="客户名称(Customer Name)">
              <el-input
                v-model="customerInfoModel.customerName"
                style="cursor: pointer;">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="贸易国(Sales Area)">
              <el-input v-model="customerInfoModel.salesArea" placeholder="请输入贸易国"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="客户地址(Local Ship Address)">
              <el-input v-model="customerInfoModel.localShipAddress"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="16">
            <el-form-item label="收货单位(Overseas Shipper)">
              <el-input v-model="customerInfoModel.overseasShipper"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运抵国(Cnative)">
              <el-input v-model="customerInfoModel.cnative" placeholder="请输入运抵国"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="收货单位地址(Overseas Address)">
              <el-input v-model="customerInfoModel.overseasAddress">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="模板名称">
              <el-input
                v-model="customerInfoModel.templateName"
                placeholder="请输入模板名称（用于另存为新的客户模版）">
                <el-button
                  slot="append"
                  type="success"
                  :disabled="!customerInfoModel.templateName || !customerInfoModel.templateName.trim()"
                  :class="{ 'fake-disabled': !customerInfoModel.templateName }"
                  @click="saveAsTemplate">
                  另存为
                </el-button>
              </el-input>
            </el-form-item>

          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px; margin-top: 10px; text-align:center">
        <el-button type="primary" @click="updateCustomerInfo('')">仅保存客户信息</el-button>
        <el-button type="primary" @click="updateCustomerInfo(customerInfoModel.templateNo)">保存并修改模版</el-button>
        <el-button @click="customerInfoDialogFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
  </div>
</template>

<script>
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import delUploadExcel from "./del_upload_excel.vue";
  import delDetailUploadExcel from "./del_detail_upload_excel.vue";
  import upcUploadExcel from "./upc_upload_excel.vue";
  import PackingDetailTab from "./components/PackingDetailTab.vue";
  import {} from "@/api/sysLanguage.js"
  import { getTableUserListLanguage} from "@/api/table.js"
  import {getTableDefaultListLanguage} from "../../../api/table";
  import excel from "@/utils/excel-util.js";
  import {
    searchEcssCoDelNotifyHeader,
    searchEcssCoDelNotifyDetail,
    updateEcssDelHeader,
    updateCustomerInfo,
    deleteEcssDelHeader,
    cancelEcssDelHeader,
    recoverEcssDelHeader,
    changeEcssDelStatus,
    updateEcssDelDetail,
    deleteEcssDelDetail,
    searchCoDelPalletDataNew,
    queryPartListAll,
    searchTemplateList,
    getCustomerList,
    getCustomers,
    getCustomerAdd,
    getNotifyPartDetail,
    fixTtlAmount,
    searchUpcImportData,
    deleteUpcImportData,
    updateCustomerTemplate
  }from "@/api/ecss/ecss.js"
  import {getBuList}from  '@/api/factory/site.js'
  import ExportUtil from "@/utils/export";
  import OssComponents from '../oss/ossComponents.vue'
  export default {
    name: "null",
    components:{
      OssComponents,
      delUploadExcel,
      delDetailUploadExcel,
      upcUploadExcel,
      Chooselist,
      PackingDetailTab,
    },
    data() {
      return {
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        // 选中行持久化相关
        selectedRowKey: null, // 当前选中行的唯一标识
        componentPartModelFlag: false,
        componentPartData: {
          site: '',
          buNo: '',
          sku: '',
          partNo: '',
          partDesc: '',
          page: 1,
          limit: 10
        },
        pageIndex3: 1,
        pageSize3: 20,
        totalPage3: 0,
        componentPartList: [],
        componentPartColumnList: [
          {
            columnProp: 'sku',
            headerAlign: "center",
            align: "center",
            columnLabel: 'PN',
            columnHidden: false,
            columnImage: false,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            columnProp: 'partNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '物料编码',
            columnHidden: false,
            columnImage: false,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '物料描述',
            columnHidden: false,
            columnImage: false,
            status: true,
            fixed: '',
            columnWidth: 300
          },
        ],

        walMartOrderFlag: 'N',
        fscFlag: 'N',
        boxSizeFlag: 'N',
        walMartOrderDialog:false,
        buList:[],
        dataList:[],
        dataList2:[],
        dataList3:[], // UPC数据列表
        dataListLoading: false,
        xiadaLoading: false, // 下达按钮加载状态
        updateDetailLoading: false, // 明细保存/取消按钮加载状态
        searchData: {
          page: 1,
          limit: 100,
          buNo:'',
          delNo:'',
          cmcInvoice:'',
          notifyStatus:'',
          startDate:'',
          endDate:'',
          username:this.$store.state.user.name,
          modifyData:'',
          fscFlag:'',
          walMartOrderFlag:'',
          boxSizeFlag:'',
        },
        buttons:{
          search:'查询',
        },
        updateHeaderModelFlag:false,
        updateHeaderModel:{
          site:'',
          buDesc:'',
          cmcInvoice:'',
          delNo:'',
          readyDate:'',
          shippingMode:'',
          destination:'',
          notifyDate:'',
          remark:'',
        },
        updateDetailModelFlag:false,
        updateDetailModel:{
          site:'',
          buNo:'',
          delNo:'',
          itemNo:'',
          partNo:'',
          partDescription:'',
          qty:'',
          salesOrder:'',
          line:'',
          customerPO:'',
          version:'',
          status:'',
          family:'',
          lt:'',
          cmcComment:'',
          saleType:'',
          awbBl:'',
          shippingNumber:'',
          forwarderInfo:'',
          currency:'',
          tp:'',
          ttlAmount:'',
          sumPrice:'',
          so:'',
          upc:'',
          remark:'',
          pn:'',
          addFlag:'',
          carton:'',
          vat:'',
          roll:'',
        },
        activeName:'detail',
        columnList1: [
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1BuDesc',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "buDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "BU",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1CmcInvoice',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "cmcInvoice",
            headerAlign: "center",
            align: "left",
            columnLabel: "CMC Invoice",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1DelNo',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "delNo",
            headerAlign: "center",
            align: "center",
            columnLabel: "发货通知单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 110
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1ReadyDate',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "readyDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "ReadyDate",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1CustomerName',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "customerName",
            headerAlign: "center",
            align: "left",
            columnLabel: "客户名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 220
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1ShippingMode',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "shippingMode",
            headerAlign: "center",
            align: "left",
            columnLabel: "ShippingMode",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1Destination',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "destination",
            headerAlign: "center",
            align: "left",
            columnLabel: "Destination",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1NotifyStatus',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "notifyStatus",
            headerAlign: "center",
            align: "left",
            columnLabel: "通知单状态",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1NotifyStatus',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "modifyLabel",
            headerAlign: "center",
            align: "left",
            columnLabel: "改单",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1NotifyDate',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "notifyDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "发货日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1ErpDelNo',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "walMartOrderFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "沃尔玛订单",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1BoxSizeFlag',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "boxSizeFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "维护箱尺寸",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1CreateBy',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "createBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "创建人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1CreateDate',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "createDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "创建时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1UpdateBy',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "updateBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "修改人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1UpdateDate',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "updateDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "修改时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 130
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table1Remark',
            tableId: "801001Table1",
            tableName: "关务系统发货通知单",
            columnProp: "remark",
            headerAlign: "center",
            align: "left",
            columnLabel: "Remark",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
        ],
        columnList2: [
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2ItemNo',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "itemNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "行号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2PartNo',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "pn",
            headerAlign: "center",
            align: "left",
            columnLabel: "PN",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2PartDescription',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "partDescription",
            headerAlign: "center",
            align: "left",
            columnLabel: "Description",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Qty',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "qty",
            headerAlign: "center",
            align: "right",
            columnLabel: "Qty (pcs)",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2SalesOrder',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "salesOrder",
            headerAlign: "center",
            align: "left",
            columnLabel: "销售订单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2CustomerPO',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "customerPO",
            headerAlign: "center",
            align: "left",
            columnLabel: "客户采购单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Version',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "version",
            headerAlign: "center",
            align: "left",
            columnLabel: "Version",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Status',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "status",
            headerAlign: "center",
            align: "left",
            columnLabel: "Status",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Family',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "family",
            headerAlign: "center",
            align: "left",
            columnLabel: "Family",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Lt',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "lt",
            headerAlign: "center",
            align: "right",
            columnLabel: "LT (wks)",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2CmcComment',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "cmcComment",
            headerAlign: "center",
            align: "left",
            columnLabel: "CMC Comment",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2SaleType',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "saleType",
            headerAlign: "center",
            align: "left",
            columnLabel: "内外销方式",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2AwbBl',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "awbBl",
            headerAlign: "center",
            align: "left",
            columnLabel: "AWB/ BL#",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2ShippingNumber',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "shippingNumber",
            headerAlign: "center",
            align: "left",
            columnLabel: "ShippingNumber",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2ForwarderInfo',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "forwarderInfo",
            headerAlign: "center",
            align: "left",
            columnLabel: "Forwarder Info",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Currency',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "currency",
            headerAlign: "center",
            align: "left",
            columnLabel: "Currency",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Tp',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "tp",
            headerAlign: "center",
            align: "right",
            columnLabel: "TP",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2TtlAmount',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "ttlAmount",
            headerAlign: "center",
            align: "right",
            columnLabel: "TTL Amount",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "vat",
            headerAlign: "center",
            align: "right",
            columnLabel: "VAT",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2SumPrice',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "sumPrice",
            headerAlign: "center",
            align: "right",
            columnLabel: "价税合计",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2So',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "so",
            headerAlign: "center",
            align: "left",
            columnLabel: "SO",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Upc',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "upc",
            headerAlign: "center",
            align: "left",
            columnLabel: "UPC",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 801001,
          //   serialNumber: '801001Table2ErpDelItemNo',
          //   tableId: "801001Table2",
          //   tableName: "关务系统发货通知单明细",
          //   columnProp: "erpDelItemNo",
          //   headerAlign: "center",
          //   align: "right",
          //   columnLabel: "ERP发货单行号",
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: '',
          //   columnWidth: 60
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "remark",
            headerAlign: "center",
            align: "left",
            columnLabel: "Remark",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "roll",
            headerAlign: "center",
            align: "right",
            columnLabel: "Roll",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "carton",
            headerAlign: "center",
            align: "right",
            columnLabel: "Carton",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "qtyRoll",
            headerAlign: "center",
            align: "right",
            columnLabel: "qty/roll",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801001,
            serialNumber: '801001Table2Remark',
            tableId: "801001Table2",
            tableName: "关务系统发货通知单明细",
            columnProp: "qtyBox",
            headerAlign: "center",
            align: "right",
            columnLabel: "qty/box",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
        ],

        ossColumns:[
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table2FileName',
            tableId: '103001Table2',
            tableName: '文件信息表',
            columnProp: 'fileName',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '文件名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table2FileRemark',
            tableId: '103001Table2',
            tableName: '文件信息表',
            columnProp: 'fileRemark',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 240
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table2CreateDate',
            tableId: '103001Table2',
            tableName: '文件信息表',
            columnProp: 'createDate',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '上传时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
          {
            userId: this.$store.state.user.name,
            functionId: 103001,
            serialNumber: '103001Table2CreatedBy',
            tableId: '103001Table2',
            tableName: '文件信息表',
            columnProp: 'createdBy',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '上传人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          }
        ],
        currentRow:{},
        // 导出 start
        exportData: [],
        exportName: '发货通知单'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["发货通知单"],
        exportFooter: [],
        // 导出 end
        exportInvoiceFlag:false,
        exportInvoice:{
          origin:"made in china",
          templateName:'',
          hsCodeDesc:'',
          contractFlag:'',
          packaging:'',
          kgs:'',
          hsCode:'',
          material:'',
          hsCodeDescType:'',
          goodsLabel:true,
          hsCodeFlag:true,
          overseasShipper:'',
          overseasAddress:'',
          fpremark:'',
          showWeight:false
        },
        exportGoodsFlag:false,
        exportGoods:{
          salesMethod:'EXW',
          currency: 'USD',
          madeArea: 'Nantong, China',
          sendPort:'Shanghai, China',
          deliveryGoodsDate:'',
          voyage :'',
          shippingDate:'',
          hsCodeDescType:'Y',
          shipper:'Checkpoint Commercial (Shanghai) Co., Ltd.   保点贸易（上海）有限公司\t\t\t\t\t\t\n' +
            'Room 1411, No. 31, Lane 2419, Hunan Road, Pudong New Area, Shanghai\t\t\t\t\t\t\n' +
            '电话/Tel: (86-21)38112888   传真/Fax: (86-21)38112990\t\t\t\t\t\t\n' +
            '上海市浦东新区沪南路2419弄31号1411室\t\t\t\t\t\t\n'
        },
        notifyPartDetailList:[],
        templateFlag:false,
        templateData:{},
        templateList:[],
        customerData:{},
        customerAddData:{},
        // 客户信息编辑相关
        customerInfoDialogFlag: false,
        customerInfoModel: {
          customerName: '',
          localShipAddress: '',
          overseasShipper: '',
          overseasAddress: '',
          salesArea: '',
          cnative: '',
          templateName: ''
        },
        // 客户选择相关
        customerSelectFlag: false,
        addressSelectFlag: false,
        shipperSelectFlag: false,
        overseasAddressSelectFlag: false,
        customerListForEdit: [],
        customerAddrsForEdit: [],
        customSearchData: {},
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = (window.innerHeight - 240)/2;
      })
    },
    methods: {
      isPnDataIncomplete(row) {
        const hsCodeDesc = row.hsCodeDesc !== null && row.hsCodeDesc !== undefined && row.hsCodeDesc !== ''&& row.hsCodeDesc !== '*';
        return !hsCodeDesc;
      },

      // 跳转到PN维护页面
      navigateToPartHsCode(pn) {
        if (!pn) {
          this.$message.warning('PN不能为空');
          return;
        }
        this.$router.push({
          path: '/ecss-partHsCode',
          query: {
            sku: pn
          }
        });
      },
      // 获取基础数据列表S
      getBaseList(val, type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 507) {
            strVal = this.updateDetailModel.partNo
          }
          this.$refs.baseList.init(val, strVal)
        })
      },

      /* 列表方法的回调 */
      getBaseData(val) {
        if (this.tagNo === 507) {
          this.updateDetailModel.partNo = val.part_no
        }
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.searchTable()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.searchTable()
      },
      searchTable(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        searchEcssCoDelNotifyHeader(this.searchData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            if(this.dataList.length>0){
              this.dataList.forEach(o => {
                // 显示改单次数，如：改单（1）、改单（2）
                o.modifyLabel = !!o.modifyFlag ? (o.modifyCount>1 ? '改单(' + o.modifyCount + ')' : '改单(1)') : '';
              });

              // 使用 $nextTick 确保 DOM 渲染完成后再设置选中行
              this.$nextTick(() => {
                try {
                  // 检查表格引用是否存在
                  if (!this.$refs.mainTable) {
                    console.warn('[行选择持久化] 表格引用不存在，跳过设置选中行');
                    return;
                  }

                  // 尝试恢复之前选中的行
                  const restoredRow = this.restoreSelectedRow();
                  if (restoredRow) {
                    this.$refs.mainTable.setCurrentRow(restoredRow);
                    this.changeData(restoredRow);
                  } else {
                    // 如果没有之前选中的行，默认选中第一行
                    this.$refs.mainTable.setCurrentRow(this.dataList[0]);
                    this.changeData(this.dataList[0]);
                  }
                } catch (error) {
                  console.error('[行选择持久化] 设置选中行失败:', error);
                  // 降级处理：只调用 changeData，不设置表格选中状态
                  const restoredRow = this.restoreSelectedRow();
                  this.changeData(restoredRow || this.dataList[0]);
                }
              });
            }else {
              this.changeData(null)
            }
          } else {
            this.dataList = [];
          }
        });
      },
      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn (tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList1 = data.rows
                break;
              // case 2:
              //   this.columnDetailList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },
      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable = {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList1 = data.rows
                break;
              // case 2:
              //   this.columnDetailList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },
      changeData(row){
        this.currentRow = JSON.parse(JSON.stringify(row));
        this.headerData=row;

        // 保存选中行的唯一标识到本地存储
        if (row && row.delNo) {
          this.selectedRowKey = row.delNo;
          this.saveSelectedRowToStorage();
        }

        // 预先查询UPC数据，用于判断是否显示UPC tab
        this.getUpcDataList();

        this.refreshCurrentTabTable ();
      },
      importModel(){
        this.$nextTick(() => {
          this.$refs.delUploadExcel.init()
        })
      },
      importDetailModel(){
        this.$nextTick(() => {
          this.$refs.delDetailUploadExcel.init(this.currentRow)
        })
      },
      /**
       * UPC导入
       */
      importUpcModel(){
        if (!this.currentRow || !this.currentRow.cmcInvoice) {
          this.$message.warning('请先选择一个发货通知单')
          return
        }
        this.$nextTick(() => {
          this.$refs.upcUploadExcel.init(this.currentRow)
        })
      },
      // TTL Amount修正方法
      fixTtlAmountHandle(){
        if (!this.currentRow || !this.currentRow.delNo) {
          this.$message.warning('请先选择一个发货通知单')
          return
        }
        this.$confirm('确认要将所有明细的价税合计(sumPrice)赋值到TTL Amount字段吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          fixTtlAmount(this.currentRow).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: 'TTL Amount修正成功',
                type: 'success',
                duration: 1500
              })
              // 刷新明细列表
              this.refreshCurrentTabTable()
            } else {
              this.$alert(data.msg || 'TTL Amount修正失败', '错误', {
                confirmButtonText: '确定'
              })
            }
          }).catch((error) => {
            this.$alert('TTL Amount修正失败: ' + error, '错误', {
              confirmButtonText: '确定'
            })
          })
        }).catch(() => {
          // 用户取消操作
        })
      },
      refreshCurrentTabTable(){
        if(this.currentRow===''||this.currentRow===null){
          this.currentRow={site:'',delNo:''}
        }
        if(this.activeName==='detail'){
          searchEcssCoDelNotifyDetail(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.dataList2 = data.rows

            } else {
              this.dataList2 = [];
            }
          });
        }
        if(this.activeName==='pallet'){
          // 刷新装箱明细组件
          if (this.$refs.packingDetailTab) {
            this.$refs.packingDetailTab.refresh();
          }
        }
        if(this.activeName==='upcDetail'){
          // 查询UPC数据
          this.getUpcDataList()
        }
      },
      /**
       * 获取UPC数据列表
       */
      getUpcDataList(){
        if(!this.currentRow || !this.currentRow.cmcInvoice){
          this.dataList3 = []
          return
        }

        const params = {
          site: this.currentRow.site,
          cmcInvoice: this.currentRow.cmcInvoice
        }

        searchUpcImportData(params).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList3 = data.rows || []
          } else {
            this.dataList3 = []
          }
        }).catch((error) => {
          console.error('查询UPC数据失败:', error)
          this.dataList3 = []
        })
      },
      /**
       * 删除发货通知单的全部UPC数据
       */
      deleteAllUpcData(){
        if (!this.currentRow || !this.currentRow.cmcInvoice) {
          this.$message.warning('请先选择一个发货通知单')
          return
        }

        // 确认删除
        this.$confirm(`确定要删除发票号 ${this.currentRow.cmcInvoice} 的全部UPC数据吗？`, '删除确认', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const params = {
            site: this.currentRow.site,
            cmcInvoice: this.currentRow.cmcInvoice
          }

          deleteUpcImportData(params).then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success('UPC数据删除成功')
              // 清空当前数据列表
              this.dataList3 = []
              // 切换回明细tab
              this.activeName = 'detail'
            } else {
              this.$alert(data.msg || 'UPC数据删除失败', '错误', {
                confirmButtonText: '确定'
              })
            }
          }).catch((error) => {
            console.error('删除UPC数据失败:', error)
            this.$alert('删除UPC数据失败: ' + error, '错误', {
              confirmButtonText: '确定'
            })
          })
        }).catch(() => {
          // 用户取消删除
        })
      },
      /**
       * 合并表格单元格方法
       * 用于合并相同cartonNo的行
       */
      arraySpanMethod({ row, column, rowIndex, columnIndex }) {
        // 只对第一列（箱号列）进行合并
        if (columnIndex === 0) {
          // 如果数据为空，不合并
          if (!this.dataList3 || this.dataList3.length === 0) {
            return {
              rowspan: 1,
              colspan: 1
            }
          }

          // 获取当前行的箱号
          const currentCartonNo = row.cartonNo

          // 如果是第一行，或者与上一行的箱号不同
          if (rowIndex === 0 || this.dataList3[rowIndex - 1].cartonNo !== currentCartonNo) {
            // 计算相同箱号的行数
            let rowspan = 1
            for (let i = rowIndex + 1; i < this.dataList3.length; i++) {
              if (this.dataList3[i].cartonNo === currentCartonNo) {
                rowspan++
              } else {
                break
              }
            }

            return {
              rowspan: rowspan,
              colspan: 1
            }
          } else {
            // 如果与上一行的箱号相同，则隐藏该单元格
            return {
              rowspan: 0,
              colspan: 0
            }
          }
        }

        // 其他列不合并
        return {
          rowspan: 1,
          colspan: 1
        }
      },
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },
      updateHeaderModelDo(row){
        this.updateHeaderModel=JSON.parse(JSON.stringify(row));
        this.updateHeaderModelFlag=true
      },
      doUpdateHeader(){
        if(this.updateHeaderModel.readyDate==null||this.updateHeaderModel.readyDate==''){
          this.$alert('请选择ReadyDate！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        updateEcssDelHeader(this.updateHeaderModel).then(({data}) => {
          if (data && data.code === 0) {
            // 保存当前选中行的标识，以便刷新后恢复
            const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null;
            if (currentSelectedKey) {
              this.selectedRowKey = currentSelectedKey;
              this.saveSelectedRowToStorage();
            }
            this.searchTable()
            this.updateHeaderModelFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      deleteDelHeader(row){
        this.$confirm('确认删除吗？', '提示').then(() => {
          deleteEcssDelHeader(row).then(({data}) => {
            if (data && data.code === 0) {
              // 如果删除的是当前选中行，清除选中状态
              if (this.currentRow && this.currentRow.delNo === row.delNo) {
                this.clearSelectedRowStorage();
              }
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      xiadaChoose(row){
        // 设置当前行
        this.currentRow = row;

        if (this.dataList2.length===0) {
          this.$alert('该发货通知单下没有明细无法下达！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.walMartOrderFlag='N';
        this.fscFlag='N';
        this.boxSizeFlag = 'N';
        this.walMartOrderDialog=true;
      },
      cancelDelHeader(row){
        this.$confirm('确认废弃吗？', '提示').then(() => {
          cancelEcssDelHeader(row).then(({data}) => {
            if (data && data.code === 0) {
              // 保存当前选中行的标识，以便刷新后恢复
              const currentSelectedKey = row ? row.delNo : null;
              if (currentSelectedKey) {
                this.selectedRowKey = currentSelectedKey;
                this.saveSelectedRowToStorage();
              }
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      recoverDelHeader(row){
        this.$confirm('确认取消废弃吗？', '提示').then(() => {
          recoverEcssDelHeader(row).then(({data}) => {
            if (data && data.code === 0) {
              // 保存当前选中行的标识，以便刷新后恢复
              const currentSelectedKey = row ? row.delNo : null;
              if (currentSelectedKey) {
                this.selectedRowKey = currentSelectedKey;
                this.saveSelectedRowToStorage();
              }
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      tableRowClassName({row}) {
        if (row.notifyStatus==='订单取消') {
          return 'warning-row';
        }
      },
      cellStyle({row, column }) {
        // 改单列显示橙色：只要modifyFlag为true就显示橙色
        if (column.property === 'modifyLabel' && row.modifyFlag===true) {
          return { color: '#ff5d03' };
        }
        return {};
      },
      cellStyleDetail({row, column }) {
        if (column.property === 'qty' && row.modifyQtyFlag===true) {
          return { color: '#ff5d03' };
        }

        // PN列保持原有的 modifyFlag 判断
        if (column.property === 'pn' && row.modifyFlag===true) {
          return { color: '#ff5d03' };
        }
        // 检查 pn 列，当 boxrolls、rollqty、boxweight 其中任意一个没有值时，将 pn 颜色改成橙色
        if (column.property === 'pn') {
          const hsCodeDesc = row.hsCodeDesc !== null && row.hsCodeDesc !== undefined && row.hsCodeDesc !== ''&& row.hsCodeDesc !== '*';

          if (!hsCodeDesc) {
            return { color: '#ff8c00' }; // 橙色
          }
        }
        return {};
      },
      xiadaEcssDel(){
        let inData={
          site:this.currentRow.site,
          buNo:this.currentRow.buNo,
          createBy:this.currentRow.createBy,
          delNo:this.currentRow.delNo,
          cmcInvoice:this.currentRow.cmcInvoice,
          notifyStatus:'已下达',
          walMartOrderFlag:this.walMartOrderFlag,
          fscFlag:this.fscFlag,
          boxSizeFlag:this.boxSizeFlag
        }
        // 开始加载
        this.dataListLoading = true;

        changeEcssDelStatus(inData).then(({data}) => {
          if (data && data.code === 0) {
            // 保存当前选中行的标识，以便刷新后恢复
            const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null;
            if (currentSelectedKey) {
              this.selectedRowKey = currentSelectedKey;
              this.saveSelectedRowToStorage();
            }
            this.searchTable()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        }).catch((error) => {
          // 处理错误情况
          this.$alert('操作失败，请重试', '错误', {
            confirmButtonText: '确定'
          })
        }).finally(() => {
          // 无论成功还是失败都要恢复加载状态
          this.dataListLoading = false;
        })
        this.walMartOrderDialog=false;
      },
      jihuaEcssDel(row){
        let inData={
          site:row.site,
          delNo:row.delNo,
          notifyStatus:'已计划'
        }
        this.$confirm('确认取消下达吗？', '提示').then(() => {
          changeEcssDelStatus(inData).then(({data}) => {
            if (data && data.code === 0) {
              // 保存当前选中行的标识，以便刷新后恢复
              const currentSelectedKey = row ? row.delNo : null;
              if (currentSelectedKey) {
                this.selectedRowKey = currentSelectedKey;
                this.saveSelectedRowToStorage();
              }
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      declarationCompleted(row){
        let inData={
          site:row.site,
          delNo:row.delNo,
          walMartOrderFlag:row.walMartOrderFlag,
          notifyStatus:'已报关'
        }
        this.$confirm('确认一键结单吗？', '提示').then(() => {
          changeEcssDelStatus(inData).then(({data}) => {
            if (data && data.code === 0) {
              // 保存当前选中行的标识，以便刷新后恢复
              const currentSelectedKey = row ? row.delNo : null;
              if (currentSelectedKey) {
                this.selectedRowKey = currentSelectedKey;
                this.saveSelectedRowToStorage();
              }
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      // 每页数
      sizeChangeHandle3 (val) {
        this.pageSize3 = val
        this.pageIndex3 = 1
        this.queryComponentPartModal()
      },

      // 当前页
      currentChangeHandle3 (val) {
        this.pageIndex3 = val
        this.queryComponentPartModal()
      },
      // 子物料列表
      queryComponentPartModal () {
        this.componentPartData.limit = this.pageSize3
        this.componentPartData.page = this.pageIndex3
        this.componentPartData.site = this.currentRow.site
        this.componentPartData.buNo = this.currentRow.buNo
        // 查询所有物料
        queryPartListAll(this.componentPartData).then(({data}) => {
          if (data && data.code === 0) {
            this.componentPartList = data.page.list
            this.pageIndex3 = data.page.currPage
            this.pageSize3 = data.page.pageSize
            this.totalPage3 = data.page.totalCount
            this.componentPartModelFlag = true
          } else {
            this.componentPartList = []
          }
        })
      },
      // 物料查询列表
      queryComponentPartList () {
        this.componentPartData.limit = this.pageSize3
        this.componentPartData.page = this.pageIndex3
        // 查询所有物料
        queryPartListAll(this.componentPartData).then(({data}) => {
          if (data && data.code === 0) {
            this.componentPartList = data.page.list
            this.pageIndex3 = data.page.currPage
            this.pageSize3 = data.page.pageSize
            this.totalPage3 = data.page.totalCount
          } else {
            this.componentPartList = []
          }
        })
      },
      // 双击选中子物料
      getComponentRowData (row) {
        this.updateDetailModel.partDescription = row.partDesc
        this.updateDetailModel.pn = row.sku
        this.updateDetailModel.partNo = row.partNo
        this.componentPartModelFlag = false
      },

      doUpdateDetail(){
        if(this.updateDetailModel.partNo==null||this.updateDetailModel.partNo==''){
          this.$alert('请输入PN！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.updateDetailModel.qty==null||this.updateDetailModel.qty==''){
          this.$alert('请输入QTY！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.updateDetailModel.qty<=0){
          this.$alert('QTY必须大于0！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }

        // 开始加载
        this.updateDetailLoading = true

        updateEcssDelDetail(this.updateDetailModel).then(({data}) => {
          if (data && data.code === 0) {
            // 保存当前选中行的标识，以便刷新后恢复
            const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null
            if (currentSelectedKey) {
              this.selectedRowKey = currentSelectedKey
              this.saveSelectedRowToStorage()
            }

            // 刷新明细表格
            this.refreshCurrentTabTable()
            // 刷新表头列表
            this.searchTable()

            this.updateDetailModelFlag=false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        }).catch((error) => {
          // 处理错误情况
          this.$alert('操作失败，请重试', '错误', {
            confirmButtonText: '确定'
          })
        }).finally(() => {
          // 无论成功还是失败都要恢复加载状态
          this.updateDetailLoading = false
        })
      },

      // 自动计算金额
      calculateAmounts() {
        // 获取数值，如果无效则为0
        const qty = parseFloat(this.updateDetailModel.qty) || 0;
        const tp = parseFloat(this.updateDetailModel.tp) || 0;
        const vat = parseFloat(this.updateDetailModel.vat) || 0;

        // 价税合计 = 数量 * TP，保留两位小数
        const sumPrice = qty * tp;
        this.updateDetailModel.sumPrice = sumPrice > 0 ? sumPrice.toFixed(2) : '';

        // TTL Amount = 价税合计 * VAT，保留两位小数
        const ttlAmount = sumPrice * vat;
        this.updateDetailModel.ttlAmount = ttlAmount > 0 ? ttlAmount.toFixed(2) : '';
      },

      openCreateDetailModel(){
        this.updateDetailModel.site=this.currentRow.site;
        this.updateDetailModel.buNo=this.currentRow.buNo;
        this.updateDetailModel.delNo=this.currentRow.delNo;
        this.updateDetailModel.partNo=''
        this.updateDetailModel.qty=''
        this.updateDetailModel.partDescription=''
        this.updateDetailModel.itemNo=''
        this.updateDetailModel.salesOrder=''
        this.updateDetailModel.line=''
        this.updateDetailModel.customerPO=''
        this.updateDetailModel.version=''
        this.updateDetailModel.status=''
        this.updateDetailModel.family=''
        this.updateDetailModel.lt=''
        this.updateDetailModel.cmcComment=''
        this.updateDetailModel.saleType=''
        this.updateDetailModel.awbBl=''
        this.updateDetailModel.shippingNumber=''
        this.updateDetailModel.forwarderInfo=''
        this.updateDetailModel.currency=''
        this.updateDetailModel.tp=''
        this.updateDetailModel.ttlAmount=''
        this.updateDetailModel.sumPrice=''
        this.updateDetailModel.so=''
        this.updateDetailModel.upc=''
        this.updateDetailModel.remark=''
        this.updateDetailModel.pn=''
        this.updateDetailModel.roll=''
        this.updateDetailModel.carton=''
        this.updateDetailModel.vat=''
        this.updateDetailModel.addFlag=0
        this.updateDetailModelFlag=true
      },
      openUpdateDetailModel(row){
        this.updateDetailModel=JSON.parse(JSON.stringify(row));
        this.updateDetailModel.addFlag=1
        this.updateDetailModelFlag=true
      },
      deleteDelDetail(row){
        this.$confirm('确认取消此明细？', '提示').then(() => {
          // 开始加载
          this.updateDetailLoading = true

          deleteEcssDelDetail(row).then(({data}) => {
            if (data && data.code === 0) {
              // 保存当前选中行的标识，以便刷新后恢复
              const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null
              if (currentSelectedKey) {
                this.selectedRowKey = currentSelectedKey
                this.saveSelectedRowToStorage()
              }

              // 刷新明细表格
              this.refreshCurrentTabTable()
              // 刷新表头列表
              this.searchTable()

              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          }).catch((error) => {
            // 处理错误情况
            this.$alert('操作失败，请重试', '错误', {
              confirmButtonText: '确定'
            })
          }).finally(() => {
            // 无论成功还是失败都要恢复加载状态
            this.updateDetailLoading = false
          })
        }).catch(() => {
          // 用户取消确认时不需要loading状态
        })
      },
      getBu () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getBuList(tempData).then(({data}) => {
          if (data.code === 0) {
            this.buList = data.row2
            if (this.buList.length===1) {
              this.searchData.buNo = this.buList[0].buNo;
            }
          }
        })
      },
      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await searchEcssCoDelNotifyHeader(this.searchData).then(({data}) => {
          this.exportList= data.page.list;
        })

        return this.exportList;
      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      finishDownload() {
      },
      fields() {
        let json = "{"
        this.columnList1.forEach((item, index) => {
          if (index == this.columnList1.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")

        return s
      },
      async exportExcel() {
        this.searchData.limit = -1
        this.searchData.page = 1
        excel.exportTable({
          url: "/ecss/coDel/searchEcssCoDelNotifyHeader",
          columnMapping:  this.columnList1,//可以直接用table，不需要的列就剔除
          mergeSetting: [],//需要合并的列
          params: this.searchData,
          fileName: this.exportName+".xlsx",
          rowFetcher: res => res.data,
          columnFormatter: [],
          dropColumns: [],//需要剔除的列，例如dropColumns: ["netWeight"]，即剔除净重列
        });
      },
      getSummaries(param) {
        const { columns } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          let sumDataList = this.dataList2.filter(item => item.qty>0);
          const values = sumDataList.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            switch(column.property) {
              case 'qty':
                sums[index] = `${values.reduce((a, b) => a + b, 0)}`;
                break;
              case 'ttlAmount':
                sums[index] = `${values.reduce((a, b) => a + b, 0).toFixed(2)}`;
                break;
              case 'sumPrice':
                sums[index] = `${values.reduce((a, b) => a + b, 0).toFixed(2)}`;
                break;
              default:
                sums[index] = '';
            }
          } else {
            sums[index] = '';
          }
        });
        this.$nextTick(() => this.$refs.detailTable.doLayout());// 强制刷新布局,  否则会被表格覆盖
        return sums;
      },

      exportInvoiceList() {
        if (!this.currentRow || !this.currentRow.buNo) {
          this.$message.warning('请选择发货通知单！')
          return
        }
        if (this.currentRow.notifyStatus==='订单取消') {
          this.$message.warning('该发货通知单已取消！')
          return
        }
        this.exportInvoice.templateName=''
        this.exportInvoice.hsCodeDesc=this.currentRow.hsCodeDesc
        this.exportInvoice.contractFlag=this.currentRow.contractFlag
        this.exportInvoice.packaging=this.currentRow.packaging
        this.exportInvoice.kgs=this.currentRow.kgs
        this.exportInvoice.hsCode=this.currentRow.hsCode
        this.exportInvoice.material=this.currentRow.material
        this.exportInvoice.hsCodeDescType=this.currentRow.hsCodeDescType
        this.exportInvoice.goodsLabel=this.currentRow.goodsLabel
        this.exportInvoice.origin="made in china"
        //this.exportInvoice = this.currentRow
        if (!this.exportInvoice.origin) {
          this.exportInvoice.origin = 'made in china'
        }
        if (!this.exportInvoice.itemNo) {
          this.exportInvoice.itemNo = 'Y'
        }
        this.notifyPartDetailList = [];
        this.customerData=''
        this.customerAddData = ''
        this.exportInvoiceFlag = true
        if (this.currentRow.buNo==='03-RFID') {
          getNotifyPartDetail(this.currentRow).then(({data}) => {
            //区分请求成功和失败的状况
            if (data && data.code == 0) {
              this.notifyPartDetailList = data.rows
              this.notifyPartDetailList.forEach(o => {
                if (!o.lossratio) {
                  o.lossratio = '1.2';
                }
              });
            } else {
              this.notifyPartDetailList = [];
            }
          });
        }
        this.templateData.type='发票'
        this.searchTemplateOne();
      },

      searchTemplateOne() {
        this.templateData.buNo = this.currentRow.buNo
        this.templateData.customName = this.currentRow.customerName
        this.templateData.shippingMode = this.currentRow.shippingMode
        searchTemplateList(this.templateData).then(({data}) => {
          if (data && data.code === 0){
            if (data.rows && data.rows.length > 0) {
              this.templateRowDblclick(data.rows[0]);
            }
          }
        })
      },

      exportGoodsList() {
        if (!this.currentRow || !this.currentRow.buNo) {
          this.$message.warning('请选择发货通知单！')
          return
        }
        this.exportGoods.hsCodeDescType = 'N'
        this.exportGoods.salesMethod = 'EXW'
        this.exportGoods.currency = this.currentRow.currency?this.currentRow.currency:this.dataList2.length>0?this.dataList2[0].currency:'USD'
        this.exportGoods.madeArea = 'Nantong, China'
        this.exportGoods.sendPort = 'Shanghai, China'
        this.exportGoods.deliveryGoodsDate = ''
        this.exportGoods.voyage = this.currentRow.buNo==='01-Label' || this.currentRow.buNo==='03-RFID'?this.currentRow.cmcInvoice:''
        this.exportGoods.shippingDate = ''
        this.exportGoodsFlag = true
      },

      /**
       * 打开客户信息编辑对话框
       */
      openCustomerInfoDialog() {
        if (!this.currentRow || !this.currentRow.cmcInvoice) {
          this.$message.warning('请选择发货通知单！')
          return
        }
        if (this.currentRow.notifyStatus === '订单取消') {
          this.$message.warning('该发货通知单已取消！')
          return
        }

        // 初始化客户信息数据
        this.customerInfoModel = {
          customerName: this.currentRow.customerName || '',
          localShipAddress: this.currentRow.localShipAddress || '',
          overseasShipper: this.currentRow.overseasShipper || '',
          overseasAddress: this.currentRow.overseasAddress || '',
          salesArea: this.currentRow.salesArea || '',
          cnative: this.currentRow.cnative || '',
          templateNo: this.currentRow.templateNo || '',
          templateName: ''
        }

        this.customerInfoDialogFlag = true
      },

      /**
       * 更新客户信息
       */
      updateCustomerInfo(templateNo) {
        // 验证必填字段
        if (!this.customerInfoModel.customerName) {
          this.$message.warning('请填写客户名称')
          return
        }

        // 准备更新数据
        const updateData = {
          site: this.currentRow.site,
          delNo: this.currentRow.delNo,
          templateNo : templateNo,
          customerName: this.customerInfoModel.customerName,
          localShipAddress: this.customerInfoModel.localShipAddress,
          overseasShipper: this.customerInfoModel.overseasShipper,
          overseasAddress: this.customerInfoModel.overseasAddress,
          salesArea: this.customerInfoModel.salesArea,
          cnative: this.customerInfoModel.cnative
        }

        // 调用专门的客户信息更新接口
        updateCustomerInfo(updateData).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success('客户信息更新成功')
            this.customerInfoDialogFlag = false
            // 刷新列表
            this.searchTable()
          } else {
            this.$message.error(data.msg || '更新失败')
          }
        }).catch(error => {
          this.$message.error('更新失败：' + (error.message || '网络异常'))
        })
      },

      /**
       * 另存为模板
       */
      async saveAsTemplate() {
        // 验证必填字段
        if (!this.customerInfoModel.templateName) {
          this.$message.warning('请输入模板名称')
          return
        }

        if (!this.customerInfoModel.customerName) {
          this.$message.warning('请填写客户名称')
          return
        }

        // 准备模板数据
        const templateData = {
          templateName: this.customerInfoModel.templateName,
          originalTemplateName: '', // 空字符串表示新增模板
          ccuscode: '', // 客户编码，可以为空
          ccusname: this.customerInfoModel.customerName,
          localShipAddress: this.customerInfoModel.localShipAddress || '',
          overseasShipper: this.customerInfoModel.overseasShipper || '',
          overseasAddress: this.customerInfoModel.overseasAddress || '',
          cnative: this.customerInfoModel.cnative || '',
          salesArea: this.customerInfoModel.salesArea || ''
        }

        try {
          const {data} = await updateCustomerTemplate(templateData)

          if (data && data.code === 0) {
            this.$message.success(`模板"${this.customerInfoModel.templateName}"保存成功！`)
            // 清空模板名称
            this.customerInfoModel.templateName = ''
          } else {
            this.$message.error(data.msg || '保存模板失败')
          }
        } catch (error) {
          console.error('保存模板失败:', error)
          this.$message.error('保存模板失败：' + (error.message || '网络异常'))
        }
      },
      // 导出
      downloadInvoice() {
        if (!this.currentRow || !this.currentRow.buNo) {
          this.$message.warning('请选择报关单！')
          return
        }
        let exportParam=this.exportInvoice
        exportParam.declarationNo = this.currentRow.declarationNo
        exportParam.site = this.currentRow.site
        exportParam.delNo = this.currentRow.delNo
        exportParam.notifyPartDetailList = this.notifyPartDetailList
        ExportUtil.export(
          "/ecss/coDel/downloadInvoice",
          exportParam, "CI "+this.currentRow.cmcInvoice+" "+this.currentRow.destination+"-"+this.currentRow.shippingMode+".xlsx"
        );
        this.exportInvoiceFlag=false
        this.searchTable()
      },

      downloadExportGoods() {
        if (!this.currentRow || !this.currentRow.buNo) {
          this.$message.warning('请选择报关单！')
          return
        }
        let exportParam=this.exportGoods
        exportParam.declarationNo = this.currentRow.declarationNo
        exportParam.site = this.currentRow.site
        exportParam.delNo = this.currentRow.delNo
        ExportUtil.export(
          "/ecss/coDel/downloadExportGoods",
          exportParam, "Booking "+this.currentRow.cmcInvoice+" "+this.currentRow.destination+"-"+this.currentRow.shippingMode+".xlsx"
        );
        this.exportGoodsFlag = false;
        this.searchTable()
      },

      openTemplate (type) {
        this.templateData.type=type;
        this.templateFlag = true;
      },

      openTemplateDialog () {
        //请求
        this.searchTemplateList();
      },
      closeTemplateDialog () {
        this.templateList = []
        this.templateFlag = false
      },
      searchTemplateList () {
        this.templateData.buNo = this.currentRow.buNo
        this.templateData.customName = ''
        searchTemplateList(this.templateData).then(({data}) => {
          if (data && data.code === 0){
            this.templateList = data.rows;
          }
        })
      },
      templateRowDblclick (row) {
        if (this.templateData.type=='发票') {
          this.exportInvoice.templateName=row.name
          this.exportInvoice.hsCodeDesc=row.hsCodeDesc
          this.exportInvoice.contractFlag=row.contractFlag
          this.exportInvoice.origin=this.currentRow.origin?this.currentRow.origin:row.origin
          this.exportInvoice.packaging=this.currentRow.packaging?this.currentRow.packaging:row.packaging
          this.exportInvoice.kgs=this.currentRow.kgs?this.currentRow.kgs:row.kgs
          this.exportInvoice.hsCode=this.currentRow.hsCode?this.currentRow.hsCode:row.hsCode
          this.exportInvoice.material=this.currentRow.material?this.currentRow.material:row.material
          this.exportInvoice.hsCodeDescType=this.currentRow.hsCodeDescType?this.currentRow.hsCodeDescType:row.hsCodeDescType
          this.exportInvoice.goodsLabel=this.currentRow.goodsLabel?this.currentRow.goodsLabel:row.goodsLabel
          this.exportInvoice.fpremark=row.remark
          this.exportInvoice.showWeight = row.showWeight
        } else if (this.templateData.type=='出口货物委托书'){
          this.exportGoods.salesMethod = row.salesMethod
          this.exportGoods.currency = row.currency
          this.exportGoods.madeArea = row.madeArea
          this.exportGoods.sendPort = row.sendPort
          this.exportGoods.deliveryGoodsDate = row.deliveryGoodsDate
          this.exportGoods.voyage = this.currentRow.buNo==='01-Label' || this.currentRow.buNo==='03-RFID'?this.currentRow.cmcInvoice:row.voyage
          this.exportGoods.shippingDate = row.shippingDate;
          this.exportGoods.shipper=row.shipper
          this.exportGoods.remark=row.remark
        }
        if (this.templateData.type!=='出口货物委托书') {
          this.notifyPartDetailList.forEach(o => {
            // 开启fsc损耗则给默认值
            if (o.lossratio) {
              if (row.fscWeight) {
                o.lossratio = o.lossratio;
              } else {
                o.lossratio = '';
              }
            } else {
              if (row.fscWeight) {
                o.lossratio = '1.2';
              } else {
                o.lossratio = '';
              }
            }
          });
        }
        this.templateFlag = false
      },

      /**
       * 保存选中行到本地存储
       * 使用页面路径和用户名作为存储键的一部分，确保不同页面和用户的选择互不影响
       */
      saveSelectedRowToStorage() {
        try {
          const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`;
          localStorage.setItem(storageKey, this.selectedRowKey);
          console.log(`[行选择持久化] 已保存选中行: ${this.selectedRowKey}`);
        } catch (error) {
          console.warn('保存选中行状态失败:', error);
        }
      },

      /**
       * 从本地存储恢复选中行
       * @returns {Object|null} 返回匹配的行数据，如果没有找到则返回null
       */
      restoreSelectedRow() {
        try {
          const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`;
          const savedRowKey = localStorage.getItem(storageKey);

          // 检查必要的条件
          if (!savedRowKey) {
            console.log('[行选择持久化] 没有保存的选中行');
            return null;
          }

          if (!this.dataList || this.dataList.length === 0) {
            console.log('[行选择持久化] 数据列表为空，无法恢复选中行');
            return null;
          }

          // 在当前数据列表中查找匹配的行
          const matchedRow = this.dataList.find(row => row && row.delNo === savedRowKey);
          if (matchedRow) {
            this.selectedRowKey = savedRowKey;
            console.log(`[行选择持久化] 已恢复选中行: ${savedRowKey}`);
            return matchedRow;
          } else {
            console.log(`[行选择持久化] 未找到匹配的行: ${savedRowKey}，当前数据列表长度: ${this.dataList.length}`);
          }

          return null;
        } catch (error) {
          console.warn('恢复选中行状态失败:', error);
          return null;
        }
      },

      /**
       * 清除本地存储的选中行状态
       */
      clearSelectedRowStorage() {
        try {
          const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`;
          localStorage.removeItem(storageKey);
          this.selectedRowKey = null;
        } catch (error) {
          console.warn('清除选中行状态失败:', error);
        }
      },
    },
    activated() {
      this.searchTable()
    },
    created() {
        this.getBu ()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)

      // 初始化时从本地存储加载选中行状态
      try {
        const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`;
        const savedRowKey = localStorage.getItem(storageKey);
        if (savedRowKey) {
          this.selectedRowKey = savedRowKey;
        }
      } catch (error) {
        console.warn('初始化选中行状态失败:', error);
      }
    }
  }
</script>

<style lang="scss" >
.warning-row td{
  color: darkred !important;
}
/deep/ .zxClass .cell {
  line-height: 24px;
  font-size: 12px;
  height: 24px;
}
/* 可点击的PN样式 */
.clickable-pn {
  cursor: pointer;
  text-decoration: underline;
}

.clickable-pn:hover {
  opacity: 0.8;
}
.fake-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

</style>
