ActivityVipDailyView.lua
3.39 KB
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
local ActivityVipDailyView = dialog.uinode("ui/Activity/ActivityVipAlertLayer.csb",import(".BaseView"))
function ActivityVipDailyView:ctor()
ActivityVipDailyView.super.ctor(self);
end
function ActivityVipDailyView:show()
local scene = cc.Director:getInstance():getRunningScene();
local inst = ActivityVipDailyView:create();
scene:addChild(inst, dialog.ZORDER_APP);
local panel = inst:getChildByName("panel");
panel:setScale(0.5);
local scaleTo = cc.ScaleTo:create(0.2,1);
panel:runAction(scaleTo);
inst:init();
return inst;
end
function ActivityVipDailyView:init()
self:setContentSize(cc.size(display.width,display.height));
ccui.Helper:doLayout(self);
local btn_get = self:getChildByName("panel"):getChildByName("btn_get");
-- local txt_1 = self:getChildByName("panel"):getChildByName("txt_1");
local txt_2 = self:getChildByName("panel"):getChildByName("txt_2");
btn_get.fn = function ()
self:onGetClick(btn_get);
end
btn_get:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, handler(self,self.onGetClick))end);
self.nodes[1] = {btn_get};
local vipList = ShopInfo.getVipList();
local vipInfo = vipList[1];
btn_get.id = vipInfo.id;
-- txt_1:setString(vipInfo.itemList[1].num);
local data = UserModel.getVipByID(vipInfo.id);
if data then
local day = math.floor((data.val2-UserModel.time_second)/(24*3600)) + 1;
if data.val1 > 0 and TimeUtil.isToday(UserModel.time_second,data.val1) then
day = day - 1;
end
if day < 0 then
day = 0;
end
txt_2:setString(day);
btn_get.data = data;
end
local btn_close = self:getChildByName("panel"):getChildByName("btn_close");
btn_close.fn = handler(self,self.onClose);
btn_close:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type,btn_close.fn)end);
self:updateSelectedState();
end
function ActivityVipDailyView:onGetClick(ref)
local data = ref.data;
if data then
if data.val1 == 0 or not TimeUtil.isToday(UserModel.time_second,data.val1) then
local function onDayRewardCallback(params)
cmsg.off("gateway_msg.get_pay_day_reward_msg_res",onDayRewardCallback);
UserModel.setVipDayTime(data.key,UserModel.time_second);
self:runAction(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function()
self:close();
end)));
end
local function timeOutFun()
cmsg.off("gateway_msg.get_pay_day_reward_msg_res",onDayRewardCallback);
end
cmsg.on("gateway_msg.get_pay_day_reward_msg_res",onDayRewardCallback);
SocketClient:getInstance():send("gateway_msg.get_pay_day_reward_msg",
{
id = data.key
},timeOutFun);
end
else
local shopInfo = ShopInfo.getPayInfo(ref.id);
ShopModel.pay(shopInfo.product,shopInfo.name,shopInfo.costList[1].num);
end
end
function ActivityVipDailyView:onClose()
self:close();
end
--返回键处理函数
function ActivityVipDailyView:onKeypadBack()
self:close();
end
--确认键处理函数
function ActivityVipDailyView:onKeypadOk()
local node = self.nodes[self.nodeIndex][self.selectedIndex];
if node and node.fn then
node.fn();
end
end
return ActivityVipDailyView