| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- //
- // SalesOrderGoodsListVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/1/22.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "OrderGoodsListVC.h"
- #import "SalesOrderGoodsListModel.h"
- #import "SalesOrderGoodsListCell.h"
- #import "OrderGoodsDetailVC.h"
- @interface SalesOrderGoodsListVC ()<OrderListDelegate,UITableViewDataSource,
- UITableViewDelegate>{
-
- }
- @end
- @implementation OrderGoodsListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- [self loadData];
- }
- /**
- 导航按钮样式
- */
- -(void)loadNavStyle
- {
- self.navigationItem.title=@"订单商品列表信息";
-
- //返回
- 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{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _vTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0,
- 0,
- self.view.frame.size.width,
- Screen_Height-rectNavHeight-rectStatusHeight)];
-
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vTableView.backgroundColor = [UIColor whiteColor];
- _vTableView.delegate = self;
- _vTableView.dataSource=self;
- [self.view addSubview: _vTableView];
-
- // _bottomView=[UIView new];
- // _bottomView.frame=CGRectMake(0,Screen_Height-rectNavHeight-rectStatusHeight-50, Screen_Width, 50);
- // [self.view addSubview:_bottomView];
- // UIView *bottomSeparator= [UIView new];
- // bottomSeparator.frame=CGRectMake(0,0, Screen_Width, 1);
- // bottomSeparator.backgroundColor = LineBackgroundColor;
- // [_bottomView addSubview:bottomSeparator];
- // _releaseOccupyBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- // _releaseOccupyBtn.frame=CGRectMake(Screen_Width-80, 10, 70,30);
- // [_releaseOccupyBtn setTitle: @"释放占库" forState: UIControlStateNormal];
- // _releaseOccupyBtn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
- // _releaseOccupyBtn.layer.borderColor=[UIColor blackColor].CGColor;
- // _releaseOccupyBtn.layer.borderWidth=1;
- // _releaseOccupyBtn.layer.cornerRadius=10;
- // [_releaseOccupyBtn addTarget:self action:@selector(releaseOccupy) forControlEvents:UIControlEventTouchUpInside];
- // [ _releaseOccupyBtn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
- // [_bottomView addSubview:_releaseOccupyBtn];
- // _occupyBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- // _occupyBtn.frame=CGRectMake(CGRectGetMinX(_releaseOccupyBtn.frame)-80, 10, 70,30);
- // [_occupyBtn setTitle: @"占库" forState: UIControlStateNormal];
- // _occupyBtn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
- // _occupyBtn.layer.borderColor=[UIColor blackColor].CGColor;
- // _occupyBtn.layer.borderWidth=1;
- // _occupyBtn.layer.cornerRadius=10;
- // [_occupyBtn addTarget:self action:@selector(occupy) forControlEvents:UIControlEventTouchUpInside];
- // [ _occupyBtn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
- // [_bottomView addSubview:_occupyBtn];
- //
- // UIButton *toSalesBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- // toSalesBtn.frame=CGRectMake(CGRectGetMinX(_occupyBtn.frame)-80, 10, 70,30);
- // [toSalesBtn setTitle: @"转销售" forState: UIControlStateNormal];
- // toSalesBtn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
- // toSalesBtn.layer.borderColor=[UIColor blackColor].CGColor;
- // toSalesBtn.layer.borderWidth=1;
- // toSalesBtn.layer.cornerRadius=10;
- // [toSalesBtn addTarget:self action:@selector(tosales) forControlEvents:UIControlEventTouchUpInside];
- // [ toSalesBtn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
- // [_bottomView addSubview:toSalesBtn];
- //
- // if([_salesOrderModel.invoiceStatusName isEqualToString:@"完成"]||[_salesOrderModel.invoiceStatusName isEqualToString:@"冲正"]){
- // _occupyBtn.layer.borderColor=NavBarUnEnbleItemColor.CGColor;
- // [_occupyBtn setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- // [_occupyBtn setEnabled:NO];
- // _releaseOccupyBtn.layer.borderColor=NavBarUnEnbleItemColor.CGColor;
- // [_releaseOccupyBtn setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- // [_releaseOccupyBtn setEnabled:NO];
- //
- // toSalesBtn.layer.borderColor=NavBarUnEnbleItemColor.CGColor;
- // [toSalesBtn setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- // [toSalesBtn setEnabled:NO];
- // }
-
- _dataList=[[NSMutableArray alloc]init];
- [self loadData];
-
- }
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)loadData{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetSalesOrderDetailListIPhone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_salesOrderModel.orderId forKey:@"OrderID"];
- _downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onOrderGoodsListFinish:);
- _downManager.onRequestFail = @selector(onOrderGoodsListFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- /**
- 加载总数数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onOrderGoodsListFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- _vTableView.backgroundView = nil;
- [self cancel];
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSArray * infoArr=[dic objectForKey:@"Result"];
- // 返回结果
- if(infoArr!=nil&& infoArr.count>0)
- {
- for (int i = 0; i < infoArr.count; i++) {
- NSDictionary * dic=infoArr[i];
- SalesOrderGoodsListModel *goodsListModel=[SalesOrderGoodsListModel new];
- [goodsListModel ParseDic:dic];
- [self.dataList addObject:goodsListModel];
- }
-
- [_vTableView reloadData];
-
- }
- else{
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- UIView *noDataView=[[UIView alloc]init];
- noDataView.frame=_vTableView.bounds;
- UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
- [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
- [noDataView addSubview:nodataImgView];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
- label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
- label.text = @"无数据";
- label.numberOfLines = 2;
- label.textColor = [UIColor lightGrayColor];
- [noDataView addSubview:label];
-
- // 有刷新数据的时候
- if(_dataList == nil || _dataList.count==0){
- _vTableView.backgroundView =noDataView;
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self cancel];
- [self showReLoginDialog:message];
- }
- else{
- [self cancel];
- [self showAlertViewText:message];
- }
- }
- }
- /**
- 加载总数数据失败回调
-
- @param sender <#sender description#>
- */
- - (void)onOrderGoodsListFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- - (void)onOccupyFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [self cancel];
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- [self showAlertViewText:@"占库成功"];
-
- [ _dataList removeAllObjects];
- [_vTableView reloadData];
- [self loadData];
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
-
- }
- }
- - (void)onOccupyFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- - (void)onNoOccupyFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [self cancel];
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- [self showAlertViewText:@"释放占库成功"];
-
- [ _dataList removeAllObjects];
- [_vTableView reloadData];
- [self loadData];
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
-
- }
- }
- - (void)onNoOccupyFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- -(void) btnCheckPressed:(SalesOrderGoodsListCell *)cell{
- _salesOrderGoodsListModel= _dataList[cell.position];
- _salesOrderGoodsListModel.isCheck=!_salesOrderGoodsListModel.isCheck;
- [cell setCheckBackground:_salesOrderGoodsListModel.isCheck];
- }
- #pragma mark - 委托回调函数
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_dataList 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{
- return 305;
-
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"SalesOrderGoodsListCell";
- SalesOrderGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- if (!cell) {
- cell=[[SalesOrderGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- else
- //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
- {
- while ([cell.contentView.subviews lastObject] != nil) {
- [( UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }
-
- _salesOrderGoodsListModel= [_dataList objectAtIndex:indexPath.row];
- cell.delegate = self;
- cell.position=indexPath.row;
- [cell setSalesGoodsOrder:_salesOrderGoodsListModel orderStatus:_salesOrderModel.status];
- BOOL checked = _salesOrderGoodsListModel.isCheck;
- [cell setCheckBackground:checked];
- return cell;
- }
- /**
- 点击单元格事件
-
- @param tableView tableView description
- @param indexPath indexPath description
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- self.hidesBottomBarWhenPushed=YES;
- OrderGoodsDetailVC *detailVc=[[OrderGoodsDetailVC alloc] init];
- _salesOrderGoodsListModel= [_dataList objectAtIndex:indexPath.row];
- detailVc.goodsListModel = _salesOrderGoodsListModel ;
- detailVc.status= _salesOrderModel.status;
- [self.navigationController pushViewController:detailVc animated:YES];
-
- }
- /**
- 修改:2017-9-25
- 适配机型
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- self.view.backgroundColor = [UIColor whiteColor];
- _vTableView.frame = CGRectMake(0,0,Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height);
- [super viewSafeAreaInsetsDidChange];
- }
- -(void)occupy{
- NSMutableArray *occupyList=[NSMutableArray new];
- if(_dataList!=nil&&_dataList.count>0){
- for(int i=0;i<_dataList.count;i++){
- SalesOrderGoodsListModel *goodsListModel=_dataList[i];
- if(goodsListModel.salesDetailType!=2&&(goodsListModel.factOrderQuantity>goodsListModel.factOccupyQuantity+goodsListModel.factToSalesQuantity)){
- [occupyList addObject:goodsListModel];
- }
-
- }
- }
-
- if(occupyList!=nil&&occupyList.count==0){
- [self showAlertViewText:@"当前订单明细已经全部占库,无需再次占库"];
- }
- else{
- NSString *detailIdList=@"(";
- for(int j=0;j<occupyList.count;j++){
- SalesOrderGoodsListModel *occupyModel=occupyList[j];
- NSString *detailId= [NSString stringWithFormat:@"%@%@",occupyModel.detailId,@","];
- detailIdList= [NSString stringWithFormat:@"%@%@",detailIdList,detailId];
- }
- NSRange range = NSMakeRange(0,detailIdList.length-1);
- detailIdList = [detailIdList substringWithRange:range];
- detailIdList= [NSString stringWithFormat:@"%@%@",detailIdList,@")"];
- [self saveOccupy:detailIdList];
- }
- }
- -(void)releaseOccupy{
- NSMutableArray *selectedNoOccupyList=[NSMutableArray new];
- for(int i=0;i<_dataList.count;i++){
- SalesOrderGoodsListModel *goodsListModel= _dataList[i];
- if(goodsListModel.isCheck){
- [selectedNoOccupyList addObject:goodsListModel];
- }
- }
-
- if(selectedNoOccupyList.count>1){
- [self showAlertViewText:@"最多只能一个商品释放占库"];
- }
- else if(selectedNoOccupyList.count==1){
- SalesOrderGoodsListModel *goodsListModel= selectedNoOccupyList[0];
- if(goodsListModel.factOccupyQuantity>0){
- [self saveReleaseOccupy:goodsListModel.detailId];
- }
- else{
- [self showAlertViewText:@"该商品占库数量为0,不能释放占库"];
- }
- }
- else{
- [self showAlertViewText:@"请勾选释放占库商品"];
- }
-
- }
- -(void)saveReleaseOccupy:(NSString*)detailId{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveReleaseOccupyIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_salesOrderModel.orderId forKey:@"OrderID"];
- [dict setObject:detailId forKey:@"DetailID"];
-
- _downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onNoOccupyFinish:);
- _downManager.onRequestFail = @selector(onNoOccupyFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)saveOccupy:(NSString*)detailIdList{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveOrderOccupyIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_salesOrderModel.orderId forKey:@"OrderID"];
- [dict setObject:detailIdList forKey:@"DetailIDList"];
- NSInteger statusValue =_salesOrderModel.status;
- NSString *status= [NSString stringWithFormat:@"%d",statusValue];
- [dict setObject:status forKey:@"Status"];
- _downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onOccupyFinish:);
- _downManager.onRequestFail = @selector(onOccupyFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 转销售
- */
- - (void)tosales{
- NSMutableArray *list=[NSMutableArray new];
- for(SalesOrderGoodsListModel *model in _dataList){
-
- if(model.isCheck){
- //完全转销售
- if(model.salesDetailType == 1){
- if(model.factToSalesQuantity>0&&model.factOrderQuantity<=model.factToSalesQuantity){
- [self showAlertViewText:[NSString stringWithFormat:@"%@%@",model.goodsName,@"商品已经全部转销售"]];
- return;
- }
- if(model.factOccupyQuantity<=0){
- [self showAlertViewText:[NSString stringWithFormat:@"%@%@",model.goodsName,@"商品没有占库数量"]];
- }
- }
- [list addObject:model];
- }
- }
- double factGoodsAmount=0;
- if(list.count>0){
- NSString *string = @"";
- for(int i = 0;i<list.count;i++){
- SalesOrderGoodsListModel *model =list[i];
- if(i == 0){
- string = [NSString stringWithFormat:@"%@",model.detailId];
- }else{
- string = [NSString stringWithFormat:@"%@,%@",string,model.detailId];
- }
-
- factGoodsAmount+=[model.orderPrice doubleValue]*model.factOrderQuantity;
-
- }
- // if([string length] > 0){
- // NewSaleSlipHomeVC *vc = [[NewSaleSlipHomeVC alloc]init];
- // vc.editFLag = 3;
- // vc.orderId =_salesOrderModel.orderId;
- // vc.customerID =_salesOrderModel.customerID;
- // vc.orderDetailIDs = string;
- // vc.factGoodsAmount=factGoodsAmount;
- // vc.refreshDelegate=self;
- // [self.navigationController pushViewController:vc animated:YES];
- // }
- }else if (list.count == 0) {
- [self showAlertViewText:@"请选择商品"];
- }
- }
- -(void)refreshOrderData{
- [self.navigationController popViewControllerAnimated:YES];
- }
- @end
|