<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.orderNo||''}}
            </el-descriptions-item>
            <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('运输方式')" :span="2">
                <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="orderData.transportId" />
                <span v-if="getDictData(DICT_TYPE.ECW_TRANSPORT_TYPE, orderData.transportId).cssClass == 'channel'" style="margin-left:10px">{{$t('出货渠道')}}:{{orderData.channelName}}</span>
              </el-descriptions-item>
             <el-descriptions-item :label="$t('始发地')" :span="2">
                 {{orderData.logisticsInfoDto?orderData.logisticsInfoDto.startTitleZh:$t('无')}}
             </el-descriptions-item>
             <el-descriptions-item :label="$t('目的地')">
                {{orderData.logisticsInfoDto?orderData.logisticsInfoDto.destTitleZh:$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-descriptions :column="4">
            <el-descriptions-item :label="$t('仓库实测')">
              <span style="margin-right:10px">{{(orderData.sumNum||0)+$t('箱')}}</span>
              <span style="margin-right:10px">{{(orderData.sumVolume||0)+'m³  '}}</span>
              <span style="margin-right:10px">{{(orderData.sumWeight||0)+'kg  '}}</span>
              <span>{{(orderData.sumQuantity||0) +$t('个')}}</span>
            </el-descriptions-item>
            <el-descriptions-item :label="$t('收费数据')">
              <span style="margin-right:10px">{{(orderData.sumNum||0)+$t('箱')}}</span>
              <span style="margin-right:10px">{{(orderData.wvolume||0)+'m³  '}}</span>
              <span style="margin-right:10px">{{(orderData.vweight||0)+'kg  '}}</span>
              <span>{{(orderData.sumQuantity||0) +$t('个')}}</span>
            </el-descriptions-item>
            <el-descriptions-item :label="$t('重货标准')" v-if="type=='order_heavy_cargo_exception'">
              <!--24-02-06 根据浩哥要求该用useWeightUnit字段-->
              {{orderData.useWeightUnit||$t('无')}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('泡货标准')" v-else>
                {{orderData.orgVolumeUnit||$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('品名')">
          <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('入库货物属性')">
              <template slot-scope="scope">
                 <p>{{$t('箱规')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.boxGauge:0}}</p>
                 <p>{{$t('品牌')}}：
                   <span v-if="scope.row.brandName">{{scope.row.brandName}}</span>
                   <dict-tag v-else :type="DICT_TYPE.ECW_IS_BRAND" :value="scope.row.feeType" />
                  </p>
                <!-- <p>{{$t('品牌')}}：<dict-tag :type="DICT_TYPE.ECW_IS_BRAND" :value="scope.row.feeType" /></p> -->
                  <p>{{$t('箱数')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.cartonsNum:0}}&nbsp;&nbsp;</p>
                  <p>{{$t('体积')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.volume:0}}CBM&nbsp;&nbsp;</p>
                  <p>{{$t('重量')}}：{{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.weight:0}}KG
                </p>
              </template>
         </el-table-column>
        <el-table-column :label="$t('重货方数')"  v-if="type=='order_heavy_cargo_exception'">
          <template slot-scope="scope">
            <span>{{scope.row.chargeVolume||0}}CBM</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('泡货方数')" v-if="type!='order_heavy_cargo_exception'">
          <template slot-scope="scope">
            <span>{{scope.row.chargeVolume||0}}CBM</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('重货重量')"  v-if="type=='order_heavy_cargo_exception'">
          <template slot-scope="scope">
            <span>{{scope.row.chargeWeight ||0}}KG</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('泡货重量')" v-if="type!='order_heavy_cargo_exception'" >
          <template slot-scope="scope">
            <span>{{scope.row.chargeWeight ||0}}KG</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('最后操作时间')" scope="handlerTime" />
      </el-table>

    </el-card>
    <el-card v-if="list.orderExceptionStatus==2">
      <div slot="header" class="card-title">{{$t('处理结果')}}</div>
      <el-descriptions :column="1">
          <el-descriptions-item :label="$t('处理时间')">
              {{parseTime(handlerParams.handlerTime)}}
          </el-descriptions-item>
          <el-descriptions-item :label="$t('处理结果')" v-if="type=='order_heavy_cargo_exception'">
              <span v-if="handlerParams.handlerResult=='general_cargo'">{{$t('设为普货')}}</span>
              <span v-else-if="handlerParams.handlerResult=='process'">{{$t('设为已处理')}}</span>
          </el-descriptions-item>
          <el-descriptions-item :label="$t('处理结果')" v-if="type!='order_heavy_cargo_exception'">
              <span v-if="handlerParams.handlerResult=='general_cargo'">{{$t('设为免泡')}}</span>
              <span v-else-if="handlerParams.handlerResult=='process'">{{$t('设为全泡')}}</span>
              <span v-else>{{$t('设为半抛')}}</span>
          </el-descriptions-item>
          <el-descriptions-item :label="$t('备注')">
            {{handlerParams.handlerRemark||"无"}}
          </el-descriptions-item>
      </el-descriptions>
    </el-card>
      <div slot="footer" class="dialog-footer">
        <div v-if="list.orderExceptionStatus!=2">
          <div v-if="type=='order_heavy_cargo_exception'">
            <el-button  type="primary" @click="submit('general_cargo')">{{$t('设为普货')}}</el-button>
            <el-button plain type="primary" @click="submit('process')">{{$t('设为已处理')}}</el-button>
          </div>
          <div v-else>
            <!---
              240808 按要求隐藏 https://czxy.cpolar.cn/task-view-199.html
              -->
            <!--<el-button  type="primary" @click="submit('general_cargo')">{{$t('设为免泡')}}</el-button>-->

            <el-button plain type="primary" @click="submit('process')">{{$t('设为全泡')}}</el-button>
            <el-button  plain type="primary" @click="submit('half_throw')">{{$t('设为半抛')}}</el-button>
          </div>

        </div>
        <div v-else>
          <el-button plain type="primary" @click="$store.dispatch('tagsView/delCurrentView')">{{$t('返回')}}</el-button>
        </div>
      </div>
      <el-form v-if="list.orderExceptionStatus!=2"  :model="handlerParams" ref="queryForms" size="small" label-width="50px" class="card">
        <el-form-item :label="$t('备注')+':'" size="medium">
          <el-input style="width: 500px;"  type="textarea" v-model="handlerParams.orderExceptionHandlerRemark"  />
        </el-form-item>
      </el-form>

  </div>
</template>

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

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

  },
  data() {
    return {
      // 遮罩层
      loading: false,
      orderData:{},
      list: {},
      orderId:0,
      type:'',
      branklist:[],
      handlerParams:{
        orderExceptionHandlerRemark:''
      }
    };
  },
  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
    }
    getProductBrankPage({pageNo:1,pageSize:500}).then((data)=>{
      this.branklist=data.data.list
    })
  },
  computed:{
      getDictData(){
          return (type, value) => getDictData(type, value) || {}
      },
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getExceptionById(this.id).then(response => {
        this.list = response.data;
        this.loading = false;
        if(this.list.orderExceptionStatus==2){
          this.getOrderExcptionResult()
        }
        this.getOrders()
      });
    },
    getBrand(id){
      var brank = this.branklist.find(item=>item.id==id)
      return brank.titleZh||''
    },
    //获取异常结果
    getOrderExcptionResult(){
      getOrderExcptionResult({orderExceptionId:this.id}).then(res=>{
        this.handlerParams = res.data.list[0]
        console.log(this.handlerParams)
      })

    },
    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,orderExceptionHandlerRemark:this.handlerParams.orderExceptionHandlerRemark}).then(res=>{
          this.$modal.msgSuccess(this.$t("提交成功"));
          this.$store.dispatch('tagsView/delCurrentView')
      })
    }
  }
}
</script>
<style scoped>
  .dialog-footer{
      margin-top: 10px;
  }
  .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;
  }
  p{
    text-align: left;
     margin: 0 !important;
  }
</style>
