123 lines
3.5 KiB
Lua
123 lines
3.5 KiB
Lua
local PhonePasswordView = {}
|
|
|
|
local M = PhonePasswordView
|
|
|
|
function PhonePasswordView.new(callback)
|
|
setmetatable(M, {__index = BaseWindow})
|
|
local self = setmetatable({}, {__index = M})
|
|
self.class = "PhonePasswordView"
|
|
self._callback = callback
|
|
self._close_destroy = true
|
|
local url = "ui://Lobby/win_phone_password"
|
|
self:init(url)
|
|
return self
|
|
end
|
|
|
|
function M:init(url)
|
|
BaseWindow.init(self,url)
|
|
self.ctr_update = self._view:GetController("update")
|
|
if DataManager.SelfUser.password then
|
|
--self.ctr_update.selectedIndex = 1
|
|
--print("DataManager.SelfUser.account_idDataManager.SelfUser.account_idDataManager.SelfUser.account_id ",DataManager.SelfUser.account_id)
|
|
--self._view:GetChild("tex_phone").text = DataManager.SelfUser.account_id--ViewUtil.phone_hide(DataManager.SelfUser.phone)
|
|
end
|
|
|
|
self._view:GetChild("tex_phone").text = DataManager.SelfUser.account_id
|
|
|
|
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 tex_passwd = self._view:GetChild("tex_passwd")
|
|
local password = tex_passwd.text
|
|
if string.len(password) <6 then
|
|
ViewUtil.ShowTips("请输入5位以上的密码")
|
|
return
|
|
end
|
|
local _data = {}
|
|
|
|
-- if self.ctr_update.selectedIndex == 1 then
|
|
|
|
-- local code = self:CheckInputCode()
|
|
-- if not code then
|
|
-- return
|
|
-- end
|
|
-- _data.phone = DataManager.SelfUser.phone
|
|
-- _data.code = code
|
|
-- end
|
|
ViewUtil.ShowModalWait(self._root_view,"正在提交...")
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
|
_data.password = password
|
|
_data.type =3
|
|
|
|
loddyctr:UpdateUserInfo(_data,function( res)
|
|
ViewUtil.CloseModalWait()
|
|
if (res.ReturnCode ==0) then
|
|
DataManager.SelfUser.password = "123"
|
|
if self._callback then self._callback() end
|
|
else
|
|
ViewUtil.ErrorTip(res.ReturnCode,"提交失败")
|
|
end
|
|
self:Close()
|
|
end)
|
|
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 |