ServiceRecommendViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // ServiceRecommendViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/21.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "ServiceRecommendViewController.h"
  9. #import "ServiceRecommendCell.h"
  10. #import "RecommendModel.h"
  11. #import "HighidentificationViewController.h"
  12. #import "YBPopupMenu.h"
  13. #import "MyattentionViewController.h"
  14. #import "MyOrderViewController.h"
  15. #import "AchievementsReleaseViewController.h"
  16. #import "ReleaserequirementsViewController.h"
  17. #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"]
  18. #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"]
  19. @interface ServiceRecommendViewController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate>{
  20. UITableView *newtableView;
  21. NSMutableArray *dataArray;
  22. int pageIndex;
  23. int pageSize;
  24. int pageNumber;
  25. UIView *showView;
  26. }
  27. @property (strong ,nonatomic) UIButton * registerAccount;
  28. @end
  29. @implementation ServiceRecommendViewController
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. [self setNavTitle:@"推荐"];
  33. [self dataInitialization];
  34. [self RecommendNetworkrequest:nil];
  35. [self loadsview];
  36. [self addRefreshing];
  37. // Do any additional setup after loading the view.
  38. }
  39. #pragma mark ----------推荐网络请求--------
  40. - (void)RecommendNetworkrequest:(id)object {
  41. int pageNumberIndex=1;
  42. if (!object) {
  43. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  44. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  45. pageNumberIndex = 1;
  46. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  47. pageNumberIndex = pageNumber+1;
  48. }
  49. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  50. [parameters safeSetObject:@(pageSize) forKey:@"pSize"];
  51. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pNo"];
  52. [NetworkRequestManager requestGetWithInterfacePrefix:JT_recommendProjectList parameters:parameters onSuccess:^(id requestData) {
  53. [self dismiss:object];
  54. if ([requestData[@"error"] count] !=0) {
  55. for (NSDictionary *dic in requestData[@"error"]) {
  56. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  57. }
  58. }else{
  59. pageNumber = pageNumberIndex;
  60. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  61. [dataArray removeAllObjects];
  62. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  63. NSMutableArray *arr = requestData[@"data"][@"list"];
  64. if ([arr count]<=0) {
  65. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  66. }
  67. }
  68. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  69. RecommendModel *model = [[RecommendModel alloc] initWithDictionary:dic error:nil];
  70. [dataArray addObject:model];
  71. }
  72. //查询不到类型底图
  73. if (dataArray.count<=0) {
  74. [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"暂无推荐~" buttonTitle:nil imageString:NewNoDataErrorImage];
  75. }else {
  76. [self hideReloadingview];
  77. [newtableView reloadData];
  78. }
  79. }
  80. } onFailure:^{
  81. [self dismiss:object];
  82. }];
  83. }
  84. #pragma mark - 上拉下拉初始化
  85. - (void)addRefreshing
  86. {
  87. __weak typeof(self) weakSelf = self;
  88. __weak UITableView *tableView = newtableView;
  89. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  90. if ([NetworkRequestManager connectedToNetwork]) {
  91. [weakSelf RecommendNetworkrequest:tableView.mj_header];
  92. }else{
  93. [tableView.mj_header endRefreshing];
  94. }
  95. }];
  96. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  97. if ([NetworkRequestManager connectedToNetwork]) {
  98. [weakSelf RecommendNetworkrequest:tableView.mj_footer];
  99. }else{
  100. [tableView.mj_footer endRefreshing];
  101. }
  102. }];
  103. }
  104. - (void)dismiss:(id)object
  105. {
  106. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  107. __weak UITableView *newvc = newtableView;
  108. [newvc.mj_header endRefreshing];
  109. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  110. __weak UITableView *newvc = newtableView;
  111. [newvc.mj_footer endRefreshing];
  112. }else {
  113. [MBProgressHUD hideHUDForView:self.view];
  114. }
  115. }
  116. - (void)dataInitialization {
  117. dataArray = NewMutableArrayInit;
  118. pageIndex = 1;
  119. pageSize = 10;
  120. pageNumber = 1;
  121. }
  122. - (void)loadsview {
  123. [self.navgationBar addSubview:self.registerAccount];
  124. _registerAccount.sd_layout
  125. .widthIs(30)
  126. .rightSpaceToView(self.navgationBar, 10)
  127. .heightIs(44)
  128. .topSpaceToView(self.navgationBar, 18);
  129. [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]];
  130. newtableView.separatorStyle = NO;
  131. }
  132. #pragma mark-------------------------UITableView------------------------------------
  133. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  134. {
  135. return 1;
  136. }
  137. //返回每段行数
  138. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  139. {
  140. return dataArray.count;
  141. }
  142. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  143. {
  144. static NSString *Cell = @"Cell";
  145. ServiceRecommendCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  146. if (cell == nil) {
  147. cell = [[ServiceRecommendCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  148. }
  149. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  150. cell.accessoryType = UITableViewCellAccessoryNone;
  151. if (dataArray.count>0) {
  152. [cell assignment:dataArray[indexPath.row]];
  153. }
  154. return cell;
  155. }
  156. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  157. {
  158. return fitScreenWidth(132)+10;
  159. }
  160. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  161. HighidentificationViewController *vc = [[HighidentificationViewController alloc] init];
  162. RecommendModel *model = dataArray[indexPath.row];
  163. vc.ID = model.ID;
  164. NewPushViewController(vc);
  165. }
  166. // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
  167. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  168. return CGFLOAT_MIN;
  169. }
  170. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  171. return CGFLOAT_MIN;
  172. }
  173. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  174. return [[UIView alloc] init];
  175. }
  176. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  177. return [[UIView alloc] init];
  178. }
  179. - (UIButton *)registerAccount
  180. {
  181. if (!_registerAccount)
  182. {
  183. _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom];
  184. // [_registerAccount setTitle:@"" forState:UIControlStateNormal];
  185. [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal];
  186. [_registerAccount setBackgroundColor:[UIColor clearColor]];
  187. [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  188. [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]];
  189. [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside];
  190. // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44];
  191. [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal];
  192. }
  193. return _registerAccount;
  194. }
  195. - (void)touchRegister:(UIButton *)sender{
  196. [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self];
  197. }
  198. #pragma mark - YBPopupMenuDelegate
  199. - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
  200. {
  201. NSLog(@"点击了 %@ 选项",TITLES[index]);
  202. if (index == 0) {
  203. if ([UserHelper isLogin]) {
  204. NSLog(@"%@",@"已登录");
  205. MyattentionViewController *vc = [[MyattentionViewController alloc] init];
  206. NewPushViewController(vc);
  207. }else{
  208. NSLog(@"%@",@"未登录");
  209. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  210. [vc setLoginSuccess:^(NSString *string) {
  211. NewPopViewController;
  212. }];
  213. NewPushViewController(vc);
  214. }
  215. }else if (index == 1){
  216. if ([UserHelper isLogin]) {
  217. NSLog(@"%@",@"已登录");
  218. MyOrderViewController*vc = [[MyOrderViewController alloc] init];
  219. NewPushViewController(vc);
  220. }else{
  221. NSLog(@"%@",@"未登录");
  222. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  223. [vc setLoginSuccess:^(NSString *string) {
  224. NewPopViewController;
  225. }];
  226. NewPushViewController(vc);
  227. }
  228. }else if (index == 2) {
  229. if ([UserHelper isLogin]) {
  230. NSLog(@"%@",@"已登录");
  231. AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init];
  232. NewPushViewController(vc);
  233. }else{
  234. NSLog(@"%@",@"未登录");
  235. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  236. [vc setLoginSuccess:^(NSString *string) {
  237. NewPopViewController;
  238. }];
  239. NewPushViewController(vc);
  240. }
  241. }else if (index == 3){
  242. if ([UserHelper isLogin]) {
  243. NSLog(@"%@",@"已登录");
  244. ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init];
  245. NewPushViewController(vc);
  246. }else{
  247. NSLog(@"%@",@"未登录");
  248. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  249. [vc setLoginSuccess:^(NSString *string) {
  250. NewPopViewController;
  251. }];
  252. NewPushViewController(vc);
  253. }
  254. }
  255. }
  256. - (void)didReceiveMemoryWarning {
  257. [super didReceiveMemoryWarning];
  258. // Dispose of any resources that can be recreated.
  259. }
  260. /*
  261. #pragma mark - Navigation
  262. // In a storyboard-based application, you will often want to do a little preparation before navigation
  263. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  264. // Get the new view controller using [segue destinationViewController].
  265. // Pass the selected object to the new view controller.
  266. }
  267. */
  268. @end