闫增涛
2024-04-09 253245731d2b0c5ea4994a9c4e17ad6b60136f2c
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// pages/bookServices/examination/questionOptions/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentIndex: {
      type: Number,
      value: 0,
    },
    questionDataList: {
      type: Array,
      value: [],
    },
    cardList: {
      type: Array,
      value: [],
    },
    subjectiveTotal: {
      type: Number,
      value: 0,
    },
    countdownTime: {
      type: Number,
      value: 0,
    },
    answerType: {
      type: String,
      value: "",
    },
    subjectiveNum: {
      type: Number,
      value: 0,
    },
    subjectiveGrade: {
      type: Number,
      value: 0,
    },
    correctNum: {
      type: Number,
      value: 0,
    },
    submitStatus: {
      type: Boolean,
      value: false,
    },
    mockSumTime: {
      type: Number,
      value: 0,
    },
    isNight: {
      type: Boolean,
      value: false,
    },
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    btnStyle: "width:320rpx;border-radius:60rpx",
    noReady: 0,
    questionCardState: false,
    setUpPopup: false,
    testReportState: false,
    sliderValue: 36,
    useTime: "",
    radioItem: "daytime",
  },
  observers: {
    countdownTime: function (newValue, oldValue) {
      if (this.properties.answerType == "option") {
        this.setData({
          useTime: this.formatTime(
            2 * 60 * 60 * 1000 - this.properties.countdownTime
          ),
        });
      } else if (this.properties.answerType == "option") {
        this.setData({
          useTime: this.formatTime(
            this.properties.mockSumTime - this.properties.countdownTime
          ),
        });
      }
      if (
        newValue == 0 &&
        (this.properties.answerType == "option" ||
          this.properties.answerType == "mock") && !this.properties.submitStatus
      ) {
        this.timeout();
      }
    },
  },
  created() {},
 
  /**
   * 组件的方法列表
   */
  methods: {
    // // 格式化时间
    formatTime(ms) {
      const hours = Math.floor((ms / (1000 * 60 * 60)) % 24)
        .toString()
        .padStart(2, "0");
      const minutes = Math.floor((ms / (1000 * 60)) % 60)
        .toString()
        .padStart(2, "0");
      const seconds = Math.floor((ms / 1000) % 60)
        .toString()
        .padStart(2, "0");
      return `${hours}:${minutes}:${seconds}`;
    },
    // 判断是否输入答案
    isHaveAnswer(data) {
      if (typeof data == "string") {
        data = data
          .replace(/<[^>]*>/g, "")
          .replace(/&nbsp;/g, "")
          .trim();
        if (data.length) {
          return true;
        } else {
          return false;
        }
      } else {
        const answer = data.find((item) => item.length > 0);
        if (answer) {
          return true;
        } else {
          return false;
        }
      }
    },
    setCollect() {
      var myEventDetail = {};
      var myEventOption = {
        bubbles: true,
        composed: true,
      };
      this.triggerEvent("setCollect", myEventDetail, myEventOption);
    },
    // 答题卡按钮
    handlePopup() {
      this.setData({
        questionCardState: true,
      });
    },
    // 答题卡跳转题目
    goQuestion(e) {
      var myEventDetail = {
        id: e.currentTarget.dataset.id,
      };
      var myEventOption = {
        bubbles: true,
        composed: true,
      };
      this.triggerEvent("goQuestion", myEventDetail, myEventOption);
    },
    // 答题卡遮罩层点击
    onVisibleChange(e) {
      this.setData({
        questionCardState: e.detail.visible,
      });
    },
    // 设置按钮
    setUpBtn() {
      this.setData({
        setUpPopup: true,
      });
    },
    // 滑块变化
    onChangeSlider(e) {
      const value = e.detail.value;
      console.log(value);
      this.triggerEvent("onChangeSlider", {
        value
      });
    },
    // 设置遮罩层点击
    onSetUpChange(e) {
      this.setData({
        setUpPopup: e.detail.visible,
      });
    },
    // 设置模式切换
    onRadioChange(e) {
      this.setData({
        radioItem: e.detail.value,
      });
      const value = e.detail.value == "night" ? true : false;
      wx.setNavigationBarColor({
        backgroundColor: "#222",
        frontColor: "#222",
      });
 
      this.triggerEvent("changeBGColor", {
        value
      });
    },
    // 重做按钮
    resterBtn() {
      wx.showModal({
        title: "提示",
        content: "是否重新开始答题?", //editable如果为true,这就是输入框的内容
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        editable: false, //是否显示输入框
        success: (res) => {
          if (res.confirm) {
            this.restart();
          }
        },
      });
    },
    // 重做事件
    restart() {
      var myEventDetail = {};
      var myEventOption = {
        bubbles: true,
        composed: true,
      };
      this.triggerEvent("restart", myEventDetail, myEventOption);
    },
 
    // 还有N道题未做弹窗
    confrimPromptDialog() {
      wx.showModal({
        title: "提示",
        content: `您还有 ${this.data.noReady}道题未答,是否提交?`, //editable如果为true,这就是输入框的内容
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        editable: false, //是否显示输入框
        success: (res) => {
          if (res.confirm) {
            this.submitPaper();
          }
        },
      });
    },
    // 底部提交按钮
    submitBtn() {
      this.setData({
        noReady: 0,
      });
      // 我的错题和收藏  直接走提交逻辑
      if (
        this.properties.answerType == "collectQuestion" ||
        this.properties.answerType == "errorQuestion"
      ) {
        this.submitPaper();
        // wx.navigateBack();
      } else if (
        this.properties.answerType == "option" ||
        this.properties.answerType == "mock"
      ) {
        if (this.properties.submitStatus) return wx.navigateBack();
        this.properties.questionDataList.forEach((item) => {
          if (!this.isHaveAnswer(item.userAnswer)) {
            this.setData({
              noReady: this.data.noReady + 1,
            });
          }
        });
        // 未做完,打开提示弹窗
        if (this.data.noReady > 0) {
          this.confrimPromptDialog();
        } else {
          // 做完了直接执行提交事件
          this.submitPaper();
        }
      }
    },
    // 提交事件
    submitPaper() {
      var myEventDetail = {};
      var myEventOption = {
        bubbles: true,
        composed: true,
      };
      this.triggerEvent("submitPaper", myEventDetail, myEventOption);
    },
    // 打开测试报告弹窗
    openTestReportDialog() {
      this.setData({
        testReportState: true,
      });
    },
    // 关闭测试报告弹窗
    closeTestReportDialog(e) {
      this.setData({
        testReportState: false,
      });
    },
    // 测试报告弹窗查看答案解析按钮
    viewAnswer() {
      this.closeTestReportDialog();
    },
    // 答题时间到
    timeout() {
      wx.showModal({
        title: "提示",
        content: "答题时间已到", //editable如果为true,这就是输入框的内容
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        editable: false, //是否显示输入框
        showCancel: false,
        success: (res) => {},
      });
      this.submitPaper();
    },
  },
});