<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
      <el-form-item :label="$t('编号')" prop="orderNo">
        <el-input v-model.trim="noParam.value" :placeholder="$t('请输入订单号、唛头、提单号')" clearable @input="replaceSpace(noParam, 'value')" @keyup.enter.native="handleQuery">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.ORDER_QUERY_NO_FIELD" defaultable v-model="noParam.key" class="w-50" />
          </template>
        </el-input>
      </el-form-item>
      <!-- <el-form-item :label="$t('唛头')" prop="marks">
        <el-input v-model="queryParams.marks" :placeholder="$t('唛头')" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->

      <el-form-item :label="$t('发货人')" prop="consignorKey">
        <el-input v-model.trim="queryParams.consignorKey" :placeholder="$t('发货人')" clearable @keyup.enter.native="handleQuery" @input="replaceSpace(queryParams, 'consignorKey')" />
      </el-form-item>
      <el-form-item :label="$t('收货人')" prop="consigneeKey">
        <el-input v-model.trim="queryParams.consigneeKey" :placeholder="$t('收货人')" clearable @keyup.enter.native="handleQuery" @input="replaceSpace(queryParams, 'consigneeKey')" />
      </el-form-item>

      <el-form-item :label="$t('控货')" prop="isCargoControl" v-show="showSearch">
        <dict-selector v-model="queryParams.isCargoControl" :type="DICT_TYPE.INFRA_BOOLEAN_STRING" fomatter="bool" clearable @change="handleQuery" />
      </el-form-item>
      <div>
        <el-form-item :label="$t('始发仓')" prop="startWarehouseIds">
          <el-select v-model="queryParams.startWarehouseIds" multiple :placeholder="$t('请选择始发仓')" clearable @change="handleQuery">
            <el-option v-for="item in exportWarehouseList" :label="$l(item, 'title')" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item :label="$t('目的国')" prop="destCountryId">
          <el-select v-model="destCountryId" multiple :label="destCountryId" :placeholder="$t('请选择目的国')" clearable @change="handleQuery">
            <el-option v-for="item in AddressProvince" :key="item.guojia" :label="item.guojiaName" :value="item.guojia"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的城市')" prop="objectiveId">
          <el-select v-model="objectiveId" multiple :placeholder="$t('请选择目的城市')" style="width: 200px" clearable @change="handleQuery">
            <el-option v-for="item in AddressCity" :key="item.shi" :label="item.shiName" :value="item.shi"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的仓')" prop="destWarehouseId">
          <el-select v-model="destWarehouseId" multiple :placeholder="$t('请选择目的仓')" style="width: 200px" clearable @change="handleQuery">
            <el-option v-for="item in AddressTown" :key="item.id" :label="item.titleZh" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </div>

      <el-form-item :label="$t('运输方式')" prop="transportId" v-if="!transportId">
        <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model.number="queryParams.transportId" clearable @change="handleQuery" />
      </el-form-item>

      <el-form-item :label="$t('商品类型')" prop="goodsTypes" v-show="showSearch">
        <selector v-model="queryParams.goodsTypes" multiple :options="productAttrList" label-field="attrName" value-field="id"> </selector>
      </el-form-item>
      <!--
      <el-form-item :label="$t('品名')" prop="prodId">
        <product-selector v-model="queryParams.prodId" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('品牌')" prop="brand">
        <dict-selector v-model="queryParams.brand" :type="DICT_TYPE.ECW_IS_BRAND" formatter="bool" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->

      <el-form-item :label="$t('商品')" prop="tidanNo" v-show="showSearch">
        <el-input v-model.trim="prodParam.value" :placeholder="$t('请输入商品类型、品名或品牌')" clearable @keyup.enter.native="handleQuery" @input="replaceSpace(prodParam, 'value')">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.ORDER_QUERY_PROD_FIELD" defaultable v-model="prodParam.key" class="w-50" />
          </template>
        </el-input>
      </el-form-item>

      <el-form-item :label="$t('入仓类型')" prop="warehouseType" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ECW_WAREHOUSING_TYPE" v-model="queryParams.warehouseTypes" multiple clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('客户经理')">
        <user-selector manage v-model="queryParams.salesmanIds" multiple clearable @change="handleQuery" :prepend="{ id: 0, nickname: $t('未分配客户经理') }" />
      </el-form-item>
      <el-form-item :label="$t('动态')" prop="statusList">
        <dict-selector :type="DICT_TYPE.ORDER_STATUS" multiple v-model="queryParams.statusList" @keyup.enter.native="handleQuery" :filter="statusDictFilter" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('收货人')" v-show="showSearch">
        <el-select v-model="queryParams.hasConsignee" :placeholder="$t('请选择')" clearable @change="handleQuery">
          <el-option :label="$t('有')" :value="true"></el-option>
          <el-option :label="$t('无')" :value="false"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item :label="$t('报关方式')" prop="customsTypes" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ECW_CUSTOMS_TYPE" multiple v-model="queryParams.customsTypes" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('是否齐货')" v-show="showSearch">
        <!--//字段存疑-->
        <dict-selector v-model="queryParams.isNeat" :type="DICT_TYPE.INFRA_BOOLEAN_STRING" fomatter="bool" clearable @change="handleQuery" />
      </el-form-item>
      <!-- <el-form-item :label="$t('重货比')" prop="weightRatio">
        <el-input style="width: 100px;" v-model="molecule" placeholder="" clearable @change="moleculeChange"
          @keyup.enter.native="handleQuery" />
        -
        <el-input style="width: 100px;" v-model="denominator" placeholder="" clearable @change="denominatorChange"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item :label="$t('备案属性')" prop="productRecords" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.PRODUCT_RECORD_ATTRIBUTE" multiple v-model="queryParams.productRecords" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('快递单号')" prop="number" v-show="showSearch">
        <el-input v-model="queryParams.number" :placeholder="$t('快递单号')" clearable @keyup.enter.native="handleQuery" onkeyup="this.value=this.value.replace(/\s+/g, '')" />
      </el-form-item>
      <el-form-item :label="$t('外部仓')" prop="isExternalWarehouse" v-show="showSearch">
        <el-select v-model="queryParams.isExternalWarehouse" :placeholder="$t('请选择')" clearable @change="handleQuery">
          <el-option :label="$t('外部仓')" value="true"></el-option>
          <el-option :label="$t('自有仓')" value="false"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item :label="$t('异常状态')" prop="abnormalStateList" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ORDER_ABNORMAL_STATE" multiple v-model="queryParams.abnormalStateList" @keyup.enter.native="handleQuery" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('审核状态')" prop="auditTypeList" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ECW_ORDER_APPROVAL_TYPE" multiple v-model="queryParams.auditTypeList" @keyup.enter.native="handleQuery" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('增值服务')" prop="types" v-show="showSearch">
        <el-select v-model="queryParams.types" multiple :placeholder="$t('请选择')" clearable @change="handleQuery">
          <el-option :label="$t('普通订单')" :value="0"></el-option>
          <el-option :label="$t('集运服务')" :value="1"></el-option>
          <el-option :label="$t('海外仓')" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <!--空运多一个出货渠道筛选-->
      <el-form-item :label="$t('出货渠道')" prop="channelIds" v-if="channelList.length">
        <selector :clearable="true" :options="channelList" :label-field="$l('name')" value-field="channelId" v-model="queryParams.channelIds" multiple></selector>
      </el-form-item>
      <el-form-item :label="$t('特需')" prop="packageType" v-show="showSearch">
        <el-select v-model="queryParams.packageTypeArr" multiple :placeholder="$t('请选择')" clearable>
          <template v-for="item in getDictDatas(DICT_TYPE.ORDER_SPECIAL_NEEDS)">
            <el-option :label="$l(item, 'label')" :value="item.value"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('提货状态')" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.PICK_STATE" multiple v-model="queryParams.pickStateList" clearable @change="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('提货率')" v-show="showSearch">
        <el-input type="number" v-model.trim="pickRatio.value" :placeholder="$t('请输入数字')" clearable @keyup.enter.native="handleQuery">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.PICK_RATIO_FIELD" defaultable v-model="pickRatio.key" class="w-50" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="">
        <dict-selector :type="DICT_TYPE.ECW_BEGINTIME_TYPE_ENDTIME" :filter="(item) => item.value != 'PickTime'" v-model="dateFilterType" defaultable style="width: 150px; margin-right: 5px" />
        <el-date-picker v-model="dateFilter" type="datetimerange" range-separator="-" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')" value-format="yyyy-MM-dd HH:mm:ss" @change="handleQuery"> </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery" :loading="loading">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5" v-if="transportId">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['ecw:order:create']">{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <!--        <el-button type="primary" plain icon="el-icon-setting" size="mini" @click="handleEdit" :disabled="!batchWarehouseAdjustment">{{$t('批量调仓')}}-->
        <!--        </el-button>-->
        <el-button type="primary" v-hasPermi="['ecw:order:batch_release']" plain icon="el-icon-setting" size="mini" @click="showBatchPickup = true">{{ $t("批量提货") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          :loading="exportLoading" v-hasPermi="['ecw:order:export']">{{$t('导出')}}</el-button> -->
        <el-dropdown v-hasPermi="isAll ? ['ecw:order:export', 'ecw:order:export:other'] : [exportPermiString]">
          <el-button type="primary" :loading="exportLoading" size="mini"> {{ $t("导出") }} <i class="el-icon-arrow-down el-icon--right"></i> </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-hasPermi="[exportPermiString]" @click.native="exportChecked">{{ $t("导出勾选") }}</el-dropdown-item>
            <el-dropdown-item v-hasPermi="[exportPermiString]" @click.native="exportSearch">{{ $t("导出搜索") }}</el-dropdown-item>
            <template v-if="isAll">
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportAbnormal">{{ $t("异常单统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportHeavyOrder">{{ $t("重货单统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportReturnOrder">{{ $t("退仓单统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportSaleRepay">{{ $t("售后赔偿金额统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportCustomsDatas">{{ $t("报关数据统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportShippingDatas">{{ $t("客户出货量统计") }}</el-dropdown-item>
              <el-dropdown-item hasPermi="[exportPermiString]" @click.native="exportShipFee">{{ $t("预付运费统计") }}</el-dropdown-item>
            </template>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
      <el-col :span="15" v-if="statistics">
        <!-- 订单列表显示搜索条件对应箱数、仓库实测、收款方数、重量 -->
        {{ $t("合计：{totalNum}箱，{totalVolume}m³(测) {totalChargeVolume}m³(重) {totalWeight}KG(测), {totalChargeWeight}kg(收费)", statistics) }}
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column :label="$t('订单编号')" width="120px" align="center" prop="orderNo">
        <template slot-scope="scope">
          <router-link
            :to="{
              path: '/order/detail',
              query: { orderId: scope.row.orderId }
            }"
            class="link-type"
          >
            <span>{{ scope.row.orderNo }}</span>
          </router-link>
          <div style="display: flex; flex-wrap: wrap" v-if="scope.row.advanceType">
            <el-button @click="deleteSpecial(item.value, scope.row.orderId)" size="mini" style="margin-left: 20px" type="danger" circle v-for="(item, index) in specialRendering(scope.row.advanceType)" :key="index">{{ item.symbol }}</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('发货人编号')" align="center">
        <template slot-scope="{ row }">
          <router-link :to="`/customer/query/${row.consignorCustomerId}`" class="link-type">
            {{ row.consignorCustomerNumber }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('收货人编号')" align="center" prop="consigneeCustomerNumber">
        <template slot-scope="{ row }">
          <router-link :to="`/customer/query/${row.consigneeCustomerId}`" class="link-type">
            {{ row.consigneeCustomerNumber }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('总箱数/入仓箱数')" align="center" prop="sumNum">
        <template slot-scope="{ row }">
          <div :style="{ color: row.customsType != 1 ? 'red' : null }">{{ row.totalNum }}{{ $t("箱") }}/{{ row.sumNum }}{{ $t("箱") }}</div>
          <dict-tag v-if="row.customsType != 1" style="color: red" :type="DICT_TYPE.ECW_CUSTOMS_TYPE" :value="row.customsType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('体积/重量')" align="center" prop="sumWeight">
        <template slot-scope="{ row }">
          <!--入仓前是填单数据，入仓后是入仓数据，装柜审核通过等状态inwarehouseState会变成0，所以只能通过sumNum来判断-->
          <component
            :is="row.orderType > 1 ? 'el-tooltip' : 'div'"
            class="item"
            :style="{
              color: row.orderType > 1 ? 'red' : null
            }"
            effect="dark"
            :content="row.orderType === 2 ? (row.wvolume || 0) + 'm³' : (row.vweight || 0) + 'kg'"
            placement="bottom"
          >
            <!-- <div v-if="row.sumNum > 0">{{row.sumVolume}}m³ /{{row.sumWeight}}Kg</div>
            <div v-else>{{row.costVO.totalVolume}}m³ /{{row.costVO.totalWeight}}Kg</div> -->
            <div>{{ row.sumVolume }}m³ /{{ row.sumWeight }}Kg</div>
          </component>
        </template>
      </el-table-column>

      <el-table-column :label="$t('始发仓')" align="center" prop="startWarehouseName">
        <template slot-scope="{ row }">
          {{ row.startWarehouseName }}
          <span style="color: red" v-if="row.isExternalWarehouse">({{ $t("外部仓") }})</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('运输方式-渠道/目的地')" align="center" prop="transportId">
        <template slot-scope="{ row }">
          <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="row.transportId" />
          <template v-if="row.channelName"> - {{ row.channelName }} </template>
          / {{ row.dstWarehouseName }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('控货')" align="center" prop="transportId">
        <template slot-scope="{ row }">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.isCargoControl" />
        </template>
      </el-table-column>

      <el-table-column :label="$t('增值服务')" align="center" prop="status">
        <template slot-scope="{ row }">
          {{ getTypeText(row.type) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('状态')" align="center" prop="status">
        <template slot-scope="scope">
          <!-- <dict-tag :type="DICT_TYPE.ORDER_STATUS" :value="scope.row.status" /> -->
          {{ scope.row.statusText }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('唛头')" align="center" prop="marks" />
      <el-table-column v-if="dept" :label="$t('客户经理')" align="center" prop="salesmanName" />
      <el-table-column :label="$t('发货人客服')" align="center" prop="consignorFollowCustomerService" />
      <el-table-column :label="$t('收货人客服')" align="center" prop="consigneeFollowCustomerService" />
      <el-table-column :label="$t('到仓箱数/方数/重量')" align="center" prop="status">
        <template slot-scope="{ row }">
          {{ row.checkNum }}{{ $t("箱") }} / {{ row.checkVolume }}m³ /{{ row.checkWeight }}Kg
        </template>
      </el-table-column>
      <el-table-column :label="$t('提货率')" align="center" prop="pickRatio" />
      <el-table-column :label="$t('动态')" align="center" prop="statusMsg" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width actions" width="180px">
        <template slot-scope="scope">
          <!-- 已删除的订单只需要删除和查看 https://zentao.jdshangmen.com/bug-view-684.html -->
          <template v-if="scope.row.status == 88">
            <el-button type="text" @click.native="oprateOrder(scope.row.orderId, 'deleteOrder')" v-hasPermi="['ecw:order:delete']">{{ $t("删除") }}</el-button>
          </template>
          <template v-else>
            <!--操作相关的-->
            <el-dropdown
              v-hasPermi="[
                'ecw:order:edit',
                'ecw:order:shipment:update',
                'ecw:order:delete',
                'ecw:order:cancel',
                'ecw:order:fee_apply',
                'ecw:order:special',
                'ecw:order:associate',
                'ecw:order:mutex',
                'ecw:order:release',
                'ecw:order:merge',
                'ecw:order:split',
                'ecw:order:merge_log',
                'ecw:order:split_log',
                // 下面几个是特价里的
                'ecw:order:discount',
                'ecw:order:reduce',
                'ecw:order:commission',
                'ecw:order:heavy',
                'ecw:order:bulky',
                'ecw:order:setCanNotShipment'
              ]"
            >
              <el-button type="text">{{ $t("操作") }}</el-button>
              <el-dropdown-menu slot="dropdown">
                <!--出货订单编辑,shipmentState > 0表示出货后，inWarehouseState == 0 表示预装未审核或者是卸柜到仓 ， shipmentState==307 表示已预装，待封柜， shipmentState==407 表示已预装，待封柜）-->
                <template
                  v-if="scope.row.shipmentState > 0 && scope.row.inWarehouseState == 0 && scope.row.shipmentState != 307 && scope.row.shipmentState != 407"
                >
                  <el-dropdown-item
                    @click.native="handleUpdate(scope.row)"
                    v-hasPermi="['ecw:order:shipment:update']"
                  >{{ $t("编辑") }}</el-dropdown-item
                  >
                </template>
                <!-- 其他编辑 -->
                <template
                  v-else-if="
                    (scope.row.status < 12 ||
                      (scope.row.status == 12 &&
                        scope.row.shipmentState == 314)) &&
                    !scope.row.abnormalState &&
                    exclude(scope.row.inWarehouseState, [204, 205, 206]) &&
                    exclude(scope.row.shipmentState, [307, 407])
                  "
                >
                  <el-dropdown-item
                    @click.native="handleUpdate(scope.row)"
                    v-hasPermi="['ecw:order:edit']"
                    >{{ $t("编辑") }}</el-dropdown-item
                  >
                </template>

                <!-- 删除 -->
                <template v-if="include(scope.row.status, [0, 2, 88])">
                  <el-dropdown-item @click.native="oprateOrder(scope.row.orderId, 'deleteOrder')" v-hasPermi="['ecw:order:delete']">{{ $t("删除") }}</el-dropdown-item>
                </template>

                <!-- 取消 -->
                <template v-if="include(scope.row.status, [2])">
                  <el-dropdown-item @click.native="oprateOrder(scope.row.orderId, 'cancelOrder')" v-hasPermi="['ecw:order:cancel']">{{ $t("取消订单") }}</el-dropdown-item>
                </template>
                <!-- <el-dropdown-item @click.native="oprateOrder(scope.row.orderId, 'recoveryOrder')" >{{$t('恢复订单')}}</el-dropdown-item>-->

                <!-- 费用申请 -->
                <template v-if="exclude(scope.row.status, [0, 88]) && exclude(scope.row.inWarehouseState, [204, 205, 206]) && exclude(scope.row.abnormalState, [1])">
                  <el-dropdown-item
                    @click.native="
                      feeApplicationBol = true
                      orderId = scope.row.orderId
                    "
                    v-hasPermi="['ecw:order:fee_apply']"
                    >{{ $t("费用申请") }}</el-dropdown-item
                  >
                </template>

                <!-- 特需,互斥，关联 -->
                <template v-if="include(scope.row.status, [2, 3, 5, 8, 9, 10]) && exclude(scope.row.abnormalState, [1, 99, 2, 3, 4, 9, 10, 11, 12, 14]) && exclude(scope.row.inWarehouseState, [204])">
                  <el-dropdown-item
                    @click.native="
                      orderId = scope.row.orderId
                      orderNo = scope.row.orderNo
                      isShow = true
                    "
                    v-hasPermi="['ecw:order:special']"
                    >{{ $t("特需") }}</el-dropdown-item
                  >
                  <el-dropdown-item @click.native="$router.push(`/order/associated-order/${scope.row.orderId}`)" v-hasPermi="['ecw:order:associate']">{{ $t("关联") }}</el-dropdown-item>
                  <el-dropdown-item @click.native="$router.push(`/order/mutex-order/${scope.row.orderId}`)" v-hasPermi="['ecw:order:mutex']">{{ $t("互斥") }}</el-dropdown-item>
                </template>

                <!-- 特价 -->
                <template v-if="exclude(scope.row.status, [0]) && exclude(scope.row.abnormalState, [1]) && exclude(scope.row.inWarehouseState, [204, 205, 206])">
                  <!-- 特价里有多个操作，只要有其一权限就显示此菜单 -->
                  <el-dropdown-item @click.native="$router.push('/order/special/' + scope.row.orderId)" v-hasPermi="['ecw:order:discount', 'ecw:order:reduce', 'ecw:order:commission', 'ecw:order:heavy', 'ecw:order:bulky']">{{ $t("特价") }}</el-dropdown-item>
                </template>

                <!-- 确认提货 -->
                <template v-if="scope.row.status >= 5 && exclude(scope.row.inWarehouseState, [1, 99, 2, 3, 4, 9, 10, 11, 12, 14]) && exclude(scope.row.inWarehouseState, [204, 205, 206]) && exclude(scope.row.abnormalState, [1])">
                  <el-dropdown-item @click.native="$router.push(`/order/release?orderId=${scope.row.orderId}`)" v-hasPermi="['ecw:order:release']">{{ $t("确认提货") }}</el-dropdown-item>
                </template>

                <!-- 合单，拆单 -->
                <!--可出后不显示拆单（经确认合单也不显示） https://zentao.test.jdshangmen.com/bug-view-5322.html-->
                <template v-if="([3, 4].indexOf(scope.row.transportId) < 0 || scope.row.airShipment < 2) && (scope.row.status < 12 || (scope.row.status == 12 && scope.row.shipmentState == 314)) && !scope.row.abnormalState && scope.row.status > 3 && exclude(scope.row.inWarehouseState, [204, 205, 206, 212, 213])">
                  <el-dropdown-item @click.native="$router.push(`/order/singleApply?orderNo=${scope.row.orderNo}`)" v-hasPermi="['ecw:order:merge']">{{ $t("合单申请") }}</el-dropdown-item>

                  <el-dropdown-item @click.native="$router.push(`/order/splitApply?orderId=${scope.row.orderId}`)" v-hasPermi="['ecw:order:split']">{{ $t("拆单申请") }}</el-dropdown-item>
                </template>

                <!--撤销拆单，拆单的子订单,预装前显示，预装后变灰不可点击-->
                <template v-if="scope.row.parentOrderId && scope.row.status < 11">
                  <el-dropdown-item @click.native="splitRevoke(scope.row)" v-hasPermi="['ecw:order:split_revoke']">{{ $t("撤销拆单") }}</el-dropdown-item>
                </template>
                <template v-if="scope.row.parentOrderId">
                  <el-dropdown-item @click.native="showParentOrder(scope.row)">{{ $t("查看母订单") }}</el-dropdown-item>
                </template>

                <!-- 合单日志，提货日志 -->
                <template v-if="scope.row.status > 2">
                  <el-dropdown-item @click.native="showMergedLogOrderNo = scope.row.orderNo" v-hasPermi="['ecw:order:merge_log']">{{ $t("合单日志") }}</el-dropdown-item>
                  <el-dropdown-item @click.native="showPickupLogOrderNo = scope.row.orderNo" v-hasPermi="['ecw:order:split_log']">{{ $t("提货日志") }}</el-dropdown-item>
                </template>

                <!--变更出货渠道-->
                <template v-if="scope.row.transportId == 3">
                  <el-dropdown-item @click.native="handleUpdate(scope.row, true)" v-hasPermi="['ecw:order:update_channel']">{{ $t("变更出货渠道") }}</el-dropdown-item>
                </template>

                <!--不可出-->
                <template v-if="include(scope.row.airShipment, [2, 3, 4]) && scope.row.status < 11">
                  <el-dropdown-item @click.native="setCanNotShipment(scope.row)" v-hasPermi="['ecw:order:setCanNotShipment']">{{ $t("不可出") }}</el-dropdown-item>
                </template>

                <!--转异-->
                <el-dropdown-item @click.native="handleException(scope.row)" v-hasPermi="['ecw:order:turnException']">{{ $t("转异") }}</el-dropdown-item>

                <template v-if="scope.row.abnormalState != 0">
                  <el-dropdown-item @click.native="openException(scope.row)">{{ $t("查看异常") }}</el-dropdown-item>
                  <el-dropdown-item @click.native="openException(scope.row)">{{ $t("处理异常") }}</el-dropdown-item>
                </template>
              </el-dropdown-menu>
            </el-dropdown>

            <template
              v-if="
                (exclude(scope.row.status,[0, 11, 12, 13, 14, 15, 17, 18, 32]) && exclude(scope.row.inWarehouseState, [204, 205, 206]))
                ||
                (scope.row.shipmentState > 0 && scope.row.inWarehouseState == 0)
              "
            >
              <!-- <el-divider direction="vertical"></el-divider> -->
              <!--仓库相关的-->
              <el-dropdown
                v-hasPermi="[
                  'ecw:order:warehouse_add',
                  'ecw:order:warehouse_update',
                  'ecw:order:warehouse_exit',
                  'ecw:order:warehouse_adjustment',
                  'ecw:order:warehouse_transfer',
                  'ecw:order:warehouse_arrive',
                  'ecw:order:stocking',
                  'ecw:order:shipment:warehouse_replenish',
                  'ecw:order:shipment:warehouse_update',
                ]"
              >
                <el-button type="text">{{ $t("仓库") }}</el-button>
                <el-dropdown-menu slot="dropdown">
                  <!-- 入仓操作 -->
                  <template v-if="include(scope.row.status, [0, 2]) || scope.row.inWarehouseState == 208">
                    <el-dropdown-item @click.native="$router.push('/order/warehousing?id=' + scope.row.orderId)" v-hasPermi="['ecw:order:warehouse_add']">{{ $t("入仓操作") }}</el-dropdown-item>
                  </template>
                  <!-- 入仓补充 -->
                  <template
                    v-if="scope.row.shipmentState > 0 && scope.row.inWarehouseState == 0"
                  >
                    <el-dropdown-item
                      @click.native="$router.push('/order/warehousing-add?shipment=1&id=' + scope.row.orderId)"
                      v-hasPermi="['ecw:order:shipment:warehouse_replenish']"
                    >{{ $t("入仓补充") }}</el-dropdown-item
                    >
                  </template>
                  <template
                    v-else-if="
                      include(
                        scope.row.inWarehouseState,
                        [201, 202, 202, 210, 202, 211, 202, 214, 215, 216]
                      ) && include(scope.row.status, [2, 3, 5, 10, 9, 8])
                    "
                  >
                    <el-dropdown-item
                      @click.native="
                        $router.push(
                          '/order/warehousing-add?id=' + scope.row.orderId
                        )
                      "
                      v-hasPermi="['ecw:order:warehouse_replenish']"
                      >{{ $t("入仓补充") }}</el-dropdown-item
                    >
                  </template>
                  <!-- 入仓修改 -->
                  <template
                    v-if="scope.row.shipmentState > 0 && scope.row.inWarehouseState == 0"
                  >
                    <el-dropdown-item
                      @click.native="$router.push('/order/warehousing-update?shipment=1&id=' + scope.row.orderId)"
                      v-hasPermi="['ecw:order:shipment:warehouse_update']"
                    >{{ $t("入仓修改") }}</el-dropdown-item
                    >
                  </template>
                  <template
                    v-else-if="
                      include(
                        scope.row.inWarehouseState,
                        [
                          201, 202, 207, 202, 209, 210, 202, 211, 202, 214, 215,
                          216, 204, 205,
                        ]
                      ) &&
                      scope.row.status != 11 &&
                      exclude(scope.row.shipmentState, [305, 307, 407])
                    "
                  >
                    <el-dropdown-item
                      @click.native="
                        $router.push(
                          '/order/warehousing-update?id=' + scope.row.orderId
                        )
                      "
                      v-hasPermi="['ecw:order:warehouse_update']"
                      :disabled2="scope.row.parentOrderId"
                      >{{ $t("入仓修改") }}</el-dropdown-item
                    >
                  </template>

                  <!-- 退仓 -->
                  <template v-if="(include(scope.row.inWarehouseState, [202, 210, 211, 214, 215, 216]) && exclude(scope.row.abnormalState, [1])) || include(scope.row.status, [16])">
                    <el-dropdown-item
                      @click.native="
                        show = true
                        orderId = scope.row.orderId
                      "
                      v-hasPermi="['ecw:order:warehouse_exit']"
                      >{{ $t("退仓") }}</el-dropdown-item
                    >
                  </template>

                  <!-- 调仓 -->
                  <template v-if="(include(scope.row.inWarehouseState, [202, 207, 209, 210, 202, 211, 212, 215, 216, 218]) || (include(scope.row.status, [16]) && exclude(scope.row.inWarehouseState, [213, 214]))) && exclude(scope.row.abnormalState, [1, 99, 2, 3, 4, 9, 10, 11, 12, 14])">
                    <el-dropdown-item
                      @click.native="
                        orderId = scope.row.orderId
                        warehouseBol = true
                      "
                      v-hasPermi="['ecw:order:warehouse_adjustment']"
                      >{{ $t("调仓") }}</el-dropdown-item
                    >
                  </template>

                  <!-- 取消调仓 -->
                  <!-- <template v-if="
                      include(scope.row.inWarehouseState, [212,213,214])
                    ">
                    <el-dropdown-item @click.native="$alert('// TODO')" >{{$t('取消调仓')}}</el-dropdown-item>
                  </template> -->

                  <!-- 调拨出仓 -->
                  <template v-if="include(scope.row.inWarehouseState, [213])">
                    <el-dropdown-item
                      @click.native="
                        $router.push({
                          path: '/order/transfer-warehousing/' + scope.row.orderId + '/' + 1
                        })
                      "
                      v-hasPermi="['ecw:order:warehouse_transfer']"
                      >{{ $t("调拨出仓") }}</el-dropdown-item
                    >
                  </template>

                  <!-- 调拨到仓 -->
                  <template v-if="include(scope.row.inWarehouseState, [214])">
                    <el-dropdown-item
                      @click.native="
                        $router.push({
                          path: '/order/transfer-to-warehouse/' + scope.row.orderId + '/' + 2
                        })
                      "
                      v-hasPermi="['ecw:order:warehouse_arrive']"
                      >{{ $t("调拨到仓") }}</el-dropdown-item
                    >
                  </template>

                  <!--开始备货-->
                  <!--需要异常处理后才能备货 https://zentao.test.jdshangmen.com/bug-view-4736.html-->
                  <template v-if="include(scope.row.airShipment, [2]) && scope.row.abnormalState === 0">
                    <el-dropdown-item
                      @click.native="
                        $router.push({
                          path: '/order/stocking?id=' + scope.row.orderId
                        })
                      "
                      v-hasPermi="['ecw:order:stocking']"
                      >{{ $t("开始备货") }}</el-dropdown-item
                    >
                  </template>
                  <!--修改备货-->
                  <template v-if="include(scope.row.airShipment, [3, 4, 10]) && scope.row.abnormalState === 0 && scope.row.status <= 5">
                    <el-dropdown-item
                      @click.native="
                        $router.push({
                          path: '/order/stocking?action=update&id=' + scope.row.orderId
                        })
                      "
                      v-hasPermi="['ecw:order:stocking_update']"
                      >{{ $t("修改备货") }}</el-dropdown-item
                    >
                  </template>
                </el-dropdown-menu>
              </el-dropdown>
            </template>

            <!-- <el-divider direction="vertical" v-if="scope.row.status != 0"></el-divider> -->
            <!--打印相关的-->
            <el-dropdown v-if="scope.row.status != 0" v-hasPermi="['ecw:order:print_tag', 'ecw:order:warehouse_receipt', 'ecw:order:landing_bill']">
              <el-button type="text">{{ $t("打印") }}</el-button>
              <el-dropdown-menu slot="dropdown">
                <!-- 打印标签 -->
                <template v-if="exclude(scope.row.status, [0]) && exclude(scope.row.abnormalState, [5, 6, 7, 8])">
                  <el-dropdown-item @click.native="printTag(scope.row)" v-hasPermi="['ecw:order:print_tag']">{{ $t("打印标签") }}</el-dropdown-item>
                </template>

                <!-- 打印入仓单 -->
                <template v-if="exclude(scope.row.status, [0, 2]) && exclude(scope.row.abnormalState, [5, 6, 7, 8])">
                  <el-dropdown-item @click.native="printWarehouseReceiptOrderId = scope.row.orderId" v-hasPermi="['ecw:order:warehouse_receipt']">{{ $t("打印入仓单") }}</el-dropdown-item>
                </template>

                <!-- 打印提单 -->
                <el-dropdown-item @click.native="printLadingBillOrderId = scope.row.orderId" :disabled="!scope.row.tidanNo" v-hasPermi="['ecw:order:landing_bill']">{{ $t("打印提单") }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

            <el-button type="text" @click="handleCopyOrder(scope.row.orderId)">{{ $t("复制") }}</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows" @pagination="getList" />

    <special-needs :orderNo="orderNo" :show.sync="isShow" :currency="JSON.stringify(currencyList)" :order-id="orderId" @determine="getList"></special-needs>
    <print-tag v-if="printTagOrderId !== null" :order-id="printTagOrderId" @close="printTagOrderId = null" :warehouse-in-num="printTagWarehouseInNum" />
    <print-warehouse-receipt v-if="printWarehouseReceiptOrderId !== null" :order-id="printWarehouseReceiptOrderId" @close="printWarehouseReceiptOrderId = null" />
    <print-lading-bill v-if="printLadingBillOrderId !== null" :order-id="printLadingBillOrderId" @close="printLadingBillOrderId = null" />
    <batch-pickup v-if="showBatchPickup" @close="onBatchClose" @success="onBatchClose" />
    <withdrawal v-if="show" :dialog-visible="show" :orderId="orderId"></withdrawal>
    <batch-single-application @getList="getList" :order-list="orderId" :dialog-visible.sync="warehouseBol"></batch-single-application>
    <fee-application v-if="feeApplicationBol" :order-id="orderId" :currencys="JSON.stringify(currencyList)" :dialog-visible.sync="feeApplicationBol "@refresh="getList"></fee-application>
    <merge-log :order-no="showMergedLogOrderNo" v-if="showMergedLogOrderNo !== null" @close="showMergedLogOrderNo = null" />
    <pickup-log v-if="showPickupLogOrderNo" :order-no="showPickupLogOrderNo" @close="showPickupLogOrderNo = null" @delete="getList" />
    <SplitRevoke
      v-if="splitRevokeOrderId"
      :order-id="splitRevokeOrderId"
      @close="
        splitRevokeOrderId = null
        getList()
      "
    ></SplitRevoke>
    <turn-exception v-if="!!tureExceptionOrder" ref="turnException" :order-no="tureExceptionOrder.orderNo" :order-id="tureExceptionOrder.orderId" @done="handleTurnExceptionDone" @cancel="handleExceptionClose"></turn-exception>
  </div>
</template>

<script>
//图片上传组件 lanbm 2024-06-19 add
import imageUpload from "@/components/ImageUpload"
import Selector from "@/components/Selector"
import ProductSelector from "@/components/ProductSelector"
import { getProductAttrList } from "@/api/ecw/productAttr"
import CustomerSelector from "@/components/CustomerSelector"
import specialNeeds from "@/views/ecw/order/components/specialNeeds"
import { createOrder, updateOrder, deleteOrder, getOrder, getOrderPage, exportOrderExcel, orderSpecialNeed, cancelOrder, recoveryOrder, getMyOrderPage, deptOrderPage, orderStatistics, orderMyStatistics, orderDeptStatistics, orderExportSearch, orderExportMySearch, orderExportDeptSearch, exportAbnormal, exportHeavyOrder, exportReturnOrder, exportSaleRepay, exportCustomsDatas, exportShippingDatas, exportShipFee, exportUnload, splitCancelApply, orderSplitRevoke, setCanShipment, setCanNotShipment, getParentOrder, getRegionList, copyOrder } from "@/api/ecw/order"
/* import { getDictDatas, DICT_TYPE } from '@/utils/dict'; */
import PrintTag from "./components/PrintTag"
import PrintWarehouseReceipt from "./components/PrintWarehouseReceipt"
import PrintLadingBill from "./components/PrintLadingBill"
import BatchPickup from "./components/BatchPickup"
import withdrawal from "@/views/ecw/order/withdrawal"
import UserSelector from "@/components/UserSelector"
import BatchSingleApplication from "@/views/ecw/order/batchSingleApplication"
import FeeApplication from "@/views/ecw/order/feeApplication"
import MergeLog from "@/views/ecw/order/components/MergeLog"
import PickupLog from "./components/PickupLog"
import { getWarehouseList } from "@/api/ecw/warehouse"
import { getCurrencyPage } from "@/api/ecw/currency"
import SplitRevoke from "@/views/ecw/order/components/SplitRevoke"
import { getChannelList } from "@/api/ecw/channel"
import Template from "@/views/cms/template/index.vue"
import { getDictDatas } from "@/utils/dict"
import TurnException from "@/views/ecw/order/components/TurnException.vue"
export default {
  name: "EcwOrderIndex",
  components: {
    TurnException,
    Template,
    UserSelector,
    FeeApplication,
    BatchSingleApplication,
    MergeLog,
    PickupLog,
    SplitRevoke,
    CustomerSelector,
    ProductSelector,
    Selector,
    specialNeeds,
    PrintTag,
    PrintWarehouseReceipt,
    PrintLadingBill,
    BatchPickup,
    withdrawal,
    imageUpload //图片上传组件
  },
  props: {
    mine: Boolean, // 标识我的订单列表
    dept: Boolean // 标识部门订单列表
  },
  data() {
    return {
      AddressCity: [],
      AddressProvince: [],
      AddressTown: [],
      destCountryId: null,
      objectiveId: null,
      destWarehouseId: null,
      // 选中数组
      ids: [],
      //目的国
      countryList: [],
      //目的城市
      cityList: [],
      //目的仓
      destWarehouseList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 订单列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        rows: 10,
        packageTypeArr: [],
        channelIds: [],
        goodsTypes: []
      },
      warehouseList: [],
      //tradeCityList: [],
      productAttrList: [], // 商品属性
      molecule: "", //重货比分子
      denominator: "", //重货比分母
      dateFilterType: "", //日期筛选类别
      dateFilter: [], //筛选日期
      errorShow: false, //是否显示转异对话框 lanbm 2024-06-19 add
      printTagOrderId: null, // 显示打印标签的订单ID
      printTagWarehouseInNum: 0, // 打印标签的订单入仓箱数
      printWarehouseReceiptOrderId: null, // 打印入仓单的订单ID
      printLadingBillOrderId: null, // 打印提单的订单ID
      showBatchPickup: false, // 是否显示批量提货弹窗
      showMergedLogOrderNo: null, // 显示合单日志订单号
      showPickupLogOrderNo: null, // 显示提货日志的订单号
      isShow: false, //特殊显示
      orderId: undefined,
      adjustmentList: [],
      show: false,
      warehouseBol: false, //调仓申请
      feeApplicationBol: false, //费用申请
      multipleSelection: [],

      transportId: null, // 指定运输方式
      transportList: [],
      orderNo: "",
      params: {
        page: 1,
        rows: 20
      },
      currencyList: [],
      statistics: null, // 统计数据

      splitRevokeOrderId: null, // 撤销拆单的订单ID
      // 渠道列表，空运需要渠道筛选
      channelList: [],
      // 编号搜索条件
      noParam: {
        key: "numberKey",
        value: ""
      },
      // 商品搜索条件
      prodParam: {
        key: "prodKey",
        value: ""
      },
      // 当前操作转异的订单
      tureExceptionOrder: null,
      pickRatio: {
        key: "eqPickRatio",
        value: ""
      }
    }
  },
  watch: {
    isChinese() {
      this.getList()
    },
    // provinceCode destCountryId

    destCountryId: {
      //监听当前地区值的变化，于与上方地区值进行了双向绑定
      deep: true, //深度监听
      handler() {
        //每当值省份值改变时其下地区值进行清空
        this.AddressCity = []
        this.AddressTown = []
        this.objectiveId = ""
        this.destWarehouseId = ""
        this.findByprovinceCode()
        if (this.destCountryId == "") {
          getRegionList(4, 4)
            .then(({ data }) => {
              this.AddressCity = data
            })
            .catch((error) => {
              console.log(error)
            })

          getRegionList(5, 5)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          getRegionList(2, this.destCountryId)
            .then(({ data }) => {
              this.AddressCity = data
            })
            .catch((error) => {
              console.log(error)
            })
          getRegionList(5, 5)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        }
        //重新加载目的城市
        //目的城市

        //  getRegionList(4, 4).then(({data}) => {
        //     this.AddressCity = data;
        // })
        //  .catch(error => {
        //     console.log(error);
        //   });

        //   getRegionList(5, 5).then(({data}) => {
        //   this.AddressTown = data;
        // })
        //   .catch(error => {
        //     console.log(error);
        //   });
      }
    },
    objectiveId: {
      deep: true, //深度监听
      handler() {
        this.AddressTown = []
        this.destWarehouseId = ""
        this.findBycityCode()

        if (this.objectiveId != "" && this.destCountryId != "" && this.destWarehouseId == "") {
          //获取当前城市值id，获取该城市下区域
          getRegionList(3, this.objectiveId)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        } else if (this.destCountryId == "" && this.objectiveId == "" && this.destWarehouseId == "") {
          getRegionList(5, 5)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          getRegionList(2, this.destCountryId)
            .then(({ data }) => {
              this.AddressCity = data
            })
            .catch((error) => {
              console.log(error)
            })
          getRegionList(5, 5)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        }
        // else if(this.objectiveId!="" && this.objectiveId=="" ){
        //   getRegionList(5, 5).then(({data}) => {
        // this.AddressTown = data;

        // }).catch(error => {
        //   console.log(error);
        // });
        // }
      }
    },
    destWarehouseId: {
      deep: true, //深度监听
      handler() {
        if (this.objectiveId != "" && this.destCountryId != "" && this.destWarehouseId == "") {
          //获取当前城市值id，获取该城市下区域
          getRegionList(3, this.objectiveId)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          getRegionList(5, 5)
            .then(({ data }) => {
              this.AddressTown = data
            })
            .catch((error) => {
              console.log(error)
            })
        }
        //   else if(this.objectiveId=="" && this.destWarehouseId==""){
        //     getRegionList(5, 5).then(({data}) => {
        //      this.AddressTown = data;
        // })
        //   .catch(error => {
        //     console.log(error);
        //   });
        //   }
      }
    }
  },
  computed: {
    // 导出的权限字符串
    exportPermiString() {
      let arr = ["ecw:order:export"]
      if (this.mine) arr.push("my")
      if (this.dept) arr.push("dept")
      if (this.transportId) arr.push(this.transportId)
      return arr.join(":")
    },
    // 是否全部订单
    isAll() {
      return !(this.mine || this.dept || this.transportId)
    },
    isChinese() {
      return this.$i18n.locale === "zh_CN"
    },
    exportWarehouseList() {
      /* tradeType 1 进口，2出口，3进出口 */
      return this.warehouseList.filter((item) => item.tradeType == 2 || item.tradeType == 3)
    },

    // importWarehouseList(){
    //   return this.warehouseList.filter(item => item.tradeType == 1 || item.tradeType == 3)
    // },
    importCountryList() {
      return this.countryList.filter((item) => item.id !== null)
    },
    importCityList() {
      return this.cityList.filter((item) => item.id !== null)
    },
    importWarehouseList() {
      return this.destWarehouseList.filter((item) => item.id !== null)
    },
    /* exportCityList() {
      return this.tradeCityList.filter(item => item.type == 2)
    },
    importCityList() {
      return this.tradeCityList.filter(item => item.type == 1)
    }, */
    combinedQueryParams() {
      let timeParams = {}
      if (this.dateFilterType && this.dateFilter) {
        timeParams["begin" + this.dateFilterType] = this.dateFilter[0]
        timeParams["end" + this.dateFilterType] = this.dateFilter[1]
      }

      let queryParams = Object.assign({}, this.queryParams, timeParams)
      if (this.transportId) {
        queryParams.transportId = this.transportId
      }
      if (this.noParam.value) {
        queryParams[this.noParam.key] = this.noParam.value
      }
      if (this.prodParam.value) {
        queryParams[this.prodParam.key] = this.prodParam.value
      }
      //目的国
      if (this.destCountryId != null && this.destCountryId != "") {
        queryParams.destCountryIds = this.destCountryId
      }
      //目的城市
      if (this.objectiveId != null && this.objectiveId != "") {
        queryParams.objectiveIds = this.objectiveId
      }
      //目的仓
      if (this.destWarehouseId != null && this.destWarehouseId != "") {
        queryParams.destWarehouseIds = this.destWarehouseId
      }
      // 提货率
      if (this.pickRatio.value) {
        queryParams[this.pickRatio.key] = this.pickRatio.value
      }
      if (queryParams.statusList?.length) {
        queryParams.statusString = queryParams.statusList.join(",")
      }
      delete queryParams.statusList
      return queryParams
    },
    /*batchWarehouseAdjustment(){
      return  this.multipleSelection.length > 0 && this.multipleSelection.every(e => e.status === 5)
    },*/
    include() {
      return (state, arr) => {
        return arr.indexOf(state) > -1
      }
    },
    exclude() {
      return (state, arr) => {
        return arr.indexOf(state) == -1
      }
    },
    // 增值服务文本
    getTypeText() {
      return (type) => {
        if (!type) return ""
        const arr = []
        if (type.indexOf("1") > -1) {
          arr.push(this.$t("集运"))
        }
        if (type.indexOf("2") > -1) {
          arr.push(this.$t("海外仓"))
        }
        return arr.join(",")
      }
    }
  },
  activated() {
    this.getList()
  },
  created() {
    this.init() //
    this.getTransportFromRoute()
    this.getList()
    getProductAttrList().then((res) => (this.productAttrList = res.data))
    //getTradeCityList().then(res => this.tradeCityList = res.data)
    getWarehouseList().then((res) => {
      this.tradeCityList = res.data
      this.warehouseList = res.data
    })

    getCurrencyPage(this.params).then((res) => (this.currencyList = res.data.list))
    // 如果是空运(专线空运和海空联运)则获取渠道
    //if (this.transportId == 3 || this.transportId == 4) {
    getChannelList().then((res) => (this.channelList = res.data))
    //}
  },
  methods: {
    init() {
      //加载时发起请求获取所有省份值
      getRegionList(1, 1)
        .then(({ data }) => {
          this.AddressProvince = data
          console.log(this.AddressProvince)
        })
        .catch((error) => {
          console.log(error)
        })
      //目的城市
      getRegionList(4, 4)
        .then(({ data }) => {
          this.AddressCity = data
        })
        .catch((error) => {
          console.log(error)
        })
      //目的仓
      getRegionList(5, 5)
        .then(({ data }) => {
          this.AddressTown = data
        })
        .catch((error) => {
          console.log(error)
        })
    },
    findByprovinceCode() {
      //获取当前省份值id，获取该省份下城市 destCountryId provinceCode

      getRegionList(2, this.destCountryId)
        .then(({ data }) => {
          this.AddressCity = data
        })
        .catch((error) => {
          console.log(error)
        })
    },
    findBycityCode() {
      //获取当前城市值id，获取该城市下区域
      getRegionList(3, this.objectiveId)
        .then(({ data }) => {
          this.AddressTown = data

          // 去重
          // let uniqueDataList = data.filter((item, index, self) => {
          // // 返回第一个匹配项的索引，用于判断当前项是否为第一个匹配项
          // const firstIndex = self.findIndex((obj) => obj.guojia === item.guojia);

          // // 如果当前项是第一个匹配项，则保留，否则过滤掉
          // return index === firstIndex;
          // });

          // this.AddressProvince = uniqueDataList
        })
        .catch((error) => {
          console.log(error)
        })
    },
    getDictDatas,

    // 取消拆单申请
    splitRevoke(row) {
      this.splitRevokeOrderId = row.orderId
    },
    // 获得导出函数
    getExportFunc() {
      let func = orderExportSearch
      if (this.mine) func = orderExportMySearch
      if (this.dept) func = orderExportDeptSearch
      return func
    },
    // 导出勾选
    exportChecked() {
      if (!this.ids.length) {
        return this.$message.error(this.$t("请勾选需要导出的订单"))
      }
      return this.exportExcel(this.getExportFunc(), { orderIdList: this.ids }, this.$t("导出勾选"))
    },
    // 导出搜索
    exportSearch() {
      return this.exportExcel(this.getExportFunc(), this.combinedQueryParams, this.$t("导出搜索"))
    },
    // 导出异常单
    exportAbnormal() {
      return this.exportExcel(exportAbnormal, this.combinedQueryParams, this.$t("异常单统计"))
    },
    // 重货单统计
    exportHeavyOrder() {
      return this.exportExcel(exportHeavyOrder, this.combinedQueryParams, this.$t("重货单统计"))
    },
    // 退仓单统计
    exportReturnOrder() {
      return this.exportExcel(exportReturnOrder, this.combinedQueryParams, this.$t("退仓单统计"))
    },
    // 售后赔偿金额统计
    exportSaleRepay() {
      return this.exportExcel(exportSaleRepay, this.combinedQueryParams, this.$t("售后赔偿金额统计"))
    },
    // 报关数据统计
    exportCustomsDatas() {
      return this.exportExcel(exportCustomsDatas, this.combinedQueryParams, this.$t("报关数据统计"))
    },

    // 客户出货量统计
    exportShippingDatas() {
      return this.exportExcel(exportShippingDatas, this.combinedQueryParams, this.$t("客户出货量统计"))
    },

    // 预付运费统计
    exportShipFee() {
      return this.exportExcel(exportShipFee, this.combinedQueryParams, this.$t("预付运费统计"))
    },

    // 卸货费统计
    exportUnload() {
      return this.exportExcel(exportUnload, this.combinedQueryParams, this.$t("卸货费统计"))
    },
    // 通用导出函数
    exportExcel(func, params, fileName = null) {
      this.exportLoading = true
      func(params)
        .then((res) => {
          if (!fileName) {
            fileName = this.$t("订单")
          }
          this.$message.success(this.$t("已加入导出队列，请稍后在下载日志中下载"))
          // this.$download.excel(res, fileName + '.xls');
        })
        .finally(() => {
          this.exportLoading = false
        })
    },
    // 提取路径中的运输方式
    getTransportFromRoute() {
      let match = this.$route.path.match(/transport_(\d)/)
      if (!match) return
      this.transportId = match[1]
    },
    oprateOrder(orderId, type) {
      let actions = {
        cancelOrder: {
          callable: cancelOrder,
          confirm: this.$t("确定要取消此订单么？")
        },
        recoveryOrder: {
          callable: recoveryOrder,
          confirm: this.$t("确定要恢复此订单么？")
        },
        deleteOrder: {
          callable: deleteOrder,
          confirm: this.$t("确定要删除此订单么？")
        }
      }
      let action = actions[type]
      if (!action) {
        return this.$alert("不支持此操作")
      }
      this.$confirm(action.confirm)
        .then(() => {
          return action.callable(orderId)
        })
        .then(() => {
          this.getList()
        })
    },

    /** 查询列表 */
    getList() {
      this.loading = true

      const query = { ...this.combinedQueryParams }
      if (query.packageTypeArr && query.packageTypeArr.length) {
        query.packageType = query.packageTypeArr.join(",")
      }
      let func = getOrderPage

      if (this.mine) {
        func = getMyOrderPage
        /* return getMyOrderPage(this.combinedQueryParams).then(response => {
          this.list = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }); */
      } else if (this.dept) {
        func = deptOrderPage
      }
      // 执行查询
      func(query).then((response) => {
        // 部分情况下，订单后面的操作下拉菜单会显示按钮，但是下来没有选项，在elTable组件更新的时候会导致渲染错误，所以要在更新渲染前清空一次list让table彻底重新渲染，避免部分更新导致异常
        this.list = []
        this.$nextTick(() => {
          this.list = response.data.list
        })
        this.total = response.data.total
        this.loading = false
      })

      this.getStatistics()
    },
    // 获得统计数据
    getStatistics() {
      let func = orderStatistics
      if (this.mine) {
        func = orderMyStatistics
      } else if (this.dept) {
        func = orderDeptStatistics
      }
      const query = { ...this.combinedQueryParams }
      if (query.packageTypeArr && query.packageTypeArr.length) {
        query.packageType = query.packageTypeArr.join(",")
        delete query.packageTypeArr
      }
      func(query).then((res) => {
        this.statistics = res.data
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1

      this.$nextTick(this.getList)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        rows: 10,
        packageTypeArr: [],
        channelId: "",
        goodsTypes: [],
        channelIds: []
      }
      this.destCountryId = null
      this.destWarehouseId = null
      this.objectiveId = null
      this.pickRatio.value = ""
      this.noParam.value = ""
      this.prodParam.value = ""
      this.dateFilter = []
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push("create?transportType=" + this.transportId)
    },
    /** 修改按钮操作, updateChannel表示变更出货渠道 */
    handleUpdate(row, updateChannel = false) {
      let url = "edit?id=" + row.orderId
      if (updateChannel) {
        url += "&updateChannel=1"
      }
      this.$router.push(url)
    },

    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      // 执行导出
      this.$modal
        .confirm(this.$t("是否确认导出所有订单数据项?"))
        .then(() => {
          this.exportLoading = true
          return exportOrderExcel(this.combinedQueryParams)
        })
        .then((response) => {
          this.$download.excel(response, "${table.classComment}.xls")
          this.exportLoading = false
        })
        .catch(() => {})
    },
    // 表格多选
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.ids = selection.map((item) => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleEdit() {
      this.warehouseBol = true
      this.orderId = this.ids.join(",")
    },
    moleculeChange() {},
    denominatorChange() {},
    specialRendering(val) {
      console.log("val", val)
      if (val !== undefined) {
        let i = val.split(",")
        return this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS)
          .filter((e) => {
            return i.indexOf(e.value) > -1
          })
          .map((item) => {
            // 打字开头的用最后一个字，否则取第一个字
            item.symbol = item.label[0] == "打" ? item.label[item.label.length - 1] : item.label[0]
            return item
          })
      }
    },
    deleteSpecial(id, orderId) {
      this.$confirm(this.$t("确定删除此特需么?"))
        .then(() => {
          return orderSpecialNeed({ orderId: orderId, advanceType: id })
        })
        .then(() => {
          this.getList()
        })
    },
    onBatchClose() {
      this.showBatchPickup = false
      this.handleQuery()
    },
    // 打印标签
    printTag(order) {
      this.printTagOrderId = order.orderId
      this.printTagWarehouseInNum = order.sumNum
    },
    // 过滤订单状态筛选字典内容
    statusDictFilter(item) {
      if (this.transportId == 3 && item.cssClass && item.cssClass != "air") {
        return false
      }
      if (this.transportId == 1 && item.cssClass && item.cssClass != "sea") {
        return false
      }
      if (this.transportId == 4 && item.cssClass && item.cssClass != "sea-air") {
        return false
      }
      return true
    },
    // 设置空运订单不可出
    async setCanNotShipment(order) {
      await this.$confirm(this.$t("确定设置订单{orderNo}不可出么？", { orderNo: order.orderNo }))
      setCanNotShipment(order.orderId).then((res) => {
        this.$message(this.$t("操作成功"))
        this.getList()
      })
    },
    // 查看母订单
    showParentOrder(row) {
      getParentOrder(row.orderId).then((res) => {
        this.$router.push("./detail?orderId=" + res.data.orderId)
      })
    },
    oprateOrder2(row, type) {
      //lanbm 2024-06-19 添加的转异功能
      this.order.orderNo = row.orderNo
      this.errorShow = true
    },
    async handleException(order) {
      this.tureExceptionOrder = order
      await this.$nextTick()
      this.$refs.turnException?.show()
    },
    handleTurnExceptionDone() {
      this.tureExceptionOrder = null
      this.getList()
    },
    handleExceptionClose() {
      this.tureExceptionOrder = null
    },
    // 复制订单
    handleCopyOrder(orderId) {
      copyOrder(orderId).then((res) => {
        this.$router.push({ path: "/order/edit", query: { id: res.data } })
      })
    },
    // 查看异常
    openException(order) {
      this.$router.push({
        path: "./pending?id=" + order.orderId
      })
    },
    // 自动去除空格
    replaceSpace(obj, field) {
      obj[field] = obj[field].replace(/\s+/g, "")
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .actions {
  .el-dropdown {
    margin-right: 10px;
    &:last-child {
      margin-right: 0;
    }
  }
}
</style>
