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.

123 lines
3.4 KiB

  1. -- 手机绑定
  2. local PhoneChangeView = class("PhoneChangeView", cc.UIView)
  3. function PhoneChangeView:ctor(callBack)
  4. PhoneChangeView.super.ctor(self)
  5. logD("yhj: 进入手机修改界面")
  6. local ui = loadUI("res/ui/ui_dating/ui_phone_change.ui")
  7. self.ui = ui
  8. self:addChild(ui)
  9. self.callBack = callBack
  10. end
  11. function PhoneChangeView:onEnter()
  12. self.ui.Items.Text_TimeDown:setVisible(false)
  13. self.ui.Items.Button_Close:registerClick(handler(self, self.onClickClose));
  14. self.ui.Items.Button_Code:registerClick(handler(self, self.onClickGetcode));
  15. self.ui.Items.Button_Sure:registerClick(handler(self, self.onClickOk));
  16. self:bindEvent(app.user, "onChangePlayerInfo", handler(self, self.onChangePlayerInfo))
  17. end
  18. function PhoneChangeView:onExit()
  19. if self.timeDown then
  20. self.timeDown:stopTimer()
  21. self.timeDown = null
  22. end
  23. end
  24. function PhoneChangeView:onClickClose()
  25. playBtnCloseEffect()
  26. self:removeFromParent()
  27. end
  28. function PhoneChangeView:showTimeDown(timeLeft)
  29. self.ui.Items.Text_TimeDown:setVisible(true)
  30. self.ui.Items.Text_TimeDown:startRemainTime(tonumber(timeLeft) or 0, function(obj, value)
  31. value = math.floor(value + 0.5)
  32. self.ui.Items.Text_TimeDown:setText(value.."秒后重试")
  33. self.ui.Items.Button_Code:setVisible(value <= 0)
  34. end)
  35. end
  36. function PhoneChangeView:onClickGetcode()
  37. playBtnEffect()
  38. local phoneNum = self.ui.Items.TextField_PhoneNew:getString()
  39. if string.len(phoneNum) ~= 11 or not checkIsNumberString(phoneNum) then
  40. showTooltip("您输入的手机号码格式不正确")
  41. return
  42. end
  43. if app.user.phonenum and tonumber(app.user.phonenum) == tonumber(phoneNum) then
  44. showTooltip("您的手机号已经是"..phoneNum)
  45. return
  46. end
  47. self.ui.Items.Button_Code:setVisible(false)
  48. self:showTimeDown(60)
  49. self.phoneNum = phoneNum
  50. app.php:requestBindPhoneProvingCode(self.phoneNum)
  51. end
  52. function PhoneChangeView:onClickOk()
  53. playBtnEffect()
  54. local phoneNum = app.user.phonenum
  55. local newPhone = self.ui.Items.TextField_PhoneNew:getString()
  56. local checkcode = self.ui.Items.TextField_Code:getString()
  57. -- 验证手机号码
  58. if string.len(phoneNum) ~= 11 or not checkIsNumberString(phoneNum) then
  59. showTooltip("您输入的手机号码格式不正确")
  60. return
  61. end
  62. -- 验证手机密码
  63. if string.len(newPhone) < 8 or string.len(newPhone) > 12 or not checkIsPasswordString(newPhone) then
  64. showTooltip("请输入英文字母或者数字的8-12位任意组合")
  65. return
  66. end
  67. -- 验证验证码
  68. if string.len(checkcode) ~= 6 or not checkIsNumberString(checkcode) then
  69. showTooltip("您输入的验证码格式不正确")
  70. return
  71. end
  72. if phoneNum and newPhone and checkcode then
  73. local request = changePlayerInfoRequest:new()
  74. request.uid = app.user.loginInfo.uid
  75. request.openId = phoneNum
  76. request.unionId = newPhone
  77. request.checkcode = checkcode
  78. request.loginType = ChangePlayerInfo.REPLCACE_PHONE
  79. request.weixinInfo = app.user.userInfo
  80. logD("PhoneChangeView onClickOk",table.tostring(request))
  81. logD("yhj: 手机修改")
  82. self.ui:sendMsg(app.user, "playerInfoChange",request)
  83. end
  84. end
  85. function PhoneChangeView:onChangePlayerInfo(event)
  86. local response = event.response
  87. local errCode = response.ret
  88. if errCode and errCode == 0 then
  89. self:removeFromParent()
  90. end
  91. end
  92. function PhoneChangeView:onClickPassword()
  93. local view = import("luaScript.Views.Main.SetPasswordView"):new(endCallback)
  94. view:setAnchorPoint(cc.p(0.5, 0.5))
  95. app:showWaitDialog(view)
  96. end
  97. return PhoneChangeView