|
@@ -13,8 +13,13 @@
|
|
|
#import "HttpRequest.h"
|
|
|
#import "UIActionSheet+NTESBlock.h"
|
|
|
#import "User.h"
|
|
|
+#import "TradeInputContainer.h"
|
|
|
+#import "TradePublishManager.h"
|
|
|
+#import "UIView+Toast.h"
|
|
|
+#import "TradeTopBarItem.h"
|
|
|
|
|
|
-@interface TradeViewController () <UIScrollViewDelegate>
|
|
|
+
|
|
|
+@interface TradeViewController () <UIScrollViewDelegate, TradeInputDelegate, TradePublishDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataList;
|
|
|
@property (nonatomic, assign) BOOL isFetching;
|
|
@@ -24,6 +29,19 @@
|
|
|
|
|
|
@property (nonatomic, strong) NSString *district;
|
|
|
|
|
|
+@property (nonatomic, strong) UIView *tradePublishView;
|
|
|
+@property (nonatomic, strong) UIView *tradeContainer;
|
|
|
+@property (nonatomic, strong) TradeInputContainer *tradeInput;
|
|
|
+@property (nonatomic, strong) UIButton *supplyBtn;
|
|
|
+@property (nonatomic, strong) UIButton *demandBtn;
|
|
|
+@property (nonatomic, strong) UILabel *balanceLabel;
|
|
|
+@property (nonatomic, strong) UIButton *balanceBtn;
|
|
|
+
|
|
|
+
|
|
|
+@property (nonatomic,strong) TradeTopBarItem *tradeItem1;
|
|
|
+@property (nonatomic,strong) TradeTopBarItem *tradeItem2;
|
|
|
+@property (nonatomic,strong) NSTimer *timer;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation TradeViewController
|
|
@@ -33,16 +51,126 @@ float postHeight = 30;
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+
|
|
|
+ [self tableView];
|
|
|
+
|
|
|
+ UIButton *showInputBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ showInputBtn.frame = CGRectMake(self.view.width - 65, self.view.height-115, 40, 40);
|
|
|
+ [showInputBtn setImage:[UIImage imageNamed:@"发布交易贴"] forState:UIControlStateNormal];
|
|
|
+ [showInputBtn addTarget:self action:@selector(showTradeInput:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.view addSubview:showInputBtn];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ _tradePublishView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
|
|
|
+ [self.view addSubview:_tradePublishView];
|
|
|
+
|
|
|
+ UIButton *btnMask = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ btnMask.backgroundColor = UIColorFromRGBA(0x000000, 0.5);
|
|
|
+ btnMask.frame = CGRectMake(0, 0, self.view.width, self.view.height);
|
|
|
+ [btnMask addTarget:self action:@selector(hideTradeInput:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_tradePublishView addSubview:btnMask];
|
|
|
+
|
|
|
+
|
|
|
+ float tabbarHeight = self.tabBarController.tabBar.frame.size.height;
|
|
|
+ _tradeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tradePublishView.width, 272)];
|
|
|
+ _tradeContainer.bottom = _tradePublishView.bottom - tabbarHeight;
|
|
|
+ [_tradePublishView addSubview:_tradeContainer];
|
|
|
+
|
|
|
+
|
|
|
+ UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ btn.backgroundColor = UIColor.whiteColor;
|
|
|
+ btn.frame = CGRectMake(0, 0, _tradeContainer.width, _tradeContainer.height);
|
|
|
+ [btn addTarget:self action:@selector(hideTradeInput:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_tradeContainer addSubview:btn];
|
|
|
+
|
|
|
+
|
|
|
+ UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 100, 30)];
|
|
|
+ titleLabel.text = @"需求/礼物赠送";
|
|
|
+ titleLabel.textColor = UIColor.grayColor;
|
|
|
+ [titleLabel setFont:[UIFont systemFontOfSize:14]];
|
|
|
+ [_tradeContainer addSubview:titleLabel];
|
|
|
+
|
|
|
+ UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ rechargeBtn.frame = CGRectMake(_tradeContainer.width - 10 - 50, 8, 50, 30);
|
|
|
+ rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
|
+ [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
|
|
|
+ UIColor *rechargeBtnColor = [UIColor colorWithRed:(51.0 / 255.0) green:(205.0 / 255.0) blue:(153.0 / 255.0) alpha:1.0];
|
|
|
+ [rechargeBtn setTitleColor:rechargeBtnColor forState:UIControlStateNormal];
|
|
|
+ [rechargeBtn addTarget:self action:@selector(showRecharge:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_tradeContainer addSubview:rechargeBtn];
|
|
|
+
|
|
|
+
|
|
|
+ _balanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_tradeContainer.width - 10 - 50 - 120, 8, 120, 30)];
|
|
|
+ _balanceLabel.font = [UIFont systemFontOfSize:14];
|
|
|
+ _balanceLabel.textAlignment = NSTextAlignmentRight;
|
|
|
+ [_tradeContainer addSubview:_balanceLabel];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ UIView *sep1 = [[UIView alloc] initWithFrame:CGRectMake(0, 45, _tradeContainer.width, .5)];
|
|
|
+ sep1.backgroundColor = UIColor.lightGrayColor;
|
|
|
+ [_tradeContainer addSubview:sep1];
|
|
|
+
|
|
|
+
|
|
|
+ _demandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ _demandBtn.frame = CGRectMake(_tradeContainer.centerX - 80, 50, 60, 35);
|
|
|
+ [_demandBtn setImage:[UIImage imageNamed:@"聊天3_03"] forState:UIControlStateNormal];
|
|
|
+ [_demandBtn setTitle:@" 需求" forState:UIControlStateNormal];
|
|
|
+ [_demandBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
|
|
|
+ [_demandBtn setTitleColor:UIColor.grayColor forState:UIControlStateNormal];
|
|
|
+ [_demandBtn addTarget:self action:@selector(toggleDemand:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_tradeContainer addSubview:_demandBtn];
|
|
|
+
|
|
|
+
|
|
|
+ _supplyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ _supplyBtn.frame = CGRectMake(_tradeContainer.centerX+20, 50, 60, 35);
|
|
|
+ [_supplyBtn setImage:[UIImage imageNamed:@"聊天3_03"] forState:UIControlStateNormal];
|
|
|
+ [_supplyBtn setTitle:@" 供求" forState:UIControlStateNormal];
|
|
|
+ [_supplyBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
|
|
|
+ [_supplyBtn setTitleColor:UIColor.grayColor forState:UIControlStateNormal];
|
|
|
+ [_supplyBtn addTarget:self action:@selector(toggleSupply:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_tradeContainer addSubview:_supplyBtn];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ UIView *sep2 = [[UIView alloc] initWithFrame:CGRectMake(0, 89, _tradeContainer.width, .5)];
|
|
|
+ sep2.backgroundColor = UIColor.lightGrayColor;
|
|
|
+ [_tradeContainer addSubview:sep2];
|
|
|
+
|
|
|
+
|
|
|
+ _tradeInput = [[TradeInputContainer alloc] initWithFrame:CGRectMake(0, 90, _tradeContainer.width, _tradeContainer.height - 90)];
|
|
|
+ _tradeInput.delegate = self;
|
|
|
+ [_tradeContainer addSubview:_tradeInput];
|
|
|
+
|
|
|
+
|
|
|
+ [self hideTradeInput:nil];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ _tradeItem1 = [[TradeTopBarItem alloc] initWithFrame:CGRectMake(0, 64, self.view.width, 40)];
|
|
|
+ _tradeItem1.hidden = YES;
|
|
|
+ [self.view addSubview:_tradeItem1];
|
|
|
+ _tradeItem2 = [[TradeTopBarItem alloc] initWithFrame:CGRectMake(0, _tradeItem1.bottom-5, self.view.width, 40)];
|
|
|
+ _tradeItem2.hidden = YES;
|
|
|
+ [self.view addSubview:_tradeItem2];
|
|
|
+
|
|
|
+ _timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(requestLastTradeDataList) userInfo:nil repeats:YES];
|
|
|
}
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
[super didReceiveMemoryWarning];
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
+
|
|
|
+ [_timer invalidate];
|
|
|
}
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated{
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
+ [_timer setFireDate:[NSDate distantPast]];
|
|
|
+
|
|
|
User *user = [User sharedInfo];
|
|
|
|
|
|
if((_district && ![_district isEqualToString:user.district]) || (!_district && user.district))
|
|
@@ -109,9 +237,18 @@ float postHeight = 30;
|
|
|
UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(onTouchSearch:)];
|
|
|
|
|
|
[navItem setRightBarButtonItems:@[rightItem, searchItem]];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ _balanceLabel.text = [NSString stringWithFormat:@"余额:%d", [User sharedInfo].coin];
|
|
|
}
|
|
|
|
|
|
|
|
|
+- (void)viewWillDisappear:(BOOL)animated{
|
|
|
+ [super viewWillDisappear:animated];
|
|
|
+ [_timer setFireDate:[NSDate distantFuture]];
|
|
|
+}
|
|
|
+
|
|
|
- (void)relocaltion{
|
|
|
UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
|
UIViewController *next = (UIViewController *)[board instantiateViewControllerWithIdentifier:@"CityPicker"];
|
|
@@ -328,4 +465,147 @@ float postHeight = 30;
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+- (void)showRecharge:(int)sender
|
|
|
+{
|
|
|
+ UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
|
+ UIViewController *next = [board instantiateViewControllerWithIdentifier:@"Recharge"];
|
|
|
+ [self.navigationController pushViewController:next animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)showTradeInput:(id)sender{
|
|
|
+ [_tradePublishView setHidden:NO];
|
|
|
+ [_tradeInput reset];
|
|
|
+ [self toggleDemand:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)hideTradeInput:(id)sender{
|
|
|
+ [_tradePublishView setHidden:YES];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)toggleDemand:(id)sender{
|
|
|
+
|
|
|
+ _tradeInput.tradeType = (int)TradeTypeDemand;
|
|
|
+ [_demandBtn setImage:[UIImage imageNamed:@"聊天3_05"] forState:UIControlStateNormal];
|
|
|
+ [_supplyBtn setImage:[UIImage imageNamed:@"聊天3_03"] forState:UIControlStateNormal];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)toggleSupply:(id)sender{
|
|
|
+
|
|
|
+ _tradeInput.tradeType = (int)TradeTypeSupply;
|
|
|
+ [_demandBtn setImage:[UIImage imageNamed:@"聊天3_03"] forState:UIControlStateNormal];
|
|
|
+ [_supplyBtn setImage:[UIImage imageNamed:@"聊天3_05"] forState:UIControlStateNormal];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority type:(int)type{
|
|
|
+
|
|
|
+ if((!msg || msg.length == 0) && picArr.count == 0)
|
|
|
+ {
|
|
|
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"你还什么都没说呢" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
|
|
|
+ [alert show];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ TradePublishManager *tradePublishManager = [[TradePublishManager alloc] init];
|
|
|
+ tradePublishManager.delegate = self;
|
|
|
+ [tradePublishManager tradePublish:msg picArr:picArr priority:priority tradeType:type];
|
|
|
+
|
|
|
+ [self hideTradeInput:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tradePublishResult:(BOOL)success{
|
|
|
+ if(success)
|
|
|
+ {
|
|
|
+ [self reset];
|
|
|
+ [self fetchDataList];
|
|
|
+ [self.view makeToast:@"发布成功" duration:2 position:CSToastPositionCenter];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [self.view makeToast:@"发布失败" duration:2 position:CSToastPositionCenter];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+- (void)requestLastTradeDataList{
|
|
|
+ NSLog(@"updateGiftTopItem");
|
|
|
+
|
|
|
+ [[HttpRequest shared] tradeLatestList:^(NSMutableArray * _Nullable dataList) {
|
|
|
+
|
|
|
+ for(int i=0; i<dataList.count; i++)
|
|
|
+ {
|
|
|
+ NSMutableDictionary *data = [dataList objectAtIndex:i];
|
|
|
+ NSString *province = [data objectForKey:@"province"];
|
|
|
+ NSString *tradeId = [data objectForKey:@"id"];
|
|
|
+
|
|
|
+ if([[User sharedInfo] isNewTradeGot:province dataId:tradeId]){
|
|
|
+
|
|
|
+ if(!_tradeItem1.isHidden && !_tradeItem2.isHidden)
|
|
|
+ {
|
|
|
+ [_tradeItem1 setInfo:_tradeItem2.infoDict];
|
|
|
+ _tradeItem1.timeCount = _tradeItem2.timeCount;
|
|
|
+
|
|
|
+ [_tradeItem2 setInfo:data];
|
|
|
+ _tradeItem2.timeCount = 0;
|
|
|
+ }
|
|
|
+ else if(!_tradeItem1.isHidden && _tradeItem2.isHidden)
|
|
|
+ {
|
|
|
+ [_tradeItem2 setInfo:data];
|
|
|
+ [_tradeItem2 setHidden:NO];
|
|
|
+ _tradeItem2.timeCount = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [_tradeItem1 setInfo:data];
|
|
|
+ [_tradeItem1 setHidden:NO];
|
|
|
+ _tradeItem1.timeCount = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [self updateTradeTopItem];
|
|
|
+ } failure:^{
|
|
|
+ [self updateTradeTopItem];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateTradeTopItem{
|
|
|
+
|
|
|
+ NSLog(@"updateGiftTopItem");
|
|
|
+
|
|
|
+ int hideTimeCount = 1;
|
|
|
+
|
|
|
+ if(!_tradeItem1.isHidden){
|
|
|
+ _tradeItem1.timeCount++;
|
|
|
+ if(_tradeItem1.timeCount > hideTimeCount)
|
|
|
+ {
|
|
|
+ [_tradeItem1 setHidden:YES];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!_tradeItem2.isHidden){
|
|
|
+ _tradeItem2.timeCount++;
|
|
|
+ if(_tradeItem2.timeCount > hideTimeCount)
|
|
|
+ {
|
|
|
+ [_tradeItem2 setHidden:YES];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(!_tradeItem2.isHidden && _tradeItem1.isHidden)
|
|
|
+ {
|
|
|
+ [_tradeItem1 setInfo:_tradeItem2.infoDict];
|
|
|
+ _tradeItem1.timeCount = _tradeItem2.timeCount;
|
|
|
+ [_tradeItem1 setHidden:NO];
|
|
|
+
|
|
|
+ [_tradeItem2 setHidden:YES];
|
|
|
+ }
|
|
|
+}
|
|
|
@end
|