Brak opisu

KXEventViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. //
  2. // KXEventViewController.m
  3. // CAISHEN
  4. //
  5. // Created by jikaipeng on 2017/8/24.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXEventViewController.h"
  9. #import "KXEventTopView.h"
  10. #import "KXEventCollectionViewCell.h"
  11. #import "KXbodyPriceColumnViewController.h"
  12. #import "KXCalculatePageViewController.h"
  13. #import "KXLittleLogginView.h"
  14. #import "KXFindToolListModel.h"
  15. #import "KXInstallmentViewController.h" //分期计算器
  16. #import "KXCarLoancalViewController.h" // 车贷计算器
  17. #import "KXHouseCalculateViewController.h" //房贷计算器
  18. #import "KXIndividualIncomeViewController.h" //个税计算器
  19. #import "KXBaseLinkViewController.h"
  20. static NSString *collectionHeaderIdenti = @"collectionHeaderIdenti";
  21. static NSString *collectionCellID = @"cellID";
  22. @interface KXEventViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXLittleLogginViewDelegate,UICollectionViewDelegateFlowLayout>
  23. @property (nonatomic, strong) UICollectionView *collectionView;
  24. @property (nonatomic, assign) NSInteger page;
  25. @property (nonatomic ,strong) NSMutableArray *dataSource;
  26. @property (nonatomic,assign) NSInteger index;
  27. @property (nonatomic,strong) NSMutableArray *systemArr;
  28. @property (nonatomic,strong) UIView *headerView;
  29. @property (nonatomic,strong) NSMutableArray *custonArr;
  30. @end
  31. @implementation KXEventViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. [self setupNavBackground];
  35. self.name = @"发现";
  36. self.view.backgroundColor = [UIColor KXColorWithHex:0xf5f4f9];
  37. // 2.0的头
  38. // [self CreateTopView];
  39. [self requestFindCustomData];
  40. [self setUpCollectionView];
  41. [MobClick event:@"FindTab"];
  42. }
  43. #pragma mark - 请求发现页工具列表
  44. - (void)requestFindCustomData{
  45. NSString *url = [NSString stringWithFormat:@"%@/activity/getToolsList",URL];
  46. [KXHTTP get:url params:nil success:^(id json) {
  47. [self.custonArr removeAllObjects];
  48. NSArray *array = [NSArray yy_modelArrayWithClass:[KXFindToolListModel class] json:json];
  49. for (KXFindToolListModel *model in array) {
  50. if ([model.show integerValue] == 1) {
  51. [self.custonArr addObject:model];
  52. }
  53. }
  54. [self setUpHeaderView];
  55. } failure:^(NSError *error) {
  56. [self setUpHeaderView];
  57. }];
  58. }
  59. #pragma mark - getter and setter
  60. - (UICollectionView *)collectionView{
  61. if (!_collectionView) {
  62. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  63. layout.itemSize = CGSizeMake(SCREEN_WIDTH-20, 230);
  64. layout.minimumInteritemSpacing = 6;
  65. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, SCREEN_HEIGHT-NavHeight-TabbarHeight) collectionViewLayout:layout];
  66. _collectionView.showsVerticalScrollIndicator = NO;
  67. }
  68. return _collectionView;
  69. }
  70. -(NSMutableArray *)dataSource
  71. {
  72. if (!_dataSource) {
  73. _dataSource=[[NSMutableArray alloc]init];
  74. }
  75. return _dataSource;
  76. }
  77. #pragma mark - event handle
  78. - (void)tapAction1:(UITapGestureRecognizer *)tapG
  79. {
  80. KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
  81. bodyPriceVC.webString = [NSString stringWithFormat:@"%@/Atesting/?channel_id=%@",CALURL,KXCHANNEL_ID];
  82. bodyPriceVC.titleString = @"身价计算器";
  83. bodyPriceVC.enterSource = @"valueCalculationa";
  84. self.tabBarController.tabBar.hidden = NO;
  85. [self.navigationController pushViewController:bodyPriceVC animated:YES];
  86. }
  87. - (void)tapAction2:(UITapGestureRecognizer *)tapG
  88. {
  89. KXCalculatePageViewController *calculate = [[KXCalculatePageViewController alloc]init];
  90. self.tabBarController.tabBar.hidden = NO;
  91. [self.navigationController pushViewController:calculate animated:YES];
  92. }
  93. - (void)CreateTopView{
  94. NSArray *imageNameArray = @[@"main_event_price",@"main_event_calculator"];
  95. NSArray *titleArray = @[@"身价计算器",@"贷款计算器"];
  96. NSArray *detailArray = @[@"等你来测",@"比价神器"];
  97. UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_MUTI*80)];
  98. backView.backgroundColor = [UIColor KXColorWithHex:0xffe100];
  99. for (NSInteger i = 0; i < 2; i++) {
  100. KXEventTopView *topView = [[KXEventTopView alloc] initWithFrame:CGRectMake(i*(SCREEN_WIDTH-1)/2, 0, (SCREEN_WIDTH-1)/2, SCREEN_MUTI*80)];
  101. topView.imageview.image = [UIImage imageNamed:imageNameArray[i]];
  102. topView.titleLabel.text = titleArray[i];
  103. topView.detaileLabel.text = detailArray[i];
  104. [backView addSubview:topView];
  105. if (i == 0) {
  106. UIView *view = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-1)/2, 10*SCREEN_MUTI, 1, 60*SCREEN_MUTI)];
  107. view.backgroundColor = [UIColor whiteColor];
  108. UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction1:)];
  109. tapG.numberOfTapsRequired = 1;
  110. [topView addGestureRecognizer:tapG];
  111. [backView addSubview:view];
  112. }
  113. else{
  114. UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction2:)];
  115. tapG.numberOfTapsRequired = 1;
  116. [topView addGestureRecognizer:tapG];
  117. }
  118. }
  119. [self.view addSubview:backView];
  120. }
  121. /**
  122. 贷款超市3.0的头
  123. */
  124. - (void)setUpHeaderView{
  125. UIView *topBackView = [[UIView alloc] init];
  126. topBackView.backgroundColor = [UIColor whiteColor];
  127. CGFloat width = (SCREEN_WIDTH-20)/4;
  128. CGFloat height = 95;
  129. NSInteger rank = 4;
  130. for (NSInteger i=0; i<self.systemArr.count; i++) {
  131. UIButton *systemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  132. //Item X轴
  133. CGFloat X = (i % rank) * width;
  134. //Item Y轴
  135. NSUInteger Y = (i / rank) * height;
  136. NSDictionary *dict = self.systemArr[i];
  137. systemBtn.frame = CGRectMake(X, Y, width, height);
  138. [systemBtn setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal];
  139. systemBtn.tag = 1000 + i;
  140. NSDictionary *mutabDict = @{NSFontAttributeName:FONT_SYS(12),NSForegroundColorAttributeName:[UIColor titleColor]};
  141. NSAttributedString *attibute = [[NSAttributedString alloc] initWithString:dict[@"title"] attributes:mutabDict];
  142. [systemBtn setAttributedTitle:attibute forState:UIControlStateNormal];
  143. systemBtn.adjustsImageWhenHighlighted = NO;
  144. [systemBtn addTarget:self action:@selector(topButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  145. [systemBtn setButtonStyle:WSLButtonStyleImageTop spacing:4];
  146. [topBackView addSubview:systemBtn];
  147. }
  148. [self.systemArr addObjectsFromArray:self.custonArr];
  149. for (NSInteger i=5; i<self.systemArr.count; i++) {
  150. UIButton *customBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  151. //Item X轴
  152. CGFloat X = (i % rank) * width;
  153. //Item Y轴
  154. NSUInteger Y = (i / rank) * height;
  155. KXFindToolListModel *model = self.systemArr[i];
  156. customBtn.frame = CGRectMake(X, Y, width, height);
  157. NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:model.icon]];
  158. UIImage *image = [[UIImage alloc] initWithData:imageData];
  159. [customBtn setImage:image forState:UIControlStateNormal];
  160. customBtn.tag = 1000 + i;
  161. NSDictionary *mutabDict = @{NSFontAttributeName:FONT_SYS(12),NSForegroundColorAttributeName:[UIColor titleColor]};
  162. NSAttributedString *attibute = [[NSAttributedString alloc] initWithString:model.name attributes:mutabDict];
  163. [customBtn setAttributedTitle:attibute forState:UIControlStateNormal];
  164. customBtn.adjustsImageWhenHighlighted = NO;
  165. [customBtn addTarget:self action:@selector(topButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  166. [customBtn setButtonStyle:WSLButtonStyleImageTop spacing:4];
  167. [topBackView addSubview:customBtn];
  168. }
  169. UIButton *placeHolderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  170. placeHolderBtn.adjustsImageWhenHighlighted = NO;
  171. //Item X轴
  172. CGFloat X = (self.systemArr.count % rank) * width;
  173. //Item Y轴
  174. NSUInteger Y = (self.systemArr.count / rank) * height;
  175. placeHolderBtn.frame = CGRectMake(X, Y, width, height);
  176. [placeHolderBtn setImage:[UIImage imageNamed:@"find_placeholder"] forState:UIControlStateNormal];
  177. [topBackView addSubview:placeHolderBtn];
  178. topBackView.frame = CGRectMake(0, 0, SCREEN_WIDTH-20, Y+height-10);
  179. topBackView.layer.cornerRadius = 4.f;
  180. self.headerView = topBackView;
  181. [self.collectionView reloadData];
  182. }
  183. #pragma mark - 头部按钮点击方法
  184. - (void)topButtonClick:(UIButton *)button{
  185. switch (button.tag - 1000) {
  186. case 0: //身价计算器
  187. {
  188. [MobClick event:@"priceCalculator"];
  189. KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
  190. bodyPriceVC.webString = [NSString stringWithFormat:@"%@/Atesting/?channel_id=%@",CALURL,KXCHANNEL_ID];
  191. bodyPriceVC.titleString = @"身价计算器";
  192. bodyPriceVC.enterSource = @"valueCalculationa";
  193. self.tabBarController.tabBar.hidden = NO;
  194. [self.navigationController pushViewController:bodyPriceVC animated:YES];
  195. }
  196. break;
  197. case 1: // 分期计算器
  198. {
  199. [MobClick event:@"sectionCalculator"];
  200. KXInstallmentViewController *instalVC = [[KXInstallmentViewController alloc] init];
  201. [self.navigationController pushViewController:instalVC animated:YES];
  202. }
  203. break;
  204. case 2: // 车贷计算器
  205. {
  206. [MobClick event:@"carCalculator"];
  207. KXCarLoancalViewController *carLoanVC = [[KXCarLoancalViewController alloc] init];
  208. [self.navigationController pushViewController:carLoanVC animated:YES];
  209. }
  210. break;
  211. case 3: //房贷计算器
  212. {
  213. [MobClick event:@"houseCalculator"];
  214. KXHouseCalculateViewController *houseCalVC = [[KXHouseCalculateViewController alloc] init];
  215. [self.navigationController pushViewController:houseCalVC animated:YES];
  216. }
  217. break;
  218. case 4: //个税计算器
  219. {
  220. [MobClick event:@"personalTaxCalculator"];
  221. KXIndividualIncomeViewController *incomeVC = [[KXIndividualIncomeViewController alloc] init];
  222. [self.navigationController pushViewController:incomeVC animated:YES];
  223. }
  224. break;
  225. // case 5: //公积金查询
  226. // {
  227. //
  228. // }
  229. // break;
  230. default:
  231. // 跳转到h5
  232. {
  233. KXBaseLinkViewController *lineVC = [[KXBaseLinkViewController alloc] init];
  234. KXFindToolListModel *model = self.systemArr[button.tag-1000];
  235. lineVC.linkString = model.url;
  236. lineVC.nameStr = model.name;
  237. [self.navigationController pushViewController:lineVC animated:YES];
  238. }
  239. break;
  240. }
  241. }
  242. - (void) setUpCollectionView{
  243. //下拉刷新
  244. MJRefreshNormalHeader *header =
  245. [[MJRefreshNormalHeader alloc]init];
  246. [header setRefreshingTarget:self refreshingAction:@selector(refreshWithHeader:)];
  247. self.collectionView.mj_header = header;
  248. [header beginRefreshing];
  249. //上拉加载
  250. MJRefreshAutoNormalFooter *footer=[[MJRefreshAutoNormalFooter alloc]init];
  251. [footer setRefreshingTarget:self refreshingAction:@selector(refreshFooter:)];
  252. self.collectionView.mj_footer=footer;
  253. _collectionView.backgroundColor = [UIColor KXColorWithHex:0xf5f4f9];
  254. [_collectionView registerClass:[KXEventCollectionViewCell class] forCellWithReuseIdentifier:collectionCellID];
  255. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionHeaderIdenti];
  256. _collectionView.dataSource = self;
  257. _collectionView.delegate = self;
  258. _collectionView.layer.cornerRadius = 4.f;
  259. _collectionView.layer.masksToBounds = YES;
  260. [self.view addSubview:self.collectionView];
  261. header.stateLabel.font = FONT_SYS(14);
  262. header.stateLabel.textColor=[UIColor detailTitleColor];
  263. header.lastUpdatedTimeLabel.font=FONT_SYS(14);
  264. header.lastUpdatedTimeLabel.textColor=[UIColor detailTitleColor];
  265. footer.stateLabel.textColor=[UIColor detailTitleColor];
  266. }
  267. #pragma mark 下拉刷新和上拉加载
  268. -(void)refreshWithHeader:(MJRefreshHeader *)header
  269. {
  270. self.page=1;
  271. [self requestDataWithPage:self.page];
  272. }
  273. -(void)refreshFooter:(MJRefreshAutoFooter *)footer
  274. {
  275. self.page++;
  276. [self requestDataWithPage:self.page];
  277. }
  278. -(void)requestDataWithPage:(NSInteger)page
  279. {
  280. NSString *urlString=[NSString stringWithFormat:@"%@/activity/getActivityList",URL];
  281. [KXHTTP post:urlString params:@{@"page":@(page)} success:^(id json) {
  282. if (self.page==1) {
  283. [self.dataSource removeAllObjects];
  284. }
  285. NSArray *array=[NSArray yy_modelArrayWithClass:[KXEventModel class] json:json[@"data"]];
  286. for (KXEventModel *model in array) {
  287. [self.dataSource addObject:model];
  288. }
  289. if (array.count < 10) {
  290. [_collectionView.mj_header endRefreshing];
  291. [_collectionView.mj_footer endRefreshing];
  292. [_collectionView.mj_footer endRefreshingWithNoMoreData];
  293. }else{
  294. [_collectionView.mj_header endRefreshing];
  295. [_collectionView.mj_footer endRefreshing];
  296. }
  297. [_collectionView reloadData];
  298. } failure:^(NSError *error) {
  299. }];
  300. }
  301. #pragma mark collectionview datasource
  302. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  303. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  304. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:collectionHeaderIdenti forIndexPath:indexPath];
  305. [headerView addSubview:self.headerView];
  306. return headerView;
  307. }
  308. return nil;
  309. }
  310. - (CGSize )collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  311. NSUInteger Y = (self.systemArr.count / 4) * 95 + 95;
  312. return CGSizeMake(SCREEN_WIDTH-20, Y);
  313. }
  314. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  315. return 1;
  316. }
  317. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  318. return self.dataSource.count;
  319. }
  320. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  321. KXEventCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
  322. cell.backgroundColor = [UIColor whiteColor];
  323. cell.layer.cornerRadius = 4.f;
  324. cell.model = self.dataSource[indexPath.row];
  325. return cell;
  326. }
  327. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  328. {
  329. self.index = indexPath.item;
  330. NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
  331. [KXHTTP post:urlString params:nil success:^(id json) {
  332. NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
  333. if (!username) {
  334. KXLittleLogginView *littleView = [[KXLittleLogginView alloc]initWithFrame:self.view.bounds];
  335. littleView.delegate = self;
  336. [self.view addSubview:littleView];
  337. }else{
  338. [MobClick event:@"findListClick"];
  339. KXEventModel *model = self.dataSource[indexPath.row];
  340. KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
  341. bodyPriceVC.webString = [NSString stringWithFormat:@"%@&channel_id=%@",model.activity_url,KXCHANNEL_ID];
  342. self.tabBarController.tabBar.hidden = NO;
  343. bodyPriceVC.titleString = model.title;
  344. bodyPriceVC.enterSource = @"activityList";
  345. [self.navigationController pushViewController:bodyPriceVC animated:YES];
  346. }
  347. } failure:^(NSError *error) {
  348. }];
  349. }
  350. - (NSMutableArray *)systemArr{
  351. if (!_systemArr) {
  352. _systemArr = [[NSMutableArray alloc] initWithArray: @[@{@"image":@"find_bodyPrice",@"title":@"身价计算器"},@{@"image":@"find_stages",@"title":@"分期计算器"},@{@"image":@"find_car",@"title":@"车贷计算器"},@{@"image":@"find_house",@"title":@"房贷计算器"},@{@"image":@"find_personTax",@"title":@"个税计算器"}]];
  353. }
  354. return _systemArr;
  355. }
  356. - (NSMutableArray *)custonArr{
  357. if (!_custonArr) {
  358. _custonArr = [NSMutableArray array];
  359. }
  360. return _custonArr;
  361. }
  362. #pragma mark =======================KXLittleLogginViewDelegate================
  363. - (void)littleLogginViewSuccess
  364. {
  365. KXEventModel *model = self.dataSource[self.index];
  366. KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
  367. bodyPriceVC.webString = [NSString stringWithFormat:@"%@&channel_id=%@",model.activity_url,KXCHANNEL_ID];
  368. self.tabBarController.tabBar.hidden = NO;
  369. bodyPriceVC.titleString = model.title;
  370. [self.navigationController pushViewController:bodyPriceVC animated:YES];
  371. }
  372. - (void)didReceiveMemoryWarning {
  373. [super didReceiveMemoryWarning];
  374. // Dispose of any resources that can be recreated.
  375. }
  376. @end