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
381
382
383
384
385
386
387
388
389
// --------------------------------------------------------------------
// @author: @syg.com(必填, 创建模块的人员)
// @description:
//      竖版商城列表子项
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var MallController = require("mall_controller");
var MallEvent = require("mall_event");
var RoleController = require("role_controller");
 
var MallItem = cc.Class({
    extends: BasePanel,
 
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("mall", "mall_item");
        this.ctrl = MallController.getInstance();
        this.size = cc.size(306, 143);
        this.width = 306;
        this.height = 143;
        this.vo = null;
        this.data = null;
        this.is_touch = true;
        this.role_vo = RoleController.getInstance().getRoleVo();
    },
 
    initPanel: function () {
        this.main_container = this.root_wnd.getChildByName("main_container");
 
        this.name = this.main_container.getChildByName("name").getComponent(cc.Label);
        this.coin = this.main_container.getChildByName("count_bg").getChildByName("coin").getComponent(cc.Sprite);
        this.price = this.main_container.getChildByName("count_bg").getChildByName("price").getComponent(cc.Label);
 
        this.good = this.main_container.getChildByName("good");
        this.goods_item = ItemsPool.getInstance().getItem("backpack_item");
        this.goods_item.initConfig(false, 1, false, true)
        // this.goods_item.setPosition(10 + BackPackItem.Width / 2, this.root_wnd.getContentSize().height / 2)
        this.goods_item.setParent(this.good);
        this.goods_item.show();
 
        this.discount = this.main_container.getChildByName("discount");
        this.discount_num = this.discount.getChildByName("discount_num").getComponent(cc.Label);
        this.discount.active = false;
        this.discount_label = this.main_container.getChildByName("discount_label").getComponent(cc.RichText);
 
        this.sold = this.main_container.getChildByName("sold");
        this.sold.active = false;
 
        this.grey = this.main_container.getChildByName("grey");
        this.grey.active = false;
 
        this.need_icon = this.main_container.getChildByName("need_icon");
        this.need_label = this.main_container.getChildByName("need_label").getComponent(cc.Label);
        this.need_icon.active = false;
        this.need_label.node.active = false;
 
        this.setSellAll(false);
        this.setData(this.data);
    },
 
    registerEvent: function () {
        this.main_container.on(cc.Node.EventType.TOUCH_END,function(){
            if (!this.is_touch)
                return
            if(this.vip_limit_flag > 0){
                message(cc.js.formatStr(Utils.TI18N("VIP%s以上可购买"),this.vip_limit_flag));
                return
            }
            if (this.rank_limit_flag){
                message(Utils.TI18N("未满足购买条件"));
                return
            }
            if (this.limit_glev_status){
                message(Utils.TI18N("该商品暂未达解锁条件哦,请努力提高公会等级"));
                return
            }
            if (this.callback)
                this.callback(this.data);
        },this)
 
        //除神秘商城以外的购买成功
        this.addGlobalEvent(MallEvent.Buy_Success_Event, function (data) {
            if (this.data.id && data.eid == this.data.id && Utils.next(data.ext || {}) != null) {
                this.data.has_buy = data.ext[0].val;
                this.discount_label.string = cc.js.formatStr(Utils.TI18N("<color=#452505>%s <color=#289b14>%s/%s</color>个</color>"), this.str, this.data.has_buy,this.data.limit_num);
                if (this.data.has_buy == this.data.limit_num)
                    this.setSellAll(true);
            }
        }.bind(this))
 
        //神秘/神格商城购买成功
        this.addGlobalEvent(MallEvent.Buy_One_Success, function (data) {
            if (this.data.order && data.order == this.data.order) {
                this.data.has_buy = this.data.has_buy+1;
                this.discount_label.string = cc.js.formatStr(Utils.TI18N("<color=#452505>%s <color=#289b14>%s/%s</color>个</color>"), this.str, this.data.has_buy, this.data.limit_num);
                var limit_num = this.data.limit_count || this.data.limit_num;
                if (limit_num != null || this.data.has_buy >= this.data.limit_num)
                    this.setSellAll(true);
            }
        }.bind(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){
                    if(key == "gold"||key == "red_gold" || key == "hero_soul" || key == "arena_cent" || key == "friend_point" || key == "guild"){
                        if(this.data["limit_day"] == 0 && this.data["limit_month"] == 0 && this.data["limit_week"] == 0 && this.data["limit_count"] ==0){
                            //不限购的非神秘神格商店物品
                            if(this.data.shop_type != 4 && this.data.shop_type != 2){
                                if(this.pay_type != "red_gold_or_gold"){
                                    if(this.role_vo[this.pay_type] && this.role_vo[this.pay_type] <(20*this.data.price)){
                                        var temp = Math.floor(this.role_vo[this.pay_type]/this.data.price);
                                        if(temp >= 1){
                                            this.data.limit_num = temp;
                                        }else{
                                            this.data.limit_num = 1
                                        }
                                    }else{
                                        this.data.limit_num = 20;
                                    }
                                }else{
                                    var own = this.role_vo["gold"] + this.role_vo["red_gold"];
                                    if(own && own <(20*this.data.price)){
                                        var temp = Math.floor(own/this.data.price);
                                        if(temp >= 1){
                                            this.data.limit_num = temp;
                                        }else{
                                            this.data.limit_num = 1;
                                        }
                                    }else{
                                        this.data.limit_num = 20;
                                    }
                                }
                            }
                        }
                    }
                    if (key == "vip_lev"){
                        if(this.vip_limit_flag > 0){
                            this.setData(this.data);
                        }
                    }
                },this)
            }
        }
    },
 
    setData: function (data) {
        this.data = data;
        if (this.root_wnd == null)
            return
        // return
        var shop_num = null; //商品类型
        if (data.shop_type != null)
            shop_num = data.shop_type;
        else
            shop_num = data.type;
 
        this.data = Utils.deepCopy(data);
        var config = Utils.getItemConfig(data.item_bid || data.item_id);
        config = Utils.deepCopy(config)
        var pay_config, pay_type;
        config.bid = data.item_bid || data.item_id;
        if (config) {
            if (data.item_num && data.item_num != 1){
                config.num = data.item_num;
            }
            this.goods_item.setData(config);
            this.name.string = config.name;
        }
        // this.goods_item.setDefaultTips();
        if(typeof(data.pay_type)=="number"){
            pay_config = Utils.getItemConfig(data.pay_type);
            pay_type = gdata("item_data","data_assets_id2label",[data.pay_type]);
        }else{
            pay_config = Utils.getItemConfig(gdata("item_data","data_assets_label2id",[data.pay_type]));
            pay_type = data.pay_type;
        }
        this.pay_type = pay_type;
        this.price.string = data.price;
        var item_res_path = PathTool.getItemRes(pay_config.icon)
        if (item_res_path){
            this.loadRes(item_res_path, function (res_object) {
                this.coin.spriteFrame = res_object;
            }.bind(this))
        }
        
 
        //限购
        this.str = "";
        var limit_num = 0;
        var limit_rank = 0;
        var limit_vip = 0;
        var is_show_limit_label = false;
 
        //天梯排名限购
        this.rank_limit_flag = false;
        if (data.limit_rank && data.limit_rank > 0) {
            if (shop_num == MallConst.MallType.Ladder) {
                var ladder_data = LadderController.getInstance().getModel().getLadderMyBaseInfo();
                if(ladder_data && ladder_data.best_rank == 0 || ladder_data.best_rank > data.limit_rank){
                    limit_rank = data.limit_rank;
                    is_show_limit_label = true
                }
            }
        }
 
        //vip等级限购
        this.vip_limit_flag = 0;
        if (data.limit_vip && data.limit_vip > 0) {
            if (this.role_vo && this.role_vo.vip_lev < data.limit_vip) {
                is_show_limit_label = true;
                limit_vip = data.limit_vip;
            }
        }
 
        if (is_show_limit_label == false) {
            if (data.limit_count != null && data.limit_count > 0) {
                this.str = "限购";
                limit_num = data.limit_count;
                is_show_limit_label = true;
            } else if (data.limit_month != null && data.limit_month > 0) {
                this.str = "每月限购";
                limit_num = data.limit_month;
                is_show_limit_label = true;
            } else if (data.limit_week != null && data.limit_week > 0) {
                this.str = "每周限购";
                limit_num = data.limit_week;
                is_show_limit_label = true;
            } else if (data.limit_day != null && data.limit_day > 0) {
                this.str = "每日限购";
                limit_num = data.limit_day;
                is_show_limit_label = true;
            } else {
                if (data.shop_type == 4 || data.shop_type == 2) {
                    limit_num = 1;
                    is_show_limit_label = true;
                } else {
                    if (pay_type != "red_gold_or_gold") {
                        if (this.role_vo[pay_type] && this.role_vo[pay_type] < (20 * data.price)) { //取资产最大可买
                            var temp = Math.floor(this.role_vo[pay_type] / data.price);
                            if (temp >= 1)
                                limit_num = temp;
                            else
                                limit_num = 1;
                        } else {
                            limit_num = 20; //无限制购买的物品 一次购买上限20
                            is_show_limit_label = false;
                        }
                    } else {
                        var own = this.role_vo.gold + this.role_vo.red_gold;
                        if (own != null && own < (20 * data.price)) {
                            var temp = Math.floor(own / data.price)
                            if (temp >= 1)
                                limit_num = temp;
                            else
                                limit_num = 1;
                        } else {
                            limit_num = 20; //无限制购买的物品 一次购买上限20
                            is_show_limit_label = false;
                        }
                    }
                }
            }
        }
 
        if (limit_vip > 0 && is_show_limit_label) {
            this.discount_label.node.active = true;
            this.discount_label.string = cc.js.formatStr(Utils.TI18N("<color=#452505><color=#289b14>      VIP%d</color>专属</color>"), limit_vip)
            this.setSellAll(false);
            this.vip_limit_flag = limit_vip;
        } else if (limit_num > 0 && is_show_limit_label) {
            this.discount_label.node.active = true;
            this.discount_label.string = cc.js.formatStr(Utils.TI18N("<color=#452505>%s <color=#289b14>%s/%s</color>个</color>"), this.str, data.has_buy, limit_num);
            if (data.has_buy == limit_num)
                this.setSellAll(true)
            else
                this.setSellAll(false)
        } else if (limit_rank > 0 && is_show_limit_label) {
            this.discount_label.node.active = true;
            this.discount_label.string = cc.js.formatStr(Utils.TI18N("<color=#452505><color=#ff1f0e>需达到%s名</color></color>"), limit_rank);
            this.setSellAll(false);
            this.rank_limit_flag = true;
        } else {
            this.discount_label.node.active = false;
            if (data.has_buy == 1)
                this.setSellAll(true);
            else
                this.setSellAll(false);
        }
 
        this.data.limit_num = limit_num;
        this.data.is_show_limit_label = is_show_limit_label;
 
        //折扣标签和折扣价格
        if (data.label != null && data.label > 0) {  //表里的
            this.discount.active = true;
            this.discount_num.string = data.label + Utils.TI18N("折");
        } else if (data.discount_type != null && data.discount_type > 0) { //服务器信息
            this.discount.active = true;
            this.discount_num.string = data.discount_type + Utils.TI18N("折");
        } else if(data.lable != null && data.lable> 0){
            this.discount.active = true;
            this.discount_num.string = Utils.TI18N("超值");
        }else {
            this.discount.active = false;
        }
 
        if (data.discount != null && data.discount > 0) {
            this.price.string = data.discount;
        }
 
        if (this.data.type == 10 || this.data.type == 11 || this.data.type == 12 || this.data.type == 13) {//装备特殊处理显示等级显示
            this.isShowLevLimit(true, this.data.lev);
        } else {
            this.isShowLevLimit(false);
        }
 
        if (this.data.type == 5 && this.data.glev != null) {
            this.isShowGLevLimit(true, this.data.glev);
        } else {
            this.isShowGLevLimit(false, 0);
        }
 
        var bid = this.ctrl.getNeedBid();
        if (bid != null && (bid == data.item_id || bid == data.item_bid)) {
            this.need_icon.active = true;
            this.need_label.node.active = true;
        } else {
            this.need_icon.active = false;
            this.need_label.node.active = false;
        }
 
        if (this.data.type == 3) {
            var is_show = this.ctrl.getModel().checkHeroChips(data.item_id);
            this.showChipTag(is_show);
        } else {
            this.showChipTag(false);
        }
    },
 
    setSellAll: function (bool) {
        if(this.root_wnd==null)return
        this.sold.active = bool;
        this.grey.active = bool;
        this.is_touch = !bool;
    },
 
    showChipTag: function (status) {
 
    },
 
    isShowLevLimit: function (status, lev) {
        if(!this.limit_lev_label){
 
        }
    },
 
    isShowGLevLimit: function (status, lev) {
 
    },
 
    addCallBack:function(value){
        this.callback = value;
    },
 
    onShow: function () {
 
    },
 
    onDelete: function () {
        if(this.role_update_event){
            if(this.role_vo){
                this.role_vo.unbind(this.role_update_event);
                this.role_update_event = null;
                this.role_vo = null;
            }
        }
        if(this.goods_item){
            this.goods_item.deleteMe();
            this.goods_item = null;
        }
        // if(this.main_container){
        //     this.main_container.off(cc.Node.EventType.TOUCH_END,function(){},this)
        // }
 
    }
 
 
});
 
module.exports = MallItem;