<template>
	<view class="page">
		<view class="stylebookbox">
			<view class="apply">样书申请</view>
			<view class="stylebook">
				欢迎您申请我们的国优、国规样书
			</view>
			<view class="dotted">
				<image src="/static/images/dotted.png" style="width: 654rpx;height: 4rpx;" mode=""></image>
			</view>
			<!-- 姓名 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">您的姓名</text>
				</view>
				<view class="box u-flex">
					<input v-model="from.name" type="text" style="width: 100%;" />
				</view>
			</view>
			<!-- 电话 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">您的电话</text>
				</view>
				<view class="box u-flex">
					<input v-model="from.phone" type="text" style="width: 100%;" />
				</view>
			</view>
			<!-- 邮箱 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">您的邮箱</text>
				</view>
				<view class="box u-flex">
					<input v-model="from.email" type="text" style="width: 100%;" />
				</view>
			</view>
			<!-- 学校 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">您所在的学校名称</text>
				</view>
				<view class="box u-flex">
					<input v-model="from.school" type="text" style="width: 100%;" />
				</view>
			</view>
			<!-- 样书 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">样书用途</text>
				</view>
				<!-- 				<view class="box u-flex"> -->
				<view class="" style="margin-top: 38rpx;">
					<u-radio-group :wrap='true' @change='changeground' v-model="value">
						<u-radio shape="square" active-color="rgba(6, 169, 113, 1)" v-for="(item, index) in list"
							:key="index" :name="index" @change="radioChange">
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</view>
				<!-- </view> -->
			</view>
			<!-- 地址 -->
			<view class="item">
				<view class="name">
					<text>*</text>
					<text style="color: rgba(34, 34, 34, 1);">您的邮寄地址</text>
				</view>
				<view class="u-flex u-row-between" style="margin-top: 40rpx;">
					<view class="address">姓名：</view>
					<view class="box u-flex " style="margin-top: 0rpx;width: 500rpx;">
						<input v-model="from.mailing_name" type="text" style="width: 100%;" />
					</view>
				</view>
				<view @click="showc=true" class="u-flex u-row-between" style="margin-top: 40rpx;">
					<view class="address">所在地区：</view>
					<view  class="box u-flex " style="margin-top: 0rpx;width: 500rpx;">
						{{from.mailing_area}}
						<!-- <input  @click="showc=true" disabled v-model="from.mailing_area" type="text" style="width: 100%;" /> -->
					</view>
				</view>
				<view class="u-flex u-row-between" style="margin-top: 40rpx;">
					<view class="address">详细地址：</view>
					<view class="box u-flex " style="margin-top: 0rpx;width: 500rpx;">
						<input v-model="from.mailing_address" type="text" style="width: 100%;" />
					</view>
				</view>
				<view class="u-flex u-row-between" style="margin-top: 40rpx;">
					<view class="address">手机号码：</view>
					<view class="box u-flex " style="margin-top: 0rpx;width: 500rpx;">
						<input v-model="from.mailing_phone" type="text" style="width: 100%;" />
					</view>
				</view>
			</view>
			<view class="btn" @click="toupload">
				提交
			</view>
		</view>
		<u-select :list='city' mode='mutil-column-auto' value-name='code' label-name='name' child-name='sub'
			v-model="showc" @confirm="changecity"></u-select>
	</view>
</template>

<script>
	import city from '../../common/city-data.js'
	export default {
		data() {
			return {
				showc:false,
				value: 0,
				list: [{
						name: '教材用书',
						disabled: false,
						id: 0
					},
					{
						name: '学习参考',
						disabled: false,
						id: 1
					},
					{
						name: '其他',
						disabled: false,
						id: 2
					}
				],
				city: city,
				from: {
					name: '',
					phone: '',
					email: '',
					school: '',
					use_to: 0,
					mailing_name: '',
					mailing_area: '',
					mailing_address: '',
					mailing_phone: '',
					books_id: ''
				}
			};
		},
		onLoad(options) {
			this.from.books_id = options.id
			console.log(city);
		},
		methods: {
			changecity(e){
				console.log(e);
				this.from.mailing_area = e[0].label+e[1].label+e[2].label
			},
			radioChange(e) {
				this.from.use_to = e
			},
			changeground(e) {
				console.log(e);
			},
			toupload() {
				if (!this.from.name) {
					this.$u.toast('请输入您的姓名')
					return
				}
				if (!this.$u.test.mobile(this.from.phone)) {
					this.$u.toast("请输入正确的手机号")
					return
				}
				if (!this.$u.test.email(this.from.email)) {
					this.$u.toast("请输入正确的邮箱号")
					return
				}
				if (!this.from.school) {
					this.$u.toast('请输入您的学校')
					return
				}
				if (!this.from.use_to) {
					this.$u.toast('请选择图书用途')
					return
				}
				if (!this.from.mailing_name) {
					this.$u.toast('请输入您的收货姓名')
					return
				}
				if (!this.from.mailing_address) {
					this.$u.toast('请输入您的收货地址')
					return
				}
				if (!this.$u.test.mobile(this.from.mailing_phone)) {
					this.$u.toast("请输入正确的收货手机号")
					return
				}
				this.$u.post("api/books/addSampleApply", {
					...this.from
				}).then(res => {
					console.log(res);
					if (res.code == 1) {
						uni.navigateBack()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		// width: 614rpx;
		height: 82rpx;
		background: #06A971;
		border-radius: 8rpx;
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		margin-top: 48rpx;
		line-height: 82rpx;
		text-align: center;
	}

	.address {
		font-size: 26rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #222222;
	}

	.item {
		margin-top: 44rpx;

		.name {
			font-size: 26rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #CF1534;
		}

		.box {
			margin-top: 24rpx;
			height: 72rpx;
			border: 2rpx solid rgba(151, 151, 151, 0.3);
		}
	}

	.page {
		background-color: rgba(246, 246, 246, 1);
		width: 750rpx;
		min-height: 100vh;
		padding: 20rpx 28rpx 68rpx;
	}

	.stylebookbox {
		background: #FFFFFF;
		border-radius: 12rpx;
		padding: 38rpx 20rpx 44rpx;

		.apply {
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #222222;
			text-align: center;
		}

		.stylebook {
			font-size: 26rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #222222;
			margin-top: 50rpx;
		}

		.dotted {
			// margin-top: 30rpx;
		}
	}
</style>