| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // MOMyBackpackCell.m
- // MiMoLive
- //
- // Created by SuperC on 2023/12/21.
- //
- #import "MOMyBackpackCell.h"
- #import "NSDate+BXHCategory.h"
- #import "NSDate+K1Util.h"
- #import "UIImageView+Gift.h"
- @implementation MOMyBackpackCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- self.backgroundColor = [UIColor clearColor];
-
- self.bgView.layer.cornerRadius = 15.0;
- self.bgView.layer.masksToBounds = YES;
-
- self.tipBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
-
- self.theSwitch.onTintColor = [MOTools colorWithHexString:@"#0BDDFC" alpha:1.0];
-
- self.titleLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
-
- [self.tipBtn setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)setCellModel:(MOShopList *)cellModel{
- _cellModel = cellModel;
-
- [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:cellModel.propInfo.storeInfo.image]];
- self.titleLab.text = cellModel.propInfo.storeInfo.name;
-
- [self.theSwitch setOn:cellModel.used];
-
- if(cellModel.expire){
- [self.tipBtn setImage:[UIImage imageNamed:@"icon_backpack_time_gray"] forState:UIControlStateNormal];
- [self.tipBtn setTitle:NSLocalString(@"mimo_common_expired") forState:UIControlStateNormal];
- [self.tipBtn setTitleColor:[MOTools colorWithHexString:@"#ABABAB" alpha:1.0] forState:UIControlStateNormal];
- }
- else{
- [self.tipBtn setImage:[UIImage imageNamed:@"icon_history_time"] forState:UIControlStateNormal];
- [self.tipBtn setTitleColor:[MOTools colorWithHexString:@"#17CBEA" alpha:1.0] forState:UIControlStateNormal];
-
-
- if(cellModel.permanent){
- [self.tipBtn setTitle:NSLocalString(@"mimo_back_pack_permanent") forState:UIControlStateNormal];
- }
- else{
- NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
- NSTimeInterval time = (cellModel.overdue - currentTime) / 1000.0;
-
- //秒
- NSDate *expireDate = [NSDate getTimeWithLong:cellModel.overdue];
- NSInteger dayNum = [NSDate bxh_daysBetweenDate:[NSDate date] andDate:expireDate];
-
- NSString *dayStr = [NSString stringWithFormat:@"%zd",dayNum];
- [self.tipBtn setTitle:[NSString stringWithFormat:@"%@%@",dayStr,NSLocalString(@"mimo_common_day")] forState:UIControlStateNormal];
- }
- }
-
- }
- - (void)setGiftModel:(MOGiftlist *)giftModel{
- _giftModel = giftModel;
-
- [self.iconImgView mo_setGiftImageWith:giftModel.giftInfo.giftPath];
- self.titleLab.text = giftModel.giftInfo.giftName;
-
- [self.tipBtn setImage:[UIImage imageNamed:@"icon_history_time"] forState:UIControlStateNormal];
- [self.tipBtn setTitle:[NSString stringWithFormat:@"x%.f",giftModel.amount] forState:UIControlStateNormal];
-
- self.theSwitch.hidden = YES;
- }
- - (IBAction)openOrCloseAction:(UISwitch *)sender {
- NSString *idStr = self.cellModel.id;
- if(idStr.length == 0){
- return;
- }
-
- if(self.cellModel.expire){
- [self.theSwitch setOn:NO];
- self.buyShopView ? self.buyShopView(self.cellModel) : nil;
- return;
- }
-
- WEAKSELF
- NSDictionary *dict = @{@"id":idStr,
- @"use":@(sender.on)};
- [kHttpManager toUseThePropWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- weakSelf.cellModel.used = sender.on;
- weakSelf.switchValueChange ? weakSelf.switchValueChange(weakSelf.cellModel) : nil;
-
- //如果更换的是头饰, 则需要更新个人页
- if(weakSelf.category == 2){
- [[MORefreshViewManage shareManager] setNeedRefreshWithCode:@"MOMineVC"];
- }
-
- if(sender.on){
- //座驾
- NSInteger enterBar = self.cellModel.propInfo.storeInfo.code;
- [[NSUserDefaults standardUserDefaults] setObject:@(enterBar) forKey:kUserEnterBar];
- }
- else{
- NSInteger enterBar = 0;
- [[NSUserDefaults standardUserDefaults] setObject:@(enterBar) forKey:kUserEnterBar];
- }
-
- }
- else{
- kShowNetError(data)
- weakSelf.theSwitch.on = !sender.on;
- }
- }];
- }
- @end
|