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

      </el-table>

    </el-card>
      <div slot="footer" class="dialog-footer">
        <div>
          <el-button  type="primary" @click="submit('general_cargo')">设为普货</el-button>
          <el-button plain type="primary" @click="submit('process')">设为已处理</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,
    };
  },
  created() {
    if(this.$route.query.id){
      this.id = this.$route.query.id
      this.getList()

    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getExceptionById(this.id).then(response => {
        this.list = response.data;
        this.loading = false;
        this.getOrders()
      });
    },
    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] = '小计'
      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] = '下单统计：'+ orderSum+' 箱 '+ orderV +' m³ ' + orderW + ' kg'
      sums[3] = '入仓统计：'+ leviteSum+' 箱 '+ 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.$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>
