| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- Page({
- data: {
- activeIcon: "/subpages/icons/ic_selected_radio.svg",
- normalIcon: "/subpages/icons/ic_radio.svg",
- activeColor: "color:#0BC3AA;",
- normalColor: "color:#666666;",
- ageOptions: [
- { value: '0', label: '20岁以下' },
- { value: '1', label: '20-29岁' },
- { value: '2', label: '30-39岁' },
- { value: '3', label: '40-49岁' },
- { value: '4', label: '50岁以上' },
- ],
- careerOptions: [
- { value: '0', label: '学生' },
- { value: '1', label: '上班族' },
- { value: '2', label: '自由职业者' },
- { value: '3', label: '企业经营者' },
- { value: '4', label: '政府、事业等单位人员' },
- { value: '5', label: '其他(请注明)' },
- ],
- noSatisfiedOptions: [
- { value: '0', label: '设备操作有困难' },
- { value: '1', label: '对睡眠帮助较小' },
- { value: '2', label: '其他原因(请详细说明)' },
- ],
- career: '',
- careerInput: '',
- stayExperOptions: [
- { value: '0', label: '非常好' },
- { value: '1', label: '较好' },
- { value: '2', label: '一般' },
- { value: '3', label: '较差' },
- { value: '4', label: '非常差' },
- ],
- stayExper: '',
- comfortOptions: [
- { value: '0', label: '非常舒适' },
- { value: '1', label: '舒适' },
- // ... 其他选项
- ],
- improvementOptions: [
- { value: '0', label: '舒适度' },
- { value: '1', label: '功能性' },
- // ... 其他选项
- ],
- //哪些方式来帮助改善睡眠
- improvementSleepOptions: [
- { value: '0', label: '调整作息时间' },
- { value: '1', label: '锻炼' },
- { value: '2', label: '使用助眠产品(如香薰、耳塞、眼罩等)' },
- { value: '3', label: '冥想或深呼吸' },
- { value: '4', label: '寻求医疗帮助' },
- { value: '5', label: '不采取措施' },
- ],
- //哪些方面让您比较满意
- satisfiedOptions: [
- { value: '0', label: '便捷的设备操作' },
- { value: '1', label: '适宜的睡眠环境' },
- { value: '2', label: '人性化的睡眠监测' },
- { value: '3', label: '体贴的睡眠辅助设施(如助眠视频、音乐等)' },
- ],
- wayImprovementSleepOptions: [
- { value: '0', label: '监测睡眠质量和提供反馈' },
- { value: '1', label: '自动调整睡眠环境(如温度、光线)' },
- { value: '2', label: '提供个性化的睡眠建议' },
- { value: '3', label: '远程医疗咨询或诊断' },
- { value: '4', label: '其他[请在此区域内作答]' },
- ],
- getSleepHealthOptions: [
- { value: '0', label: '互联网' },
- { value: '1', label: '社交媒体' },
- { value: '2', label: '书籍或杂志' },
- { value: '3', label: '医疗专业人士' },
- { value: '4', label: '朋友或家人' },
- { value: '5', label: '其他[请在此区域内作答]' },
- ],
- influenceSleepOptions: [
- { value: '0', label: '工作压力' },
- { value: '1', label: '生活压力' },
- { value: '2', label: '环境噪音' },
- { value: '3', label: '光线过亮' },
- { value: '4', label: '身体不适(如疼痛、消化不良等)' },
- { value: '5', label: '心理问题(如焦虑、抑郁等)' },
- { value: '6', label: '其他(请注明)' },
- ],
- improvSleepMethodsOptions: [
- { value: '0', label: '听轻音乐' },
- { value: '1', label: '喝热牛奶' },
- { value: '2', label: '进行放松训练(如深呼吸、冥想等)' },
- { value: '3', label: '使用助眠药物' },
- { value: '4', label: '其他(请注明)' },
- ],
- gender: '',
- sleepEnvironmentComfort: '',
- productComfort: '',
- improvementAreas: [], // 使用数组来存储多选答案
- ImprovementSleep: [],//哪些方式来帮助改善睡眠
- improvementSleep: [],
- satisfied: [],// 哪些方面让您比较满意
- suggestion: '', // 文本输入的建议
- thirdPlatformsInput: '',//填写第三方平台
- noSatisfied: '',//体验不满意的原因
- wayImprovementSleep: '',//哪些方式来帮助改善睡眠
- wayImprovementSleepInput: '',//请填写帮助改善睡眠方式文本
- getSleepHealth: [],// 从哪里获取关于睡眠健康的信息
- getSleepHealthInput: '',//您通常从哪里获取关于睡眠健康的信息文本
- influenceSleep: [],//您认为以下哪些因素会影响您的睡眠
- influenceSleepInput: '',//您认为以下哪些因素会影响您的睡眠文本
- improvSleepMethods: [],//您认为以下哪些因素会影响您的睡眠
- improvSleepMethodsInput: '',//您认为以下哪些因素会影响您的睡眠文本
- age: '',//您的年龄
- noSatisfiedInput: '',//让您对本次睡眠房入住体验不满意的原因是文本
- channel: '',//您是通过什么渠道预定到的本酒店睡眠房?
- hotel: '',//酒店
- room: '',//房间
- mInputId:''//自动滚动用的
- },
- // 处理性别选择
- bindGenderChange: function (e) {
- this.setData({
- gender: e.detail
- });
- },
- // 处理入住体验的选择
- bindStayExperOptions: function (e) {
- this.setData({
- stayExper: e.detail
- });
- },
- // 处理睡眠环境舒适度(温度、湿度)的选择
- bindSleepEnvironmentComfort: function (e) {
- this.setData({
- sleepEnvironmentComfort: e.detail.value
- });
- },
- // 处理睡眠产品舒适度的选择
- bindProductComfort: function (e) {
- this.setData({
- productComfort: e.detail.value
- });
- },
- // 处理改进空间的多选问题
- bindImprovementAreas: function (e) {
- this.setData({
- improvementAreas: e.detail.value
- });
- },
- bindChannelChange: function (e) {
- this.setData({
- channel: e.detail
- });
- },
- // 改善睡眠
- bindImprovementSleep: function (e) {
- this.setData({
- improvementSleep: e.detail
- });
- },
- // 改善睡眠
- bindGetSleepHealth: function (e) {
- this.setData({
- getSleepHealth: e.detail
- });
- },
- //您认为以下哪些因素会影响您的睡眠
- bindInfluenceSleep: function (e) {
- this.setData({
- influenceSleep: e.detail
- });
- },
- //您通常使用什么方法来改善睡眠质量
- bindImprovSleepMethods: function (e) {
- this.setData({
- improvSleepMethods: e.detail
- });
- },
- // 体验不满意的原因
- bindNoSatisfiedChange: function (e) {
- this.setData({
- noSatisfied: e.detail
- });
- },
- bindCareerChange: function (e) {
- this.setData({
- career: e.detail
- });
- },
- bindAgeChange: function (e) {
- this.setData({
- age: e.detail
- });
- },
- // 哪些方面的多选问题
- bindSatisfied: function (e) {
- console.log(e)
- this.setData({
- satisfied: e.detail
- });
- },
- // 哪些方式来帮助改善睡眠
- bindWayImprovementSleep: function (e) {
- this.setData({
- wayImprovementSleep: e.detail
- });
- },
- bindNoSatisfiedInput: function (e) {
- this.setData({
- noSatisfiedInput: e.detail.value
- });
- },
- bindCareerInputInput: function (e) {
- this.setData({
- careerInput: e.detail.value
- });
- },
- bindGetSleepHealthInput: function (e) {
- this.setData({
- getSleepHealthInput: e.detail.value
- });
- },
- bindInfluenceSleepInput: function (e) {
- this.setData({
- influenceSleepInput: e.detail.value
- });
- },
- bindImprovSleepMethodsInput: function (e) {
- this.setData({
- improvSleepMethodsInput: e.detail.value
- });
- },
- // 方式来帮助改善睡眠文本输入
- bindWayImprovementSleepInput: function (e) {
- this.setData({
- wayImprovementSleepInput: e.detail.value
- });
- },
- bindThirdPlatformsInputInput: function (e) {
- this.setData({
- thirdPlatformsInput: e.detail.value
- });
- },
- // 职业填写
- bindSuggestionInput: function (e) {
- this.setData({
- suggestion: e.detail.value
- });
- },
- // 提交问卷的函数
- submitSurvey: function () {
- 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,
- suggestion: this.data.suggestion,
- career: this.data.career,
- careerInput: this.data.careerInput,
- thirdPlatformsInput: this.data.thirdPlatformsInput,
- noSatisfied: this.data.noSatisfied,
- noSatisfiedInput: this.data.noSatisfiedInput,
- improvementSleep: this.data.improvementSleep,
- wayImprovementSleep: this.data.wayImprovementSleep,
- wayImprovementSleepInput: this.data.wayImprovementSleepInput,
- getSleepHealth: this.data.getSleepHealth,
- bindGetSleepHealthInput: this.data.bindGetSleepHealthInput,
- influenceSleep: this.data.influenceSleep,
- influenceSleepInput: this.data.influenceSleepInput,
- improvSleepMethods: this.data.improvSleepMethods,
- improvSleepMethodsInput: this.data.improvSleepMethodsInput,
- age: this.data.age,
- channel: this.data.channel,
- };
- let checkList = {
- age: this.data.age,
- career: this.data.career,
- gender: this.data.gender,
- channel: this.data.channel,
- stayExper: this.data.stayExper,
- satisfied: this.data.satisfied,
- noSatisfied: this.data.noSatisfied,
- improvementSleep: this.data.improvementSleep,
- wayImprovementSleep: this.data.wayImprovementSleep,
- getSleepHealth: this.data.getSleepHealth,
- influenceSleep: this.data.influenceSleep,
- improvSleepMethods: this.data.improvSleepMethods,
- suggestion: this.data.suggestion,
- // sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
- // productComfort: this.data.productComfort,
- // improvementAreas: this.data.improvementAreas,
- // thirdPlatformsInput: this.data.thirdPlatformsInput,
- }
- var isFinish = true;
- var emptyKey = "";
- const that = this;
- for (const key in checkList) {
- if (checkList.hasOwnProperty(key)) {
- const element = checkList[key];
- if (!element || (Array.isArray(element) && element.length <= 0)) { // 检查属性值是否为空
- // 这里可以添加更复杂的判断,比如仅针对字符串检查是否为空字符串
- // if (typeof obj[key] === 'string' && obj[key].trim() === '') {
- isFinish = false;
- emptyKey = key;
- wx.showModal({
- title: '无法提交',
- content: '您还有部分题目未完成,请检查后重新提交',
- showCancel: false,
- confirmColor: '#0BC3AA',
- confirmText: "好的",
- success(res) {
- console.log(emptyKey.toString());
- that.setData({
- mInputId: emptyKey.toString()
- })
- }
- })
- return; // 停止循环
- }
- }
- }
- if (!isFinish) {
- wx.showModal({
- title: '无法提交',
- content: '您还有部分题目未完成,请检查后重新提交',
- showCancel: false,
- confirmColor: '#0BC3AA',
- confirmText: "好的",
- success(res) {
- console.log(emptyKey.toString());
-
- }
- })
- return;
- }
- // 将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);
- }
- });
- // 清空表单:
- // this.setData({
- // gender: '',
- // careerInput:'',
- // stayExper:'',
- // sleepEnvironmentComfort: '',
- // productComfort: '',
- // improvementAreas: [], // 使用数组来存储多选答案
- // ImprovementSleep: [],//哪些方式来帮助改善睡眠
- // satisfied: [],// 哪些方面让您比较满意
- // suggestion: '', // 文本输入的建议
- // thirdPlatformsInput: '',//填写第三方平台
- // noSatisfied: '',//体验不满意的原因
- // wayImprovementSleep: '',//哪些方式来帮助改善睡眠
- // wayImprovementSleepInput: '',//请填写帮助改善睡眠方式文本
- // getSleepHealth: [],// 从哪里获取关于睡眠健康的信息
- // getSleepHealthInput: '',//您通常从哪里获取关于睡眠健康的信息文本
- // influenceSleep: [],//您认为以下哪些因素会影响您的睡眠
- // influenceSleepInput: '',//您认为以下哪些因素会影响您的睡眠文本
- // improvSleepMethods: [],//您认为以下哪些因素会影响您的睡眠
- // improvSleepMethodsInput: '',//您认为以下哪些因素会影响您的睡眠文本
- // age: '',//您的年龄
- // noSatisfiedInput: '',//让您对本次睡眠房入住体验不满意的原因文本
- // channel: '',
- // });
- },
- onLoad(option) {
- var that = this;
- console.log("sleepEvaluation页面");
- // wx.clearStorage();
- 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,
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- });
|