Browse Source

feat(questionnaire): validate future expectation

Developer 3 days ago
parent
commit
1ae4d5463b

+ 2 - 2
components/CusNotice/index2.vue

@@ -14,8 +14,8 @@
 				<div class="notice-box-content-p2">The following 36 statements describe the ideal state of a team. Please score the actual performance of the team being tested on each statement from two perspectives:</div>
 				<div class="notice-box-content-p1">1、同意度:1-5分共5个等级,假如您完全同意该团队当下达到了所描述的状态为5分,假如您完全不同意该团队当下达到了所描述的状态为1分</div>
 				<div class="notice-box-content-p2">Agreement: There are 5 levels ranging from 1 to 5. Score of 5 if you completely agree that the team has reached the statement. Score of 1 if you completely disagree.</div>
-				<div class="notice-box-content-p1">2、重要性:1-5分共5个等级,假如您认为所描述的状态对该团队当下非常重要为5分,假如您认为所描述的状态对该团队当下非常不重要为1分</div>
-				<div class="notice-box-content-p2">Importance: There are 5 levels ranging from 1 to 5. Score of 5 if you believe that the statement is extremely significant for the team at this moment. Score of 1 if you believe it is very insignificant.</div>
+				<div class="notice-box-content-p1">2、一年后期待:1-5分共5个等级,请评估团队在此项陈述方面一年后可达成的表现;一年后期待分必须高于现状评分。</div>
+				<div class="notice-box-content-p2">Future expectation: Rate the performance the team can achieve in one year from 1 to 5. The future expectation score must be higher than the current score.</div>
 				<div class="notice-box-content-p1">完成这个问卷调查大约需要15-20分钟。如有任何疑问,欢迎添加大衡同学企业微信联系。</div>
 				<div class="notice-box-content-p2">Completing these questions should take approximately 15-20 minutes. If you have any questions, please feel free to scan below QR code to contact with Transcend.</div>
 				<div class="notice-box-content-info adffcac">

+ 2 - 2
components/QuestionItem/index2.vue

@@ -45,7 +45,7 @@
 			return {
 				assessmentMethodCfg:{
 					'1':'您对团队当前在此项陈述上所描述的实际表现的同意程度为:',
-					'2':'此项陈述对该团队当前的重要性: '
+					'2':'您对团队在此项陈述方面一年后可达成表现的同意程度为:'
 				}
 			}
 		},
@@ -142,4 +142,4 @@
 			}
 		}
 	}
-</style>
+</style>

+ 2 - 2
components/QuestionItem/index3.vue

@@ -62,7 +62,7 @@
 			return {
 				assessmentMethodCfg:{
 					'1':'您对团队当前在此项陈述上所描述的实际表现的同意程度为:',
-					'2':'此项陈述对该团队当前的重要性: '
+					'2':'您对团队在此项陈述方面一年后可达成表现的同意程度为:'
 				}
 			}
 		},
@@ -116,4 +116,4 @@
 			}
 		}
 	}
-</style>
+</style>

+ 24 - 7
pagesPublish/questionnaireFill.vue

@@ -54,8 +54,9 @@
 <script>
 	import QuestionItem from '@/components/QuestionItem/index3.vue'
 	import CusNotice from '@/components/CusNotice/index2.vue'
-	import CusTeamInfo from '@/components/CusTeamInfo/index.vue'
-	import CusTeamUser from '@/components/CusTeamUser/index.vue'
+	import CusTeamInfo from '@/components/CusTeamInfo/index.vue'
+	import CusTeamUser from '@/components/CusTeamUser/index.vue'
+	const { validateFutureExpectation } = require('@/utils/perillScore.js')
 	export default {
 		components:{ CusNotice, QuestionItem, CusTeamInfo, CusTeamUser },
 		data(){
@@ -246,7 +247,7 @@
 					}
 				});
 			
-				if (firstUnansweredIndex > -1) {
+				if (firstUnansweredIndex > -1) {
 					uni.showModal({
 						title: '提示',
 						content: `第 ${firstUnansweredIndex + 1} 项未选择答案,请选择。`,
@@ -258,9 +259,25 @@
 							}
 						}
 					});
-					return; // 终止提交
-				}
-			
+					return; // 终止提交
+				}
+
+				let firstInvalidExpectationIndex = -1;
+				this.list.forEach((l, i) => {
+					const error = validateFutureExpectation(l.answer);
+					this.$set(l, 'warn', !!error);
+					if (error && firstInvalidExpectationIndex === -1) firstInvalidExpectationIndex = i;
+				});
+				if (firstInvalidExpectationIndex > -1) {
+					uni.showModal({
+						title: '提示',
+						content: '一年后期待分应高于现状评分,请注意!',
+						showCancel: false,
+						success: res => { if (res.confirm) this.scrollToQuestion(firstInvalidExpectationIndex); }
+					});
+					return;
+				}
+			
 				const submitList = this.list.map((l) => {
 					let {answer,userAnswer,warn,...other} = JSON.parse(JSON.stringify(l));
 					userAnswer.forEach(u=>{
@@ -485,4 +502,4 @@
 			}
 		}
 	}
-</style>
+</style>

+ 27 - 0
tests/perillScore.test.js

@@ -0,0 +1,27 @@
+const assert = require('node:assert/strict')
+const fs = require('node:fs')
+const path = require('node:path')
+const { validateFutureExpectation } = require('../utils/perillScore')
+
+const method = (assessmentMethod, score) => ({
+	assessmentMethod,
+	value: `${score}-分`
+})
+
+assert.equal(validateFutureExpectation([method('1', 3), method('2', 4)]), '')
+assert.equal(
+	validateFutureExpectation([method('1', 3), method('2', 3)]),
+	'一年后期待分应高于现状评分,请注意!'
+)
+assert.equal(
+	validateFutureExpectation([method('1', 3), method('2', '')]),
+	'一年后期待分应高于现状评分,请注意!'
+)
+
+const questionnaireConfig = fs.readFileSync(
+	path.join(__dirname, '../../ChuangHeng_new/src/views/modules/agent/questionnaireList.vue'),
+	'utf8'
+)
+assert.doesNotMatch(questionnaireConfig, /<el-option label="重要性" :value="2"><\/el-option>/)
+
+console.log('perill score rules: PASS')

+ 18 - 0
utils/perillScore.js

@@ -0,0 +1,18 @@
+function score(value) {
+	const match = String(value || '').trim().match(/^(\d+)/)
+	return match ? Number(match[1]) : null
+}
+
+function validateFutureExpectation(answerMethods) {
+	const methods = answerMethods || []
+	const current = methods.find(item => String(item.assessmentMethod) === '1')
+	const future = methods.find(item => String(item.assessmentMethod) === '2')
+	const currentScore = score(current && current.value)
+	const futureScore = score(future && future.value)
+	if (currentScore === null || futureScore === null || futureScore <= currentScore) {
+		return '一年后期待分应高于现状评分,请注意!'
+	}
+	return ''
+}
+
+module.exports = { validateFutureExpectation }