difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
"use strict";
cc._RF.push(module, '68669Ad5XpC4Lw+4ffTXOFr', 'sureveyquest_window');
// Scripts/mod/welfare/view/sureveyquest_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-08-12 15:43:29
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var WelfareEvent = require("welfare_event");
 
var WelfareConst = require("welfare_const");
 
var SureveyquestWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("welfare", "surveyquest_window");
    this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Big; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
 
    this.ctrl = arguments[0];
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.topic_length = 10; //题目数
 
    this.index_count = -1; //做题数量
 
    this.answer_ret_temp = null;
    this.topic_layout = {}; //点击区域
 
    this.answer_list = []; //答案
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("background");
    this.main_container = this.root_wnd.getChildByName("main_container");
    this.btn_start = this.main_container.getChildByName("btn_start");
    this.btn_start.label = this.btn_start.getChildByName("Text_9").getComponent(cc.Label);
    this.btn_close = this.main_container.getChildByName("btn_close");
    this.answer_content = this.main_container.getChildByName("answer_content");
    this.answer_content.active = false;
    this.titleTopic = this.main_container.getChildByName("titleTopic").getComponent(cc.Label);
    this.topic_layout_nd = this.answer_content.getChildByName("topic_layout");
    this.scroll = this.answer_content.getChildByName("answer_scroll");
    this.content = this.answer_content.getChildByName("answer_scroll").getChildByName("content");
    this.main_container.getChildByName("Text_10").getComponent(cc.Label).string = Utils.TI18N("小助手的冒险调查"); // --调查开始的框
 
    this.text_prompt = this.main_container.getChildByName("text_prompt");
    this.start_title = this.text_prompt.getChildByName("Text_8").getComponent(cc.Label);
    this.start_title.string = "";
    this.start_memo = this.text_prompt.getChildByName("Text_8_0").getComponent(cc.Label);
    this.start_memo.string = ""; // --填空框
 
    this.suggest_panel = this.main_container.getChildByName("suggest_panel");
    this.text_field_eb = this.suggest_panel.getChildByName("text_Field").getComponent(cc.EditBox);
    this.suggest_panel.active = false; // --奖励框
 
    this.reward_panel = this.main_container.getChildByName("reward_panel");
    this.reward_panel.active = false;
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.btn_start.on('click', function () {
      Utils.playButtonSound(1);
      var open_data = this.ctrl.getModel().getQuestOpenData();
 
      if (open_data && open_data.flag != 0) {
        this.ctrl.sender24604();
        return;
      }
 
      if (this.index_count > this.topic_length) return;
 
      if (this.questNaire_list) {
        var last_data = this.questNaire_list[this.index_count]; //有题目
 
        var tab = {};
        tab.id = last_data.id;
        tab.topic_type = last_data.topic_type;
 
        if (last_data.specific_type != WelfareConst.QuestConst.fill_blank) {
          var status_return = false;
 
          for (var i in this.topic_layout) {
            if (this.topic_layout[i].active && this.topic_layout[i].getChildByName("checkmark").active) {
              status_return = true;
              break;
            }
          }
 
          if (!status_return && last_data.must == 1) {
            message(Utils.TI18N("必须选择一个答案"));
            return;
          } // [{id:"题目ID",topic_type:"类型",ret:"ret"},{id:"题目ID",topic_type:"类型",ret:"ret"},{id:"题目ID",topic_type:"类型",ret:"ret"}]
 
 
          var str = "";
 
          for (var _i in this.topic_layout) {
            if (this.topic_layout[_i].active && this.topic_layout[_i].getChildByName("checkmark").active) {
              str += _i;
            }
          }
 
          tab.ret = str;
        } else {
          //意见
          if (last_data.must == 1 && this.text_field_eb.string == "") {
            message(Utils.TI18N("当前题必填"));
            return;
          }
 
          tab.ret = this.text_field_eb.string;
        }
 
        this.answer_list.push(tab);
      }
 
      this.index_count = this.index_count + 1;
 
      if (this.index_count == 0) {
        this.ctrl.sender24602();
      }
 
      if (this.questNaire_list) {
        if (this.index_count == this.questNaire_list.length) {
          this.ctrl.sender24603(this.answer_list);
        } else {
          this.startTopicAnswer(this.questNaire_list);
        }
      }
    }, this);
    this.btn_close.on('click', function () {
      Utils.playButtonSound(2);
      this.ctrl.openSureveyQuestView(false);
    }, this);
    this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Basic, function (data) {
      if (!data || Utils.next(data) == null) return;
      var open = this.ctrl.getModel().getQuestOpenData();
 
      if (open && open.status == 0) {
        return;
      }
 
      this.answer_reward_list = data.rewards;
      var open_data = this.ctrl.getModel().getQuestOpenData();
 
      if (open_data) {
        if (open_data.flag == 0) {
          this.start_title.string = Utils.TI18N("亲爱的冒险者大人:");
          this.start_memo.string = Utils.TI18N("辛苦您参加小助手的冒险调查,小助手为大人\n\n准备了小小谢礼,放在了问卷的最后哦~");
        } else {
          this.getRewardList(open_data.flag);
        }
      }
    }.bind(this));
    this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Topic_Content, function (data) {
      if (!data || Utils.next(data) == null) return;
      var open = this.ctrl.getModel().getQuestOpenData();
 
      if (open && open.status == 0) {
        return;
      }
 
      this.topic_length = data.questionnaire_list.length;
      data.questionnaire_list.sort(function (a, b) {
        return a.sort - b.sort;
      });
      this.questNaire_list = data.questionnaire_list;
      this.startTopicAnswer(this.questNaire_list);
    }.bind(this));
    this.addGlobalEvent(WelfareEvent.SureveyQuest_Submit, function () {
      this.answer_content.active = false;
      this.suggest_panel.active = false;
      this.titleTopic.node.active = false;
      this.getRewardList();
    }, this);
    this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Get_Reward, function (data) {
      if (!data || Utils.next(data) == null) return;
      var open = this.ctrl.getModel().getQuestOpenData();
 
      if (open && open.status == 0) {
        return;
      }
 
      this.btn_start.label.string = Utils.TI18N("已完成");
      this.btn_start.label.node.getComponent(cc.LabelOutline).enabled = false;
      this.btn_start.getComponent(cc.Button).interactable = false;
      this.btn_start.getComponent(cc.Button).enableAutoGrayEffect = true;
    }, this);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    var open_data = this.ctrl.getModel().getQuestOpenData();
 
    if (open_data.flag == 1) {
      this.ctrl.setWelfareStatus(WelfareConst.WelfareIcon.quest, true);
    } else {
      this.ctrl.setWelfareStatus(WelfareConst.WelfareIcon.quest, false);
    }
 
    this.ctrl.sender24601();
  },
  //题目
  startTopicAnswer: function startTopicAnswer(data) {
    var _this = this;
 
    this.scroll.getComponent(cc.ScrollView).scrollToTop(0);
    this.text_prompt.active = false;
    if (!data || Utils.next(data) == null) return;
 
    if (!data[this.index_count]) {
      return;
    }
 
    var answer = data[this.index_count].specific_type;
 
    if (answer == WelfareConst.QuestConst.single) {
      this.selectNum = WelfareConst.QuestConst.single;
    } else if (answer == WelfareConst.QuestConst.multiple) {
      this.selectNum = WelfareConst.QuestConst.multiple;
    }
 
    this.titleTopic.string = data[this.index_count].title;
 
    if (answer == WelfareConst.QuestConst.fill_blank) {
      this.answer_content.active = false;
      this.suggest_panel.active = true;
      this.text_field_eb.string = "";
      return;
    } else {
      this.answer_content.active = true;
      this.suggest_panel.active = false;
    }
 
    var str = data[this.index_count].option.replace(/\\r/g, "");
    var strArr = [];
 
    for (var i = 0; i < str.length; ++i) {
      if (str[i] == '"') {
        strArr.push(i);
      }
    }
 
    var topic = {};
 
    for (var _i2 = 0; _i2 < strArr.length / 4; ++_i2) {
      var index = _i2 * 4;
      var p = /[a-z]/i;
      var string = str.slice(strArr[index] + 1, strArr[index + 1]);
      var string1 = str.slice(strArr[index + 2] + 1, strArr[index + 3]);
      var b = p.test(string);
 
      if (b) {
        topic[string] = string1;
      }
    }
 
    for (var _i3 in this.topic_layout) {
      if (this.topic_layout[_i3]) {
        this.topic_layout[_i3].active = false;
        this.topic_layout[_i3].getChildByName("checkmark").active = false;
      }
    }
 
    var spacingY = 30;
    var count = 0;
    var itemHeight = 40;
    var height = 5;
 
    var _loop = function _loop(_i4) {
      var node = _this.topic_layout[_i4];
 
      if (node == null) {
        node = cc.instantiate(_this.topic_layout_nd);
 
        _this.content.addChild(node);
 
        node.background_sp = node.getChildByName("Background").getComponent(cc.Sprite);
        node.label = node.getChildByName("Background").getChildByName("label").getComponent("cc.Label");
        node.getChildByName("checkmark").active = false;
        _this.topic_layout[_i4] = node;
        node.on('touchend', function (event) {
          this.setButtonState(_i4);
        }, _this);
      }
 
      node.active = true;
      count++;
      var path = void 0;
 
      if (answer == WelfareConst.QuestConst.single) {
        path = PathTool.getUIIconPath("common", "common_1030");
      } else {
        path = PathTool.getUIIconPath("common", "common_1044");
      }
 
      node.label.string = topic[_i4];
 
      node.label._updateRenderData(true);
 
      40 + 30 * (2 - 1);
      var y = height;
 
      if (node.label.node.height > itemHeight) {
        height = y + node.label.node.height + spacingY;
      } else {
        height = y + itemHeight + spacingY;
      }
 
      node.setPosition(-243, -y);
 
      _this.loadRes(path, function (res) {
        node.background_sp.spriteFrame = res;
      }.bind(_this));
    };
 
    for (var _i4 in topic) {
      _loop(_i4);
    }
 
    this.content.height = height - spacingY;
 
    if (this.index_count != this.topic_length) {
      this.btn_start.label.string = Utils.TI18N("下一页");
    }
  },
  setButtonState: function setButtonState(index) {
    if (this.selectNum == WelfareConst.QuestConst.single) {
      for (var i in this.topic_layout) {
        if (this.topic_layout[i].active) {
          this.topic_layout[i].getChildByName("checkmark").active = false;
        }
      }
 
      this.topic_layout[index].getChildByName("checkmark").active = true;
    } else if (this.selectNum == WelfareConst.QuestConst.multiple) {
      this.topic_layout[index].getChildByName("checkmark").active = !this.topic_layout[index].getChildByName("checkmark").active;
      var count = 0;
 
      for (var _i5 in this.topic_layout) {
        if (this.topic_layout[_i5].active && this.topic_layout[_i5].getChildByName("checkmark").active) {
          count++;
        }
      }
 
      if (count > this.selectNum) {
        if (count == this.selectNum + 1) {
          this.topic_layout[index].getChildByName("checkmark").active = false;
        }
 
        message(Utils.TI18N("最多选择三个选项"));
      }
    }
  },
  getRewardList: function getRewardList(flag) {
    flag = flag || 1;
    this.reward_panel.active = true;
    this.end_memo = this.reward_panel.getChildByName("Text_1").getComponent(cc.Label);
    this.end_memo.string = Utils.TI18N("亲爱的冒险者大人~\n\n请收下小助手的一点心意");
 
    if (flag == 2) {
      this.btn_start.label.string = Utils.TI18N("已完成");
      this.btn_start.label.node.getComponent(cc.LabelOutline).enabled = false;
      this.btn_start.getComponent(cc.Button).interactable = false;
      this.btn_start.getComponent(cc.Button).enableAutoGrayEffect = true;
    } else {
      this.btn_start.label.string = Utils.TI18N("领取奖励");
    }
 
    if (this.answer_reward_list) {
      var content = this.reward_panel.getChildByName("good_cons").getChildByName("content");
      var space_x = 10;
      this.award_item = [];
 
      for (var i = 0; i < this.answer_reward_list.length; ++i) {
        var bid = this.answer_reward_list[i].bid;
        var num = this.answer_reward_list[i].num;
        var item = ItemsPool.getInstance().getItem("backpack_item");
        item.setParent(content);
        var x = 60 + i * 120 + i * space_x;
        item.setPosition(x, 60);
        item.show();
        item.setData({
          bid: bid,
          num: num
        });
        this.award_item.push(item);
      }
 
      content.width = this.answer_reward_list.length * 120 + (this.answer_reward_list.length - 1) * space_x;
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.award_item) {
      for (var i = 0; i < this.award_item.length; ++i) {
        if (this.award_item[i]) {
          this.award_item[i].deleteMe();
          this.award_item[i] = null;
        }
      }
 
      this.award_item = null;
    }
 
    this.ctrl.openSureveyQuestView(false);
  }
});
 
cc._RF.pop();