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
"use strict";
cc._RF.push(module, 'd238dS87aRG/IiJ48OB85Gm', 'mall_action_window');
// Scripts/mod/mall/view/mall_action_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-04-19 16:53:47
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var MallController = require("mall_controller");
 
var MallEvent = require("mall_event");
 
var CommonScrollView = require("common_scrollview");
 
var RoleController = require("role_controller");
 
var TimeTool = require("timetool");
 
var MallItem = require("mall_item");
 
var MallConst = require("mall_const");
 
var RoleEvent = require("role_event");
 
var MallActionWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("mall", "mall_action_window"); // this.viewTag = SCENE_TAG.ui;                //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Full; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
 
    this.ctrl = MallController.getInstance();
    this.role_vo = RoleController.getInstance().getRoleVo();
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.tab_list = {};
    this.cur_tab = null;
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    var self = this;
    self.background = self.root_wnd.getChildByName("background");
 
    if (self.background != null) {
      this.loadRes(PathTool.getUIIconPath("bigbg", "bigbg_2", "jpg"), function (res) {
        self.background.getComponent(cc.Sprite).spriteFrame = res;
      }.bind(this));
    }
 
    self.background.scale = FIT_SCALE;
    self.mainContainer = self.root_wnd.getChildByName("main_container");
    self.main_panel = self.mainContainer.getChildByName("main_panel");
    self.tableContainer = self.main_panel.getChildByName("tab_container");
 
    for (var i = 1; i < 5; ++i) {
      var tab_btn = self.tableContainer.getChildByName("tab_btn_" + i);
      tab_btn.getChildByName("tab_tips").active = false;
      tab_btn.getChildByName("red_num").active = false;
      tab_btn.getChildByName("select_bg").active = false;
      ;
      tab_btn.active = false;
      self.tab_list[i] = tab_btn;
    }
 
    self.container = self.main_panel.getChildByName("container");
    self.btn = self.container.getChildByName("btn");
    self.btn_label = self.btn.getChildByName("txt");
    self.btn.active = false;
    self.coin_bg = self.container.getChildByName("Image_50");
    self.coin = self.container.getChildByName("coin");
    self.count = self.container.getChildByName("count");
    self.add_btn = self.container.getChildByName("add_btn");
    self.add_btn.active = false;
    self.refresh_count = self.container.getChildByName("refresh_count");
    self.refresh_count.getComponent(cc.Label).string = "";
    self.tips_btn = self.container.getChildByName('tips_btn');
    self.tips_btn.active = false;
    self.time = self.container.getChildByName("time").getComponent(cc.Label);
    self.time.node.active = false;
    self.good_cons = self.container.getChildByName("good_cons");
    self.winTitle = self.main_panel.getChildByName("win_title");
    self.winTitle.getComponent(cc.Label).string = "活动商城";
    self.close_btn = self.main_panel.getChildByName("close_btn");
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    var _this = this;
 
    this.addGlobalEvent(MallEvent.Update_Action_event, function (data) {
      this.updateData(data);
    }.bind(this)); // --获取所有活动数据
 
    this.addGlobalEvent(MallEvent.Buy_Action_Shop_Success_event, function (data) {
      if (!this.action_data_list) return;
 
      if (this.cur_index && this.action_data_list[this.cur_index]) {
        if (this.action_data_list[this.cur_index].bid == data.bid) {
          var exchange_list = this.action_data_list[this.cur_index].exchange_list;
          var list = this.common_scrollview.data_list;
 
          for (var i = 0; i < list.length; ++i) {
            var cell = list[i];
 
            if (cell.index && exchange_list[cell.index].aim == data.aim) {
              exchange_list[cell.index].buy_count = data.buy_count;
 
              if (this.common_scrollview) {
                this.common_scrollview.updateItemData(cell.index, this.convertItemInfo(exchange_list[cell.index]));
              }
            }
          }
        }
      }
    }.bind(this));
 
    if (this.role_assets_event == null) {
      this.role_assets_event = this.role_vo.bind(RoleEvent.UPDATE_ROLE_ACTION_ASSETS, function (key, value) {
        if (!this.action_data_list) return;
 
        if (this.cur_index && this.action_data_list[this.cur_index]) {
          if (key == this.action_data_list[this.cur_index].need_id) {
            this.count.getComponent(cc.Label).string = value;
          }
        }
      }.bind(this));
    }
 
    var _loop = function _loop(i) {
      var tab_btn = _this.tab_list[i];
      tab_btn.on('click', function () {
        this.changeTabView(i, true);
      }, _this);
    };
 
    for (var i in this.tab_list) {
      _loop(i);
    }
 
    this.close_btn.on('click', function () {
      Utils.playButtonSound(2);
      this.onCloseBtn();
    }, this);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    this.first_bid = params;
    this.ctrl.send16660();
  },
  updateData: function updateData(data) {
    var self = this;
    if (!data) return;
    if (data.holiday_exchanges && Utils.next(data.holiday_exchanges) == null) return; // --记录道具信息
 
    self.dic_item_config = {}; // --商城数据
 
    self.action_data_list = {};
    self.cur_index = 1;
    data.holiday_exchanges.sort(function (a, b) {
      return a.bid - b.bid;
    });
 
    for (var i = 0; i < data.holiday_exchanges.length; ++i) {
      var v = data.holiday_exchanges[i];
      var index = i + 1;
 
      if (self.tab_list[index]) {
        self.tab_list[index].getChildByName("title").getComponent(cc.Label).string = v.exchange_name;
        self.tab_list[index].active = this;
 
        if (self.first_bid && self.first_bid == v.bid) {
          self.cur_index = index;
        }
      }
 
      v.exchange_list.sort(function (a, b) {
        return a.aim - b.aim;
      });
      self.action_data_list[index] = v;
    }
 
    self.changeTabView(self.cur_index);
  },
  changeTabView: function changeTabView(index, is_check) {
    index = Number(index);
    var self = this;
    if (is_check && self.cur_index == index) return;
 
    if (self.cur_tab != null) {
      if (self.cur_tab) {
        self.cur_tab.getChildByName("title").color.fromHEX(Config.color_data.data_color16[2]);
      }
 
      self.cur_tab.getChildByName("select_bg").active = false;
    }
 
    self.cur_index = index;
    self.cur_tab = self.tab_list[index];
 
    if (self.cur_tab != null) {
      var label = self.cur_tab.getChildByName("title");
      label.color.fromHEX(Config.color_data.data_color16[2]);
      self.cur_tab.getChildByName("select_bg").active = true;
    }
 
    self.tips_btn.active = false;
    self.updateScrollviewList();
    self.updateInfo();
  },
  updateScrollviewList: function updateScrollviewList() {
    var self = this;
 
    if (self.common_scrollview == null) {
      var scroll_view_size = self.good_cons.getContentSize();
      var setting = {
        item_class: MallItem,
        start_x: 4,
        //-- 第一个单元的X起点
        space_x: 0,
        //-- x方向的间隔
        start_y: 5,
        //-- 第一个单元的Y起点
        space_y: 0,
        //-- y方向的间隔
        item_width: 306,
        //-- 单元的尺寸width
        item_height: 147,
        //-- 单元的尺寸height
        row: 1,
        //-- 行数,作用于水平滚动类型
        col: 2,
        //-- 列数,作用于垂直滚动类型
        delay: 4,
        //-- 创建延迟时间
        once_num: 1 //-- 每次创建的数量
 
      };
      self.common_scrollview = new CommonScrollView();
      self.common_scrollview.createScroll(self.good_cons, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting, cc.v2(0, 0));
    }
 
    var itemInfo = [];
 
    for (var i = 0; i < self.action_data_list[self.cur_index].exchange_list.length; ++i) {
      var item = self.action_data_list[self.cur_index].exchange_list[i];
      itemInfo.push(this.convertItemInfo(item));
    }
 
    self.common_scrollview.setData(itemInfo, function (cell) {
      this.ctrl.openMallBuyWindow(true, cell);
    }.bind(this));
  },
  convertItemInfo: function convertItemInfo(data) {
    return {
      item_id: data.item_list[0].bid,
      item_num: data.item_list[0].num,
      price: data.expend_num,
      pay_type: data.expend_id,
      shop_type: MallConst.MallType.ActionShop,
      aim: data.aim,
      is_show_limit_label: false,
      limit_count: data.limit_buy,
      name: data.aim_str,
      has_buy: data.buy_count,
      bid: this.action_data_list[this.cur_index].bid,
      //--子活动编号
      lable: data.lable
    };
  },
  // --更新主界面信息
  updateInfo: function updateInfo() {
    var self = this;
    var need_id = self.action_data_list[self.cur_index].need_id;
    var config = Utils.getItemConfig(need_id);
 
    if (config && need_id != 0) {
      var res = PathTool.getItemRes(config.icon);
 
      if (self.record_cost_res == null || self.record_cost_res != res) {
        this.loadRes(res, function (SpriteFrame) {
          this.coin.getComponent(cc.Sprite).spriteFrame = SpriteFrame;
        }.bind(this));
      }
 
      self.coin_bg.active = true;
      self.coin.active = true;
      self.count.active = true;
    } else {
      self.coin_bg.active = false;
      self.coin.active = false;
      self.count.active = false;
    }
 
    var count = self.role_vo.getActionAssetsNumByBid(need_id);
    self.count.getComponent(cc.Label).string = count;
    self.time.node.active = true;
    var time = self.action_data_list[self.cur_index].end_time - gcore.SmartSocket.getTime();
 
    if (time < 0) {
      time = 0;
    }
 
    self.setLessTime(time);
  },
  setLessTime: function setLessTime(less_time) {
    if (!this.time) return;
 
    if (less_time > 0) {
      this.setTimeFormatString(less_time);
 
      if (this.time_tichet == null) {
        this.time_tichet = gcore.Timer.set(function () {
          less_time--;
          this.setTimeFormatString(less_time);
 
          if (less_time < 0) {
            gcore.Timer.del(this.time_tichet);
            this.time_tichet = null;
            this.setTimeFormatString(less_time);
          }
        }.bind(this), 1000, -1);
      }
    } else {
      this.setTimeFormatString(less_time);
    }
  },
  setTimeFormatString: function setTimeFormatString(time) {
    this.rest_time = time;
 
    if (time > 0) {
      this.time.string = "剩余时间:" + TimeTool.getTimeFormatDayIIIIII(time);
    } else {
      this.time.string = "剩余时间: 0";
    }
  },
  onCloseBtn: function onCloseBtn() {
    this.ctrl.openMallActionWindow(false); //--关闭
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.time_tichet) {
      gcore.Timer.del(this.time_tichet);
      this.time_tichet = null;
    }
 
    if (this.common_scrollview) {
      this.common_scrollview.deleteMe();
      this.common_scrollview = null;
    }
 
    if (this.role_assets_event) {
      this.role_vo.unbind(this.role_assets_event);
      this.role_assets_event = null;
    }
 
    this.ctrl.openMallActionWindow(false); //--关闭
  }
});
 
cc._RF.pop();