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
"use strict";
cc._RF.push(module, 'd2940cZ54tG06gpzkmWRYBh', 'collect_panel');
// Scripts/mod/welfare/view/collect_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     收藏有礼
// <br/>Create: 2019-04-25 16:44:35
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var WelfareEvent = require("welfare_event");
 
var CollectPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("welfare", "collect_panel");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.ctrl = require("welfare_controller").getInstance();
    this.item_list = {};
    this.is_can_get = false;
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.main_container = this.seekChild("main_container");
    this.item_container = this.seekChild(this.main_container, "item_container");
    this.bg_sp_2 = this.seekChild(this.main_container, "bg_2", cc.Sprite);
    this.loadRes(PathTool.getBigBg("welfare/txt_cn_shwx_collect", "jpg"), function (res) {
      this.bg_sp_2.spriteFrame = res;
    }.bind(this));
    this.desc = this.seekChild(this.main_container, "txt_2", cc.Label);
    this.desc.string = Utils.TI18N("1.点击“右上角三个点” •••\n2.点击“添加到我的小程序”\n3.点击“关闭圆圈” ⊙\n4.点击我的小程序“剑魂之光”开启游戏,领取奖励");
    this.go_btn = this.seekChild(this.main_container, "go_btn");
    this.go_btn_lb = this.seekChild(this.go_btn, "label", cc.Label);
    this.go_btn_lb.string = Utils.TI18N("收藏领好礼");
    this.go_btn_lo = this.seekChild(this.go_btn, "label", cc.LabelOutline);
    this.go_btn_btn = this.seekChild(this.main_container, "go_btn", cc.Button);
 
    if (this.ctrl.getModel().getCollectAwardStatus() == 1) {
      this.go_btn_lb.string = Utils.TI18N("已领取");
      this.go_btn_lo.enabled = false;
      Utils.setGreyButton(this.go_btn_btn);
    }
 
    if (window.wx) {
      var options = wx.getLaunchOptionsSync();
      var val = wx.getStorageSync("is_open_scene");
 
      if (val == 1 || options && options.scene && (options.scene == 1001 || options.scene == 1089 || options.scene == 1103 || options.scene == 1104)) {
        this.is_can_get = true;
        wx.setStorageSync("is_open_scene", 1);
      }
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.go_btn.on("click", function () {
      Utils.playButtonSound(1);
 
      if (PLATFORM_TYPR == "SH_SDK") {
        //深海小程序
        this.clickGoBtnBySHWX();
      }
    }.bind(this));
    this.addGlobalEvent(WelfareEvent.Update_get_SHWX_collect_award_status, function (status) {
      // meesage(status)
      if (status == 2) {
        this.go_btn_lb.string = Utils.TI18N("收藏领好礼");
      } else if (status == 1) {
        this.go_btn_lb.string = Utils.TI18N("已领取");
        this.go_btn_lo.enabled = false;
        Utils.setGreyButton(this.go_btn_btn);
      }
    }.bind(this));
    this.addGlobalEvent(WelfareEvent.Update_SHWX_show_scene_val, function (scene) {
      if (this.ctrl.getModel().getCollectAwardStatus() == 1 || this.is_can_get == true) {
        return;
      }
 
      if (window.wx) {
        var val = wx.getStorageSync("is_open_scene");
 
        if (val == 1 || scene && (scene == 1001 || scene == 1089 || scene == 1103 || scene == 1104)) {
          this.is_can_get = true;
          wx.setStorageSync("is_open_scene", 1);
        }
      }
    }.bind(this));
  },
  clickGoBtnBySHWX: function clickGoBtnBySHWX() {
    if (this.is_can_get == true) {
      if (this.ctrl.getModel().getCollectAwardStatus() == 0) {
        this.ctrl.send16696();
      }
    } else {
      message(Utils.TI18N("请先收藏到我的小程序"));
    }
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {
    this.setItemList();
  },
  setItemList: function setItemList() {
    if (PLATFORM_TYPR == "SH_SDK") {
      var bind_data = this.ctrl.getModel().getCollectAward();
      if (bind_data == null) return;
      var index = 0;
 
      for (var i in bind_data) {
        var v = bind_data[i];
 
        if (!this.item_list[i]) {
          var item = ItemsPool.getInstance().getItem("backpack_item");
          item.initConfig(false, 0.7, false, true);
          item.show();
          item.setParent(this.item_container);
          item.setData({
            bid: v.bid,
            num: v.num
          });
          item.setPosition(index * 110 - 110, 80);
          this.item_list[i] = item;
          index = index + 1;
        }
      }
    }
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    this.is_shate = false;
 
    if (this.item_list) {
      for (var k in this.item_list) {
        this.item_list[k].deleteMe();
        this.item_list[k] = null;
      }
 
      this.item_list = null;
    }
  }
});
 
cc._RF.pop();