<template>
	<view>
		<dHeader :title="$lang.lang.light.weightException"></dHeader>
		<view class="start-bar"></view>
		<view class="order-info">
			<view class="order-info-v">
				<view class="order-info-title">
					<image src=".../../static/img/corder-1.png" mode=""></image>
					<text>{{$lang.lang.light.info}}</text>
				</view>
				<view class="order-info-line">
					<view class="order-info-line-v">
						<view class="">{{$lang.lang.light.marks}}：{{orderData.marks}}</view>
						<view class="">{{$lang.lang.light.sum}}：{{orderData.sumNum}}/{{orderData.costVO?orderData.costVO.totalNum:0}}</view>
						<view class="">{{$lang.lang.light.orderStatus}}：{{getStatusName(orderData.status)}}</view>
						<view class="">{{$lang.lang.light.consignor}}：{{orderData.consignorVO?orderData.consignorVO.name:''}}</view>
					</view>
					<view class="order-info-line-v">
						<view class="" >{{$lang.lang.light.transport}}：{{getConfigLabel('transport',orderData.transportId)}}</view>
						<view class="" >{{$lang.lang.light.startCity}}：{{orderData.logisticsInfoDto?orderData.logisticsInfoDto[$lang.startTitle]:''}}</view>
						<view class="">{{$lang.lang.light.endCity}}：{{orderData.logisticsInfoDto?orderData.logisticsInfoDto[$lang.destTitle]:''}}</view>
						<view class="">{{$lang.lang.light.consignee}}：{{orderData.consigneeVO?orderData.consigneeVO.name:''}}</view>
					</view>
				</view>
				<view class="order-info-line">
					<view class="order-info-line-v">
						<view class="">{{$lang.lang.light.company}}：{{orderData.consigneeVO?orderData.consigneeVO.company:''}}</view>
						<view class="">{{$lang.lang.light.phone}}：{{orderData.consigneeVO?$request.checkAddIcon(orderData.consigneeVO.countryCode):''}}{{orderData.consigneeVO?orderData.consigneeVO.phone:''}}</view>
						<view class="">{{$lang.lang.orderInfo.consignorCom}}：{{orderData.consignorVO?orderData.consignorVO.company:''}}</view>
						<view class="">{{$lang.lang.orderInfo.consignorTel}}：{{orderData.consignorVO?$request.checkAddIcon(orderData.consignorVO.countryCode):''}}{{orderData.consignorVO?orderData.consignorVO.phone:''}}</view>
						<view class="">{{$lang.lang.light.date}}：{{orderData.deliveryDate||''}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="corder-tab2 bgf">
			<view class="corder-tab-top">
				<image src="../../static/img/corder-2.png" mode=""></image>
				<view class="noborder">
					<text>{{$lang.lang.light.incoming}}</text>
					<!-- <text class="addGoods" @click="open(-1)">添加商品</text> -->
				</view>
			</view>
			<view class="corder-goods">
				<view class="" v-for="(item,index) in shopData" :key="index">
					<view class="corder-gnums">{{index+1}}</view>
					<view class="corder-goods-v">
						<view class="corder-goods-v-item">
							<view class="weight_style">
								<text>{{$lang.lang.light.goodsName}}：</text>
								<text>{{item.prodTitleZh}}{{item.prodTitleEn}}</text>
							</view>
							<view class="weight_style">
								<text>{{$lang.lang.light.formInfo}}:</text>
								<view class="weight_info">
									<text>{{$lang.lang.light.brand}}：{{item.brandType?$lang.lang.create.yes:$lang.lang.create.no}}</text>
									<text>{{$lang.lang.light.num}}：{{item.num||0}} </text>
									<text>{{$lang.lang.light.volume}}：{{item.volume||0}}CBM </text>
									<text> {{$lang.lang.light.weight}}：{{item.weight||0}}KG</text>
								</view>
							</view>
							<view class="weight_style">
								<text>{{$lang.lang.light.incoming}}:</text>
								<view class="weight_info">
									<text>{{$lang.lang.light.box}}：{{item.warehouseInInfoVO?item.warehouseInInfoVO.boxGauge:0}} </text>
									<text>{{$lang.lang.light.brand}}：{{item.brandType?$lang.lang.create.yes:$lang.lang.create.no}}</text>
									<text>{{$lang.lang.light.num}}：{{item.warehouseInInfoVO?item.warehouseInInfoVO.cartonsNum:0}}</text>
									<text>{{$lang.lang.light.volume}}：{{item.warehouseInInfoVO?item.warehouseInInfoVO.volume:0}}CBM </text>
									<text> {{$lang.lang.light.weight}}：{{item.warehouseInInfoVO?item.warehouseInInfoVO.weight:0}}KG</text>
								</view>
						    </view>
							<view class="weight_style">
								<text>{{$lang.lang.light.weightVolume}}: </text>
								<text>{{ item.weVolume||0}}CBM</text>
							</view>
							<view class="weight_style">
								<text>{{$lang.lang.light.lastTime}}: </text>
								<text>{{ item.updateTime?$request.getLocalTime(item.updateTime):'无'}}</text>
							</view>
						</view>

					</view>
				</view>
				<view  class="corder-goods-v corder-sum">
					<view>
						<text>{{$lang.lang.light.total}}:</text>
						<text>{{$lang.lang.light.num}}：{{shopSum.sumNum||0}} </text>
						<text>{{$lang.lang.light.volume}}：{{shopSum.sumVolume||0}}CBM </text>
						<text> {{$lang.lang.light.weight}}：{{shopSum.sumWeight||0}}KG</text>
					</view>
					<view>
						<text>{{$lang.lang.light.rucang}}:</text>
						<text>{{$lang.lang.light.num}}：{{shopSum.warehouseNum||0}} </text>
						<text>{{$lang.lang.light.volume}}：{{shopSum.warehouseVolume||0}}CBM </text>
						<text> {{$lang.lang.light.weight}}：{{shopSum.warehouseWeight||0}}KG</text>
					</view>
				</view>
			</view>
			<view class="apply-btn">
					<!-- <view @click="sumbit('general_cargo')">{{$lang.lang.light.common}}</view> -->
					<view  @click="sumbit('process')">{{$lang.lang.light.weightAgree}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import dHeader from '../../components/dHeader/index.vue'
	import config from '../../utils/config.js'
	export default {
		components: {
			dHeader
		},
		data() {
			return {
				orderExceptionData:{},
				shopData:[],
				orderData:[],
				statusData:[],
				shopSum:{
					sumNum:0,
					sumVolume:0,
					sumWeight:0,
					warehouseNum:0,
					warehouseVolume:0,
					warehouseWeight:0,
				},
				config:{
					transport:[],
					exceptionType:[],
					exceptionStatus:[]
				},
				params:{}
			}
		},
		onLoad(op) {

			this.getStatusData()
			if(op.id){
				this.getExceptionData(op.id,op.orderId)
			}
			this.orderConfig('transport_type', 'transport')
			this.orderConfig('order_error_type', 'exceptionType')
			this.orderConfig('order_exception_status', 'exceptionStatus')
		},
		methods: {
			getConfigLabel(key,value){
				var label = ''
				let that = this
				that.config[key].forEach(function(item,index){
					if(item.value == value){
            label = item[that.$lang.label]

					}
				})
				return label
			},
			//获取状态名
			getStatusName (type){
				let that = this
				var status = that.statusData.find(item=>item.value == type)
				if(status) {
          return status[that.$lang.label]
				}
			},
			getExceptionData(id,orderId){
				let that = this
				that.$request.get('/app-api/ecw/order-exception/getExceptionById',{id:id}).then(res => {
					if(res.code==0&&res.data){
						that.orderExceptionData = res.data
						that.getOrderData(orderId)
						that.orderConfig(that.orderExceptionData.orderExceptionType+'_result','result')
					}
				})
			},
			getStatusData () {
				this.$request.getConfig('order_status').then(res => {
					if(res.code==0&&res.data && res.data.list.length > 0){
						this.statusData = res.data.list
					}
				})
			},
			orderConfig (field, key) {
				this.$request.getConfig(field).then(res => {
					if(res.code==0&&res.data.list.length > 0){
						this.config[key] = res.data.list
					}
				})
			},
			getOrderData(id){
				let that = this
				that.$request.get('/app-api/my/order/info/'+id).then(res => {
					if(res.code==0&&res.data){
						that.orderData = res.data
						that.shopData = that.orderData.orderItemVOList
						// that.orderData.orderItemVOList.forEach((item)=>{
						// 	if(item.prodId == that.orderExceptionData.orderItemId){
						// 		that.shopData.push(item)
						// 	}
						// })
						that.getSumData()
					}
				})
			},
			getSumData(){
				let that = this
				console.log(that.shopData)
				that.shopData.forEach((item)=>{
					that.shopSum.sumNum += item.num
					that.shopSum.sumVolume += item.volume
					that.shopSum.sumWeight += item.weight

					that.shopSum.warehouseNum += item.warehouseInInfoVO.cartonsNum
					that.shopSum.warehouseVolume += item.warehouseInInfoVO.volume
					that.shopSum.warehouseWeight += item.warehouseInInfoVO.weight
				})
			},
			sumbit(result){
				let that = this
				that.params.orderExceptionId = that.orderExceptionData.id
				that.params.orderExceptionStatus = that.orderExceptionData.orderExceptionStatus
				that.params.orderExceptionHandlerResult = result
				that.params.source = 'mobile'
				that.$request.post('/app-api/ecw/order-exception/handlerExceptionByExceptionId',that.params).then(res => {
					if(res.code==0){
						uni.showToast({
							title:this.$lang.lang.notice.operation,
							icon:'none'
						})
						setTimeout(()=>{
							uni.reLaunch({
								url:'../exception/exception?id='+that.orderData.orderId
							})
						},2000)
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			}
		}
	}
</script>

<style>
@import url("../../static/css/exception.css");
</style>
