<template>
  <div v-if="show" class="app-container">
    <el-card class="card">
      <div slot="header" class="card-title">
        {{ $t('orderdetail.orderNo') }}：{{ order.orderNo }}
        <template v-if="order.tidanNo"> - {{ order.tidanNo }}</template>
        <template v-else-if="order.containerNumber"> - {{ order.containerNumber }}</template>
      </div>

      <el-row :gutter="10">
        <el-col :span="12">
          <!--发货人-->
          <div style="display: flex;">
            <div style="width: 6px;height: 26px;background: #659FD5;border-radius: 0px 6px 6px 0px;" />
            <span style="font-size: 18px;font-weight: 500;color: #333;line-height: 26px;margin-left: 5px;">{{ $t('orderdetail.consignorName') }}</span>
          </div>
          <el-descriptions class="margin-top" border :column="2">
            <el-descriptions-item :label="$t('orderdetail.consignorName')" label-style="width:120px">{{ order.consignorVO.name }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.consignorPhone')" label-style="width:120px">+{{ order.consignorVO.countryCode }} {{ order.consignorVO.phone }}</el-descriptions-item>
          </el-descriptions>
          <el-descriptions v-if="showMore" border :column="3" :content-style="{width:'100px'}">
            <el-descriptions-item :label="$t('orderdetail.consignorNameEn')" label-style="width:120px">{{ order.consignorVO.nameEn }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.consignorCompany')" label-style="width:120px">
              {{ order.consignorVO.company }}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.consignorCompanyEn')" label-style="width:120px">
              {{ order.consignorVO.companyEn }}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.consignorEmail')" label-style="width:120px">{{ order.consignorVO.email }}</el-descriptions-item>
          </el-descriptions>
        </el-col>
        <el-col :span="12">
          <!--收货人-->
          <div style="display: flex;">
            <div class="flex-1 flex">
              <div style="width: 6px;height: 26px;background: #659FD5;border-radius: 0px 6px 6px 0px;" />
              <span style="font-size: 18px;font-weight: 500;color: #333;line-height: 26px;margin-left: 5px;">{{ $t('orderdetail.consigneeName') }}</span>
            </div>
            <span style="color:#409EFF;margin-left:100px;font-size:16px" @click="consigneeChange">{{ consigneeText }}</span>
          </div>
          <el-descriptions class="margin-top" border :column="2">
            <el-descriptions-item :label="$t('orderdetail.consigneeName')" label-style="width:120px">{{ consigneeVO.name }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.consigneePhone')" label-style="width:120px">
              <template v-if="consigneeVO.countryCode">
                +{{ consigneeVO.countryCode }}
              </template>
              {{ consigneeVO.phone }}
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions class="margin-top" border :column="3">
            <el-descriptions-item :label="$t('delivery.harvestMethod')" label-style="width:120px">{{consigneeVO?(consigneeVO.harvestMethod==1?$t('orderdetail.own'):$t('orderdetail.toRoom')):''}}</el-descriptions-item>
            <el-descriptions-item :label="$t('delivery.deliveryaddress')" label-style="width:120px">{{ addressName }}</el-descriptions-item>
            <el-descriptions-item :label="$t('delivery.addressdetail')" label-style="width:150px">{{consigneeVO?consigneeVO.address:''}}</el-descriptions-item>
            <template v-if="showMore">
              <el-descriptions-item :label="$t('orderdetail.consigneeNameEn')" label-style="width:120px">{{ consigneeVO.nameEn }}</el-descriptions-item>
              <el-descriptions-item :label="$t('公司中文名称')" label-style="width:120px">
                {{ consigneeVO.company }}
              </el-descriptions-item>
              <el-descriptions-item :label="$t('orderdetail.consigneeCompanyEn')" label-style="width:120px">
                {{ consigneeVO.companyEn }}
              </el-descriptions-item>
              <el-descriptions-item :label="$t('orderdetail.consigneeEmail')" label-style="width:120px">{{ consigneeVO.email }}</el-descriptions-item>
            </template>
          </el-descriptions>
        </el-col>
      </el-row>
    </el-card>

    <!--运输-->
    <el-card class="card">
      <div style="display: flex;margin-top: 20px;">
        <div style="width: 6px;height: 26px;background: #659FD5;border-radius: 0px 6px 6px 0px;" />
        <span style="font-size: 18px;font-weight: 500;color: #333;line-height: 26px;margin-left: 5px;">{{ $t('orderdetail.transportInfo') }}</span>
      </div>
      <el-row>
        <el-col>
          <el-descriptions class="margin-top" border :column="5">
            <el-descriptions-item :label="$t('orderdetail.startTitle')">{{ $l(order.initialLogisticsInfoDto, 'startTitle') }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.destTitle')">{{ $l(order.initialLogisticsInfoDto, 'destCountryTitle') }}-{{ $l(objectCity, 'title') }}-{{ $l(order.initialLogisticsInfoDto, 'destTitle') }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.transport')" :span="1">
              <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="order.transportId" />
            </el-descriptions-item>
            <el-descriptions-item v-if="getDictData(DICT_TYPE.ECW_TRANSPORT_TYPE, order.transportId).cssClass == 'channel'" :label="$t('orderdetail.channel')" :span="1">{{ getChannelNameById(order.channelId) }}</el-descriptions-item>
            <el-descriptions-item  v-if="order.type" :label="$t('服务')">{{ typeName }}</el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>

      <!--基础-->
      <div style="display: flex;margin-top: 20px;">
        <div style="width: 6px;height: 26px;background: #659FD5;border-radius: 0px 6px 6px 0px;" />
        <span style="font-size: 18px;font-weight: 500;color: #333;line-height: 26px;margin-left: 5px;">{{ $t('orderdetail.baseInfo') }}</span>
      </div>
      <el-descriptions class="margin-top" border :column="2">
        <el-descriptions-item :label="$t('orderdetail.marks')">{{ order.marks }}</el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.costVO')">
          {{ order.costVO.totalNum }}{{ $t('orderdetail.box') }} {{ order.costVO.totalWeight }}Kg {{ order.costVO.totalVolume }}m³ {{ order.costVO.totalQuantity }}{{ $t('price.one') }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.warehouseNum')">
          {{ order.sumNum }}{{ $t('orderdetail.box') }} {{ order.vweight }}Kg {{ order.sumVolume }}m³ {{ order.sumQuantity }}{{ $t('price.one') }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.entry')">
          {{ order.sumNum }}{{ $t('orderdetail.box') }} {{ order.vweight }}Kg {{ order.wvolume }}m³ {{ order.sumQuantity }}{{ $t('price.one') }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('prepayDeal.drawee')">
          <span  v-if="order.drawee==1">{{ $t('orderdetail.consignor') }}</span>
          <span  v-else-if="order.drawee==2">{{ $t('orderdetail.consignee') }}</span>
          <el-button type="text" v-else @click="showDraweeDialog=true">{{$t('自定义')}}</el-button>
        </el-descriptions-item>

        <!--单证报关-->
        <el-descriptions-item :label="$t('orderdetail.customsType')">
          <dict-tag :type="DICT_TYPE.ECW_CUSTOMS_TYPE" :value="order.customsType" />
        </el-descriptions-item>

        <el-descriptions-item :label="$t('orderdetail.isCargoControl')">{{ order.isCargoControl?$t('orderdetail.is'):$t('orderdetail.no') }}</el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.objectport')" v-if="[3, 4].indexOf(+order.transportId) > -1">
          {{ order.productRecord==1? $t('orderdetail.ourUndertakes'):$t('orderdetail.customerUndertakes')}}
        </el-descriptions-item>
        <el-descriptions-item v-else label="">
          <!--占位-->
        </el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.packageType')">
          <template v-if="order.packageType">
            <dict-tag v-for="packageType in order.packageType.split(',').filter(item => !!item)" :key="packageType" class="mr-10" :type="DICT_TYPE.ORDER_SPECIAL_NEEDS" :value="packageType" />
          </template>
        </el-descriptions-item>
        <el-descriptions-item :label="$t('orderdetail.packageRemarks')">
          {{ order.packageRemarks }}
        </el-descriptions-item>
        <template v-if="showMore">
          <el-descriptions-item :label="$t('orderdetail.deliveryDate')">
            {{ order.deliveryDate }}
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.warehouseType')">
            <dict-tag :type="DICT_TYPE.ECW_WAREHOUSING_TYPE" :value="order.warehouseType" />
          </el-descriptions-item>

          <!--下面几个是空运特有字段-->
          <!--清关证书-->
          <el-descriptions-item v-if="[3, 4].indexOf(+order.transportId) > -1" :label="$t('delivery.customsClearCert')">{{ order.isSingleTicketTransport?$t('orderdetail.is'):$t('orderdetail.no') }}</el-descriptions-item>
          <!--清关证书备注-->
          <el-descriptions-item v-if="[3, 4].indexOf(+order.transportId) > -1" :label="$t('delivery.clearCertRemark')">
            {{ order.clearCertRemark }}
          </el-descriptions-item>
          <!--是否拆包-->
          <el-descriptions-item v-if="[3, 4].indexOf(+order.transportId) > -1" :label="$t('delivery.isUnpack')">
            {{ order.isUnpack?$t('orderdetail.is'):$t('orderdetail.no') }}
          </el-descriptions-item>
          <!--单票立刻转运-->
          <el-descriptions-item v-if="[3, 4].indexOf(+order.transportId) > -1" :label="$t('delivery.isSingleTicketTransport')">
            {{ order.isSingleTicketTransport?$t('orderdetail.is'):$t('orderdetail.no') }}
          </el-descriptions-item>

          <el-descriptions-item :label="$t('orderdetail.isCollection')">
            <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="order.isCollection" />
            <template v-if="order.isCollection == 1">({{order.collectionProxy}}{{currencyMap[order.collectionProxyCurrency]}})</template>
          </el-descriptions-item>
          <el-descriptions-item :label="$t('delivery.displayBillLading')">
            {{order.displayBillLadingPrice ? $t('orderdetail.is'):$t('orderdetail.no')}}
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.warehouseName')">
            {{order.isExternalWarehouse ? $t('orderdetail.externalWarehouse') : $t('orderdetail.ownWarehouse') }}
            <template v-if="order.isExternalWarehouse" v-for="(item, index) in order.externalWarehouseDtoList" >
              <div v-if="item.estLoadingTime || item.loadingAddress" :key="index">
                {{$t('orderdetail.estLoading')}}： {{item.estLoadingTime}}
                {{$t('orderdetail.loadingAddress')}}：{{item.loadingAddress}}
              </div>
            </template>
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.expressNO')">
            {{order.number}}
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.creator')">
            {{order.creatorName}} （{{order.userType == 1 ? $t('orderdetail.member') : $t('orderdetail.admin')}}）
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.createTime')">
            {{order.createTime|parseTime}}
          </el-descriptions-item>
          <el-descriptions-item :label="$t('orderdetail.customerService')">
            {{order.salesmanName}}
          </el-descriptions-item>
        </template>
      </el-descriptions>

      <!--<div v-if="[3, 4].indexOf(+order.transportId) > -1" style="display: flex;margin-top: 20px;">
        <div style="width: 6px;height: 26px;background: #659FD5;border-radius: 0px 6px 6px 0px;" />
        <span style="font-size: 18px;font-weight: 500;color: #333;line-height: 26px;margin-left: 5px;">{{ $t('orderdetail.transportInfo') }}</span>
      </div>-->
      <!--下面字段在原型上没有体现，暂时不显示-->
      <el-row v-if="false">
        <el-col>
          <el-descriptions class="margin-top" border :column="2">
            <el-descriptions-item :label="$t('orderdetail.deliveryDate')">{{ order.deliveryDate }}</el-descriptions-item>
            <el-descriptions-item :label="$t('orderdetail.warehouseType')">
              <dict-tag :type="DICT_TYPE.ECW_WAREHOUSING_TYPE" :value="order.warehouseType" />
            </el-descriptions-item>

             <el-descriptions-item :label="$t('orderdetail.isCollection')">
               <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="order.isCollection" />
               <span v-if="order.isCollection">({{ order.collectionProxy }} {{ currencyMap[order.collectionProxyCurrency] }})</span>
             </el-descriptions-item>
             <el-descriptions-item :label="$t('orderdetail.tiedanPrice')">
               {{ order.displayBillLadingPrice?$t('orderdetail.is'):$t('orderdetail.no') }}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('orderdetail.warehouseName')" v-if="order.isExternalWarehouse&&order.externalWarehousedtolist.length>0">
               <div>{{$t('orderdetail.externalWarehouse')}}</div>
               <div>{{$t('orderdetail.estLoading')}}:{{orderData.externalWarehousedtolist[0].estLoadingtime}}</div>
               <div>{{$t('orderdetail.loadingAddress')}}:{{orderData.externalWarehousedtolist[0].loadingAddress}}</div>
             </el-descriptions-item>
             <el-descriptions-item :label="$t('delivery.number')">
               {{ order.number }}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('orderdetail.creator')">
               {{order.creator}}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('bannerdetail.time')">
               {{ order.createTime }}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('orderdetail.customerManage')">
               {{ order.salesmanName }}
             </el-descriptions-item>
<!--            <el-descriptions-item :label="$t('delivery.doubleClear')">
              <dict-tag :type="DICT_TYPE.ECW_DOUBLE_CLEAR" :value="order.doubleClear" />
            </el-descriptions-item>
            <el-descriptions-item :label="$t('delivery.airlineCompany')">{{ order.airlineCompany }}</el-descriptions-item> -->
          </el-descriptions>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="card">
      <el-tabs v-model="activeName">
        <el-tab-pane :label="$t('orderdetail.activeFirst')" name="first">
          <el-table
              :data="order.orderItemVOList"
              border
              style="width: 100%"
              show-summary
              :summary-method="getSummary"
          >
            <el-table-column :label="$t('序号')" type="index"></el-table-column>
            <el-table-column prop="prodTitle" :label="$t('orderdetail.prodTitle')">
              <template slot-scope="{row}">
                <template >{{ row.prodTitleZh }}/{{row.prodTitleEn}}</template>
              </template>
            </el-table-column>
            <el-table-column prop="brand" :label="$t('orderdetail.brand')">
              <template slot-scope="{row}">
                <template v-if="row.brandName">{{ row.brandName }}</template>
                <dict-tag v-else :type="DICT_TYPE.ECW_IS_BRAND" :value="row.brandType" />
              </template>
            </el-table-column>
            <el-table-column prop="prodTitle" :label="$t('orderdetail.inWarehouseInfo')">
              <template slot-scope="{row}">
                <template >{{row.warehouseInInfoVO?row.warehouseInInfoVO.cartonsNum:0}}{{$t('prepayDeal.box')}}
              {{row.warehouseInInfoVO?row.warehouseInInfoVO.weight:0}}KG
              {{row.warehouseInInfoVO?row.warehouseInInfoVO.volume:0}}m³
              {{row.warehouseInInfoVO?row.warehouseInInfoVO.quantityAll:0}}{{$t('price.one')}}</template>
              </template>
            </el-table-column>
            <el-table-column prop="warehouseType" :label="$t('complaint.type')" />
            <el-table-column prop="unit" :label="$t('orderdetail.packing')">
              <template slot-scope="{row}">
                <dict-tag :type="DICT_TYPE.ECW_PACKAGING_TYPE" :value="row.unit" />
              </template>
            </el-table-column>
            <el-table-column prop="worth" :label="$t('orderdetail.worth')" />
            <el-table-column prop="sumNum" :label="$t('delivery.number')">
              <template slot-scope="{row}">
                {{ row.warehouseInInfoVO ? row.warehouseInInfoVO.expressNo : '' }}
              </template>
            </el-table-column>
            <el-table-column prop="" :label="$t('orderdetail.material')">
              <template slot-scope="{row}">
                <dict-tag :type="DICT_TYPE.ECW_PRODUCT_MATERIAL" :value="row.material" />
              </template>
            </el-table-column>
            <el-table-column prop="link" :label="$t('delivery.link')" />

            <el-table-column prop="prodTitle" :label="$t('orderdetail.costVO')">
              <template slot-scope="{row}">
                <template >{{row.num}}{{$t('prepayDeal.box')}}{{row.weight}}KG{{row.volume}}m³{{row.quantity}}{{$t('price.one')}}</template>
              </template>
            </el-table-column>
            <el-table-column prop="expressNo" :label="$t('orderdetail.tiandanExpressNO')" />
          </el-table>
          <!--<div style="padding: 20px 0;display: flex; align-items: center;justify-content: space-evenly;">
            <div>{{$t('delivery.sum')}}：</div>
            <div>{{$t('orderdetail.inWarehouseInfo')}}:{{getProSum.washouseNum}}{{$t('prepayDeal.box')}}{{getProSum.washouseWeight}}KG {{getProSum.washouseVolume}}m³{{getProSum.washouseQuantity}}{{$t('price.one')}}</div>
            <div>{{$t('delivery.worth')}}:{{getProSum.worth}}</div>
            <div>{{$t('orderdetail.costVO')}}:{{getProSum.num}}{{$t('prepayDeal.box')}}{{getProSum.weight}}KG {{getProSum.volume}}m³{{getProSum.quantity}}{{$t('price.one')}}</div>
          </div>-->
        </el-tab-pane>
        <el-tab-pane :label="$t('orderdetail.activeSecond')" name="second">
          <el-timeline v-if="order.orderTimeVOList && order.orderTimeVOList.length" :reverse="false" style="padding-top: 10px;">
            <el-timeline-item v-for="(activity, index) in order.orderTimeVOList" :key="index" :timestamp="getTime(activity.businessTime)">
              <div>{{ $l(activity, 'title') }}</div>
              <div :class="activity.mark==1?'red':''">{{ $l(activity, 'remarks') }}</div>
            </el-timeline-item>
          </el-timeline>
          <el-result v-else icon="info " :title="$t('orderdetail.noData')" :sub-title="$t('orderdetail.notOrderData')" />
        </el-tab-pane>
        <el-tab-pane :label="$t('orderdetail.activeThree')" name="three">

          <el-button type="text" :disabled="order.inWarehouseState == 0 && order.shipmentState == 0" @click="showWarehouseReceipt=true">{{ $t('orderdetail.showWarehouseReceipt') }}</el-button>
          <el-button type="text" :disabled="!order.tidanNo || order.ladingState==false" @click.native="showLadingBill=true">{{ $t('orderdetail.showLadingBill') }}</el-button>
          <el-button type="text" @click.native="declarationOrderId=order.orderId">{{ $t('common.seeDeclaration') }}</el-button>
          <!-- <el-button :disabled="true" type="text">{{$t('orderdetail.装箱单未上传')}}</el-button> -->
        </el-tab-pane>
      </el-tabs>
    </el-card>

    <el-dialog :title="$t('付款人')" :visible.sync="showDraweeDialog" v-if="order && order.customDraweeVOList">
      <el-table :data="order.customDraweeVOList" v-if="order.drawee==3" >
        <el-table-column :label="$t('费用类型')" prop="label" width="200px">
          <template slot-scope="{row}">
            <dict-tag :type="DICT_TYPE.ECW_CUSTOM_DRAWEE" :value="row.name"/>
          </template>
        </el-table-column>
        <el-table-column :label="$t('付款人')" width="300px">
          <template slot-scope="{row}">
            <dict-tag :type="DICT_TYPE.DRAWEE" :value="row.value" />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <print-warehouse-receipt v-if="showWarehouseReceipt" :order-id="order.orderId" @close="showWarehouseReceipt=false" />
    <print-lading-bill v-if="showLadingBill" :order-id="order.orderId" :transport-type="order.transportId" @close="showLadingBill=false" />
    <declaration-documents v-if="declarationOrderId !== null" :order-id="order.orderId" :disabled="documentsDidables" @close="declarationOrderId=null" />
  </div>
</template>

<script>
import { getOrder, getOfferCheck } from '@/api/order'
import { getDictDatas, DICT_TYPE, getDictData } from '@/utils/dict'
import PrintWarehouseReceipt from './components/PrintWarehouseReceipt'
import PrintLadingBill from './components/PrintLadingBill'
import DictTag from '@/components/DictTag'
import { getCurrencyList, getChannelList, getListTree, getCityData } from '@/api/data'
import DeclarationDocuments from './components/DeclarationDocuments'
import { parseTime } from '@/utils/index'
import Decimal from 'decimal.js'
export default {
  name: 'Detail',
  components: {
    PrintWarehouseReceipt, PrintLadingBill, DictTag, DeclarationDocuments
  },
  filters: {
    customsTypeFilter(e, customsTypeList) {
      if (e) return customsTypeList.find(item => item.value == e).label
    },
    transportFilter(e, transportList) {
      if (e) return transportList.find(item => item.value == e).label
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      order: {},
      activeName: 'first',
      orderId: 17,
      tableData: [],
      channelList: [],
      showDraweeDialog: false,
      queryParams: {
        page: 1,
        rows: 10
      },
      show: false,
      customsTypeList: getDictDatas(DICT_TYPE.ECW_CUSTOMS_TYPE), // 报关类型
      transportList: getDictDatas(DICT_TYPE.ECW_TRANSPORT_TYPE), // 运输方式
      showWarehouseReceipt: false, // 是否显示打印入仓单
      showLadingBill: false, // 是否显示打印提单
      consigneeText: this.$t('orderdetail.showText'),
      showMore: false,
      declarationOrderId: null,
      documentsDidables: true,
      offerNumber: '',// 关联报价单
      address:'',
      objectCity:''
    }
  },
  computed: {
    currencyMap() {
      const map = {}
      this.currencyList.forEach(item => {
        map[item.id] = item.titleZh
      })
      return map
    },
    addressName() {
      let that = this
      var orderAdderss = ''
      if(that.order&&that.order.consigneeVO&&that.order.consigneeVO.country){

        var country = that.address.find(item=>item.id == that.order.consigneeVO.country)||''
        if(country){
          if(that.$i18n.locale=='zh'){
            orderAdderss = country.titleZh
          }else{
            orderAdderss = country.titleEn
          }
          if(that.order.consigneeVO.province){
            var province = country.children.find(item=>item.id == that.order.consigneeVO.province)||''
            if(province){
              if(that.$i18n.locale=='zh'){
                orderAdderss += province.titleZh
              }else{
                orderAdderss += province.titleEn
              }
              if(that.order.consigneeVO.city){
                var city = province.children.find(item=>item.id == that.order.consigneeVO.city)||''
                if(city){
                  if(that.$i18n.locale=='zh'){
                    orderAdderss += city.titleZh
                  }else{
                    orderAdderss += city.titleEn
                  }
                }
              }
            }
          }
        }
      }
      return orderAdderss
    },
    typeName(){
      let typeName = []
      if(this.order.type){
        if(this.order.type.includes(1)){
          typeName.push(this.$t('orderdetail.service'))
        }
        if(this.order.type.includes(2)){
          typeName.push(this.$t('orderdetail.oversears'))
        }
      }
      return typeName.join("、")
    },
    getDictData() {
      return (type, value) => getDictData(type, value) || {}
    },
    getTime() {
      return (value) => parseTime(value) || ''
    },
    consigneeVO(){
      return this.order.consigneeVO || {}
    }
  },
  created() {
    getCurrencyList().then(res => {
      this.currencyList = res.data
    })
    getChannelList().then((res) => (this.channelList = res.data))
    if (this.$route.query.orderId) {
      this.orderId = this.$route.query.orderId
      // getOrder({ orderId: this.orderId }).then(response => {
      //   this.order = response.data
      //   this.loading = true
      // })
      this.getOrder()
      this.getOfferNumber()
      this.getAddress()
    }
  },
  methods: {
    getSummary() {
      // 货值汇总
      let worth = new Decimal(0)
      // 入仓箱数
      let wCartonsNum = new Decimal(0)
      // 入仓重量
      let wWeight = new Decimal(0)
      // 入仓体积
      let wVolume = new Decimal(0)
      // 入仓个数
      let wQuantity = new Decimal(0)

      // 填单箱数
      let cartonsNum = new Decimal(0)
      // 填单个数
      let quantity = new Decimal(0)
      // 填单重量
      let weight = new Decimal(0)
      // 填单体积
      let volume = new Decimal(0)
      this.order.orderItemVOList.forEach(item => {
        worth = worth.plus(item.worth || 0)
        console.log({worth: item.worth})
        if(item.warehouseInInfoVO){
          wCartonsNum = wCartonsNum.plus(item.warehouseInInfoVO.cartonsNum || 0)
          wWeight = wWeight.plus(item.warehouseInInfoVO.weight || 0)
          wVolume = wVolume.plus(item.warehouseInInfoVO.volume || 0)
          wQuantity = wQuantity.plus(item.warehouseInInfoVO.quantityAll || 0)
        }
        quantity = quantity.plus(item.quantity || 0)
        weight = weight.plus(item.weight || 0)
        volume = volume.plus(item.volume || 0)
        cartonsNum = cartonsNum.plus(item.num || 0)
      })
      return [
         null, null, this.$t("合计") + ":",
        `${wCartonsNum}${this.$t('prepayDeal.box')} ${wWeight}Kg ${wVolume}m³ ${wQuantity}${this.$t('price.one')}`,
        null, null,
        worth.toNumber(),
        null, null, null,
        `${cartonsNum}${this.$t('prepayDeal.box')} ${weight}Kg ${volume}m³ ${quantity}${this.$t('price.one')}`
      ]
    },
    /** 查询列表 */
    getOrder() {
      const that = this
      that.loading = true
      // 执行查询
      getOrder(that.orderId).then(response => {
        that.order = response.data
        if(!that.order.consigneeVO){
          that.order.consigneeVO = {}
        }
        that.documentsDidables = (that.order.customsType == 2)
        this.show = true
        that.getObjectCity(that.order.initialLogisticsInfoDto.destCityId)
      })
    },
    getAddress(){
     getListTree({ treeType: 1 }).then(response => {
        this.address = response.data
      })
    },
    // 显示更多
    consigneeChange() {
      this.showMore = !this.showMore
      this.consigneeText = this.showMore ? this.$t('orderdetail.hiddenText') : this.$t('orderdetail.showText')
    },
    //获取城市
    getObjectCity(id){
      getCityData({id:id}).then(res => {
      		this.objectCity = res.data
      })
    },
    // 根据渠道id显示渠道名
    getChannelNameById(id) {
      const cc = this.channelList.find((item) => item.channelId == id)
      if (cc) {
        return cc.nameZh
      } else {
        return '/'
      }
    },
    getOfferNumber() {
      const that = this
      console.log(that.orderId)
      getOfferCheck({ orderId: that.orderId }).then(response => {
        that.offerNumber = response?.data?.number ?? ''
      })
    }
  }
}
</script>

<style scoped>
.card {
  margin-bottom: 20px;
}
.card-title{
  font-size: 18px;
  font-weight: bold;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.el-icon-arrow-down {
  font-size: 12px;
}
.margin-top{
  margin-top: 20px;
}
.hiddenInfo{
  display:none;
}
.showInfo{
  display:block;
}
.red{
  color:red !important;
}
</style>
