question.js
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {
getBindtapData
} from '../../utils/util';
import Date from '../../utils/date';
let app = getApp();
Page({
data: {
questionList: [], // 题目列表
// questionResult: {
// "status": 1,
// "elasticValue": 50,
// "coupons": [{
// "couponId": "20839",
// "couponCode": "RLLL1IHG",
// "rule": "RLLL1IHG",
// "startDate": 1564479217000,
// "endDate": 1567094399000,
// "type": 4,
// "name": "眼部护理体验券-7月24日",
// "state": 0
// }]
// },
questionResult: {},
// 答题结果
questionNumList: ["A", "B", "C", "D"],
myAnswer: [], //我的答案
},
onShareAppMessage() {},
onLoad(options) {
this.initData();
},
initData() {
this.queryQuestionList();
},
/**
* 跳转至创建心愿单
*/
onCreateWishHandler() {
app.router.push({
openType: "redirectTo",
path: "createWish"
})
},
/**
* 点击答案
* 设置选择的按钮
*/
onSelectAnswerHandler(evt) {
let curIndex = getBindtapData(evt, "index");
let curPIndex = getBindtapData(evt, "pindex");
let questionList = this.data.questionList;
// 重置本题的选中状态
questionList[curPIndex].answers.forEach(element => {
element.selected = false;
});
questionList[curPIndex].answers[curIndex].selected = true;
questionList[curPIndex].selected = true; // 题目已被选择
let myAnswer = this.data.myAnswer;
let curAnswer = {
questionCode: questionList[curPIndex].questionCode,
answerNo: questionList[curPIndex].answers[curIndex].answerNo
}
myAnswer[curPIndex] = curAnswer;
this.setData({
questionList,
myAnswer
})
},
/**
* 提交答案
*/
onSubmitQuestionResultHandler() {
let _this = this;
// 检查是否有提没提交 完整判断应该判断题目数要大于0,这里就算了
let questionList = this.data.questionList;
let isComplete = questionList.every((item) => {
return item.selected == true;
})
let myAnswer = this.data.myAnswer;
if (isComplete) {
wx.showModal({
content: "确认提交?",
confirmText: "确认",
success(res) {
app.post({
url: app.api.answerSubmit,
data: myAnswer
}).then((result) => {
let questionResult = result;
questionResult.coupons.forEach(element => {
element.endDateStr = new Date(element.endDate).toString("yy-MM-dd");
});
_this.setData({
questionResult
})
console.log("answerSubmit:", _this.data.questionResult);
})
}
})
} else {
wx.showModal({
content: "答题未完成",
confirmText: "继续答题",
showCancel: false,
success(res) {
}
})
}
},
/**
* 请求问题列表
*/
queryQuestionList() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.questionList,
data: {}
}).then((result) => {
let {
questionList
} = result;
console.log("questionList", questionList);
this.setData({
questionList: questionList
})
resolve();
})
});
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
case "_evt_hide":
break;
default:
break;
}
},
})