sleepEvaluation.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. Page({
  2. data: {
  3. activeIcon: "/subpages/icons/ic_selected_radio.svg",
  4. normalIcon: "/subpages/icons/ic_radio.svg",
  5. activeColor: "color:#0BC3AA;",
  6. normalColor: "color:#666666;",
  7. ageOptions: [
  8. { value: '0', label: '20岁以下' },
  9. { value: '1', label: '20-29岁' },
  10. { value: '2', label: '30-39岁' },
  11. { value: '3', label: '40-49岁' },
  12. { value: '4', label: '50岁以上' },
  13. ],
  14. careerOptions: [
  15. { value: '0', label: '学生' },
  16. { value: '1', label: '上班族' },
  17. { value: '2', label: '自由职业者' },
  18. { value: '3', label: '企业经营者' },
  19. { value: '4', label: '政府、事业等单位人员' },
  20. { value: '5', label: '其他(请注明)' },
  21. ],
  22. noSatisfiedOptions: [
  23. { value: '0', label: '设备操作有困难' },
  24. { value: '1', label: '对睡眠帮助较小' },
  25. { value: '2', label: '其他原因(请详细说明)' },
  26. ],
  27. career: '',
  28. careerInput: '',
  29. stayExperOptions: [
  30. { value: '0', label: '非常好' },
  31. { value: '1', label: '较好' },
  32. { value: '2', label: '一般' },
  33. { value: '3', label: '较差' },
  34. { value: '4', label: '非常差' },
  35. ],
  36. stayExper: '',
  37. comfortOptions: [
  38. { value: '0', label: '非常舒适' },
  39. { value: '1', label: '舒适' },
  40. // ... 其他选项
  41. ],
  42. improvementOptions: [
  43. { value: '0', label: '舒适度' },
  44. { value: '1', label: '功能性' },
  45. // ... 其他选项
  46. ],
  47. //哪些方式来帮助改善睡眠
  48. improvementSleepOptions: [
  49. { value: '0', label: '调整作息时间' },
  50. { value: '1', label: '锻炼' },
  51. { value: '2', label: '使用助眠产品(如香薰、耳塞、眼罩等)' },
  52. { value: '3', label: '冥想或深呼吸' },
  53. { value: '4', label: '寻求医疗帮助' },
  54. { value: '5', label: '不采取措施' },
  55. ],
  56. //哪些方面让您比较满意
  57. satisfiedOptions: [
  58. { value: '0', label: '便捷的设备操作' },
  59. { value: '1', label: '适宜的睡眠环境' },
  60. { value: '2', label: '人性化的睡眠监测' },
  61. { value: '3', label: '体贴的睡眠辅助设施(如助眠视频、音乐等)' },
  62. ],
  63. wayImprovementSleepOptions: [
  64. { value: '0', label: '监测睡眠质量和提供反馈' },
  65. { value: '1', label: '自动调整睡眠环境(如温度、光线)' },
  66. { value: '2', label: '提供个性化的睡眠建议' },
  67. { value: '3', label: '远程医疗咨询或诊断' },
  68. { value: '4', label: '其他[请在此区域内作答]' },
  69. ],
  70. getSleepHealthOptions: [
  71. { value: '0', label: '互联网' },
  72. { value: '1', label: '社交媒体' },
  73. { value: '2', label: '书籍或杂志' },
  74. { value: '3', label: '医疗专业人士' },
  75. { value: '4', label: '朋友或家人' },
  76. { value: '5', label: '其他[请在此区域内作答]' },
  77. ],
  78. influenceSleepOptions: [
  79. { value: '0', label: '工作压力' },
  80. { value: '1', label: '生活压力' },
  81. { value: '2', label: '环境噪音' },
  82. { value: '3', label: '光线过亮' },
  83. { value: '4', label: '身体不适(如疼痛、消化不良等)' },
  84. { value: '5', label: '心理问题(如焦虑、抑郁等)' },
  85. { value: '6', label: '其他(请注明)' },
  86. ],
  87. improvSleepMethodsOptions: [
  88. { value: '0', label: '听轻音乐' },
  89. { value: '1', label: '喝热牛奶' },
  90. { value: '2', label: '进行放松训练(如深呼吸、冥想等)' },
  91. { value: '3', label: '使用助眠药物' },
  92. { value: '4', label: '其他(请注明)' },
  93. ],
  94. gender: '',
  95. sleepEnvironmentComfort: '',
  96. productComfort: '',
  97. improvementAreas: [], // 使用数组来存储多选答案
  98. ImprovementSleep: [],//哪些方式来帮助改善睡眠
  99. improvementSleep: [],
  100. satisfied: [],// 哪些方面让您比较满意
  101. suggestion: '', // 文本输入的建议
  102. thirdPlatformsInput: '',//填写第三方平台
  103. noSatisfied: '',//体验不满意的原因
  104. wayImprovementSleep: '',//哪些方式来帮助改善睡眠
  105. wayImprovementSleepInput: '',//请填写帮助改善睡眠方式文本
  106. getSleepHealth: [],// 从哪里获取关于睡眠健康的信息
  107. getSleepHealthInput: '',//您通常从哪里获取关于睡眠健康的信息文本
  108. influenceSleep: [],//您认为以下哪些因素会影响您的睡眠
  109. influenceSleepInput: '',//您认为以下哪些因素会影响您的睡眠文本
  110. improvSleepMethods: [],//您认为以下哪些因素会影响您的睡眠
  111. improvSleepMethodsInput: '',//您认为以下哪些因素会影响您的睡眠文本
  112. age: '',//您的年龄
  113. noSatisfiedInput: '',//让您对本次睡眠房入住体验不满意的原因是文本
  114. channel: '',//您是通过什么渠道预定到的本酒店睡眠房?
  115. hotel: '',//酒店
  116. room: '',//房间
  117. mInputId:''//自动滚动用的
  118. },
  119. // 处理性别选择
  120. bindGenderChange: function (e) {
  121. this.setData({
  122. gender: e.detail
  123. });
  124. },
  125. // 处理入住体验的选择
  126. bindStayExperOptions: function (e) {
  127. this.setData({
  128. stayExper: e.detail
  129. });
  130. },
  131. // 处理睡眠环境舒适度(温度、湿度)的选择
  132. bindSleepEnvironmentComfort: function (e) {
  133. this.setData({
  134. sleepEnvironmentComfort: e.detail.value
  135. });
  136. },
  137. // 处理睡眠产品舒适度的选择
  138. bindProductComfort: function (e) {
  139. this.setData({
  140. productComfort: e.detail.value
  141. });
  142. },
  143. // 处理改进空间的多选问题
  144. bindImprovementAreas: function (e) {
  145. this.setData({
  146. improvementAreas: e.detail.value
  147. });
  148. },
  149. bindChannelChange: function (e) {
  150. this.setData({
  151. channel: e.detail
  152. });
  153. },
  154. // 改善睡眠
  155. bindImprovementSleep: function (e) {
  156. this.setData({
  157. improvementSleep: e.detail
  158. });
  159. },
  160. // 改善睡眠
  161. bindGetSleepHealth: function (e) {
  162. this.setData({
  163. getSleepHealth: e.detail
  164. });
  165. },
  166. //您认为以下哪些因素会影响您的睡眠
  167. bindInfluenceSleep: function (e) {
  168. this.setData({
  169. influenceSleep: e.detail
  170. });
  171. },
  172. //您通常使用什么方法来改善睡眠质量
  173. bindImprovSleepMethods: function (e) {
  174. this.setData({
  175. improvSleepMethods: e.detail
  176. });
  177. },
  178. // 体验不满意的原因
  179. bindNoSatisfiedChange: function (e) {
  180. this.setData({
  181. noSatisfied: e.detail
  182. });
  183. },
  184. bindCareerChange: function (e) {
  185. this.setData({
  186. career: e.detail
  187. });
  188. },
  189. bindAgeChange: function (e) {
  190. this.setData({
  191. age: e.detail
  192. });
  193. },
  194. // 哪些方面的多选问题
  195. bindSatisfied: function (e) {
  196. console.log(e)
  197. this.setData({
  198. satisfied: e.detail
  199. });
  200. },
  201. // 哪些方式来帮助改善睡眠
  202. bindWayImprovementSleep: function (e) {
  203. this.setData({
  204. wayImprovementSleep: e.detail
  205. });
  206. },
  207. bindNoSatisfiedInput: function (e) {
  208. this.setData({
  209. noSatisfiedInput: e.detail.value
  210. });
  211. },
  212. bindCareerInputInput: function (e) {
  213. this.setData({
  214. careerInput: e.detail.value
  215. });
  216. },
  217. bindGetSleepHealthInput: function (e) {
  218. this.setData({
  219. getSleepHealthInput: e.detail.value
  220. });
  221. },
  222. bindInfluenceSleepInput: function (e) {
  223. this.setData({
  224. influenceSleepInput: e.detail.value
  225. });
  226. },
  227. bindImprovSleepMethodsInput: function (e) {
  228. this.setData({
  229. improvSleepMethodsInput: e.detail.value
  230. });
  231. },
  232. // 方式来帮助改善睡眠文本输入
  233. bindWayImprovementSleepInput: function (e) {
  234. this.setData({
  235. wayImprovementSleepInput: e.detail.value
  236. });
  237. },
  238. bindThirdPlatformsInputInput: function (e) {
  239. this.setData({
  240. thirdPlatformsInput: e.detail.value
  241. });
  242. },
  243. // 职业填写
  244. bindSuggestionInput: function (e) {
  245. this.setData({
  246. suggestion: e.detail.value
  247. });
  248. },
  249. // 提交问卷的函数
  250. submitSurvey: function () {
  251. let surveyData = {
  252. hotel: this.data.hotel,
  253. room: this.data.room,
  254. gender: this.data.gender,
  255. stayExper: this.data.stayExper,
  256. sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
  257. productComfort: this.data.productComfort,
  258. improvementAreas: this.data.improvementAreas,
  259. satisfied: this.data.satisfied,
  260. suggestion: this.data.suggestion,
  261. career: this.data.career,
  262. careerInput: this.data.careerInput,
  263. thirdPlatformsInput: this.data.thirdPlatformsInput,
  264. noSatisfied: this.data.noSatisfied,
  265. noSatisfiedInput: this.data.noSatisfiedInput,
  266. improvementSleep: this.data.improvementSleep,
  267. wayImprovementSleep: this.data.wayImprovementSleep,
  268. wayImprovementSleepInput: this.data.wayImprovementSleepInput,
  269. getSleepHealth: this.data.getSleepHealth,
  270. bindGetSleepHealthInput: this.data.bindGetSleepHealthInput,
  271. influenceSleep: this.data.influenceSleep,
  272. influenceSleepInput: this.data.influenceSleepInput,
  273. improvSleepMethods: this.data.improvSleepMethods,
  274. improvSleepMethodsInput: this.data.improvSleepMethodsInput,
  275. age: this.data.age,
  276. channel: this.data.channel,
  277. };
  278. let checkList = {
  279. age: this.data.age,
  280. career: this.data.career,
  281. gender: this.data.gender,
  282. channel: this.data.channel,
  283. stayExper: this.data.stayExper,
  284. satisfied: this.data.satisfied,
  285. noSatisfied: this.data.noSatisfied,
  286. improvementSleep: this.data.improvementSleep,
  287. wayImprovementSleep: this.data.wayImprovementSleep,
  288. getSleepHealth: this.data.getSleepHealth,
  289. influenceSleep: this.data.influenceSleep,
  290. improvSleepMethods: this.data.improvSleepMethods,
  291. suggestion: this.data.suggestion,
  292. // sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
  293. // productComfort: this.data.productComfort,
  294. // improvementAreas: this.data.improvementAreas,
  295. // thirdPlatformsInput: this.data.thirdPlatformsInput,
  296. }
  297. var isFinish = true;
  298. var emptyKey = "";
  299. const that = this;
  300. for (const key in checkList) {
  301. if (checkList.hasOwnProperty(key)) {
  302. const element = checkList[key];
  303. if (!element || (Array.isArray(element) && element.length <= 0)) { // 检查属性值是否为空
  304. // 这里可以添加更复杂的判断,比如仅针对字符串检查是否为空字符串
  305. // if (typeof obj[key] === 'string' && obj[key].trim() === '') {
  306. isFinish = false;
  307. emptyKey = key;
  308. wx.showModal({
  309. title: '无法提交',
  310. content: '您还有部分题目未完成,请检查后重新提交',
  311. showCancel: false,
  312. confirmColor: '#0BC3AA',
  313. confirmText: "好的",
  314. success(res) {
  315. console.log(emptyKey.toString());
  316. that.setData({
  317. mInputId: emptyKey.toString()
  318. })
  319. }
  320. })
  321. return; // 停止循环
  322. }
  323. }
  324. }
  325. if (!isFinish) {
  326. wx.showModal({
  327. title: '无法提交',
  328. content: '您还有部分题目未完成,请检查后重新提交',
  329. showCancel: false,
  330. confirmColor: '#0BC3AA',
  331. confirmText: "好的",
  332. success(res) {
  333. console.log(emptyKey.toString());
  334. }
  335. })
  336. return;
  337. }
  338. // 将surveyData发送到服务器
  339. console.log('提交的问卷数据:', surveyData);
  340. //后边会提交到数据库
  341. // wx.request({
  342. // url: `${aipushApi}/getdatefromsn`, //
  343. // method: 'POST',
  344. // header: {
  345. // 'content-type': 'application/json', // 默认值
  346. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  347. // },
  348. // data:{
  349. //     "surveyData":surveyData,"token":"token_push"
  350. // },
  351. // success(res) {
  352. // wx.showToast({
  353. // title: '问卷提交成功',
  354. // icon: 'success',
  355. // duration: 2000
  356. // });
  357. // },
  358. // fail: function (error) {
  359. // console.error('error', error);
  360. // } ,
  361. // complete: function (e) {
  362. // }
  363. // });
  364. wx.showToast({
  365. title: '问卷提交成功',
  366. icon: 'success',
  367. duration: 2000,
  368. success() {
  369. setTimeout(() => {
  370. wx.navigateBack()
  371. }, 1500);
  372. }
  373. });
  374. // 清空表单:
  375. // this.setData({
  376. // gender: '',
  377. // careerInput:'',
  378. // stayExper:'',
  379. // sleepEnvironmentComfort: '',
  380. // productComfort: '',
  381. // improvementAreas: [], // 使用数组来存储多选答案
  382. // ImprovementSleep: [],//哪些方式来帮助改善睡眠
  383. // satisfied: [],// 哪些方面让您比较满意
  384. // suggestion: '', // 文本输入的建议
  385. // thirdPlatformsInput: '',//填写第三方平台
  386. // noSatisfied: '',//体验不满意的原因
  387. // wayImprovementSleep: '',//哪些方式来帮助改善睡眠
  388. // wayImprovementSleepInput: '',//请填写帮助改善睡眠方式文本
  389. // getSleepHealth: [],// 从哪里获取关于睡眠健康的信息
  390. // getSleepHealthInput: '',//您通常从哪里获取关于睡眠健康的信息文本
  391. // influenceSleep: [],//您认为以下哪些因素会影响您的睡眠
  392. // influenceSleepInput: '',//您认为以下哪些因素会影响您的睡眠文本
  393. // improvSleepMethods: [],//您认为以下哪些因素会影响您的睡眠
  394. // improvSleepMethodsInput: '',//您认为以下哪些因素会影响您的睡眠文本
  395. // age: '',//您的年龄
  396. // noSatisfiedInput: '',//让您对本次睡眠房入住体验不满意的原因文本
  397. // channel: '',
  398. // });
  399. },
  400. onLoad(option) {
  401. var that = this;
  402. console.log("sleepEvaluation页面");
  403. // wx.clearStorage();
  404. console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
  405. if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  406. wx.showModal({
  407. title: '提示',
  408. content: '请先扫描房间二维码',
  409. showCancel: false
  410. });
  411. setTimeout(function () {
  412. wx.reLaunch({
  413. url: '/pages/scan/scan',
  414. })
  415. }, 2000) // 设置延时时间,单位为毫秒
  416. } else if (wx.getStorageSync('res').result.split('|').length != 2) {
  417. wx.showModal({
  418. title: '提示',
  419. content: '房间二维码不正确,请重新扫码',
  420. showCancel: false
  421. });
  422. setTimeout(function () {
  423. wx.reLaunch({
  424. url: '/pages/scan/scan',
  425. })
  426. }, 2000) // 设置延时时间,单位为毫秒
  427. } else {
  428. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  429. // const now = Date.now()
  430. // if (expiresAt || expiresAt < now) {
  431. // // 扫码结果已过期
  432. // wx.showToast({
  433. // title: '扫码结果失效或已过期,请重新扫码',
  434. // icon: 'none'
  435. // });
  436. // // 清除过期的扫码结果
  437. // wx.removeStorageSync('scanResultExpiresAt');
  438. // setTimeout(function() {
  439. // wx.reLaunch({
  440. // url: '/pages/scan/scan',
  441. // })
  442. // }, 2000) // 设置延时时间,单位为毫秒
  443. // }else{
  444. // //续期
  445. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  446. // }
  447. let hotelTemp = '';
  448. let roomTemp = '';
  449. hotelTemp = wx.getStorageSync('res').result.split('|')[0];
  450. roomTemp = wx.getStorageSync('res').result.split('|')[1];
  451. this.setData({
  452. hotel: hotelTemp,
  453. room: roomTemp,
  454. });
  455. }
  456. },
  457. /**
  458. * 生命周期函数--监听页面隐藏
  459. */
  460. onHide: function () {
  461. },
  462. /**
  463. * 生命周期函数--监听页面卸载
  464. */
  465. onUnload: function () {
  466. },
  467. });