<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'BU:'">
        <el-select v-model="searchData.buNo" placeholder="请选择"  >
          <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="'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.walMartOrderFlag" 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>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ '导出' }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      @row-click="changeData"
      highlight-current-row
      :height="height"
      :data="dataList"
      ref="mainTable"
      border :cell-style="cellStyle"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="100"
        fixed="left"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" v-if="scope.row.notifyStatus==='仓库已确认'" @click="declarationModel(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-table
          :height="height"
          :data="dataList2"
          border
          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>
              <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>
      </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-tabs>
    <el-dialog title="创建报关单" :close-on-click-modal="false" v-drag :visible.sync="declarationFlag" width="1100px">
      <el-form  label-position="top"  style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item :label="'CMC Invoice'" >
              <el-input v-model="declarationData.cmcInvoice" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'海关编号'" >
              <el-input v-model="declarationData.customsOfficeCode"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'录入编号'" >
              <el-input v-model="declarationData.inputCode"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'境内发货人'" >
              <el-input v-model="declarationData.localShipper"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'出关类别'" >
              <el-input v-model="declarationData.shipType"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'出口日期'" >
              <el-date-picker
                style="width: 100%"
                v-model="declarationData.shipDate"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'申报日期'" >
              <el-date-picker
                style="width: 100%"
                v-model="declarationData.submitDate"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'境外收货人'" >
              <el-input v-model="declarationData.overseasShipper"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'境外收货地址'" >
              <el-input v-model="declarationData.overseasAddress"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'备案号'" >
              <el-input v-model="declarationData.filingNo"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'运输方式'" >
              <el-input v-model="declarationData.shippingMode" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'运输工具名称及航次号'" >
              <el-input v-model="declarationData.shippingData"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'提运单号'" >
              <el-input v-model="declarationData.deliverNo"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'生产销售单位'" >
              <el-input v-model="declarationData.salesPartner"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'监管方式'" >
              <el-input v-model="declarationData.regulatoryMethod"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'征免性质'" >
              <el-input v-model="declarationData.dutyStatus"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'许可证号'" >
              <el-input v-model="declarationData.permitNumber"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'贸易国（地区）'" >
              <el-input v-model="declarationData.salesArea"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'运抵国（地区）'" >
              <el-input v-model="declarationData.receiveArea"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'指运港'" >
              <el-input v-model="declarationData.shippingPort"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'离境口岸'" >
              <el-input v-model="declarationData.exitPort"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'随附单证及编号'" >
              <el-input v-model="declarationData.documents"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'标记唛码及备注'" >
              <el-input v-model="declarationData.remark"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'包装种类'" >
              <el-input v-model="declarationData.packageType" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'件数'" >
              <el-input v-model="declarationData.packageQty"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'箱数'" >
              <el-input v-model="declarationData.boxQty"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'毛重（KG）'" >
              <el-input v-model="declarationData.grossWeight"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'净重（KG）'" >
              <el-input v-model="declarationData.netWeight"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'成交方式'" >
              <el-input v-model="declarationData.paymentType" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'运费'" >
              <el-input v-model="declarationData.shipPrice"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'保费'" >
              <el-input v-model="declarationData.premium"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'杂费'" >
              <el-input v-model="declarationData.otherPrice"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'托盘重量（KG）'" >
              <el-input v-model="declarationData.palletWeight"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'总毛重（KG）'" >
              <el-input v-model="declarationData.allWeight"  ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'特殊关系确认'" >
              <el-select v-model="declarationData.specialRelationshipComfirm"  style="width: 100%">
                <el-option value="Y" label="是"></el-option>
                <el-option value="N" label="否"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'价格影响确认'" >
              <el-select v-model="declarationData.priceInfluenceConfirm"  style="width: 100%">
                <el-option value="Y" label="是"></el-option>
                <el-option value="N" label="否"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'支付特许使用费确认'" >
              <el-select v-model="declarationData.royaltyPaymentsConfirm"  style="width: 100%">
                <el-option value="Y" label="是"></el-option>
                <el-option value="N" label="否"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="rq ">
      <el-table
        height="250"
        :data="detailList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          prop="hsCodeDesc"
          header-align="center"
          align="left"
          label="品名"
          min-width="120">
        </el-table-column>
        <el-table-column
          prop="hsCode"
          header-align="center"
          align="left"
          label="HS Code"
          min-width="80">
        </el-table-column>
        <el-table-column
          prop="qty"
          header-align="center"
          align="right"
          label="数量"
          min-width="60">
        </el-table-column>
        <el-table-column
          prop="unit"
          header-align="center"
          align="left"
          label="单位"
          min-width="60">
        </el-table-column>
        <el-table-column
          prop="netWeight"
          header-align="center"
          align="right"
          label="净重"
          min-width="60">
        </el-table-column>
        <el-table-column
          prop="unitPrice"
          header-align="center"
          align="right"
          label="单价"
          min-width="60">
<!--          <template slot-scope="scope">
            <el-input  v-model="scope.row.unitPrice" @change="changeToalPrice(scope.row)" type="number" style="height: 11px;width:98%"></el-input>
          </template>-->
        </el-table-column>
        <el-table-column
          prop="totalPrice"
          header-align="center"
          align="right"
          label="总价"
          min-width="60">
          <template slot-scope="scope">
            <span >{{scope.row.totalPrice.toFixed(2)}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="currency"
          header-align="center"
          align="left"
          label="币制"
          min-width="60">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.currency"  style="height: 11px;width:98%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="madeArea"
          header-align="center"
          align="left"
          label="原产国（地区）"
          min-width="80">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.madeArea"  style="height: 11px;width:98%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="destination"
          header-align="center"
          align="left"
          label="最终目的国（地区）"
          min-width="100">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.destination"  style="height: 11px;width:98%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="sourceArea"
          header-align="center"
          align="left"
          label="境内货源地"
          min-width="100">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.sourceArea"  style="height: 11px;width:98%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="levy"
          header-align="center"
          align="left"
          label="征免"
          min-width="60">
          <template slot-scope="scope">
            <el-input  v-model="scope.row.levy"  style="height: 11px;width:98%"></el-input>
          </template>
        </el-table-column>
      </el-table>
      </div>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" :loading="saveLoading" :disabled="saveLoading" @click="saveDeclaration()">保存</el-button>
        <el-button type="primary" @click="declarationFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>



  </div>
</template>

<script>

  import {} from "@/api/sysLanguage.js"
  import PackingDetailTab from "./components/PackingDetailTab.vue";
  import {
    searchEcssCoDelNotifyHeaderForDanZheng,
    searchEcssCoDelNotifyDetail,
    searchCoDelPalletDataNew,
    getDeclarationDefaultData,
    saveDeclaration,
  }from "@/api/ecss/ecss.js"
  import {getBuList}from  '@/api/factory/site.js'
  export default {
    name: "null",
    components:{
      PackingDetailTab,
    },
    data() {
      return {
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        buList:[],
        dataList:[],
        dataList2:[],
        detailList:[],
        dataListLoading: false,
        saveLoading: false,
        searchData: {
          page: 1,
          limit: 100,
          buNo:'',
          delNo:'',
          cmcInvoice:'',
          notifyStatus:'',
          startDate:'',
          endDate:'',
          username:this.$store.state.user.name,
        },
        buttons:{
          search:'查询',
        },
        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: '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: "erpDelNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "ERP发货单号",
            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: 120
          },
          {
            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
          },
        ],

        currentRow:{},
        // 导出 start
        exportData: [],
        exportName: '发货通知单'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["发货通知单"],
        exportFooter: [],
        // 导出 end
        declarationFlag:false,
        customerData:{},
        customerMap:new Map,
        customerAddData:{},
        declarationData:{
          site:'',
          customsOfficeCode:'',
          inputCode:'',
          localShipper:'',
          localShipAddress:'',
          shipType:'',
          shipDate:'',
          submitDate:'',
          filingNo:'',
          overseasShipper:'',
          overseasAddress :'',
          shippingMode:'',
          shippingData:'',
          deliverNo:'',
          salesPartner:'',
          regulatoryMethod:'',
          dutyStatus:'',
          permitNumber:'',
          cmcInvoice:'',
          salesArea:'',
          receiveArea:'',
          shippingPort:'',
          exitPort:'',
          documents:'',
          remark:'',
          packageType:'',
          packageQty:'',
          grossWeight:'',
          netWeight:'',
          paymentType:'',
          shipPrice:'',
          premium:'',
          otherPrice:'',
          specialRelationshipComfirm:'',
          priceInfluenceConfirm:'',
          royaltyPaymentsConfirm:'',
          delNo:'',
          palletWeight:'',
          allWeight:'',
        },
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = (window.innerHeight - 240)/2;
      })
    },
    methods: {
      // 每页数
      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
        searchEcssCoDelNotifyHeaderForDanZheng(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.$refs.mainTable.setCurrentRow(this.dataList[0]);
              this.changeData(this.dataList[0])
              this.dataList.forEach(o => {
                if (o.notifyStatus==='仓库已确认'&&!o.notifyDate) {
                  o.notifyDate='发货日期不确定'
                }
              });
            }else {
              this.changeData(null)
            }
          } else {
            this.dataList = [];
          }
        });
      },
      cellStyle({row, column }) {
        if (column.property === 'notifyDate' && row.notifyDate==='发货日期不确定') {  // 根据列属性判断
          return { color: '#ff5d03' };
        }
        return {};
      },
      changeData(row){
        this.currentRow = JSON.parse(JSON.stringify(row));
        if (this.currentRow.notifyDate==='发货日期不确定') {
          this.currentRow.notifyDate=''
        }
        this.headerData=row;
        this.refreshCurrentTabTable ();
      },
      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();
          }
        }
      },
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },
      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;
            }
          }
        })
      },
      changeToalPrice(row){
        row.totalPrice=row.unitPrice*row.qty
      },
      declarationModel(row){
        let indata=JSON.parse(JSON.stringify(row));
        if (row.notifyDate==='发货日期不确定') {
          indata.notifyDate=''
        }
        getDeclarationDefaultData(indata).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code === 0) {
           this.declarationData=data.row
            this.detailList=data.rows
         /*    this.customerData=data.customers
            this.customerAddData = data.customerAdd
            if (data.customerAdd && data.customerAdd.length > 0 && data.customers && data.customers.length > 0) {
              this.declarationData.overseasAddress = this.declarationData.overseasAddress?this.declarationData.overseasAddress:data.customerAdd[0].cDeliverAdd
              this.declarationData.overseasShipper = this.declarationData.overseasShipper?this.declarationData.overseasShipper:data.customers[0].ccontactname
            } */
            this.declarationFlag=true

            /* this.customerData.forEach(o => {
              if (!this.customerMap.has(o.ccontactname)) {
                this.customerMap.set(o.ccontactname, o.cnative);
              }
            }); */
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        });
      },
      /* setDestination(){
        this.detailList.forEach(o => o.destination=this.customerMap.get(this.declarationData.overseasShipper))
        this.declarationData.receiveArea=this.customerMap.get(this.declarationData.overseasShipper)
        this.declarationData.salesArea=this.customerMap.get(this.declarationData.overseasShipper)
      }, */
      saveDeclaration(){
        // 防止重复点击
        if(this.saveLoading) {
          return false
        }

        if(this.detailList==null|| this.detailList.length<1){
          this.$alert('不存在明细记录！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        for (let i = 0; i <this.detailList.length ; i++) {
          if(this.detailList[i].unitPrice==null||this.detailList[i].unitPrice==""||this.detailList[i].unitPrice<=0){
            this.$alert('请输入正确的单价！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
        }

        // 开始loading
        this.saveLoading = true
        this.declarationData.detailList=this.detailList

        saveDeclaration(this.declarationData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code === 0) {
            this.declarationFlag=false
            this.searchTable()
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        }).catch(error => {
          // 处理请求异常
          this.$alert('保存失败，请重试！', '错误', {
            confirmButtonText: '确定'
          })
          console.error('保存报关单失败:', error)
        }).finally(() => {
          // 无论成功失败都要关闭loading
          this.saveLoading = false
        });
      },
      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await searchEcssCoDelNotifyHeaderForDanZheng(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
      },

    },
    activated() {
      this.searchTable()
    },
    created() {
        this.getBu ()
    }
  }
</script>

<style scoped>

</style>
