119 lines
3.1 KiB
Lua
119 lines
3.1 KiB
Lua
local PhoneBindView = {}
|
|
|
|
local M = PhoneBindView
|
|
|
|
function PhoneBindView.new(callback)
|
|
setmetatable(M, {__index = BaseWindow})
|
|
local self = setmetatable({}, {__index = M})
|
|
self.class = "PhoneBindView"
|
|
self._callback = callback
|
|
self._close_destroy = true
|
|
local url = "ui://Lobby/win_phone"
|
|
self:init(url)
|
|
return self
|
|
end
|
|
|
|
function M:init(url)
|
|
BaseWindow.init(self,url)
|
|
|
|
if DataManager.SelfUser.phone then
|
|
local ctr_update = self._view:GetController("update")
|
|
ctr_update.selectedIndex = 1
|
|
end
|
|
|
|
local btn_getCode = self._view:GetChild("btn_getCode")
|
|
btn_getCode.onClick:Set(function()
|
|
self:GetCode()
|
|
end)
|
|
|
|
local btn_ok = self._view:GetChild("btn_ok")
|
|
btn_ok.onClick:Set(function()
|
|
self:Bind()
|
|
end)
|
|
end
|
|
|
|
--获取验证码
|
|
function M:GetCode()
|
|
local phone = self:CheckInputPhone()
|
|
if not phone then
|
|
return
|
|
end
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
|
loddyctr:GetPhoneCode(phone,function( res)
|
|
if res.ReturnCode == 0 then
|
|
self._view:GetController("code").selectedIndex = 1
|
|
self._left_time = 120
|
|
UpdateBeat:Add(self.OnUpdate, self)
|
|
else
|
|
ViewUtil.ErrorTip(res.ReturnCode, "请输入正确的手机号")
|
|
end
|
|
end)
|
|
end
|
|
|
|
function M:OnUpdate()
|
|
local deltaTime = Time.deltaTime
|
|
local _left_time = self._left_time
|
|
if (_left_time > 0) then
|
|
_left_time = _left_time - deltaTime
|
|
_left_time = math.max(0, _left_time)
|
|
local leftTime = math.floor(_left_time)
|
|
self._view:GetChild("tex_time").text = tostring(leftTime).."后重新发送"
|
|
self._left_time = _left_time
|
|
else
|
|
self._view:GetController("code").selectedIndex=0
|
|
UpdateBeat:Remove(self.OnUpdate, self)
|
|
end
|
|
end
|
|
|
|
function M:Destroy()
|
|
BaseWindow.Destroy(self)
|
|
UpdateBeat:Remove(self.OnUpdate, self)
|
|
end
|
|
|
|
--绑定
|
|
function M:Bind()
|
|
local phone = self:CheckInputPhone()
|
|
if not phone then
|
|
return
|
|
end
|
|
local code = self:CheckInputCode()
|
|
if not code then
|
|
return
|
|
end
|
|
ViewUtil.ShowModalWait(self._root_view,"正在提交...")
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
|
local _data = {}
|
|
_data.type =4
|
|
_data.phone = phone
|
|
_data.code = code
|
|
loddyctr:UpdateUserInfo(_data,function( res)
|
|
ViewUtil.CloseModalWait()
|
|
if (res.ReturnCode ==0) then
|
|
DataManager.SelfUser.phone = phone
|
|
if self._callback then self._callback() end
|
|
else
|
|
ViewUtil.ErrorTip(res.ReturnCode,"提交失败")
|
|
end
|
|
self:Close()
|
|
end)
|
|
end
|
|
|
|
function M:CheckInputPhone()
|
|
local phone = self._view:GetChild("tex_phone").text
|
|
if not (string.len(phone) == 11 or string.len(phone) == 12) then
|
|
ViewUtil.ShowTips("请输入正确的手机号")
|
|
return
|
|
end
|
|
return phone
|
|
end
|
|
|
|
function M:CheckInputCode()
|
|
local code = self._view:GetChild("tex_code").text
|
|
if not (string.len(code) == 6) then
|
|
ViewUtil.ShowTips("请输入正确的验证码")
|
|
return
|
|
end
|
|
return code
|
|
end
|
|
|
|
return M |