|
- --
-
- local InviteCodeView = class("InviteCodeView", cc.UIView)
-
- function InviteCodeView:ctor()
-
- InviteCodeView.super.ctor(self)
- local ui = loadUI("res/ui/ui_dating/ui_InviteCode.ui")
- self.ui = ui
- self:addChild(ui)
-
- -- 最大数字数量
- self.maxNumCount = 5;
- self.nums = {}
- end
-
- function InviteCodeView:onEnter()
- InviteCodeView.super.onEnter(self)
-
- self.defalutLen = 0
- self.ui.Items.TextCode:setText("")
- self.ui.Items.Text_present:setText("")
- self.ui.Items.Text_diamond:setText("")
-
- self.ui.Items.TextBMFont_3:setVisible(false)
- self.ui.Items.TextBMFont_4:setVisible(false)
- self.ui.Items.TextBMFont_5:setVisible(false)
- self.ui.Items.TextBMFont_6:setVisible(false)
- self.ui.Items.Text_present:setVisible(false)
-
- self.ui.Items.Button:registerClick(handler(self,self.onClickText))
- self.ui.Items.Button_Close:registerClick(handler(self,self.onClickClose))
- self.ui.Items.Button_Invite:registerClick(handler(self,self.onClickInvite))
-
- self:bindEvent(app, "onGetInviteCodeInfoResponse", handler(self, self.updateView))
- self:bindEvent(app, "onBindInviteCodeResponse", handler(self, self.updateView))
-
- self:updateView()
-
- -- 请求邀请码数据
- app.php:requestGetInviteCodeInfo();
- end
-
- function InviteCodeView:onInputAdd(value)
-
- if table.nums(self.nums) >= self.maxNumCount then
- return
- end
-
- local numVal = tonumber(value)
- if value >= 0 and value <= 9 then
- table.insert(self.nums, numVal)
- end
-
- self:updateCode()
- end
-
- function InviteCodeView:onInputDel()
- if table.nums(self.nums) <= 0 then
- return
- end
-
- local cnt = table.nums(self.nums)
- table.remove(self.nums, cnt)
-
- self:updateCode()
- end
-
- function InviteCodeView:onInputFinish()
- self.ui.Items.Layout_1:playClip("fadeOut")
- end
-
- function InviteCodeView:updateCode()
- local str = ""
- for k,v in ipairs(self.nums) do
- str = str .. v
- end
-
- self.ui.Items.TextCode:setText(str);
- end
-
- function InviteCodeView:updateView()
- local totalData = app.php.inviteCodeData;
- if not totalData then
- return
- end
-
- --奖励
- if totalData.award then
- self.ui.Items.Text_diamond:setText(tostring(totalData.award))
- end
-
- --赠送
- if totalData.payper then
- self.ui.Items.Text_present:setText(tostring(totalData.payper))
- end
-
- --是否要绑定
- if totalData.code and totalData.code ~= "" then
- self.ui.Items.TextCode:setText(totalData.code)
- self.ui.Items.TextCode:setTouchEnabled(false)
- self.ui.Items.Button:setEnabled(false)
- self.ui.Items.Button_Invite:setEnabled(false)
- else
- self.ui.Items.Button_Invite:setEnabled(true)
- end
- end
-
- function InviteCodeView:onClickClose()
- playBtnCloseEffect()
- self:removeFromParent()
- end
-
- function InviteCodeView:onClickInvite()
- playBtnEffect()
- local length = string.len(self.ui.Items.TextCode:getText())
- if length <= 0 then
- showTooltip("请您输入邀请码")
- return
- end
-
- local text = self.ui.Items.TextCode:getText()
- app.php:requestBindInviteCode(text)
- end
-
- function InviteCodeView:onClickText()
- self.ui.Items.Layout_1:playClip("fadeIn")
- local view = import("luaScript.Views.Main.NumInputView"):new(handler(self, self.onInputAdd), handler(self, self.onInputDel), handler(self, self.onInputFinish))
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
- function InviteCodeView:onClickInput(event,mType)
- if mType == 0 then -- attach IME
- print("attach IME")
- elseif mType == 1 then -- detach IME
- print("detach IME")
- showTooltip(self.ui.Items.TextField:getString())
- self.ui.Items.TextCode:setText(self.inputText)
- elseif mType == 2 then -- insert text
- print("insert text")
- local insertStr = self.ui.Items.TextField:getString()
- local length = string.len(insertStr)
- if self.defalutLen == 0 then
- if length == 1 then
- if self:getIsNumber(insertStr) then
- self.ui.Items.TextCode:setText(insertStr)
- self.inputText = self.inputText..insertStr
- self.defalutLen = length
- else
- self.ui.Items.TextField:setText(self.inputText)
- end
- else
- self.ui.Items.TextField:setText(self.inputText)
- end
- else
- local disLen = length - self.defalutLen
- if disLen == 1 then
- local insertStr = string.sub(insertStr,self.defalutLen + 1,length)
- if self:getIsNumber(insertStr) then
- self.inputText = self.inputText..insertStr
- self.ui.Items.TextCode:setText(self.inputText)
- self.defalutLen = length
- else
- self.ui.Items.TextField:setText(self.inputText)
- end
- else
- self.ui.Items.TextField:setText(self.inputText)
- end
- end
- elseif mType == 3 then -- delete text
- print(" delete text")
- local insertStr = self.ui.Items.TextField:getString()
- local length = string.len(insertStr)
- if self.defalutLen == 0 then
- self.inputText = ""
- self.ui.Items.TextCode:setText(self.inputText)
- self.ui.Items.TextField:setText(self.inputText)
- else
- self.inputText = insertStr
- self.ui.Items.TextCode:setText(self.inputText)
- self.defalutLen = length
- end
- end
- end
-
- function InviteCodeView:getIsNumber(word)
- local num = tonumber(word)
- if num and num >= 0 and num <= 9 then
- return true
- else
- return false
- end
- end
-
- return InviteCodeView
|