ProcurementApplyListDetailVc.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. //
  2. // ProcurementApplyListDetailVc.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2018/7/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "ProcurementApplyListDetailVc.h"
  9. @interface ProcurementApplyListDetailVc ()
  10. {
  11. NSMutableDictionary *_cellHeight;
  12. }
  13. @end
  14. @implementation ProcurementApplyListDetailVc
  15. #pragma mark -公共函数
  16. /**
  17. 视图加载完成函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self loadNavStyle];
  22. _detailArray=[[NSMutableArray alloc]init];
  23. _cellHeight = [[NSMutableDictionary alloc] init];
  24. [self initHeaderView];
  25. [self initUI];
  26. [self startLoading];
  27. [self loadData];
  28. }
  29. /**
  30. 安全区视图发生变化
  31. */
  32. -(void)viewSafeAreaInsetsDidChange{
  33. [self.view setBackgroundColor:[UIColor whiteColor]];
  34. _tableView.frame=CGRectMake(0, 0, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height);
  35. [super viewSafeAreaInsetsDidChange];
  36. }
  37. #pragma mark -委托函数
  38. /**
  39. 加载列表数据成功回调
  40. @param sender <#sender description#>
  41. */
  42. - (void)onLoadFinish:(ASIDownManager *)sender {
  43. // 取消进度条
  44. [self stopLoading];
  45. // 服务器返回数据
  46. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  47. // 服务器返回数据状态值
  48. int iStatus = resultModel.status;
  49. // 服务器返回数据消息
  50. NSString *message = resultModel.message;
  51. double totalApplyQuantity=0;
  52. double totalApprovedQuantity=0;
  53. // 服务器返回数据状态值正确
  54. if (iStatus == 0) {
  55. NSDictionary *infoDic=(NSDictionary*)resultModel.result;
  56. if(infoDic!=nil){
  57. NSArray *infoArray=[infoDic objectForKey:@"Table"];
  58. if(infoArray!=nil&&infoArray.count>0){
  59. _tableView.tableHeaderView=_procurementDetailHeadView;
  60. for(int i=0;i<infoArray.count;i++){
  61. NSDictionary *dic=[infoArray objectAtIndex:i];
  62. ProcurementApplyListDetailModel *detailModel = [ProcurementApplyListDetailModel dk_modelWithDictionary:dic];
  63. [_detailArray addObject:detailModel];
  64. }
  65. [_tableView reloadData];
  66. for(int i=0;i<_detailArray.count;i++){
  67. ProcurementApplyListDetailModel *detailModel=[_detailArray objectAtIndex:i];
  68. if([detailModel.orderNo isEqualToString:@"小计"]||[detailModel.applyNo isEqualToString:@"小计"])
  69. {
  70. continue;
  71. }
  72. totalApplyQuantity+=[detailModel.applyQuantity doubleValue];
  73. totalApprovedQuantity+=[detailModel.approvedQuantity doubleValue];
  74. }
  75. _lblProcurementQuantity.text=[NSString stringWithFormat:@"%.6f",totalApplyQuantity];
  76. _lblApprovedQuantity.text=[NSString stringWithFormat:@"%.6f",totalApprovedQuantity];
  77. }
  78. else{
  79. // 无数据的view
  80. UIView *noDataView = [self noDataViewByFrame:_tableView.bounds];
  81. _tableView.backgroundView=noDataView;
  82. [self showAlertViewText:@"未找到匹配结果"];
  83. return;
  84. }
  85. }
  86. }
  87. // 服务器返回数据状态值异常
  88. else if(iStatus == ActionResultStatusAuthError
  89. ||iStatus == ActionResultStatusNoLogin
  90. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  91. [self showReLoginDialog:message];
  92. }
  93. else{
  94. [self showAlertViewText:message];
  95. return;
  96. }
  97. }
  98. /**
  99. 加载数据失败回调
  100. @param sender <#sender description#>
  101. */
  102. - (void)onLoadFail:(ASIDownManager *)sender {
  103. [self stopLoading];
  104. [self showAlertViewText:@"网络异常"];
  105. }
  106. /**
  107. tableview的行数
  108. @param tableView <#tableView description#>
  109. @param section <#section description#>
  110. @return <#return value description#>
  111. */
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  113. {
  114. return [_detailArray count];
  115. }
  116. /**
  117. tableview的分区数
  118. @param tableView <#tableView description#>
  119. @return <#return value description#>
  120. */
  121. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  122. return 1;
  123. }
  124. /**
  125. 获取tableview cell
  126. @param tableView <#tableView description#>
  127. @param indexPath <#indexPath description#>
  128. @return <#return value description#>
  129. */
  130. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. NSString *cellIdentifier = @"CellId";
  133. ProcurementApplyListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  134. cell = [[ProcurementApplyListDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  135. NSUInteger row = [indexPath row];
  136. ProcurementApplyListDetailModel *detailModel = [_detailArray objectAtIndex:row];
  137. [cell setProcurementApplyListDetailCell:detailModel];
  138. _cellHeight[@(indexPath.row)] = @(cell.height);
  139. return cell;
  140. }
  141. /**
  142. 点击单元格事件
  143. @param tableView tableView description
  144. @param indexPath indexPath description
  145. */
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  147. {
  148. ProcurementApplyListDetailModel *detailModel= [_detailArray objectAtIndex:indexPath.row];
  149. if(!([detailModel.applyNo isEqualToString:@"小计"]||[detailModel.orderNo isEqualToString:@"小计"])){
  150. self.hidesBottomBarWhenPushed=YES;
  151. ProcurementApplyDetailVc *detailVc = [[ProcurementApplyDetailVc alloc] init];
  152. detailVc.detailModel = detailModel;
  153. [self.navigationController pushViewController:detailVc animated:YES];
  154. }
  155. }
  156. /**
  157. 预估高度
  158. @param tableView <#tableView description#>
  159. @param indexPath <#indexPath description#>
  160. @return <#return value description#>
  161. */
  162. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  163. return 250;
  164. }
  165. /**
  166. tableview的高度
  167. @param tableView <#tableView description#>
  168. @param indexPath <#indexPath description#>
  169. @return <#return value description#>
  170. */
  171. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  172. return [_cellHeight[@(indexPath.row)] floatValue];;
  173. }
  174. #pragma mark -私有函数
  175. /**
  176. 初始化UI
  177. */
  178. -(void)initUI
  179. {
  180. [self.view setBackgroundColor:[UIColor whiteColor]];
  181. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];
  182. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  183. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  184. _tableView.backgroundColor = [UIColor clearColor];
  185. _tableView.delegate = self;
  186. _tableView.dataSource=self;
  187. [self.view addSubview:_tableView];
  188. }
  189. /**
  190. 初始化header
  191. */
  192. -(void)initHeaderView
  193. {
  194. CGFloat height = 170;
  195. CGFloat titleHeight = 50;
  196. CGFloat lblx = 20;
  197. CGFloat lblwidth = 130;
  198. CGFloat fontsize = 14;
  199. CGFloat valuey = 10;
  200. CGFloat valueheight = 25;
  201. CGFloat heightLine =1;
  202. _procurementDetailHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, height)];
  203. [_procurementDetailHeadView setBackgroundColor:[UIColor whiteColor]];
  204. //总合计 —————————
  205. UIView *vtotal = [UIView new];
  206. vtotal.frame=CGRectMake(0, 0, Screen_Width, titleHeight);
  207. [_procurementDetailHeadView addSubview:vtotal];
  208. UILabel *lbtotal = [UILabel new];
  209. lbtotal.frame=CGRectMake(lblx, valuey, lblwidth, valueheight);
  210. lbtotal.font = [UIFont boldSystemFontOfSize:fontsize];
  211. lbtotal.text = @"合计";
  212. [vtotal addSubview:lbtotal];
  213. //分割线
  214. _viewBackground = [UIView new];
  215. _viewBackground.frame = CGRectMake(0, CGRectGetMaxY(vtotal.frame), Screen_Width, heightLine);
  216. _viewBackground.backgroundColor = LineBackgroundColor;
  217. [_procurementDetailHeadView addSubview:_viewBackground];
  218. //货物金额 —————————
  219. UIView *vtotalProcurementQuantity = [UIView new];
  220. vtotalProcurementQuantity.frame=CGRectMake(0, CGRectGetMaxY(_viewBackground.frame), Screen_Width, titleHeight);
  221. [_procurementDetailHeadView addSubview:vtotalProcurementQuantity];
  222. UIImageView *imgview = [UIImageView new];
  223. imgview.frame=CGRectMake(lblx, valuey + 5,25,25);
  224. [imgview setImage:[UIImage imageNamed:@"apply_quantity"]];
  225. [vtotalProcurementQuantity addSubview:imgview];
  226. UILabel *lbltotalProcurementQuantityTitle = [UILabel new];
  227. lbltotalProcurementQuantityTitle.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey+5, lblwidth, valueheight);
  228. lbltotalProcurementQuantityTitle.font = [UIFont systemFontOfSize:fontsize];
  229. lbltotalProcurementQuantityTitle.text = @"请购数量";
  230. [vtotalProcurementQuantity addSubview:lbltotalProcurementQuantityTitle];
  231. _lblProcurementQuantity = [UILabel new];
  232. _lblProcurementQuantity.frame=CGRectMake(CGRectGetMaxX(lbltotalProcurementQuantityTitle.frame), valuey+5,Screen_Width-CGRectGetMaxX(lbltotalProcurementQuantityTitle.frame)-20, valueheight);
  233. _lblProcurementQuantity.font = [UIFont systemFontOfSize:fontsize];
  234. _lblProcurementQuantity.textAlignment = NSTextAlignmentRight;
  235. [vtotalProcurementQuantity addSubview:_lblProcurementQuantity];
  236. _viewBackground = [UIView new];
  237. _viewBackground.frame = CGRectMake(0, CGRectGetMaxY(vtotalProcurementQuantity.frame), Screen_Width, heightLine);
  238. _viewBackground.backgroundColor = LineBackgroundColor;
  239. [_procurementDetailHeadView addSubview:_viewBackground];
  240. UIView *vtotalApprovedQuantity = [UIView new];
  241. vtotalApprovedQuantity.frame=CGRectMake(0,CGRectGetMaxY(_viewBackground.frame), Screen_Width, titleHeight);
  242. [_procurementDetailHeadView addSubview:vtotalApprovedQuantity];
  243. UIImageView *imgviewReceivable = [UIImageView new];
  244. imgviewReceivable.frame=CGRectMake(lblx, valuey+5,25,25);
  245. [imgviewReceivable setImage:[UIImage imageNamed:@"approved_quantity"]];
  246. [vtotalApprovedQuantity addSubview:imgviewReceivable];
  247. UILabel *lbtotalApprovedQuantityTitle = [UILabel new];
  248. lbtotalApprovedQuantityTitle.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+5, lblwidth, valueheight);
  249. lbtotalApprovedQuantityTitle.font = [UIFont systemFontOfSize:fontsize];
  250. lbtotalApprovedQuantityTitle.text = @"核准数量";
  251. [vtotalApprovedQuantity addSubview:lbtotalApprovedQuantityTitle];
  252. _lblApprovedQuantity = [UILabel new];
  253. _lblApprovedQuantity.frame=CGRectMake(CGRectGetMaxX(lbtotalApprovedQuantityTitle.frame), valuey+5, Screen_Width-CGRectGetMaxX(lbtotalApprovedQuantityTitle.frame)-20, valueheight);
  254. _lblApprovedQuantity.font = [UIFont systemFontOfSize:fontsize];
  255. _lblApprovedQuantity.textAlignment = NSTextAlignmentRight;
  256. [vtotalApprovedQuantity addSubview:_lblApprovedQuantity];
  257. //分割线
  258. _topSeparator = [UIView new];
  259. _topSeparator.backgroundColor = LineBackgroundColor;
  260. [_procurementDetailHeadView addSubview:_topSeparator];
  261. _topSeparator.frame = CGRectMake(0, CGRectGetMaxY(vtotalApprovedQuantity.frame), Screen_Width, 10);
  262. _procurementDetailHeadView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(vtotalApprovedQuantity.frame));
  263. }
  264. /**
  265. 加载数据源
  266. */
  267. -(void)loadData
  268. {
  269. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  270. [dict setObject:@"GetProcurementApplyReportDetailIphone" forKey:@"Action"];
  271. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  272. [dict setObject:kkUserCode forKey:@"UserCode"];
  273. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  274. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  275. [dict setObject:_applyId == nil?@"":_applyId forKey:@"ApplyID"];
  276. [dict setObject:_sortType == nil?@"":_sortType forKey:@"SortType"];
  277. _downManager = [[ASIDownManager alloc] init];
  278. _downManager.delegate = self;
  279. _downManager.onRequestSuccess = @selector(onLoadFinish:);
  280. _downManager.onRequestFail = @selector(onLoadFail:);
  281. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  282. }
  283. /**
  284. 导航按钮样式
  285. */
  286. - (void)loadNavStyle {
  287. self.navigationItem.title = @"请购明细表";
  288. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  289. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  290. [button addTarget:self action:@selector(goBack)
  291. forControlEvents:UIControlEventTouchUpInside];
  292. button.frame = CGRectMake(0, 0,45,22);
  293. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  294. self.navigationItem.leftBarButtonItem = menuButton;
  295. }
  296. @end