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.

155 lines
4.7 KiB

  1. -- 手机绑定
  2. local PhoneBindView = class("PhoneBindView", cc.UIView)
  3. function PhoneBindView:ctor(endCallback)
  4. PhoneBindView.super.ctor(self)
  5. local ui = loadUI("res/ui/ui_dating/ui_phone_bind.ui")
  6. self.ui = ui
  7. self:addChild(ui)
  8. self.endCallback = endCallback
  9. end
  10. function PhoneBindView:onEnter()
  11. self.ui.Items.Text_TimeDown:setVisible(false)
  12. self.ui.Items.Button_Close:registerClick(handler(self, self.onClickClose));
  13. self.ui.Items.Button_Code:registerClick(handler(self, self.onClickGetcode));
  14. self.ui.Items.Button_Sure:registerClick(handler(self, self.onClickOk));
  15. self.ui.Items.Button_Normal:registerClick(handler(self, self.onClickRestEye))
  16. self.ui.Items.Button_Sel:registerClick(handler(self, self.onClickEye))
  17. self.ui.Items.Button_Sel:setVisible(false)
  18. self.ui.Items.ImageView_1:setVisible(app.config.ModuleConfig.IsSupportHongBaoKa);
  19. self:bindEvent(app.user, "onBindResponse", handler(self, self.onPhoneBindResponse))
  20. end
  21. function PhoneBindView:onExit()
  22. if self.timeDown then
  23. self.timeDown:stopTimer()
  24. self.timeDown = null
  25. end
  26. end
  27. function PhoneBindView:onClickClose()
  28. playBtnCloseEffect()
  29. if self.endCallback then
  30. self.endCallback()
  31. end
  32. self:removeFromParent()
  33. end
  34. function PhoneBindView:showTimeDown(timeLeft)
  35. self.ui.Items.Text_TimeDown:setVisible(true)
  36. self.ui.Items.Text_TimeDown:startRemainTime(tonumber(timeLeft) or 0, function(obj, value)
  37. value = math.floor(value + 0.5)
  38. self.ui.Items.Text_TimeDown:setText(value.."秒后重试")
  39. self.ui.Items.Button_Code:setVisible(value <= 0)
  40. end)
  41. end
  42. function PhoneBindView:onClickGetcode()
  43. playBtnEffect()
  44. if app.user.phonenum and app.user.phonenum ~= "" then
  45. showTooltip("您已经绑定过手机号了")
  46. return
  47. end
  48. local phoneNum = self.ui.Items.TextField_PhoneNum:getString()
  49. if string.len(phoneNum) ~= 11 or not checkIsNumberString(phoneNum) then
  50. showTooltip("您输入的手机号码格式不正确")
  51. return
  52. end
  53. self.ui.Items.Button_Code:setVisible(false)
  54. self:showTimeDown(60)
  55. self.phoneNum = phoneNum
  56. app.php:requestBindPhoneProvingCode(self.phoneNum)
  57. end
  58. function PhoneBindView:onClickOk()
  59. playBtnEffect()
  60. if app.user.phonenum and app.user.phonenum ~= "" then
  61. showTooltip("您已经绑定过手机号了")
  62. return
  63. end
  64. local phoneNum = self.ui.Items.TextField_PhoneNum:getString()
  65. local password = self.ui.Items.TextField_PhoneCode:getString()
  66. local checkcode = self.ui.Items.TextField_Code:getString()
  67. -- 验证手机号码
  68. if string.len(phoneNum) ~= 11 or not checkIsNumberString(phoneNum) then
  69. showTooltip("您输入的手机号码格式不正确")
  70. return
  71. end
  72. -- 验证手机密码
  73. if string.len(password) < 8 or string.len(password) > 12 or not checkIsPasswordString(password) then
  74. showTooltip("请输入英文字母或者数字的8-12位任意组合")
  75. return
  76. end
  77. -- 验证验证码
  78. if string.len(checkcode) ~= 6 or not checkIsNumberString(checkcode) then
  79. showTooltip("您输入的验证码格式不正确")
  80. return
  81. end
  82. local request = PhoneBindRequest:new()
  83. request.uid = app.user.loginInfo.uid
  84. request.account = phoneNum
  85. request.password = password
  86. request.checkcode = checkcode
  87. request.weixinInfo = app.user.userInfo
  88. request.rewardType = 5 -- 奖励类型:1. 房卡 2.金币 3. 活动房卡 4. RMB 5. 红包券
  89. request.bindType = BIND_TYPE.PHONE
  90. self.ui:sendMsg(app.user, "requestBindPhoneNum", request)
  91. end
  92. function PhoneBindView:onPhoneBindResponse(event)
  93. local response = event.response
  94. local errCode = response.ret
  95. local userInfo = response.userInfo
  96. local rewardCoin = response.rewardCoin
  97. if errCode and errCode == BIND_TYPE_RESULT.PHONE then -- 如果成功则关闭界面
  98. --显示红包券奖励
  99. if rewardCoin and rewardCoin > 0 and app.config.ModuleConfig.IsSupportHongBaoKa then
  100. app.user.loginInfo.curLiquanNum = tonumber(app.user.loginInfo.curLiquanNum) + rewardCoin
  101. local view = import("luaScript.Views.Main.HongBaoKa.GetHongBaoKaEffect"):new(rewardCoin,1)
  102. view:setAnchorPoint(cc.p(0.5, 0.5))
  103. app:showWaitDialog(view)
  104. end
  105. if self.endCallback then
  106. self.endCallback()
  107. end
  108. self:removeFromParent()
  109. end
  110. end
  111. function PhoneBindView:onClickEye()
  112. playBtnEffect()
  113. self.ui.Items.TextField_PhoneCode:setPasswordEnabled(true)
  114. self.ui.Items.Button_Normal:setVisible(true)
  115. self.ui.Items.Button_Sel:setVisible(false)
  116. self.ui.Items.TextField_PhoneCode:setText(self.ui.Items.TextField_PhoneCode:getString())
  117. end
  118. function PhoneBindView:onClickRestEye()
  119. playBtnEffect()
  120. self.ui.Items.TextField_PhoneCode:setPasswordEnabled(false)
  121. self.ui.Items.Button_Normal:setVisible(false)
  122. self.ui.Items.Button_Sel:setVisible(true)
  123. self.ui.Items.TextField_PhoneCode:setText(self.ui.Items.TextField_PhoneCode:getString())
  124. end
  125. return PhoneBindView