<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="帐单时间">
          <div class="block">
            <el-date-picker
              v-model="customerBillTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              value-format="yyyy-MM-dd"
              end-placeholder="结束日期"
            />
          </div>
        </el-form-item>
        <el-form-item label="客户">
          <el-input v-model="pagerDto._Co_CustomerName" clearable />
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select
            v-model="pagerDto._Eq_CollectionBillStatus"
            placeholder="订单状态"
            filterable
          >
            <el-option
              v-for="item in ReceiptLadingBillOrderStatusEnums"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="渠道">
          <el-select
            v-model="pagerDto._Eq_ChannelId"
            placeholder="渠道"
            clearable
            filterable
          >
            <el-option
              v-for="item in channels"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="提单号">
          <el-input v-model="pagerDto._Eq_BillNumber" class="input-with-select" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="pagerDto._Eq_BillType" type="hidden" />
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            size="small"
            plain
            @click="getData()"
          >搜索</el-button>
        </el-form-item>

        <el-button
          v-if="IsFinance()"
          icon="el-icon-download"
          size="small"
          plain
          type="success"
          :loading="downloadLoading"
          @click="exportLadingBills"
        >导出提单均摊数据</el-button>

        <el-button
          v-if="IsFinance()"
          icon="el-icon-download"
          size="small"
          plain
          type="success"
          @click="dialogFeeAsFile=true"
        >导入/导出均摊</el-button>

        <el-button
          v-if="IsFinance()"
          icon="el-icon-download"
          size="small"
          plain
          type="success"
          :loading="downloadLoading"
          @click="exportLadingBillsByCustomer"
        >导出客户监控表</el-button>
        <el-button
          v-if="status == '1'&&(!isCustomerBill)"
          icon="el-icon-plus"
          size="small"
          plain
          type="primary"
          @click="dialogStartVisible = true"
        >开始对帐</el-button>
        <el-button
          v-else-if="status == '1'&&(isCustomerBill)"
          icon="el-icon-plus"
          size="small"
          plain
          type="primary"
          @click="dialogStartByCustomerVisible = true"
        >开始对帐</el-button>
        <el-button type="danger" size="small" icon="el-icon-upload2" @click="dialogInputBill=true">
          上传帐单
        </el-button>
      </el-form>
      <el-tabs type="card" @tab-click="tab_cliek">
        <el-tab-pane :key="1" label="头程帐单" />
        <el-tab-pane v-if="!isCustomerBill" :key="7" label="一级中转账单" />
        <el-tab-pane v-if="!isCustomerBill" :key="8" label="二级中转账单" />
        <el-tab-pane :key="2" label="国内清关帐单" />
        <el-tab-pane :key="3" label="国外清关帐单" />
        <el-tab-pane v-if="!isCustomerBill" :key="9" label="关税账单" />
        <el-tab-pane v-if="!isCustomerBill" :key="10" label="海外中转账单" />
        <el-tab-pane :key="11" label="补贴账单" />
        <el-tab-pane v-if="isCustomerBill" :key="4" label="收款帐单" />
        <el-tab-pane v-if="!isCustomerBill && IsFinance()" :key="5" label="盈亏分析" />
      </el-tabs>
      <el-table
        :data="s1Data"
        border
        height="700"
        @selection-change="handleSelectionChange"
      >
        <el-table-column width="50" type="selection" />
        <el-table-column label="提单号" prop="BillNumber" width="150" />

        <el-table-column
          v-if="status == 1 || status == 5"
          label="帐单时间"
          prop="FristBillTime"
          width="190"
        />

        <el-table-column
          v-if="status == 2"
          label="帐单时间"
          prop="DomesticClearBillTime"
          width="210"
        />

        <el-table-column
          v-if="status == 3"
          label="帐单时间"
          prop="OverseasClearBillTime"
          width="210"
        />

        <el-table-column
          v-if="status == 4"
          label="帐单时间"
          prop="CustomerBillTime"
          width="210"
        />
        <el-table-column
          v-if="status == 7"
          label="帐单时间"
          prop="FirstTransferBillTime"
          width="210"
        />
        <el-table-column
          v-if="status == 8"
          label="帐单时间"
          prop="SecondTransferBillTime"
          width="210"
        />
        <el-table-column
          v-if="status == 9"
          label="帐单时间"
          prop="TaxBillTime"
          width="210"
        />

        <el-table-column
          v-if="status == 10"
          label="帐单时间"
          prop="OverSeaTransferBillTime"
          width="210"
        />

        <el-table-column
          v-if="status == 11"
          label="帐单时间"
          prop="SubsidyBillTime"
          width="210"
        />

        <el-table-column width="250" label="服务商/客户">
          <template slot-scope="scope">
            {{
              status == "1"
                ? scope.row.FristServiceName
                : status == "2"
                  ? scope.row.DomesticClearServiceName
                  : status == "4"
                    ? scope.row.CustomerName
                    : status == "7"
                      ? scope.row.FirstTransferServiceName
                      : status == "8"
                        ? scope.row.SecondTransferServiceName
                        : status == "9"
                          ? scope.row.TaxServiceName
                          : status == "10"
                            ? scope.row.OverSeaTransferServiceName
                            : status == "11"
                              ? scope.row.SubsidyServiceName
                              : scope.row.OverseasClearServiceName
            }}
          </template>
        </el-table-column>

        <el-table-column
          v-if="!isCustomerBill"
          label="渠道"
          prop="ChannelName"
          width="100"
        />

        <el-table-column width="70" label="始发地" prop="Departure" />
        <el-table-column width="70" label="目的地" prop="_Destination" />
        <el-table-column width="80" label="箱数" prop="BoxQty" />
        <el-table-column width="80" label="票数" prop="Pieces" />
        <el-table-column label="重量" width="100">
          <template slot-scope="scope"> {{ scope.row.Weight }}KG </template>
        </el-table-column>

        <el-table-column v-if="status != 5" label="计费总额" width="150">
          <template slot-scope="scope">
            {{ getPrice(scope.row) }}
            {{
              status == "1"
                ? ""
                : status == "2"
                  ? ""
                  : status == "3"
                    ? scope.row.OverseasClearCurreny
                    : status == "11"
                      ? scope.row.SubsidyCurrency
                      : ""
            }}
          </template>
        </el-table-column>

        <el-table-column v-if="status == 5" label="预计收入(rmb)" width="150">
          <template slot-scope="scope">
            {{ scope.row.CustomerIncome }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="预计总成本(rmb)" width="150">
          <template slot-scope="scope">
            {{ scope.row.Cost - scope.row.SubsidyFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="空运成本">
          <template slot-scope="scope">
            {{ scope.row.FristFee + scope.row.DomesticClearFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="一级中转成本" width="120">
          <template slot-scope="scope">
            {{ scope.row.FirstTransferFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="二级中转成本" width="120">
          <template slot-scope="scope">
            {{ scope.row.SecondTransferFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="清关成本">
          <template slot-scope="scope">
            {{ scope.row.OverseasClearFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="关税成本">
          <template slot-scope="scope">
            {{ scope.row.TaxFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="海外中转成本" width="120">
          <template slot-scope="scope">
            {{ scope.row.OverSeaTransferFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="派送成本">
          <template slot-scope="scope">
            {{ scope.row.DeliveryCost }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="补贴">
          <template slot-scope="scope">
            {{ scope.row.SubsidyFee }}
          </template>
        </el-table-column>
        <el-table-column v-if="status == 5" label="预计毛利" width="150">
          <template slot-scope="scope">
            <span
              :style="
                'color:' +
                  (scope.row.CustomerIncome - scope.row.Cost > 0 ? 'green' : 'red')
              "
            >
              {{ Math.round(scope.row.CustomerIncome - scope.row.Cost) }}
              ({{
                Math.round(
                  ((scope.row.CustomerIncome - scope.row.Cost) /
                    scope.row.CustomerIncome) *
                    10000
                ) /
                  100 +
                  "%"
              }})
              {{ scope.row.CustomerIncome - scope.row.Cost >= 0 ? "↑" : "↓" }}
              <el-link
                type="primary"
                @click="getLadingDetails(scope.row.BillNumber, status)"
              >下载明细</el-link>
            </span>
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            !isCustomerBill &&
              (status < 5 ||
                status == 7 ||
                status == 8 ||
                status == 9 ||
                status == 10 ||
                status == 11)
          "
          label="预计总额"
          width="150"
        >
          <template slot-scope="scope">
            {{ getEstimatePrice(scope.row) }}
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            !isCustomerBill &&
              (status < 5 ||
                status == 7 ||
                status == 8 ||
                status == 9 ||
                status == 10 ||
                status == 11)
          "
          label="毛利"
          width="150"
        >
          <template slot-scope="scope">
            <span :style="'color:' + (getGrossProfit(scope.row) > 0 ? 'green' : 'red')">
              {{ getGrossProfit(scope.row) }}
              {{
                status == "1"
                  ? ""
                  : status == "2"
                    ? ""
                    : status == "3"
                      ? scope.row.OverseasClearCurreny
                      : ""
              }}
              ({{
                Math.round(
                  getPrice(scope.row) > 0
                    ? ((getGrossProfit(scope.row) / getPrice(scope.row)) * 10000) / 100
                    : 0
                )
              }}%) {{ getGrossProfit(scope.row) >= 0 ? "↑" : "↓" }}</span>
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            status < 5 ||
              status == 7 ||
              status == 8 ||
              status == 9 ||
              status == 10 ||
              status == 11
          "
          label="每kg"
          width="200"
        >
          <template slot-scope="scope">
            {{ Math.round(getUnitPrice(scope.row, 0) * 100) / 100 }}
            {{
              status == "1"
                ? ""
                : status == "2"
                  ? ""
                  : status == "3"
                    ? scope.row.OverseasClearCurreny
                    : ""
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="status < 5" label="每票" width="100">
          <template slot-scope="scope">
            {{ Math.round(getUnitPrice(scope.row, 2) * 100) / 100 }}
            {{
              status == "1"
                ? ""
                : status == "2"
                  ? ""
                  : status == "3"
                    ? scope.row.OverseasClearCurreny
                    : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="
            status < 5 ||
              status == 7 ||
              status == 8 ||
              status == 9 ||
              status == 10 ||
              status == 11
          "
          label="源文件"
          width="80"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              :href="
                status == '1'
                  ? scope.row.FristFileUrl
                  : status == 2
                    ? scope.row.DomesticClearFileUrl
                    : status == 7
                      ? scope.row.FirstTransferFileUrl
                      : status == 8
                        ? scope.row.SecondTransferFileUrl
                        : status == 9
                          ? scope.row.TaxFileUrl
                          : status == 10
                            ? scope.row.OverSeaTransferFileUrl
                            : status == 11
                              ? scope.row.SubsidyFileUrl
                              : scope.row.OverseasClearFileUrl
              "
            >下载</el-link>
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            status < 5 ||
              status == 7 ||
              status == 8 ||
              status == 9 ||
              status == 10 ||
              status == 11
          "
          label="帐单"
          width="100"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="downloadFile(scope.row.Id, status)"
            >下载</el-link>
            <el-link
              type="primary"
              style="margin-left: 5px"
              @click="viewFile(scope.row, status)"
            >预览</el-link>
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            status < 5 ||
              status == 7 ||
              status == 8 ||
              status == 9 ||
              status == 10 ||
              status == 11
          "
          :label="status == '4' ? '已收' : '已付'"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="showDetail(scope.row)"
            >{{
               status == "1"
                 ? scope.row.PaymentFristFee
                 : status == "2"
                   ? scope.row.PaymentDomesticClearFee
                   : status == "3"
                     ? scope.row.PaymentOverseasClearFee
                     : status == "7"
                       ? scope.row.PaymentFirstTransferFee
                       : status == "8"
                         ? scope.row.PaymentSecondTransferFee
                         : status == "9"
                           ? scope.row.PaymentTaxFee
                           : status == "10"
                             ? scope.row.PaymentOverseaTransferFee
                             : status == "11"
                               ? scope.row.PaymentSubsidy
                               : scope.row.CusetomerCheques
             }}
              {{
                status == "1"
                  ? scope.row.FristCurrency
                  : status == "2"
                    ? scope.row.DomesticClearCurrency
                    : status == "3"
                      ? scope.row.OverseasClearCurreny
                      : status == "9"
                        ? scope.row.TaxFeeCurrency
                        : status == "10"
                          ? scope.row.OverSeaTransferFeeCurrency
                          : status == "11"
                            ? scope.row.SubsidyCurrency
                            : status == "4"
                              ? scope.row.CustomerIncomeCurrency
                              : ""
              }}</el-link>
          </template>
        </el-table-column>

        <el-table-column
          v-if="
            status != 5 ||
              status == 7 ||
              status == 8 ||
              status == 9 ||
              status == 10 ||
              status == 11
          "
          label="操作"
          width="250"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="deleteBill(scope.row.Id)">删除</el-button>
            <el-button
              v-if="
                status < 5 ||
                  status == 7 ||
                  status == 8 ||
                  status == 9 ||
                  status == 10 ||
                  status == 11
              "
              size="mini"
              @click="editBill(scope.row, status)"
            >
              修改
            </el-button>
            <el-button
              v-if="
                status < 5 ||
                  status == 7 ||
                  status == 8 ||
                  status == 9 ||
                  status == 10 ||
                  status == 11
              "
              size="mini"
              type="success"
              @click="Payment(scope.row)"
            >
              {{ status == "4" ? "收款" : "付款" }}
            </el-button></template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-sizes="[100, 200, 300, 400]"
        :current-page="pagerDto.PageIndex"
        :page-size="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @current-change="getData"
      />

      <el-dialog title="修改帐单" :visible.sync="dialogEditVisible">
        <el-form :model="row" label-width="120px">
          <el-form-item label="提单号">
            <el-input v-model="row.BillNumber" autocomplete="off" :disabled="true" />
          </el-form-item>

          <el-form-item v-if="!isCustomerBill" label="渠道">
            <el-select
              v-model="row.ChannelId"
              clearable
              filterable
            >
              <el-option
                v-for="item in channels"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              />
            </el-select>
          </el-form-item>

          <el-form-item :label="status == 4 ? '客户' : '服务商'">
            <el-select
              v-model="FristServiceName"
              :placeholder="status == 4 ? '客户' : '服务商'"
              filterable
            >
              <el-option
                v-for="item in canService"
                :key="item.ServiceName + item.Id"
                :label="item.ServiceName"
                :value="item.ServiceName"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="始发地口岸">
            <el-select v-model="row.Departure" placeholder="始发地口岸" filterable>
              <el-option
                v-for="item in OriginPorts"
                :key="item.Port"
                :label="item.Port"
                :value="item.Port"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="目的地口岸">
            <el-select v-model="row._Destination" placeholder="目的地口岸" filterable>
              <el-option
                v-for="item in DestinationPorts"
                :key="item.Port"
                :label="item.Port"
                :value="item.Port"
              />
            </el-select>
          </el-form-item>

          <el-form-item v-if="status == 1&&isCustomerBill" label="头程币种">
            <el-select
              v-model="row.FristCurrency"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>

          <el-form-item v-if="status == 2&&isCustomerBill" label="国内清关币种">
            <el-select
              v-model="row.DomesticClearCurrency"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>

          <el-form-item v-if="status == 4&&isCustomerBill" label="收款币种">
            <el-select
              v-model="row.CustomerIncomeCurrency"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="status == 3" label="清关币种">
            <el-select
              v-model="row.OverseasClearCurreny"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="status == 10" label="海外中转币种">
            <el-select
              v-model="row.OverSeaTransferFeeCurrency"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="status == 11" label="补贴币种">
            <el-select
              v-model="row.SubsidyCurrency"
              placeholder="币种"
              filterable
            >
              <el-option
                v-for="item in currencies"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="箱数">
            <el-input v-model="row.BoxQty" />
          </el-form-item>
          <el-form-item label="票数">
            <el-input v-model="row.Pieces" />
          </el-form-item>
          <el-form-item :label="status=='4'?'计费重量': '重量'">
            <el-input v-model="row.Weight" />
            KG
          </el-form-item>
          <el-form-item v-if="status == 4" label="毛重">
            <el-input v-model="row.GrossWeight" />KG
          </el-form-item>
          <el-form-item v-if="status == 4" label="体积重">
            <el-input v-model="row.VolumeWeight" />KG
          </el-form-item>

          <el-form-item v-if="status == 4" label="帐单时间">
            <el-date-picker
              v-model="row.CustomerBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>

          <el-form-item v-if="status == 1" label="帐单时间">
            <el-date-picker
              v-model="row.FristBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>

          <el-form-item v-if="status == 2" label="帐单时间">
            <el-date-picker
              v-model="row.DomesticClearBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>

          <el-form-item v-if="status == 3" label="帐单时间">
            <el-date-picker
              v-model="row.OverseasClearBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item v-if="status == 7" label="帐单时间">
            <el-date-picker
              v-model="row.FirstTransferBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item v-if="status == 8" label="帐单时间">
            <el-date-picker
              v-model="row.SecondTransferBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item v-if="status == 9" label="帐单时间">
            <el-date-picker
              v-model="row.TaxBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item v-if="status == 10" label="帐单时间">
            <el-date-picker
              v-model="row.OverSeaTransferBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item v-if="status == 11" label="帐单时间">
            <el-date-picker
              v-model="row.SubsidyBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>
          <el-form-item label="计费模板">
            <el-select
              v-model="templateId"
              placeholder="计费模板"
              filterable
              @change="changeEditTemplate"
            >
              <el-option
                v-for="item in canTemplate"
                :key="item.Id"
                :label="item.TemplateName"
                :value="item.Id"
              />
            </el-select>
          </el-form-item>

          <el-form-item
            v-for="(domain, index) in rowIncidentalFees"
            :key="'r'+index"
            :label="'计费' + (index + 1)"
            :prop="'createDtoInfo.' + index + '.Node'"
          >
            <el-input v-model="domain.IncidentalFee" class="input-with-select">
              <el-select
                slot="prepend"
                v-model="domain.IncidentalType"
                placeholder="计费类型"
                filterable
              >
                <el-option
                  v-for="item in canFeeTypes"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                />
              </el-select>
            </el-input>
            <el-button
              icon="el-icon-delete"
              style="margin-left: 10px"
              @click.prevent="removeBillIncidentalFee(domain)"
            />
          </el-form-item>

          <el-form-item v-if="this.status != '4'" label="帐单文件">
            <el-upload
              class="upload-demo"
              action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
              :on-success="changeFileUrl"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogEditVisible = false">取 消</el-button>
          <el-button type="primary" @click="postEditBill">确 定</el-button>
          <el-button @click="addBillIncidentalFee">新增计费项</el-button>
        </div>
      </el-dialog>

      <el-dialog title="付款" :visible.sync="dialogPaymentVisible">
        <el-form :model="row" label-width="80px">
          <el-form-item
            :label="
              (status == '1'
                ? '头程'
                : status == '2'
                  ? '国内清关'
                  : status == '3'
                    ? '国外清关'
                    : '客户') + '金额'
            "
          >
            <el-input
              v-model="postPaymentFee"
              :max="getMaxFee(row)"
              min="0"
              autocomplete="off"
            />
            /{{ getMaxFee(row) }}
            {{ status == "3" ? row.OverseasClearCurreny : "" }}
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="postPaymentRemark" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogPaymentVisible = false">取 消</el-button>
          <el-button type="primary" @click="postPayment">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="付款明细" :visible.sync="dialogFees">
        <el-table :data="sBillData" border>
          <el-table-column label="变更时间" prop="CreateTime" />
          <el-table-column label="变更前" prop="OldValue" />
          <el-table-column label="变更金额">
            <template slot-scope="scope">
              {{ scope.row.NewValue - scope.row.OldValue }}
            </template>
          </el-table-column>
          <el-table-column label="变更后" prop="NewValue" />
          <el-table-column label="备注" prop="Remark" />
        </el-table>
      </el-dialog>

      <el-dialog title="导入帐单" :visible.sync="dialogInputBill">
        <el-form>
          <el-form-item label="帐单文件">
            <el-upload
              class="upload-demo"
              action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
              :on-success="changeImputBillUrl"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
            </el-upload>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="success" @click="postInputFile">提交数据</el-button>

          </el-form-item>
        </el-form>
      </el-dialog>

      <el-dialog title="开始对帐" :visible.sync="dialogStartVisible">
        <el-form :model="createDto" label-width="120px">
          <el-form-item label="提单号">
            <el-input
              v-model="createDto.BillNumber"
              autocomplete="off"
              @change="loadBillInfo"
            />
          </el-form-item>

          <el-form-item v-if="!isCustomerBill" label="渠道">
            <el-select
              v-model="createDto.ChannelId"
              clearable
              filterable
            >
              <el-option
                v-for="item in channels"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              />
            </el-select>
          </el-form-item>

          <el-form-item :label="status == 4 ? '客户' : '服务商'">
            <el-select
              v-model="FristServiceName"
              :placeholder="status == 4 ? '客户' : '服务商'"
              filterable
            >
              <el-option
                v-for="item in canService"
                :key="item.ServiceName + item.Id"
                :label="item.ServiceName"
                :value="item.ServiceName"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="帐单时间">
            <el-date-picker
              v-model="createDto.CustomerBillTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="帐单时间"
            />
          </el-form-item>

          <el-form-item label="始发地口岸">
            <el-select v-model="createDto.Departure" placeholder="始发地口岸" filterable>
              <el-option
                v-for="item in OriginPorts"
                :key="item.Port"
                :label="item.Port"
                :value="item.Port"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="目的地口岸">
            <el-select
              v-model="createDto._Destination"
              placeholder="目的地口岸"
              filterable
            >
              <el-option
                v-for="item in DestinationPorts"
                :key="item.Port"
                :label="item.Port"
                :value="item.Port"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="箱数">
            <el-input v-model="createDtoInfo.SysBoxQty" />
          </el-form-item>
          <el-form-item label="票数">
            <el-input v-model="createDtoInfo.SysPieces" />
          </el-form-item>
          <el-form-item label="计费重量">
            <el-input v-model="createDtoInfo.SysWeight" />KG
          </el-form-item>
          <el-form-item label="计费模板">
            <el-select
              v-model="templateId"
              placeholder="计费类型"
              filterable
              @change="changeCreateTemplate"
            >
              <el-option
                v-for="item in canTemplate"
                :key="item.Id"
                :label="item.TemplateName"
                :value="item.Id"
              />
            </el-select>
          </el-form-item>

          <el-form-item
            v-for="(domain, index) in createDto.IncidentalFees"
            :key="domain.IncidentalType"
            :label="'计费' + (index + 1)"
            :prop="'createDtoInfo.' + index + '.Node'"
          >
            <el-input v-model="domain.IncidentalFee" class="input-with-select">
              <el-select
                slot="prepend"
                v-model="domain.IncidentalType"
                placeholder="计费类型"
              >
                <el-option
                  v-for="item in canFeeTypes"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                />
              </el-select>
            </el-input>
            <el-button
              icon="el-icon-delete"
              style="margin-left: 10px"
              @click.prevent="removeIncidentalFee(domain)"
            />
          </el-form-item>

          <el-form-item label="帐单文件">
            <el-upload
              class="upload-demo"
              action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
              :on-success="changeFristUrl"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
            </el-upload>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogStartVisible = false">取 消</el-button>
          <el-button type="primary" @click="postStart">确 定</el-button>
          <el-button @click="addIncidentalFee">新增计费项</el-button>
        </div>
      </el-dialog>
      <!--客户头程 start --->
      <el-dialog title="开始对帐" :visible.sync="dialogStartByCustomerVisible" top="20px">
        <el-form :model="createDto" label-width="120px" inline>
          <el-row>
            <el-col :span="12"><el-form-item label="提单号" :span="6">
              <el-input
                v-model="createDto.BillNumber"
                autocomplete="off"
                @change="loadBillInfo"
              />
            </el-form-item></el-col>
            <el-col :span="12"> <el-form-item :label="status == 4 ? '客户' : '服务商'">
              <el-select
                v-model="FristServiceName"
                :placeholder="status == 4 ? '客户' : '服务商'"
                filterable
              >
                <el-option
                  v-for="item in canService"
                  :key="item.ServiceName + item.Id"
                  :label="item.ServiceName"
                  :value="item.ServiceName"
                />
              </el-select>
            </el-form-item></el-col>
          </el-row>

          <el-row><el-col :span="12">
                    <el-form-item label="帐单时间" :span="6">
                      <el-date-picker
                        v-model="createDto.CustomerBillTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="帐单时间"
                      />
                    </el-form-item>
                  </el-col>
            <el-col :span="12">
              <el-form-item label="始发地口岸" :span="6">
                <el-select v-model="createDto.Departure" placeholder="始发地口岸" filterable>
                  <el-option
                    v-for="item in OriginPorts"
                    :key="item.Port"
                    :label="item.Port"
                    :value="item.Port"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="目的地口岸" :span="6">
                <el-select
                  v-model="createDto._Destination"
                  placeholder="目的地口岸"
                  filterable
                >
                  <el-option
                    v-for="item in DestinationPorts"
                    :key="item.Port"
                    :label="item.Port"
                    :value="item.Port"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="箱数" :span="6">
                <el-input v-model="createDtoInfo.SysBoxQty" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="票数" :span="6">
                <el-input v-model="createDtoInfo.SysPieces" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计费重量" :span="6">
                <el-input v-model="createDtoInfo.SysWeight" />KG
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="订单状态" :span="6">
                <el-select
                  v-model="createDto.CollectionBillStatus"
                  placeholder="订单状态"
                  filterable
                >
                  <el-option
                    v-for="item in ReceiptLadingBillOrderStatusEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="航线">
                <el-select
                  v-model="createDto.ShipRoute"
                  placeholder="航线"
                  filterable
                >
                  <el-option
                    v-for="item in ShipRouteEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="航司">
                <el-select
                  v-model="createDto.Airline"
                  placeholder="航司"
                  filterable
                >
                  <el-option
                    v-for="item in AirlineService"
                    :key="item.Id"
                    :label="item.ServiceName"
                    :value="item.ServiceName"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售员">
                <el-select
                  v-model="createDto.Salesman"
                  placeholder="销售员"
                  filterable
                >
                  <el-option
                    v-for="item in SalesmanEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="航班号" :span="6">
                <el-input v-model="createDto.FlightNumber" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="报关备注" :span="6">
                <el-input v-model="createDto.ClearanceNote" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="订仓起飞时间" :span="6">
                <el-date-picker
                  v-model="createDto.BookedOffTime"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际起飞时间" :span="6">
                <el-date-picker
                  v-model="createDto.ActualBookedOffTime"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="出库重量" :span="6">
                <el-input v-model="createDto.DeliveryWeight" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="出库体积" :span="6">
                <el-input v-model="createDto.DeliveryVolume" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="磅重" :span="6">
                <el-input v-model="createDto.PoundWeight" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" :span="6">
                <el-input v-model="createDto.CustomerMonitoringRemarks" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="货型重量" :span="6">
                <el-input v-model="createDto.TypeWeight" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否预报" :span="6">
                <el-select
                  v-model="createDto.IsForecast"
                  placeholder="是否预报"
                  filterable
                >
                  <el-option label="是" value="是" />
                  <el-option label="否" value="否" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="帐单文件">
                <el-upload
                  class="upload-demo"
                  action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
                  :on-success="changeFristUrl"
                >
                  <el-button size="small" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计费模板">
                <el-select
                  v-model="templateId"
                  placeholder="计费类型"
                  filterable
                  @change="changeCreateTemplate"
                >
                  <el-option
                    v-for="item in canTemplate"
                    :key="item.Id"
                    :label="item.TemplateName"
                    :value="item.Id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item
            v-for="(domain, index) in createDto.IncidentalFees"
            :key="domain.IncidentalType"
            :label="'计费' + (index + 1)"
            :prop="'createDto.' + index + '.Node'"
          >
            <el-input v-model="domain.IncidentalFee" class="input-with-select">
              <el-select
                slot="prepend"
                v-model="domain.IncidentalType"
                placeholder="计费类型"
              >
                <el-option
                  v-for="item in canFeeTypes"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                />
              </el-select>
            </el-input>
            <el-button
              icon="el-icon-delete"
              style="margin-left: 10px"
              @click.prevent="removeIncidentalFee(domain)"
            />
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogStartByCustomerVisible = false">取 消</el-button>
          <el-button type="primary" @click="postStart">确 定</el-button>
          <el-button @click="addIncidentalFee">新增计费项</el-button>
        </div>
      </el-dialog>
      <el-dialog title="修改帐单" :visible.sync="dialogEditByCustomerVisible" top="20px">
        <el-form :model="row" label-width="120px" inline>
          <el-row>
            <el-col :span="12">
              <el-form-item label="提单号">
                <el-input v-model="row.BillNumber" autocomplete="off" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :span="6" :label="status == 4 ? '客户' : '服务商'">
                <el-select
                  v-model="FristServiceName"
                  :placeholder="status == 4 ? '客户' : '服务商'"
                  filterable
                >
                  <el-option
                    v-for="item in canService"
                    :key="item.ServiceName + item.Id"
                    :label="item.ServiceName"
                    :value="item.ServiceName"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="始发地口岸">
                <el-select v-model="row.Departure" placeholder="始发地口岸" filterable>
                  <el-option
                    v-for="item in OriginPorts"
                    :key="item.Port"
                    :label="item.Port"
                    :value="item.Port"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="目的地口岸">
                <el-select v-model="row._Destination" placeholder="目的地口岸" filterable>
                  <el-option
                    v-for="item in DestinationPorts"
                    :key="item.Port"
                    :label="item.Port"
                    :value="item.Port"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 1&&isCustomerBill" label="头程币种">
                <el-select
                  v-model="row.FristCurrency"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 2&&isCustomerBill" label="国内清关币种">
                <el-select
                  v-model="row.DomesticClearCurrency"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 4&&isCustomerBill" label="收款币种">
                <el-select
                  v-model="row.CustomerIncomeCurrency"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 3" label="清关币种">
                <el-select
                  v-model="row.OverseasClearCurreny"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 10" label="海外中转币种">
                <el-select
                  v-model="row.OverSeaTransferFeeCurrency"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 11" label="补贴币种">
                <el-select
                  v-model="row.SubsidyCurrency"
                  placeholder="币种"
                  filterable
                >
                  <el-option
                    v-for="item in currencies"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="箱数">
                <el-input v-model="row.BoxQty" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="票数">
                <el-input v-model="row.Pieces" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="status=='4'?'计费重量': '重量'">
                <el-input v-model="row.Weight" />
                KG
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 4" label="毛重">
                <el-input v-model="row.GrossWeight" />KG
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 4" label="体积重">
                <el-input v-model="row.VolumeWeight" />KG
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item v-if="status == 4" label="帐单时间">
                <el-date-picker
                  v-model="row.CustomerBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 1" label="帐单时间">
                <el-date-picker
                  v-model="row.FristBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 2" label="帐单时间">
                <el-date-picker
                  v-model="row.DomesticClearBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 3" label="帐单时间">
                <el-date-picker
                  v-model="row.OverseasClearBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 7" label="帐单时间">
                <el-date-picker
                  v-model="row.FirstTransferBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 8" label="帐单时间">
                <el-date-picker
                  v-model="row.SecondTransferBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 9" label="帐单时间">
                <el-date-picker
                  v-model="row.TaxBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 10" label="帐单时间">
                <el-date-picker
                  v-model="row.OverSeaTransferBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
              <el-form-item v-if="status == 11" label="帐单时间">
                <el-date-picker
                  v-model="row.SubsidyBillTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="帐单时间"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="订单状态" :span="6">
                <el-select
                  v-model="row.CollectionBillStatus"
                  placeholder="订单状态"
                  filterable
                >
                  <el-option
                    v-for="item in ReceiptLadingBillOrderStatusEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="航线">
                <el-select
                  v-model="row.ShipRoute"
                  placeholder="航线"
                  filterable
                >
                  <el-option
                    v-for="item in ShipRouteEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="航司">
                <el-select
                  v-model="row.Airline"
                  placeholder="航司"
                  filterable
                >
                  <el-option
                    v-for="item in AirlineService"
                    :key="item.Id"
                    :label="item.ServiceName"
                    :value="item.ServiceName"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售员">
                <el-select
                  v-model="row.Salesman"
                  placeholder="销售员"
                  filterable
                >
                  <el-option
                    v-for="item in SalesmanEnums"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="航班号" :span="6">
                <el-input v-model="row.FlightNumber" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="报关备注" :span="6">
                <el-input v-model="row.ClearanceNote" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="订仓起飞时间" :span="6">
                <el-date-picker v-model="row.BookedOffTime" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际起飞时间" :span="6">
                <el-date-picker v-model="row.ActualBookedOffTime" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="出库重量" :span="6">
                <el-input v-model="row.DeliveryWeight" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="出库体积" :span="6">
                <el-input v-model="row.DeliveryVolume" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="磅重" :span="6">
                <el-input v-model="row.PoundWeight" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" :span="6">
                <el-input v-model="row.CustomerMonitoringRemarks" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="12">
            <el-form-item label="货型重量" :span="6">
              <el-input v-model="createDto.TypeWeight" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否预报" :span="6">
              <el-select
                v-model="createDto.IsForecast"
                placeholder="是否预报"
                filterable
              >
                <el-option label="是" value="是" />
                <el-option label="否" value="否" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="this.status != '4'" label="帐单文件">
              <el-upload
                class="upload-demo"
                action="http://wms.xingyunyi.cn/api/Finance/updateLoadFile"
                :on-success="changeFileUrl"
              >
                <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计费模板">
              <el-select
                v-model="templateId"
                placeholder="计费模板"
                filterable
                @change="changeEditTemplate"
              >
                <el-option
                  v-for="item in canTemplate"
                  :key="item.Id"
                  :label="item.TemplateName"
                  :value="item.Id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-form-item
            v-for="(domain, index) in rowIncidentalFees"
            :key="'r'+index"
            :label="'计费' + (index + 1)"
            :prop="'createDtoInfo.' + index + '.Node'"
          >
            <el-input v-model="domain.IncidentalFee" class="input-with-select">
              <el-select
                slot="prepend"
                v-model="domain.IncidentalType"
                placeholder="计费类型"
                filterable
              >
                <el-option
                  v-for="item in canFeeTypes"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                />
              </el-select>
            </el-input>
            <el-button
              icon="el-icon-delete"
              style="margin-left: 10px"
              @click.prevent="removeBillIncidentalFee(domain)"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogEditByCustomerVisible = false">取 消</el-button>
          <el-button type="primary" @click="postEditBill">确 定</el-button>
          <el-button @click="addBillIncidentalFee">新增计费项</el-button>
        </div>
      </el-dialog>
      <!--客户头程 end --->
      <el-dialog title="帐单明细" :visible.sync="dialogDetailVisible">
        <table
          class="t_d"
          border="1"
          cellspacing="0"
          cellpadding="0"
          style="border-color: #ebeeee"
          width="100%"
        >
          <thead>
            <tr>
              <td v-if="status == 1" colspan="5" class="t_title">
                {{ row.FristServiceName }}
              </td>
              <td v-if="status == 2" colspan="5" class="t_title">
                {{ row.DomesticClearServiceName }}
              </td>
              <td v-if="status == 3" colspan="5" class="t_title">
                {{ row.OverseasClearServiceName }}
              </td>
              <td v-if="status == 4" colspan="5" class="t_title">
                {{ row.CustomerName }}
              </td>
            </tr>
            <tr>
              <td style="width: 200px">日期</td>
              <td v-if="status == 1">{{ row.FristBillTime }}</td>
              <td v-if="status == 2">{{ row.DomesticClearBillTime }}</td>
              <td v-if="status == 3">{{ row.OverseasClearBillTime }}</td>
              <td v-if="status == 4">{{ row.CustomerBillTime }}</td>
              <td>单号</td>
              <td colspan="2">
                {{ row.BillNumber }}
              </td>
            </tr>
            <tr>
              <td>PIECE(件数)</td>
              <td>{{ row.BoxQty }}</td>
              <td>
                <b v-if="status=='4'">Billing weight(计费重量)</b>
                <span v-else>WEIGHT (重量)</span>
              </td>
              <td colspan="2">{{ row.Weight }}</td>
            </tr>
            <tr>
              <td>VolumeWeight(体积重量)</td>
              <td>{{ row.VolumeWeight }}</td>
              <td>GrossWeight(毛重) </td>
              <td colspan="2">{{ row.GrossWeight }}</td>
            </tr>
            <tr>
              <td>Departure(始发站)</td>
              <td>{{ row.Departure }}</td>
              <td>Destination (目的站)</td>
              <td colspan="2">{{ row._Destination }}</td>
            </tr>
            <tr>
              <td>费用项目</td>
              <td>{{ status=='4'?'计费重量':'重量/票数' }}</td>
              <td>币制</td>
              <td>单价</td>
              <td>金额</td>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, i) in viewRowIncidentalFees()" :key="i">
              <td>
                {{ getType(item.IncidentalType).Name }}
              </td>
              <td>
                {{
                  getType(item.IncidentalType).CalculationMethod == 0
                    ? "1"
                    : getType(item.IncidentalType).CalculationMethod == 2
                      ? row.Weight + "Kg"
                      : row.Pieces + "票"
                }}
              </td>
              <td>
                {{ status == 3 ? item.OverseasClearCurreny : "RMB" }}
              </td>
              <td>
                {{ item.IncidentalFee }}
              </td>
              <td>
                {{
                  getType(item.IncidentalType).CalculationMethod == 0
                    ? item.IncidentalFee
                    : getType(item.IncidentalType).CalculationMethod == 2
                      ? item.IncidentalFee * row.Weight
                      : item.IncidentalFee * row.Pieces
                }}
              </td>
            </tr>
            <tr>
              <td>合计（TOTAL）</td>
              <td colspan="3" />
              <td v-if="status == 1">{{ row.FristFee }}</td>
              <td v-if="status == 2">{{ row.DomesticClearFee }}</td>
              <td v-if="status == 3">{{ row.OverseasClearFee }}</td>
              <td v-if="status == 4">{{ row.CusetomerFee }}</td>
            </tr>
          </tbody>
        </table>
      </el-dialog>
      <el-dialog title="导入/导出均摊" :visible.sync="dialogFeeAsFile">
        <el-form>
          <el-form-item>
            <el-alert type="info" show-icon>
              不允许导入相同的提单，系统不检查不存在的提。
              <br>
              不需要表头，表第一列数据为提单号，表第二列数据为总额
              <br>
              直接复制excel内容
            </el-alert>
          </el-form-item>

          <el-form-item label="详细报价">
            <el-input v-model="input.Content" type="textarea" :rows="20" />
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="inputJT()">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  _getData,
  _getBillInfo,
  _postStart2,
  _postEditBill,
  _postPass,
  _postPayment,
  _getLadingBillLogs,
  _postReject,
  _getIncidentals,
  _deleteBill,
  _postInputFile,
  _downloadLadingbillDataByCustomer,
  _getFeeAsFile
} from '@/api/finance'
import { Loading } from 'element-ui'
import { getToken } from '@/utils/auth'
import {
  _getFinanceIncidentalFeeType,
  _getAllPublic,
  _getPaymentStatus
} from '@/api/baseInfo'
import { _getRates, _getCurrencies } from '@/api/financeRate'
import { _getFinanceFirstTemplateDtos } from '@/api/firstTemplate'
import { _getAllService } from '@/api/firstService'
import { _getAllFirstPort } from '@/api/firstPort'
import { mapGetters } from 'vuex'
import { Get } from '@/api/enum/enums'

export default {
  name: 'LadingBill',
  computed: {
    ...mapGetters(['roles'])
  },
  data() {
    return {
      dialogFeeAsFile: false,
      input: {},
      inputBillUrl: '',
      dialogInputBill: false,
      downloadLoading: false,
      selectedBillNumbers: [],
      dialogDetailVisible: false,
      isCustomerBill: false,
      dialogFees: false,
      dialogPaymentVisible: false,
      postPaymentClearFee: 0,
      postPaymentFristFee: 0,
      laddingNumber: '',
      postPaymentFeeStatus: 0,
      FristServiceName: '',
      Customers: [],
      templateId: '',
      s1: 0,
      s2: 0,
      s3: 0,
      status: 1,
      formLabelWidth: 80,
      dialogStartVisible: false,
      dialogEditVisible: false,
      dialogStartByCustomerVisible: false,
      dialogEditByCustomerVisible: false,
      dialogConfirmVisible: false,
      postPaymentFee: 0,
      postPaymentRemark: '',
      passNumber: '',
      channels: [],
      createDto: {
        BillNumber: '',
        FristFee: 0,
        FristFileUrl: '',
        IncidentalFees: []
      },
      customerBillTime: [],
      createDtoInfo: {
        SysBoxQty: 0,
        SysPieces: 0,
        SysWeight: 0
      },
      rates: [],
      currencies: [],
      row: {},
      rowIncidentalFees: [],
      canFeeTypes: [],
      s1Data: [
        {
          BillNumber: '700-000000-000',
          BoxQty: 1,
          SysBoxQty: 1,
          Pieces: 1,
          SysPieces: 1,
          Weight: 10,
          SysWeight: 20,
          FristFileUrl: '',
          ClearFileUrl: '',
          ClearCurreny: 'EUR',
          FristFee: 100.0,
          ClearFee: 200.0,
          UpdateTime: '2020-07-08 22:00:00',
          _Destination: '',
          FristServiceName: ''
        }
      ],
      pagerDto: {
        PageIndex: 1,
        PageSize: 100,
        total: 0,
        QuerySort: [{ Field: 'Id', IsDesc: true }],
        _Eq_BillNumber: '',
        _Eq_BillType: ''
      },
      loadingInstance: {},
      s2Data: [],
      s3Data: [],
      sBillData: [],
      FeeTypes: [],
      PaymentStatus: [],
      canTemplate: [],
      TemplateList: [],
      allService: [],
      canService: [],
      AirlineService: [],
      OriginPorts: [],
      DestinationPorts: [],
      ReceiptLadingBillOrderStatusEnums: [],
      SalesmanEnums: [],
      ShipRouteEnums: []
    }
  },
  created() {
    _getAllPublic().then((resp) => {
      this.channels = resp
    })
    this.isCustomerBill = this.$route.path == '/finance/userLadingBill'
    if (this.isCustomerBill) {
      this.pagerDto._Eq_BillType = 1
    } else {
      this.pagerDto._Eq_BillType = 0
    }

    this.getData(0)
    _getFinanceIncidentalFeeType().then((response) => {
      this.FeeTypes = response
      _getFinanceFirstTemplateDtos().then((res) => {
        this.TemplateList = res
        _getAllService().then((res) => {
          this.allService = res
          this.setCanFees()
        })
      })
    })

    _getAllFirstPort().then((resp) => {
      for (var i = 0; i < resp.length; i++) {
        if (resp[i].PortType == 1) {
          this.OriginPorts.push({ Port: resp[i].Port })
        } else {
          this.DestinationPorts.push({ Port: resp[i].Port })
        }
      }
    })
    _getRates().then((resp) => {
      this.rates = resp
    })
    _getCurrencies().then((resp) => {
      this.currencies = resp
    })
    _getPaymentStatus().then((resp) => {
      this.PaymentStatus = resp
    })
    Get('ReceiptLadingBillOrderStatusEnum').then((res) => {
      this.ReceiptLadingBillOrderStatusEnums = res
    })
    Get('SalesmanEnum').then((res) => {
      this.SalesmanEnums = res
    })
    Get('ShipRouteEnum').then((res) => {
      this.ShipRouteEnums = res
    })
    // this.isCustomerBill = true;
  },
  methods: {
    inputJT() {
      if (this.input.Content) {
        this.input.Content = this.input.Content.trim()

        // 拆分行
        var itemList = this.input.Content.split(/[\r\n]+/)
        // 判断表格是否对齐
        var notAligned = itemList.filter(x => {
          return x.split(/[\t\x20]+/).length != 2
        })
        if (notAligned.length > 0) {
          // 表格未对齐
          this.$alert('当前内容表格未对齐<br/>' + notAligned.join('<br/>'), { dangerouslyUseHTMLString: true })
          return false
        }

        // 判断表格内容是否为全数字
        var regext = /^\d+(\.\d+)?$/
        var notNumber = itemList.filter((x, i) => {
          return !regext.test(x.split(/[\t\x20]+/)[1].trim())
        })

        if (notNumber.length > 0) {
          this.$alert('当前内容非纯数字<br/>' + notNumber.join('<br/>'), { dangerouslyUseHTMLString: true })
          return false
        }
        var cf = []
        var postData = []
        debugger
        for (var i = 0; i < itemList.length; i++) {
          var fi = itemList[i]
          var number = fi.split(/[\t\x20]+/)[0].trim()
          var fee = fi.split(/[\t\x20]+/)[1].trim()
          if (postData.filter(x => { return x.Number == number }).length > 0) {
            // 重复
            cf.push('#' + (i + 1) + '#' + fi)
          } else {
            postData.push({ Number: number, Fee: fee })
          }
        }
        if (cf.length > 0) {
          this.$alert('当前内容重复<br/>' + cf.join('<br/>'), { dangerouslyUseHTMLString: true })
          return false
        }
        _getFeeAsFile({ LaddingBillList: postData }).then(r => {

        })
      } else {
        this.$alert('请输入详细内容')
      }
    },
    viewRowIncidentalFees() {
      return this.status == '4'
        ? this.rowIncidentalFees.filter((x) => x.IncidentalFee > 0)
        : this.rowIncidentalFees
    },
    changeImputBillUrl(r) {
      this.inputBillUrl = r.Data.url
    },
    deleteBill(id) {
      var that = this
      this.$confirm('是否确认删除帐单?').then((response) => {
        _deleteBill({ Id: id }).then((response) => {
          that.getData()
        })
      })
    },
    IsAdmin() {
      for (var i = 0; i < this.roles.length; i++) {
        if (this.roles[i] == '系统管理员') {
          return true
        }
      }
      return false
    },
    IsFinance() {
      for (var i = 0; i < this.roles.length; i++) {
        if (this.roles[i] == '系统管理员' || this.roles[i] == '财务') {
          return true
        }
      }
      return false
    },
    postInputFile() {
      _postInputFile({ url: this.inputBillUrl, feeType: this.status }).then(
        (r) => {
          this.$message('导入成功')
          this.dialogInputBill = false
          this.loadBillInfo()
        }
      )
    },
    handleSelectionChange(val) {
      const billNums = val.map((item) => {
        return item.BillNumber
      })
      this.selectedBillNumbers = billNums
    },
    exportFeeAsFile() {

    },
    exportLadingBills() {
      if (!this.selectedBillNumbers || this.selectedBillNumbers.length == 0) {
        this.$message({
          message: '请先选择提单',
          type: 'warning'
        })
      } else {
        this.downloadLoading = true
        const param = {
          LaddingBills: this.selectedBillNumbers,
          Type: this.status
        }
        var url = `${process.env.VUE_APP_BASE_API}/Finance/GetFee`
        var x = new XMLHttpRequest()
        x.open('POST', url, true)
        x.responseType = 'blob'
        x.setRequestHeader('content-type', 'application/json')
        x.setRequestHeader('token', getToken())
        const fileName =
          this.status == 1
            ? '头程'
            : this.status == 2
              ? '国内清关'
              : this.status == 3
                ? '国外清关'
                : '其他'
        x.onload = (e) => {
          var url = window.URL.createObjectURL(x.response)
          var a = document.createElement('a')
          a.href = url
          a.download = `提单均摊-${fileName}.xls`
          a.click()
          this.downloadLoading = false
        }
        const data = JSON.stringify(param)
        x.send(data)
      }
    },
    exportLadingBillsByCustomer() {
      _downloadLadingbillDataByCustomer(this.pagerDto)
    },
    getType(typeId) {
      for (var i = 0; i < this.FeeTypes.length; i++) {
        if (this.FeeTypes[i].Id == typeId) {
          return this.FeeTypes[i]
        }
      }
    },
    changeCreateTemplate() {
      for (var i = 0; i < this.TemplateList.length; i++) {
        if (this.TemplateList[i].Id == this.templateId) {
          this.createDto.IncidentalFees = []
          for (var j = 0; j < this.TemplateList[i].Details.length; j++) {
            this.createDto.IncidentalFees.push({
              IncidentalType: this.TemplateList[i].Details[j].IncidentalType,
              IncidentalFee: this.TemplateList[i].Details[j].IncidentalFee
            })
          }
        }
      }
    },
    changeEditTemplate() {
      for (var i = 0; i < this.TemplateList.length; i++) {
        if (this.TemplateList[i].Id == this.templateId) {
          this.rowIncidentalFees = []
          for (var j = 0; j < this.TemplateList[i].Details.length; j++) {
            this.rowIncidentalFees.push({
              IncidentalType: this.TemplateList[i].Details[j].IncidentalType,
              IncidentalFee: this.TemplateList[i].Details[j].IncidentalFee
            })
          }
        }
      }
    },

    downloadFile(id, type) {
      var url =
        process.env.VUE_APP_BASE_API +
        '/Finance/DownloadFile?Id=' +
        id +
        '&type=' +
        type
      var x = new XMLHttpRequest()
      x.open('GET', url, true)
      x.responseType = 'blob'
      x.setRequestHeader('token', getToken())
      x.onload = function(e) {
        // 会创建一个 DOMString，其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a')
        a.href = url
        a.download = '1.xls'
        a.click()
      }
      x.send()
    },
    getLadingDetails(BillNumber) {
      var url =
        process.env.VUE_APP_BASE_API +
        '/Finance/GetLadingDetails?BillNumber=' +
        BillNumber
      var x = new XMLHttpRequest()
      x.open('GET', url, true)
      x.responseType = 'blob'
      x.setRequestHeader('token', getToken())
      x.onload = function(e) {
        // 会创建一个 DOMString，其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a')
        a.href = url
        a.download = '1.xls'
        a.click()
      }
      x.send()
    },
    viewFile(row, type) {
      this.row = row
      _getIncidentals(row.Id, type).then((r) => {
        this.rowIncidentalFees = r
        this.dialogDetailVisible = true
      })
    },
    loadBillInfo() {
      this.createDto.BillNumber = this.createDto.BillNumber.trim()
      this.getBillInfo(this.createDto.BillNumber)
    },
    changeFristUrl(r) {
      debugger
      this.createDto.FristFileUrl = r.Data.url
    },
    getMaxFee(row) {
      if (this.status == '1') {
        return row.FristFee - row.PaymentFristFee
      } else if (this.status == '2') {
        return row.DomesticClearFee - row.PaymentDomesticClearFee
      } else if (this.status == '3') {
        return row.OverseasClearFee - row.PaymentOverseasClearFee
      } else if (this.status == '4') {
        return row.CusetomerFee - row.CusetomerCheques
      }
    },
    getSumUnitPrice(row) {
      return (
        row.AvgWeightFristFee +
        row.AvgWeightDomesticClearFee +
        row.AvgWeightOverseasClearFee * this.getRate(row.OverseasClearCurreny)
      )
    },
    getSumUnitPrice2(row) {
      return (
        row.FristFee +
        row.DomesticClearFee +
        row.OverseasClearFee * this.getRate(row.OverseasClearCurreny)
      )
    },
    getUnitPrice(r, type) {
      if (this.status == '1') {
        if (type == 2) {
          return r.AvgPiecesFristFee
        } else {
          return r.AvgWeightFristFee
        }
      } else if (this.status == '2') {
        if (type == 2) {
          return r.AvgPiecesDomesticClearFee
        } else {
          return r.AvgWeightDomesticClearFee
        }
      } else if (this.status == '3') {
        if (type == 2) {
          return r.AvgPiecesOverseasClearFee
        } else {
          return r.AvgWeightOverseasClearFee
        }
      } else if (this.status == '4') {
        if (type == 2) {
          return r.AvgPiecesCusetomerFee
        } else {
          return r.AvgWeightCusetomerFee
        }
      } else if (this.status == '7') {
        return r.AvgFirstTransferPrice
      } else if (this.status == '8') {
        return r.AvgSecondTransferPrice
      } else if (this.status == '9') {
        return r.AvgTaxPrice
      } else if (this.status == '10') {
        return r.AvgOverSeaTransferPrice
      } else if (this.status == '11') {
        return r.AvgSubsidyPrice
      }
    },

    getPrice(r) {
      if (this.status == '1') {
        return r.FristFee
      } else if (this.status == '2') {
        return r.DomesticClearFee
      } else if (this.status == '3') {
        return r.OverseasClearFee
      } else if (this.status == '7') {
        return r.FirstTransferFee
      } else if (this.status == '8') {
        return r.SecondTransferFee
      } else if (this.status == '9') {
        return r.TaxFee
      } else if (this.status == '10') {
        return r.OverSeaTransferFee
      } else if (this.status == '11') {
        return r.SubsidyFee
      } else {
        return r.CusetomerFee
      }
    },
    getEstimatePrice(r) {
      if (this.status == '1') {
        return r.FirstLegUnitPrice * r.Weight
      } else if (this.status == '2') {
        return r.DeclareUnitPrice * r.Weight
      } else if (this.status == '3') {
        return (
          (r.ClearanceUnitWeightPrice + r.ClearanceUnitPiecesPrice) * r.Weight
        )
      } else if (this.status == '4') {
        return (
          (r.FirstLegUnitPrice + r.DeclareUnitPrice) * r.Weight +
          (r.ClearanceUnitWeightPrice + r.ClearanceUnitPiecesPrice) *
            r.Weight *
            this.getRate(r.OverseasClearCurreny)
        )
      } else if (this.status == '7') {
        return (r.FirstTransferPrice * r.Weight).toFixed(2)
      } else if (this.status == '8') {
        return (r.SecondTransferPrice * r.Weight).toFixed(2)
      } else if (this.status == '9') {
        return (r.TaxPrice * r.Weight).toFixed(2)
      } else if (this.status == '10') {
        return (r.OverSeaTransferPrice * r.Weight).toFixed(2)
      } else if (this.status == '11') {
        return (r.SubsidyPrice * r.Weight).toFixed(2)
      }
    },
    getGrossProfit(row) {
      if (
        this.status == '1' ||
        this.status == '2' ||
        this.status == '3' ||
        this.status == '7' ||
        this.status == '8' ||
        this.status == '9' ||
        this.status == '10'
      ) {
        return (
          Math.round((this.getEstimatePrice(row) - this.getPrice(row)) * 100) /
          100
        )
      } else if (this.status == '11') {
        return (
          Math.round((this.getPrice(row) - this.getEstimatePrice(row)) * 100) /
          100
        )
      }
    },
    getRate(currency) {
      var rate = 0
      for (var i = 0; i < this.rates.length; i++) {
        if (this.rates[i].Currency == currency) {
          rate = this.rates[i].ToCNY
        }
      }
      return rate
    },
    changeFileUrl(r) {
      if (this.status == '1') {
        this.row.FristFileUrl = r.Data.url
      } else if (this.status == '2') {
        this.row.DomesticClearFileUrl = r.Data.url
      } else if (this.status == '3') {
        this.row.OverseasClearFileUrl = r.Data.url
      }
    },
    tab_cliek(t) {
      switch (t.label) {
        case '头程帐单':
          this.status = '1'
          break
        case '国内清关帐单':
          this.status = '2'
          break
        case '国外清关帐单':
          this.status = '3'
          break
        case '收款帐单':
          this.status = '4'
          break
        case '盈亏分析':
          this.status = '5'
          break
        case '一级中转账单':
          this.status = '7'
          break
        case '二级中转账单':
          this.status = '8'
          break
        case '关税账单':
          this.status = '9'
          break
        case '海外中转账单':
          this.status = '10'
          break
        case '补贴账单':
          this.status = '11'
          break
      }
      this.getData()
      this.setCanFees()
    },
    setCanFees() {
      this.canFeeTypes = []
      for (var i = 0; i < this.FeeTypes.length; i++) {
        if (this.FeeTypes[i].FeeType == this.status) {
          this.canFeeTypes.push(this.FeeTypes[i])
        }
      }
      this.canTemplate = []
      for (var i = 0; i < this.TemplateList.length; i++) {
        if (this.TemplateList[i].FeeType == this.status) {
          this.canTemplate.push(this.TemplateList[i])
        }
      }
      this.canService = []
      for (var i = 0; i < this.allService.length; i++) {
        if (this.allService[i].ServiceType == this.status) {
          this.canService.push(this.allService[i])
        }
      }
      this.AirlineService = []
      for (var i = 0; i < this.allService.length; i++) {
        if (this.allService[i].ServiceType == 12) {
          this.AirlineService.push(this.allService[i])
        }
      }
    },
    editBill(row) {
      console.log('a')
      this.row = row
      var that = this
      this.templateId = ''
      debugger
      switch (this.status * 1) {
        case 1:
          this.FristServiceName = this.row.FristServiceName
          break
        case 2:
          this.FristServiceName = this.row.DomesticClearServiceName
          break
        case 3:
          this.FristServiceName = this.row.OverseasClearServiceName
          break
        case 4:
          this.FristServiceName = this.row.CustomerName
          break
        case 7:
          this.FristServiceName = this.row.FirstTransferServiceName
          break
        case 8:
          this.FristServiceName = this.row.SecondTransferServiceName
          break
        case 9:
          this.FristServiceName = this.row.TaxServiceName
          break
        case 10:
          this.FristServiceName = this.row.OverSeaTransferServiceName
          break
        case 11:
          this.FristServiceName = this.row.SubsidyServiceName
          break
      }

      _getIncidentals(row.Id, this.status).then((response) => {
        that.rowIncidentalFees = []
        for (var i = 0; i < response.length; i++) {
          that.rowIncidentalFees.push(response[i])
        }
        // 判断是否客户订单
        if (!this.isCustomerBill) {
          that.dialogEditVisible = true
        } else {
          this.dialogEditByCustomerVisible = true
          if (that.CollectionBillStatus == 10 && this.IsFinance()) {
          } else {
            that.ReceiptLadingBillOrderStatusEnums.forEach(x => {
              if (this.row.CollectionBillStatus > x.Id) {
                that.ReceiptLadingBillOrderStatusEnums.splice(x, 1)
              }
            })
          }
        }
      })
    },
    passBill(number) {
      this.passNumber = number
      this.dialogConfirmVisible = true
    },
    postReject(number) {
      this.$confirm('是否确认驳回').then(() => {
        _postReject(number).then((response) => {
          this.$message({
            message: '驳回成功',
            type: 'success'
          })
          this.getData()
        })
      })
    },
    getData(pageIndex) {
      if (this.isCustomerBill) {
        if (this.customerBillTime.length > 0) {
          this.pagerDto._GrE_CustomerBillTime = this.customerBillTime[0]
          this.pagerDto._LeE_CustomerBillTime = this.customerBillTime[1]
        } else {
          this.pagerDto._GrE_DeliveryTime = ''
          this.pagerDto._LeE_DeliveryTime = ''
        }
      } else {
        this.pagerDto._GrE_FristBillTime = ''
        this.pagerDto._LeE_FristBillTime = ''
        this.pagerDto._GrE_OverseasClearBillTime = ''
        this.pagerDto._LeE_OverseasClearBillTime = ''
        this.pagerDto._GrE_DomesticClearBillTime = ''
        this.pagerDto._LeE_DomesticClearBillTime = ''
        this.pagerDto._GrE_FirstTransferBillTime = ''
        this.pagerDto._LeE_FirstTransferBillTime = ''
        this.pagerDto._GrE_SecondTransferBillTime = ''
        this.pagerDto._LeE_SecondTransferBillTime = ''
        this.pagerDto._GrE_TaxBillTime = ''
        this.pagerDto._LeE_TaxBillTime = ''
        this.pagerDto._GrE_OverSeaTransferBillTime = ''
        this.pagerDto._LeE_OverSeaTransferBillTime = ''
        this.pagerDto._GrE_SubsidyBillTime = ''
        this.pagerDto._LeE_SubsidyBillTime = ''

        if (this.customerBillTime.length > 0) {
          var dateStart = this.customerBillTime[0]
          var dateEnt = this.customerBillTime[1]
          if (this.status == 1) {
            this.pagerDto._GrE_FristBillTime = dateStart
            this.pagerDto._LeE_FristBillTime = dateEnt
          } else if (this.status == 2) {
            this.pagerDto._GrE_DomesticClearBillTime = dateStart
            this.pagerDto._LeE_DomesticClearBillTime = dateEnt
          } else if (this.status == 3) {
            this.pagerDto._GrE_OverseasClearBillTime = dateStart
            this.pagerDto._LeE_OverseasClearBillTime = dateEnt
          } else if (this.status == 7) {
            this.pagerDto._GrE_FirstTransferBillTime = dateStart
            this.pagerDto._LeE_FirstTransferBillTime = dateEnt
          } else if (this.status == 8) {
            this.pagerDto._GrE_SecondTransferBillTime = dateStart
            this.pagerDto._LeE_SecondTransferBillTime = dateEnt
          } else if (this.status == 9) {
            this.pagerDto._GrE_TaxBillTime = dateStart
            this.pagerDto._LeE_TaxBillTime = dateEnt
          } else if (this.status == 10) {
            this.pagerDto._GrE_OverSeaTransferBillTime = dateStart
            this.pagerDto._LeE_OverSeaTransferBillTime = dateEnt
          } else if (this.status == 11) {
            this.pagerDto._GrE_SubsidyBillTime = dateStart
            this.pagerDto._LeE_SubsidyBillTime = dateEnt
          }
        }
      }
      if (pageIndex && pageIndex > 0) {
        this.pagerDto.PageIndex = pageIndex
      } else {
        this.pagerDto.PageIndex = 1
      }
      if (this.status == 1) {
        this.pagerDto._Eq_PaymentFristFeeStatus = this.postPaymentFeeStatus
      } else if (this.status == 2) {
        this.pagerDto._Eq_PaymentDomesticClearFeeStatus =
          this.postPaymentFeeStatus
      } else if (this.status == 3) {
        this.pagerDto._Eq_PaymentOverseasClearFeeStatus =
          this.postPaymentFeeStatus
      } else if (this.status == 4) {
        // this.pagerDto._Eq_CusetomerChequesStatus = this.postPaymentFeeStatus
      }
      _getData(this.pagerDto).then((response) => {
        this.s1Data = response.Result
        this.pagerDto.total = response.TotalCount
      })
    },
    getBillInfo(number) {
      _getBillInfo(number).then((response) => {
        debugger
        this.createDtoInfo.SysBoxQty = response.SysBoxQty
        this.createDtoInfo.SysPieces = response.SysPieces
        this.createDtoInfo.SysWeight = response.SysWeight / 1000
        this.createDto._Destination = response.Destination
      })
    },
    postStart() {
      this.createDto.BoxQty = this.createDtoInfo.SysBoxQty
      this.createDto.Pieces = this.createDtoInfo.SysPieces
      this.createDto.Weight = this.createDtoInfo.SysWeight
      this.createDto.BillType = this.isCustomerBill ? 1 : 0
      this.createDto.FristServiceName = this.FristServiceName
      _postStart2(this.createDto).then((rseponse) => {
        this.$message({
          message: '通过成功',
          type: 'success'
        })
        this.getData()
        this.dialogStartVisible = false
      })
    },
    postEditBill() {
      this.row.IncidentalFees = this.rowIncidentalFees
      this.row.Type = this.status
      debugger
      switch (this.status * 1) {
        case 1:
          this.row.FristServiceName = this.FristServiceName
          break
        case 2:
          this.row.DomesticClearServiceName = this.FristServiceName
          break
        case 3:
          this.row.OverseasClearServiceName = this.FristServiceName
          break
        case 4:
          this.row.CustomerName = this.FristServiceName
          break
        case 7:
          this.row.FirstTransferServiceName = this.FristServiceName
          break
        case 8:
          this.row.SecondTransferServiceName = this.FristServiceName
          break
        case 9:
          this.row.TaxServiceName = this.FristServiceName
          break
        case 10:
          this.row.OverSeaTransferServiceName = this.FristServiceName
          break
        case 11:
          this.row.SubsidyServiceName = this.FristServiceName
          break
      }
      console.log(this.row)
      _postEditBill(this.row).then((response) => {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.getData()
        this.dialogEditVisible = false
      })
    },
    postPass() {
      this.loadingInstance = Loading.service()
      _postPass(this.passNumber)
        .then((response) => {
          this.getData()
          this.dialogConfirmVisible = false
          this.loadingInstance.close()
        })
        .catch((response) => {
          this.loadingInstance.close()
        })
    },
    Payment(row) {
      this.row = row
      // this.postPaymentClearFee = 0
      // this.postPaymentFristFee = 0
      this.dialogPaymentVisible = true
    },
    postPayment() {
      _postPayment({
        PostPaymentFee: this.postPaymentFee,
        Remark: this.postPaymentRemark,
        Type: this.status,
        Id: this.row.Id
      }).then((response) => {
        this.getData()
        this.dialogPaymentVisible = false
      })
    },
    showDetail(row) {
      this.row = row
      this.dialogFees = true
      _getLadingBillLogs({
        billId: row.Id,
        Type: this.status
      }).then((response) => {
        this.sBillData = response
      })
    },
    removeIncidentalFee(item) {
      var index = this.createDto.IncidentalFees.indexOf(item)
      if (index !== -1) {
        this.createDto.IncidentalFees.splice(index, 1)
      }
    },
    addIncidentalFee() {
      if (this.canFeeTypes && this.canFeeTypes.length > 0) {
        this.createDto.IncidentalFees.push({
          IncidentalType: this.canFeeTypes[0].Id,
          IncidentalFee: 0
        })
      }
    },

    removeBillIncidentalFee(item) {
      var index = this.rowIncidentalFees.indexOf(item)
      if (index !== -1) {
        this.rowIncidentalFees.splice(index, 1)
      }
    },
    addBillIncidentalFee() {
      if (this.canFeeTypes && this.canFeeTypes.length > 0) {
        this.rowIncidentalFees.push({
          IncidentalType: this.canFeeTypes[0].Id,
          IncidentalFee: 0
        })
      }
    }
  }
}
</script>
<style>
.el-pagination {
  margin-top: 10px;
}
.el-dialog .el-form .el-input,
.el-dialog .el-form .el-select {
  width: 300px;
}
.el-select--medium {
  width: 150px !important;
}
.el-select--medium .el-input--medium {
  width: 150px !important;
}

.el-table tbody tr:hover > td {
  background-color: #fdfad8 !important;
}
.el-tag {
  margin-right: 5px !important;
  clear: both;
  display: block;
  width: 100px;
}

.t_d td {
  line-height: 40px;
  padding-left: 10px;
  /* border: 1px solid #000; */
}

.t_d .t_title {
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  line-height: 60px;
}
</style>
