123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- //
- // KXCreditCardViewController.m
- // CAISHEN
- //
- // Created by xiaoxi on 2017/12/1.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXCreditCardViewController.h"
- #import "KXCreditCardTableViewCell.h"
- #import "KXCreditCardModel.h"
- #import "KXLittleLogginView.h"
- #import "KXBaseLinkViewController.h"
- #import "KXCreditCardModel.h"
- @interface KXCreditCardViewController () <UITableViewDelegate,UITableViewDataSource,KXLittleLogginViewDelegate>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @property (nonatomic, assign) NSInteger index;
- @property (nonatomic, assign) NSInteger page;
- @end
- @implementation KXCreditCardViewController
- static NSString *const cellID = @"KXCreditCardTableViewCell";
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.name = @"信用卡";
- [self setupContentView];
- [MobClick event:@"CreditTab"];
- }
- - (void)setupContentView {
-
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-TabbarHeight) style:UITableViewStylePlain];
- self.tableView.backgroundColor = [UIColor whiteColor];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.tableFooterView = [[UIView alloc] init];
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.tableView registerClass:[KXCreditCardTableViewCell class] forCellReuseIdentifier:cellID];
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self headerFresh];
- }];
- self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- [self footerFresh];
- }];
- [self.tableView emptyViewConfigerBlock:^(FOREmptyAssistantConfiger *configer) {
- configer.emptyTitle = @"没有数据";
- configer.emptyTitleFont = FONT_SYS(14*SCREEN_MUTI);
- configer.emptyTitleColor = [UIColor detailTitleColor];
- }];
- [self.view addSubview:self.tableView];
- [self.tableView.mj_header beginRefreshing];
- // self.page = 1;
- // [self requestDataWithPage:self.page];
- }
- - (void)updateCreditStateWithModel:(KXCreditCardModel *)model{
-
- }
- - (void)headerFresh {
-
- self.page = 1;
- [self requestDataWithPage:self.page];
- }
- - (void)footerFresh {
-
- self.page ++;
- [self requestDataWithPage:self.page];
- }
- - (void)requestDataWithPage:(NSInteger)page {
-
- NSString *urlString = [NSString stringWithFormat:@"%@/CreditCard/list",URL];
- [KXHTTP post:urlString params:@{@"pageId":@(page)} success:^(id json) {
- NSArray *array = [NSArray yy_modelArrayWithClass:[KXCreditCardModel class] json:json[@"list"]];
- if (self.page == 1) {
- [self.dataSource removeAllObjects];
- }
- if (array.count) {
- [self.dataSource addObjectsFromArray:array];
- }
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- [self.tableView reloadData];
- } failure:^(NSError *error) {
-
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- return self.dataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- KXCreditCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
- KXCreditCardModel *model = self.dataSource[indexPath.row];
- [cell.iconView sd_setImageWithURL:[NSURL URLWithString:model.card_icon] placeholderImage:[UIImage imageNamed:@"placeholder_rectangle"]];
- NSMutableAttributedString *nameAttStr = [[NSMutableAttributedString alloc] initWithString:model.name];
- if (model.keywords.count > 1) {
- NSTextAttachment *att = [[NSTextAttachment alloc] init];
- att.image = [UIImage imageNamed:@"ic_blue"];
- att.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
- NSAttributedString *attStr = [NSAttributedString attributedStringWithAttachment:att];
- [nameAttStr appendAttributedString:attStr];
- NSTextAttachment *att1 = [[NSTextAttachment alloc] init];
- att1.image = [UIImage imageNamed:@"ic_red"];
- att1.bounds = CGRectMake(16, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
- NSAttributedString *attStr1 = [NSAttributedString attributedStringWithAttachment:att1];
- [nameAttStr appendAttributedString:attStr1];
- } else if (model.keywords.count == 1) {
- if ([model.keywords[0] isEqualToString:@"礼"]) {
- NSTextAttachment *att1 = [[NSTextAttachment alloc] init];
- att1.image = [UIImage imageNamed:@"ic_red"];
- att1.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
- NSAttributedString *attStr1 = [NSAttributedString attributedStringWithAttachment:att1];
- [nameAttStr appendAttributedString:attStr1];
- } else if ([model.keywords[0] isEqualToString:@"荐"]) {
- NSTextAttachment *att = [[NSTextAttachment alloc] init];
- att.image = [UIImage imageNamed:@"ic_blue"];
- att.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
- NSAttributedString *attStr = [NSAttributedString attributedStringWithAttachment:att];
- [nameAttStr appendAttributedString:attStr];
- }
- }
- cell.nameView.attributedText = nameAttStr;
- cell.adView.text = model.desc;
- NSMutableAttributedString *personsAttStr = [[NSMutableAttributedString alloc] initWithString:@"申请人数:" attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0x666666]}];
- NSAttributedString *personsAtt = [[NSAttributedString alloc] initWithString:model.apply_num attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0xe42a2a]}];
- [personsAttStr appendAttributedString:personsAtt];
- cell.personsView.attributedText = personsAttStr;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsMake(0, LEADING_SPACE, 0, LEADING_SPACE)];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- return 83*SCREEN_MUTI;
- }
- //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- //
- // UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40*SCREEN_MUTI)];
- // header.backgroundColor = [UIColor KXColorWithRed:239 green:239 blue:244];
- //
- // UIImageView *hotImageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, (40-18)/2*SCREEN_MUTI, 18*SCREEN_MUTI, 18*SCREEN_MUTI)];
- // hotImageView.image = [UIImage imageNamed:@"main_hot"];
- // [header addSubview:hotImageView];
- //
- // UILabel *hotLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(hotImageView.frame)+10, 0, 150, 40*SCREEN_MUTI)];
- // hotLabel.text = @"热门信用卡";
- // hotLabel.textColor = [UIColor KXColorWithHex:0x595959];
- // hotLabel.font = FONT_SYS(14*SCREEN_MUTI);
- // [header addSubview:hotLabel];
- //
- // return header;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- //
- // return 40*SCREEN_MUTI;
- //}
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- self.index = indexPath.item;
- KXCreditCardModel *model = self.dataSource[indexPath.row];
- NSString *urlString=[NSString stringWithFormat:@"%@/CreditCard/add",URL];
- [KXHTTP post:urlString params:@{@"product_id":model.ID} success:^(id json) {
- NSString *username = [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
-
- if (!username) {
- KXLittleLogginView *littleView = [[KXLittleLogginView alloc]initWithFrame:self.view.bounds];
- littleView.delegate = self;
- [self.view addSubview:littleView];
- }else{
- [MobClick event:@"creditListClick"];
- KXBaseLinkViewController *webVC = [[KXBaseLinkViewController alloc] init];
- webVC.nameStr = @"申请信用卡";
- webVC.linkString = model.url;
-
- [self.navigationController pushViewController:webVC animated:YES];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- #pragma mark =======================KXLittleLogginViewDelegate================
- - (void)littleLogginViewSuccess
- {
- KXCreditCardModel *model = self.dataSource[self.index];
- NSString *urlString=[NSString stringWithFormat:@"%@/CreditCard/add",URL];
- [KXHTTP post:urlString params:@{@"product_id":model.ID} success:^(id json) {
- KXBaseLinkViewController *webVC = [[KXBaseLinkViewController alloc] init];
- webVC.nameStr = @"申请信用卡";
- webVC.linkString = model.url;
- [self.navigationController pushViewController:webVC animated:YES];
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark lazy loading
- - (NSMutableArray *)dataSource {
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- /*
- #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
|