client/lua_probject/base_project/Game/View/Lobby/PhonePasswordView.lua

122 lines
3.5 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
local PhonePasswordView = {}
local M = PhonePasswordView
function PhonePasswordView.new(callback)
2025-04-11 12:49:08 +08:00
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-04-01 10:48:36 +08:00
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)
2025-04-11 12:49:08 +08:00
BaseWindow.init(self, url)
2025-04-01 10:48:36 +08:00
self.ctr_update = self._view:GetController("update")
if DataManager.SelfUser.password then
--self.ctr_update.selectedIndex = 1
2025-04-11 12:49:08 +08:00
---- print("DataManager.SelfUser.account_idDataManager.SelfUser.account_idDataManager.SelfUser.account_id ",DataManager.SelfUser.account_id)
2025-04-01 10:48:36 +08:00
--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
2025-04-11 12:49:08 +08:00
2025-04-01 10:48:36 +08:00
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
2025-04-11 12:49:08 +08:00
local loddyctr = ControllerManager.GetController(LoddyController)
loddyctr:GetPhoneCode(phone, function(res)
2025-04-01 10:48:36 +08:00
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)
2025-04-11 12:49:08 +08:00
self._view:GetChild("tex_time").text = tostring(leftTime) .. "后重新发送"
2025-04-01 10:48:36 +08:00
self._left_time = _left_time
else
2025-04-11 12:49:08 +08:00
self._view:GetController("code").selectedIndex = 0
2025-04-01 10:48:36 +08:00
UpdateBeat:Remove(self.OnUpdate, self)
2025-04-11 12:49:08 +08:00
end
2025-04-01 10:48:36 +08:00
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
2025-04-11 12:49:08 +08:00
if string.len(password) < 6 then
2025-04-01 10:48:36 +08:00
ViewUtil.ShowTips("请输入5位以上的密码")
return
end
local _data = {}
2025-04-11 12:49:08 +08:00
2025-04-01 10:48:36 +08:00
-- 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
2025-04-11 12:49:08 +08:00
ViewUtil.ShowModalWait(self._root_view, "正在提交...")
local loddyctr = ControllerManager.GetController(LoddyController)
2025-04-01 10:48:36 +08:00
_data.password = password
2025-04-11 12:49:08 +08:00
_data.type = 3
2025-04-01 10:48:36 +08:00
2025-04-11 12:49:08 +08:00
loddyctr:UpdateUserInfo(_data, function(res)
2025-04-01 10:48:36 +08:00
ViewUtil.CloseModalWait()
2025-04-11 12:49:08 +08:00
if (res.ReturnCode == 0) then
2025-04-01 10:48:36 +08:00
DataManager.SelfUser.password = "123"
if self._callback then self._callback() end
else
2025-04-11 12:49:08 +08:00
ViewUtil.ErrorTip(res.ReturnCode, "提交失败")
2025-04-01 10:48:36 +08:00
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
2025-04-11 12:49:08 +08:00
return M