|
|
@@ -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; // 可选,但建议清除以避免潜在的错误
|
|
|
+ // }
|
|
|
},
|
|
|
});
|