<template>
	<view class="allContent">
		<view class="list-item">
			<view><text>订单号：</text><text>{{state.params['orderNo']}}</text></view>
			<view><text>业务类型：</text><text>{{state.params['businessTypeC']}}</text></view>
			<view><text>订单状态：</text><text>{{state.params['orderStatusStr']}}</text></view>
			<view><text>订单阶段：</text><text>{{state.params['orderStepStr']}}</text></view>
			<view><text>车牌号：</text><text>{{state.params['vehiclePlate']}}</text></view>
			<view><text>车牌颜色：</text><text>{{getVehiclePlateColorPai(state.params['vehiclePlateColorC'])}}</text></view>
			<template v-if="state.paramsdData.orderType=='VEHICLEINFOCHANGE'">
				<view v-if="state.params['beforeChangeData']&&state.params['beforeChangeData']['type']"><text>原车型：</text><text>{{state.params['beforeChangeData']['typeStr']}}</text></view>
				<view  v-if="state.params['afterChangeData']&&state.params['afterChangeData']['type']"><text>现车型：</text><text>{{state.params['afterChangeData']['typeStr']}}</text></view>
				<view v-if="state.params['beforeChangeData']"><text>原车牌：</text><text>{{state.params['beforeChangeData']['vehiclePlate']}}</text></view>
				<view><text>现车牌：</text><text>{{state.params['afterChangeData']['vehiclePlate']}}</text></view>
				<view v-if="state.params['beforeChangeData']"><text>原车牌颜色：</text><text>{{getVehiclePlateColorPai(state.params['beforeChangeData']['vehiclePlateColor'])}}</text></view>
				<view><text>现车牌颜色：</text><text>{{getVehiclePlateColorPai(state.params['afterChangeData']['vehiclePlateColor'])}}</text></view>
			</template>
			<template v-if="state.paramsdData.orderType=='SIGNOUT'">
				<view><text>ETC卡号：</text><text>{{state.params['cardId']}}</text></view>
				<view><text>OBU号：</text><text>{{state.params['obuId']}}</text></view>
				<!-- <view><text>退款金额：</text><text>{{state.params['aa']}}</text></view>
				<view><text>退款方式：</text><text>{{state.params['aa']}}</text></view>
				<view><text>注销原图：</text><text>{{state.params['aa']}}</text></view> -->
			</template>
			<template v-if="state.paramsdData.orderType=='EXCHANGE_CARD' || state.paramsdData.orderType=='EXCHANGE_OBU' || state.paramsdData.orderType=='EXCHANGE_ALL'">
				<view v-if="state.params['newCardId']"><text>更换ETC卡号：</text><text>{{state.params['newCardId']}}</text></view>
				<view v-if="state.params['newObuId']"><text>更换OBU号：</text><text>{{state.params['newObuId']}}</text></view>
			</template>
			<template v-if="state.paramsdData.orderType=='CARDLOSS' || state.paramsdData.orderType=='OBULOSS' || state.paramsdData.orderType=='CARDOBULOSS'">
				<view><text>ETC卡号：</text><text>{{state.params['cardId']}}</text></view>
				<view><text>OBU号：</text><text>{{state.params['obuId']}}</text></view>
			</template>
			<template v-if="state.paramsdData.orderType=='CUSTOMERINFOCHANGE'">
				<view><text>原手机号：</text><text>{{state.params['oldMobile']}}</text></view>
				<view><text>现手机号：</text><text>{{state.params['newMobile']}}</text></view>
			</template>
			
			<view class="btns">
				<view class="btn btn-primary" v-if="state.params['orderStep']=='WAIT_PAY'" @click="pay(state.params['orderNo'],state.params['orderType'])">支付</view>
				<view class="btn btn-primary" v-if="state.params['orderStep']=='DELIVER'" @click="gotoConfirmReceiptSH(state.params['id'])">确认收货</view>
				<view style="display: flex;" v-if="state.params['orderStep']=='ACTIVE_COMPLETE'||state.params['orderStep']=='RECEIVE' || state.params['orderStep']=='WRITE_CARD_COMPLETE' || state.params['orderStep']=='WRITE_OBU_COMPLETE'|| state.params['orderStep']=='EXCHANGE_APPLY'">
					<view class="btn btn-primary" @click="gotoExchangeOrder(state.params)">换货</view>
					<view class="btn btn-primary" @click="activateSH(state.params)">去激活</view>
				</view>
			    <!-- 注销 待支付 取消订单 -->
				<view class="btn btn-primary" v-if="(state.params['orderStep']=='WAIT_PAY' || state.params['orderStep']=='AUDIT') && state.params['orderType']=='SIGNOUT'" @click="signout(state.params['orderNo'],state.params['orderType'])">取消</view>
				<!-- 待审核 取消 （卡签挂失没有） -->
				<view class="btn btn-primary" v-if="state.params['orderStep']=='AUDIT' && (state.params['orderType']=='CUSTOMERINFOCHANGE' || state.params['orderType']=='VEHICLEINFOCHANGE' || state.params['orderType']=='EXCHANGE_CARD' || state.params['orderType']=='EXCHANGE_OBU'|| state.params['orderType']=='EXCHANGE_ALL')" @click="signout(state.params['id'],state.params['orderType'])">取消</view>
			</view>
		</view>
	</view>

