143 lines
4.2 KiB
Lua
143 lines
4.2 KiB
Lua
--实名认证窗口
|
|
|
|
local RealAddressView = {}
|
|
|
|
local M = RealAddressView
|
|
|
|
function RealAddressView.new(type,callback)
|
|
setmetatable(M, {__index = BaseWindow})
|
|
local self = setmetatable({}, {__index = M})
|
|
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)
|
|
BaseWindow.init(self,url)
|
|
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")
|
|
btn_address.onClick:Set(function ()
|
|
self:address_action()
|
|
end)
|
|
|
|
self.ctr_update = view:GetController("update")
|
|
|
|
local ctr_nav = view:GetController("nav")
|
|
ctr_nav.onChanged:Set(function()
|
|
if ctr_nav.selectedIndex ==0 then
|
|
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
|
|
self._view:GetChild("tex_name1").text ="姓名:".. user.real_info.name
|
|
self._view:GetChild("tex_identity1").text = "身份证号:"..ViewUtil.identity_hide(user.real_info.identity)
|
|
else
|
|
self.ctr_update.selectedIndex = 0
|
|
end
|
|
end
|
|
function M:SetCallBack(callback)
|
|
self._CB = callback
|
|
end
|
|
|
|
function M:real_action()
|
|
local check,str = self:CheckInputValidity()
|
|
if not check then
|
|
ViewUtil.ShowTips(str)
|
|
return
|
|
end
|
|
ViewUtil.ShowModalWait(self._root_view,"正在提交认证...")
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
|
local _data = {}
|
|
_data.type =1
|
|
local real_info = {}
|
|
real_info.name =self._view:GetChild("tex_name").text
|
|
real_info.identity = self._view:GetChild("tex_identity").text
|
|
_data.real_info = real_info
|
|
loddyctr:UpdateUserInfo(_data,function( res)
|
|
ViewUtil.CloseModalWait()
|
|
if (res.ReturnCode ==0) then
|
|
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
|
|
if not (tonumber(id) or string.sub(id,18,18) == "X") then
|
|
return false, "请输入正确的身份证号码"
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
function M:address_action()
|
|
local tex_address = self._view:GetChild("tex_address").text
|
|
if string.len(tex_address) <=0 then
|
|
ViewUtil.ShowTips("请输入详细地址")
|
|
return
|
|
end
|
|
ViewUtil.ShowModalWait(self._root_view,"正在提交...")
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
|
local _data = {}
|
|
_data.type =2
|
|
_data.address = tex_address
|
|
loddyctr:UpdateUserInfo(_data,function( res)
|
|
ViewUtil.CloseModalWait()
|
|
if (res.ReturnCode ==0) then
|
|
DataManager.SelfUser.address = _data.address
|
|
if self._callback then self._callback() end
|
|
else
|
|
ViewUtil.ErrorTip(res.ReturnCode,"提示失败")
|
|
end
|
|
self:Close()
|
|
end)
|
|
end
|
|
|
|
return M |