<template>
	<!-- <navBar title="补办ETC卡"></navBar> -->
	<view class="oderPage">
		<u-form :model="form" ref="myForm" :error-type="errorType">
			<view class="from">
				<u-form-item prop="orderNumber">
					<view class="from_item">
						<text>新办单号:</text>
						<u-input v-model="form.orderNumber" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="carId">
					<view class="from_item">
						<text>订单车牌号:</text>
						<u-input v-model="form.carId" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="oldCardId">
					<view class="from_item">
						<text>原卡号:</text>
						<u-input v-model="form.oldCardId" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="status">
					<view class="from_item">
						<text>原卡状态:</text>
						<u-input v-model="form.status" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="receiving">
					<view class="from_item">
						<text><text style="color: red;">*</text>收货方式：</text>
						<u-radio-group v-model="form.receiving">
							<u-radio :customStyle="{marginBottom: '8px'}" activeColor="#2CE242"
								v-for="(item, index) in radiolist1" :key="index" :label="item.disabled"
								:name="item.name" @change="radioChange">
								{{item.name}}
							</u-radio>
						</u-radio-group>
					</view>
				</u-form-item>
				<u-form-item prop="region" v-if="form.receiving=='营业点自提'">
					<view class="from_item">
						<text><text style="color: red;">*</text>自提网点：</text>
						<view style="display: flex;" @click="showPicker">
							<u-input v-model="form.region" class="input" disabled placeholder="请选择" />
							<u-icon name="arrow-right" style="margin-left: 10px;display: flex;"></u-icon>
						</view>
					</view>
				</u-form-item>
				<u-form-item prop="name" v-if="form.receiving=='邮寄'">
					<view class="from_item">
						<text><text style="color: red;">*</text>姓名：</text>
						<u-input v-model="form.name" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="phone" v-if="form.receiving=='邮寄'">
					<view class="from_item">
						<text><text style="color: red;">*</text>电话：</text>
						<u-input v-model="form.phone" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="region" v-if="form.receiving=='邮寄'">
					<view class="from_item">
						<text><text style="color: red;">*</text>地区：</text>
						<view style="display: flex;" @click="showPicker">
							<u-input v-model="form.region" class="input" disabled placeholder="请选择" />
							<u-icon name="arrow-right" style="margin-left: 10px;display: flex;"></u-icon>
						</view>
					</view>
				</u-form-item>
				<u-form-item prop="address" v-if="form.receiving=='邮寄'">
					<view class="from_item">
						<text><text style="color: red;">*</text>详细地址：</text>
						<u-input v-model="form.address" class="input" placeholder="请输入详细到门牌号" />
					</view>
				</u-form-item>
				<u-form-item prop="zipCode" v-if="form.receiving=='邮寄'">
					<view class="from_item">
						<text>邮政编码：</text>
						<u-input v-model="form.zipCode" class="input" placeholder="邮政编码" />
					</view>
				</u-form-item>
				<u-form-item prop="remark">
					<view class="from_item1">
						<text><text style="color: red;">*</text>补卡原因:</text>
						<u-input v-model="form.remark" type="textarea" class="textarea" placeholder="请输入补卡原因，限制50字以内。"
							maxlength="50" />
						<!-- <textarea name="" id="" placeholder="请输入补卡原因，限制50字以内。"></textarea> -->
					</view>
				</u-form-item>
			</view>
		</u-form>
		<button class="submit" @click="submit">确认退费</button>
		<!-- 地区弹窗 -->
		<view>
			<u-picker v-model="show" mode="region" @confirm="confirm"></u-picker>
		</view>
		<!-- 自提网点弹窗 -->
		<view>
			<u-picker v-model="show" mode="region" @confirm="confirm"></u-picker>
		</view>
	</view>

</template>

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

	import {
		ref,
		reactive
	} from "vue";
	import {
		onReady
	} from "@dcloudio/uni-app";

	// 表单数据
	const form = reactive({
		orderNumber: '2141543454545',
		carId: '贵A12345',
		oldCardId: '',
		status: "",
		receiving: "营业点自提",
		name: '许珅',
		phone: '13821934313',
		region: '',
		address: '',
		zipCode: '',
		remark: ''

	})
	// 验证规则
	const rules = {
		receiving: [{
			required: true,
			message: '请选择收获方式',
			trigger: ['change', 'blur'],
		}],
		name: [{
			required: true,
			message: '请输入姓名',
			trigger: ['change', 'blur'],
		}],
		phone: [{
				required: true,
				message: '请输入手机号',
				trigger: ['change', 'blur'],
			},
			{
				// 自定义验证函数，见上说明
				validator: (rule, value, callback) => {
					// 上面有说，返回true表示校验通过，返回false表示不通过
					console.log(checkStr(value, 'mobile'), '0011');
					return checkStr(value, 'mobile')
				},
				message: '手机号码不正确',
				trigger: ['change', 'blur'],
			}
		],
		// status: [{
		// 	required: true,
		// 	message: '请选择状态',
		//  
		// 	trigger: ['change', 'blur'],
		// }],
		region: [{
			required: true,
			message: '请输入区域',

			trigger: ['change', 'blur'],
		}],
		address: [{
			required: true,
			message: '请输入详细地址',
			trigger: ['change', 'blur'],
		}],
		// zipCode: [{
		// 	required: true,
		// 	message: '请输入邮编',
		// 	trigger: ['change', 'blur'],
		// }],
		remark: [{
			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: '营业点自提',
			disabled: false
		},
		{
			name: '邮寄',
			disabled: false
		},
	], )

	let show = ref(false)

	// 打开地区先择器
	const showPicker = function() {
		show.value = true
	}
	// 确定地区
	const confirm = (e) => {
		console.log(e);
		form.region = e.province.name + e.city.name + e.area.name
	}

	// 单选
	const radioChange = (n) => {
		console.log('radioChange', n);
		// if (n == '卡退费') {
		// 	flag.value = true
		// 	console.log(flag.value);
		// } else {
		// 	flag.value = false
		// 	console.log(flag.value);
		// }
	}

	// 提交
	const submit = () => {
		myForm.value.validate((valid) => {
			console.log(valid);
			if (valid) {
				console.log('验证通过', form);
				navTo('/subpackage/after-sale/card-supplement/reissuePay')
			} else {
				console.log('验证未通过');
			}
		})
	}
</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;

					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>
