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
"use strict";
cc._RF.push(module, '41dbb7vmw9KApsrv0m+tTYS', 'welfare_main_window');
// Scripts/mod/welfare/view/welfare_main_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-03-04 11:29:34
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var WelfareConst = require("welfare_const");
 
var WelfareController = require("welfare_controller");
 
var WelfareEvent = require("welfare_event");
 
var ActionEvent = require("action_event");
 
var ActionConst = require("action_const");
 
var ActionController = require("action_controller");
 
var MainuiConst = require("mainui_const");
 
var Welfare_mainWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("welfare", "welfare_main_view");
    this.viewTag = SCENE_TAG.ui; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Full; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.sub_list = [];
    this.tab_list = {};
    this.tab_width = 78;
    this.off_space = 50;
    this.panel_list = {};
    this.selected_tab = null;
    this.selected_panel = null;
    this.ctrl = WelfareController.getInstance();
    this.model = this.ctrl.getModel();
    this.action_ctrl = ActionController.getInstance();
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.seekChild("background");
    this.background.scale = this.background.scale * FIT_SCALE;
    this.main_container_nd = this.seekChild("main_container");
    this.main_panel_nd = this.seekChild(this.main_container_nd, "main_panel");
    this.container_nd = this.seekChild(this.main_panel_nd, "container");
    this.close_btn_nd = this.seekChild(this.main_container_nd, "close_btn");
    this.tab_container_nd = this.seekChild(this.main_container_nd, "tab_container");
    this.tab_scroll_nd = this.seekChild(this.tab_container_nd, "tab_scroll");
    this.tab_scroll_sv = this.seekChild(this.tab_container_nd, "tab_scroll", cc.ScrollView);
    this.tab_scroll_content_nd = this.seekChild(this.tab_scroll_nd, "content");
    this.loadRes(PathTool.getBigBg("welfare/welfare_bg", "jpg"), function (res) {
      this.background.getComponent(cc.Sprite).spriteFrame = res;
    }.bind(this));
    this.loadRes(PathTool.getBigBg("welfare/welfare_bg_1"), function (res) {
      this.main_panel_nd.getChildByName("tab_sprite_bg").getComponent(cc.Sprite).spriteFrame = res;
    }.bind(this));
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.close_btn_nd, function () {
      this.ctrl.openMainWindow(false);
    }.bind(this), 1);
    this.addGlobalEvent(WelfareEvent.UPDATE_WELFARE_TAB_STATUS, function (vo) {
      this.setTabStatus(vo.bid);
    }, this);
    this.addGlobalEvent(ActionEvent.UPDATE_HOLIDAY_TAB_STATUS, function (type, vo) {
      if (type != ActionConst.ActionType.Wonderful) return;
      if (!this.action_ctrl.isSpecialBid(vo.bid)) return;
      this.setTabStatus(vo.bid);
    }, this);
    this.addGlobalEvent(ActionEvent.UPDATA_FUND_RED_STATUS_EVENT, function () {
      if (this.auto_bid == MainuiConst.icon.fund) {
        this.setTabStatus(this.selected_tab.getData().bid);
      }
    }.bind(this));
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(bid) {
    if (bid) {
      if (bid == MainuiConst.icon.fund) {
        var fund_id_list = ActionController.getInstance().getModel().getOpenFundIds();
 
        for (var k = 0; k < fund_id_list.length; ++k) {
          var v = fund_id_list[k];
          var config = Config.month_fund_data.data_fund_data[v.id];
 
          if (config) {
            var sub_data = {};
            sub_data.bid = v.id;
            sub_data.title = config.name;
            sub_data.ico = config.icon_id;
            this.sub_list.push(sub_data);
          }
        }
 
        this.sub_list.sort(Utils.tableCommonSorter([["bid", false]]));
      } else {
        this.sub_list = this.ctrl.getWelfareSubList();
      }
    } else {
      this.sub_list = this.ctrl.getWelfareSubList();
    }
 
    this.auto_bid = bid || WelfareConst.WelfareIcon.sign;
    this.createSubType();
  },
  createSubType: function createSubType() {
    var _this = this;
 
    if (this.sub_list == null || Utils.next(this.sub_list) == null) {} else {
      var sum = Utils.getArrLen(this.sub_list);
      var max_width = sum * (this.tab_width + this.off_space) + 110;
      this.max_width = Math.max(this.tab_scroll_nd.width, max_width);
      this.tab_scroll_content_nd.width = this.max_width;
      this.tab_scroll_sv.scrollToLeft(0);
 
      var call_back = function (item) {
        if (item.getData().bid == WelfareConst.WelfareIcon.quest) {
          this.ctrl.openSureveyQuestView(true);
        } else {
          this.handleSelectedTab(item);
 
          if (item.getData().bid == ActionConst.FundType.type_one || item.getData().bid == ActionConst.FundType.type_two) {
            var _model = require("action_controller").getInstance().getModel();
 
            if (item.getData().bid == ActionConst.FundType.type_one) {
              _model.updateFundRedStatus(ActionConst.FundRedIndex.fund_buy_one, false);
            } else {
              _model.updateFundRedStatus(ActionConst.FundRedIndex.fund_buy_two, false);
            }
          }
        }
      }.bind(this);
 
      var index_selected = -1;
      var tab_item = null;
      var _x = null;
      var data = null;
 
      var _loop = function _loop(i) {
        var data = _this.sub_list[i];
        Utils.delayRun(_this.tab_scroll_content_nd, 0.01 * Number(i), function () {
          if (data != null && data.bid != null && this.tab_list[data.bid] == null) {
            var WelfareTab = require("welfare_tab_panel");
 
            tab_item = new WelfareTab();
            tab_item.show();
            tab_item.setData(data);
            _x = i * (this.tab_width + this.off_space) + 110;
            tab_item.setPosition(_x, -68);
            tab_item.setClickCallBack(call_back);
            tab_item.setParent(this.tab_scroll_content_nd);
            this.tab_list[data.bid] = tab_item;
 
            if (this.auto_bid != null) {
              if (this.auto_bid == data.bid) {
                index_selected = i;
              } else if (this.auto_bid == MainuiConst.icon.fund && (data.bid == ActionConst.FundType.type_one || data.bid == ActionConst.FundType.type_two)) {
                index_selected = 0;
              }
            } //设置红点状态
 
 
            this.setTabStatus(data.bid);
          }
        }.bind(_this));
      };
 
      for (var i = 0; i < sum; i++) {
        _loop(i);
      } // if (index_selected == 0) {
      //     index_selected = 0;
      // }
      // //手动设置选中第一个
 
 
      this.timer_hander = this.startUpdate(20, function () {
        data = this.sub_list[index_selected];
 
        if (data != null) {
          if (index_selected && index_selected != 1) {
            this.tab_scroll_sv.scrollToPercentHorizontal(index_selected / sum, 0.5);
          }
 
          this.handleSelectedTab(this.tab_list[data.bid]);
          this.stopUpdate(this.timer_hander);
        }
      }.bind(this), 100);
    }
  },
  //设置标签页红点状态
  setTabStatus: function setTabStatus(bid) {
    var vo;
 
    if (bid == ActionConst.FundType.type_one || bid == ActionConst.FundType.type_two) {
      var _model = require("action_controller").getInstance().getModel();
 
      if (bid == ActionConst.FundType.type_one) {
        vo = _model.getFundRedStatusByBid(ActionConst.FundRedIndex.fund_get_one);
 
        if (!vo) {
          vo = _model.getFundRedStatusByBid(ActionConst.FundRedIndex.fund_buy_one);
        }
      } else if (bid == ActionConst.FundType.type_two) {
        vo = _model.getFundRedStatusByBid(ActionConst.FundRedIndex.fund_get_two);
 
        if (!vo) {
          vo = _model.getFundRedStatusByBid(ActionConst.FundRedIndex.fund_buy_two);
        }
      }
    } else {
      vo = this.ctrl.getWelfareStatusByID(bid);
    }
 
    if (this.action_ctrl.isSpecialBid(bid)) {
      vo = this.action_ctrl.getHolidayAweradsStatus(bid);
    }
 
    var tab_item = this.tab_list[bid];
    if (tab_item == null) return;
 
    if (vo == null || vo.status == false || vo == false) {
      if (tab_item.updateTipsStatus) {
        tab_item.updateTipsStatus(false);
      }
    } else {
      if (tab_item.updateTipsStatus) {
        tab_item.updateTipsStatus(true);
      }
    }
  },
  handleSelectedTab: function handleSelectedTab(tab) {
    if (this.selected_tab != null && this.selected_tab == tab) return;
 
    if (this.selected_tab != null) {
      this.selected_tab.setSelected(false);
    }
 
    this.selected_tab = tab;
 
    if (this.selected_tab != null) {
      this.selected_tab.setSelected(true);
    }
 
    this.changePanelByTab();
  },
  changePanelByTab: function changePanelByTab() {
    if (this.selected_tab == null || this.selected_tab.data == null) return;
    var data = this.selected_tab.data;
    if (data.bid == null || data.bid == 0) return;
 
    if (data.panel_type == null || data.panel_type == 0 || WelfareConst.WelfarePanelTypeView[data.panel_type] == null) {
      if (data.bid == ActionConst.FundType.type_one || data.bid == ActionConst.FundType.type_two) {} else {
        return;
      }
    }
 
    if (this.selected_panel != null) {
      if (this.selected_panel.setVisibleStatus) {
        this.selected_panel.setVisibleStatus(false);
      } else {
        this.selected_panel.setVisible(false);
      }
 
      this.selected_panel = null;
    }
 
    if (this.panel_list[data.bid] == null) {
      var view_str = WelfareConst.WelfarePanelTypeView[data.panel_type];
 
      if (view_str) {
        if (this.panel_list[data.bid] == null) {
          this.panel_list[data.bid] = Utils.createClass(view_str);
          this.panel_list[data.bid].show(data.bid);
          this.panel_list[data.bid].setParent(this.container_nd);
        }
      } else {
        var panel_view;
 
        if (data.bid == ActionConst.FundType.type_one || data.bid == ActionConst.FundType.type_two) {
          var fundOnePanel = require("action_fund_one_panel");
 
          panel_view = new fundOnePanel(data.bid);
        } // else if(data.bid == ActionConst.FundType.type_two){
        //     let fundTwoPanel = require("action_fund_two_panel")
        //     panel_view = new fundTwoPanel()
        // }
 
 
        if (panel_view) {
          this.panel_list[data.bid] = panel_view;
          this.panel_list[data.bid].show();
          this.panel_list[data.bid].setParent(this.container_nd);
          this.panel_list[data.bid].setPosition(0, -20);
        }
      }
    }
 
    this.selected_panel = this.panel_list[data.bid];
 
    if (this.selected_panel != null) {
      if (this.selected_panel.setVisibleStatus) {
        this.selected_panel.setVisibleStatus(true);
      } else {
        this.selected_panel.setVisible(true);
      }
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    for (var k in this.panel_list) {
      if (this.panel_list[k].deleteMe) {
        this.panel_list[k].deleteMe();
        this.panel_list[k] = null;
      }
    }
 
    this.panel_list = null;
 
    for (var k in this.tab_list) {
      if (this.tab_list[k].deleteMe) {
        this.tab_list[k].deleteMe();
        this.tab_list[k] = null;
      }
    }
 
    this.tab_list = null;
    this.tab_scroll_content_nd.stopAllActions();
    this.ctrl.openMainWindow(false);
  }
});
 
cc._RF.pop();