| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- //
- // NewOrderGoodsDetailVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/1/24.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "NewOrderGoodsDetailVC.h"
- @interface NewOrderGoodsDetailVC ()
- @end
- @implementation NewOrderGoodsDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _inventoryGoodsDetailList=[[NSMutableArray alloc]init];
- _inventoryGoodsDetailDeleteList=[[NSMutableArray alloc]init];
- [self initSlideSlip];
- [self initUI];
- }
- -(void)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- UIView *topSeparatorView = [UIView new];
- topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
- topSeparatorView.backgroundColor = LineBackgroundColor;
- [self.view addSubview:topSeparatorView];
-
- CGFloat height = 40;
- UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame)+5, Screen_Width, 50)];
- searchView.backgroundColor = [UIColor whiteColor];
- _btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
- _btnSearch.frame = CGRectMake(20, 5, Screen_Width-40, height);
- _btnSearch.layer.cornerRadius = 6.0f;
- [_btnSearch setTitle:@"搜索商品" forState:UIControlStateNormal];
- [_btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- _btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
- _btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
- _btnSearch.backgroundColor = LineBackgroundColor;
- [_btnSearch addTarget:self action:@selector(goodsSearch) forControlEvents:UIControlEventTouchUpInside];
- [searchView addSubview:_btnSearch];
- [self.view addSubview:searchView];
-
- // UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom];
- // scan.frame=CGRectMake(searchView.frame.size.width-35,8,35,35);
- // scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
- // [scan setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
- // [searchView addSubview:scan];
- [self.view addSubview:searchView];
- // [scan addTarget:self action:@selector(btnScanCilck) forControlEvents:UIControlEventTouchUpInside];
- UIView *middleSeparatorView = [UIView new];
- middleSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(searchView.frame)+5, Screen_Width, 10);
- middleSeparatorView.backgroundColor = LineBackgroundColor;
- [self.view addSubview:middleSeparatorView];
- _vDetailTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0,
- CGRectGetMaxY(middleSeparatorView.frame),
- self.view.frame.size.width,
- Screen_Height - CGRectGetMaxY(middleSeparatorView.frame))];
-
- _vDetailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vDetailTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vDetailTableView.backgroundColor = [UIColor whiteColor];
- _vDetailTableView.delegate = self;
- _vDetailTableView.dataSource=self;
- [self.view addSubview:_vDetailTableView];
- _vDetailTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
- //键盘将要显示时候的通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- //键盘将要结束时候的通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
- }
- /**
- 扫描点击事件
- */
- -(void)btnScanCilck{
- ScanViewController *scanVc=[[ScanViewController alloc]init];
- scanVc.rootVC=self;
- [self.orderNav pushViewController:scanVc animated:YES];
- }
- /**
- 抽屉初始化
- */
- - (void)initSlideSlip{
- // 抽屉对象
- __weak typeof(self) weakself=self;
- self.filterController = [[SideSlipFilterController alloc]
- initWithSponsor:self
- resetBlock:^(NSArray *dataList) {
- for (SideSlipModel *model in dataList) {
-
- model.selectedItemList = nil;
- model.customDict = nil;
- }
- } commitBlock:^(NSArray *dataList) {
- SideSlipModel *serviceRegionModel = dataList[0];
- InventorySearchModel *m = [serviceRegionModel.customDict objectForKey:INVENTORY_SEARCH_RANGE_MODEL];
-
-
- [weakself.filterController dismiss];
- self.hidesBottomBarWhenPushed = YES;
- InventoryGoodsSearchListVC* inventoryGoodsSearchVc=[[InventoryGoodsSearchListVC alloc]init];
- inventoryGoodsSearchVc.brandId = m.brandId;
- inventoryGoodsSearchVc.goodsCode = m.goodsCode;
- inventoryGoodsSearchVc.goodsName= m.goodsName;
- inventoryGoodsSearchVc.onlyCode = m.onlyCode;
- inventoryGoodsSearchVc.warehouseAreaId = m.warehouseId;
- inventoryGoodsSearchVc.isFilterQuantityEqZero = m.isfilterQuantityEqZero;
- inventoryGoodsSearchVc.orderListDelegate=self;
- [self.orderNav pushViewController:inventoryGoodsSearchVc animated:YES];
- }];
- _filterController.animationDuration = AnimationDuration;
- _filterController.hasHeadView = YES;
- _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
- _filterController.dataList = [self packageDataList];
- }
- /**
- 数据源
-
- @return <#return value description#>
- */
- - (NSArray *)packageDataList {
- NSMutableArray *dataArray = [NSMutableArray array];
- SideSlipModel *model = [[SideSlipModel alloc] init];
- model.containerCellClass = @"OrderGoodsDetailSearchCell";
- model.regionTitle = @"查询条件";
-
- [dataArray addObject:model];
- return [dataArray mutableCopy];
- }
- -(void)goUsePosition:(NSInteger)position{
- self.hidesBottomBarWhenPushed = YES;
- CustomerReportTextVC *tc=[[CustomerReportTextVC alloc] init];
- _cellIndex=position;
- tc.delegate=self;
- tc.showDialogViewTag=ReportUsePosition;
- [self.orderNav pushViewController:tc animated:YES];
- }
- - (void)customerReportTextDoneDatas:(CustomerReportTextInfoModel *)model CustomerReport:(CustomerReport)cr{
- if (model==nil) {
- return;
- }
-
- if(cr==ReportUsePosition){
- _usePositionId=model.idCode;
- _usePositionName=model.name;
- InventoryListModel *inventoryModel= _inventoryGoodsDetailList[_cellIndex];
- inventoryModel.usePositionId=_usePositionId;
- inventoryModel.usePositionName=_usePositionName;
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_cellIndex inSection:0];
- //2.将indexPath添加到数组
- NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
- //3.传入数组,对当前cell进行刷新
- [_vDetailTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
- }
-
- }
- -(void)showNewOrderDetailError:(NSString*)errorMsg{
- [self showAlertViewText:errorMsg];
- }
- -(void)updateNewOrderGoodsDetail:(NewOrderGoodsDetailCell*)cell textField:(UITextField *)field{
- _inventoryGoodsDetailList[cell.cellIndex]=cell.inventoryModel;
-
- if(field.tag==1004)
- {
- InventoryListModel *goodsModel= _inventoryGoodsDetailList[cell.cellIndex];
- NSString *combinationQuantity=field.text;
- NSString *currentPromotionDetailId=goodsModel.promotionDetailId;
- NSString *currentOpCombPromotionFlag=goodsModel.opCombPromotionFlag;
- if(currentOpCombPromotionFlag==nil)
- {
- currentOpCombPromotionFlag=@"";
- }
- for(int i=0;i<_inventoryGoodsDetailList.count;i++)
- {
- InventoryListModel *inventModel=[_inventoryGoodsDetailList objectAtIndex:i];
- NSString *promotionDetailId=inventModel.promotionDetailId;
- NSString *opCombPromotionFlag=inventModel.opCombPromotionFlag;
- if(opCombPromotionFlag==nil||[opCombPromotionFlag isEqualToString:@""])
- {
- opCombPromotionFlag=@"";
- }
- if((currentPromotionDetailId!=nil&¤tPromotionDetailId.length>0)&&(promotionDetailId!=nil&&promotionDetailId.length>0))
- {
- if(([currentPromotionDetailId intValue]==[promotionDetailId intValue])&&([currentOpCombPromotionFlag isEqualToString:opCombPromotionFlag]))
- {
- NSString *goodsQuantityHide=inventModel.goodsQuantityHide;
- int decimalPlaces=[inventModel.decimalPlaces intValue];
- double combinationQuantityValue= [combinationQuantity doubleValue];
- double goodsQuantity=[goodsQuantityHide doubleValue]*combinationQuantityValue;
- NSString *format=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
- NSString *goodsQuantityStr=[NSString stringWithFormat:format,goodsQuantity];
- [inventModel setSalesQuantity:goodsQuantityStr];
- [inventModel setCombinationQuantity:combinationQuantity];
- OrderQuantity *orderQuantity=[OrderQuantity new];
- [orderQuantity setSalesOrderDetailBoxAndPiece:[inventModel.salesQuantity intValue] inventoryModel:inventModel];
-
-
-
- }
- }
- }
- }
-
- if(field.tag==1005)
- {
- InventoryListModel *goodsModel= _inventoryGoodsDetailList[cell.cellIndex];
- if(goodsModel.circulateType==1&&goodsModel.acreageFlag)
- {
- NSString *markedPrice=goodsModel.markedPrice;
- if(goodsModel.acreagePrice!=nil&&goodsModel.acreagePrice.length>0)
- {
- if([goodsModel.acreagePrice doubleValue]!=0)
- {
- double salesPrice=[goodsModel.acreagePrice doubleValue]*goodsModel.acreage;
- [goodsModel setSalesPrice:[NSString stringWithFormat:@"%lf",salesPrice]];
- double discount=[goodsModel.acreagePrice doubleValue]/[goodsModel.markedPrice doubleValue]*100;
- NSString *discountStr=[NSString stringWithFormat:@"%.2f",discount];
- [goodsModel setDiscount:discountStr];
- }
- else
- {
- [goodsModel setDiscount:@"100"];
- }
- }
-
- else
- {
- if([markedPrice doubleValue]!=0)
- {
- [goodsModel setDiscount:@"0"];
- }
- else
- {
- [goodsModel setDiscount:@"100"];
- }
- }
- }
- }
-
- [_vDetailTableView reloadData];
-
- if(field.tag==1001||field.tag==1002||field.tag==1004||field.tag==1005){
- [self.homeVC calculate:@"orderDetail"];
- }
-
-
- }
- -(void)deleteOrderDetail:(NSInteger)cellIndex{
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要删除?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-
- }];
- UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- InventoryListModel *inventoryModel=self->_inventoryGoodsDetailList[cellIndex];
- NSString *flag= inventoryModel.flag;
- NSString *opCombPromotionFlag=inventoryModel.opCombPromotionFlag;
- NSString *promotionType=inventoryModel.promotionTypeDetailId;
- NSString *promotionDetailId=inventoryModel.promotionDetailId;
- if(self->_editFlag){
-
-
- if([flag isEqualToString:@"1"]){
- [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
- }
- else if([flag isEqualToString:@"2"]){
- inventoryModel.flag=@"3";
- [self->_inventoryGoodsDetailDeleteList addObject:inventoryModel];
- [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
- }
- }
- else
-
- {
-
-
- if((promotionType!=nil&&promotionType.length>0)&&(promotionDetailId!=nil&&promotionDetailId.length>0))
- {
- if([promotionType intValue]==1){
-
- [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
-
- }
-
-
- if([promotionType intValue]==2){
- for(long i=self->_inventoryGoodsDetailList.count-1;i>=0;i--)
- {
- InventoryListModel *goodsModel=[self->_inventoryGoodsDetailList objectAtIndex:i];
- if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)
- {
- if( [promotionDetailId intValue]
- == [goodsModel.promotionDetailId intValue] )
- {
- [ self->_inventoryGoodsDetailList removeObjectAtIndex:i];
- }
- }
- }
- }
-
- if([promotionType intValue]==5)
- {
- for(long i=self->_inventoryGoodsDetailList.count-1;i>=0;i--)
- {
- InventoryListModel *goodsModel=[self->_inventoryGoodsDetailList objectAtIndex:i];
- if((goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)&&(goodsModel.opCombPromotionFlag!=nil&&goodsModel.opCombPromotionFlag.length>0))
- {
-
- if(([promotionDetailId intValue]==[goodsModel.promotionDetailId intValue])&&[opCombPromotionFlag isEqualToString:goodsModel.opCombPromotionFlag])
- {
- [self->_inventoryGoodsDetailList removeObjectAtIndex:i];
- }
-
- } } }
-
- }
- else{
- [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
- }
-
-
- }
-
- [self->_vDetailTableView reloadData];
- [self.homeVC calculate:@"orderDetail"];
-
- }];
- UIColor *cancelColor=[UIColor blackColor];
- UIColor *sureColor=[UIColor redColor];
- [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
- [otherAction setValue:sureColor forKey:@"titleTextColor"];
- [alertController addAction:cancelAction];
- [alertController addAction:otherAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- -(void)keyboardWillShow:(NSNotification *)sender{
- //获得键盘的尺寸
- CGRect keyBoardRect=[sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- //当键盘将要显示时,将tableView的下边距增跟改为键盘的高度
- self.vDetailTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
- }
- -(void)keyboardDidHide:(NSNotification *)sender{
- //当键盘将要消失时,边距还原初始状态
- self.vDetailTableView.contentInset = UIEdgeInsetsZero;
- }
- -(void)goodsSearch{
- [_filterController showPagerView:self.orderNav];
- }
- -(void)showCheckedInventoryList:(NSMutableArray*)inventoryList{
- if(_editFlag){
- for(int i=0;i<inventoryList.count;i++){
- InventoryListModel *inventoryModel=inventoryList[i];
- Boolean ii=NO;
- Boolean jj=NO;
- if(_inventoryGoodsDetailList!=nil&&_inventoryGoodsDetailList.count>0){
- for(int j=0;j<_inventoryGoodsDetailList.count;j++){
- InventoryListModel *detailModel=_inventoryGoodsDetailList[j];
- if([inventoryModel.inventoryId isEqualToString:detailModel.inventoryId]){
- double salesQuantityValue= [detailModel.salesQuantity doubleValue];
- ++salesQuantityValue;
- detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
- ];
- ii=YES;
- }
- }
- }
-
- if(!ii){
- for(NSInteger j=_inventoryGoodsDetailDeleteList.count-1;j>=0;j--){
- InventoryListModel *deleteInventoryModel=_inventoryGoodsDetailDeleteList[j];
- if([inventoryModel.inventoryId isEqualToString:deleteInventoryModel.inventoryId]){
- deleteInventoryModel.flag=@"2";
- deleteInventoryModel.salesPrice=inventoryModel.salesPrice;
- deleteInventoryModel.salesQuantity=@"1";
- [_inventoryGoodsDetailList addObject:deleteInventoryModel];
- [_inventoryGoodsDetailDeleteList removeObjectAtIndex:j];
- jj=YES;
- }
- }
- if(!jj){
- inventoryModel.flag=@"1";
- [_inventoryGoodsDetailList addObject:inventoryModel];
- }
- }
- }
- }
- else{
- for(int i=0;i<inventoryList.count;i++){
- InventoryListModel *inventoryCheckedModel=inventoryList[i];
- Boolean ii=NO;
- if(_inventoryGoodsDetailList!=nil&&_inventoryGoodsDetailList.count>0){
-
- for(int j=0;j<_inventoryGoodsDetailList.count;j++){
- InventoryListModel *detailModel= _inventoryGoodsDetailList[j];
- if([inventoryCheckedModel.inventoryId isEqualToString:detailModel.inventoryId]){
- double salesQuantityValue= [detailModel.salesQuantity doubleValue];
- ++salesQuantityValue;
- detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
- ];
- ii=YES;
-
- }
- }
- }
-
- if(!ii){
- [_inventoryGoodsDetailList addObject:inventoryCheckedModel];
-
- }
-
- }
- }
-
-
- [_vDetailTableView reloadData];
- [self.homeVC calculate:@"orderDetail"];
- }
- #pragma mark - 委托回调函数
- #pragma mark - tableView回调
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_inventoryGoodsDetailList 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 417;
-
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"InventoryListCell";
- NewOrderGoodsDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- cell=[[NewOrderGoodsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- cell.orderDelegate=self;
- cell.cellIndex=indexPath.row;
- InventoryModel *inventoryModel= [_inventoryGoodsDetailList objectAtIndex:indexPath.row];
- [cell setInventoryCell:inventoryModel editStatus:_editStatus ContractPriceFlag:_contractPriceValues];
-
- return cell;
- }
- /**
- 扫描回调函数
- @param code <#code description#>
- */
- -(void)reloadDataWithOnlyCode:(NSString *)code
- {
- self.hidesBottomBarWhenPushed = YES;
- InventoryGoodsSearchListVC* inventoryGoodsSearchVc=[[InventoryGoodsSearchListVC alloc]init];
- inventoryGoodsSearchVc.barCode=code;
- inventoryGoodsSearchVc.loadFlag=@"scan";
- inventoryGoodsSearchVc.isFilterQuantityEqZero=YES;
- inventoryGoodsSearchVc.orderListDelegate=self;
- [self.orderNav pushViewController:inventoryGoodsSearchVc animated:YES];
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- @end
|