<template>
	<view class="oderPage">
		<u-form :model="form"  :error-type="errorType">
			<view class="from">

				<u-form-item prop="applyType">
					<view class="from_item">
						<text><text style="color: red;">*</text>申请类型：</text>
						<view style="display: flex;">
							<picker @change="bindPickerChange" :value="index" :range="columnsOld">
								<view class="uni-input">{{index>=0?columnsOld[index]:"请选择"}}</view>
							</picker>
							<u-icon name="arrow-right" style="margin-left: 10px;display: flex;"
								@click="showPicker"></u-icon>
						</view>
					</view>
				</u-form-item>
			</view>
		</u-form>
		<view class="message">
			<view><text class="red">*</text>设备更换需将原设备寄回</view>
			<view>寄回信息：</view>
			<view>收件人：ETC售后 联系电话：18798751224（此电话仅用于ETC售后收取快递，如需咨询业务请致电4008008787）</view>
			<view>寄回地址：{{state.address}}</view>
			<view>补换订单审核时效：设备签收后的2个自然日完成审核，审核通过后请关注订单物流单号；</view>
		</view>
		<button class="submit" @click="submit">下一步</button>
	</view>

</template>

<script setup lang="ts">
	import {
		navTo
	} from "@/utils/utils.ts"
	import {
		ref,
		reactive
	} from "vue";
	import {
		onReady
	} from "@dcloudio/uni-app";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		getMailingAddress
	} from "@/subpackage/orders/js/publicRequest";
	// 表单数据
	const form = reactive({
		orderId: '',
		applyType: '',
		operation: ''

	})
	const state = reactive({
		address: '',
	
	})
	//接受通过该id查询订单详情
	const oldId = ref('')

	const applyType = ref('')
	//选择器数据 
	const index = ref('-1');
	const columnsOld = ["换货-换卡签"]
	const columns = [
		{
			label: '换货-换卡签',
			// 其他属性值
			id: 'ALL'
		},
	]
	const bindPickerChange = (e) => {
		console.log('picker发送选择改变，携带值为', e.detail.value)
		index.value = e.detail.value
		form.applyType = columns[e.detail.value].id
		applyType.value = columns[e.detail.value].label
	}
	// 验证规则
	const rules = {

	}
	// 验证提示类型(toast要版本为1.3.5才支持)
	const errorType = ['message', 'border-bottom', 'toast']

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

	let show = ref(false)

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


	// 提交
	const submit = () => {
		if (form.applyType) {
			console.log('验证通过', form);
			navTo(`/subpackage/orders/apply-ex-goods?orderId=${oldId.value}&address=${state.address}`) //测试用
		} else {
			uni.showToast({
				title: "请选择申请类型",
				icon: "none"
			})
		}
	}

	onLoad((option) => {
		form.orderId = option.orderId
		oldId.value = option.id
		console.log(form,option.id);
		getMailingAddress(option.orderId,option.id).then((address) => {
			console.log("address",address)
			state.address=address
		})
	});
</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;
				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;
	}

	.red {
		color: red;
		margin-right: 10rpx;
	}

	.message {
		font-size: 30rpx;
		margin-top: 30rpx;
		padding: 0 20rpx;
	}
</style>