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

189 lines
7.7 KiB
Lua
Raw Normal View History

2025-10-23 17:58:16 +08:00
local LobbyGiftDiamond = {}
2025-10-16 16:26:09 +08:00
local M = LobbyGiftDiamond
2025-10-17 18:30:44 +08:00
function M.new(data, callback)
2025-10-16 16:26:09 +08:00
setmetatable(M, { __index = BaseWindow })
2025-10-17 18:30:44 +08:00
local self = setmetatable({}, { __index = M })
self.class = "LobbyGiftDiamond"
2025-10-20 18:30:18 +08:00
self._full = true
2025-10-16 16:26:09 +08:00
self._close_destroy = true
2025-10-20 18:30:18 +08:00
self._close_zone = false
2025-10-17 18:30:44 +08:00
self._data = data
self._callback = callback
2025-10-16 16:26:09 +08:00
self:init("ui://Lobby/GiftDiamond")
return self
end
function M:init(url)
BaseWindow.init(self, url)
2025-10-20 18:30:18 +08:00
local input_id = self._view:GetChild('input_id')
2025-10-23 17:58:16 +08:00
input_id.onClick:Set(function()
self._view:GetChild('text_name').text = ""
self._view:GetChild('btn_head').url = ""
end)
2025-10-20 18:30:18 +08:00
input_id.onFocusOut:Set(function()
--发送查找用户的协议
2025-10-23 17:58:16 +08:00
local lobbyCtr = ControllerManager.GetController(LoddyController)
lobbyCtr:GetUserInfoByDaili({ tagId = tonumber(input_id.text) }, function(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "没有该用户")
else
if res.Data.nick == "" and res.Data.portrait == "" then
ViewUtil.ErrorTip(res.ReturnCode, "没有该用户")
else
self._view:GetChild('text_name').text = res.Data.nick
ImageLoad.Load(res.Data.portrait, self._view:GetChild('btn_head'))
end
end
end)
2025-10-20 18:30:18 +08:00
end)
2025-10-16 16:26:09 +08:00
self._view:GetChild('btn_center').onClick:Set(function()
2025-10-20 18:30:18 +08:00
local text_id = input_id.text
2025-10-16 16:26:09 +08:00
local text_num = self._view:GetChild('input_num').text
2025-10-23 17:58:16 +08:00
if self._view:GetChild('text_name').text == "" then
ViewUtil.ErrorTip(-1, "请输入正确的用户ID")
return
end
2025-10-24 19:30:35 +08:00
if not tonumber(text_num) or tonumber(text_num) == 0 then
ViewUtil.ErrorTip(-1, "请输入赠送数量")
return
end
2025-10-23 17:58:16 +08:00
local _curren_msg = MsgWindow.new(self._root_view,
2025-10-24 19:30:35 +08:00
string.format("确定赠送玩家(%s)%s房卡吗", self._view:GetChild('text_name').text, text_num),
2025-10-23 17:58:16 +08:00
MsgWindow.MsgMode.OkAndCancel)
2025-10-24 19:30:35 +08:00
_curren_msg._new_hide = false
2025-10-23 17:58:16 +08:00
_curren_msg.onOk:Add(function()
local lobbyCtr = ControllerManager.GetController(LoddyController)
lobbyCtr:GiftDiamond(
{ tagId = tonumber(text_id), diamo = tonumber(text_num), tagNick = self._view:GetChild('text_name').text },
function(res)
if res.ReturnCode == 0 then
DataManager.SelfUser.diamo = DataManager.SelfUser.diamo - text_num
self._callback()
self._view:GetChild('input_num').text = ""
-- self:Destroy()
ViewUtil.ErrorTip(-1, "赠送房卡成功")
else
ViewUtil.ErrorTip(res.ReturnCode, "赠送房卡失败")
end
end)
2025-10-16 16:26:09 +08:00
end)
2025-10-23 17:58:16 +08:00
_curren_msg:Show()
2025-10-16 16:26:09 +08:00
end)
2025-10-20 18:30:18 +08:00
local ctr_page = self._view:GetController('page')
ctr_page.onChanged:Set(function()
if ctr_page.selectedIndex == 0 then
input_id.text = ""
self._view:GetChild('input_num').text = ""
self._view:GetChild('text_name').text = ""
self._view:GetChild('btn_head').url = ""
elseif ctr_page.selectedIndex == 1 then
2025-10-23 17:58:16 +08:00
self._data_sendPage = 0
self._data_GetPage = 0
self:FillRecord(1)
2025-10-20 18:30:18 +08:00
end
end)
2025-10-23 17:58:16 +08:00
local crt_detail = self._view:GetController('detail')
crt_detail.onChanged:Set(function()
self:FillRecord(1 - crt_detail.selectedIndex)
end)
2025-10-20 18:30:18 +08:00
self._list_list = self._view:GetChild('list')
self._list_list.itemRenderer = function(index, obj)
2025-10-23 17:58:16 +08:00
local info = self._data_resList[index + 1]
if self._changeType == 1 then
obj:GetChild('name1').text = ViewUtil.stringEllipsis(info.user_nick)
obj:GetChild('id1').text = ViewUtil.stringEllipsis(info.uid)
obj:GetChild('name2').text = ViewUtil.stringEllipsis(info.operator_name)
obj:GetChild('id2').text = ViewUtil.stringEllipsis(info.operator)
else
obj:GetChild('name2').text = ViewUtil.stringEllipsis(info.user_nick)
obj:GetChild('id2').text = ViewUtil.stringEllipsis(info.uid)
obj:GetChild('name1').text = ViewUtil.stringEllipsis(info.operator_name)
obj:GetChild('id1').text = ViewUtil.stringEllipsis(info.operator)
end
obj:GetChild('time').text = os.date("%Y-%m-%d", info.time)
obj:GetChild('num').text = info.diamo
2025-10-20 18:30:18 +08:00
end
2025-10-23 17:58:16 +08:00
self._btn_lastPage = self._view:GetChild('btn_lastPage')
self._btn_lastPage.onClick:Set(function()
if self._changeType == 0 then
self._data_GetPage = self._data_GetPage - 1
else
self._data_sendPage = self._data_sendPage - 1
end
local pageNum = self._changeType == 0 and self._data_GetPage or self._data_sendPage
if pageNum == 0 then
self._btn_lastPage:GetController('donTouch').selectedIndex = 1.
self._btn_lastPage.touchable = false
else
self._btn_lastPage:GetController('donTouch').selectedIndex = 0
self._btn_lastPage.touchable = true
end
self:FillRecord(self._changeType or 0)
end)
self._btn_nextPage = self._view:GetChild('btn_nextPage')
self._btn_nextPage.onClick:Set(function()
if self._changeType == 0 then
self._data_GetPage = self._data_GetPage + 1
else
self._data_sendPage = self._data_sendPage + 1
end
local pageNum = self._changeType == 0 and self._data_GetPage or self._data_sendPage
if (pageNum + 1) * 4 >= self._list_list.numItems then
self._btn_nextPage:GetController('donTouch').selectedIndex = 1.
self._btn_nextPage.touchable = false
else
self._btn_nextPage:GetController('donTouch').selectedIndex = 0
self._btn_nextPage.touchable = true
end
self:FillRecord(self._changeType or 0)
end)
end
function M:FillRecord(type)
--type 0:转入记录 1转出记录
--发送请求填充记录并渲染数据,默认约定一页只有四条数据
self._changeType = type
local pageNum = type == 0 and self._data_GetPage or self._data_sendPage
ViewUtil:ShowModalWait2(0.1)
local lobbyCtr = ControllerManager.GetController(LoddyController)
lobbyCtr:GetGiftDiamondRecord(
{ pageNo = pageNum * 4, changeType = type }, function(res)
if res.ReturnCode ~= 0 then
ViewUtil.ErrorTip(res.ReturnCode, "没有记录啦")
else
if pageNum == 0 then
self._btn_lastPage:GetController('donTouch').selectedIndex = 1.
self._btn_lastPage.touchable = false
else
self._btn_lastPage:GetController('donTouch').selectedIndex = 0
self._btn_lastPage.touchable = true
end
if (pageNum + 1) * 4 >= res.Data.count then
self._btn_nextPage:GetController('donTouch').selectedIndex = 1.
self._btn_nextPage.touchable = false
else
self._btn_nextPage:GetController('donTouch').selectedIndex = 0
self._btn_nextPage.touchable = true
end
self._view:GetChild('text_pageNum').text = string.format("%s/%s", pageNum + 1,
math.ceil(res.Data.count / 4))
self._data_resList = res.Data.rechargeDimoList
self._list_list.numItems = #self._data_resList
ViewUtil.CloseModalWait2()
end
end)
2025-10-16 16:26:09 +08:00
end
return M