<!-- 录入成绩和证书 -->
<template>
	<view class="achievement" id="achievement">
		<u-form :model="form" ref="uForm" class="achievement-form">
			<u-form-item label="考试名称:" label-position="top" :required="true">
				<u-input v-model="form.teamName" placeholder="请输入内容" />
			</u-form-item>
			<u-form-item label="成绩:" label-position="top" :required="true">
				<view class="achievement-form-result">
					<u-form-item label="得分" label-width="70" class="item" :border-bottom="false">
						<u-input v-model="form.score" border type="number" placeholder="得分" />
					</u-form-item>
					<u-form-item label="满分" label-width="70" class="item" :border-bottom="false">
						<u-input v-model="form.fullScore" border type="number" placeholder="满分" />
					</u-form-item>
				</view>
			</u-form-item>
			<u-form-item label="通过日期:" label-position="top" :required="true">
				<u-input v-model="form.passedDate" placeholder="选择通过日期" type="select" @click="dateShow = true" border />
			</u-form-item>
			<u-form-item label="上传证书:" label-position="top" :border-bottom="false">
				<u-form-item label="证书名称" label-width="140" :border-bottom="false">
					<u-input v-model="form.certName" placeholder="请输入内容" border />
				</u-form-item>
				<u-form-item label="证书相片" label-width="140" :border-bottom="false">
					<u-upload :action="upload.action" :custom-btn="true" :limitType="['png', 'jpg']" :max-count="2" @on-success="uploadSuccess" @on-remove="uploadRemove">
						<view class="upload-button" slot="addBtn">
							<view class="upload-button-icon">
								<u-image src="../../../static/img/upload-add.png" mode="aspectFill" width="62"
									height="64" />
							</view>
							<view>上传相片</view>
						</view>
					</u-upload>
					<view class="tips">支持jpg.png格式</view>
				</u-form-item>
			</u-form-item>
		</u-form>
		<view class="achievement-submit">提交</view>
		<u-calendar v-model="dateShow" mode="date" @change="dateChange"></u-calendar>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					teamName: '',
					score: '',
					fullScore: '',
					passedDate: '',
					certName: '',
					picList: []
				},
				dateShow: false,
				upload: {
					action: this.config.uploadUrl
				}
			}
		},
		methods: {
			/**
			 * 日历选择器选中触发
			 * @param {Object} e
			 */
			dateChange(e) {
				this.form.passedDate = e.result;
			},
			/**
			 * 图片上传成功触发
			 * @param {Object} res
			 */
			uploadSuccess(res) {
				if (res.code === 200) {
					this.form.picList.push(res.data.url)
				} else {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'error'
					})
				}
			},
			/**
			 * 移除图片下标
			 * @param {Object} index
			 */
			uploadRemove(index) {
				this.form.picList.splice(index, 1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './addAchievementCertificate.scss';
</style>
