| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- Page({
- data: {
- gender: '',
- // ... 其他数据
- satisfactionOptions: [
- { value: 'verySatisfied', label: '非常满意' },
- { value: 'satisfied', label: '满意' },
- // ... 其他选项
- ],
- comfortOptions: [
- { value: 'veryComfortable', label: '非常舒适' },
- { value: 'comfortable', label: '舒适' },
- // ... 其他选项
- ],
- improvementOptions: [
- { value: 'comfort', label: '舒适度' },
- { value: 'functionality', label: '功能性' },
- // ... 其他选项
- ],
- sleepEnvironmentQuietness: '',
- sleepEnvironmentComfort: '',
- productComfort: '',
- improvementAreas: [], // 使用数组来存储多选答案
- suggestion: '', // 文本输入的建议
- // ... 其他数据
- },
-
- // 处理性别选择
- bindGenderChange: function(e) {
- this.setData({
- gender: e.detail.value
- });
- },
-
- // 处理睡眠环境安静程度的选择
- bindSleepEnvironmentQuietness: function(e) {
- this.setData({
- sleepEnvironmentQuietness: e.detail.value
- });
- },
-
- // 处理睡眠环境舒适度(温度、湿度)的选择
- 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 // 直接将选中项的值数组设置为data中的improvementAreas
- });
- },
-
- // 处理文本输入的建议
- bindSuggestionInput: function(e) {
- this.setData({
- suggestion: e.detail.value
- });
- },
-
- // 提交问卷的函数
- submitSurvey: function() {
- let surveyData = {
- gender: this.data.gender,
- sleepEnvironmentQuietness: this.data.sleepEnvironmentQuietness,
- sleepEnvironmentComfort: this.data.sleepEnvironmentComfort,
- productComfort: this.data.productComfort,
- improvementAreas: this.data.improvementAreas,
- suggestion: this.data.suggestion,
- // ... 其他需要提交的数据
- };
-
- // 将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
- });
-
- // 清空表单:
- // this.setData({
- // gender: '',
- // sleepEnvironmentQuietness: '',
- // sleepEnvironmentComfort: '',
- // productComfort: '',
- // improvementAreas: '',
- // suggestion: '',
- // // ... 重置其他数据
- // });
- },
-
- });
|