// pages/user/evaluation.js import {createEvaluation} from './../../utils/api.js'; Page({ /** * 页面的初始数据 */ data: { subjects: [ { "title": "您是否感到头疼不适?", "subject": "headache", "options": [{ "text": "无头痛", "score": 0 }, { "text": "轻度头痛", "score": 1 }, { "text": "重度头痛", "score": 2 }, { "text": "严重头痛,丧失活动能力", "score": 3 }] }, { "title": "您是否感觉到胃肠道不适?", "subject": "gastrointestinal", "options": [{ "text": "食欲好", "score": 0 }, { "text": "食欲不振或恶心", "score": 1 }, { "text": "恶心或呕吐(小于等于5次呕吐)", "score": 2 }, { "text": "严重恶心或呕吐(大于5次呕吐),丧失活动能力", "score": 3 }] }, { "title": "您是否感觉到疲劳或虚弱?", "subject": "tired", "options": [{ "text": "疲劳或虚弱", "score": 0 }, { "text": "轻度疲劳或虚弱", "score": 1 }, { "text": "重度疲劳或虚弱", "score": 2 }, { "text": "严重疲劳或虚弱,丧失活动能力", "score": 3 }] }, { "title": "您是否感觉到头晕或眩晕?", "subject": "dizzy", "options": [{ "text": "无头晕或眩晕", "score": 0 }, { "text": "轻度头晕或眩晕", "score": 1 }, { "text": "重度头晕或眩晕", "score": 2 }, { "text": "严重头晕或眩晕,丧失活动能力", "score": 3 }] } ], createModel:{ headache: -1, gastrointestinal: -1, tired: -1, dizzy:-1 } }, onRadioChange(e){ let subj = e.currentTarget.dataset.subject; var model = this.data.createModel; model[subj] = e.detail.value; this.setData({ createModel: model }) }, async onSubmit(){ for(var k in this.data.createModel){ if(this.data.createModel[k] == -1){ wx.showToast({ title: '请选择所有选项后再提交', icon:'none' }); return; } } let data = await createEvaluation(this.data.createModel); console.log(data); wx.hideLoading(); wx.redirectTo({ url: 'result?id=' + data.id, }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })