189 lines
7.7 KiB
Lua
189 lines
7.7 KiB
Lua
local LobbyGiftDiamond = {}
|
||
|
||
local M = LobbyGiftDiamond
|
||
|
||
function M.new(data, callback)
|
||
setmetatable(M, { __index = BaseWindow })
|
||
local self = setmetatable({}, { __index = M })
|
||
self.class = "LobbyGiftDiamond"
|
||
self._full = true
|
||
self._close_destroy = true
|
||
self._close_zone = false
|
||
self._data = data
|
||
self._callback = callback
|
||
self:init("ui://Lobby/GiftDiamond")
|
||
return self
|
||
end
|
||
|
||
function M:init(url)
|
||
BaseWindow.init(self, url)
|
||
|
||
local input_id = self._view:GetChild('input_id')
|
||
|
||
input_id.onClick:Set(function()
|
||
self._view:GetChild('text_name').text = ""
|
||
self._view:GetChild('btn_head').url = ""
|
||
end)
|
||
|
||
input_id.onFocusOut:Set(function()
|
||
--发送查找用户的协议
|
||
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)
|
||
end)
|
||
|
||
self._view:GetChild('btn_center').onClick:Set(function()
|
||
local text_id = input_id.text
|
||
local text_num = self._view:GetChild('input_num').text
|
||
if self._view:GetChild('text_name').text == "" then
|
||
ViewUtil.ErrorTip(-1, "请输入正确的用户ID")
|
||
return
|
||
end
|
||
if not tonumber(text_num) or tonumber(text_num) == 0 then
|
||
ViewUtil.ErrorTip(-1, "请输入赠送数量")
|
||
return
|
||
end
|
||
local _curren_msg = MsgWindow.new(self._root_view,
|
||
string.format("确定赠送玩家(%s)%s房卡吗?", self._view:GetChild('text_name').text, text_num),
|
||
MsgWindow.MsgMode.OkAndCancel)
|
||
_curren_msg._new_hide = false
|
||
_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)
|
||
end)
|
||
_curren_msg:Show()
|
||
end)
|
||
|
||
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
|
||
self._data_sendPage = 0
|
||
self._data_GetPage = 0
|
||
self:FillRecord(1)
|
||
end
|
||
end)
|
||
|
||
local crt_detail = self._view:GetController('detail')
|
||
crt_detail.onChanged:Set(function()
|
||
self:FillRecord(1 - crt_detail.selectedIndex)
|
||
end)
|
||
|
||
self._list_list = self._view:GetChild('list')
|
||
self._list_list.itemRenderer = function(index, obj)
|
||
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
|
||
end
|
||
|
||
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)
|
||
end
|
||
|
||
return M
|