<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">
					<input v-model='from.selected_name' type="text" style="width: 100%;" />
				</view>
			</view>
			<!-- 稿件状态 -->
			<view class="" style="position: relative;">
				<view class="item">
					<view class="name">
						<text style="color: rgba(34, 34, 34, 1);">稿件状态</text>
					</view>
					<view class="box u-flex" style="padding-right: 28rpx;" @click="toshowb">
						<input placeholder-style="font-size: 26rpx;" class="input" type="text"
							style="width: 100%;padding: 28rpx;" placeholder="请选择" v-model="manuscript"
							:disabled="true" />
						<u-icon name="arrow-down-fill" size='12' color='rgba(150, 150, 150, 1)'></u-icon>
					</view>
				</view>
				<view v-if="showb" class="" style="position: absolute;top:130rpx;left: 0;background: #FFFFFF;
				box-shadow: 0rpx 8rpx 28rpx -10rpx rgba(0,0,0,0.2);width: 100%;z-index: 999;padding-bottom:28rpx ;">
					<scroll-view>
						<view class="" style="padding:0 30rpx ;height: 64rpx;line-height: 64rpx;"
							:class="item.id==from.funds_status?'green':'wart'" v-for="(item,index) in manuscriptlist"
							:key="index" @click="changefundb(item.id,item.name)">{{item.name}}</view>
					</scroll-view>
				</view>
			</view>
			<view class="item">
				<view class="name">
					<text style="color: rgba(34, 34, 34, 1);">最迟出版时间</text>
				</view>
				<view class="box u-flex" style="padding: 0 28rpx;" @click="show=true">
					<image src="/static/images/calendar.png" style="width: 44rpx;height: 44rpx;" mode=""></image>
					<u-calendar v-model="show" mode="date" @change="change"></u-calendar>
					<input v-model="from.last_publish_time" :disabled="true" type="text"
						style="width: 100%;margin-left: 20rpx;" />
				</view>
			</view>
			<!-- 经费情况 -->
			<view class="" style="position: relative;">
				<view class="item">
					<view class="name">
						<text style="color: rgba(34, 34, 34, 1);">经费情况</text>
					</view>
					<view class="box u-flex" style="padding-right: 28rpx;" @click="toshow">
						<input placeholder-style="font-size: 26rpx;" class="input" type="text"
							style="width: 100%;padding: 28rpx;" v-model="fundsName" placeholder="请选择"
							:disabled="true" />
						<u-icon name="arrow-down-fill" size='12' color='rgba(150, 150, 150, 1)'></u-icon>
					</view>
				</view>
				<view v-if="showa" class="" style="position: absolute;top:130rpx;left: 0;background: #FFFFFF;
				box-shadow: 0rpx 8rpx 28rpx -10rpx rgba(0,0,0,0.2);width: 100%;z-index: 999;padding-bottom:28rpx ;">
					<scroll-view>
						<view class="" style="padding:0 30rpx ;height: 64rpx;line-height: 64rpx;"
							:class="item.id==from.funds_status?'green':'wart'" v-for="(item,index) in moneylist"
							:key="index" @click="changefunds(item.id,item.name)">{{item.name}}</view>
					</scroll-view>
				</view>
			</view>
			<!-- 上传 -->
			<view class="item">
				<view class="name">
					<text style="color: rgba(34, 34, 34, 1);">作者简介及目录上传</text>
				</view>
				<view v-if="showd" class="uploading" style="position: relative;">
					<view class="" @click="close">
						<image src="../../static/images/close (2).png"
							style="position: absolute;top:-20rpx;right: -20rpx;width: 40rpx;height: 40rpx;" mode="">
						</image>
					</view>
					<image src="../../static/images/pdf (2).png" style="width: 64rpx;height: 64rpx;" mode=""></image>
					<view style="margin-top: 16rpx;font-size: 20rpx;
