local UILuckyLotteryDirectGift = UIViewClass() function UILuckyLotteryDirectGift:OnOpened(context) self.activityId = context.activityId self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.RefreshAllGift) CTL.LuckyLottery.SetDailyRedPoint(self.activityId) self.giftInfo = {} self:RefreshAllGift() CTL.DirectGift.SaveNewDirectGiftInfo(nil, self.activityId) end local function SortById(giftInfoA, giftInfoB) return giftInfoA.giftId < giftInfoB.giftId end function UILuckyLotteryDirectGift:RefreshAllGift() --这边模块内默认排序是售罄沉底,这边需要固定顺序,不需要排序,所以取出来再重新按照giftId排序 local temp = {} for i, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, self.activityId) do table.insert(temp, v) end table.sort(temp, SortById) for i, v in ipairs(temp) do local cell = self.group_Gift[i] if cell then self.giftInfo[i] = v self:RefreshGiftCell(v, cell) else break end end end function UILuckyLotteryDirectGift:RefreshGiftCell(data, cell) local sheetData = data.data local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) cell.txt_Title.text = giftRewardData.Name --cell.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate) UIUtils.SetImageByAssetBundle(cell.img_Gift, sheetData.HotPackagePic) --这里默认只配置一个道具,只显示第一个道具的道具名x数量 local reward = giftRewardData.Reward_Table[1] local itemData = DataSheetManager.ItemData:GetDataByID(reward.RewardID) cell.txt_ItemName.text = UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]) .. "x" .. reward.RewardNum local amount = MDL.Currency.GetIAPRewardAmountBy(giftRewardData.IapID) UIUtils.SetActive(cell.txt_Integral, amount and true or false) if amount then UIUtils.SetLabel(cell.txt_Integral, string.FormatByIdsId(Const_IDS.IDS_TotalTopUp_Score_Tips_Giftbag, amount)) end if sheetData.IsFree then UIUtils.SetLabelText(cell.txt_BuyPrice, Const_IDS.IDS_Gift_Receive) else cell.txt_BuyPrice.text = MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID) end UIUtils.SetActive(cell.txt_Integral, not sheetData.IsFree) ---需要补充限购逻辑,购买到限购的置灰逻辑 --限购显示 if sheetData.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(cell.group_Limit, false) cell.state_Gift:SetState(0) else UIUtils.SetActive(cell.group_Limit, true) if sheetData.LimitType == LuaConst.LimitBuyType.Forever then UIUtils.SetLabelText(cell.lab_Limit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) else cell.lab_Limit.text = CTL.PayMall.GetLimitedTitleText(sheetData.LimitType) end local limitNumText = (sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(self.activityId, data.giftId)) .. "/" .. sheetData.TimesLimit if data.state == MDL.DirectGift.GiftStateEnum.Available then cell.state_Gift:SetState(0) limitNumText = UTL.Color.FormatGreenColor(limitNumText) elseif data.state == MDL.DirectGift.GiftStateEnum.ShowLimited then cell.state_Gift:SetState(1) limitNumText = UTL.Color.FormatRedColor(limitNumText) end cell.txt_Limit.text = limitNumText end end function UILuckyLotteryDirectGift:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() else for i, v in ipairs(self.group_Gift) do if comp == v.btn_Buy then local data = self.giftInfo[i] if data.data.IsFree then MDL.DirectGift.DirectGiftGetFreeAwardReq(data.activityId, data.giftId) return end local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(data.data.GiftID) local iapStringId = giftRewardData.IapID local iap for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapStringId then iap = v.Index break end end if iap then MDL.Currency.GetOrderIDReq(iap, MDL.Currency.PayType.DirectGift, data.giftId, data.activityId, MDL.OperationActivity.ActivityType.LuckyLottery) else logging.error(LTAG.ERROR, "iap not found", iapStringId) end end end end end function UILuckyLotteryDirectGift:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end return UILuckyLotteryDirectGift