<template>
	<view>
		<dHeader :title="$lang.lang.exception.see"></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.exception.info}}</text>
				</view>
				<view class="order-info-line">
					<view class="order-info-line-v">
						<view class="">{{$lang.lang.exception.marks}}：{{orderData.marks}}</view>
						<view class="">{{$lang.lang.exception.sum}}：{{orderData.sumNum}}/{{orderData.costVO?orderData.costVO.totalNum:0}}</view>
						<view class="">{{$lang.lang.exception.orderStatus}}：{{getStatusName(orderData.status)}}</view>
						<view class="">{{$lang.lang.exception.consignor}}：{{orderData.consignorVO?orderData.consignorVO.name:''}}</view>
					</view>
					<view class="order-info-line-v">
						<view class="" >{{$lang.lang.exception.transport}}：{{getConfigLabel('transport',orderData.transportId)}}</view>
						<view class="" >{{$lang.lang.exception.startCity}}：{{orderData.logisticsInfoDto?(orderData.logisticsInfoDto[$lang.startTitle]):''}}</view>
						<view class="">{{$lang.lang.exception.endCity}}：{{orderData.logisticsInfoDto?(orderData.logisticsInfoDto[$lang.destTitle]):''}}</view>
						<view class="">{{$lang.lang.exception.consignee}}：{{orderData.consigneeVO?orderData.consigneeVO.name:''}}</view>
					</view>
				</view>
				<view class="order-info-line">
					<view class="order-info-line-v">
						<view class="">{{$lang.lang.exception.company}}：{{orderData.consigneeVO?orderData.consigneeVO.company:''}}</view>
						<view class="">{{$lang.lang.exception.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.exception.date}}：{{orderData.deliveryDate||$lang.lang.create.no}}</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.exception.question}}</text>
					<!-- <text class="addGoods" @click="open(-1)">添加商品</text> -->
				</view>
			</view>
			<view class="corder-goods">
				<view class="" v-for="(item,index) in exceptiondata" :key="index">
					<view class="corder-gnums">{{index+1}}</view>
					<view class="corder-goods-v">
						<view class="corder-goods-v-item">
							<view class="">
								<text>{{$lang.lang.exception.exception}}：</text>
								<text>{{getConfigLabel('exceptionType',item.orderExceptionType)}}</text>
							</view>
							<view class="">
								<text>{{$lang.lang.exception.describe}}：</text>
								<text>{{$lang.locale=='zh'?item.orderExceptionDescVO.descZh:$lang.locale=='en'?item.orderExceptionDescVO.descEn:item.orderExceptionDescVO.descFr}}</text>
							</view>
							<view class="">
								<text>{{$lang.lang.exception.file}}:</text>
								<view  class="" v-for="(itemFile,index) in item.orderExceptionAttr" :key="index" @click="downLoadFile(itemFile)">
									<view class="fileName">{{$lang.lang.exception.file}}{{index+1}}</view>
								</view>
							</view>

						</view>

						<view class="corder-goods-v-item">
							<view class="">
								<text>{{$lang.lang.exception.money}}:</text>
								<text>{{item.orderExceptionAmount}}</text>
							</view>
							<view class="">
								<text>{{$lang.lang.exception.status}}:</text>
								<text>{{getConfigLabel('exceptionStatus',item.orderExceptionStatus)}}</text>
							</view>

						</view>
					</view>
					<view class="corder-link" v-if="item.orderExceptionStatus!='2'">
<!-- 						<view class="">
							<text>类型：</text>
							<text>{{getConfigLabel('exceptionType',item.orderExceptionType)}}</text>
						</view> -->
						<view v-if="item.orderExceptionType=='order_superfluous_box_exception'||item.orderExceptionType=='order_lack_box_exception'" class="link-btn" @click="toBoxExcetpion('../box_exception/box_exception',item.id)">{{$lang.lang.exception.toDeal}}</view>
						<view v-if="item.orderExceptionType=='order_heavy_cargo_exception'" class="link-btn" @click="toBoxExcetpion('../weight_exception/weight_exception',item.id)">{{$lang.lang.exception.toDeal}}</view>
						<view v-if="item.orderExceptionType=='order_doc_exception'" class="link-btn" @click="toBoxExcetpion('../doc_exception/doc_exception',item.id)">{{$lang.lang.exception.toDeal}}</view>
						<view v-if="item.orderExceptionType=='order_bulky_cargo_exception'" class="link-btn" @click="toBoxExcetpion('../light_exception/light_exception',item.id)">{{$lang.lang.exception.toDeal}}</view>
					</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 {
				exceptiondata:[],
				orderData:{},
				statusData:[],
				config:{
					transport:[],
					exceptionType:[],
					exceptionStatus:[]
				},
				orderId:0
			}
		},
		onLoad(op) {

			this.getStatusData()
			if(op.id){
				this.orderId = op.id
				this.getOrderData(op.id)
				this.getExcetpionData(op.id)
			}
			this.orderConfig('transport_type', 'transport')
			this.orderConfig('order_error_type', 'exceptionType')
			this.orderConfig('order_exception_status', 'exceptionStatus')
		},
		created() {
			if(this.orderId){
				this.getExcetpionData(this.orderId)
			}
		},
		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]
				}
			},
			//获取异常
			getExcetpionData(id){
				let that = this
				that.exceptiondata = []
				that.$request.get('/app-api/ecw/order-exception/getExceptionListByOrderId',{orderId:id}).then(res => {
					if(res.code==0&&res.data){
						that.exceptiondata = res.data
						that.exceptiondata.forEach((item)=>{
							if(item.orderExceptionAttr){
								item.orderExceptionAttr = item.orderExceptionAttr.split(',')
							}else{
								item.orderExceptionAttr = []
							}
						})
					}
				})
			},
			//获取状态
			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&&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
					}
				})
			},
			toBoxExcetpion(url,id){
				uni.navigateTo({
					url:url+'?id='+id+'&orderId='+this.orderData.orderId
				})
			},
			downLoadFile(file) {
			      uni.showLoading({
			        mask: true,
			      });
				  // var urlFile = config.CDN_DOMAIN + file
				var urlFile = file
			      uni.downloadFile({
			        url: urlFile, //仅为示例，并非真实的资源
			        success: (res) => {
						uni.hideLoading();
			          if (res.statusCode === 200) {
			            var filePath = res.tempFilePath;
			            uni.openDocument({
			              filePath: filePath,
			              success: function (res) {
			                console.log("打开文档成功");
			              },
			            });
			          }
			        },
			    })
			}
		}
	}
</script>

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