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
"use strict";
cc._RF.push(module, '79ae0DGSAJDmrW9FteIzBBg', 'action_high_value_gift_panel');
// Scripts/mod/action/view/action_high_value_gift_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     超值礼包/限时礼包
// <br/>Create: 2019-07-03 19:20:01
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var ActionEvent = require("action_event");
 
var ActionConst = require("action_const");
 
var ActionController = require("action_controller");
 
var CommonScrollView = require("common_scrollview");
 
var Action_high_value_giftPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("action", "action_high_value_gift_panel");
    this.holiday_bid = arguments[0];
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.ctrl = ActionController.getInstance();
    this.model = this.ctrl.getModel();
    this.touch_btn = true;
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.main_container = this.root_wnd.getChildByName("main_container");
    this.img_bg = this.main_container.getChildByName("img_bg").getComponent(cc.Sprite);
    var str = "txt_cn_action_high_value_gift_panel";
    var config_data = Config.function_data.data_limit_little_recharge[this.holiday_bid];
 
    if (config_data && config_data.bg_name && config_data.bg_name != "") {
      str = config_data.bg_name;
    }
 
    var res = PathTool.getBigBg(str, null, "action");
    this.loadRes(res, function (resObject) {
      this.img_bg.spriteFrame = resObject;
    }.bind(this));
    this.txt_time_title = this.main_container.getChildByName("txt_time_title").getComponent(cc.Label); //时间标题
 
    this.txt_time_title.string = Utils.TI18N("剩余时间:");
    this.txt_time_title.node.color = new cc.Color().fromHEX(config_data.time_title_color.toString()); //设置字体颜色
 
    this.txt_time_title_line = this.main_container.getChildByName("txt_time_title").getComponent(cc.LabelOutline);
    this.txt_time_title_line.color = new cc.Color().fromHEX(config_data.time_stroke_color);
    this.txt_time_val = this.main_container.getChildByName("txt_time_val").getComponent(cc.Label); //剩余时间
 
    this.txt_time_val.node.color = new cc.Color().fromHEX(config_data.time_title_color);
    this.txt_time_val_line = this.main_container.getChildByName("txt_time_val").getComponent(cc.LabelOutline);
    this.txt_time_val_line.color = new cc.Color().fromHEX(config_data.time_stroke_color);
    this.txt_price = this.main_container.getChildByName("txt_price").getComponent(cc.Label); //礼包原价
 
    this.txt_price.node.color = new cc.Color().fromHEX(config_data.common_color);
    this.txt_discount_title = this.main_container.getChildByName("txt_discount_title").getComponent(cc.Label);
    this.txt_discount_title.string = Utils.TI18N("现价:");
    this.txt_discount_title.node.color = new cc.Color().fromHEX(config_data.common_color);
    this.txt_discount_price = this.main_container.getChildByName("txt_discount_price").getComponent(cc.Label); //礼包折扣价
 
    this.txt_discount_price.node.color = new cc.Color().fromHEX(config_data.common_color);
    this.txt_limit_time = this.main_container.getChildByName("txt_limit_time").getComponent(cc.Label); //礼包限购次数
 
    this.txt_limit_time.node.color = new cc.Color().fromHEX(config_data.common_color);
    this.btn_buy = this.main_container.getChildByName("btn_buy");
    this.btn_buy_bt = this.main_container.getChildByName("btn_buy").getComponent(cc.Button);
    this.txt_buy = this.btn_buy.getChildByName("txt_buy").getComponent(cc.Label);
    this.txt_buy.string = Utils.TI18N("立即抢购");
    this.txt_buy_line = this.btn_buy.getChildByName("txt_buy").getComponent(cc.LabelOutline);
    var send_data = config_data.send_data;
 
    if (send_data && Utils.next(send_data) != null) {
      var bid = send_data[0][0];
      var num = send_data[0][1];
      var send_img = Utils.createImage(this.main_container, null, 229, 616, cc.v2(0, 0.5), false, 1, false);
      this.loadRes(PathTool.getItemRes(bid), function (send_img, resObject) {
        send_img.spriteFrame = resObject;
      }.bind(this, send_img));
      send_img.node.scale = 0.4;
      this.send_num_nd = this.seekChild("send_val");
      this.send_num_nd.active = true;
      this.send_num = this.send_num_nd.getComponent("CusRichText");
      this.send_num.setNum(num);
    }
 
    this.goods_list = this.main_container.getChildByName("goods_list");
    var scroll_size = this.goods_list.getContentSize();
    var setting = {
      item_class: "backpack_item",
      // 单元类
      start_x: 10,
      // 第一个单元的X起点
      space_x: 25,
      // x方向的间隔
      start_y: 8,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: 120 * 0.9,
      // 单元的尺寸width
      item_height: 120 * 0.9,
      // 单元的尺寸height
      row: 1,
      // 行数,作用于水平滚动类型
      col: 0 // 列数,作用于垂直滚动类型
 
    };
    this.item_scroll_view = new CommonScrollView();
    this.item_scroll_view.createScroll(this.goods_list, cc.v2(-scroll_size.width / 2, 0), ScrollViewDir.horizontal, ScrollViewStartPos.top, scroll_size, setting);
    this.item_scroll_view.setClickEnabled(false);
 
    if (this.holiday_bid == ActionConst.ActionRankCommonType.week_gift) {
      this.txt_time_title.node.y = 569;
      this.txt_time_val.node.y = 569;
    }
 
    this.ctrl.cs16603(this.holiday_bid);
    this.model.setGiftRedStatus({
      bid: ActionConst.ActionRankCommonType.high_value_gift,
      status: false
    });
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.addGlobalEvent(ActionEvent.UPDATE_HOLIDAY_SIGNLE, function (data) {
      if (!data) return;
 
      if (data.bid == this.holiday_bid) {
        this.setData(data);
      }
    }.bind(this));
    this.addGlobalEvent(ActionEvent.Is_Charge_Event, function (data) {
      if (data && data.status && data.charge_id) {
        var charge_config = Config.charge_data.data_charge_data[data.charge_id];
 
        if (charge_config && data.status == 1 && data.charge_id == this.cur_charge_id) {
          SDK.pay(charge_config.val, 1, charge_config.id, charge_config.name, charge_config.name);
        }
      }
    }.bind(this));
    Utils.onTouchEnd(this.btn_buy, function () {
      if (!this.touch_btn) return;
 
      if (this.get_item_ticket == null) {
        this.get_item_ticket = gcore.Timer.set(function () {
          this.touch_btn = true;
 
          if (this.get_item_ticket != null) {
            gcore.Timer.del(this.get_item_ticket);
            this.get_item_ticket = null;
          }
        }.bind(this), 2, 1);
        this.touch_btn = null;
 
        if (this.data && this.data.charge_id && this.data.left_time > 0) {
          this.cur_charge_id = this.data.charge_id;
          this.ctrl.sender21016(this.data.charge_id);
        }
      }
    }.bind(this), 1);
  },
  setData: function setData(data) {
    if (!data) return; // 倒计时
 
    var time = data.remain_sec || 0;
    this.model.setCountDownTime(this.txt_time_val, time);
    this.data = data.aim_list[0]; // 限购:已购次数/总次数
 
    var totle_count = null;
    var current_count = null;
    var current_list = Utils.keyfind('aim_args_key', ActionConst.ActionExtType.RechageCurCount, this.data.aim_args);
    var totle_list = Utils.keyfind('aim_args_key', ActionConst.ActionExtType.RechageTotalCount, this.data.aim_args);
    current_count = current_list.aim_args_val || 0;
    totle_count = totle_list.aim_args_val || 0;
    this.txt_limit_time.string = Utils.TI18N(cc.js.formatStr("限购:%d/%d", current_count, totle_count)); // 剩余购买次数
 
    this.data.left_time = totle_count - current_count; // 折扣前价格、折扣后价格
 
    var price = null;
    var discount_price = null;
    var price_list = Utils.keyfind('aim_args_key', ActionConst.ActionExtType.ActivityOldPrice, this.data.aim_args);
    var dis_price_list = Utils.keyfind('aim_args_key', ActionConst.ActionExtType.ActivityCurrentPrice, this.data.aim_args);
    price = price_list.aim_args_val || 0;
    discount_price = dis_price_list.aim_args_val || 0;
    this.txt_price.string = Utils.TI18N(cc.js.formatStr("原价:¥%d", price));
    this.txt_discount_price.string = Utils.TI18N(cc.js.formatStr("¥%d", discount_price));
    var charge_list = Utils.keyfind('aim_args_key', ActionConst.ActionExtType.ItemRechargeId, this.data.aim_args); // 支付物品ID
 
    this.data.charge_id = charge_list.aim_args_val || 0; // 加载礼包物品列表
 
    this.loadRewardList(this.data.item_list);
 
    if (this.data.left_time == 0) {
      this.txt_buy.string = Utils.TI18N("已领取");
      this.txt_buy_line.color = new cc.Color(0x55, 0x55, 0x55, 0x55);
      this.btn_buy_bt.interactable = false;
      this.btn_buy_bt.enableAutoGrayEffect = true;
    } else {
      this.btn_buy_bt.interactable = true;
      this.btn_buy_bt.enableAutoGrayEffect = false;
    }
  },
  loadRewardList: function loadRewardList(item_list) {
    var list = [];
 
    if (item_list.length > 0) {
      for (var i in item_list) {
        var vo = {};
 
        if (vo) {
          vo.bid = item_list[i].bid;
          vo.num = item_list[i].num;
          list.push(vo);
        }
      }
 
      var item_count = list.length;
      var scroll_size = this.goods_list.getContentSize();
 
      if (item_count > 5) {
        this.item_scroll_view.setClickEnabled(true);
 
        if (this.item_scroll_view.root_wnd) {
          this.item_scroll_view.root_wnd.x = -scroll_size.width / 2;
        }
      } else {
        this.item_scroll_view.setClickEnabled(false);
 
        if (this.item_scroll_view.root_wnd) {
          this.item_scroll_view.root_wnd.x = -scroll_size.width / 2 + (5 - item_count) * 10 + (4 - item_count) * 55;
        }
      }
 
      this.item_scroll_view.setData(list);
      this.item_scroll_view.addEndCallBack(function () {
        var list = this.item_scroll_view.getItemList();
 
        for (var i in list) {
          list[i].setDefaultTip();
        }
      }.bind(this));
    }
  },
  setVisibleStatus: function setVisibleStatus(bool) {
    bool = bool || false;
    this.setVisible(bool);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {},
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.item_scroll_view) {
      this.item_scroll_view.deleteMe();
      this.item_scroll_view = null;
    }
 
    if (this.get_item_ticket != null) {
      gcore.Timer.del(this.get_item_ticket);
      this.get_item_ticket = null;
    }
  }
});
 
cc._RF.pop();