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
"use strict";
cc._RF.push(module, '4ed04BQijlLZabeYNzOWJEK', 'action_limit_gift_main_panel');
// Scripts/mod/action/view/action_limit_gift_main_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-04-25 17:10:55
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var TimeTool = require("timetool");
 
var ActionLimitGiftMainPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("action", "action_limit_gift_main_panel");
    this.data = arguments[0];
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {},
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    var self = this;
    self.main_container = self.root_wnd.getChildByName("main_container");
    var x = this.getPositionX();
    this.setPosition(x, -20);
    self.title_img = self.main_container.getChildByName("title_img");
    self.is_level_gift = false;
 
    if (self.data && self.data.config) {
      var title = self.data.config.res_1 || "txt_cn_action_limit_gift_level";
      var path = PathTool.getUIIconPath("bigbg/limit_gift", title);
      this.loadRes(path, function (res) {
        self.title_img.getComponent(cc.Sprite).spriteFrame = res;
      }.bind(this));
 
      if (self.data.config.codition && self.data.config.codition[0] != null) {
        self.level_img = self.main_container.getChildByName("level_img");
 
        if (self.data.config.codition[0] == "lev") {
          // --说明是等级礼包
          self.is_level_gift = true;
          var level;
 
          if (self.data.config.res_2 == null || self.data.config.res_2 == "") {
            level = "action_limit_gift_level_18";
          } else {
            level = self.data.config.res_2;
          }
 
          var path1 = PathTool.getUIIconPath("bigbg/limit_gift", level);
          this.loadRes(path1, function (res) {
            self.level_img.getComponent(cc.Sprite).spriteFrame = res;
          }.bind(this));
        }
      }
    }
 
    self.item_scrollview = self.main_container.getChildByName("item_scrollview");
    self.content = self.item_scrollview.getChildByName("content"); // self.item_scrollview:setScrollBarEnabled(false)
    // -- self.item_scrollview:setSwallowTouches(false)
 
    self.comfirm_btn = self.main_container.getChildByName("comfirm_btn");
    self.comfirm_label = self.comfirm_btn.getChildByName("label");
    self.time_val = self.main_container.getChildByName("time_val").getComponent(cc.Label); // --和后端协议好..活动结束后会有两天兑换时间..这里把时间减去了
 
    var time = self.data.end_time;
    self.setLessTime(time);
    self.value = self.main_container.getChildByName("value");
 
    if (self.is_level_gift) {
      self.time_val.node.y = -51;
      self.item_scrollview.width = 240;
      self.item_scrollview.y = -97;
      self.content.y = -self.item_scrollview.width / 2; // self.item_scrollview:setContentSize(cc.size(469,240))
    } // self.item_scrollview_size = self.item_scrollview:getContentSize()
 
 
    self.setData(this.data);
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.comfirm_btn.on('click', function () {
      Utils.playButtonSound(1);
      this.onComfirmBtn();
    }, this);
  },
  onComfirmBtn: function onComfirmBtn() {
    var self = this;
    if (!self.data) return;
    if (!self.data.config) return;
    var charge_id = self.data.config.package_id || 0;
    var charge_config = Config.charge_data.data_charge_data[charge_id];
 
    if (charge_config) {
      SDK.pay(charge_config.val, null, charge_config.id, charge_config.name, charge_config.name);
    }
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {},
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  setData: function setData(data) {
    var _this = this;
 
    var self = this;
    if (!data) return;
    if (!data.config) return;
    this.data = data;
    var num = self.data.num || 0;
    self.value.getComponent(cc.Label).string = "剩余: " + num;
    if (self.item_list) return;
    var config = Config.charge_data.data_charge_data[self.data.config.package_id];
 
    if (config) {
      var str = config.val + "元";
      self.comfirm_label.getComponent(cc.Label).string = str;
    } // --物品id
 
 
    var reward = self.data.config.reward || [];
    var scale = 0.9;
    self.item_list = {};
 
    var _loop = function _loop(i) {
      Utils.delayRun(self.content, i / 30, function () {
        var node = new cc.Node();
        node.setContentSize(120 * scale, 120 * scale);
        self.content.addChild(node);
 
        if (!self.item_list[i]) {
          var bid = reward[i][0];
          var _num = reward[i][1];
          var item = ItemsPool.getInstance().getItem("backpack_item");
          item.setDefaultTip(true, false);
          item.setParent(node);
          item.initConfig(false, scale, false, true);
          item.show();
          self.item_list[i] = item;
          item.setData({
            bid: bid,
            num: _num
          });
        }
      }.bind(_this));
    };
 
    for (var i = 0; i < reward.length; ++i) {
      _loop(i);
    }
  },
  setLessTime: function setLessTime(less_time) {
    var self = this;
 
    if (!self.time_val) {
      return;
    }
 
    less_time = less_time || 0;
 
    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) {
    if (time > 0) {
      var str = "剩余时间: " + TimeTool.getTimeFormatDayIIIIII(time);
      this.time_val.string = str;
    } else {
      this.time_val.string = "";
    }
  },
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.time_tichet) {
      gcore.Timer.del(this.time_tichet);
      this.time_tichet = null;
    }
 
    if (this.item_list) {
      for (var i in this.item_list) {
        this.item_list[i].deleteMe();
      }
    }
  }
});
 
cc._RF.pop();