ShareWxView.lua 2.7 KB
local ShareWxView = dialog.uinode("ui/ShareWxLayer.csb",import(".BaseView"))

--微信分享界面
function ShareWxView:ctor()
    ShareWxView.super.ctor(self);
end

function ShareWxView:show(selectedIndex)
    local scene = cc.Director:getInstance():getRunningScene()
    local inst = ShareWxView:create();
    scene:addChild(inst, dialog.ZORDER_POP);

    local panel = inst:getChildByName("panel");
    panel:setScale(0.5);
    local scaleTo = cc.ScaleTo:create(0.2,1);
    panel:runAction(scaleTo);

    selectedIndex = selectedIndex or 1;
    inst.selectedIndex = selectedIndex;

    inst:init();

    UmengHelper.onEvent("share");

    return inst;
end

function ShareWxView:init()
    self:setContentSize(cc.size(display.width,display.height));
    ccui.Helper:doLayout(self);

    local btn_1 = self:getChildByName("panel"):getChildByName("btn_1");
    btn_1.fn = handler(self,self.onShareFriend);
    btn_1:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_1.fn)end);

    local btn_2 = self:getChildByName("panel"):getChildByName("btn_2");
    btn_2.fn = handler(self,self.onShareTimeLine);
    btn_2:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_2.fn)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.nodes[1] = {btn_close};
    self.nodes[2] = {btn_1,btn_2};
    
    self.nodeIndex = 2;
    self:updateSelectedState();
end

function ShareWxView:onShareFriend()
    self:shareToWx(0);
    self:close();
end

function ShareWxView:onShareTimeLine()
    self:shareToWx(1);
    self:close();
end

function ShareWxView:onClose()
    self:close();
end

function ShareWxView:shareToWx(shareScene)
    local function onShareBackFun(result)
        if result == "success" then
            if shareScene== 0 then
                SocketClient:getInstance():send("gateway_msg.mail_share_private_give_msg",{});
            else
                SocketClient:getInstance():send("gateway_msg.mail_share_public_give_msg",{});
            end
        elseif result == "notinstalled" then
            Alert.showOne("未安装微信,请先安装微信");
        end
    end
    local obj = {};
    obj.url = SHARE_URL;
    obj.title = "全家棋牌";
    obj.content = "全家棋牌是一款包含斗地主、麻将、掼蛋、牛牛等棋牌游戏的游戏大厅";
    obj.scene = shareScene;
    DeviceUtil.ShareWxWebpage(json.encode(obj),onShareBackFun);
end

--返回键处理函数
function ShareWxView:onKeypadBack()
    if self.cancelFun then
        self.cancelFun();
    end
    self:close();
end

return ShareWxView