<template>
	<view class="content">
		<view class="top hflex acenter jcenter">
			<image src="static/info.png" mode="aspectFill"></image>
			<text>支持word、pdf、xls等格式</text>
		</view>
		<view class="form">
			<view class="item hflex acenter jbetween">
				<view class="label">姓名</view>
				<u-input placeholder="请输入您的姓名" border="none" v-model="name" inputAlign="right"></u-input>
			</view>
			<view class="item hflex acenter jbetween">
				<view class="label">联系电话</view>
				<u-input placeholder="请输入您的联系电话" border="none" v-model="mobile" inputAlign="right"></u-input>
			</view>
			<view class="item vflex" style="border: none;">
				<view class="label">上传简历</view>
				<view class="upload hflex acenter jcenter" @click="toupload">
					<image src="static/upload.png" mode="aspectFill"></image>
					<text>上传文件</text>
				</view>
				<view class="file hflex acenter" v-if="resume">
					<image src="static/lianjie.png" mode="aspectFill"></image>
					<text>{{resume}}</text>
				</view>
			</view>
		</view>
		<view class="btn" :class="resume && name && mobile ? 'btn-sure' : ''" @click="submit">确认并上传</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				resume: '',
				name: '',
				mobile: '',
				id: '',
			}
		},
		onLoad(options) {
			that = this
			this.id = options.id
		},
		methods: {
			submit() {
				if (!this.name) {
					$api.info('请先输入您的姓名')
					return
				}
				if (!this.mobile) {
					$api.info('请先输入您的联系方式')
					return
				}
				if (!this.file) {
					$api.info('请先上传您的简历')
					return
				}
				$api.req({
					url: 'job/' + that.id + '/delivery',
					method: 'POST',
					data: {
						name: that.name,
						mobile: that.mobile,
						resume: that.resume
					}
				}, function(res) {
					if (res.code == 10000) {
						uni.redirectTo({
							url: '/pageC/success'
						})
					}
				})

			},
			toupload() {
				var _this = this
				uni.chooseFile({
					count: 1, //默认100
					extension: ['.doc', '.docx', '.pdf', '.xls'], //word、pdf、xls
					success: function(res) {
						uni.showLoading({
							title: '上传中'
						})
						console.log(JSON.stringify(res.tempFilePaths));
						let resume = JSON.stringify(res.tempFilePaths)
						uni.uploadFile({
							url: $api.config.baseUrl + 'upload/file', //仅为示例，非真实的接口地址
							filePath: resume,
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								var data = JSON.parse(uploadFileRes.data)
								_this.resume = data.data.url
								uni.hideLoading()
							}
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.content::v-deep {
		background: #FFFFFF;

		.form {
			padding: 0 28rpx;

			.item {
				padding: 28rpx 0;
				border-bottom: 1px solid #F5F5F5;

				.label {
					font-size: 32rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #333333;
				}

				.u-input {
					max-width: 450rpx;
				}

				.file {
					image {
						width: 32rpx;
						height: 32rpx;
					}

					text {
						font-size: 28rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.85);
						padding: 0 0 0 8rpx;
					}
				}

				.upload {
					background: #FFFFFF;
					border-radius: 8rpx;
					border: 2rpx solid #D9D9D9;
					padding: 10rpx 32rpx;
					max-width: max-content;
					margin: 20rpx 0 16rpx;

					image {
						width: 28rpx;
						height: 28rpx;
					}

					text {
						font-size: 28rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.85);
						padding: 0 0 0 16rpx;
					}
				}
			}
		}

		.top {
			width: 100%;
			height: 60rpx;
			background: #00B0B0;

			image {
				width: 28rpx;
				height: 28rpx;
				margin: 0 8rpx 0 0;
			}

			text {
				font-size: 22rpx;
				font-family: SFPro, SFPro;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		.btn-sure {
			opacity: 1 !important;
		}

		.btn {
			width: 702rpx;
			height: 84rpx;
			background: #00B0B0;
			border-radius: 44rpx;
			opacity: 0.3;
			position: fixed;
			bottom: 66rpx;
			left: 24rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 84rpx;
			text-align: center;
		}
	}
</style>