| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //
- // SalesOrderBusinessDepartmentVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/1/31.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "SalesOrderBusinessDepartmentVC.h"
- @interface SalesOrderBusinessDepartmentVC ()
- @end
- @implementation SalesOrderBusinessDepartmentVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- }
- /**
- 导航按钮样式
- */
- -(void)loadNavStyle
- {
- //右边
- UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
- [btnAdd addTarget:self action:@selector(submitData)
- forControlEvents:UIControlEventTouchUpInside];
- btnAdd.frame = CGRectMake(0, 0,60,14);
- [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
- [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
-
- UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
- self.navigationItem.title=@"请选择";
- self.navigationItem.rightBarButtonItem = menubtnAdd;
-
-
- //返回
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- -(void)initUI{
- _vTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0,
- 0,
- self.view.frame.size.width,
- self.view.frame.size.height)];
-
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vTableView.backgroundColor = [UIColor whiteColor];
- _vTableView.delegate = self;
- _vTableView.dataSource=self;
- [self.view addSubview:_vTableView];
- if(_departmentList!=nil&&_departmentList.count>0){
- [_vTableView reloadData];
- }
-
- }
- -(Boolean) isMainDepartment:(NSMutableArray*) departmentList{
- Boolean mainDepartmentFlag=NO;
- for(DepartmentFrame *frame in departmentList){
- if(frame.departmentModel.isMainDepartmentStatus){
- mainDepartmentFlag=YES;
- break;
- }
- }
- return mainDepartmentFlag;
- }
- -(void)submitData{
- _departmentCheckedList=[[NSMutableArray alloc]init];
- for( DepartmentFrame *frame in _departmentList){
- if(frame.departmentModel.isCheckedStatus){
- [_departmentCheckedList addObject:frame];
- }
- }
-
- if(_departmentCheckedList!=nil&&_departmentCheckedList.count==0){
- [self showAlertViewText:@"请选择业务部门"];
- return;
- }
- Boolean mainDepartmentFlag=[self isMainDepartment:_departmentCheckedList];
- if(!mainDepartmentFlag){
- [self showAlertViewText:@"请选择主业务部门"];
- return;
- }
-
- if([self.departmentDelegate respondsToSelector:@selector(showDepartmentInfo:)])
- {
- [self.departmentDelegate showDepartmentInfo:_departmentCheckedList];
-
- }
- [self.navigationController popViewControllerAnimated:YES];
-
-
- }
- #pragma mark - tableView回调
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_departmentList count];
- }
- /**
- <#Description#>
-
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- /**
- 高度
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- BusinessDepartmentFrame *frame= [_departmentList objectAtIndex:indexPath.row];
- return frame.cellHeight ;
-
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"DepartmentCell";
- SalesOrderDepartmentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
- cell=[[SalesOrderDepartmentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- DepartmentFrame *departmentFrame = [_departmentList objectAtIndex:indexPath.row];
- cell.delegate = self;
- [cell parseDepartmentInfo:departmentFrame];
- cell.cellIndex=indexPath.row;
- BOOL checked = departmentFrame.departmentModel.isCheckedStatus;
- BOOL mainDepartmentChecked=departmentFrame.departmentModel.isMainDepartmentStatus;
- [cell setCheckBackground:checked];
- [cell setMainDepartmentCheckBackground:mainDepartmentChecked];
- return cell;
- }
- -(void)btnDepartmentCheckPressed:(SalesOrderDepartmentCell*)cell{
- DepartmentFrame *departmentFrame= _departmentList[cell.cellIndex];
-
- _departmentModel=departmentFrame.departmentModel;
- BOOL checked=!_departmentModel.isCheckedStatus;
-
- int total=0;
- for(DepartmentFrame *frame in _departmentList){
- if(frame.departmentModel.isCheckedStatus){
- ++total;
- }
- }
-
- if(total==0){
- _departmentModel.isMainDepartmentStatus=YES;
- _departmentModel.isCheckedStatus=checked;
- [_vTableView reloadData];
- return;
- }
- _departmentModel.isCheckedStatus=checked;
- if( !_departmentModel.isCheckedStatus&&_departmentModel.isMainDepartmentStatus){
- _departmentModel.isMainDepartmentStatus=NO;
-
- }
- [_vTableView reloadData];
-
- }
- -(void)btnMainDepartmentPressed:(SalesOrderDepartmentCell*)cell{
- DepartmentFrame *departmentFrame= _departmentList[cell.cellIndex];
- _departmentModel= departmentFrame.departmentModel;
- if(_departmentModel.isCheckedStatus){
- if(!_departmentModel.isMainDepartmentStatus){
- _departmentModel.isMainDepartmentStatus=YES;
- for(DepartmentFrame *frame1 in _departmentList){
- if(frame1.departmentModel.organizationId!=_departmentModel.organizationId){
- frame1.departmentModel.isMainDepartmentStatus=NO;
- }
- }
-
- }
- else{
- _departmentModel.isMainDepartmentStatus=NO;
- for(DepartmentFrame *frame1 in _departmentList){
- if(frame1.departmentModel.organizationId!=_departmentModel.organizationId){
- frame1.departmentModel.isMainDepartmentStatus=NO;
- }
- }
- }
- }
- else{
- _departmentModel.isMainDepartmentStatus=NO;
- }
-
- [_vTableView reloadData];
- }
- - (void)goBack
- {
- if([self.departmentDelegate respondsToSelector:@selector(recoveryData)])
- {
- [self.departmentDelegate recoveryData];
-
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- @end
|