SalesOrderBusinessDepartmentVC.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // SalesOrderBusinessDepartmentVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/1/31.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SalesOrderBusinessDepartmentVC.h"
  9. @interface SalesOrderBusinessDepartmentVC ()
  10. @end
  11. @implementation SalesOrderBusinessDepartmentVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. [self loadNavStyle];
  15. [self initUI];
  16. }
  17. /**
  18. 导航按钮样式
  19. */
  20. -(void)loadNavStyle
  21. {
  22. //右边
  23. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  24. [btnAdd addTarget:self action:@selector(submitData)
  25. forControlEvents:UIControlEventTouchUpInside];
  26. btnAdd.frame = CGRectMake(0, 0,60,14);
  27. [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  28. btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
  29. [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
  30. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  31. self.navigationItem.title=@"请选择";
  32. self.navigationItem.rightBarButtonItem = menubtnAdd;
  33. //返回
  34. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  35. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  36. forState:UIControlStateNormal];
  37. [button addTarget:self action:@selector(goBack)
  38. forControlEvents:UIControlEventTouchUpInside];
  39. button.frame = CGRectMake(0, 0, 15, 18);
  40. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  41. self.navigationItem.leftBarButtonItem = menuButton;
  42. }
  43. -(void)initUI{
  44. _vTableView = [[UITableView alloc]
  45. initWithFrame:CGRectMake(0,
  46. 0,
  47. self.view.frame.size.width,
  48. self.view.frame.size.height)];
  49. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  50. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  51. _vTableView.backgroundColor = [UIColor whiteColor];
  52. _vTableView.delegate = self;
  53. _vTableView.dataSource=self;
  54. [self.view addSubview:_vTableView];
  55. if(_departmentList!=nil&&_departmentList.count>0){
  56. [_vTableView reloadData];
  57. }
  58. }
  59. -(Boolean) isMainDepartment:(NSMutableArray*) departmentList{
  60. Boolean mainDepartmentFlag=NO;
  61. for(DepartmentFrame *frame in departmentList){
  62. if(frame.departmentModel.isMainDepartmentStatus){
  63. mainDepartmentFlag=YES;
  64. break;
  65. }
  66. }
  67. return mainDepartmentFlag;
  68. }
  69. -(void)submitData{
  70. _departmentCheckedList=[[NSMutableArray alloc]init];
  71. for( DepartmentFrame *frame in _departmentList){
  72. if(frame.departmentModel.isCheckedStatus){
  73. [_departmentCheckedList addObject:frame];
  74. }
  75. }
  76. if(_departmentCheckedList!=nil&&_departmentCheckedList.count==0){
  77. [self showAlertViewText:@"请选择业务部门"];
  78. return;
  79. }
  80. Boolean mainDepartmentFlag=[self isMainDepartment:_departmentCheckedList];
  81. if(!mainDepartmentFlag){
  82. [self showAlertViewText:@"请选择主业务部门"];
  83. return;
  84. }
  85. if([self.departmentDelegate respondsToSelector:@selector(showDepartmentInfo:)])
  86. {
  87. [self.departmentDelegate showDepartmentInfo:_departmentCheckedList];
  88. }
  89. [self.navigationController popViewControllerAnimated:YES];
  90. }
  91. #pragma mark - tableView回调
  92. /**
  93. 单元格cell个数
  94. @param tableView <#tableView description#>
  95. @param section <#section description#>
  96. @return <#return value description#>
  97. */
  98. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  99. {
  100. return [_departmentList count];
  101. }
  102. /**
  103. <#Description#>
  104. @param tableView <#tableView description#>
  105. @return <#return value description#>
  106. */
  107. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  108. return 1;
  109. }
  110. /**
  111. 高度
  112. @param tableView <#tableView description#>
  113. @param indexPath <#indexPath description#>
  114. @return <#return value description#>
  115. */
  116. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  117. BusinessDepartmentFrame *frame= [_departmentList objectAtIndex:indexPath.row];
  118. return frame.cellHeight ;
  119. }
  120. /**
  121. 每个单元格cell
  122. @param tableView <#tableView description#>
  123. @param indexPath <#indexPath description#>
  124. @return <#return value description#>
  125. */
  126. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  127. {
  128. static NSString *cellIdentifier = @"DepartmentCell";
  129. SalesOrderDepartmentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  130. cell=[[SalesOrderDepartmentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  131. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  132. DepartmentFrame *departmentFrame = [_departmentList objectAtIndex:indexPath.row];
  133. cell.delegate = self;
  134. [cell parseDepartmentInfo:departmentFrame];
  135. cell.cellIndex=indexPath.row;
  136. BOOL checked = departmentFrame.departmentModel.isCheckedStatus;
  137. BOOL mainDepartmentChecked=departmentFrame.departmentModel.isMainDepartmentStatus;
  138. [cell setCheckBackground:checked];
  139. [cell setMainDepartmentCheckBackground:mainDepartmentChecked];
  140. return cell;
  141. }
  142. -(void)btnDepartmentCheckPressed:(SalesOrderDepartmentCell*)cell{
  143. DepartmentFrame *departmentFrame= _departmentList[cell.cellIndex];
  144. _departmentModel=departmentFrame.departmentModel;
  145. BOOL checked=!_departmentModel.isCheckedStatus;
  146. int total=0;
  147. for(DepartmentFrame *frame in _departmentList){
  148. if(frame.departmentModel.isCheckedStatus){
  149. ++total;
  150. }
  151. }
  152. if(total==0){
  153. _departmentModel.isMainDepartmentStatus=YES;
  154. _departmentModel.isCheckedStatus=checked;
  155. [_vTableView reloadData];
  156. return;
  157. }
  158. _departmentModel.isCheckedStatus=checked;
  159. if( !_departmentModel.isCheckedStatus&&_departmentModel.isMainDepartmentStatus){
  160. _departmentModel.isMainDepartmentStatus=NO;
  161. }
  162. [_vTableView reloadData];
  163. }
  164. -(void)btnMainDepartmentPressed:(SalesOrderDepartmentCell*)cell{
  165. DepartmentFrame *departmentFrame= _departmentList[cell.cellIndex];
  166. _departmentModel= departmentFrame.departmentModel;
  167. if(_departmentModel.isCheckedStatus){
  168. if(!_departmentModel.isMainDepartmentStatus){
  169. _departmentModel.isMainDepartmentStatus=YES;
  170. for(DepartmentFrame *frame1 in _departmentList){
  171. if(frame1.departmentModel.organizationId!=_departmentModel.organizationId){
  172. frame1.departmentModel.isMainDepartmentStatus=NO;
  173. }
  174. }
  175. }
  176. else{
  177. _departmentModel.isMainDepartmentStatus=NO;
  178. for(DepartmentFrame *frame1 in _departmentList){
  179. if(frame1.departmentModel.organizationId!=_departmentModel.organizationId){
  180. frame1.departmentModel.isMainDepartmentStatus=NO;
  181. }
  182. }
  183. }
  184. }
  185. else{
  186. _departmentModel.isMainDepartmentStatus=NO;
  187. }
  188. [_vTableView reloadData];
  189. }
  190. - (void)goBack
  191. {
  192. if([self.departmentDelegate respondsToSelector:@selector(recoveryData)])
  193. {
  194. [self.departmentDelegate recoveryData];
  195. }
  196. [self.navigationController popViewControllerAnimated:YES];
  197. }
  198. - (void)didReceiveMemoryWarning {
  199. [super didReceiveMemoryWarning];
  200. }
  201. @end