Browse Source

增加合并选项功能

wangjian 1 tuần trước cách đây
mục cha
commit
df163ab27c

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
     "name" : "uni-app-demo",
-    "appid" : "__UNI__797F817",
+    "appid" : "__UNI__5EC4523",
     "description" : "demo",
     "versionName" : "1.0.0",
     "versionCode" : "100",

+ 106 - 8
pagesAdmin/satisfaction/business/satisfactionQuestions/satisfactionQuestions.vue

@@ -20,6 +20,7 @@
 					<view
 						class="ques_item_box"
 						:id="'p' + index"
+						v-if="!isQuestionHidden(item)"
 						:class="item.QuestType == 'SubTitle' ? 'sub_title' : ''"
 					>
 						<view class="ques_title_box">
@@ -27,6 +28,28 @@
 							<text v-if="item.QuestType != 'SubTitle'">{{ item.Sort }}.{{ item.Question }}</text>
 							<text v-if="item.QuestType == 'SubTitle'">{{ item.Num }}、{{ item.Question }}</text>
 						</view>
+						<!-- 大标题满意度 -->
+						<view
+							class="ques_options displayFlexCol"
+							v-if="item.QuestType == 'SubTitle' && item.HasScaleInSubtitle"
+						>
+							<block
+								v-for="(childItem, childIndex) in subtitleSatisfactionOptions"
+								:key="`SubTitleSatisfaction-${index}-${childIndex}`"
+							>
+								<text
+									class="choice_item"
+									:class="
+										isSubtitleSatisfactionActive(item.SubTitleIndex, childIndex) ? 'active_option' : ''
+									"
+									:data-subtitleindex="item.SubTitleIndex"
+									:data-childindex="childIndex"
+									@click="choiceSubtitleSatisfaction"
+								>
+									{{ childItem }}
+								</text>
+							</block>
+						</view>
 						<!-- 填空题 -->
 						<view
 							class="ques_options align_items_left displayFlexCol"
@@ -319,6 +342,8 @@ const quesList = ref({} as any);
 const imgList = ref([]);
 const point = ref('');
 const complete = ref(false);
+const subtitleSatisfactionOptions = ['非常满意', '比较满意', '一般', '不太满意', '很不满意'];
+const subtitleSatisfaction = reactive({} as Record<string, number | null>);
 const anonymousType = ref(0);
 const showModal_Anonymous = ref(false); // 是否实名填写弹窗显示
 const showModal_User = ref(false); // 实名用户选择弹窗显示
