AlertNoMoneyView.lua
3.27 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
104
105
106
107
108
109
110
111
112
local AlertNoMoneyView = dialog.uinode("ui/AlertNoMoneyLayer.csb",import(".BaseView"))
function AlertNoMoneyView:ctor()
AlertNoMoneyView.super.ctor(self);
end
function AlertNoMoneyView:show(shopID,okFun,cancelFun)
local scene = cc.Director:getInstance():getRunningScene()
local inst = AlertNoMoneyView:create();
scene:addChild(inst, dialog.ZORDER_APP);
inst:setContentSize(cc.size(display.width,display.height));
ccui.Helper:doLayout(inst);
local panel = inst:getChildByName("panel");
panel:setScale(0.5);
local scaleTo = cc.ScaleTo:create(0.2,1);
panel:runAction(scaleTo);
inst.shopID = shopID;
inst.okFun = okFun;
inst.cancelFun = cancelFun;
inst.selectedIndex = 2;
inst:init();
return inst;
end
function AlertNoMoneyView:init()
local shopInfo = ShopInfo.getShopInfo(self.shopID);
local itemID = shopInfo.itemList[1].id;
local itemInfo = ItemInfo.getItemInfo(itemID);
self:getChildByName("panel"):getChildByName("txt"):setString(shopInfo.itemList[1].num);
local btn_ok = self:getChildByName("panel"):getChildByName("btn_ok");
btn_ok.fn = handler(self,self.onOk);
btn_ok:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_ok.fn)end);
local costNum = shopInfo.costList[1].num;
btn_ok:getChildByName("txt"):setString(costNum.."兑换");
local btn_cancel = self:getChildByName("panel"):getChildByName("btn_cancel");
btn_cancel.fn = handler(self,self.onCancel);
btn_cancel:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_cancel.fn)end);
self.nodes[1] = {btn_cancel,btn_ok};
self:updateSelectedState();
end
function AlertNoMoneyView:onOk()
local shopInfo = ShopInfo.getShopInfo(self.shopID);
local costID = shopInfo.costList[1].id;
local costNum = shopInfo.costList[1].num;
local myNum = UserModel.getItemNum(costID);
if myNum >= costNum then
LoadingManager.showDataLoading();
ShopModel.buy(self.shopID,1,handler(self,self.onBuyCallBack),handler(self,self.onTimeoutFn));
else
local function okFun()
local scene = cc.Director:getInstance():getRunningScene();
local shopView = scene:getChildByName("ShopView");
if shopView then
shopView:setTab(1);
self:close();
else
AppManager.show("ShopView");
end
end
Alert.showTwo(strings.msg_1003,okFun);
end
end
function AlertNoMoneyView:onBuyCallBack(params)
LoadingManager.removeDataLoading();
if params.errcode == EnumErrorCode.EC_SUCCESS then
if self.okFun then
self.okFun();
end
self:close();
else
if self.cancelFun then
self.cancelFun();
end
EffectManager.showFntPop(strings.msg_2017);
end
end
function AlertNoMoneyView:onTimeoutFn(params)
LoadingManager.removeDataLoading();
if self.cancelFun then
self.cancelFun();
end
self:close();
end
function AlertNoMoneyView:onCancel()
if self.cancelFun then
self.cancelFun();
end
self:close();
end
--返回键处理函数
function AlertNoMoneyView:onKeypadBack()
if self.cancelFun then
self.cancelFun();
end
self:close();
end
return AlertNoMoneyView