<template>
	<view>
		<dHeader :title="orderExceptionData.orderExceptionType=='order_superfluous_box_exception'?$lang.lang.boxException.exception:$lang.lang.boxException.exceptionless"></dHeader>
		<view class="start-bar"></view>
		<view class="order-info">
			<view class="order-info-v">
				<view class="order-info-line">
					<view class="order-info-line-v">
						<view class=""><text>{{$lang.lang.boxException.orderNo}}：</text><text>{{orderData.orderNo}}</text></view>
						<!-- <view class=""><text>{{$lang.lang.boxException.prodZh}}：</text><text>{{shopData.prodTitleZh}}</text></view> -->
						<!-- <view class=""><text>{{$lang.lang.boxException.prodEn}}：</text><text>{{shopData.prodTitleEn}}</text></view> -->
						<view>
							<text>{{$lang.lang.boxException.line}}：</text>
							<view class="channel">
								<text>【{{getConfigLabel('transport',orderData.transportId)}}】</text>
								<text v-if="orderData.transportId==3||orderData.transportId==4">【{{orderData.channelName}}】</text>
								<text>从【 {{orderData.logisticsInfoDto?(orderData.logisticsInfoDto[$lang.startTitle]):''}} 】发往【{{orderData.logisticsInfoDto?(orderData.logisticsInfoDto[$lang.destTitle]):''}}】</text>
							</view>
						</view>
						<view class="11"><text>{{$lang.lang.boxException.form}}：{{(orderData.costVO.totalNum||0)+$lang.lang.boxException.box+(orderData.costVO.totalNum||0)+'m³ '+(orderData.costVO.totalWeight||0)+'kg'}}</text>
						<!-- <text>{{(orderData.costVO?orderData.costVO.totalNum:0)+'箱 '+(orderData.costVO?orderData.costVO.totalVolume:0)+'m³ '+(orderData.costVO?orderData.costVO.totalWeight:0)+'kg'}}</text> -->
						</view>
						<view class="22"><text>{{$lang.lang.boxException.in}}：</text><text>{{(orderData.sumNum||0)+$lang.lang.boxException.box+&nbsp;&nbsp;+(orderData.sumVolume||0)+'m³ '+(orderData.sumWeight||0)+'kg'}}</text></view>
						<view class=""><text>{{$lang.lang.boxException.describe}}：</text><text>{{$lang.locale=='zh'?orderExceptionData.orderExceptionDescVO.descZh:orderExceptionData.orderExceptionDescVO.descEn}}</text></view>
						<view class="corder-tab1-item">
							<text>{{$lang.lang.boxException.result}}:</text>
							<picker :class="params.orderExceptionHandlerResult == 0 ? 'v-picker v-picker-2' : 'v-picker'" mode='selector' :value="config.result.index" :range="config.result.label" v-if="config.result.label.length>0" @change="changeResult">
								<view class="uni-input">{{config.result.label[config.result.index]}}</view>
							</picker>
							<image class="rgt" src="../../static/img/rgt.png" mode=""></image>
						</view>
						<view class="corder-tab1-item">
							<text>{{$lang.lang.boxException.remark}}</text>
							<textarea v-model="params.orderExceptionHandlerRemark"></textarea>
						</view>
						<view class="apply-btn">
								<view @click="sumbit">{{$lang.lang.boxException.sumbit}}</view>
								<view @click="reset">{{$lang.lang.boxException.reset}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
    import dHeader from '../../components/dHeader/index.vue'
	export default {
		components: {
			dHeader
		},
		data() {
			return {
				orderData:{},
				shopData:{},
				orderExceptionData:{},
				config:{
					transport:{
						label:[],
						value:[]
					},
					result:{
						index:0,
						label:[],
						value:[]
					},
				},
				params:{
					orderExceptionHandlerResult:'',
					orderExceptionHandlerRemark:''
				}
			}
		},
		onLoad(op) {
			this.orderConfig('transport_type', 'transport')
			if(op.id){
				this.getExceptionData(op.id,op.orderId)
			}
		},
		methods: {
			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')
					}
				})
			},
			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.orderData.orderItemVOList.forEach((item)=>{
						// 	if(item.orderItemId == that.orderExceptionData.orderItemId){
						// 		that.shopData = item
						// 	}
						// })
					}
				})
			},
			reset(){
				this.params.orderExceptionHandlerRemark=""
				this.params.orderExceptionHandlerResult=""
			},
			getConfigLabel(key,value){
				var indexs = ''
				this.config[key].value.forEach(function(item,index){

					if(item == value){
						indexs = index
					}
				})
				return this.config[key].label[indexs]
			},
			orderConfig (field, key) {
				let that = this
				that.$request.getConfig(field).then(res => {
					if(res.code==0&&res.data&&res.data.list.length > 0){
						var d = res.data.list
						for(var i in d){
							if(that.$lang.locale=='zh'){
								that.config[key].label.push(d[i].label)
							}else{
								that.config[key].label.push(d[i].labelEn)
							}
							that.config[key].value.push(d[i].value)
						}
					}
				})
			},
			changeResult(e){
				this.config.result.index = e.detail.value
				this.params.orderExceptionHandlerResult = this.config.result.value[e.detail.value]
			},
			sumbit(){
				let that = this
				that.params.orderExceptionId = that.orderExceptionData.id
				that.params.orderExceptionStatus = that.orderExceptionData.orderExceptionStatus
				if(!that.params.orderExceptionHandlerResult){
					that.params.orderExceptionHandlerResult = that.config.result.value[0]
				}
				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.notices.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/box_exception.css");
</style>
