ActivityVipDailyView.lua 3.39 KB
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