Ver Fonte

接口复制

柒零 há 1 ano atrás
pai
commit
6c9c952a3c

+ 1 - 0
componets/authorized-login-dialog/authorizedLoginDialog.js

@@ -78,6 +78,7 @@ Component({
       this.setData({
         nickName: nickName,
       })
+      wx.setStorageSync('nickName', nickName);
       this.checkHasUserInfo();
     },
     // 输入手机号

+ 127 - 54
subpages/sleepEvaluation/sleepEvaluation.js

@@ -1,8 +1,15 @@
 const baseUrl = "https://fare.somnisix.top/";
 const authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
 const api = "system/sleepEvaluation";
+
+const homeApi = "https://fare.somnisix.top";
+const homeApiTest = "http://localhost:8080";
+const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
+
+
 Page({
 	data: {
+
 		activeIcon: "/subpages/icons/ic_selected_radio.svg",
 		normalIcon: "/subpages/icons/ic_radio.svg",
 		activeColor: "color:#0BC3AA;",
@@ -120,7 +127,9 @@ Page({
 		channel: '',//您是通过什么渠道预定到的本酒店睡眠房?
 		hotel: '',//酒店
 		room: '',//房间
-		mInputId: ''//自动滚动用的
+		mInputId: '',//自动滚动用的
+		intervalId1: null,
+		intervalId2: null,//授权解除定时任务
 	},
 
 	// 处理性别选择  
@@ -279,7 +288,7 @@ Page({
 			if (type == "wayImprovementSleep") {
 				var tempList = that.data.wayImprovementSleep
 				if (!tempList || (Array.isArray(tempList) && (!tempList.length || !tempList.includes(value)))) {
-					valueList[valueList.length ] = value
+					valueList[valueList.length] = value
 					that.setData({
 						wayImprovementSleep: valueList
 					})
@@ -331,33 +340,44 @@ Page({
 	},
 	// 提交问卷的函数  
 	submitSurvey: function () {
-
+		var that = this;
+		const { nickName } = wx.getStorageSync('userInfo');
+		const unionid = wx.getStorageSync('unionid');
+		console.log('nickName==' + nickName);
+		console.log('unionid==' + unionid);
 		let surveyData = {
 			hotel: this.data.hotel,
 			room: this.data.room,
 			gender: this.data.gender,
 			stayExper: this.data.stayExper,
-			sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
-			productComfort: this.data.productComfort,
-			improvementAreas: this.data.improvementAreas,
-			satisfied: this.data.satisfied,
+			userId: nickName,
+			id2: unionid,
+
+			//sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
+			//productComfort: this.data.productComfort,
+			//improvementAreas: this.data.improvementAreas,
+
+			satisfied: (!this.data.satisfied || this.data.satisfied.length === 0) ? '' : (Array.isArray(this.data.satisfied) ? this.data.satisfied.map(item => String(item)).join(',') : this.data.satisfied),
 			suggestion: this.data.suggestion,
 			career: this.data.career,
 			careerInput: this.data.careerInput,//1
 			thirdPlatformsInput: this.data.thirdPlatformsInput,//2
-			noSatisfied: this.data.noSatisfied,
+			noSatisfied: (!this.data.noSatisfied || this.data.noSatisfied.length === 0) ? '' : (Array.isArray(this.data.noSatisfied) ? this.data.noSatisfied.map(item => String(item)).join(',') : this.data.noSatisfied),
 			noSatisfiedInput: this.data.noSatisfiedInput,//3
-			improvementSleep: this.data.improvementSleep,
-			wayImprovementSleep: this.data.wayImprovementSleep,
+			improvementSleep: (!this.data.improvementSleep || this.data.improvementSleep.length === 0) ? '' : (Array.isArray(this.data.improvementSleep) ? this.data.improvementSleep.map(item => String(item)).join(',') : this.data.improvementSleep),
+			wayImprovementSleep: (!this.data.wayImprovementSleep || this.data.wayImprovementSleep.length === 0) ? '' : (Array.isArray(this.data.wayImprovementSleep) ? this.data.wayImprovementSleep.map(item => String(item)).join(',') : this.data.wayImprovementSleep),
 			wayImprovementSleepInput: this.data.wayImprovementSleepInput,//4
-			getSleepHealth: this.data.getSleepHealth,
+			getSleepHealth: (!this.data.getSleepHealth || this.data.getSleepHealth.length === 0) ? '' : (Array.isArray(this.data.getSleepHealth) ? this.data.getSleepHealth.map(item => String(item)).join(',') : this.data.getSleepHealth),
 			getSleepHealthInput: this.data.getSleepHealthInput,//5
-			influenceSleep: this.data.influenceSleep,
+			influenceSleep: (!this.data.influenceSleep || this.data.influenceSleep.length === 0) ? '' : (Array.isArray(this.data.influenceSleep) ? this.data.influenceSleep.map(item => String(item)).join(',') : this.data.influenceSleep),
 			influenceSleepInput: this.data.influenceSleepInput,//6
-			improvSleepMethods: this.data.improvSleepMethods,
+			improvSleepMethods: (!this.data.improvSleepMethods || this.data.improvSleepMethods.length === 0) ? '' : (Array.isArray(this.data.improvSleepMethods) ? this.data.improvSleepMethods.map(item => String(item)).join(',') : this.data.improvSleepMethods),
 			improvSleepMethodsInput: this.data.improvSleepMethodsInput,//7
 			age: this.data.age,
 			channel: this.data.channel,
+			//数据库存的是:bindGetSleepHealth bindGetSleepHealthInput
+			bindGetSleepHealth: (!this.data.getSleepHealth || this.data.getSleepHealth.length === 0) ? '' : (Array.isArray(this.data.getSleepHealth) ? this.data.getSleepHealth.map(item => String(item)).join(',') : this.data.getSleepHealth),
+			bindGetSleepHealthInput: this.data.getSleepHealthInput,
 		};
 
 		let checkList = {
@@ -383,7 +403,7 @@ Page({
 
 		let checkInputList = [
 			{
-				name:"career",
+				name: "career",
 				type: "radio",
 				checkList: this.data.career,
 				checkValue: "5",
@@ -430,8 +450,6 @@ Page({
 		var isFinish = true;
 		var emptyKey = "";
 
-		const that = this;
-
 		for (const key in checkList) {
 			if (checkList.hasOwnProperty(key)) {
 				const element = checkList[key];
@@ -461,7 +479,7 @@ Page({
 
 		for (let i = 0; i < checkInputList.length; i++) {
 			const element = checkInputList[i];
-			if ((element.type == 'checkbox' && Array.isArray(element.checkList) && element.checkList.includes(element.checkValue) && !element.checkInput) || (element.type == 'radio' && element.checkList == element.checkValue  && !element.checkInput) ) { // 检查属性值是否为空  
+			if ((element.type == 'checkbox' && Array.isArray(element.checkList) && element.checkList.includes(element.checkValue) && !element.checkInput) || (element.type == 'radio' && element.checkList == element.checkValue && !element.checkInput)) { // 检查属性值是否为空  
 				// 这里可以添加更复杂的判断,比如仅针对字符串检查是否为空字符串  
 				// if (typeof obj[key] === 'string' && obj[key].trim() === '') {  
 				isFinish = false;
@@ -482,7 +500,7 @@ Page({
 				})
 				return; // 停止循环  
 			}
-			
+
 		}
 
 		if (!isFinish) {
@@ -506,44 +524,50 @@ Page({
 		// 将surveyData发送到服务器  
 		console.log('提交的问卷数据:', surveyData);
 
-		//后边会提交到数据库
-		//   wx.request({
-		//   url: `${aipushApi}/getdatefromsn`, //
-		//   method: 'POST',
-		// 	header: {
-		// 		  'content-type': 'application/json', // 默认值
-		// 		  'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
-		// 	 },
-		// 	data:{
-		// 	     "surveyData":surveyData,"token":"token_push"
-		// 	 },
-		//   success(res) {
-		// 	wx.showToast({
-		// 	  title: '问卷提交成功',  
-		// 	  icon: 'success',  
-		// 	  duration: 2000  
-		// 	}); 
-
-		//   },
-		//   fail: function (error) {
-		// 	  console.error('error', error);  
-		// 	} ,
-		//   complete: function (e) {
-		//   }
-		// });	
-
-
-		wx.showToast({
-			title: '问卷提交成功',
-			icon: 'success',
-			duration: 2000,
-			success() {
-				setTimeout(() => {
-					wx.navigateBack()
-				}, 1500);
+		//提交到数据库
+		wx.request({
+			url: `${homeApi}/system/sleepEvaluation`, //
+			method: 'POST',
+			header: {
+				'content-type': 'application/json', // 默认值
+				'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
+			},
+			data: surveyData,
+			success(res) {
+				console.log('res===' + JSON.stringify(res));
+				console.log('res.code===' + res.code);
+				if (res && res.data && res.data.code == 200) {
+					if (that.data.intervalId1) {
+						clearInterval(that.data.intervalId1);
+						that.data.intervalId1 = null;
+					}
+					wx.showToast({
+						title: '问卷提交成功',
+						icon: 'success',
+						duration: 2000,
+						success() {
+							setTimeout(() => {
+								wx.navigateBack()
+							}, 1500);
+						}
+					});
+
+				}
+			},
+			fail: function (error) {
+				console.error('error', error);
+			},
+			complete: function (e) {
 			}
 		});
 
+
+		// wx.showToast({
+		// 	title: '问卷提交成功',
+		// 	icon: 'success',
+		// 	duration: 2000
+		// });
+
 		// 清空表单:  
 		// this.setData({  
 		// gender: '', 
@@ -632,15 +656,64 @@ Page({
 			});
 		}
 	},
+	submitDB: function () {
+		var that = this;
+		if (!that.data.intervalId1) {
+			that.data.intervalId1 = setInterval(() => {
+				that.submitSurvey();
+			}, 1000);
+		}
+	},
+	onShow: function (options) {
+		// var that = this;
+		// if (!that.data.intervalId2) {
+		// 	that.data.intervalId2 = setInterval(() => {
+		// 		// 这里执行你的代码  
+		// 		console.log('sleepEvaluation页面:'+Date.now());
+		// 	}, 10000);
+		// }
+	},
+	// startInterval: function () {
+	// 	 var that = this;
+	// 	 if (!that.data.intervalId) {
+	// 	 	that.data.intervalId = setInterval(() => {
+	// 	 		that.submitSurvey();
+	// 	 	}, 1000);
+	// 	 }  
+	// },
+	// clearInterval: function () {
+	// 	   var that = this;
+	//   	   if (that.data.intervalId) {
+	//   		 clearInterval(that.data.intervalId);  
+	//   		 that.data.intervalId = null;
+	//   	   }
+	//   },
 	/**
 	 * 生命周期函数--监听页面隐藏
 	 */
 	onHide: function () {
+		var that = this;
+		if (that.data.intervalId1) {
+			clearInterval(that.data.intervalId1);
+			that.data.intervalId1 = null;
+		}
+		// if (this.data.intervalId2) {
+		// 	clearInterval(this.data.intervalId2);
+		// 	this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误  
+		// }
 	},
 	/**
 	 * 生命周期函数--监听页面卸载
 	 */
 	onUnload: function () {
-
+		var that = this;
+		if (that.data.intervalId1) {
+			clearInterval(that.data.intervalId1);
+			that.data.intervalId1 = null;
+		}
+		// if (this.data.intervalId2) {
+		// 	clearInterval(this.data.intervalId2);
+		// 	this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误  
+		// }
 	},
 });

+ 208 - 11
subpages/sleepQualityIndexAssessment/sleepQualityIndexAssessment.js

@@ -1,3 +1,4 @@
+// miniprogram/pages/testSAS/testSAS.js
 // const db = wx.cloud.database()
 const baseUrl = "https://fare.somnisix.top/";
 const authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
@@ -5,6 +6,11 @@ const api = "system/questionInvest";
 const qnaire = require("./data.js")
 var ans = new Array(24)
 var ansJson = []
+
+const homeApi = "https://fare.somnisix.top";
+const homeApiTest = "http://localhost:8080";
+const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
+
 Page({
 	data: {
 		qnaire: [],
@@ -17,8 +23,8 @@ Page({
 		currentDateItem: null,
 		answerJson: [],
 		columns: [[], []],
-		BMI: null, 
-		mInputScrollId:null,
+		BMI: null,
+		mInputScrollId: null,
 		weight: 0,
 		height: 0,
 		promptTextMessageFlag: false,//结果弹窗
@@ -55,6 +61,11 @@ Page({
 			}
 			return value;
 		},
+		hotel: '',//酒店
+		room: '',//房间
+		intervalId1: null,
+		intervalId2: null,//解除授权
+		oldJsonList: null,
 	},
 	onOpenDateDialog(event) {
 		const item = event.currentTarget.dataset.item;
@@ -113,7 +124,7 @@ Page({
 				mInputScrollId: "item" + item.num
 			});
 		}, 200);
-	}, 
+	},
 	onChangePrivacy(event) {
 		const check = event.detail;
 
@@ -243,8 +254,9 @@ Page({
 				// 	finish = false;
 				// }
 			}
-			
+
 		}
+		console.log('oldJsonList==' + JSON.stringify(oldJsonList));
 		if (finish == false) {
 			wx.showModal({
 				title: '无法提交',
@@ -262,17 +274,20 @@ Page({
 			wx.showLoading({
 				title: '加载中',
 			})
+			this.setData({
+				oldJsonList: oldJsonList,
+			});
 			setTimeout(function () {
 				wx.hideLoading({
 					success(res) {
-						_this.answer2db(oldJsonList);
+						_this.submitDB();
 					}
 				})
 			}, 2000)
 		}
 	},
 
-	answer2db: function (answerJson) {
+	answer2db: function () {
 		// db.collection('SAS').add({
 		//   data: {
 		//     answer: this.data.answer
@@ -288,6 +303,7 @@ Page({
 		//     console.error('[数据库] [新增记录] 失败:', err)
 		//   }
 		// })
+		const answerJson = this.data.oldJsonList;
 		console.log('answerJson=' + JSON.stringify(answerJson))
 		let totalAllTemp = 0;
 		let value1 = answerJson[0].value;
@@ -304,6 +320,7 @@ Page({
 		let value5h = answerJson[11].value;
 		let value5i = answerJson[12].value;
 		let value5j = answerJson[13].value;
+		let value5jDes = '';//这个值没有算
 		let value6 = answerJson[14].value;
 		let value7 = answerJson[15].value;
 		let value8 = answerJson[16].value;
@@ -314,6 +331,7 @@ Page({
 		let value13 = answerJson[21].value;
 		let value14 = answerJson[22].value;
 		let value15 = answerJson[23].value;
+		let value15Des = '';//这个值没有算
 
 		//计算规则  https://mp.weixin.qq.com/s/QyTzuPoNErMjc2KcA1M61g
 		let comA = 0;//条目6
@@ -444,6 +462,83 @@ Page({
 			comScoreDesc: _comScoreDesc,
 			promptTextMessageFlag: true,
 		})
+
+		var that = this;
+		const { nickName } = wx.getStorageSync('userInfo_em');
+		const unionid = wx.getStorageSync('unionid');
+		console.log('nickName==' + nickName);
+		console.log('unionid==' + unionid);
+		let surveyData = {
+			hotel: this.data.hotel,
+			room: this.data.room,
+			userId: nickName,
+			id2: unionid,
+			value1: value1,
+			value2: value2,
+			value3: value3,
+			value4: value4,
+			value5a: value5a,
+			value5b: value5b,
+			value5c: value5c,
+			value5d: value5d,
+			value5e: value5e,
+			value5f: value5f,
+			value5g: value5g,
+			value5h: value5h,
+			value5i: value5i,
+			value5j: value5j,
+			value5jDes: value5jDes,
+			value6: value6,
+			value7: value7,
+			value8: value8,
+			value9: value9,
+			value10: value10,
+			value11: value11,
+			value12: value12,
+			value13: value13,
+			value14: value14,
+			value15: value15,
+			value15Des: value15Des,
+			value16: comAll,//备用16(评分)
+			value17: _comScoreStatus,//备用17(评分说明)
+			value18: _comScoreDesc,
+			value18: comA + ',' + comB + ',' + comC + ',' + comD + ',' + comE + ',' + comF + ',' + comG //备用18(comA、comB、comC、comD、comE、comF、comG)
+		};
+
+		// 将surveyData发送到服务器  
+		console.log('提交的问卷数据:', surveyData);
+
+		//提交到数据库
+		wx.request({
+			url: `${homeApi}/system/questionInvest`, //
+			method: 'POST',
+			header: {
+				'content-type': 'application/json', // 默认值
+				'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
+			},
+			data: surveyData,
+			success(res) {
+				console.log('res===' + JSON.stringify(res));
+				console.log('res.code===' + res.data.code);
+				if (res && res.data && res.data.code == 200) {
+					wx.showToast({
+						title: '问卷提交成功',
+						icon: 'success',
+						duration: 2000
+					});
+					if (that.data.intervalId1) {
+						clearInterval(that.data.intervalId1);
+						that.data.intervalId1 = null;
+					}
+				}
+			},
+			fail: function (error) {
+				console.error('error', error);
+			},
+			complete: function (e) {
+			}
+		});
+
 	},
 	judgmentScoreRange(scoreValue, startScore, endScore) {
 		return scoreValue >= startScore && scoreValue <= endScore;
@@ -536,11 +631,34 @@ Page({
 		console.log("diffInMinutes==" + diffInMinutes)
 		return diffInMinutes;
 	},
+	// startInterval: function () {
+	// 	 var that = this;
+	// 	 if (!that.data.intervalId1) {
+	// 	 	that.data.intervalId1 = setInterval(() => {
+	// 	 		that.answer2db();
+	// 	 	}, 1000);
+	// 	 }  
+	// },
+	// clearInterval: function () {
+	// 	   var that = this;
+	//   	   if (that.data.intervalId1) {
+	//   		 clearInterval(that.data.intervalId1);  
+	//   		 that.data.intervalId1 = null;
+	//   	   }
+	//   },
+	submitDB: function () {
+		var that = this;
+		if (!that.data.intervalId1) {
+			that.data.intervalId1 = setInterval(() => {
+				that.answer2db();
+			}, 1000);
+		}
+	},
 	/**
 	 * 生命周期函数--监听页面加载
 	 */
 	onLoad: function (options) {
-		
+
 
 		let oldJsonList = qnaire.qnaire
 		oldJsonList.forEach(element => {
@@ -584,6 +702,63 @@ Page({
 			qnaire: oldJsonList,
 			columns
 		});
+		console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
+		if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
+			wx.showModal({
+				title: '提示',
+				content: '请先扫描房间二维码',
+				showCancel: false
+			});
+
+			setTimeout(function () {
+				wx.reLaunch({
+					url: '/pages/scan/scan',
+				})
+			}, 2000) // 设置延时时间,单位为毫秒
+		} else if (wx.getStorageSync('res').result.split('|').length != 2) {
+			wx.showModal({
+				title: '提示',
+				content: '房间二维码不正确,请重新扫码',
+				showCancel: false
+			});
+
+			setTimeout(function () {
+				wx.reLaunch({
+					url: '/pages/scan/scan',
+				})
+			}, 2000) // 设置延时时间,单位为毫秒
+		} else {
+			// const expiresAt = wx.getStorageSync('scanResultExpiresAt');
+			// const now = Date.now() 
+			// if (expiresAt || expiresAt < now) {
+			//   // 扫码结果已过期  
+			//   wx.showToast({  
+			//     title: '扫码结果失效或已过期,请重新扫码',  
+			//     icon: 'none'  
+			//   });  
+			//   // 清除过期的扫码结果  
+			//   wx.removeStorageSync('scanResultExpiresAt');  
+			//   setTimeout(function() {
+			//       wx.reLaunch({
+			//       		url: '/pages/scan/scan',
+			//       })
+			//     }, 2000) // 设置延时时间,单位为毫秒
+
+			// }else{
+			// 	//续期
+			// 	wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
+			// }
+
+			let hotelTemp = '';
+			let roomTemp = '';
+
+			hotelTemp = wx.getStorageSync('res').result.split('|')[0];
+			roomTemp = wx.getStorageSync('res').result.split('|')[1];
+			this.setData({
+				hotel: hotelTemp,
+				room: roomTemp,
+			});
+		}
 	},
 
 	/**
@@ -596,22 +771,44 @@ Page({
 	/**
 	 * 生命周期函数--监听页面显示
 	 */
-	onShow: function () {
-	
+	onShow: function (options) {
+		// var that = this;
+		// if (!that.data.intervalId2) {
+		// 	that.data.intervalId2 = setInterval(() => {
+		// 		// 这里执行你的代码  
+		// 		console.log('sleepQualityIndexAssessment页面:'+Date.now());
+		// 	}, 10000);
+		// }
 	},
 
 	/**
 	 * 生命周期函数--监听页面隐藏
 	 */
 	onHide: function () {
-
+		var that = this;
+		if (that.data.intervalId1) {
+			clearInterval(that.data.intervalId1);
+			that.data.intervalId1 = null;
+		}
+		// if (that.data.intervalId2) {
+		//   clearInterval(that.data.intervalId2);  
+		//   that.data.intervalId2 = null;
+		// }
 	},
 
 	/**
 	 * 生命周期函数--监听页面卸载
 	 */
 	onUnload: function () {
-
+		var that = this;
+		if (that.data.intervalId1) {
+			clearInterval(that.data.intervalId1);
+			that.data.intervalId1 = null;
+		}
+		// if (that.data.intervalId2) {
+		//   clearInterval(that.data.intervalId2);  
+		//   that.data.intervalId2 = null;
+		// }
 	},
 
 	/**