-- 全民推广 设置界面 local GroupNumberInputView = import(".GroupNumberInputView") local GroupMngPromoteSetView = {} local M = GroupMngPromoteSetView local STR_TIP = { IsNull = "至少要添加一条推广奖励项。", SameNum = "设置了相同的推广人数,相同项只有一条会生效,是否继续?", SameVal = "设置了相同的推广奖励比例,是否继续?", } function GroupMngPromoteSetView.new(gid, blur_view) local self = M self.class = "GroupMngPromoteSetView" self.group_id = gid self.blur_view = blur_view self.promote_data = {} self.old_data = nil self:InitView() return self end local function FillPromoteItem(self, index, item) local min_p, min_v, max_p, max_v = -1, -1, 999999, 100 local data = self.promote_data[index + 1] if index > 0 then local last_data = self.promote_data[index] min_p = last_data.num min_v = last_data.val end if index < #self.promote_data - 1 then local next_data = self.promote_data[index + 2] max_p = next_data.num max_v = next_data.val end if #self.promote_data == 1 and index == 0 then item:GetController("last").selectedIndex = 1 else item:GetController("last").selectedIndex = 0 end item:GetChild("btn_remove").onClick:Set(function() local msg_tip = MsgWindow.new(self._root_view, "确定要移除该条奖励吗?", MsgWindow.MsgMode.OkAndCancel) msg_tip.onOk:Add(function() table.remove(self.promote_data, index + 1) self.lst_promote.numItems = #self.promote_data end) msg_tip:Show() end) local btn_p = item:GetChild("btn_p") local btn_v = item:GetChild("btn_v") local tex_p = btn_p:GetChild("tex_num") local tex_v = btn_v:GetChild("tex_num") tex_p.text = data.num tex_v.text = string.format("%d%%", data.val) btn_p.onClick:Set(function() local gfiv = GroupNumberInputView.new(self._root_view,function(num) if num <= min_p then ViewUtil.ErrorTip(nil, "输入值必须大于" .. min_p) return end if num >= max_p then ViewUtil.ErrorTip(nil, "输入值必须小于" .. max_p) return end tex_p.text = num data.num = num end, 0) gfiv:Show() end) btn_v.onClick:Set(function() local gfiv = GroupNumberInputView.new(self._root_view,function(num) if num <= min_v then ViewUtil.ErrorTip(nil, "输入值必须大于" .. min_v) return end if num >= max_v then ViewUtil.ErrorTip(nil, "输入值必须小于" .. max_v) return end if num > 100 then ViewUtil.ErrorTip(nil, "输入值不能超过100") return end tex_v.text = string.format("%d%%", num) data.val = num end, 0) gfiv:Show() end) end function M:InitView() self._view = UIPackage.CreateObjectFromURL("ui://NewGroup/View_GroupPromoteSet") self.lst_promote = self._view:GetChild("lst_promote") self.lst_promote:SetVirtual() self.lst_promote.itemRenderer = function(index, item) FillPromoteItem(self, index, item) end self.lst_promote.numItems = 0 self._view:GetChild("btn_add").onClick:Set(function() local last_data = self.promote_data[#self.promote_data] if last_data.val == 100 then ViewUtil.ErrorTip(nil, "奖励最大为100%,无法再新增。") return end local tem = {num = last_data.num + 1, val = last_data.val + 1} table.insert(self.promote_data, tem) self.lst_promote.numItems = #self.promote_data end) self._view:GetChild("btn_confirm").onClick:Set(function() local msg_confirm = MsgWindow.new(self._root_view, "确定修改吗?", MsgWindow.MsgMode.OkAndCancel) msg_confirm.onOk:Add(function() self:CheckData(function() self:SetPromote() end) end) msg_confirm:Show() end) self._view:GetChild("btn_cancel").onClick:Set(function() local msg_cancel = MsgWindow.new(self._root_view, "确定恢复所有改动吗?", MsgWindow.MsgMode.OkAndCancel) msg_cancel.onOk:Add(function() self.promote_data = membe_deep_clone(self.old_data) self.lst_promote.numItems = #self.promote_data end) msg_cancel:Show() end) end function M:CheckData(callback) local str_tip if #self.promote_data == 0 then str_tip = STR_TIP.IsNull local msg_tip = MsgWindow.new(self._root_view, str_tip, MsgWindow.MsgMode.OnlyOk) msg_tip.onOk:Add(function( ... ) msg_tip:Dispose() end) msg_tip:Show() else local tn, tv = {}, {} for i = 1, #self.promote_data do local data = self.promote_data[i] if tn[data.num] then tn[data.num] = tn[data.num] + 1 else tn[data.num] = 1 end if tv[data.val] then tv[data.val] = tv[data.val] + 1 else tv[data.val] = 1 end end if table.nums(tn) < #self.promote_data then str_tip = STR_TIP.SameNum elseif table.nums(tv) < #self.promote_data then str_tip = STR_TIP.SameVal end if str_tip then local msg_tip = MsgWindow.new(self._root_view, str_tip, MsgWindow.MsgMode.OkAndCancel) msg_tip.onOk:Add(function() callback() end) msg_tip:Show() else callback() end end end function M:initData() local fgCtr = ControllerManager.GetController(NewGroupController) fgCtr:FG_GetPromote(self.group_id, function(res) if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, "获取推广奖励失败") else local data = res.Data.data self.old_data = data self.promote_data = membe_deep_clone(data) self.lst_promote.numItems = #self.promote_data self._view:GetController("not_null").selectedIndex = 1 end end) end function M:SetPromote() local fgCtr = ControllerManager.GetController(NewGroupController) fgCtr:FG_SetPromote(self.group_id, self.promote_data, function(res) if res.ReturnCode ~= 0 then ViewUtil.ErrorTip(res.ReturnCode, "设置推广奖励失败") else self.old_data = membe_deep_clone(self.promote_data) end end) end return M