<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-card>
        <div slot="header" class="card-title">{{$t('查看')}}</div>
        <el-descriptions :column="4">
            <el-descriptions-item :label="$t('唛头')">
                {{orderData.marks?orderData.marks:$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('已到箱数/总箱数')">
                {{orderData.sumNum||0}}/{{orderData.costVO?orderData.costVO.totalNum:0}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('订单状态')">
              <dict-tag :type="DICT_TYPE.ORDER_STATUS" :value="orderData.status" />
            </el-descriptions-item>
            <el-descriptions-item :label="$t('送货日期')">
              <span>{{orderData.deliveryDate||$t('无')}}</span>
            </el-descriptions-item>
            <el-descriptions-item :label="$t('运输方式')">
                <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="orderData.transportId" />
              </el-descriptions-item>
             <el-descriptions-item :label="$t('始发地')" :span="2">
                  {{orderData.logisticsInfoDto?orderData.logisticsInfoDto.startAddressZh:$t('无')}}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('目的地')">
                {{orderData.logisticsInfoDto?orderData.logisticsInfoDto.destAddressZh:$t('无')}}
             </el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="4">
            <el-descriptions-item :label="$t('发货人')">
                {{orderData.consignorVO?orderData.consignorVO.name||$t('无'):$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('发货公司')">
                {{orderData.consignorVO?orderData.consignorVO.company||$t('无'):$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('发货电话')">
                {{orderData.consignorVO?((orderData.consignorVO.countryCode?checkCode(orderData.consignorVO.countryCode):'')+orderData.consignorVO.phone)||$t('无'):$t('无')}}
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions :column="4">
            <el-descriptions-item :label="$t('收货人')">
                {{orderData.consigneeVO?orderData.consigneeVO.name||$t('无'):$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('收货公司')">
                {{orderData.consigneeVO?orderData.consigneeVO.company||$t('无'):$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('收货电话')">
                {{orderData.consigneeVO?((orderData.consigneeVO.countryCode?checkCode(orderData.consigneeVO.countryCode):'')+orderData.consigneeVO.phone)||$t('无'):$t('无')}}
            </el-descriptions-item>
        </el-descriptions>
    </el-card>
    <el-card class="card">
      <!-- 列表 -->
      <div slot="header" class="card-title">{{$t('货物信息')}}</div>
      <el-table v-loading="loading" border :data="orderData.orderItemVOList" :summary-method="getSummaries" show-summary>
        <el-table-column :label="$t('序号')" align="center" prop="id" type="index">
          <template slot-scope="scope">
              <span>{{scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('品名')" align="center" >
          <template slot-scope="scope">
            <p>{{scope.row.prodTitleEn||''}}</p>
            <p>{{scope.row.prodTitleZh||''}}</p>
          </template>
          </el-table-column>
          <el-table-column :label="$t('填单货物信息')">
            <template slot-scope="scope">
              <p>{{$t('品牌')}}：<dict-tag :value="scope.row.brandType" :type="DICT_TYPE.ECW_IS_BRAND" /></p>
              <p>{{$t('箱数')}}：{{scope.row.num||0}}</p>
              <p>{{$t('体积')}}：{{scope.row.volume||0}}CBM</p>
              <p>{{$t('重量')}}：{{scope.row.weight||0}}KG</p>
            </template>
            </el-table-column>
            <el-table-column :label="$t('入库货物属性')" align="center" >
              <template slot-scope="scope">
                 <span>{{$t('箱规')}}：{{scope.row.boxGauge||0}}</span>
                 <p>
                  <span>{{$t('品牌')}}：<dict-tag :value="scope.row.brandType" :type="DICT_TYPE.ECW_IS_BRAND" /></span>
                  <span>{{$t('箱数')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.cartonsNum:0}}</span>
                  <span>{{$t('体积')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.volume:0}}CBM</span>
                  <span>{{$t('重量')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.weight:0}}KG</span>
                </p>
              </template>
         </el-table-column>
        <el-table-column :label="$t('重货方数')" align="center" v-if="type=='order_heavy_cargo_exception'">
          <template slot-scope="scope">
            <span>{{ scope.row.warehouseInInfoVO?(scope.row.warehouseInInfoVO.heavyNumber||0):0}}CBM</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('泡货方数')" align="center" v-else >
          <template slot-scope="scope">
            <span>{{ scope.row.warehouseInInfoVO?(scope.row.warehouseInInfoVO.lightNumber||0):0}}CBM</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('最后操作时间')" scope="handlerTime" />

      </el-table>

    </el-card>
      <div slot="footer" class="dialog-footer">
        <div>
          <el-button  type="primary" @click="submit('general_cargo')">{{$t('设为普货')}}</el-button>
          <el-button plain type="primary" @click="submit('process')">{{$t('设为已处理')}}</el-button>
        </div>
      </div>
  </div>
</template>

<script>
import {getExceptionById,handlerExceptionByExceptionId} from "@/api/ecw/orderException"
import {DICT_TYPE} from  '@/utils/dict'
import {getOrder} from '@/api/ecw/order'

export default {
  name: "WeightDeal",
  components: {

  },
  data() {
    return {
      // 遮罩层
      loading: false,
      orderData:{},
      list: {},
      orderId:0,
      type:''
    };
  },
  created() {
    if(this.$route.query.id){
      this.id = this.$route.query.id
      this.getList()
    }
    if(this.$route.query.type){
      this.type = this.$route.query.type
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getExceptionById(this.id).then(response => {
        this.list = response.data;
        this.loading = false;
        this.getOrders()
      });
    },
    checkCode(data){
      if(data.indexOf('+')==-1){
      	return '+'+data
      }
      return data
    },
    getOrders(){
      getOrder(this.list.orderId).then(response => {
        this.orderData = response.data
      });
    },
    getSummaries(){
      const sums = [];
      if(!this.orderData || !this.orderData.list ||ths.orderData.length==0){
        return sums
      }
      sums[0] = this.$t('小计')
      var orderSum = 0
      var orderV = 0
      var orderW = 0
      var leviteSum = 0
      var leviteV = 0
      var leviteW = 0
      this.orderData.list.forEach((column, index) => {
          orderSum += column.orderSum
          orderV += column.volume
          orderW += column.weight
          leviteSum += column.orderSum
          leviteV += column.volume
          leviteW += column.weight
      });
      sums[1] = ''
      sums[2] = this.$t('下单统计：')+ orderSum+this.$t(' 箱 ')+ orderV +' m³ ' + orderW + ' kg'
      sums[3] = this.$t('入仓统计：')+ leviteSum+this.$t(' 箱 ')+ leviteV +' m³ ' + leviteW + ' kg'
      sums[4] = ''
      sums[5] = ''
      return sums;
    },
    submit(result){
      handlerExceptionByExceptionId({orderExceptionId:this.list.id,orderExceptionHandlerResult:result}).then(res=>{
          this.$modal.msgSuccess(this.$t("提交成功"));
          this.$router.back()
      })
    }
  }
}
</script>
<style scoped>
  .filelist{
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  .filelist span{
    width: 48%;
    margin-right: 2%;
    color: #1E98D7;
  }
  .card-title{
      font-size: 18px;
      font-weight: bold;
      margin-top: 10px;
  }
  .card{
    margin-top: 20px;
  }
</style>
