<template>
	<view class="index-wrap">
		<view class="content">
			<view class="title-h1">PDCA 循环法</view>
			<view class="banner"></view>
			<view class="txt-wrap">
				<view class="p-txt">
					PDCA循环由质量管理专家戴明于20世纪50年代优化完善并推广，又称“戴明环”，其核心是通过计划、执行、检查、处理四个阶段的闭环管理进行目标执行效果的持续改进，可适用于个人知识管理、技能提升等学习场景。
				</view>
				<view class="p-txt">
					<text class="strong-txt">Plan(计划)：</text>明确目标与步骤，包括现状分析、问题识别及解决方案制定。
				</view>
				<view class="p-txt">
					<text class="strong-txt">Do(执行)：</text>根据计划实施具体措施，如教学中的课堂授课、企业中的产品生产。
				</view>
				<view class="p-txt">
					<text class="strong-txt">Check(检查)：</text>评估执行效果，通过数据对比、因果图等方法发现偏差。
				</view>
				<view class="p-txt">
					<text class="strong-txt">Act(处理)：</text>总结经验并标准化流程，如将成功经验纳入培训体系或优化资源配置。
				</view>
			</view>
			<view class="title-h1">年度学习计划清单</view>
			<view class="txt-wrap">
				<view class="strong-txt mb30">
					请填写你的“年度学习计划清单”，并按照PDCA循环法执行和落实计划。
				</view>
				<view class="p-txt">
					说明:
				</view>
				<view class="gp-txt">
					<text class="strong-txt">（1）总目标：</text>
					期望达到的综合成就和发展方向，它是整个计划的核心和导向，如成为金融领域具有深厚理论基础和丰富实践经验的高端专业人才。
				</view>
				<view class="gp-txt">
					<text class="strong-txt">（2）课程学习：</text>
					为了达到总目标需完成的各类课程,包括通识教育课程、专业课程、选修课程等，如完成《计量经济学》的学习。
				</view>
				<view class="gp-txt">
					<text class="strong-txt">（3）实践活动：</text>
					为了达到总目标需参与的各类实践活动，如志愿服务、社团活动、实习实训、创新创业项目等，如加入金融学术社团。
				</view>
				<view class="gp-txt">
					<text class="strong-txt">（4）技能提升：</text>
					通过自学或参加培训等方式，提升个人技能，包括外语能力、计算机技能、专业技能等，如利用课余时间学习Python课程，并考取相应资格证书。
				</view>
				<view class="gp-txt">
					<text class="strong-txt">（5）职业规划：</text>
					对个人未来职业发展的系统性安排，核心包括职业方向定位、职业成就预期、职业路径设计等，如“通过投行实习明确方向一3年内成为分析师→5年内晋升经理”。 
				</view>
			</view>
			<view class="target-content">
				<view class="target-tabbar">
					<view class="item" :class="checkedTargetCode ==item.EncodeId?'on':''" v-for="(item,index) in targetList" :key="index" @click="changeTarget(item)">
						<text v-text=" '学习'+ tabs[index]"></text>
					</view>
				</view>
				<view class="desc-wrap">
					<view class="h3-title">
						目标描述
					</view>
					<view class="desc-txt">
						<text class="blue-txt">从【SMART目标制定】的数据中读取的内容:</text>
						<text v-text="targetForm.TargetDesc?targetForm.TargetDesc:'无'"></text>
					</view>
				</view>
				<view class="form-wrap">
					<view class="year-plan-item" v-for="(item,index) in planList" :key="index">
						<view class="plan-title">
							{{index+1}}年度计划
						</view>
						<view class="form-item">
							<view class="label">
								课程学习
							</view>
							<view class="input-wrap">
								<input v-model="item.CourseName" placeholder="通识教育课程、专业课程、选修课程等"></input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">
								实践活动
							</view>
							<view class="input-wrap">
								<input v-model="item.ActivityName" placeholder="志愿服务、社团活动、实习实训、创新创业项目等"></input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">
								技能提升
							</view>
							<view class="input-wrap">
								<input v-model="item.Ability" placeholder="外语能力、计算机技能、专业技能等，及计划考..."></input>
							</view>
						</view>
						<view class="form-item">
							<view class="label">
								职业规划
							</view>
							<view class="input-wrap">
								<input v-model="item.JobPlan" placeholder="职业方向定位、职业成就预期、职业路径设计等"></input>
							</view>
						</view>
						<view class="del-year-btn" @click="deletePlan(index)">
							删除该年度计划
						</view>
					</view>
				</view>
			</view>
			<view class="btn-wrap">
				<view class="add-btn" @click="addPlan"  v-show="planList.length<5">
					+增加年度计划
				</view>
				<view class="commit-btn" @click="commitForm">
					确认提交
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "@/packageCa/apiCa/studentProfile.js"
	import apiuser from "@/packageCa/apiCa/user.js"
	export default {
		data() {
			return {
				tabs:['目标一 ', '目标二 ', '目标三 ', '目标四 ', '目标五 '],
				targetForm: {}, //当前选中的目标
				targetList: [],//目标列表
				checkedTargetCode: "",// 目标码
				planList: [],  //年度计划列表
				emptyPlanList: [
					{
						EncodeId: '',//Id
						CourseName: '',//课程学习
						ActivityName: '',//实践活动 
						Ability: '',//技能提升 
						JobPlan: ''//职业规划
					}
				],  //空
				delIds:[],//删除的计划id
			}
		},
		created() {
			this.queryPlanList();
		},
		methods: {
			// 添加日志
			postLog(operationType, remarks, beforeData = "", afterData = ""){
				try {
				  const data = {
				    OperationType: operationType,
				    Remarks: remarks,
				    BeforeOperationJson: beforeData,
				    AfterOperationJson: afterData
				  };
					console.log(data);
				  // return;
				  // 异步记录日志，不阻塞主流程
				  apiuser.saveUserOperationLog(data).then((res) => {
				    console.log('[Operation Log] 记录成功', res);
				  }).catch((err) => {
				    console.error('[Operation Log] 记录失败', err);
				  });
				} catch (e) {
				  console.error('[Operation Log] 记录异常', e);
				}
			},
			// 切换目标标签
			changeTarget(ITEM){
				if(ITEM.EncodeId == this.checkedTargetCode){
					return;
				}
				this.checkedTargetCode = ITEM.EncodeId;
				this.targetForm = this.targetList.filter(item=>item.EncodeId == ITEM.EncodeId)[0];
				this.queryPlanList();
			},
			// 获取学习目标
			async querySmartTargets() {
				const res = await api.querySmartTargets();
				if (res.Result == 1) {
					this.targetList = res.Data;
					if(res.Data.length>0){
						this.checkedTargetCode = res.Data[0].EncodeId;
						this.targetForm = res.Data[0];
					}
				} else {
					uni.showToast({
						title: res.Message,
						icon: "none"
					})
				}
			},
			// 获取单个获取年度计划
			async queryPlanList() {
				if(this.targetList.length == 0){
					await this.querySmartTargets();
				}
				if(!this.checkedTargetCode){
					return;
				}
				const res = await api.queryPlanList(this.checkedTargetCode);
				if (res.Result == 1) {
					this.planList = res.Data;
					if(res.Data.length == 0){
						this.planList = JSON.parse(JSON.stringify(this.emptyPlanList));
					}
				} else {
					uni.showToast({
						title: res.Message,
						icon: "none"
					})
				}
			},
			// 增加年度计划
			addPlan(){
				 this.planList.push({...this.emptyPlanList[0]});
			},
			// 删除年度计划
			deletePlan(INDEX){
				if (this.planList[INDEX].EncodeId != '') {
					this.delIds.push(this.planList[INDEX].EncodeId)
				}
				this.planList.splice(INDEX, 1);
			},
			//确认表单
			async commitForm() {
				uni.showLoading({
					title: "保存中..."
				}) 
				const data = {
					EncodeId: this.checkedTargetCode,
					PlanList: this.planList,
					DelIds: this.delIds,
				}
				const res = await api.savePlanList(data);
				uni.hideLoading();
				if (res.Result == 1) {
					uni.showToast({
						title: "保存成功",
						icon: "success"
					})
					this.queryPlanList();
					this.delIds=[];
					this.postLog(302,`【新增】新增了学习计划`,"",JSON.stringify(data))
				} else {
					uni.showToast({
						title: res.Message,
						icon: "none"
					})
				}
			},
		}
	}
