MOMyBackpackCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // MOMyBackpackCell.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/21.
  6. //
  7. #import "MOMyBackpackCell.h"
  8. #import "NSDate+BXHCategory.h"
  9. #import "NSDate+K1Util.h"
  10. #import "UIImageView+Gift.h"
  11. @implementation MOMyBackpackCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. // Initialization code
  15. self.backgroundColor = [UIColor clearColor];
  16. self.bgView.layer.cornerRadius = 15.0;
  17. self.bgView.layer.masksToBounds = YES;
  18. self.tipBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  19. self.theSwitch.onTintColor = [MOTools colorWithHexString:@"#0BDDFC" alpha:1.0];
  20. self.titleLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
  21. [self.tipBtn setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
  22. }
  23. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  24. [super setSelected:selected animated:animated];
  25. // Configure the view for the selected state
  26. }
  27. - (void)setCellModel:(MOShopList *)cellModel{
  28. _cellModel = cellModel;
  29. [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:cellModel.propInfo.storeInfo.image]];
  30. self.titleLab.text = cellModel.propInfo.storeInfo.name;
  31. [self.theSwitch setOn:cellModel.used];
  32. if(cellModel.expire){
  33. [self.tipBtn setImage:[UIImage imageNamed:@"icon_backpack_time_gray"] forState:UIControlStateNormal];
  34. [self.tipBtn setTitle:NSLocalString(@"mimo_common_expired") forState:UIControlStateNormal];
  35. [self.tipBtn setTitleColor:[MOTools colorWithHexString:@"#ABABAB" alpha:1.0] forState:UIControlStateNormal];
  36. }
  37. else{
  38. [self.tipBtn setImage:[UIImage imageNamed:@"icon_history_time"] forState:UIControlStateNormal];
  39. [self.tipBtn setTitleColor:[MOTools colorWithHexString:@"#17CBEA" alpha:1.0] forState:UIControlStateNormal];
  40. if(cellModel.permanent){
  41. [self.tipBtn setTitle:NSLocalString(@"mimo_back_pack_permanent") forState:UIControlStateNormal];
  42. }
  43. else{
  44. NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
  45. NSTimeInterval time = (cellModel.overdue - currentTime) / 1000.0;
  46. //秒
  47. NSDate *expireDate = [NSDate getTimeWithLong:cellModel.overdue];
  48. NSInteger dayNum = [NSDate bxh_daysBetweenDate:[NSDate date] andDate:expireDate];
  49. NSString *dayStr = [NSString stringWithFormat:@"%zd",dayNum];
  50. [self.tipBtn setTitle:[NSString stringWithFormat:@"%@%@",dayStr,NSLocalString(@"mimo_common_day")] forState:UIControlStateNormal];
  51. }
  52. }
  53. }
  54. - (void)setGiftModel:(MOGiftlist *)giftModel{
  55. _giftModel = giftModel;
  56. [self.iconImgView mo_setGiftImageWith:giftModel.giftInfo.giftPath];
  57. self.titleLab.text = giftModel.giftInfo.giftName;
  58. [self.tipBtn setImage:[UIImage imageNamed:@"icon_history_time"] forState:UIControlStateNormal];
  59. [self.tipBtn setTitle:[NSString stringWithFormat:@"x%.f",giftModel.amount] forState:UIControlStateNormal];
  60. self.theSwitch.hidden = YES;
  61. }
  62. - (IBAction)openOrCloseAction:(UISwitch *)sender {
  63. NSString *idStr = self.cellModel.id;
  64. if(idStr.length == 0){
  65. return;
  66. }
  67. if(self.cellModel.expire){
  68. [self.theSwitch setOn:NO];
  69. self.buyShopView ? self.buyShopView(self.cellModel) : nil;
  70. return;
  71. }
  72. WEAKSELF
  73. NSDictionary *dict = @{@"id":idStr,
  74. @"use":@(sender.on)};
  75. [kHttpManager toUseThePropWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  76. if(kCode_Success){
  77. weakSelf.cellModel.used = sender.on;
  78. weakSelf.switchValueChange ? weakSelf.switchValueChange(weakSelf.cellModel) : nil;
  79. //如果更换的是头饰, 则需要更新个人页
  80. if(weakSelf.category == 2){
  81. [[MORefreshViewManage shareManager] setNeedRefreshWithCode:@"MOMineVC"];
  82. }
  83. if(sender.on){
  84. //座驾
  85. NSInteger enterBar = self.cellModel.propInfo.storeInfo.code;
  86. [[NSUserDefaults standardUserDefaults] setObject:@(enterBar) forKey:kUserEnterBar];
  87. }
  88. else{
  89. NSInteger enterBar = 0;
  90. [[NSUserDefaults standardUserDefaults] setObject:@(enterBar) forKey:kUserEnterBar];
  91. }
  92. }
  93. else{
  94. kShowNetError(data)
  95. weakSelf.theSwitch.on = !sender.on;
  96. }
  97. }];
  98. }
  99. @end