You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.0 KiB

  1. --
  2. local InviteCodeView = class("InviteCodeView", cc.UIView)
  3. function InviteCodeView:ctor()
  4. InviteCodeView.super.ctor(self)
  5. local ui = loadUI("res/ui/ui_dating/ui_InviteCode.ui")
  6. self.ui = ui
  7. self:addChild(ui)
  8. -- 最大数字数量
  9. self.maxNumCount = 5;
  10. self.nums = {}
  11. end
  12. function InviteCodeView:onEnter()
  13. InviteCodeView.super.onEnter(self)
  14. self.defalutLen = 0
  15. self.ui.Items.TextCode:setText("")
  16. self.ui.Items.Text_present:setText("")
  17. self.ui.Items.Text_diamond:setText("")
  18. self.ui.Items.TextBMFont_3:setVisible(false)
  19. self.ui.Items.TextBMFont_4:setVisible(false)
  20. self.ui.Items.TextBMFont_5:setVisible(false)
  21. self.ui.Items.TextBMFont_6:setVisible(false)
  22. self.ui.Items.Text_present:setVisible(false)
  23. self.ui.Items.Button:registerClick(handler(self,self.onClickText))
  24. self.ui.Items.Button_Close:registerClick(handler(self,self.onClickClose))
  25. self.ui.Items.Button_Invite:registerClick(handler(self,self.onClickInvite))
  26. self:bindEvent(app, "onGetInviteCodeInfoResponse", handler(self, self.updateView))
  27. self:bindEvent(app, "onBindInviteCodeResponse", handler(self, self.updateView))
  28. self:updateView()
  29. -- 请求邀请码数据
  30. app.php:requestGetInviteCodeInfo();
  31. end
  32. function InviteCodeView:onInputAdd(value)
  33. if table.nums(self.nums) >= self.maxNumCount then
  34. return
  35. end
  36. local numVal = tonumber(value)
  37. if value >= 0 and value <= 9 then
  38. table.insert(self.nums, numVal)
  39. end
  40. self:updateCode()
  41. end
  42. function InviteCodeView:onInputDel()
  43. if table.nums(self.nums) <= 0 then
  44. return
  45. end
  46. local cnt = table.nums(self.nums)
  47. table.remove(self.nums, cnt)
  48. self:updateCode()
  49. end
  50. function InviteCodeView:onInputFinish()
  51. self.ui.Items.Layout_1:playClip("fadeOut")
  52. end
  53. function InviteCodeView:updateCode()
  54. local str = ""
  55. for k,v in ipairs(self.nums) do
  56. str = str .. v
  57. end
  58. self.ui.Items.TextCode:setText(str);
  59. end
  60. function InviteCodeView:updateView()
  61. local totalData = app.php.inviteCodeData;
  62. if not totalData then
  63. return
  64. end
  65. --奖励
  66. if totalData.award then
  67. self.ui.Items.Text_diamond:setText(tostring(totalData.award))
  68. end
  69. --赠送
  70. if totalData.payper then
  71. self.ui.Items.Text_present:setText(tostring(totalData.payper))
  72. end
  73. --是否要绑定
  74. if totalData.code and totalData.code ~= "" then
  75. self.ui.Items.TextCode:setText(totalData.code)
  76. self.ui.Items.TextCode:setTouchEnabled(false)
  77. self.ui.Items.Button:setEnabled(false)
  78. self.ui.Items.Button_Invite:setEnabled(false)
  79. else
  80. self.ui.Items.Button_Invite:setEnabled(true)
  81. end
  82. end
  83. function InviteCodeView:onClickClose()
  84. playBtnCloseEffect()
  85. self:removeFromParent()
  86. end
  87. function InviteCodeView:onClickInvite()
  88. playBtnEffect()
  89. local length = string.len(self.ui.Items.TextCode:getText())
  90. if length <= 0 then
  91. showTooltip("请您输入邀请码")
  92. return
  93. end
  94. local text = self.ui.Items.TextCode:getText()
  95. app.php:requestBindInviteCode(text)
  96. end
  97. function InviteCodeView:onClickText()
  98. self.ui.Items.Layout_1:playClip("fadeIn")
  99. local view = import("luaScript.Views.Main.NumInputView"):new(handler(self, self.onInputAdd), handler(self, self.onInputDel), handler(self, self.onInputFinish))
  100. view:setAnchorPoint(cc.p(0.5, 0.5))
  101. app:showWaitDialog(view)
  102. end
  103. function InviteCodeView:onClickInput(event,mType)
  104. if mType == 0 then -- attach IME
  105. print("attach IME")
  106. elseif mType == 1 then -- detach IME
  107. print("detach IME")
  108. showTooltip(self.ui.Items.TextField:getString())
  109. self.ui.Items.TextCode:setText(self.inputText)
  110. elseif mType == 2 then -- insert text
  111. print("insert text")
  112. local insertStr = self.ui.Items.TextField:getString()
  113. local length = string.len(insertStr)
  114. if self.defalutLen == 0 then
  115. if length == 1 then
  116. if self:getIsNumber(insertStr) then
  117. self.ui.Items.TextCode:setText(insertStr)
  118. self.inputText = self.inputText..insertStr
  119. self.defalutLen = length
  120. else
  121. self.ui.Items.TextField:setText(self.inputText)
  122. end
  123. else
  124. self.ui.Items.TextField:setText(self.inputText)
  125. end
  126. else
  127. local disLen = length - self.defalutLen
  128. if disLen == 1 then
  129. local insertStr = string.sub(insertStr,self.defalutLen + 1,length)
  130. if self:getIsNumber(insertStr) then
  131. self.inputText = self.inputText..insertStr
  132. self.ui.Items.TextCode:setText(self.inputText)
  133. self.defalutLen = length
  134. else
  135. self.ui.Items.TextField:setText(self.inputText)
  136. end
  137. else
  138. self.ui.Items.TextField:setText(self.inputText)
  139. end
  140. end
  141. elseif mType == 3 then -- delete text
  142. print(" delete text")
  143. local insertStr = self.ui.Items.TextField:getString()
  144. local length = string.len(insertStr)
  145. if self.defalutLen == 0 then
  146. self.inputText = ""
  147. self.ui.Items.TextCode:setText(self.inputText)
  148. self.ui.Items.TextField:setText(self.inputText)
  149. else
  150. self.inputText = insertStr
  151. self.ui.Items.TextCode:setText(self.inputText)
  152. self.defalutLen = length
  153. end
  154. end
  155. end
  156. function InviteCodeView:getIsNumber(word)
  157. local num = tonumber(word)
  158. if num and num >= 0 and num <= 9 then
  159. return true
  160. else
  161. return false
  162. end
  163. end
  164. return InviteCodeView