| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- //
- // ServiceRecommendViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2017/12/21.
- // Copyright © 2017年 罗云飞. All rights reserved.
- //
- #import "ServiceRecommendViewController.h"
- #import "ServiceRecommendCell.h"
- #import "RecommendModel.h"
- #import "HighidentificationViewController.h"
- #import "YBPopupMenu.h"
- #import "MyattentionViewController.h"
- #import "MyOrderViewController.h"
- #import "AchievementsReleaseViewController.h"
- #import "ReleaserequirementsViewController.h"
- #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"]
- #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"]
- @interface ServiceRecommendViewController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate>{
- UITableView *newtableView;
- NSMutableArray *dataArray;
- int pageIndex;
- int pageSize;
- int pageNumber;
- UIView *showView;
- }
- @property (strong ,nonatomic) UIButton * registerAccount;
- @end
- @implementation ServiceRecommendViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"推荐"];
- [self dataInitialization];
- [self RecommendNetworkrequest:nil];
- [self loadsview];
- [self addRefreshing];
- // Do any additional setup after loading the view.
- }
- #pragma mark ----------推荐网络请求--------
- - (void)RecommendNetworkrequest:(id)object {
- int pageNumberIndex=1;
-
- if (!object) {
- [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
- }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
- pageNumberIndex = 1;
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- pageNumberIndex = pageNumber+1;
- }
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:@(pageSize) forKey:@"pSize"];
- [parameters safeSetObject:@(pageNumberIndex) forKey:@"pNo"];
- [NetworkRequestManager requestGetWithInterfacePrefix:JT_recommendProjectList parameters:parameters onSuccess:^(id requestData) {
- [self dismiss:object];
- if ([requestData[@"error"] count] !=0) {
- for (NSDictionary *dic in requestData[@"error"]) {
- [MBProgressHUD showError:dic[@"message"] toView:self.view];
- }
- }else{
- pageNumber = pageNumberIndex;
- if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
- [dataArray removeAllObjects];
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- NSMutableArray *arr = requestData[@"data"][@"list"];
- if ([arr count]<=0) {
- [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
- }
- }
- for (NSDictionary *dic in requestData[@"data"][@"list"]) {
- RecommendModel *model = [[RecommendModel alloc] initWithDictionary:dic error:nil];
- [dataArray addObject:model];
- }
- //查询不到类型底图
- if (dataArray.count<=0) {
- [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"暂无推荐~" buttonTitle:nil imageString:NewNoDataErrorImage];
- }else {
- [self hideReloadingview];
- [newtableView reloadData];
- }
- }
- } onFailure:^{
- [self dismiss:object];
- }];
- }
- #pragma mark - 上拉下拉初始化
- - (void)addRefreshing
- {
-
- __weak typeof(self) weakSelf = self;
- __weak UITableView *tableView = newtableView;
- tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
- [weakSelf RecommendNetworkrequest:tableView.mj_header];
-
- }else{
- [tableView.mj_header endRefreshing];
- }
- }];
-
- tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
-
- [weakSelf RecommendNetworkrequest:tableView.mj_footer];
-
- }else{
- [tableView.mj_footer endRefreshing];
- }
- }];
- }
- - (void)dismiss:(id)object
- {
- if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_header endRefreshing];
-
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_footer endRefreshing];
-
- }else {
- [MBProgressHUD hideHUDForView:self.view];
- }
- }
- - (void)dataInitialization {
- dataArray = NewMutableArrayInit;
- pageIndex = 1;
- pageSize = 10;
- pageNumber = 1;
- }
- - (void)loadsview {
- [self.navgationBar addSubview:self.registerAccount];
- _registerAccount.sd_layout
- .widthIs(30)
- .rightSpaceToView(self.navgationBar, 10)
- .heightIs(44)
- .topSpaceToView(self.navgationBar, 18);
- [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
- newtableView.separatorStyle = NO;
- }
- #pragma mark-------------------------UITableView------------------------------------
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- //返回每段行数
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return dataArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *Cell = @"Cell";
- ServiceRecommendCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[ServiceRecommendCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- if (dataArray.count>0) {
- [cell assignment:dataArray[indexPath.row]];
- }
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return fitScreenWidth(132)+10;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- HighidentificationViewController *vc = [[HighidentificationViewController alloc] init];
- RecommendModel *model = dataArray[indexPath.row];
- vc.ID = model.ID;
- NewPushViewController(vc);
- }
- // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- - (UIButton *)registerAccount
- {
- if (!_registerAccount)
- {
- _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom];
- // [_registerAccount setTitle:@"" forState:UIControlStateNormal];
- [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal];
- [_registerAccount setBackgroundColor:[UIColor clearColor]];
- [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
- [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]];
- [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside];
- // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44];
- [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal];
- }
- return _registerAccount;
- }
- - (void)touchRegister:(UIButton *)sender{
- [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self];
-
- }
- #pragma mark - YBPopupMenuDelegate
- - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
- {
- NSLog(@"点击了 %@ 选项",TITLES[index]);
- if (index == 0) {
- if ([UserHelper isLogin]) {
- NSLog(@"%@",@"已登录");
- MyattentionViewController *vc = [[MyattentionViewController alloc] init];
- NewPushViewController(vc);
- }else{
- NSLog(@"%@",@"未登录");
- NewLoginViewController *vc = [[NewLoginViewController alloc] init];
- [vc setLoginSuccess:^(NSString *string) {
- NewPopViewController;
- }];
- NewPushViewController(vc);
- }
- }else if (index == 1){
- if ([UserHelper isLogin]) {
- NSLog(@"%@",@"已登录");
- MyOrderViewController*vc = [[MyOrderViewController alloc] init];
- NewPushViewController(vc);
- }else{
- NSLog(@"%@",@"未登录");
- NewLoginViewController *vc = [[NewLoginViewController alloc] init];
- [vc setLoginSuccess:^(NSString *string) {
- NewPopViewController;
- }];
- NewPushViewController(vc);
- }
- }else if (index == 2) {
- if ([UserHelper isLogin]) {
- NSLog(@"%@",@"已登录");
- AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init];
- NewPushViewController(vc);
- }else{
- NSLog(@"%@",@"未登录");
- NewLoginViewController *vc = [[NewLoginViewController alloc] init];
- [vc setLoginSuccess:^(NSString *string) {
- NewPopViewController;
- }];
- NewPushViewController(vc);
- }
- }else if (index == 3){
- if ([UserHelper isLogin]) {
- NSLog(@"%@",@"已登录");
- ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init];
- NewPushViewController(vc);
- }else{
- NSLog(@"%@",@"未登录");
- NewLoginViewController *vc = [[NewLoginViewController alloc] init];
- [vc setLoginSuccess:^(NSString *string) {
- NewPopViewController;
- }];
- NewPushViewController(vc);
- }
- }
- }
- - (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
|