hengyang_client/lua_probject/base_project/Game/View/Lobby/RealAddressView.lua

145 lines
4.2 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
--实名认证窗口
local RealAddressView = {}
local M = RealAddressView
2025-11-06 17:37:53 +08:00
function RealAddressView.new(type, callback)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-04-01 10:48:36 +08:00
self.class = "RealAddressView"
self._type = type
self._callback = callback
self._close_destroy = true
self:init("ui://Lobby/win_real_address")
return self
end
function M:init(url)
2025-11-06 17:37:53 +08:00
BaseWindow.init(self, url)
2025-04-01 10:48:36 +08:00
local view = self._view
local btn_real = view:GetChild("btn_real")
btn_real.onClick:Set(function()
self:real_action()
end)
local btn_address = view:GetChild("btn_address")
2025-11-06 17:37:53 +08:00
btn_address.onClick:Set(function()
2025-04-01 10:48:36 +08:00
self:address_action()
end)
self.ctr_update = view:GetController("update")
local ctr_nav = view:GetController("nav")
ctr_nav.onChanged:Set(function()
2025-11-06 17:37:53 +08:00
if ctr_nav.selectedIndex == 0 then
2025-04-01 10:48:36 +08:00
self:fill_real()
else
local user = DataManager.SelfUser
if user.address then
self._view:GetChild("tex_address").text = user.address
end
end
end)
if self._type == 0 then
self:fill_real()
end
ctr_nav.selectedIndex = self._type
end
function M:fill_real()
local user = DataManager.SelfUser
if user.real_info then
self.ctr_update.selectedIndex = 1
2025-11-06 17:37:53 +08:00
self._view:GetChild("tex_name1").text = "姓名:" .. user.real_info.name
self._view:GetChild("tex_identity1").text = "身份证号:" .. ViewUtil.identity_hide(user.real_info.identity)
2025-04-01 10:48:36 +08:00
else
self.ctr_update.selectedIndex = 0
end
end
2025-11-06 17:37:53 +08:00
2025-04-01 10:48:36 +08:00
function M:SetCallBack(callback)
self._CB = callback
end
function M:real_action()
2025-11-06 17:37:53 +08:00
local check, str = self:CheckInputValidity()
2025-04-01 10:48:36 +08:00
if not check then
ViewUtil.ShowTips(str)
return
end
2025-11-06 17:37:53 +08:00
ViewUtil.ShowModalWait2(self._root_view, "正在提交认证...")
local loddyctr = ControllerManager.GetController(LoddyController)
2025-04-01 10:48:36 +08:00
local _data = {}
2025-11-06 17:37:53 +08:00
_data.type = 1
2025-04-01 10:48:36 +08:00
local real_info = {}
2025-11-06 17:37:53 +08:00
real_info.name = self._view:GetChild("tex_name").text
2025-04-01 10:48:36 +08:00
real_info.identity = self._view:GetChild("tex_identity").text
_data.real_info = real_info
2025-11-06 17:37:53 +08:00
loddyctr:UpdateUserInfo(_data, function(res)
ViewUtil.CloseModalWait2()
if (res.ReturnCode == 0) then
2025-04-01 10:48:36 +08:00
DataManager.SelfUser.real_info = real_info
if self._callback then self._callback() end
else
ViewUtil.ErrorTip(res.ReturnCode, "认证失败,请重试")
end
self:Close()
end)
end
function M:CheckInputValidity()
local name = self._view:GetChild("tex_name").text
local id = self._view:GetChild("tex_identity").text
if name then
local l = string.len(name)
if l == 0 then return false, "请输入名字" end
-- 中文长度是3
if l == 3 then return false, "名字过短" end
for i = 1, l do
local c = string.byte(string.sub(name, i, i))
--if not ((65 <= c and c <= 90) or (97 <= c and c <= 122) or c > 127) then
if not (c > 127) then
return false, "名字中不能包含英文、数字或特殊符号"
end
end
end
if id then
local l = string.len(id)
if l ~= 18 then return false, "请输入18位身份证号码" end
2025-11-06 17:37:53 +08:00
if not (tonumber(id) or string.sub(id, 18, 18) == "X") then
2025-04-01 10:48:36 +08:00
return false, "请输入正确的身份证号码"
end
end
return true
end
function M:address_action()
local tex_address = self._view:GetChild("tex_address").text
2025-11-06 17:37:53 +08:00
if string.len(tex_address) <= 0 then
2025-04-01 10:48:36 +08:00
ViewUtil.ShowTips("请输入详细地址")
return
end
2025-11-06 17:37:53 +08:00
ViewUtil.ShowModalWait2(self._root_view, "正在提交...")
local loddyctr = ControllerManager.GetController(LoddyController)
2025-04-01 10:48:36 +08:00
local _data = {}
2025-11-06 17:37:53 +08:00
_data.type = 2
2025-04-01 10:48:36 +08:00
_data.address = tex_address
2025-11-06 17:37:53 +08:00
loddyctr:UpdateUserInfo(_data, function(res)
ViewUtil.CloseModalWait2()
if (res.ReturnCode == 0) then
2025-04-01 10:48:36 +08:00
DataManager.SelfUser.address = _data.address
if self._callback then self._callback() end
else
2025-11-06 17:37:53 +08:00
ViewUtil.ErrorTip(res.ReturnCode, "提示失败")
2025-04-01 10:48:36 +08:00
end
self:Close()
end)
end
2025-11-06 17:37:53 +08:00
return M