| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- //
- // UseEarnestAmountVC.m
- // IBOSSmini
- //
- // Created by ssl on 2018/2/28.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "UseEarnestAmountVC.h"
- @interface UseEarnestAmountVC ()<UseEarnestAmountCellDelegate>
- @end
- @implementation UseEarnestAmountVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- [self registerKeybordNotification];
-
- }
- -(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;
- if(_earnestList!=nil&&_earnestList.count>0){
- _arr= [[NSMutableArray alloc]initWithArray:_earnestList copyItems:YES];
- [_vTableView reloadData];
- }
- if(_earnestList == nil && _orderId != nil){
- _earnestList = [NSMutableArray array];
- [self loadEarnestDataSource];
- }
- }
- -(void)submitData{
- [self.view endEditing:YES];
- if([self.useEarnestAmountDelegate respondsToSelector:@selector(callbackUseEarnestAmount:)])
- {
- [self.useEarnestAmountDelegate callbackUseEarnestAmount:_earnestList];
-
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(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];
-
-
- }
- #pragma mark - tableView回调
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_earnestList 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 160;
-
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"UseEarnestAmountCell";
- UseEarnestAmountCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
- cell=[[UseEarnestAmountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- cell.position= indexPath.row;
- cell.cellDelegate = self;
- UseEarnestAmountModel *earnestModel = [_earnestList objectAtIndex:indexPath.row];
- [cell parseEarnestInfo:earnestModel];
- return cell;
- }
- - (void)goBack
- {
- if([self.useEarnestAmountDelegate respondsToSelector:@selector(callbackUseEarnestAmount:)])
- {
- [self.useEarnestAmountDelegate callbackUseEarnestAmount:_arr];
-
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- /**
- 使用定金
- */
- -(void)loadEarnestDataSource{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetUseEarnestAmountDataIphone" 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:_orderId forKey:@"OrderID"];
- [dict setObject:@"" forKey:@"SalesID"];
- [dict setObject:[NSString stringWithFormat:@"%d",_editFLag-1] forKey:@"Flg"];
-
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.OnImageDown = @selector(onEarnestLoadFinish:);
- _downManager.OnImageFail = @selector(onEarnestLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)onEarnestLoadFinish:(ASIDownManager *)sender{
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [self stopLoading];
- // 服务器返回数据是否正确
- 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];
- double unusedEarnest = [[dic objectForKey:@"UnusedEarnest"] doubleValue];
- if(unusedEarnest != 0){
- UseEarnestAmountModel *model = [[UseEarnestAmountModel alloc] init];
- if(self.goodsAmount != 0){
- if(self.goodsAmount > unusedEarnest){
- model.moneyInformation = [NSString stringWithFormat:@"%.4f",unusedEarnest];
- self.goodsAmount -= unusedEarnest;
- }else{
- model.moneyInformation = [NSString stringWithFormat:@"%.4f",self.goodsAmount];
- self.goodsAmount -= self.goodsAmount;
- }
- }else{
- model.moneyInformation = @"0";
- }
- NSString *settlementType = [dic objectForKey:@"SettlementType"];
- NSString *settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
- NSString *unusedEarnest = [NSString stringWithFormat:@"%.4f",[[dic objectForKey:@"UnusedEarnest"] doubleValue]];
- model.settlementType = settlementType;
- model.settlementTypeName = settlementTypeName;
- model.unUserdEarnest = unusedEarnest;
- [_earnestList addObject:model];
- }
-
- }
- if(_earnestList.count>0){
- _arr= [[NSMutableArray alloc]initWithArray:_earnestList copyItems:YES];
- }
- [_vTableView reloadData];
- }
- }
-
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
- }
- }
- -(void)onEarnestLoadFail:(ASIDownManager *)sender{
- [self stopLoading];
- [self showAlertViewText:@"加载失败"];
- }
- -(void)update:(int) position flag:(int) flag text:(NSString *) str{
- UseEarnestAmountModel *model = [self.earnestList objectAtIndex:position];
- if(flag == 1){
- model.moneyInformation = str;
- }else{
- model.remarks = str;
- }
- }
- // 键盘弹出改变tableview高度
- - (void)registerKeybordNotification {
-
- NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
-
- [notification removeObserver:self];
-
- [notification addObserver:self
-
- selector:@selector(showKeyboard:)
-
- name:UIKeyboardWillShowNotification
-
- object:nil];
-
- [notification addObserver:self
-
- selector:@selector(hideKeyboard:)
-
- name:UIKeyboardWillHideNotification
-
- object:nil];
-
- #ifdef __IPHONE_5_0
-
- // 5.0以上系统中文键盘高度与4.0系统不一样
-
- float version = [[[UIDevice currentDevice] systemVersion] floatValue];
-
- if (version >= 5.0) {
-
- [notification addObserver:self
-
- selector:@selector(showKeyboard:)
-
- name:UIKeyboardWillChangeFrameNotification
-
- object:nil];
-
- }
-
- #endif
-
- }
- - (void)showKeyboard:(NSNotification *)notification {
-
- NSDictionary *userInfo = [notification userInfo];
-
- NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
-
- CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
-
- CGFloat height = CGRectGetHeight(self.view.frame) - keyboardHeight;
-
-
-
- /* 使用动画效果,过度更加平滑 */
-
- [UIView beginAnimations:nil context:nil];
-
- [UIView setAnimationDuration:0.1];
-
- {
-
- CGRect rect = _vTableView.frame;
-
- rect.size.height = height;
-
- _vTableView.frame = rect;
-
- }
-
- [UIView commitAnimations];
-
- }
- - (void)hideKeyboard:(NSNotification *)notification {
-
- [UIView beginAnimations:nil context:nil];
-
- [UIView setAnimationDuration:0.1];
-
- {
-
- CGRect rect = _vTableView.frame;
-
- rect.size.height = CGRectGetHeight(self.view.frame) ;
-
- _vTableView.frame = rect;
-
- }
-
- [UIView commitAnimations];
-
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
- if(scrollView.isDragging){
- [self.view endEditing:YES];
- }
- }
- @end
|