font-family: PingFangSC, PingFang SC;
font-weight: 400;
color: #222222;">{{name}}</view>
				</view>
				<view v-else class="uploading" @click="upload1">
					<image src="../../static/images/uploading.png" style="width: 64rpx;height: 64rpx;" mode=""></image>
					<view class="up" style="margin-top: 16rpx;">选择文件</view>
					<view class="up" style="text-align: center;">请上传pdf,不超过10M</view>
				</view>
			</view>
			<view class="btn" @click="touploading">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
						name: '教材用书',
						disabled: false
					},
					{
						name: '学习参考',
						disabled: false
					},
					{
						name: '其他',
						disabled: false
					}
				],
				show: false,
				from: {
					name: '',
					phone: '',
					email: '',
					school: '',
					manuscript_status: "",
					last_publish_time: '',
					funds_status: 0,
					biographical_url: '',
					selected_name: ''
				},
				moneylist: [{
						id: 0,
						name: '无经费'
					},
					{
						id: 1,
						name: '三万及以内'
					},
					{
						id: 2,
						name: '五万及以内'
					},
					{
						id: 3,
						name: '五万以上'
					},
				],
				manuscriptlist: [{
						id: 0,
						name: '待启动'
					},
					{
						id: 1,
						name: '编写中'
					},
					{
						id: 2,
						name: '已截稿'
					},
				],
				fundsName: '', //经费名称
				manuscript: '', //稿件状态
				showa: false,
				showb: false,
				name: '',
				path1: '',
				path: '',
				showd: false
			};
		},
		methods: {
			close() {
				this.showd = false
				this.from.biographical_url = ''
			},
			upload1() {
				let that = this;
				uni.chooseFile({
					// count: , //限制选择的文件数量
					type: 'all', //非图片和视频的文件,不选默认为all
					extension: [".pdf", 'pdf'], //此处限制文件类型
					success(res) {
						var tempFilePaths = res.tempFiles
						console.log('临时路径', tempFilePaths)
						that.name = tempFilePaths[0].name
						that.path1 = tempFilePaths[0].path
						that.upload(tempFilePaths[0].path)
					}
				})
			},
			upload(file) {
				uni.showLoading({
					title: '加载中'
				});
				uni.uploadFile({
					url: 'https://hire.hdlkeji.com/api/common/upload', //仅为示例，非真实的接口地址
					filePath: file,
					name: 'file',
					formData: {
						'user': 'test'
					},
					success: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '上传成功',
							icon: 'success',
							duration: 1000
						})
						var obj = JSON.parse(res.data)
						this.from.biographical_url = obj.data.fullurl
						this.showd = true
						// this.flielist.push(obj.data.fullurl)
					},
					fail: (err) => {
						console.log('uploadImage fail', err);
						uni.hideLoading();
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					},
				});
			},
			touploading() {
				if (!this.from.name) {
					this.$u.toast('请填写您的姓名')
					return
				}
				if (!this.from.school) {
					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.selected_name) {
					this.$u.toast('请填写选题名称')
					return
				}
				this.$u.post('api/books/addContribute', {
					...this.from
				}).then(res => {
					if (res.code == 1) {
						this.$u.toast('提交成功')
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index/index'
							})
						}, 800)
					}
				})
			},
			toshowb() {
				this.showb = !this.showb
			},
			toshow() {
				this.showa = !this.showa
			},
			changefunds(id, name) {
				this.from.funds_status = id
				this.fundsName = name
				this.showa = false
			},
			changefundb(id, name) {
				this.from.manuscript_status = id
				this.manuscript = name
				this.showb = false
			},
			change(e) {
				this.from.last_publish_time = e.result
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wart {
		height: 64rpx;
		font-size: 28rpx;
		font-family: SFPro, SFPro;
		font-weight: 400;
		color: #222222;
	}

	.green {
		background: #06A971;
		font-size: 28rpx;
		font-family: SFPro, SFPro;
		font-weight: 400;
		color: #FFFFFF;
	}

	.uploading {
		width: 184rpx;
		height: 184rpx;
		border: 2rpx solid rgba(151, 151, 151, 0.3);
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 22rpx;

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

	.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>