</template>

<script setup lang="ts">
	import { reactive } from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	import { pay,signout,gotoConfirmReceiptSH,activateSH,gotoExchangeOrder } from "@/composables/afterSale.js";
	import { vehicleInfoChangeView,cancelView,changeCardObuView,changeCardObuViewAfter,cardObuLossView,customerInfoChangeView} from "@/utils/network/api.js";
	import {requestNew } from "@/utils/network/request.js";
	import {vehiclePlateColor,getVehiclePlateColorPai } from "@/datas/vehiclePlateColor";
	import { getItem, StorageKeys } from "@/utils/storage";
	const state = reactive({
		params: {},  //上一个页面传递过来的参数
		promoteName: "",  //产品名称
		promoteId: "",//产品编号
		tableData: [],
		paramsdData:{},
		businessRange:[]
	});
    
	onLoad((options) => {
		let getBusiness = getItem('key')['BUSINESSAPP_TYPE'];
		for (var k = 0; k < getBusiness.length; k++) {
			let obj = {};
			obj['value'] = getBusiness[k]['code']
			obj['text'] = getBusiness[k]['name']
			state.businessRange.push(obj)
		}
		state.paramsdData = JSON.parse(decodeURIComponent(options.params))
		search(state.paramsdData.orderType)
		console.log("options.promoteId", state.paramsdData)
	})
	const search = (orderType) => {
		// 车辆信息变更-VEHICLEINFOCHANGE
		// 用户信息变更-CUSTOMERINFOCHANGE
		// 注销-SIGNOUT
		// 单卡挂失-CARDLOSS   单签挂失-OBULOSS  卡签挂失-CARDOBULOSS
		// 设备更换(换卡签-卡-EXCHANGE_CARD    换卡签-签-EXCHANGE_OBU  换卡签-卡签-EXCHANGE_ALL)
		var api=""
		var data={}
		if(orderType=='VEHICLEINFOCHANGE'){
			api=vehicleInfoChangeView
			data={
				orderNo: state.paramsdData.orderNo
			}
		}else if(orderType=='SIGNOUT'){
			api=cancelView
			data={
				id: state.paramsdData.id
			}
		}else if(orderType=='EXCHANGE_CARD' || orderType=='EXCHANGE_OBU' || orderType=='EXCHANGE_ALL'){
			api=changeCardObuViewAfter
			data={
				id: state.paramsdData.id
			}
		}else if(orderType=='CARDLOSS' || orderType=='OBULOSS' || orderType=='CARDOBULOSS'){
			api=cardObuLossView
			data={
				id: state.paramsdData.id
			}
		}else if(orderType=='CUSTOMERINFOCHANGE'){
			api=customerInfoChangeView
			data={
				id: state.paramsdData.id
			}
		}
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		requestNew(api, options).then((res) => {
			console.log("res==",res)
			for (var i in res) {
				for (var m = 0; m < state.businessRange.length; m++) {
					if (res['orderType'] == state.businessRange[m]['value']) {
						res['businessTypeC'] = state.businessRange[m]['text']
						break;
					}
				}
				// 车型字典
				let typeData=getItem('key')['VEHICLE_MODEL_TYPE']
				for (var n = 0; n < typeData.length; n++) {
					if(res['beforeChangeData']){
						if(typeData[n]['code']==res['beforeChangeData']['type']){
							res['beforeChangeData']['typeStr']=typeData[n]['name']
							break;
						}
					}
					if(typeData[n]['code']==1){
						res['afterChangeData']['typeStr']=typeData[n]['name']
						break;
					}
				}
				
			}
			state.params=res
		})
		
	}
</script>

<style scoped>
	.allContent {
		background-color: #EEF7F7;
		height: 100vh;
		overflow: hidden;
	}

	.list-item {
		width: 95%;
		border-radius: 10rpx;
		margin: 30rpx auto;
		font-size: 28rpx;
		border: 1rpx solid #ccc;
		padding: 12rpx;
		box-sizing: border-box;
		background-color: white;

	}

	.list-item>view {
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
	}

	.list-item>view>text:first-child {
		width: 26%;
		display: inline-block;
	}

	.list-item>view>text:last-child {
		width: 74%;
		display: inline-block;
		word-break: break-all;
	}
	.btns {
		position: relative;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		border-top: 1px solid #dcdcdc;
		margin: 0 30rpx;
		padding: 20rpx 0;
	}
	.btn-primary {
		color:white;
		background-color: #133850 ;
	}
	.btn {
		height: 60rpx;
		line-height: 58rpx;
		border-radius: 30rpx;
		padding: 0 24rpx;
		font-size: 23rpx;
		box-sizing: border-box;
		margin-right: 12rpx;
	}
</style>