sleepEvaluation.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Page({
  2. data: {
  3. gender: '',
  4. // ... 其他数据
  5. satisfactionOptions: [
  6. { value: 'verySatisfied', label: '非常满意' },
  7. { value: 'satisfied', label: '满意' },
  8. // ... 其他选项
  9. ],
  10. comfortOptions: [
  11. { value: 'veryComfortable', label: '非常舒适' },
  12. { value: 'comfortable', label: '舒适' },
  13. // ... 其他选项
  14. ],
  15. improvementOptions: [
  16. { value: 'comfort', label: '舒适度' },
  17. { value: 'functionality', label: '功能性' },
  18. // ... 其他选项
  19. ],
  20. sleepEnvironmentQuietness: '',
  21. sleepEnvironmentComfort: '',
  22. productComfort: '',
  23. improvementAreas: [], // 使用数组来存储多选答案
  24. suggestion: '', // 文本输入的建议
  25. // ... 其他数据
  26. },
  27. // 处理性别选择
  28. bindGenderChange: function(e) {
  29. this.setData({
  30. gender: e.detail.value
  31. });
  32. },
  33. // 处理睡眠环境安静程度的选择
  34. bindSleepEnvironmentQuietness: function(e) {
  35. this.setData({
  36. sleepEnvironmentQuietness: e.detail.value
  37. });
  38. },
  39. // 处理睡眠环境舒适度(温度、湿度)的选择
  40. bindSleepEnvironmentComfort: function(e) {
  41. this.setData({
  42. sleepEnvironmentComfort: e.detail.value
  43. });
  44. },
  45. // 处理睡眠产品舒适度的选择
  46. bindProductComfort: function(e) {
  47. this.setData({
  48. productComfort: e.detail.value
  49. });
  50. },
  51. // 处理改进空间的多选问题
  52. bindImprovementAreas: function(e) {
  53. this.setData({
  54. improvementAreas: e.detail.value // 直接将选中项的值数组设置为data中的improvementAreas
  55. });
  56. },
  57. // 处理文本输入的建议
  58. bindSuggestionInput: function(e) {
  59. this.setData({
  60. suggestion: e.detail.value
  61. });
  62. },
  63. // 提交问卷的函数
  64. submitSurvey: function() {
  65. let surveyData = {
  66. gender: this.data.gender,
  67. sleepEnvironmentQuietness: this.data.sleepEnvironmentQuietness,
  68. sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
  69. productComfort: this.data.productComfort,
  70. improvementAreas: this.data.improvementAreas,
  71. suggestion: this.data.suggestion,
  72. // ... 其他需要提交的数据
  73. };
  74. // 将surveyData发送到服务器
  75. console.log('提交的问卷数据:', surveyData);
  76. //后边会提交到数据库
  77. // wx.request({
  78. // url: `${aipushApi}/getdatefromsn`, //
  79. // method: 'POST',
  80. // header: {
  81. // 'content-type': 'application/json', // 默认值
  82. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  83. // },
  84. // data:{
  85. //     "surveyData":surveyData,"token":"token_push"
  86. // },
  87. // success(res) {
  88. // wx.showToast({
  89. // title: '问卷提交成功',
  90. // icon: 'success',
  91. // duration: 2000
  92. // });
  93. // },
  94. // fail: function (error) {
  95. // console.error('error', error);
  96. // } ,
  97. // complete: function (e) {
  98. // }
  99. // });
  100. wx.showToast({
  101. title: '问卷提交成功',
  102. icon: 'success',
  103. duration: 2000
  104. });
  105. // 清空表单:
  106. // this.setData({
  107. // gender: '',
  108. // sleepEnvironmentQuietness: '',
  109. // sleepEnvironmentComfort: '',
  110. // productComfort: '',
  111. // improvementAreas: '',
  112. // suggestion: '',
  113. // // ... 重置其他数据
  114. // });
  115. },
  116. });