<template>
	<view class="content">
		<view class="container">
			<headers :titles="titles"><uni-icons type="arrow-left" color="#000000" size="22px"></uni-icons></headers>
			<view class="up-box">
				<view class="">考试通过截图</view>
				<view class="">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
						:maxCount="10"></u-upload>
				</view>
			</view>
			<view class="up-box">
				<view class="">科目</view>
				<view class="right-text" @click="show = true">
					<view class="" v-if="!courseSubject">选择科目</view>
					<view class="" v-else>{{courseSubject}}</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<view class="anniu" @click="gogogo()">
				提交
			</view>
			<u-picker :show="show" :columns="columns" @confirm="confirm" @cancel="cancel"></u-picker>
		</view>

	</view>
</template>

<script>
	import upload from '@/utils/upload.js'
	import request from '../../utils/request'
	import headers from '../../components/header/headers.vue'
	export default {
		data() {
			return {
				titles: "上传成绩",
				fileList1: [],
				msg: "1",
				courseSubject: null,
				List: [],
				columns: [
					['科目一', '科目二', '科目三', '科目四']
				],
				photo: null,
				show: false,
				status: 'loading',
			}
		},
		onShow() {
			// this.actList = ["1", "1", "1", "1", "1", ]
			// this.status = "nomore" 底部刷新结束
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers
		},
		methods: {
			async gogogo() {
				let res = await request({
					url: `/drivingSchool/system/pass`,
					method: 'post',
					data: {
						photo: this.photo,
						courseSubject: this.courseSubject
					}
				})
				if (res.code == 200) {
					uni.showToast({
						title: '提交成功'
					})
					uni.navigateBack()
				}

			},
			confirm(e) {
				console.log(e);
				this.courseSubject = e.value[0]
				this.show = false
			},
			cancel() {
				this.show = false
			},
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
				if (event.name == '1') {
					this.photoUrl.splice(event.index, 1)
				}
				if (event.name == '2') {
					this.videoUr = null
				}

			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,

					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(e) {
				console.log(e);
				upload({
					url: '/common/upload',
					filePath: e,
				}).then((res) => {
					console.log(res.fileName);
					this.photo = res.fileName


				})
			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #fff;

		height: 100vh;
	}

	.container {
		width: 100%;
		background: #fff;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.up-box {
		width: 95%;
		border-bottom: 1px solid #ebebeb;
		margin: 10px auto;
		padding: 10px 0px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.right-text {
		display: flex;
		align-items: center;
	}

	.anniu {
		width: 95%;
		height: 40px;
		background: #2fb000;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 40px auto;
		border-radius: 4px;
	}
</style>