<template>
	<!-- <navBar title="补办ETC卡"></navBar> -->
	<view class="oderPage">
		<u-form :model="form" ref="myForm" :error-type="errorType">
			<view class="from">
				<u-form-item prop="operation">
					<view class="from_item">
						<text><text style="color: red;">*</text>注销方式：</text>
						<u-radio-group v-model="form.operation">
							<u-radio :customStyle="{marginBottom: '8px'}" activeColor="#2CE242"
								v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.name"
								@change="radioChange">
								{{item.disabled}}
							</u-radio>
						</u-radio-group>
					</view>
				</u-form-item>
				<u-form-item prop="applyType">
					<view class="from_item">
						<text><text style="color: red;">*</text>申请类型：</text>
						<view style="display: flex;" @click="showPicker">
							<u-input v-model="applyType" class="input" disabled placeholder="请选择" />
							<u-icon name="arrow-right" style="margin-left: 10px;display: flex;"></u-icon>
						</view>
					</view>
				</u-form-item>
			</view>
		</u-form>
		<button class="submit" @click="submit">下一步</button>
		<!-- 自提网点弹窗 -->
		<view>
			<u-picker mode="selector" v-model="show" :range="columns" range-key="label" @confirm="confirm"></u-picker>
		</view>
	</view>

</template>

<script setup lang="ts">
	import {
		checkStr,
		navTo
	} from "@/utils/utils.ts"

	import {
		ref,
		reactive
	} from "vue";
	import {
		orderExchangeApply
	} from "@/utils/network/api.js"
	import {
		request
	} from "@/utils/network/request";
	import {
		stringToJson
	} from "@/utils/network/encryption";
	import {
		getItem,
		StorageKeys
	} from "@/utils/storage";
	import {
		onReady
	} from "@dcloudio/uni-app";
	import {
		onLoad
	} from "@dcloudio/uni-app";

	// 表单数据
	const form = reactive({
		orderId: '',
		applyType: '',
		operation: ''

	})
	//接受通过该id查询订单详情
	const oldId=ref('')

	const applyType = ref('')
	//选择器数据 
	const columns = [{
			label: '换货-换卡',
			// 其他属性值
			id: 'CARD '
		},
		{
			label: '换货-换签',
			// 其他属性值
			id: 'OBU'
		},
		{
			label: '换货-换卡签',
			// 其他属性值
			id: 'ALL'
		},
		{
			label: '换卡签-换卡',
			// 其他属性值
			id: 'EXCHANGE_CARD'
		},
		{
			label: '换卡签-换签',
			// 其他属性值
			id: 'EXCHANGE_OBU'
		},
		{
			label: '换卡签-换卡签',
			// 其他属性值
			id: 'EXCHANGE_ALL'
		},
	]

	// 验证规则
	const rules = {
		// applyType: [{
		// 	required: true,
		// 	message: '请选择申请类型',
		// 	trigger: ['change', 'blur'],
		// }],
		// operation: [{
		// 	required: true,
		// 	message: '请选择注销方式',
		// 	trigger: ['change', 'blur'],
		// }]
	}
	// 验证提示类型(toast要版本为1.3.5才支持)
	const errorType = ['message', 'border-bottom', 'toast']

	// 设置验证规则
	const myForm = ref(null)
	onReady(() => {
		myForm.value.setRules(rules)
	})

	// 单选数据列表
	const radiolist1 = reactive([{
			name: 1,
			disabled: '有卡注销'
		},
		{
			name: 2,
			disabled: '无卡注销'
		},
	], )




	let show = ref(false)

	// 打开地区先择器
	const showPicker = function() {
		show.value = true
	}
	// 确定地区
	const confirm = (e) => {
		console.log(e);
		form.applyType = columns[e].id
		applyType.value = columns[e].label
	}

	// 单选
	const radioChange = (n) => {
		console.log('radioChange', n);
		console.log(form);
	}


	// 提交
	const submit = () => {

		if (form.operation && form.applyType) {
			console.log('验证通过', form);
			navTo(`/subpackage/orders/apply-ex-goods?orderId=${oldId.value}&id=8822ca31f88e448eb534767ba4d01eb9`) //测试用
			// const options = {
			// 	type: 2,
			// 	data: form,
			// 	method: "POST",
			// 	showLoading: true,
			// };
			// request(orderExchangeApply, options).then((res) => {
			// 	const data = stringToJson(res.bizContent);
			// 	console.log(data);
			// 	// navTo(`/orders/apply-ex-goods?orderId=${oldId.value}&id=${data.id}`)
				
			// });
		} else if (!form.applyType) {
			uni.showToast({
				title: "请选择申请类型",
				icon: "none"
			})
		} else {
			uni.showToast({
				title: "请选择注销类",
				icon: "none"
			})
		}




		// myForm.value.validate((valid) => {
		// 	console.log(valid);
		// 	if (valid) {

		// 	} else {
		// 		console.log('验证未通过');
		// 	}
		// })
	}


	onLoad((option) => {
		form.orderId = option.orderId
		oldId.value=option.id
		console.log(form);
	});
</script>


<style>
	page {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		background-color: #F3F3F3;
	}
</style>
<style lang="scss" scoped>
	.oderPage {
		flex: 1;
		width: 100%;

		.from {
			background-color: #fff;
			margin-top: 20rpx;

			::v-deep .u-form-item {
				padding: 0;
				line-height: normal;

				.u-form-item__message {
					margin-bottom: 12rpx
				}
			}

			.from_item {
				display: flex;
				flex-wrap: nowrap;
				justify-content: space-between;
				padding: 0 30rpx;
				// border-bottom: #DCDCDC 1px solid;
				align-items: center;
				height: 80rpx;

				::v-deep .input {
					text-align: right;
					flex: 1;
                    background: transparent;
					input {
						text-align: right;
					}
				}
			}

			.from_item1 {
				display: flex;
				flex-wrap: nowrap;
				flex-direction: column;
				justify-content: space-between;
				padding: 30rpx;
				border-bottom: #DCDCDC 1px solid;

				input {
					text-align: right;
				}

				.textarea {
					background-color: #F1F1F1;
					width: 100%;
					border-radius: 20rpx;
					margin-top: 10rpx;
					text-indent: 1rem;
					height: 180rpx;
					padding: 20rpx;
					box-sizing: border-box;
				}
			}
		}
	}

	.submit {
		background: linear-gradient(to left, #43A1E0 0%, #13E7C1 100%);
		width: 670rpx;
		height: 80rpx;
		color: #fff;
		border-radius: 100rpx;
		margin: 26px auto;
		font-size: 32rpx;
	}
</style>
