<template>
	<view style="padding-bottom: 50rpx;">
		<view class="pagebg">
			<view class="" style="width: 100%;height: 400rpx;">
				<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="500" style="width: 100%;height: 100%;">
					<swiper-item v-for="(item,index) in swiperList" :key="index">
						<image :src="item.imageUrl" style="width: 100%;height: 100%;" mode=""></image>
					</swiper-item>
				</swiper>
			</view>
			<view class="content">
				<view class="box">
					<view>
						<view class="text-bold" style="color: #333333;">您的姓名</view>
						<view class="inutline">
							<u-input v-model="form.applyName" type="text" placeholder="请输入真实姓名"
								inputAlign="text-align:left" />
						</view>
					</view>
					<view class="margin-top">
						<view class="text-bold" style="color: #333333;">您的年龄</view>
						<view class="inutline">
							<u-input v-model="form.applyAge" type="text" placeholder="请输入年龄"
								inputAlign="text-align:left" />
						</view>
					</view>
					<view class="margin-top">
						<view class="text-bold" style="color: #333333;">联系电话</view>
						<view class="inutline">
							<u-input v-model="form.applyPhone" type="text" placeholder="请输入联系电话"
								inputAlign="text-align:left" />
						</view>
					</view>
					<view class="margin-top">
						<view class="text-bold" style="color: #333333;">报考课程</view>
						<view class="">
							<u-input v-model="form.applyContent" type="text" placeholder="请输入报考课程"
								inputAlign="text-align:left" />
						</view>
					</view>
				</view>
				<view v-if="form.status==3&&form.auditContent">拒绝理由:{{form.auditContent}}</view>
				<view class="btn" v-if="form.status==1||form.status==3" @click="submit()">修改</view>
				<view class="btn" v-else @click="submit()">提交</view>
				
			</view>
		</view>
		<view class="text flex justify-center">
			<view class="text-box" v-html="value">
				<!-- {{value}} -->
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					applyName: '',
					applyPhone: '',
					applyAge: '',
					applyContent: '',
					classify:1
				},
				userId: '',
				value:'',
				swiperList:[]
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync('userId')
			this.getSwiperList();
			if(this.userId){
				this.getDetails()
				this.$Request.get('/app/common/type/316').then(res => {
					if (res.code == 0) {
						this.value = res.data.value
					}
				});
			}
		},
		onShow() {

		},
		methods: {
			//获取轮播图
			getSwiperList() {
				this.$Request.get("/app/banner/selectBannerList", {
					classify: 7
				}).then(res => {
					if (res.code == 0) {
						this.swiperList = res.data
					}
				});
			},
			getDetails() {
				let data = {
					classify: 1
				}
				this.$Request.get('/app/apply/selectApplyByUserIdAndClassify', data).then(res => {
					if (res.code == 0 && res.data) {
						this.form = res.data
					}
				})
			},
			submit() {
				if(this.userId==''){
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
					return
				}
				if (!this.form.applyName) {
					uni.showToast({
						title: '请输入真实姓名',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if (!this.form.applyAge) {
					uni.showToast({
						title: '请输入年龄',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if (!this.form.applyPhone) {
					uni.showToast({
						title: '请输入联系电话',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if (!this.form.applyContent) {
					uni.showToast({
						title: '请输入报考证书',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if(this.form.status ==1||this.form.status==3){
					this.$Request.postJson('/app/apply/updateApply', this.form).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '修改成功！',
								icon: 'none'
							})
							setTimeout(function() {
								uni.switchTab({
									url:'/pages/index/index'
								})
							}, 1000)
						}
					})
				}else{
					this.$Request.postJson('/app/apply/insertApply', this.form).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '提交成功！',
								icon: 'none'
							})
							setTimeout(function() {
								uni.switchTab({
									url:'/pages/index/index'
								})
							}, 1000)
						}
					})
				}
				

			}
		}
	}
</script>

<style lang="less">
	page{
		background-color: #82a9fe;
	}
	.text{
		margin-top: 50rpx;
		width: 100%;
		.text-box{
			width: 686rpx;
			text-align: center;
		}
	}
	.pagebg {
		width: 100%;
	}

	.pagebg image {
		width: 100%;
		height: 100%;
	}

	.content {
		z-index: 99;
		margin: 30upx 30upx;
	}

	.box {


		background: #FFFFFF;
		border: 4upx solid #000000;
		border-radius: 20upx;
		padding: 30upx;
	}

	.inutline {

		border-bottom: 1rpx solid #E9E9E9;
	}
	.btn{
		background: #FFFFFF;
		border-radius: 10upx;
		text-align: center;
		margin-top: 30upx;
		padding: 30upx;
		color: #000000;
		font-weight: bold;
		letter-spacing: 2rpx;
	}
	
</style>