</script>
<style lang="scss">
	$image-oss-url: "https://51xuanxiao.oss-cn-hangzhou.aliyuncs.com/Resource/xcx_sygh";
	page {
		background: #f4f7fc url("#{$image-oss-url}/17.png") no-repeat;
		background-size: contain;
		overflow-y: scroll;
	}
</style>
<style lang="scss" scoped>
	$image-oss-url: "https://51xuanxiao.oss-cn-hangzhou.aliyuncs.com/Resource/xcx_sygh";
	.head-bar {
		position: relative;
	    text-align: center;
	    font-size: 36rpx;
	    font-weight: 600;
	    height: 60rpx;
	    line-height: 60rpx;
		.go-back {
		    position: absolute;
		    left: 10rpx;
		    top: 0;
		    width: 60rpx;
		    height: 60rpx;
		    background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABUklEQVRoQ+3ZOwrCQBCA4UlyCVsrQauQdPYewcNYWXoHK1s9gYeYdIKlracYWYggkgiTnccuaB3D/+1sYEMKyPxXZN4Pf0DMBOu6XpZluQOANRGduq7bc+/nNoE+/gwAq3c0IrJ72H/grtDQ9UPxAPBAxDn3/uaAkfjQvUXES9IA6fiANZuARrwZQCveBKAZrw7QjlcFWMSrAaziVQCW8eIA63hRgEe8GMArXgTgGR8N8I6PAqQQPxmQSvxkQNM0VwDYfJ3dJ53nuef/7+vZx+l+9W8pxE+aQNu2CyK6ZwsI4VlvoQDI/iFOCcF+iD/3fgqTiAKkMIlogDdCBOCJEAN4IUQBHghxgDVCBWCJUANYIVQBFgh1gDbCBKCJMANoIUwBGghzwA/EExFn3HdkF8AYIpvPrO9VDu8TVVUdiKghomNWH7q5W2Xserct9Af0K/AChQ/cMY9OGScAAAAASUVORK5CYII=") center no-repeat;
		    background-size: 38rpx 38rpx;
		}
	}
	.index-wrap {
		.content {
			padding-top: 40rpx;
			.title-h1 {
				font-size: 36rpx;
				color: #333;
				padding: 20rpx 30rpx;
				font-weight: 600;
			}
			.banner {
				width: 100%;
				height: 423rpx;
				background: url("#{$image-oss-url}/gaoxiao/academicEvaluation/pdca-banner.png");
				background-size: 100%;
			}
			.txt-wrap {
				padding: 50rpx 30rpx 20rpx;
				background: #fff;
				.p-txt {
					font-size: 28rpx;
					line-height: 48rpx;
					color: #333333;
					margin-bottom: 20rpx;
				}
				.gp-txt {
					font-size: 28rpx;
					line-height: 48rpx;
					color: #666;
					margin-bottom: 20rpx;
				}
				.mb30 {
					margin-bottom: 30rpx;
				}
				.strong-txt {
					color: #333333;
					font-weight: 600;
				}
			}
			.target-content {
				background: #fff;
				padding: 40rpx 30rpx 0;
				margin-top: 40rpx;
				.target-tabbar {
					margin-bottom: 30rpx;
					display: flex;
					flex-wrap: wrap;
					.item {
						position: relative;
						width: 150rpx;
						height: 64rpx;
						line-height: 64rpx;
						text-align: center;
						border-radius: 34rpx;
						border: solid 2rpx #eeeeee;
						font-size: 26rpx;
						color: #999999;
						margin-right: 20rpx;
						margin-bottom: 20rpx;
						&.on {
							color: #1989fa;
							border-color: #1989fa;
						}
					}
				}
				.desc-wrap {
					margin-bottom: 40rpx;
					.h3-title {
						color: #333333;
						font-size: 28rpx;
						margin-bottom: 20rpx;
					}
					.desc-txt {
						color: #666666;
						font-size: 28rpx;
						line-height: 48rpx;
						.blue-txt {
							color: #1989fa;
						}
					}
				}
				.form-wrap {
					padding-bottom: 40rpx;
					.year-plan-item {
						.plan-title {
							display: flex;
							align-items: center;
							justify-content: center;
							color: #333333;
							font-size: 32rpx;
							padding: 50rpx 0;
							font-weight: 600;
							&:before {
								content: "";
								display: block;
								width: 18rpx;
								height: 6rpx;
								margin-right: 40rpx;
								background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAADBAMAAACzJDhFAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAALVBMVEUZifoqkvrW6v3t9f4Zifrt9f7W6v1BnftdrPt8u/ybzPy62/0qkvrW6v0AAAA9scLEAAAAB3RSTlOF+fmF+fP6+pjy2gAAAAFiS0dEDm+9ME8AAAAHdElNRQfpChgQCQN2b864AAAAGUlEQVQI12NgrJi1yYDBp2LW3gAGIHubAQA3mgZaYkKVQgAAAABJRU5ErkJggg==");
								background-size: 100%;
							}
							&::after {
								content: "";
								display: block;
								margin-left: 40rpx;
								width: 18rpx;
								height: 6rpx;
								background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAADBAMAAACzJDhFAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAALVBMVEX+/v7t9f5Bnfsqkvr+/v4qkvpBnfvW6v262/2bzPx8u/xdrPvt9f5BnfsAAADw0cYcAAAAB3RSTlOF+fmF+fP6+pjy2gAAAAFiS0dEDm+9ME8AAAAHdElNRQfpChgQCQmWuiemAAAAGUlEQVQI12NgrJi1yYDBp2LW3gAGIHubAQA3mgZaYkKVQgAAAABJRU5ErkJggg==");
								background-size: 100%;
							}
						}
						.form-item {
							.label {
								font-size: 28rpx;
								color: #333333;
								margin-bottom: 30rpx;
							}
							.input-wrap {
								margin-bottom: 40rpx;
								input {
									width: 650rpx;
									height: 76rpx;
									line-height: 76rpx;
									padding:  0 20rpx;
									background-color: #ffffff;
									border-radius: 6rpx;
									border: solid 2rpx #eeeeee;
									font-size: 28rpx;
									&::-webkit-input-placeholder {
										color: #bebebe;
										font-size: 28rpx;
									}
								}
							}
						}
						.del-year-btn {
							width: 686rpx;
							height: 74rpx;
							line-height: 74rpx;
							text-align: center;
							border-radius: 6rpx;
							margin-top: 50rpx;
							border: solid 2rpx #ff625f;
							color: #ff6157;
							font-size: 32rpx;
						}
					}
				
				}
			}
			.btn-wrap {
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 50rpx 30rpx;
				.commit-btn {
					width: 335rpx;
					height: 80rpx;
					background-color: #1989fa;
					border-radius: 40rpx;
					font-size: 28rpx;
					color: #fff;
					text-align: center;
					line-height: 80rpx;
				}
						
				.add-btn {
					width: 331rpx;
					height: 76rpx;
					font-size: 28rpx;
					text-align: center;
					line-height: 76rpx;
					border-radius: 40rpx;
					color: #1989fa;
					border: solid 2rpx #1989fa;
					margin-right: 20rpx;
				}
			}
		}
	}
</style>