// // LDCollectionTicketController.m // YouHuiProject // // Created by 小花 on 2018/1/24. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDCollectionTicketController.h" #import "LDCollectionTicketCell.h" #import "LDDateHeaderView.h" #import "LDCollectionModel.h" #import "LDSimilarGoodsController.h" #import "LDLoginViewController.h" @interface LDCollectionTicketController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *nearbyArr; // 即将过期的数组 @property (nonatomic, strong) NSMutableArray *allDataArr; @end @implementation LDCollectionTicketController - (void)viewDidLoad { [super viewDidLoad]; [self configTableView]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self configNoDataView]; [self loadData]; } - (void)configTableView { self.view.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.tableView]; } - (void)configNoDataView { self.tableView.showNoDataView = YES; if (![AccountTool isLogin]) { self.tableView.defaultNoDataText = @"未登录,点击登录"; kWeak(self); self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) { kStrong(self); LDNewLoginVC *login = [[LDNewLoginVC alloc] init]; login.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:login animated:YES completion:nil]; }; }else { self.tableView.defaultNoDataText = @"暂无收藏数据,点击刷新"; kWeak(self); self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) { kStrong(self); [self loadData]; }; } } - (void)loadData { if (![AccountTool isLogin]) { return; } [LDHttp post:MyCollectCollectTicket params:nil success:^(id json) { [self.allDataArr removeAllObjects]; NSArray *detailList = json[@"goods_detail"]; for (NSArray *arr in detailList) { NSMutableArray *items = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[LDCollectionModel class] json:arr]; [self.allDataArr addObject:items]; } self.nearbyArr = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[LDCollectionModel class] json:json[@"nearly_outdate"]]; if (self.nearbyArr.count != 0) { [self.allDataArr insertObject:self.nearbyArr atIndex:0]; } [self.tableView reloadData]; } failure:^(NSError *error) { }]; } /** 移除收藏 */ - (void)deleteCollectionGoodAtIndexPath:(NSIndexPath *)indexPath { LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row]; NSDictionary *para = @{@"goods_id":model.goods_id}; [LDHttp post:DelCollectionTickets params:para success:^(id json) { // 删除模型 NSMutableArray *mArr = self.allDataArr[indexPath.section]; [mArr removeObjectAtIndex:indexPath.row]; [self.allDataArr replaceObjectAtIndex:indexPath.section withObject:mArr]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } failure:^(NSError *error) { }]; } #pragma mark ------------------------ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [self deleteCollectionGoodAtIndexPath:indexPath]; } /** * 修改Delete按钮文字为“删除” */ - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"删除"; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *arr = self.allDataArr[section]; return arr.count; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.allDataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { LDCollectionTicketCell *cell = [LDCollectionTicketCell cellWithTableView:tableView]; cell.selectionStyle = UITableViewCellSelectionStyleNone; LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row]; cell.model = model; cell.similarClick = ^{ //找相似点击 LDSimilarGoodsController *similar = [[LDSimilarGoodsController alloc] init]; similar.goods_id = model.goods_id; [self.navigationController pushViewController:similar animated:YES]; }; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { LDDateHeaderView *header = [[LDDateHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)]; LDCollectionModel *model = [self.allDataArr[section] firstObject]; [header setDateWith:model.collect_time]; return header; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row]; // if ([model.is_outdate boolValue]) { // //找相似 // LDSimilarGoodsController *similar = [[LDSimilarGoodsController alloc] init]; // similar.goods_id = model.goods_id; // [self.navigationController pushViewController:similar animated:YES]; // }else { // LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init]; // detail.goods_id = model.goods_id; // [self.navigationController pushViewController:detail animated:YES]; // } LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.coupon_start_time coupon_end_time:model.coupon_end_time coupon_id:model.coupon_id]; detail.requestModel = requestModel; [self.navigationController pushViewController:detail animated:YES]; } #pragma mark ===================== layezer ============== - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-TabbarHeight) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; // _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } return _tableView; } - (NSMutableArray *)allDataArr { if (!_allDataArr) { _allDataArr = [NSMutableArray array]; } return _allDataArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end