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
"use strict";
cc._RF.push(module, '3ba6fK/WPlDb7Cx2tWlpg+g', 'vip_panel');
// Scripts/mod/vip/view/vip_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-02-27 21:36:38
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var VipController = require("vip_controller");
 
var RoleController = require("role_controller");
 
var VipEvent = require("vip_event");
 
var CommonScrollView = require("common_scrollview");
 
var VipLabelItemPanel = require("vip_label_item_panel");
 
var VipPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("vip", "vip_panel");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.ctrl = VipController.getInstance();
    this.model = this.ctrl.getModel();
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.item_list = {};
    this.desc_list = {};
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.main_container_nd = this.seekChild("main_container");
    this.chargeCon_nd = this.seekChild(this.main_container_nd, "chargeCon");
    this.goods_scroll_nd = this.seekChild(this.chargeCon_nd, "goods_scroll");
    this.giftCon_nd = this.seekChild(this.chargeCon_nd, "giftCon");
    this.buy_btn_nd = this.seekChild(this.chargeCon_nd, "buy_btn");
    this.buy_btn_nd.active = true;
    this.buy_complete_nd = this.seekChild(this.chargeCon_nd, "buy_complete");
    this.buy_complete_nd.active = false;
    this.buy_btn_lb = this.seekChild(this.buy_btn_nd, "buy_btn_label", cc.Label);
    this.buy_btn_sp = this.seekChild(this.buy_btn_nd, "buy_price", cc.Sprite);
    this.buy_red_nd = this.seekChild(this.buy_btn_nd, "red");
    this.buy_red_nd.active = false;
    this.title_lb = this.seekChild(this.chargeCon_nd, "title", cc.Label);
    this.old_price_rt = this.seekChild(this.chargeCon_nd, "old_price", cc.RichText);
    this.buy_price_sp = this.seekChild(this.buy_btn_nd, "buy_price", cc.Sprite);
    this.sprite_1_nd = this.seekChild(this.main_container_nd, "Sprite_1");
    this.sprite_1_sp = this.seekChild(this.main_container_nd, "Sprite_1", cc.Sprite);
    this.loadRes(PathTool.getUIIconPath("vip", "vipbg5"), function (res) {
      this.sprite_1_sp.spriteFrame = res;
    }.bind(this)); //月卡领取
 
    this.supre_good_con_nd = this.seekChild(this.sprite_1_nd, "good_con");
    var tab_size = this.supre_good_con_nd.getContentSize();
    var setting = {
      item_class: "backpack_item",
      // 单元类
      start_x: 0,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: BackPackItem.Width * 0.6,
      // 单元的尺寸width
      item_height: BackPackItem.Height * 0.6,
      // 单元的尺寸height
      row: 1,
      // 行数,作用于水平滚动类型
      col: 0,
      // 列数,作用于垂直滚动类型
      // need_dynamic: true
      scale: 0.6
    };
    this.item_scrollview = new CommonScrollView();
    this.item_scrollview.createScroll(this.supre_good_con_nd, cc.v2(0, 0), ScrollViewDir.horizontal, ScrollViewStartPos.top, tab_size, setting, cc.v2(0.5, 0.5));
    var tab_size = this.goods_scroll_nd.getContentSize();
    var setting = {
      item_class: "backpack_item",
      // 单元类
      start_x: 0,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 10,
      // y方向的间隔
      item_width: BackPackItem.Width * 0.65,
      // 单元的尺寸width
      item_height: BackPackItem.Height * 0.8,
      // 单元的尺寸height
      row: 1,
      // 行数,作用于水平滚动类型
      col: 0,
      // 列数,作用于垂直滚动类型
      // need_dynamic: true
      scale: 0.65
    };
    this.reward_scrollview = new CommonScrollView();
    this.reward_scrollview.createScroll(this.goods_scroll_nd, cc.v2(0, 0), ScrollViewDir.horizontal, ScrollViewStartPos.top, tab_size, setting, cc.v2(0.5, 0.5));
    var tab_size = this.giftCon_nd.getContentSize();
    var setting = {
      item_class: VipLabelItemPanel,
      // 单元类
      start_x: 0,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: 400,
      // 单元的尺寸width
      item_height: 30,
      // 单元的尺寸height
      row: 1,
      // 行数,作用于水平滚动类型
      col: 1,
      // 列数,作用于垂直滚动类型
      need_dynamic: true
    };
    this.info_scroll = new CommonScrollView();
    this.info_scroll.createScroll(this.giftCon_nd, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, tab_size, setting, cc.v2(0.5, 0.5));
    this.supre_card_get_nd = this.seekChild(this.sprite_1_nd, "btn_get");
    this.supre_card_get_btn = this.seekChild(this.sprite_1_nd, "btn_get", cc.Button);
    this.supre_card_get_nd.active = false;
    this.supre_card_get_lb = this.seekChild(this.supre_card_get_nd, "Text_3_0", cc.Label);
    this.supre_card_get_lb.string = "领取";
    this.supre_card_get_red_nd = this.seekChild(this.supre_card_get_nd, "red_point");
    this.supre_card_get_red_nd.active = false;
    this.des_labellist = {};
    this.red_line_nd = this.seekChild(this.old_price_rt.node, "red_line");
    this.desc_rt = this.seekChild(this.main_container_nd, "desc_label", cc.RichText);
 
    if (this.role_vo.vip_lev > Config.vip_data.data_get_reward_length - 1) {
      this.setData(Config.vip_data.data_get_reward_length - 1);
    } else {
      this.setData(this.role_vo.vip_lev);
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.buy_btn_nd.on(cc.Node.EventType.TOUCH_END, function () {
      var role_vip = this.role_vo.vip_lev;
      var is_vip = this.role_vo.is_vip;
 
      if (role_vip == 0 && is_vip == 1) {
        if (this.config.lev == 0) {
          this.ctrl.sender16711(this.index);
        } else {
          var str = cc.js.formatStr('未达到VIP%s', this.config.lev);
          message(str);
        }
      } else {
        //如果是vip先判断等级足够不
        if (this.config) {
          if (this.config.lev > role_vip) {
            var str = cc.js.formatStr("未达到VIP%s", this.config.lev);
            message(str);
          } else {
            this.ctrl.sender16711(this.index);
          }
        }
      }
    }, this);
    this.addGlobalEvent(VipEvent.UPDATE_GET_LIST, function () {
      var get_list = this.model.getGetGiftList();
 
      if (get_list[this.index] != null) {
        this.buy_price_sp.node.active = false;
        this.buy_btn_nd.active = false;
        this.buy_complete_nd.active = true;
      } else {
        this.buy_price_sp.node.active = true;
        this.buy_btn_nd.active = true;
        this.buy_complete_nd.active = false;
      }
 
      this.updateRed();
    }, this);
 
    if (this.role_vo) {
      if (this.role_update_event == null) {
        this.role_update_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
          this.timer = gcore.Timer.set(function () {
            if (key == "vip_lev") this.updateRed();
          }.bind(this), Math.random() * 1000, 1);
        }, this);
      }
    }
 
    this.addGlobalEvent(VipEvent.SUPRE_CARD_GET, function (status) {
      this.supre_card_get_nd.active = true;
 
      if (status == 1) {
        // this.supre_card_get_btn.interactable = true;
        Utils.setGreyButton(this.supre_card_get_btn, false);
        this.supre_card_get_lb.string = "领取";
        this.supre_card_get_lb.node.color = new cc.Color(113, 40, 4);
        this.supre_card_get_red_nd.active = true;
      } else {
        this.supre_card_get_red_nd.active = false;
 
        if (status == 0) {
          Utils.setGreyButton(this.supre_card_get_btn);
          this.supre_card_get_btn.interactable = true;
          this.supre_card_get_lb.string = "待激活";
          this.supre_card_get_lb.node.color = new cc.Color(113, 40, 4);
        } else {
          // this.supre_card_get_btn.interactable = false;
          Utils.setGreyButton(this.supre_card_get_btn);
          this.supre_card_get_lb.string = "已领取";
          this.supre_card_get_lb.node.color = new cc.Color(255, 255, 255);
        }
      }
    }, this);
    this.supre_card_get_nd.on("click", function () {
      this.ctrl.sender16708();
    }, this);
    this.ctrl.sender16707();
    this.ctrl.sender16710();
    this.ctrl.setIsFirst(false);
  },
  updateRed: function updateRed() {
    var get_list = this.model.getGetGiftList();
 
    if (this.index == this.role_vo.vip_lev) {
      if (get_list[this.index] == null && this.ctrl.getIsFirst()) {
        this.buy_red_nd.active = true;
      } else {
        this.buy_red_nd.active = false;
      }
    } else {
      this.buy_red_nd.active = false;
    }
  },
  setData: function setData(index) {
    this.index = index;
    if (this.root_wnd) this.onShow();
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow() {
    if (this.index == null) return;
    var index = this.index;
    var config = gdata("vip_data", "data_get_reward", [index]);
    var list = [];
    var reward_list = gdata("charge_data", "data_supre_reward_data", [index]).reward;
 
    for (var i in reward_list) {
      var v = reward_list[i];
      var tab = {};
      tab.bid = v[0];
      tab.num = v[1];
      list.push(tab);
    }
 
    this.item_scrollview.setData(list);
    this.item_scrollview.addEndCallBack(function () {
      var list = this.item_scrollview.getItemList();
 
      for (var k in list) {
        if (list[k]) list[k].setDefaultTip();
      }
    }.bind(this));
    this.config = config;
    this.title_lb.string = Utils.TI18N("VIP" + index + "特权");
    var item_id = gdata("item_data", "data_assets_label2id", "gold");
    var res = PathTool.getItemRes(item_id);
    var desc_str = cc.js.formatStr(Utils.TI18N("累计充值<color=#249013>%s </c><img src='%s'/>即可享受以下特权"), this.config.gold, item_id);
    this.desc_rt.string = desc_str;
    this.loadRes(res, function (resObject) {
      this.desc_rt.addSpriteFrame(resObject);
    }.bind(this)); //特权礼包内容
 
    var items = config.items;
    var list = [];
 
    for (var i in items) {
      var v = items[i];
      var tab = {};
      tab.bid = v[0];
      tab.num = v[1];
      list.push(tab);
    }
 
    var extend = {
      scale: 0.65,
      is_show_tips: true
    };
    this.reward_scrollview.setData(list, null, extend); //特权信息
 
    var desc_list = config.spe_desc;
    this.info_scroll.setData(desc_list);
    var item_id2 = Utils.getItemConfig(config.old_price[0][0]).icon;
    var res2 = PathTool.getItemRes(item_id2);
    this.old_price_rt.string = cc.js.formatStr(Utils.TI18N("原价<img src='%s'/>%s"), item_id2, config.old_price[0][1]);
    this.loadRes(res2, function (resObject) {
      this.old_price_rt.addSpriteFrame(resObject);
    }.bind(this));
    this.buy_btn_lb.string = cc.js.formatStr(Utils.TI18N("%d 购买"), config.price[0][1]);
    this.loadRes(PathTool.getItemRes(Utils.getItemConfig(config.old_price[0][0]).icon), function (bg_sf) {
      this.buy_btn_sp.spriteFrame = bg_sf;
    }.bind(this));
    var get_list = this.model.getGetGiftList();
 
    if (get_list && get_list[index] != null) {
      this.buy_price_sp.node.active = false;
      this.buy_btn_nd.active = false;
      this.buy_complete_nd.active = true;
    } else {
      this.buy_price_sp.node.active = true;
      this.buy_btn_nd.active = true;
      this.buy_complete_nd.active = false;
    }
 
    this.updateRed();
  },
  clearItemList: function clearItemList() {
    if (this.item_list) {
      for (var k in this.item_list) {
        var item = this.item_list[k];
 
        if (item) {
          item.setVisible(false);
        }
      }
    }
  },
  setVisibleStatus: function setVisibleStatus(status) {
    this.setVisible(status);
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    for (var k in this.item_list) {
      if (this.item_list[k]) {
        this.item_list[k].deleteMe();
        this.item_list[k] = null;
      }
    }
 
    this.item_list = null;
 
    if (this.role_vo) {
      if (this.role_update_event != null) {
        this.role_vo.unbind(this.role_update_event);
        this.role_update_event = null;
      }
    }
 
    this.role_vo = null;
 
    if (this.item_scrollview) {
      this.item_scrollview.DeleteMe();
    }
 
    this.item_scrollview = null;
 
    if (this.info_scroll) {
      this.info_scroll.DeleteMe();
    }
 
    this.info_scroll = null;
  }
});
 
cc._RF.pop();