@@ -540,6 +565,8 @@ const getSec = () => {
 const bySort = (list: any[]) => {
 	let find = 0;
 	let sort = 0;
+	let currentSubTitleIndex = -1;
+	let currentSubTitleItem = null as any;
 	let item = {} as any;
 	for (var t = 0; t < list.length; t++) {
 		item = list[t];
@@ -549,12 +576,20 @@ const bySort = (list: any[]) => {
 			sort = 0;
 			//判断是出现的第几个子标题
 			//num是子标题的排序
+			item.SubTitleIndex = find;
+			item.HasScaleInSubtitle = false;
+			currentSubTitleIndex = find;
+			currentSubTitleItem = item;
 			item.Num = toChinesNum(find + 1);
 			find++;
 		} else {
 			//sort是子标题底下的排序
+			item.SubTitleIndex = currentSubTitleIndex;
 			item.Sort = sort + 1;
 			sort++;
+			if (item.QuestType == 'Scale' && currentSubTitleItem) {
+				currentSubTitleItem.HasScaleInSubtitle = true;
+			}
 		}
 		item.SortNum = t;
 		if (common.isNotEmpty(item.QuestionItemList)) {
@@ -593,6 +628,57 @@ const toChinesNum = (num) => {
 };
 
 /** 单选/多选/量表 */
+const isSubtitleScaleExpanded = (subtitleIndex) => {
+	return Number(subtitleSatisfaction[subtitleIndex]) > 0;
+};
+
+const isSubtitleSatisfactionActive = (subtitleIndex, childIndex) => {
+	return Number(subtitleSatisfaction[subtitleIndex]) === Number(childIndex);
+};
+
+const isQuestionHidden = (item) => {
+	return item?.QuestType == 'Scale' && item.SubTitleIndex > -1 && !isSubtitleScaleExpanded(item.SubTitleIndex);
+};
+
+const getAnswerIndex = (answerList, questId) => {
+	let answerIndex = -1;
+	answerList.forEach((item, index) => {
+		if (item.QuestId == questId) {
+			answerIndex = index;
+		}
+	});
+	return answerIndex;
+};
+
+const setSingleQuestionAnswer = (question, answerList, childIndex) => {
+	if (!question?.QuestionItemList?.[childIndex]) return;
+	const answerIndex = getAnswerIndex(answerList, question.QuestId);
+	const answer = question.QuestionItemList[childIndex].ItemId;
+	question.AnswerList = [answer];
+	if (answerIndex > -1) {
+		answerList[answerIndex].Answer = answer;
+	}
+};
+
+const choiceSubtitleSatisfaction = (e) => {
+	const subtitleIndex = Number(e.currentTarget.dataset.subtitleindex);
+	const childIndex = Number(e.currentTarget.dataset.childindex);
+	const questionList = quesList.value.QuestionList;
+	const answerList = quesAnswers.AnswerList;
+	subtitleSatisfaction[subtitleIndex] = childIndex;
+
+	if (childIndex == 0) {
+		questionList.forEach((item) => {
+			if (item.SubTitleIndex == subtitleIndex && item.QuestType == 'Scale') {
+				setSingleQuestionAnswer(item, answerList, 0);
+			}
+		});
+	}
+
+	quesList.value.QuestionList = questionList;
+	quesAnswers.AnswerList = answerList;
+};
+
 const choiceOption = (e) => {
 	let index = e.currentTarget.dataset.index;
 	let childIndex = e.currentTarget.dataset.childindex;
@@ -903,10 +989,28 @@ const setVal = (e) => {
 };
 
 /** 提交 */
+const validateSubtitleSatisfaction = () => {
+	const questionList = quesList.value.QuestionList || [];
+	for (var i = 0; i < questionList.length; i++) {
+		const item = questionList[i];
+		if (
+			item.QuestType == 'SubTitle' &&
+			item.HasScaleInSubtitle &&
+			subtitleSatisfaction[item.SubTitleIndex] == null
+		) {
+			common.showToast('存在未填写的问卷');
+			point.value = 'p' + i;
+			return false;
+		}
+	}
+	return true;
+};
+
 const submit = () => {
 	throttle(async () => {
 		await common.sleep(1000);
 		if (complete.value) return;
+		if (!validateSubtitleSatisfaction()) return;
 		uni.showLoading();
 		const answers = { ...quesAnswers } as any;
 		for (var i = 0; i < answers.AnswerList.length; i++) {
@@ -931,23 +1035,17 @@ const submit = () => {
 		queryPatient.cardNo = cardNo;
 		queryPatient.cardType = cardType;
 		let patientInfoRes = await QueryMemberByCard_V3(queryPatient);
-		console.log('患者信息:', patientInfoRes);
 		let patientInfo = patientInfoRes.resData;
-		console.log('患者信息:', patientInfo);
 		if (!patientInfo) {
 		  uni.hideLoading();
 		  return;
 		}
-		
-		console.log('患者信息:', patientInfo);
-		
+
 		if (patientInfo.RespCode === '10000' && patientInfo.Data && patientInfo.Data.length > 0) {
 		  mobile = patientInfo.Data[0].mobile;
 		  memberName = patientInfo.Data[0].memberName;
 		}
-		console.log('mobile:', mobile);
-		console.log('memberName:', memberName);
-		
+
 		answers.AnswerList = JSON.stringify(quesAnswers.AnswerList);
 		// 安全读取 currentUser 字段,缺失则置空
 		const memberId = currentUser.value?.MemberId ?? currentUser.value?.memberId ?? currentUser.value?.cardNo ?? ''