<template>
	<view class="personal-reporting">
		<view class="student-management">
			<view class="form-item">
				<label>01 指导学生取得第二课堂学分奖励</label>
				<input type="number" v-model="passs" placeholder="请填写所带学生第二课堂合格人数"
					placeholder-class="input-placeholder" />
			</view>
			<view class="form-item" @tap="toinstructorJobPerformance">
				<label>02 辅导员工作业绩填报</label>
				<uni-icons type="right" size="16" color="#202020"></uni-icons>
			</view>
			<view class="form-item" @tap="toundertakeStudentWorkAssignments">
				<label>03 承接区级、校级学生工作任务</label>
				<uni-icons type="right" size="16" color="#202020"></uni-icons>
			</view>
			<view class="form-item" @tap="toholdAPost">
				<label>04 担任职务</label>
				<uni-icons type="right" size="16" color="#202020"></uni-icons>
			</view>
			<view class="form-item" @tap="tomajorReward">
				<label>04 重大任务奖励</label>
				<uni-icons type="right" size="16" color="#202020"></uni-icons>
			</view>
		</view>
		<view class="btns" v-if="substatus!=1">
			<button type="primary" class="save" style="margin-right: 25rpx;" @tap="onSave">保存</button>
			<button type="primary" class="next-page" @tap="onSubmit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		servingUpdate
	} from '../../../../api/compositive-performance/holdAPost';
	import {
		toBackPage
	} from "@/utils/toBack.js"
	import {
		getCurrentDateTime
	} from "@/utils/getCurrentDateTime.js"
	import {
		performanceUpdate,
		passAdd,
		passUpdate,
		getInfoByFdNameAndYears
	} from '@/api/compositive-performance/index.js';
	export default {
		data() {
			return {
				year: "", //年份
				reportingId: "", //填报记录id
				passs: "", //第二课堂合格人数
				passsId: "", //第二课堂详情id
				substatus: "", //提交状态
			}
		},
		onLoad(option) {
			this.year = option.year;
			this.reportingId = option.id;
			this.substatus = option.substatus;
			this.getPassStuByFdNameAndYears();
		},
		methods: {
			async getPassStuByFdNameAndYears() {
				let res = await getInfoByFdNameAndYears({
					fdName: uni.getStorageSync("stuName"),
					years: this.year,
				})
				if (res.data) {
					this.passs = res.data.passs;
					this.passsId = res.data.id;
				}

			},
			toinstructorJobPerformance() {
				console.log(this.reportingId);
				uni.navigateTo({
					url: `./instructorJobPerformance/list?year=${this.year}&substatus=${this.substatus}`
				})
			},
			toholdAPost() {
				uni.navigateTo({
					url: `./holdAPost/list?year=${this.year}&substatus=${this.substatus}`
				})
			},
			toundertakeStudentWorkAssignments() {
				uni.navigateTo({
					url: `./undertakeStudentWorkAssignments/list?year=${this.year}&substatus=${this.substatus}`
				})
			},
			tomajorReward() {
				uni.navigateTo({
					url: `./majorReward/list?year=${this.year}&substatus=${this.substatus}`
				})
			},
			async onSave() {
				if (this.reportingId && this.passsId == "") {
					let res = await passAdd({
						fdName: uni.getStorageSync("stuName"),
						years: this.year,
						passs: this.passs,

					});
					if (res.code == 200) {
						uni.showToast({
							title: "保存成功",
							icon: "none"
						})
						toBackPage(500);
					}
				} else {
					let res = await passUpdate({
						fdName: uni.getStorageSync("stuName"),
						years: this.year,
						passs: this.passs,
						id: this.passsId
					});
					if (res.code == 200) {
						uni.showToast({
							title: "保存成功",
							icon: "none"
						})
						toBackPage(500);
					}
				}
			},
			onSubmit() {
				uni.showModal({
					title: "确定提交吗?",
					success: async (bool) => {
						if (bool.confirm) {
							if (this.reportingId && this.passsId == "") {
								let res = await passAdd({
									fdName: uni.getStorageSync("stuName"),
									years: this.year,
									passs: this.passs,

								});
								if (res.code == 200) {
									this.performanceUpdate()
								}
							} else {
								let res = await passUpdate({
									fdName: uni.getStorageSync("stuName"),
									years: this.year,
									passs: this.passs,
									id: this.passsId
								});
								if (res.code == 200) {
									this.performanceUpdate()
								}
							}
						}
					}
				})

			},
			performanceUpdate() {
				let formData = {
					id: this.reportingId,
					college: uni.getStorageSync("deptName"),
					fdTime: getCurrentDateTime(),
					fdName: uni.getStorageSync("stuName"),
					years: this.year,
					substatus: 1,
				}
				performanceUpdate(formData).then((result) => {
					if (result.code == 200) {
						uni.showToast({
							title: "提交成功"
						})
						toBackPage(500);
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.personal-reporting {
		background-color: #f5f5f7;
		height: calc(100vh - 44px);
		padding: 40rpx;

		.student-management {
			.form-item {
				padding: 22rpx 40rpx 40rpx 40rpx;
				background-color: white;
				margin-bottom: 40rpx;
				border-radius: 16rpx;

				label {
					margin-bottom: 20rpx;
					display: inline-block;
					font-size: 26rpx;
					color: #404040;
				}

				input {
					border: 1px solid #E1E1E1;
					border-radius: 10rpx;
					height: 60rpx;
					padding-left: 30rpx;

					.input-placeholder {
						color: #b6b6b6;
					}
				}

				&:not(:first-child) {
					padding: 0 40rpx;
					height: 50px;
					line-height: 50rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					label {
						margin: 0;
					}
				}
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			display: flex;
			margin-top: 100rpx;
			padding: 20rpx 20rpx;
			background-color: white;

			button {
				flex: 1;
				height: 44px;
			}

			.save {
				background-color: transparent;
				color: #1890FF;
				border: 1px solid #1890FF;
				margin-right: 40rpx;
			}
		}
	}
</style>