local CoinFunctions = import("luaScript.Views.Coin.Util.CoinFunctions"); -- 充值界面 local RechargeView = class("RechargeView", cc.UIView) function RechargeView:ctor(shopType,isWebGame,isOpenCoinGame,pid) RechargeView.super.ctor(self) self.ui = loadUI("res/ui/ui_dating/ui_chongzhi.ui") self:addChild(self.ui) self.ui.Items.Layout_liquan_shuoming:setVisible(false) self.btnRadioManager = import("luaScript.Tools.RadioManager"):new() self.isWebGame = isWebGame --此类型和PHP传过来的type类型需要对应上,且ui上显示的按钮也需要和此类型对应 self.shopType = shopType or STORE_TYPE.BUY_ZUANSHI --是否在金币场游戏中(金币场游戏中可能打开商城界面) self.isOpenCoinGame = isOpenCoinGame --self:requestBuyRecord() self.pid = pid if self.pid then self.ui.Items.ImageView_BG:loadTexture(string.format("res/ui/zy_dating/dating/dating_di_%d.jpg",self.pid)) end end function RechargeView:onEnter() RechargeView.super.onEnter(self) self:initButton() self:initUI() --初始化购买钻石界面 self:initRechargeView() -- 默认显示充值界面 self:showRechargeView() --显示顶部数据信息 self:showTopInfo() self:initBindEvent() --请求商城数据 if not app.phpShop.shopData then --没有数据,需要去获取数据 app.phpShop:getShopInfo() end if isReviewVersion() then self.ui.Items.CheckBox_liquan:setVisible(false) self.ui.Items.CheckBox_huanledou:setVisible(false) self.ui.Items.CheckBox_qinyouquanbg:setVisible(false) self.ui.Items.CheckBox_datingbg:setVisible(false) self.ui.Items.CheckBox_liaotianqipao:setVisible(false) self.ui.Items.CheckBox_yuyinqipao:setVisible(false) end self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) if app.user.logOut.status == 1 then local view = import("luaScript.Views.Main.LogOut.LogOutTips"):new() view:setAnchorPoint(cc.p(0.5,0.5)) app:showWaitDialog(view,nil,false) self:onClickClose(); return end end,0.1,false) end function RechargeView:initButton() self.ui.Items.Button_Close:registerClick(handler(self , self.onClickClose)); --兑换记录 self.ui.Items.Button_history:registerClick(handler(self , self.onClickHistory)); --背包 self.ui.Items.Button_BeiBao:registerClick(handler(self, self.onClickGotoBag)) self.btnRadioManager:addItem(self.ui.Items.CheckBox_buy_jinbi_bg, STORE_TYPE.CHANGE_COIN)--兑换金币 if self.isOpenCoinGame then --在金币场游戏中打开此界面时,只显示金币 self.ui.Items.CheckBox_huanledou:setVisible(false) self.ui.Items.CheckBox_buy_bg:setVisible(false) self.ui.Items.CheckBox_liquan:setVisible(false) self.ui.Items.CheckBox_qinyouquanbg:setVisible(false) self.ui.Items.CheckBox_datingbg:setVisible(false) self.ui.Items.CheckBox_liaotianqipao:setVisible(false) self.ui.Items.CheckBox_yuyinqipao:setVisible(false) else self.btnRadioManager:addItem(self.ui.Items.CheckBox_huanledou, STORE_TYPE.BUY_HUANLEDOU)--购买欢乐豆 self.btnRadioManager:addItem(self.ui.Items.CheckBox_buy_bg, STORE_TYPE.BUY_ZUANSHI) --购买钻石 self.btnRadioManager:addItem(self.ui.Items.CheckBox_liquan, STORE_TYPE.CHANGE_LIQUAN) --礼券兑换 self.btnRadioManager:addItem(self.ui.Items.CheckBox_qinyouquanbg, STORE_TYPE.CHANGE_QYQBG) --亲友圈背景兑换 self.btnRadioManager:addItem(self.ui.Items.CheckBox_datingbg, STORE_TYPE.CHANGE_DTBG) --大厅背景兑换 self.btnRadioManager:addItem(self.ui.Items.CheckBox_liaotianqipao, STORE_TYPE.CHANGE_LTQP) --聊天气泡兑换 self.btnRadioManager:addItem(self.ui.Items.CheckBox_yuyinqipao, STORE_TYPE.CHANGE_YYQP) --语音气泡兑换 end --默认显示购买按钮为选中状态 local index = self.shopType self:updateLeftBtnStatus(tonumber(index)) self.btnRadioManager:setDefault(index) local callBack = function ( value ) playBtnEffect() local selectImgName = string.format("res/ui/zy_dating/chongzhi/chongzhi_btn_left_normal_%d.png",index) self.selectImageView:loadTexture(selectImgName) --购买 self:showRechargeView() --更新左边按钮 self:updateLeftBtnStatus(tonumber(value)) self.shopType = value index = value self:initRechargeView() self:showTopInfo() --选择非礼券选项,隐藏礼券说明框 if tonumber(value) ~= STORE_TYPE.CHANGE_LIQUAN then self.ui.Items.Layout_liquan_shuoming:setVisible(false) end end self.btnRadioManager:setCallback(callBack) -- 未成年人消费限制 self.ui.Items.Layout_tip:registerClick(handler(self, self.onOpenTip)) end function RechargeView:onOpenTip() local view = import("luaScript.Views.Main.RechargeXianzhiTip"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function RechargeView:initUI() --金币数量 self.ui.Items.Text_jinbi:bind(app.user.loginInfo, "curJingbiNum", function() --超过1w的金币,后面显示文字 local strCoin = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curJingbiNum) self.ui.Items.Text_jinbi:setString(strCoin) end ) -- 钻石数量 self.ui.Items.Text_zuanshiNum:bind(app.user.loginInfo, "curCardNum", function() self.ui.Items.Text_zuanshiNum:setString(tostring(app.user.loginInfo.curCardNum)) end ) --欢乐豆 self.ui.Items.Text_huanledou:bind(app.user.loginInfo, "curBeanNum", function() self.ui.Items.Text_huanledou:setString(tostring(app.user.loginInfo.curBeanNum)) end ) --礼券 self.ui.Items.Text_liquan:bind(app.user.loginInfo, "curLiquanNum", function() local strLiquan = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curLiquanNum) self.ui.Items.Text_liquan:setString(strLiquan) end ) self.ui.Items.Layout_liquan:registerClick(function () playBtnEffect() self.ui.Items.Layout_liquan_shuoming:setVisible(not self.ui.Items.Layout_liquan_shuoming:isVisible()) end); --点击非礼券说明的地方,隐藏礼券说明框 self.ui.Items.Layout_1:registerClick(function () self.ui.Items.Layout_liquan_shuoming:setVisible(false) end) self.ui.Items.CheckBox_liquan:setVisible(self:isShowLiQuanTab()) self.ui.Items.CheckBox_qinyouquanbg:setVisible(app.config.ModuleConfig.IsSupportPropShop) self.ui.Items.CheckBox_datingbg:setVisible(app.config.ModuleConfig.IsSupportPropShop) self.ui.Items.CheckBox_liaotianqipao:setVisible(app.config.ModuleConfig.IsSupportPropShop) self.ui.Items.CheckBox_yuyinqipao:setVisible(app.config.ModuleConfig.IsSupportPropShop) self.ui.Items.CheckBox_huanledou:setVisible(app.config.ModuleConfig.IsSupportYouXianBean) self.ui.Items.CheckBox_buy_jinbi_bg:setVisible(app.config.ModuleConfig.IsSupportCoin) self.ui.Items.Layout_2:requestDoLayout() self.ui.Items.Layout_2:doLayout(); local layoutLeftSize = self.ui.Items.Layout_2:getContentSize() autoAdaptHeight(self.ui.Items.ImageView) autoAdaptHeight(self.ui.Items.ScrollView_left) if layoutLeftSize then self.ui.Items.ScrollView_left:setInnerContainerSize(layoutLeftSize) end self.ui.Items.Layout_record_item:setVisible(false) self.ui.Items.Layout_buy_item:setVisible(false) self.ui.Items.Layout_liquan_item:setVisible(false) end --- RechargeView:isShowLiQuanTab 是否显示左侧礼券tab function RechargeView:isShowLiQuanTab () return false; end function RechargeView:initBindEvent() --商品信息拉取 self:bindEvent(app.phpShop, "getShopInfoSuccessed", handler(self, self.initRechargeView)) --兑换金币回调 self:bindEvent(app.phpShop , "exchangeCoinSuccess" , handler(self , self.onDuiHuanCoin)); --操作成功 self:bindEvent(app , "onBagOperateResponse" , handler(self , self.onBagOperateResponse)); end function RechargeView:onBagOperateResponse() if not app.php.mypropdata then return end for k,v in pairs(app.php.mypropdata) do if v.prop_id and v.prop_id >= 200 and v.prop_id < 300 then self.pid = v.prop_id self.ui.Items.ImageView_BG:loadTexture(string.format("res/ui/zy_dating/dating/dating_di_%d.jpg",v.prop_id)) end end showTooltip("装扮成功") end --更新左边按钮选中状态图片 function RechargeView:updateLeftBtnStatus(value) local selectImgName = string.format("res/ui/zy_dating/chongzhi/chongzhi_btn_left_select_%d.png", value) self.selectImageView = self.ui.Items["ImageView_buy_"..value] self.selectImageView:loadTexture(selectImgName) end -- 创建一个充值项的ui function RechargeView:createRechargeItem(config, idx) --[[ ["10023"] = { ["currency"] = 2, ["desc"] = 18房卡, ["icon"] = http://api.dingdingqipai.com/pic/d_18.png, ["id"] = 10023, ["name"] = 18房卡, ["number"] = 18, ["order"] = 2, ["pay_type"] = { [1] = { ["id"] = 2, ["name"] = 微信支付, }, [2] = { ["id"] = 3, ["name"] = H5支付, }, }, ["price"] = 18, ["privilege_icon"] = , ["product_id"] = , }, --]] local uiTemplate = self.ui.Items.Layout_buy_item local uiItem = uiTemplate:getCopied() uiItem.Items = getUIItems(uiItem) --最热标签 -- if idx ==3 then--> 1 and idx < 5 then -- uiItem.Items.ImageView_hot:setVisible(true) -- else uiItem.Items.ImageView_hot:setVisible(false) -- end local rechargeId = (config.id); -- 标题 --uiItem.Items.RechargeName:setText(tostring(config.number)) -- 更新商品图标 uiItem.updateIcon = function() uiItem.Items.ImageIcon:setVisible(false) local rechargeConfig = app.phpShop.shopData[rechargeId] if not rechargeConfig then return end local iconUrl = convertIconUrl(rechargeConfig.icon) local iconFile = getImageNameFromUrl(iconUrl) local texture = loadTextureFromFile(iconFile) if texture then local w = texture:getWidth(); local sz = uiItem.Items.ImageIcon:getContentSize() uiItem.Items.ImageIcon:setVisible(true) uiItem.Items.ImageIcon:setTexture2(texture); --uiItem.Items.ImageIcon:setScale(w / sz.width) end end -- 更新赠送角标 uiItem.updatePrivilege = function() uiItem.Items.ImageView_zengsong:setVisible(false) local rechargeConfig = app.phpShop.shopData[rechargeId] if not rechargeConfig then return end local iconFile = getImageNameFromUrl(rechargeConfig.privilege_icon) local texture = loadTextureFromFile(iconFile) if texture then uiItem.Items.ImageView_zengsong:setVisible(true) uiItem.Items.ImageView_zengsong:setTexture2(texture); end end local function onUpdateImage(event) if tolua.isnull(uiItem) then return end if not event or event.id ~= rechargeId then return end uiItem.updateIcon(); uiItem.updatePrivilege(); end -- 监听下载事件,本充值项的图片下载成功时更新图片 uiItem:bindEvent(app.phpShop, "downloadImageSuccessed", onUpdateImage); onUpdateImage({id = config.id}); -- 价格 uiItem.Items.RechargeNum:setText(tostring(config.price)) --标识图 if tonumber(config.type) == STORE_TYPE.CHANGE_COIN or tonumber(config.type) >= STORE_TYPE.CHANGE_QYQBG then uiItem.Items.ImageView_9:loadTexture("res/ui/zy_tongyong/zy_icon/icon_zuanshi.png") uiItem.Items.ImageView_10:loadTexture("res/ui/zy_dating/chongzhi/chongzhi_img_ke.png") else uiItem.Items.ImageView_9:loadTexture("res/ui/zy_dating/chongzhi/chongzhi_img_zuanshi_btn.png") uiItem.Items.ImageView_10:loadTexture("res/ui/zy_dating/chongzhi/chongzhi_img_yuan.png") end -- 按钮 uiItem.Items.ImageIcon:registerClick(function() playBtnEffect() logD("RechargeView:createRechargeItem(), onClickBuy, config = ", table.tostring(config)) if tonumber(config.type) >= STORE_TYPE.CHANGE_QYQBG then local view = import("luaScript.Views.Recharge.StoreDuiHuanView"):new(config.type,config.prop_id,0); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) return end if tonumber(config.type) == STORE_TYPE.CHANGE_COIN then --金币兑换 CoinFunctions.exchangeCoinFromDiamond(config.id,config.price,config.number) return end local payTypeSize = table.nums(config.pay_type) if payTypeSize==0 then showConfirmDialog("支付不可用,请联系客服手工充值!") return end local payTypeInfo = config.pay_type[1] if payTypeSize == 1 and payTypeInfo and tonumber(payTypeInfo.id) == PayType.Apple then logD("payTypeInfo = ", table.tostring(payTypeInfo)) app.plugin:payIosPay(config); else local view = import("luaScript.Views.Main.RechargeViewChoice"):new(config) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end) return uiItem; end -- 创建一个礼券兑换项的ui function RechargeView:createLiquanItem(config, idx) local uiTemplate = self.ui.Items.Layout_liquan_item local uiItem = uiTemplate:getCopied() uiItem.Items = getUIItems(uiItem) --最热标签 uiItem.Items.ImageView_hot_liquan:setVisible(false) local rechargeId = (config.id); -- 更新商品图标 uiItem.updateIcon = function() uiItem.Items.ImageIcon_liquan:setVisible(false) local rechargeConfig = app.phpShop.shopData[rechargeId] if not rechargeConfig then return end local iconFile = getImageNameFromUrl(rechargeConfig.icon) local texture = loadTextureFromFile(iconFile) if texture then local w = texture:getWidth(); local sz = uiItem.Items.ImageIcon_liquan:getContentSize() uiItem.Items.ImageIcon_liquan:setVisible(true) uiItem.Items.ImageIcon_liquan:setTexture2(texture); end end -- 更新赠送角标 uiItem.updatePrivilege = function() uiItem.Items.ImageView_zengsong_liquan:setVisible(false) local rechargeConfig = app.phpShop.shopData[rechargeId] if not rechargeConfig then return end local iconUrl = convertIconUrl(rechargeConfig.icon) local iconFile = getImageNameFromUrl(iconUrl) local texture = loadTextureFromFile(iconFile) if texture then uiItem.Items.ImageView_zengsong_liquan:setVisible(true) uiItem.Items.ImageView_zengsong_liquan:setTexture2(texture); end end local function onUpdateImage(event) if tolua.isnull(uiItem) then return end if not event or event.id ~= rechargeId then return end uiItem.updateIcon(); uiItem.updatePrivilege(); end -- 监听下载事件,本充值项的图片下载成功时更新图片 uiItem:bindEvent(app.phpShop, "downloadImageSuccessed", onUpdateImage); onUpdateImage({id = config.id}); -- 价格 local itemPrice = config.price if tonumber(config.price) > 10000 then itemPrice = itemPrice / 10000 uiItem.Items.Layout_wan:setVisible(true) else uiItem.Items.Layout_wan:setVisible(false) end uiItem.Items.RechargeNum_liquan:setText(tostring(itemPrice)) --重新布局 uiItem.Items.Layout_7:requestDoLayout(); uiItem.Items.Layout_7:doLayout(); -- 礼券兑换按钮 uiItem.Items.ImageIcon_liquan:registerClick(function() playBtnEffect() if tonumber(app.user.loginInfo.curLiquanNum) < tonumber(config.price) then --礼券不足 local function callback() self:removeFromParent() end local view = import("Views.Main.LiquanBuzuView"):new(callback) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) return end if idx == 1 or idx == 2 then --兑换金币或钻石 else --兑换实物 local function onOk() end -- showConfirmDialog("请联系客服微信进行兑换:ddph5566", onOk); showConfirmDialog("请联系客服进行兑换", onOk); end end) return uiItem; end -- 初始化充值项 function RechargeView:initRechargeView() local shopData = app.phpShop.shopData if not shopData then return end app.phpShop:onDownLoadImageByType(tonumber(self.shopType)) local ttshopdata = {} for k,v in pairs (shopData) do table.insert(ttshopdata,v) end table.sort(ttshopdata,function(a,b) if a.order and b.order then if a.order ~= b.order then return a.order < b.order else return a.price < b.price end else return false end end) local uiScrollView = self.ui.Items.ScrollView_buy; uiScrollView:hideAllBar(); uiScrollView:removeAllChildren() uiScrollView:getInnerContainer():setAutoSize(true) local idx = 1 for id, config in pairs(ttshopdata) do --暂时先只显示六个商品 if config.type == self.shopType then if tonumber(config.type) == STORE_TYPE.CHANGE_LIQUAN then --礼券类型创建礼券项 local item = self:createLiquanItem(config, idx) uiScrollView:addChild(item, config.order) idx = idx + 1 else if tonumber(config.type) < STORE_TYPE.CHANGE_QYQBG then local item = self:createRechargeItem(config, idx) uiScrollView:addChild(item, config.order) idx = idx + 1 else if config.price < 10 then local item = self:createRechargeItem(config, idx) uiScrollView:addChild(item, config.order) idx = idx + 1 end end end end end uiScrollView:jumpToTopOnSizeChanged() end -- 显示充值界面 function RechargeView:showRechargeView() self.ui.Items.Layout_buy:setVisible(true) end -- 显示金币兑换界面 function RechargeView:showExchangeView() self.ui.Items.Layout_buy:setVisible(false) end -- 关闭界面 function RechargeView:onClickClose() playBtnCloseEffect() self:removeFromParent() if self.isWebGame then app.phpShop:dispatchEvent({name = GAME_EVENT.RECHARGE_CLOSE}) end end function RechargeView:onDuiHuanCoin(data) if not data then return; end local response = data.response; local id = response.id local gold = response.gold --金币 local card = response.card --钻石 local coupons = response.coupons --礼券 local fileName = "res/ui/zy_dating/chongzhi/chongzhi_img_icon.png" local info = {} if gold and not coupons then --只有金币变化,说明是用钻石兑换金币 logD("RechargeView:onDuiHuanCoin zuanshi curJingbiNum = "..table.tostring(app.user.loginInfo.curJingbiNum)) if tonumber(response.lastCoinNum) > tonumber(gold) then info.coin = tonumber(response.lastCoinNum) - gold; else logD("coin",gold) logD("app.user.loginInfo.curJingbiNum",response.lastCoinNum) info.coin = gold - tonumber(response.lastCoinNum); end app.user.loginInfo.curJingbiNum = gold info.fileName = fileName showFuLiConfirmForCoin(info) elseif gold and coupons then --礼券和金币同时变化,说明是用礼券兑换了金币 logD("RechargeView:onDuiHuanCoin liquan curJingbiNum = "..table.tostring(app.user.loginInfo.curJingbiNum)) if tonumber(response.lastCoinNum) > tonumber(gold) then info.coin = tonumber(response.lastCoinNum) - gold; else info.coin = gold - tonumber(response.lastCoinNum); end app.user.loginInfo.curJingbiNum = gold app.user.loginInfo.curLiquanNum = coupons info.fileName = fileName showFuLiConfirmForCoin(info) elseif not gold and coupons then --礼券变化,但金币没变化,表示兑换的是钻石 logD("RechargeView:onDuiHuanCoin curCardNum = "..table.tostring(app.user.loginInfo.curCardNum)) fileName = "res/ui/zy_dating/chongzhi/chongzhi_icon_zuan.png" info.coupons = app.user.loginInfo.curLiquanNum - coupons; app.user.loginInfo.curLiquanNum = coupons info.card = card - app.user.loginInfo.curCardNum end info.fileName = fileName -- 刷新房卡数量 app.user.loginInfo.curCardNum = card --黄十八兑换道具的时候没有金币返回 if gold then app.user.loginInfo.curJingbiNum = gold end end --购买/兑换记录 function RechargeView:onClickHistory() playBtnEffect() local view = import("luaScript.Views.Main.HistoryView"):new(self.shopType); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end --根据当前类型显示顶部数据 function RechargeView:showTopInfo() self.ui.Items.Layout_jinbi:setVisible(app.config.ModuleConfig.IsSupportCoin) self.ui.Items.Layout_zuanshi:setVisible(true) self.ui.Items.Layout_liquan:setVisible(false) --兑换记录按钮 if tonumber(self.shopType) == STORE_TYPE.CHANGE_COIN then --金币不需要兑换记录 self.ui.Items.Layout_beibao:setVisible(false) self.ui.Items.Button_history:setVisible(false) elseif tonumber(self.shopType) == STORE_TYPE.BUY_ZUANSHI or tonumber(self.shopType) == STORE_TYPE.BUY_HUANLEDOU then --钻石和欢乐豆需要显示购买记录 self.ui.Items.Layout_history:setVisible(true) self.ui.Items.Layout_beibao:setVisible(false) self.ui.Items.Button_history:setVisible(true) self.ui.Items.Button_history:loadTextureNormal("res/ui/zy_dating/chongzhi/chongzhi_btn_buy_history.png") elseif tonumber(self.shopType) == STORE_TYPE.CHANGE_LIQUAN then --礼券需要显示兑换记录 self.ui.Items.Button_history:setVisible(true) self.ui.Items.Button_history:loadTextureNormal("res/ui/zy_dating/chongzhi/chongzhi_btn_exchange_history.png") else self.ui.Items.Layout_history:setVisible(false) self.ui.Items.Layout_beibao:setVisible(true) end if isReviewVersion() then self.ui.Items.Layout_dingdingdou:setVisible(false) else self.ui.Items.Layout_dingdingdou:setVisible(app.config.ModuleConfig.IsSupportYouXianBean) end self.ui.Items.Layout_top:requestDoLayout(); self.ui.Items.Layout_top:doLayout(); end function RechargeView:onClickGotoBag() playBtnEffect() local view = import("luaScript.Views.Recharge.MineBag"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) self:removeFromParent() end return RechargeView