123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @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
|