ScienceAchievementsViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. //
  2. // ScienceAchievementsViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/12.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "ScienceAchievementsViewController.h"
  9. #import "SQFiltrateView.h"
  10. #import "ScienceachievementsCell.h"
  11. #import "AchievementsdetailViewController.h"
  12. #import "AchievementslistModel.h"
  13. #import "YBPopupMenu.h"
  14. #import "MyattentionViewController.h"
  15. #import "MyOrderViewController.h"
  16. #import "AchievementsReleaseViewController.h"
  17. #import "ReleaserequirementsViewController.h"
  18. #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"]
  19. #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"]
  20. @interface ScienceAchievementsViewController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate>{
  21. UITableView *newtableView;
  22. NSMutableArray *dataArray;
  23. SQFiltrateView *filtrateView;
  24. NSMutableArray *industrytypeArray;//行业类型
  25. NSString *fieldA;//行业类型ID
  26. NSString *category;
  27. int pageNo;
  28. UIView *showView;//无数据UI
  29. SQFiltrateItem *item1;
  30. }
  31. @property (strong ,nonatomic) UIButton * registerAccount;
  32. @end
  33. @implementation ScienceAchievementsViewController
  34. - (void)viewWillDisappear:(BOOL)animated {
  35. [super viewWillDisappear:animated];
  36. [filtrateView hideAllItemView];
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self setNavTitle:@"科技成果"];
  41. [self dataInitialization];
  42. [self IndustrytypeNetworkrequest];
  43. [self AchievementListNetworkrequest:nil];
  44. [self loadsView];
  45. // Do any additional setup after loading the view.
  46. }
  47. #pragma mark -----行业类型数组网络请求------
  48. - (void)IndustrytypeNetworkrequest {
  49. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  50. [NetworkRequestManager requestGetWithInterfacePrefix:JT_industryList parameters:parameters onSuccess:^(id requestData) {
  51. NSLog(@"服务器返回数据:%@",requestData);
  52. if ([requestData[@"error"] count] !=0) {
  53. for (NSDictionary *dic in requestData[@"error"]) {
  54. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  55. }
  56. }else{
  57. for (NSDictionary *dic in requestData[@"data"]) {
  58. [industrytypeArray addObject:dic];
  59. }
  60. NSDictionary *dic = @{@"id":@"",@"name":@"全部"};
  61. [industrytypeArray addObject:dic];
  62. [self classificationview];
  63. [filtrateView setNeedsLayout];//强行刷新view;
  64. }
  65. } onFailure:^{
  66. }];
  67. }
  68. #pragma mark -----科技成果列表网络请求------
  69. - (void)AchievementListNetworkrequest:(id)object {
  70. int pageNumberIndex=1;
  71. if (!object) {
  72. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  73. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  74. pageNumberIndex = 1;
  75. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  76. pageNumberIndex = pageNo+1;
  77. }
  78. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  79. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码
  80. [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数
  81. [parameters safeSetObject:@"" forKey:@"ownerId"];//所有人ID
  82. [parameters safeSetObject:fieldA forKey:@"fieldA"];
  83. //技术类型需要搞俩个参数
  84. [parameters safeSetObject:category forKey:@"category"];
  85. [NetworkRequestManager requestGetWithInterfacePrefix:JT_achievementList parameters:parameters onSuccess:^(id requestData) {
  86. [self dismiss:object];
  87. NSLog(@"服务器返回数据:%@",requestData);
  88. if ([requestData[@"error"] count] !=0) {
  89. for (NSDictionary *dic in requestData[@"error"]) {
  90. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  91. }
  92. }else{
  93. pageNo = pageNumberIndex;
  94. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组
  95. [dataArray removeAllObjects];
  96. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉
  97. if ([requestData[@"data"][@"list"] count]<=0) {
  98. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  99. return;
  100. }
  101. }else{//选择类型要清空数组
  102. [dataArray removeAllObjects];
  103. }
  104. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  105. AchievementslistModel *model = [[AchievementslistModel alloc] initWithDictionary:dic error:nil];
  106. [dataArray addObject:model];
  107. }
  108. //查询不到类型底图
  109. if (dataArray.count<=0) {
  110. [self addErrorLoadingFrame:CGRectMake(0, NavHeader+44, newtableView.width, newtableView.height) title:@"暂时没有您查询的成果类型~" buttonTitle:nil imageString:NewNoDataErrorImage];
  111. }else {
  112. [self hideReloadingview];
  113. [newtableView reloadData];
  114. }
  115. }
  116. } onFailure:^{
  117. [self dismiss:object];
  118. }];
  119. }
  120. - (void)dataInitialization {
  121. fieldA = @"";
  122. category = @"";
  123. pageNo = 1;
  124. dataArray = NewMutableArrayInit;
  125. industrytypeArray = NewMutableArrayInit;
  126. }
  127. #pragma mark -------分类-------------
  128. - (void)classificationview{
  129. UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, 1)];
  130. line.backgroundColor = NewLineGrayColor;
  131. [self.view addSubview:line];
  132. item1 = [[SQFiltrateItem alloc]init];
  133. item1.listType = OptionListType_Tag;
  134. item1.numberType = OptionNumberType_Single;
  135. NSMutableArray *arr = NewMutableArrayInit;
  136. for (NSDictionary *dic in industrytypeArray) {
  137. [arr addObject:dic[@"name"]];
  138. }
  139. item1.optionData = arr;
  140. item1.title = @"行业类型";
  141. SQFiltrateItem *item2 = [[SQFiltrateItem alloc]init];
  142. item2.listType = OptionListType_Tag;
  143. item2.numberType = OptionNumberType_Single;
  144. /*
  145. 0--专利, 1--软著, 2--项目, 3--版权, 4--工业设计, 5--配方, 6--非标
  146. */
  147. item2.optionData = @[@"专利",@"软著",@"项目",@"版权",@"工业设计",@"配方",@"非标",@"全部"];
  148. item2.title = @"技术类型";
  149. filtrateView = [[SQFiltrateView alloc]initWithFrame:CGRectMake(0, NavHeader+1, SCREEN_WIDTH, 44)
  150. filtrateItems:@[item1,item2]];
  151. [filtrateView touchBlock:^(SQFiltrateView * _Nonnull view, SQFiltrateItem * _Nonnull item) {
  152. NSLog(@"%@:%@",item.title,item.choseSet);
  153. if ([item.title isEqualToString:@"行业类型"]) {
  154. NSMutableArray *arr = NewMutableArrayInit;
  155. for (NSDictionary *dic in industrytypeArray) {
  156. [arr addObject:dic[@"id"]];
  157. }
  158. NSSet *luo = [NSSet new];
  159. if (!item.choseSet.count) {//如果什么都不选
  160. fieldA = @"";
  161. }else{
  162. for (luo in item.choseSet) {
  163. NSString *str = [NSString stringWithFormat:@"%@",luo];
  164. NSString *Id = [arr objectAtIndex:[str integerValue]];
  165. fieldA = Id;
  166. }
  167. }
  168. }else{
  169. if (!item.choseSet.count) {//如果什么都不选
  170. category = @"";
  171. }else{
  172. for (NSSet *luo in item.choseSet) {
  173. NSString *str = [NSString stringWithFormat:@"%@",luo];
  174. if ([str isEqualToString:@"7"]) {
  175. category = @"";
  176. }else{
  177. category = str;
  178. }
  179. }
  180. }
  181. }
  182. [self AchievementListNetworkrequest:nil];
  183. }];
  184. [self.view addSubview:filtrateView];
  185. }
  186. #pragma mark -----加载界面-------
  187. - (void)loadsView{
  188. [self.navgationBar addSubview:self.registerAccount];
  189. _registerAccount.sd_layout
  190. .widthIs(30)
  191. .rightSpaceToView(self.navgationBar, 10)
  192. .heightIs(44)
  193. .topSpaceToView(self.navgationBar, 18);
  194. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+44, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-44) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  195. newtableView.separatorStyle = NO;
  196. [self addRefreshing];
  197. }
  198. #pragma mark-------------------------UITableView------------------------------------
  199. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  200. {
  201. return 1;
  202. }
  203. //返回每段行数
  204. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  205. {
  206. return dataArray.count;
  207. }
  208. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  209. {
  210. static NSString *Cell = @"Cell";
  211. ScienceachievementsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  212. if (cell == nil) {
  213. cell = [[ScienceachievementsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  214. }
  215. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  216. cell.accessoryType = UITableViewCellAccessoryNone;
  217. if (dataArray.count>0) {
  218. [cell assignment:dataArray[indexPath.row]];
  219. }
  220. return cell;
  221. }
  222. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  223. {
  224. return 132;
  225. }
  226. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  227. AchievementsdetailViewController *vc = [[AchievementsdetailViewController alloc] init];
  228. AchievementslistModel *model = dataArray[indexPath.row];
  229. vc.ID = model.ID;
  230. NewPushViewController(vc);
  231. }
  232. // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
  233. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  234. return CGFLOAT_MIN;
  235. }
  236. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  237. return CGFLOAT_MIN;
  238. }
  239. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  240. return [[UIView alloc] init];
  241. }
  242. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  243. return [[UIView alloc] init];
  244. }
  245. #pragma mark - 上拉下拉初始化
  246. - (void)addRefreshing
  247. {
  248. __weak typeof(self) weakSelf = self;
  249. __weak UITableView *newvc = newtableView;
  250. newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  251. if ([NetworkRequestManager connectedToNetwork]) {
  252. [weakSelf AchievementListNetworkrequest:newvc.mj_header];
  253. }else{
  254. [newvc.mj_header endRefreshing];
  255. }
  256. }];
  257. newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  258. if ([NetworkRequestManager connectedToNetwork]) {
  259. [weakSelf AchievementListNetworkrequest:newvc.mj_footer];
  260. }else{
  261. [newvc.mj_footer endRefreshing];
  262. }
  263. }];
  264. }
  265. - (void)dismiss:(id)object
  266. {
  267. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  268. __weak UITableView *newvc = newtableView;
  269. [newvc.mj_header endRefreshing];
  270. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  271. __weak UITableView *newvc = newtableView;
  272. [newvc.mj_footer endRefreshing];
  273. }else {
  274. [MBProgressHUD hideHUDForView:self.view];
  275. }
  276. }
  277. //#pragma mark - 无数据UI展示
  278. //- (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  279. //{
  280. // if(!showView)
  281. // {
  282. // [newtableView addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  283. // [showView setHidden:NO];
  284. // [showView setBackgroundColor:NewGroupTableViewBackgroundColor];
  285. //
  286. // UIImage *noimg = [UIImage imageNamed:image];
  287. // UIImageView *tempIcon = [[UIImageView alloc]initWithImage:noimg];
  288. // [showView addSubview:tempIcon];
  289. // tempIcon.sd_layout
  290. // .leftSpaceToView(showView, (showView.width/2)-(noimg.size.height/2))
  291. // .topSpaceToView(showView, (showView.height/2)-(noimg.size.height/2+20))
  292. // .widthIs(noimg.size.width)
  293. // .heightIs(noimg.size.height);
  294. //
  295. // UILabel *tipLab = [UILabel new];
  296. // [showView addSubview:tipLab];
  297. // [tipLab setText:text];
  298. // [tipLab setTextAlignment:NSTextAlignmentCenter];
  299. // [tipLab setTextColor:NewNoDataColor];
  300. // [tipLab setBackgroundColor:NewClearColor];
  301. // [tipLab setFont:NewAutoFont(12.0)];
  302. // tipLab.sd_layout
  303. // .leftEqualToView(showView)
  304. // .rightEqualToView(showView)
  305. // .topSpaceToView(tempIcon,0)
  306. // .heightIs(20.0);
  307. //
  308. // }
  309. //
  310. // [UIView beginAnimations:@"ShowArrow" context:nil];
  311. //
  312. // [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  313. //
  314. // [UIView setAnimationDuration:0.25f];
  315. //
  316. // [UIView setAnimationDelegate:self];
  317. // [showView setAlpha:1.0f];
  318. // [UIView commitAnimations];
  319. //
  320. //}
  321. - (UIButton *)registerAccount
  322. {
  323. if (!_registerAccount)
  324. {
  325. _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom];
  326. // [_registerAccount setTitle:@"" forState:UIControlStateNormal];
  327. [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal];
  328. [_registerAccount setBackgroundColor:[UIColor clearColor]];
  329. [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  330. [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]];
  331. [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside];
  332. // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44];
  333. [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal];
  334. }
  335. return _registerAccount;
  336. }
  337. - (void)touchRegister:(UIButton *)sender{
  338. [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self];
  339. }
  340. #pragma mark - YBPopupMenuDelegate
  341. - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
  342. {
  343. NSLog(@"点击了 %@ 选项",TITLES[index]);
  344. if (index == 0) {
  345. if ([UserHelper isLogin]) {
  346. NSLog(@"%@",@"已登录");
  347. MyattentionViewController *vc = [[MyattentionViewController alloc] init];
  348. NewPushViewController(vc);
  349. }else{
  350. NSLog(@"%@",@"未登录");
  351. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  352. [vc setLoginSuccess:^(NSString *string) {
  353. NewPopViewController;
  354. }];
  355. NewPushViewController(vc);
  356. }
  357. }else if (index == 1){
  358. if ([UserHelper isLogin]) {
  359. NSLog(@"%@",@"已登录");
  360. MyOrderViewController*vc = [[MyOrderViewController alloc] init];
  361. NewPushViewController(vc);
  362. }else{
  363. NSLog(@"%@",@"未登录");
  364. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  365. [vc setLoginSuccess:^(NSString *string) {
  366. NewPopViewController;
  367. }];
  368. NewPushViewController(vc);
  369. }
  370. }else if (index == 2) {
  371. if ([UserHelper isLogin]) {
  372. NSLog(@"%@",@"已登录");
  373. AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init];
  374. NewPushViewController(vc);
  375. }else{
  376. NSLog(@"%@",@"未登录");
  377. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  378. [vc setLoginSuccess:^(NSString *string) {
  379. NewPopViewController;
  380. }];
  381. NewPushViewController(vc);
  382. }
  383. }else if (index == 3){
  384. if ([UserHelper isLogin]) {
  385. NSLog(@"%@",@"已登录");
  386. ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init];
  387. NewPushViewController(vc);
  388. }else{
  389. NSLog(@"%@",@"未登录");
  390. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  391. [vc setLoginSuccess:^(NSString *string) {
  392. NewPopViewController;
  393. }];
  394. NewPushViewController(vc);
  395. }
  396. }
  397. }
  398. - (void)didReceiveMemoryWarning {
  399. [super didReceiveMemoryWarning];
  400. // Dispose of any resources that can be recreated.
  401. }
  402. /*
  403. #pragma mark - Navigation
  404. // In a storyboard-based application, you will often want to do a little preparation before navigation
  405. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  406. // Get the new view controller using [segue destinationViewController].
  407. // Pass the selected object to the new view controller.
  408. }
  409. */
  410. @end