SciencedemandViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //
  2. // SciencedemandViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/12.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "SciencedemandViewController.h"
  9. #import "SQFiltrateView.h"
  10. #import "SciencedemandCell.h"
  11. #import "DemanddetailViewController.h"
  12. #import "Demandmodel.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 SciencedemandViewController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate>{
  21. UITableView *newtableView;
  22. NSMutableArray *dataArray;
  23. SQFiltrateView *filtrateView;
  24. NSMutableArray *industrytypeArray;
  25. int pageNo;
  26. NSString *dataCategory;
  27. NSString *fieldA;
  28. }
  29. @property (strong ,nonatomic) UIButton * registerAccount;
  30. @end
  31. @implementation SciencedemandViewController
  32. - (void)viewWillDisappear:(BOOL)animated {
  33. [super viewWillDisappear:animated];
  34. [filtrateView hideAllItemView];
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. [self setNavTitle:@"科技需求"];
  39. [self dataInitialization];
  40. [self IndustrytypeNetworkrequest];
  41. [self demandNetworkrequest:nil];
  42. [self loadsView];
  43. // Do any additional setup after loading the view.
  44. }
  45. - (void)demandNetworkrequest:(id)object {
  46. int pageNumberIndex=1;
  47. if (!object) {
  48. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  49. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  50. pageNumberIndex = 1;
  51. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  52. pageNumberIndex = pageNo+1;
  53. }
  54. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  55. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码
  56. [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数
  57. [parameters safeSetObject:fieldA forKey:@"industryCategoryA"];//行业类型
  58. [parameters safeSetObject:dataCategory forKey:@"demandType"];//技术类型
  59. [NetworkRequestManager requestGetWithInterfacePrefix:JT_demandList parameters:parameters onSuccess:^(id requestData) {
  60. [self dismiss:object];
  61. NSLog(@"服务器返回数据:%@",requestData);
  62. if ([requestData[@"error"] count] !=0) {
  63. for (NSDictionary *dic in requestData[@"error"]) {
  64. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  65. }
  66. }else{
  67. pageNo = pageNumberIndex;
  68. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组
  69. [dataArray removeAllObjects];
  70. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉
  71. if ([requestData[@"data"][@"list"] count]<=0) {
  72. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  73. }
  74. }else{//选择类型要清空数组
  75. [dataArray removeAllObjects];
  76. }
  77. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  78. Demandmodel *model = [[Demandmodel alloc] initWithDictionary:dic error:nil];
  79. [dataArray addObject:model];
  80. }
  81. //查询不到类型底图
  82. if (dataArray.count<=0) {
  83. [self addErrorLoadingFrame:CGRectMake(0, NavHeader+44, newtableView.width, newtableView.height) title:@"暂时没有您查询的需求类型~" buttonTitle:nil imageString:NewNoDataErrorImage];
  84. }else {
  85. [self hideReloadingview];
  86. [newtableView reloadData];
  87. }
  88. }
  89. } onFailure:^{
  90. [self dismiss:object];
  91. }];
  92. }
  93. #pragma mark -----行业类型数组网络请求------
  94. - (void)IndustrytypeNetworkrequest {
  95. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  96. [NetworkRequestManager requestGetWithInterfacePrefix:JT_industryList parameters:parameters onSuccess:^(id requestData) {
  97. NSLog(@"服务器返回数据:%@",requestData);
  98. if ([requestData[@"error"] count] !=0) {
  99. for (NSDictionary *dic in requestData[@"error"]) {
  100. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  101. }
  102. }else{
  103. for (NSDictionary *dic in requestData[@"data"]) {
  104. [industrytypeArray addObject:dic];
  105. }
  106. NSDictionary *dic = @{@"id":@"",@"name":@"全部"};
  107. [industrytypeArray addObject:dic];
  108. [self classificationview];
  109. [filtrateView setNeedsLayout];//强行刷新view;
  110. }
  111. } onFailure:^{
  112. }];
  113. }
  114. - (void)dataInitialization {
  115. dataArray = NewMutableArrayInit;
  116. industrytypeArray = NewMutableArrayInit;
  117. pageNo = 1;
  118. fieldA = @"";
  119. dataCategory = @"";
  120. }
  121. #pragma mark -------分类-------------
  122. - (void)classificationview{
  123. UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, 1)];
  124. line.backgroundColor = NewLineGrayColor;
  125. [self.view addSubview:line];
  126. SQFiltrateItem *item1 = [[SQFiltrateItem alloc]init];
  127. item1.listType = OptionListType_Tag;
  128. item1.numberType = OptionNumberType_Single;
  129. NSMutableArray *arr = NewMutableArrayInit;
  130. for (NSDictionary *dic in industrytypeArray) {
  131. [arr addObject:dic[@"name"]];
  132. }
  133. item1.optionData = arr;
  134. item1.title = @"行业类型";
  135. SQFiltrateItem *item2 = [[SQFiltrateItem alloc]init];
  136. item2.listType = OptionListType_Tag;
  137. item2.numberType = OptionNumberType_Single;
  138. /*
  139. demandType=0 技术购买需求
  140. demandType=1 技术设备类需求
  141. demandType=2 技术方案型需求
  142. demandType=3 技术攻关型需求
  143. demandType=4 技术咨询型需求
  144. demandType=5 技术人才型需求
  145. */
  146. item2.optionData = @[@"技术购买",@"技术设备类",@"技术方案型",@"技术攻关型",@"技术咨询型",@"技术人才型",@"全部"];
  147. item2.title = @"技术类型";
  148. filtrateView = [[SQFiltrateView alloc]initWithFrame:CGRectMake(0, NavHeader+1, SCREEN_WIDTH, 44)
  149. filtrateItems:@[item1,item2]];
  150. [filtrateView touchBlock:^(SQFiltrateView * _Nonnull view, SQFiltrateItem * _Nonnull item) {
  151. NSLog(@"%@:%@",item.title,item.choseSet);
  152. if ([item.title isEqualToString:@"行业类型"]) {
  153. NSMutableArray *arr = NewMutableArrayInit;
  154. for (NSDictionary *dic in industrytypeArray) {
  155. [arr addObject:dic[@"id"]];
  156. }
  157. NSSet *luo = [NSSet new];
  158. if (!item.choseSet.count) {//如果什么都不选
  159. fieldA = @"";
  160. }else{
  161. for (luo in item.choseSet) {
  162. NSString *str = [NSString stringWithFormat:@"%@",luo];
  163. NSString *Id = [arr objectAtIndex:[str integerValue]];
  164. fieldA = Id;
  165. }
  166. }
  167. }else{
  168. if (!item.choseSet.count) {//如果什么都不选
  169. dataCategory = @"";
  170. }else{
  171. for (NSSet *luo in item.choseSet) {
  172. NSString *str = [NSString stringWithFormat:@"%@",luo];
  173. if ([str isEqualToString:@"6"]) {
  174. dataCategory = @"";
  175. }else{
  176. dataCategory = str;
  177. }
  178. }
  179. }
  180. }
  181. [self demandNetworkrequest:nil];
  182. }];
  183. [self.view addSubview:filtrateView];
  184. }
  185. #pragma mark -----加载界面-------
  186. - (void)loadsView{
  187. [self.navgationBar addSubview:self.registerAccount];
  188. _registerAccount.sd_layout
  189. .widthIs(30)
  190. .rightSpaceToView(self.navgationBar, 10)
  191. .heightIs(44)
  192. .topSpaceToView(self.navgationBar, 18);
  193. // hideAllItemView
  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. SciencedemandCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  212. if (cell == nil) {
  213. cell = [[SciencedemandCell 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. Demandmodel *model = dataArray[indexPath.row];
  228. DemanddetailViewController *vc = [[DemanddetailViewController alloc] init];
  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 demandNetworkrequest:newvc.mj_header];
  253. }else{
  254. [newvc.mj_header endRefreshing];
  255. }
  256. }];
  257. newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  258. if ([NetworkRequestManager connectedToNetwork]) {
  259. [weakSelf demandNetworkrequest: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. - (UIButton *)registerAccount
  278. {
  279. if (!_registerAccount)
  280. {
  281. _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom];
  282. // [_registerAccount setTitle:@"" forState:UIControlStateNormal];
  283. [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal];
  284. [_registerAccount setBackgroundColor:[UIColor clearColor]];
  285. [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  286. [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]];
  287. [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside];
  288. // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44];
  289. [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal];
  290. }
  291. return _registerAccount;
  292. }
  293. - (void)touchRegister:(UIButton *)sender{
  294. [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self];
  295. }
  296. #pragma mark - YBPopupMenuDelegate
  297. - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
  298. {
  299. NSLog(@"点击了 %@ 选项",TITLES[index]);
  300. if (index == 0) {
  301. if ([UserHelper isLogin]) {
  302. NSLog(@"%@",@"已登录");
  303. MyattentionViewController *vc = [[MyattentionViewController alloc] init];
  304. NewPushViewController(vc);
  305. }else{
  306. NSLog(@"%@",@"未登录");
  307. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  308. [vc setLoginSuccess:^(NSString *string) {
  309. NewPopViewController;
  310. }];
  311. NewPushViewController(vc);
  312. }
  313. }else if (index == 1){
  314. if ([UserHelper isLogin]) {
  315. NSLog(@"%@",@"已登录");
  316. MyOrderViewController*vc = [[MyOrderViewController alloc] init];
  317. NewPushViewController(vc);
  318. }else{
  319. NSLog(@"%@",@"未登录");
  320. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  321. [vc setLoginSuccess:^(NSString *string) {
  322. NewPopViewController;
  323. }];
  324. NewPushViewController(vc);
  325. }
  326. }else if (index == 2) {
  327. if ([UserHelper isLogin]) {
  328. NSLog(@"%@",@"已登录");
  329. AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init];
  330. NewPushViewController(vc);
  331. }else{
  332. NSLog(@"%@",@"未登录");
  333. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  334. [vc setLoginSuccess:^(NSString *string) {
  335. NewPopViewController;
  336. }];
  337. NewPushViewController(vc);
  338. }
  339. }else if (index == 3){
  340. if ([UserHelper isLogin]) {
  341. NSLog(@"%@",@"已登录");
  342. ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init];
  343. NewPushViewController(vc);
  344. }else{
  345. NSLog(@"%@",@"未登录");
  346. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  347. [vc setLoginSuccess:^(NSString *string) {
  348. NewPopViewController;
  349. }];
  350. NewPushViewController(vc);
  351. }
  352. }
  353. }
  354. - (void)didReceiveMemoryWarning {
  355. [super didReceiveMemoryWarning];
  356. // Dispose of any resources that can be recreated.
  357. }
  358. /*
  359. #pragma mark - Navigation
  360. // In a storyboard-based application, you will often want to do a little preparation before navigation
  361. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  362. // Get the new view controller using [segue destinationViewController].
  363. // Pass the selected object to the new view controller.
  364. }
  365. */
  366. @end