| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // MOMyBackpackTableView.m
- // MiMoLive
- //
- // Created by SuperC on 2023/12/21.
- //
- //一页的size
- #define kPageSize 20
- #import "MOMyBackpackTableView.h"
- @interface MOMyBackpackTableView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- /** 游标 */
- @property (nonatomic, copy) NSString *next;
- /** 没有更多的数据视图 */
- @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
- @end
- @implementation MOMyBackpackTableView
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
-
- self.backgroundColor = [UIColor clearColor];
-
- [self addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self);
- }];
-
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (void)listWillAppear{
- if(self.dataArr.count == 0){
-
- if(self.category == 4){
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"page":basePage};
- [self getUserGiftBagDataWith:baseDict];
- }
- else{
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"category":@(self.category),
- @"page":basePage};
- [self toGetMyBackpackListWithDict:baseDict];
- }
- }
- }
- - (void)toGetFirstHttpData{
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"category":@(self.category),
- @"page":basePage};
- [self toGetMyBackpackListWithDict:baseDict];
- }
- - (void)getUserGiftBagDataWith:(NSDictionary *)dict{
-
- WEAKSELF
- [kHttpManager toGetThePackGiftAllWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [weakSelf.tableView.mj_footer endRefreshing];
- if(kCode_Success){
- MOGiftListBaseData *baseData = [MOGiftListBaseData modelObjectWithDictionary:data[@"data"]];
- if(baseData.next == nil || baseData.next.length == 0){
- if(weakSelf.next == nil || weakSelf.next.length == 0){
-
- if(weakSelf.dataArr.count > 0){
- [weakSelf.dataArr removeAllObjects];
- }
-
- //第一页
- weakSelf.dataArr = [baseData.giftlist mutableCopy];
- }
- else{
- //最后一页
- [weakSelf.dataArr addObjectsFromArray:baseData.giftlist];
- }
- weakSelf.next = @"";
-
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- weakSelf.next = baseData.next;
- [weakSelf.dataArr addObjectsFromArray:baseData.giftlist];
- }
-
- for (MOGiftlist *object in weakSelf.dataArr) {
- object.isBag = YES;
- }
- [weakSelf.tableView reloadData];
-
- weakSelf.tableView.mj_footer.hidden = (weakSelf.dataArr.count > 0) ? NO : YES;
- weakSelf.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)toGetMyBackpackListWithDict:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetThePropUserListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
- [self.tableView.mj_footer endRefreshing];
-
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOShopBaseData *baseModel = [MOShopBaseData modelObjectWithDictionary:data[@"data"]];
- if(baseModel.next == nil || baseModel.next.length == 0){
- if(self.next == nil || self.next.length == 0){
- //第一页
- self.dataArr = [baseModel.shopList mutableCopy];
- }
- else{
- //最后一页
- [self.dataArr addObjectsFromArray:baseModel.shopList];
- }
- self.next = @"";
-
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- self.next = baseModel.next;
- [self.dataArr addObjectsFromArray:baseModel.shopList];
- }
-
- [self.tableView reloadData];
- self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
- self.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (UIView *)listView{
- return self;
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- WEAKSELF
-
- if(self.category == 4){
- MOGiftlist *modle = self.dataArr[indexPath.row];
- MOMyBackpackCell *cell = [tableView dequeueReusableCellWithIdentifier:MOMyBackpackCell_ID];
- cell.giftModel = modle;
- return cell;
- }
- else{
- MOShopList *model = self.dataArr[indexPath.row];
- MOMyBackpackCell *cell = [tableView dequeueReusableCellWithIdentifier:MOMyBackpackCell_ID];
- cell.category = self.category;
- cell.cellModel = model;
-
- //设置成功回调
- cell.switchValueChange = ^(MOShopList * _Nonnull cellModel) {
- for (MOShopList *tempObject in weakSelf.dataArr) {
- if([tempObject.id isEqualToString:cellModel.id]){
- tempObject.used = cellModel.used;
- }
- else{
- tempObject.used = NO;
- }
- }
- [weakSelf.tableView reloadData];
- };
-
- cell.buyShopView = ^(MOShopList * _Nonnull cellModel) {
- weakSelf.buyShopView ? weakSelf.buyShopView(cellModel) : nil;
- };
-
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- #pragma mark - Lazy
- - (UITableView *)tableView{
- if (!_tableView)
- {
- _tableView= [[UITableView alloc] init];
- if (@available(iOS 11.0, *))
- {
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- self.tableView.sectionHeaderTopPadding = 0;
- }
-
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.rowHeight = 94.0;
- [_tableView registerNib:[UINib nibWithNibName:@"MOMyBackpackCell" bundle:nil] forCellReuseIdentifier:MOMyBackpackCell_ID];
-
- WEAKSELF
- _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
-
- if(weakSelf.next.length == 0){
- return;
- }
-
- if(weakSelf.category == 4){
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"page":basePage};
- [self getUserGiftBagDataWith:baseDict];
- }
- else{
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
- NSDictionary *baseDict = @{@"category":@(weakSelf.category),
- @"page":basePage};
- [weakSelf toGetMyBackpackListWithDict:baseDict];
- }
- }];
-
- _tableView.mj_footer.hidden = YES;
-
- _tableView.backgroundView = self.noMoreDataView;
-
- }
- return _tableView;
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (MONoMoreDataView *)noMoreDataView{
- if(!_noMoreDataView){
- _noMoreDataView = [MONoMoreDataView new];
- }
- return _noMoreDataView;
- }
- @end
|