DemanddetailViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. //
  2. // DemanddetailViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/16.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "DemanddetailViewController.h"
  9. #import "DemandCell.h"
  10. #import "RequirementdescriptionCell.h"
  11. #import "OrdertakingViewController.h"
  12. #import "DemanddetailModel.h"
  13. #import "CGPurchaseintentionViewController.h"
  14. #import "XuqiuImageCell.h"
  15. #import "YBPopupMenu.h"
  16. #import "MyattentionViewController.h"
  17. #import "MyOrderViewController.h"
  18. #import "AchievementsReleaseViewController.h"
  19. #import "ReleaserequirementsViewController.h"
  20. #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"]
  21. #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"]
  22. @interface DemanddetailViewController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate>{
  23. UITableView *newtableView;
  24. NSMutableArray *dataArray;
  25. NSMutableArray *DemanddetailArray;
  26. UIButton *followBT;
  27. }
  28. @property (strong ,nonatomic) UIButton * registerAccount;
  29. @end
  30. @implementation DemanddetailViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self setNavTitle:@"需求详情"];
  34. [self dataInitialization];
  35. [self demandDetailsNetworkrequest];
  36. [self loadsView];
  37. // Do any additional setup after loading the view.
  38. }
  39. #pragma mark ---------需求详情关注网络请求-------
  40. - (void)followBTclick:(UIButton *)sender {
  41. if ([UserHelper isLogin]) {
  42. NSLog(@"%@",@"已登录");
  43. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  44. // [parameters safeSetObject:[UserEntity sharedInstance].token forKey:@"uid"];
  45. /*
  46. 0-成果 1-需求 2-专家 3-政策 4-活动 5-其他
  47. */
  48. [parameters safeSetObject:@"1" forKey:@"type"];
  49. DemanddetailModel *model = DemanddetailArray[0];
  50. [parameters safeSetObject:model.ID forKey:@"objectId"];
  51. [parameters safeSetObject:model.interest forKey:@"interest"];
  52. [NetworkRequestManager requestGetWithInterfacePrefix:JT_interestAdd parameters:parameters onSuccess:^(id requestData) {
  53. NSLog(@"服务器返回数据:%@",requestData);
  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. if ([requestData[@"data"] isEqualToString:@"取消关注成功"]) {
  60. DemanddetailModel *model = DemanddetailArray[0];
  61. NSInteger follownumber = [model.countInterest integerValue]-1;
  62. model.countInterest = [NSString stringWithFormat:@"%ld",follownumber];
  63. model.interest = @"0";
  64. [DemanddetailArray removeAllObjects];
  65. [DemanddetailArray addObject:model];
  66. [followBT setImage:[UIImage imageNamed:@"未关注"] forState:UIControlStateNormal];
  67. [MBProgressHUD showSuccess:@"哎呀,您取消关注啦!" toView:self.view];
  68. [newtableView reloadData];
  69. }else{
  70. ResultsDetailsModel *model = DemanddetailArray[0];
  71. NSInteger follownumber = [model.countInterest integerValue]+1;
  72. model.countInterest = [NSString stringWithFormat:@"%ld",follownumber];
  73. model.interest = @"1";
  74. [DemanddetailArray removeAllObjects];
  75. [DemanddetailArray addObject:model];
  76. [followBT setImage:[UIImage imageNamed:@"已关注"] forState:UIControlStateNormal];
  77. [MBProgressHUD showSuccess:@"哎呀,您关注成功啦!" toView:self.view];
  78. [newtableView reloadData];
  79. }
  80. }
  81. } onFailure:^{
  82. }];
  83. }else{
  84. NSLog(@"%@",@"未登录");
  85. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  86. [vc setLoginSuccess:^(NSString *string) {
  87. [self demandDetailsNetworkrequest];
  88. NewPopViewController;
  89. }];
  90. NewPushViewController(vc);
  91. }
  92. }
  93. #pragma mark -------需求详情网络请求--------
  94. - (void)demandDetailsNetworkrequest {
  95. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  96. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  97. [parameters safeSetObject:_ID forKey:@"id"];
  98. [NetworkRequestManager requestGetWithInterfacePrefix:JT_demandDetail parameters:parameters onSuccess:^(id requestData) {
  99. [MBProgressHUD hideHUDForView:self.view];
  100. NSLog(@"服务器返回数据:%@",requestData);
  101. if ([requestData[@"error"] count] !=0) {
  102. for (NSDictionary *dic in requestData[@"error"]) {
  103. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  104. }
  105. }else{
  106. DemanddetailModel *model = [[DemanddetailModel alloc] initWithDictionary:requestData[@"data"] error:nil];
  107. [DemanddetailArray addObject:model];
  108. if ([model.interest isEqualToString:@"0"]) {
  109. [followBT setImage:[UIImage imageNamed:@"未关注"] forState:UIControlStateNormal];
  110. }else{
  111. [followBT setImage:[UIImage imageNamed:@"已关注"] forState:UIControlStateNormal];
  112. }
  113. [newtableView reloadData];
  114. }
  115. } onFailure:^{
  116. [MBProgressHUD hideHUDForView:self.view];
  117. }];
  118. }
  119. - (void)dataInitialization {
  120. dataArray = NewMutableArrayInit;
  121. [dataArray addObject:@"1"];
  122. [dataArray addObject:@"1"];
  123. DemanddetailArray = NewMutableArrayInit;
  124. }
  125. #pragma mark ----加载界面
  126. - (void)loadsView{
  127. [self.navgationBar addSubview:self.registerAccount];
  128. _registerAccount.sd_layout
  129. .widthIs(30)
  130. .rightSpaceToView(self.navgationBar, 10)
  131. .heightIs(44)
  132. .topSpaceToView(self.navgationBar, 18);
  133. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  134. newtableView.separatorStyle = NO;
  135. UIView *view = [UIView new];
  136. view.backgroundColor = NewWhiteColor;
  137. [self.view addSubview:view];
  138. view.sd_layout
  139. .bottomEqualToView(self.view)
  140. .heightIs(44)
  141. .widthIs(SCREEN_WIDTH);
  142. followBT = [UIButton new];
  143. followBT.backgroundColor = NewClearColor;
  144. NewTouchUpInside(followBT, followBTclick:);
  145. [view addSubview:followBT];
  146. followBT.sd_layout
  147. .leftEqualToView(view)
  148. .heightIs(44)
  149. .topEqualToView(view)
  150. .widthIs(44);
  151. UIButton *submissionpurchase = [UIButton new];
  152. [submissionpurchase setTitle:@"接 单" forState:UIControlStateNormal];
  153. [submissionpurchase setTitleColor:NewWhiteColor forState:UIControlStateNormal];
  154. submissionpurchase.titleLabel.font = NewFont(15);
  155. submissionpurchase.titleLabel.textAlignment = NSTextAlignmentCenter;
  156. submissionpurchase.backgroundColor = NewRGBColor(252, 133, 52, 1);
  157. NewTouchUpInside(submissionpurchase, submissionpurchaseclick:);
  158. [view addSubview:submissionpurchase];
  159. submissionpurchase.sd_layout
  160. .rightEqualToView(view)
  161. .heightIs(44)
  162. .widthIs(fitScreenWidth(121));
  163. UIButton *negotiate = [UIButton new];
  164. [negotiate setTitle:@"洽 谈" forState:UIControlStateNormal];
  165. [negotiate setTitleColor:NewWhiteColor forState:UIControlStateNormal];
  166. negotiate.titleLabel.font = NewFont(15);
  167. negotiate.titleLabel.textAlignment = NSTextAlignmentCenter;
  168. negotiate.backgroundColor = NewButtonColor;
  169. NewTouchUpInside(negotiate, negotiateclick:);
  170. [view addSubview:negotiate];
  171. negotiate.sd_layout
  172. .rightSpaceToView(submissionpurchase, 1)
  173. .heightIs(44)
  174. .widthIs(fitScreenWidth(121));
  175. }
  176. #pragma mark-------------------------UITableView------------------------------------
  177. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  178. {
  179. return 1;
  180. }
  181. //返回每段行数
  182. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  183. {
  184. return dataArray.count+1;
  185. }
  186. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  187. {
  188. static NSString *Cell = @"Cell";
  189. static NSString *Cell1 = @"Cell1";
  190. static NSString *Cell2 = @"Cell2";
  191. if (indexPath.row == 0) {
  192. DemandCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  193. if (cell == nil) {
  194. cell = [[DemandCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  195. }
  196. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  197. cell.accessoryType = UITableViewCellAccessoryNone;
  198. if (DemanddetailArray.count>0) {
  199. [cell assignment:DemanddetailArray[indexPath.row]];
  200. }
  201. return cell;
  202. }else if (indexPath.row == 1){
  203. RequirementdescriptionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
  204. if (cell == nil) {
  205. cell = [[RequirementdescriptionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
  206. }
  207. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  208. cell.accessoryType = UITableViewCellAccessoryNone;
  209. if (DemanddetailArray.count>0) {
  210. cell.title.text = @"需求描述";
  211. DemanddetailModel *model = DemanddetailArray[0];
  212. if (model.problemDes == NULL) {
  213. cell.content.text = @"暂无需求描述";
  214. }else{
  215. cell.content.text = model.problemDes;
  216. }
  217. }
  218. return cell;
  219. }else if (indexPath.row == 2){
  220. XuqiuImageCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell2];
  221. if (cell == nil) {
  222. cell = [[XuqiuImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell2];
  223. }
  224. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  225. cell.accessoryType = UITableViewCellAccessoryNone;
  226. if (DemanddetailArray.count>0) {
  227. DemanddetailModel *model = DemanddetailArray[0];
  228. UIImageView *image = [UIImageView new];
  229. image.backgroundColor = NewClearColor;
  230. image.frame = CGRectMake(15, 0, SCREEN_WIDTH-30, 188);
  231. if (model.pictureUrls.count>0) {
  232. [image sd_setImageWithURL:NewURL([model.pictureUrls[0] mosaicUrlPrefix]) placeholderImage:NewImageNamed(@"")];
  233. }
  234. [cell.contentView addSubview:image];
  235. }
  236. return cell;
  237. }
  238. return [[UITableViewCell alloc] init];
  239. }
  240. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  241. {
  242. if (indexPath.row == 0) {
  243. return 220;
  244. }else if(indexPath.row == 1){
  245. if (DemanddetailArray.count>0) {
  246. DemanddetailModel *model = DemanddetailArray[0];
  247. if (model.problemDes == NULL) {
  248. CGFloat height = [NewUtils heightforString:@"暂无需求描述" andWidth:SCREEN_WIDTH-30 fontSize:fitScreenWidth(13)];
  249. return height+70;
  250. }else{
  251. CGFloat height = [NewUtils heightforString:model.problemDes andWidth:SCREEN_WIDTH-30 fontSize:fitScreenWidth(13)];
  252. return height+70;
  253. }
  254. }
  255. }else if (indexPath.row == 2){
  256. if (DemanddetailArray.count>0) {
  257. DemanddetailModel *model = DemanddetailArray[0];
  258. if (model.pictureUrls.count>0) {
  259. return 188;
  260. }else{
  261. return 0;
  262. }
  263. }
  264. }
  265. return 0;
  266. }
  267. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  268. }
  269. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  270. return CGFLOAT_MIN;
  271. }
  272. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  273. return CGFLOAT_MIN;
  274. }
  275. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  276. return [[UIView alloc] init];
  277. }
  278. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  279. return [[UIView alloc] init];
  280. }
  281. #pragma mark ------接单------
  282. - (void)submissionpurchaseclick:(UIButton *)sender {
  283. if ([UserHelper isLogin]) {
  284. NSLog(@"%@",@"已登录");
  285. DemanddetailModel *model = DemanddetailArray[0];
  286. CGPurchaseintentionViewController *vc = [[CGPurchaseintentionViewController alloc] init];
  287. vc.ID = model.ID;
  288. vc.commodityType = @"2";
  289. NewPushViewController(vc);
  290. }else{
  291. NSLog(@"%@",@"未登录");
  292. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  293. [vc setLoginSuccess:^(NSString *string) {
  294. [self demandDetailsNetworkrequest];
  295. NewPopViewController;
  296. }];
  297. NewPushViewController(vc);
  298. }
  299. }
  300. - (void)negotiateclick:(UIButton *)sender {
  301. if ([UserHelper isLogin]) {
  302. NSLog(@"%@",@"已登录");
  303. if (DemanddetailArray.count>0) {
  304. DemanddetailModel *model = DemanddetailArray[0];
  305. if (model.easemobName == NULL) {
  306. model.easemobName = HXKF;
  307. }
  308. EaseMessageViewController *viewController = [[EaseMessageViewController alloc] initWithConversationChatter:model.easemobName conversationType:0];
  309. if ([model.easemobName isEqualToString:HXKF]) {
  310. viewController.title = @"客服在线";
  311. }else{
  312. viewController.title = model.easemobName;
  313. }
  314. viewController.hidesBottomBarWhenPushed = YES;
  315. [[NSNotificationCenter defaultCenter]postNotificationName:@"环信登录成功" object:nil];
  316. [self.navigationController pushViewController:viewController animated:YES];
  317. }
  318. }else{
  319. NSLog(@"%@",@"未登录");
  320. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  321. [vc setLoginSuccess:^(NSString *string) {
  322. [self demandDetailsNetworkrequest];
  323. NewPopViewController;
  324. }];
  325. NewPushViewController(vc);
  326. }
  327. }
  328. - (UIButton *)registerAccount
  329. {
  330. if (!_registerAccount)
  331. {
  332. _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom];
  333. // [_registerAccount setTitle:@"" forState:UIControlStateNormal];
  334. [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal];
  335. [_registerAccount setBackgroundColor:[UIColor clearColor]];
  336. [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  337. [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]];
  338. [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside];
  339. // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44];
  340. [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal];
  341. }
  342. return _registerAccount;
  343. }
  344. - (void)touchRegister:(UIButton *)sender{
  345. [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self];
  346. }
  347. #pragma mark - YBPopupMenuDelegate
  348. - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
  349. {
  350. NSLog(@"点击了 %@ 选项",TITLES[index]);
  351. if (index == 0) {
  352. if ([UserHelper isLogin]) {
  353. NSLog(@"%@",@"已登录");
  354. MyattentionViewController *vc = [[MyattentionViewController alloc] init];
  355. NewPushViewController(vc);
  356. }else{
  357. NSLog(@"%@",@"未登录");
  358. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  359. [vc setLoginSuccess:^(NSString *string) {
  360. [self demandDetailsNetworkrequest];
  361. NewPopViewController;
  362. }];
  363. NewPushViewController(vc);
  364. }
  365. }else if (index == 1){
  366. if ([UserHelper isLogin]) {
  367. NSLog(@"%@",@"已登录");
  368. MyOrderViewController*vc = [[MyOrderViewController alloc] init];
  369. NewPushViewController(vc);
  370. }else{
  371. NSLog(@"%@",@"未登录");
  372. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  373. [vc setLoginSuccess:^(NSString *string) {
  374. [self demandDetailsNetworkrequest];
  375. NewPopViewController;
  376. }];
  377. NewPushViewController(vc);
  378. }
  379. }else if (index == 2) {
  380. if ([UserHelper isLogin]) {
  381. NSLog(@"%@",@"已登录");
  382. AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init];
  383. NewPushViewController(vc);
  384. }else{
  385. NSLog(@"%@",@"未登录");
  386. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  387. [vc setLoginSuccess:^(NSString *string) {
  388. [self demandDetailsNetworkrequest];
  389. NewPopViewController;
  390. }];
  391. NewPushViewController(vc);
  392. }
  393. }else if (index == 3){
  394. if ([UserHelper isLogin]) {
  395. NSLog(@"%@",@"已登录");
  396. ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init];
  397. NewPushViewController(vc);
  398. }else{
  399. NSLog(@"%@",@"未登录");
  400. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  401. [vc setLoginSuccess:^(NSString *string) {
  402. [self demandDetailsNetworkrequest];
  403. NewPopViewController;
  404. }];
  405. NewPushViewController(vc);
  406. }
  407. }
  408. }
  409. - (void)didReceiveMemoryWarning {
  410. [super didReceiveMemoryWarning];
  411. // Dispose of any resources that can be recreated.
  412. }
  413. /*
  414. #pragma mark - Navigation
  415. // In a storyboard-based application, you will often want to do a little preparation before navigation
  416. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  417. // Get the new view controller using [segue destinationViewController].
  418. // Pass the selected object to the new view controller.
  419. }
  420. */
  421. @end