Fenix Wang пре 8 година
родитељ
комит
adca29ca3b
34 измењених фајлова са 1030 додато и 118 уклоњено
  1. BIN
      NIMDemo/NIM.xcworkspace/xcuserdata/Fenix.xcuserdatad/UserInterfaceState.xcuserstate
  2. 12 0
      NIMDemo/NIMDemo.xcodeproj/project.pbxproj
  3. 18 0
      NIMDemo/NIMDemo/CityManager.h
  4. 83 0
      NIMDemo/NIMDemo/CityManager.m
  5. 37 4
      NIMDemo/NIMDemo/Classes/Sections/Session/ViewController/NTESSessionViewController.m
  6. 6 2
      NIMDemo/NIMDemo/GroupTableController.m
  7. 15 0
      NIMDemo/NIMDemo/HttpRequest/HttpRequest.h
  8. 147 0
      NIMDemo/NIMDemo/HttpRequest/HttpRequest.m
  9. 30 0
      NIMDemo/NIMDemo/LocationManager.h
  10. 141 0
      NIMDemo/NIMDemo/LocationManager.m
  11. 2 1
      NIMDemo/NIMDemo/LoginViewController.m
  12. 2 2
      NIMDemo/NIMDemo/RegisterViewController.m
  13. 1 0
      NIMDemo/NIMDemo/SectionTrade/TradeData.h
  14. 1 0
      NIMDemo/NIMDemo/SectionTrade/TradeData.m
  15. 3 0
      NIMDemo/NIMDemo/SectionTrade/TradeDetailViewController.m
  16. 21 7
      NIMDemo/NIMDemo/SectionTrade/TradeModifyViewController.m
  17. 1 0
      NIMDemo/NIMDemo/SectionTrade/TradePublishManager.h
  18. 4 1
      NIMDemo/NIMDemo/SectionTrade/TradePublishManager.m
  19. 6 3
      NIMDemo/NIMDemo/SectionTrade/TradeTableViewCell.m
  20. 137 66
      NIMDemo/NIMDemo/SectionTrade/TradeViewController.m
  21. 46 3
      NIMDemo/NIMDemo/SocialPublishViewController.m
  22. 8 3
      NIMDemo/NIMDemo/User.h
  23. 16 0
      NIMDemo/NIMDemo/User.m
  24. 6 4
      NIMDemo/NIMDemo/ViewController.m
  25. 6 0
      NIMKit/NIMKit.xcodeproj/project.pbxproj
  26. 2 0
      NIMKit/NIMKit/Classes/Protocols/NIMMessageCellProtocol.h
  27. 22 7
      NIMKit/NIMKit/Classes/Sections/Input/GiftInputContainer.m
  28. 4 0
      NIMKit/NIMKit/Classes/Sections/Input/NIMInputView.h
  29. 41 0
      NIMKit/NIMKit/Classes/Sections/Input/NIMInputView.m
  30. 5 2
      NIMKit/NIMKit/Classes/Sections/Input/TradeInputContainer.h
  31. 135 13
      NIMKit/NIMKit/Classes/Sections/Input/TradeInputContainer.m
  32. 27 0
      NIMKit/NIMKit/Classes/Sections/Input/TradePriorityItemData.h
  33. 27 0
      NIMKit/NIMKit/Classes/Sections/Input/TradePriorityItemData.m
  34. 18 0
      NIMKit/NIMKit/Classes/Sections/Session/View/NIMMessageCell.m

BIN
NIMDemo/NIM.xcworkspace/xcuserdata/Fenix.xcuserdatad/UserInterfaceState.xcuserstate


+ 12 - 0
NIMDemo/NIMDemo.xcodeproj/project.pbxproj

@@ -224,6 +224,8 @@
 		C482C3351F14817500EF2B71 /* TradeDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3341F14817500EF2B71 /* TradeDetailViewController.m */; };
 		C482C3381F14B32300EF2B71 /* TradeModifyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3371F14B32300EF2B71 /* TradeModifyViewController.m */; };
 		C482C33B1F14B43A00EF2B71 /* TradeModifyImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C33A1F14B43A00EF2B71 /* TradeModifyImageView.m */; };
+		C482C33E1F15CA8500EF2B71 /* LocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C33D1F15CA8500EF2B71 /* LocationManager.m */; };
+		C482C3471F16360100EF2B71 /* CityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3461F16360100EF2B71 /* CityManager.m */; };
 		C4A734601EE6BBD300D6489D /* GroupMoreTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4A7345F1EE6BBD300D6489D /* GroupMoreTableViewController.m */; };
 		C4A734631EE6D4DE00D6489D /* GroupMoreTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C4A734621EE6D4DE00D6489D /* GroupMoreTableViewCell.m */; };
 		C4A7D3661EE803E7009B5849 /* FriendViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4A7D3651EE803E6009B5849 /* FriendViewController.m */; };
@@ -674,6 +676,10 @@
 		C482C3371F14B32300EF2B71 /* TradeModifyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TradeModifyViewController.m; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/SectionTrade/TradeModifyViewController.m; sourceTree = "<group>"; };
 		C482C3391F14B43A00EF2B71 /* TradeModifyImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TradeModifyImageView.h; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/SectionTrade/TradeModifyImageView.h; sourceTree = "<group>"; };
 		C482C33A1F14B43A00EF2B71 /* TradeModifyImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TradeModifyImageView.m; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/SectionTrade/TradeModifyImageView.m; sourceTree = "<group>"; };
+		C482C33C1F15CA8500EF2B71 /* LocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LocationManager.h; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/LocationManager.h; sourceTree = "<group>"; };
+		C482C33D1F15CA8500EF2B71 /* LocationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LocationManager.m; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/LocationManager.m; sourceTree = "<group>"; };
+		C482C3451F16360100EF2B71 /* CityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CityManager.h; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/CityManager.h; sourceTree = "<group>"; };
+		C482C3461F16360100EF2B71 /* CityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CityManager.m; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/CityManager.m; sourceTree = "<group>"; };
 		C4A7345E1EE6BBD300D6489D /* GroupMoreTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupMoreTableViewController.h; sourceTree = "<group>"; };
 		C4A7345F1EE6BBD300D6489D /* GroupMoreTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupMoreTableViewController.m; sourceTree = "<group>"; };
 		C4A734611EE6D4DE00D6489D /* GroupMoreTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupMoreTableViewCell.h; sourceTree = "<group>"; };
@@ -1814,6 +1820,8 @@
 				C4B6394E1ED57DAB004288FC /* city.plist */,
 				C4B6394F1ED57DAB004288FC /* PSCityPickerView.h */,
 				C4B639501ED57DAB004288FC /* PSCityPickerView.m */,
+				C482C3451F16360100EF2B71 /* CityManager.h */,
+				C482C3461F16360100EF2B71 /* CityManager.m */,
 			);
 			name = CityPicker;
 			sourceTree = "<group>";
@@ -1827,6 +1835,8 @@
 				C40F4C4A1EF15BC7002B197A /* GiftTopBarItem.m */,
 				C482C30E1F0CAE7300EF2B71 /* TradeTopBarItem.h */,
 				C482C30F1F0CAE7300EF2B71 /* TradeTopBarItem.m */,
+				C482C33C1F15CA8500EF2B71 /* LocationManager.h */,
+				C482C33D1F15CA8500EF2B71 /* LocationManager.m */,
 			);
 			name = User;
 			sourceTree = "<group>";
@@ -2211,6 +2221,7 @@
 				61E471331B7D963E00F4A1BF /* NTESSearchLocalHistoryObject.m in Sources */,
 				6173AED81BAAC8F500854D49 /* NTESSignSettingViewController.m in Sources */,
 				61E471201B7D963E00F4A1BF /* NTESCustomNotificationObject.m in Sources */,
+				C482C33E1F15CA8500EF2B71 /* LocationManager.m in Sources */,
 				C4A7D3661EE803E7009B5849 /* FriendViewController.m in Sources */,
 				6173AEC41BAAB94400854D49 /* NTESUserInfoSettingViewController.m in Sources */,
 				C4F1D1601F03DDE500A04B28 /* SocialCommentDetailTableViewCell.m in Sources */,
@@ -2274,6 +2285,7 @@
 				C4B1463C1EF24E6300819893 /* SettingAccountViewController.m in Sources */,
 				61E471611B7D963E00F4A1BF /* NTESNoDisturbTimeCell.m in Sources */,
 				C41B6EFC1EEFB67500AD1F53 /* RechargeItem.m in Sources */,
+				C482C3471F16360100EF2B71 /* CityManager.m in Sources */,
 				6185D2991BAAFBAF0046F90F /* NTESSettingCheckCell.m in Sources */,
 				61E471581B7D963E00F4A1BF /* NTESMutiClientsCell.m in Sources */,
 				61E4718B1B7D96AA00F4A1BF /* NTESClientUtil.m in Sources */,

+ 18 - 0
NIMDemo/NIMDemo/CityManager.h

@@ -0,0 +1,18 @@
+//
+//  CityManager.h
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "TradePriorityItemData.h"
+
+@interface CityManager : NSObject
+
++ (instancetype)shared;
+
+- (TradePriorityType)tradePriorityTypeByTeamName:(NSString *)teamName;
+
+@end

+ 83 - 0
NIMDemo/NIMDemo/CityManager.m

@@ -0,0 +1,83 @@
+//
+//  CityManager.m
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import "CityManager.h"
+
+
+@interface CityManager()
+
+@property (nonatomic, strong) NSMutableDictionary       *cityDict;
+
+@end
+
+@implementation CityManager
+
++ (instancetype)shared
+{
+    static CityManager *shared = nil;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        shared = [[CityManager alloc] init];
+        [shared setUpCityDict];
+    });
+    return shared;
+}
+
+
+- (void)setUpCityDict{
+    
+    _cityDict = [[NSMutableDictionary alloc] init];
+    
+    NSBundle *bundle=[NSBundle mainBundle];
+    NSString *path = [bundle pathForResource:@"city" ofType:@"plist"];
+    NSDictionary *allCityInfo = [[NSDictionary alloc] initWithContentsOfFile:path];
+    
+    
+    for(int i=0; i<allCityInfo.count; i++)
+    {
+        NSDictionary *provinceDict = [allCityInfo objectForKey:[@(i) stringValue]];
+        NSString *province = [[provinceDict allKeys] firstObject];
+        [_cityDict setValue:[@(TradePriorityProvince) stringValue] forKey:province];
+        
+        NSDictionary *cityDict = [[provinceDict allValues] firstObject];
+        for(int j=0; j<cityDict.count; j++)
+        {
+            NSDictionary *districtDict = [cityDict objectForKey:[@(j) stringValue]];
+            NSString *city = [[districtDict allKeys] firstObject];
+            [_cityDict setValue:[@(TradePriorityCity) stringValue] forKey:city];
+            
+            NSArray *districtArr = [[districtDict allValues] firstObject];
+            for(int k=0; k<districtArr.count; k++)
+            {
+                NSString *district = [districtArr objectAtIndex:k];
+                [_cityDict setValue:[@(TradePriorityDistrict) stringValue] forKey:district];
+            }
+        }
+    }
+}
+
+- (TradePriorityType)tradePriorityTypeByTeamName:(NSString *)teamName{
+    
+    int type = [[_cityDict objectForKey:teamName] intValue];
+    
+    if(type == (int)TradePriorityProvince)
+    {
+        return TradePriorityProvince;
+    }
+    else if(type == (int)TradePriorityCity)
+    {
+        return TradePriorityCity;
+    }
+    else if(type == (int)TradePriorityDistrict)
+    {
+        return TradePriorityDistrict;
+    }
+    return TradePriorityCountry;
+}
+
+@end

+ 37 - 4
NIMDemo/NIMDemo/Classes/Sections/Session/ViewController/NTESSessionViewController.m

@@ -59,6 +59,8 @@
 #import "TradeInputContainer.h"
 #import "NIMMessageMaker.h"
 #import "GroupInfoViewController.h"
+#import "NIMInputView.h"
+#import "CityManager.h"
 
 
 @interface NTESSessionViewController ()
@@ -70,7 +72,8 @@ NTESTimerHolderDelegate,
 NIMContactSelectDelegate,
 NIMEventSubscribeManagerDelegate,
 GiftDataSourceDelegate,
-TradeInputDelegate>
+TradeInputDelegate,
+NIMInputDelegate>
 
 @property (nonatomic,strong)    NTESCustomSysNotificationSender *notificaionSender;
 @property (nonatomic,strong)    NTESSessionConfig       *sessionConfig;
@@ -196,6 +199,24 @@ TradeInputDelegate>
         BOOL isSystemTeam = [[User sharedInfo] isSystemTeam:self.session.sessionId];
         giftInput.supplyBtn.hidden = !isSystemTeam;
         giftInput.demandBtn.hidden = !isSystemTeam;
+        
+        if(isSystemTeam)
+        {
+            NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:self.session.sessionId];
+            NSString *teamName = team.teamName;
+            TradePriorityType priorityType = [[CityManager shared] tradePriorityTypeByTeamName:teamName];
+            NSMutableArray *priorityItems = [[NSMutableArray alloc] init];
+            for(int i=0; i<user.tradePriorityItemArr.count; i++)
+            {
+                TradePriorityItemData *priorityItem = [user.tradePriorityItemArr objectAtIndex:i];
+                if(priorityItem.type <= (int)priorityType)
+                {
+                    [priorityItems addObject:priorityItem];
+                }
+            }
+            
+            [giftInput.tradeContainer fillItemData:priorityItems];
+        }
     }
     else if(self.session.sessionType == NIMSessionTypeP2P)
     {
@@ -543,6 +564,15 @@ TradeInputDelegate>
     return YES;
 }
 
+- (BOOL)onLongPressAvatar:(NSString *)userId{
+    
+    NSLog(@"onLongPressAvatar : %@", userId);
+    
+    [self.sessionInputView addAtItem:userId];
+    
+    return YES;
+}
+
 
 #pragma mark - Cell Actions
 - (void)showImage:(NIMMessage *)message
@@ -1101,11 +1131,14 @@ TradeInputDelegate>
 }
 
 
-- (void)hideGiftMovie:(int)sender
+- (void)hideGiftMovie:(id)sender
 {
     _giftMovieContainer.hidden = YES;
 }
 
+- (void)inputTabSelected{
+    [self hideGiftMovie:nil];
+}
 
 - (void)deleteChatCache:(int)sender
 {
@@ -1136,7 +1169,7 @@ TradeInputDelegate>
 
 
 
-- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority type:(int)type{
+- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority priorityType:(int)priorityType type:(int)type{
     
     if((!msg || msg.length == 0) && picArr.count == 0)
     {
@@ -1147,7 +1180,7 @@ TradeInputDelegate>
     
     TradePublishManager *tradePublishManager = [[TradePublishManager alloc] init];
     tradePublishManager.inputView = self.sessionInputView;
-    [tradePublishManager tradePublish:msg picArr:picArr priority:priority tradeType:type];
+    [tradePublishManager tradePublish:msg picArr:picArr priority:priority priorityType:priorityType tradeType:type];
     
 }
 

+ 6 - 2
NIMDemo/NIMDemo/GroupTableController.m

@@ -361,7 +361,10 @@
 
 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
 {
-    [self.locationManager stopUpdatingLocation];
+    User *user = [User sharedInfo];
+    
+    if(user.districtRoomId && user.districtRoomId.length > 0)
+        [self.locationManager stopUpdatingLocation];
     
     NSLog(@"经度:%f", newLocation.coordinate.longitude);
     NSLog(@"纬度:%f", newLocation.coordinate.latitude);
@@ -377,7 +380,6 @@
     }];
     
     
-    User *user = [User sharedInfo];
     if(user.latitude != newLocation.coordinate.latitude || user.longitude != newLocation.coordinate.longitude)
     {
         user.longitude = newLocation.coordinate.longitude;
@@ -456,6 +458,8 @@
                     title = [NSString stringWithFormat:@"%@%@", [title substringWithRange:NSMakeRange(0, 6)], @"..."];
                 }
                 [wself.localBtn setTitle:title forState:UIControlStateNormal];
+                
+                [self gotoTeamChat:user.districtRoomId];
             }
         }
         

+ 15 - 0
NIMDemo/NIMDemo/HttpRequest/HttpRequest.h

@@ -34,6 +34,14 @@
          success:(void (^_Nullable)())success
          failure:(void (^_Nullable)(NSError * _Nullable error))failure;
 
+//location
+- (void)location:(double)longitude
+        latitude:(double)latitude
+         success:(void (^_Nullable)(NSString * _Nullable province, NSString * _Nullable city, NSString * _Nullable district, NSString * _Nullable provinceRoomId, NSString * _Nullable cityRoomId, NSString * _Nullable districtRoomId))success
+         failure:(void (^_Nullable)())failure;
+
+- (void)coordinate2Location:(void (^_Nullable)())success
+                    failure:(void (^_Nullable)())failure;
 
 //social
 - (void)getSocialDataList:(NSString *_Nullable)lastId
@@ -65,6 +73,7 @@
               picArr:(NSMutableArray *_Nullable)picArr
                 type:(int)type
             priority:(int)priority
+        priorityType:(int)priorityType
              success:(void (^_Nullable)())success
              failure:(void (^_Nullable)())failure;
 
@@ -84,6 +93,12 @@
           success:(void (^_Nullable)(NSMutableArray * _Nullable dataList))success
           failure:(void (^_Nullable)())failure;
 
+- (void)tradeSearchList:(NSString *_Nonnull)keyWord
+              tradeSort:(TradeSort)tradeSort
+                   page:(int)page
+                success:(void (^_Nullable)(NSMutableArray * _Nullable dataList))success
+                failure:(void (^_Nullable)())failure;
+
 - (void)tradeLatestList:(void (^_Nullable)(NSMutableArray * _Nullable dataList))success
                 failure:(void (^_Nullable)())failure;
 

+ 147 - 0
NIMDemo/NIMDemo/HttpRequest/HttpRequest.m

@@ -12,25 +12,35 @@
 #import "User.h"
 #import "NTESService.h"
 #import "NTESLoginManager.h"
+#import "TradePriorityItemData.h"
+#import "CityManager.h"
 
 
 @interface HttpRequest()
 
 @property (nonatomic, strong) NSString *urlRoot;
 
+//register & login
 @property (nonatomic, strong) NSString *urlLogin;
 @property (nonatomic, strong) NSString *urlRegister;
 
+//location
+@property (nonatomic, strong) NSString *urlLocation;
+@property (nonatomic, strong) NSString *urlCoordinate2Location;
+
+//social
 @property (nonatomic, strong) NSString *urlSocialDataList;
 @property (nonatomic, strong) NSString *urlSocialLike;
 @property (nonatomic, strong) NSString *urlSocialLikeList;
 @property (nonatomic, strong) NSString *urlSocialComment;
 @property (nonatomic, strong) NSString *urlSocialCommentList;
 
+//trade
 @property (nonatomic, strong) NSString *urlTradePublish;
 @property (nonatomic, strong) NSString *urlTradeEdit;
 @property (nonatomic, strong) NSString *urlTradeDelete;
 @property (nonatomic, strong) NSString *urlTradeDataList;
+@property (nonatomic, strong) NSString *urlTradeSearchDataList;
 @property (nonatomic, strong) NSString *urlTradeLatestDataList;
 @property (nonatomic, strong) NSString *urlTradeFollow;
 @property (nonatomic, strong) NSString *urlTradeDeleteFollow;
@@ -57,19 +67,27 @@
     {
         self.urlRoot = @"http://whosay.dashgame.com/";
         
+        
         self.urlRegister = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=index&a=register"];
         self.urlLogin = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=index&a=login"];
         
+        
+        self.urlLocation = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=index&a=location"];
+        self.urlCoordinate2Location = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=index&a=coordinate_2_location"];
+        
+        
         self.urlSocialDataList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=social&a=lists"];
         self.urlSocialLike = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=social&a=like"];
         self.urlSocialLikeList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=social&a=like_list"];
         self.urlSocialComment = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=social&a=comment"];
         self.urlSocialCommentList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=social&a=comment_list"];
         
+        
         self.urlTradePublish = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=publish"];
         self.urlTradeEdit = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=edit"];
         self.urlTradeDelete = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=delete"];
         self.urlTradeDataList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=lists"];
+        self.urlTradeSearchDataList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=search"];
         self.urlTradeLatestDataList = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=latest_lists"];
         self.urlTradeFollow = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=follow"];
         self.urlTradeDeleteFollow = [NSString stringWithFormat:@"%@%@", self.urlRoot, @"index.php?m=who&c=trade&a=delete_follow"];
@@ -206,6 +224,18 @@
         user.districtRoomId = [data valueForKey:@"district_room_id"];
         user.firstTimeJoin = YES;
         
+        
+        
+        NSMutableArray *tradePriorityItemArr = [data valueForKey:@"trade_priority"];
+        [user.tradePriorityItemArr removeAllObjects];
+        for(int i=0; i<tradePriorityItemArr.count; i++)
+        {
+            TradePriorityItemData *priorityItem = [[TradePriorityItemData alloc] initByJson:[tradePriorityItemArr objectAtIndex:i]];
+            [user.tradePriorityItemArr addObject:priorityItem];
+        }
+        
+        [CityManager shared];
+        
         if(success)
             success();
         
@@ -252,8 +282,74 @@
 
 
 
+//location
+- (void)location:(double)longitude
+        latitude:(double)latitude
+         success:(void (^_Nullable)(NSString * _Nullable province, NSString * _Nullable city, NSString * _Nullable district, NSString * _Nullable provinceRoomId, NSString * _Nullable cityRoomId, NSString * _Nullable districtRoomId))success
+         failure:(void (^_Nullable)())failure{
+    
+    NSDictionary *parameters = @{@"longitude":@(longitude), @"latitude":@(latitude)};
+    
+    [self request:_urlLocation parameters:parameters progress:nil success:^(id jsonData) {
+        
+        NSString *province = [jsonData objectForKey:@"province"];
+        NSString *city = [jsonData objectForKey:@"city"];
+        NSString *district = [jsonData objectForKey:@"district"];
+        
+        NSString *provinceRoomId = [jsonData objectForKey:@"province_room_id"];
+        NSString *cityRoomId = [jsonData objectForKey:@"city_room_id"];
+        NSString *districtRoomId = [jsonData objectForKey:@"district_room_id"];
+        
+        if(success)
+            success(province, city, district, provinceRoomId, cityRoomId, districtRoomId);
+        
+    } failure:^{
+        if(failure)
+            failure();
+    }];
+}
+
+
+
+- (void)coordinate2Location:(void (^_Nullable)())success
+                    failure:(void (^_Nullable)())failure
+{
+    __weak User *user = [User sharedInfo];
+    
+    NSDictionary *parameters = @{@"id":[NSString stringWithFormat:@"%d", user.userId],
+                                 @"longitude":[NSString stringWithFormat:@"%F", user.longitude],
+                                 @"latitude":[NSString stringWithFormat:@"%F", user.latitude]
+                                 };
+    
+    [self request:_urlCoordinate2Location parameters:parameters progress:nil success:^(id jsonData) {
+        
+        if([jsonData objectForKey:@"province"])
+            user.province = [jsonData objectForKey:@"province"];
+        if([jsonData objectForKey:@"city"])
+            user.city = [jsonData objectForKey:@"city"];
+        if([jsonData objectForKey:@"district"])
+            user.district = [jsonData objectForKey:@"district"];
+        
+        if([jsonData objectForKey:@"province_room_id"])
+            user.provinceRoomId = [jsonData objectForKey:@"province_room_id"];
+        if([jsonData objectForKey:@"city_room_id"])
+            user.cityRoomId = [jsonData objectForKey:@"city_room_id"];
+        if([jsonData objectForKey:@"district_room_id"])
+            user.districtRoomId = [jsonData objectForKey:@"district_room_id"];
+        
+        if(success)
+            success();
+        
+     } failure:^{
+         if(failure)
+             failure();
+     }];
+}
+
+
 
 
+//social
 - (void)getSocialDataList:(NSString *)lastId
                   success:(void (^_Nullable)(NSMutableArray *dataList))success
                   failure:(void (^_Nullable)())failure{
@@ -430,6 +526,7 @@
               picArr:(NSMutableArray *)picArr
                 type:(int)type
             priority:(int)priority
+        priorityType:(int)priorityType
              success:(void (^_Nullable)())success
              failure:(void (^_Nullable)())failure{
     
@@ -444,6 +541,7 @@
     [parameters setValue:msg forKey:@"msg"];
     [parameters setValue:picArr forKey:@"pic"];
     [parameters setValue:[NSString stringWithFormat:@"%d", priority] forKey:@"priority"];
+    [parameters setValue:[NSString stringWithFormat:@"%d", priorityType] forKey:@"priority_type"];
     [parameters setObject:roomId forKey:@"room_id"];
     
     [self request:_urlTradePublish parameters:parameters progress:nil success:^(id jsonData) {
@@ -570,6 +668,55 @@
 }
 
 
+- (void)tradeSearchList:(NSString *)keyWord
+              tradeSort:(TradeSort)tradeSort
+                   page:(int)page
+                success:(void (^_Nullable)(NSMutableArray * _Nullable dataList))success
+                failure:(void (^_Nullable)())failure{
+    
+    User *user = [User sharedInfo];
+    
+    NSString *province = user.province ? user.province : @"";
+    NSString *userId = [NSString stringWithFormat:@"%d", user.userId];
+    
+    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
+    [parameters setValue:[NSString stringWithFormat:@"%ld", (long)tradeSort] forKey:@"sort"];
+    [parameters setValue:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
+    [parameters setValue:province forKey:@"province"];
+    [parameters setValue:userId forKey:@"user_id"];
+    [parameters setValue:keyWord forKey:@"key"];
+    
+    
+    [self request:_urlTradeSearchDataList parameters:parameters progress:nil success:^(id jsonData) {
+        
+        NSMutableArray *userIds = [[NSMutableArray alloc] init];
+        
+        NSMutableArray *jsonList = [jsonData objectForKey:@"list"];
+        NSMutableArray *list = [[NSMutableArray alloc] init];
+        
+        for(int i=0; i<jsonList.count; i++)
+        {
+            NSDictionary *json = [jsonList objectAtIndex:i];
+            TradeData *data = [[TradeData alloc] init];
+            [data setData:json];
+            [list addObject:data];
+            
+            [userIds addObject:data.userId];
+        }
+        
+        [[NIMSDK sharedSDK].userManager fetchUserInfos:userIds completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
+            if(success)
+                success(list);
+        }];
+        
+    } failure:^{
+        if(failure)
+            failure();
+    }];
+    
+}
+
+
 
 - (void)tradeLatestList:(void (^_Nullable)(NSMutableArray *dataList))success
                 failure:(void (^_Nullable)())failure{

+ 30 - 0
NIMDemo/NIMDemo/LocationManager.h

@@ -0,0 +1,30 @@
+//
+//  LocationManager.h
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@protocol LocationDelegate <NSObject>
+
+@optional
+- (void)coordinateUpdate:(double)longitude latitude:(double)latitude;
+
+@end
+
+@interface LocationManager : NSObject
+
+
+@property (nonatomic, weak) id<LocationDelegate> delegate;
+
+
++ (LocationManager *)sharedManager;
+- (void)startUpdate;
+- (void)stopUpdate;
+
+- (void)relocationWhenEnter;
+
+@end

+ 141 - 0
NIMDemo/NIMDemo/LocationManager.m

@@ -0,0 +1,141 @@
+//
+//  LocationManager.m
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import "LocationManager.h"
+#import <CoreLocation/CoreLocation.h>
+#import "SVProgressHUD.h"
+#import "HttpRequest.h"
+#import "User.h"
+
+@interface LocationManager()<CLLocationManagerDelegate, LocationDelegate>
+
+@property(strong, nonatomic) CLLocationManager *locationManager;
+
+@end
+
+@implementation LocationManager
+
++ (instancetype)sharedManager
+{
+    static LocationManager *sharedManager = nil;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        sharedManager = [[LocationManager alloc] init];
+        [sharedManager setUpComponent];
+    });
+    return sharedManager;
+}
+
+
+- (void)setUpComponent{
+    
+    self.locationManager = [[CLLocationManager alloc] init];
+    self.locationManager.delegate = self;
+    self.locationManager.distanceFilter = 1.0;
+    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
+    
+    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
+    {
+        [self.locationManager requestAlwaysAuthorization]; // 永久授权
+        [self.locationManager requestWhenInUseAuthorization]; //使用中授权
+    }
+
+}
+
+- (void)startUpdate{
+
+    [self.locationManager startUpdatingLocation];
+    
+}
+
+- (void)stopUpdate{
+    
+    [self.locationManager stopUpdatingLocation];
+    
+}
+
+- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
+{
+    [self.locationManager stopUpdatingLocation];
+    
+    NSLog(@"经度:%f", newLocation.coordinate.longitude);
+    NSLog(@"纬度:%f", newLocation.coordinate.latitude);
+    NSLog(@"速度:%f 米/秒", newLocation.speed);
+    CLGeocoder * geocoder = [[CLGeocoder alloc] init];
+    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
+        
+        NSDictionary *locationInfo = [[NSDictionary alloc]init];
+        for (CLPlacemark * placemark in placemarks) {
+            locationInfo = [placemark addressDictionary];
+        }
+        NSLog(@"%@",locationInfo);
+    }];
+    
+    
+    if(self.delegate && [self.delegate respondsToSelector:@selector(coordinateUpdate:latitude:)]){
+        
+        [self.delegate coordinateUpdate:newLocation.coordinate.longitude latitude:newLocation.coordinate.latitude];
+        
+    }
+}
+
+- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
+{
+    NSLog(@"localtion error %@", error);
+    [self.locationManager stopUpdatingLocation];
+    
+    if(self.delegate && [self.delegate respondsToSelector:@selector(coordinateUpdate:latitude:)]){
+        
+        [self.delegate coordinateUpdate:0 latitude:0];
+        
+    }
+}
+
+
+
+
+
+- (void)relocationWhenEnter{
+    
+    self.delegate = self;
+    [self startUpdate];
+    
+}
+
+- (void)coordinateUpdate:(double)longitude latitude:(double)latitude{
+    self.delegate = nil;
+    
+    if(longitude != 0 && latitude != 0)
+    {
+        User *user = [User sharedInfo];
+        user.longitude = longitude;
+        user.latitude = latitude;
+        
+        [[HttpRequest shared] coordinate2Location:^{
+            [self toTabBarView];
+        } failure:^{
+            [self toTabBarView];
+        }];
+    }
+    else
+    {
+        [self toTabBarView];
+    }
+}
+
+- (void)toTabBarView{
+    UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
+    UIViewController *next = [board instantiateViewControllerWithIdentifier:@"TabBarView"];
+    
+    UIViewController *vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];
+    UINavigationController *nav = vc.navigationController ? vc.navigationController : (UINavigationController *)vc;
+    [nav pushViewController:next animated:NO];
+    [SVProgressHUD dismiss];
+}
+
+@end

+ 2 - 1
NIMDemo/NIMDemo/LoginViewController.m

@@ -15,6 +15,7 @@
 #import "SVProgressHUD.h"
 #import "UIView+Toast.h"
 #import "HttpRequest.h"
+#import "LocationManager.h"
 
 @interface LoginViewController ()
 @property (weak, nonatomic) IBOutlet UITextField *mobileTextField;
@@ -80,7 +81,7 @@
 }
 
 - (void)showTabBarView{
-    [self performSegueWithIdentifier:@"login2Tab" sender:self];
+    [[LocationManager sharedManager] relocationWhenEnter];
 }
 
 @end

+ 2 - 2
NIMDemo/NIMDemo/RegisterViewController.m

@@ -12,6 +12,7 @@
 #import "SVProgressHUD.h"
 #import "UIView+Toast.h"
 #import "User.h"
+#import "LocationManager.h"
 
 @interface RegisterViewController ()
 @property (weak, nonatomic) IBOutlet UITextField *mobileTextField;
@@ -84,8 +85,7 @@
 
 - (void)loginNIM:(NSString *)uid token:(NSString *)token{
     [[HttpRequest shared] loginNIM:uid token:token success:^{
-        [self performSegueWithIdentifier:@"register2Tab" sender:self];
-        [SVProgressHUD dismiss];
+        [[LocationManager sharedManager] relocationWhenEnter];
     } failure:^(NSError * _Nullable error) {
         [self.view makeToast:[NSString stringWithFormat:@"进入聊天失败 error:%@", error] duration:2.0 position:CSToastPositionCenter];
         [SVProgressHUD dismiss];

+ 1 - 0
NIMDemo/NIMDemo/SectionTrade/TradeData.h

@@ -35,6 +35,7 @@ typedef NS_ENUM(NSInteger, TradeSort) {
 @property (nonatomic, strong) NSMutableArray        *picArr;
 @property (nonatomic, strong) NSMutableArray        *thumbArr;
 @property (nonatomic, strong) NSMutableArray        *picIdArr;
+@property (nonatomic, assign) int                   priorityType;
 @property (nonatomic, assign) int                   priority;
 @property (nonatomic, strong) NSString              *time;
 @property (nonatomic, assign) BOOL                  followed;

+ 1 - 0
NIMDemo/NIMDemo/SectionTrade/TradeData.m

@@ -21,6 +21,7 @@
     _thumbArr = [data objectForKey:@"thumbs"];
     _picIdArr = [data objectForKey:@"pic_ids"];
     
+    _priorityType = [[data objectForKey:@"priority_type"] intValue];
     _priority = [[data objectForKey:@"priority"] intValue];
     _time = [data objectForKey:@"inputtime"];
     

+ 3 - 0
NIMDemo/NIMDemo/SectionTrade/TradeDetailViewController.m

@@ -149,8 +149,11 @@
     {
         NSURL *url = [NSURL URLWithString:[_data.picArr objectAtIndex:i]];
         UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _imgContainer.width, 0)];
+        [imgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTouchImage:)]];
         [imgView setContentScaleFactor:[[UIScreen mainScreen] scale]];
         imgView.contentMode =  UIViewContentModeScaleToFill;
+        imgView.userInteractionEnabled = YES;
+        imgView.tag = i;
         
         NSLog(@"load image url %@", url.absoluteString);
         [imgView sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

+ 21 - 7
NIMDemo/NIMDemo/SectionTrade/TradeModifyViewController.m

@@ -14,6 +14,7 @@
 #import "User.h"
 #import "NIMKitMediaFetcher.h"
 #import "TradePublishManager.h"
+#import "TradePriorityItemData.h"
 
 @interface TradeModifyViewController ()<TradeModifyImageDelegate, TradePublishDelegate>
 
@@ -38,6 +39,8 @@
 @property (nonatomic, assign) int                   imgColumns;
 @property (nonatomic, assign) int                   maxImgs;
 
+@property (nonatomic, strong) TradePriorityItemData *priorityTypeItem;
+
 @end
 
 @implementation TradeModifyViewController
@@ -50,6 +53,17 @@
         _imgArr = [[NSMutableArray alloc] init];
         _imgReuseArr = [[NSMutableArray alloc] init];
         _imgIdArr = [[NSMutableArray alloc] init];
+        
+        NSMutableArray *itemArr = [User sharedInfo].tradePriorityItemArr;
+        for(int i=0; i<itemArr.count; i++)
+        {
+            TradePriorityItemData *item = [itemArr objectAtIndex:i];
+            if(item.type == tradeData.priorityType)
+            {
+                _priorityTypeItem = item;
+                break;
+            }
+        }
     }
     return self;
     
@@ -134,15 +148,15 @@
     titleLabel.text = @"添加置顶";
     [_scrollView addSubview:titleLabel];
     
-    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(_scrollView.width - 150, titleLabel.top, 100, 40)];
+    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, titleLabel.top, width-20, 40)];
     _countLabel.textAlignment = NSTextAlignmentRight;
     [_scrollView addSubview:_countLabel];
     
-    UIButton *countBtn = [UIButton buttonWithType:UIButtonTypeCustom];
-    countBtn.frame = CGRectMake(_scrollView.width - 50, titleLabel.top, 30, 30);
-    [countBtn setImage:[UIImage imageNamed:@"箭头_下"] forState:UIControlStateNormal];
-    //[countBtn addTarget:self action:@selector(toggleSlider:) forControlEvents:UIControlEventTouchUpInside];
-    [_scrollView addSubview:countBtn];
+//    UIButton *countBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+//    countBtn.frame = CGRectMake(_scrollView.width - 50, titleLabel.top, 30, 30);
+//    [countBtn setImage:[UIImage imageNamed:@"箭头_下"] forState:UIControlStateNormal];
+//    //[countBtn addTarget:self action:@selector(toggleSlider:) forControlEvents:UIControlEventTouchUpInside];
+//    [_scrollView addSubview:countBtn];
     
     _slider = [[UISlider alloc] initWithFrame:CGRectMake(50, titleLabel.bottom, _scrollView.width-70, 40)];
     _slider.minimumValue = 0;
@@ -333,7 +347,7 @@
 
 
 - (void)sliderValueChanged{
-    _countLabel.text = [NSString stringWithFormat:@"x%d(+%.0f)", _data.priority, roundf(_slider.value)];
+    _countLabel.text = [NSString stringWithFormat:@"x%d(+%.0f) (%@ 单价%d)", _data.priority, roundf(_slider.value), _priorityTypeItem.name, _priorityTypeItem.price];
 }
 
 

+ 1 - 0
NIMDemo/NIMDemo/SectionTrade/TradePublishManager.h

@@ -26,6 +26,7 @@
 - (void)tradePublish:(NSString *_Nullable)msg
               picArr:(NSMutableArray *_Nullable)picArr
             priority:(int)priority
+        priorityType:(int)priorityType
            tradeType:(int)tradeType;
 
 - (void)tradeEdit:(NSString *_Nullable)msg

+ 4 - 1
NIMDemo/NIMDemo/SectionTrade/TradePublishManager.m

@@ -22,6 +22,7 @@
 @property (nonatomic, strong) NSMutableArray        *picDataArr;
 @property (nonatomic, assign) int                   uploadIndex;
 @property (nonatomic, assign) int                   priority;
+@property (nonatomic, assign) int                   priorityType;
 @property (nonatomic, assign) int                   tradeType;
 
 @property (nonatomic, assign) BOOL                  isEdit;
@@ -33,11 +34,13 @@
 - (void)tradePublish:(NSString *)msg
               picArr:(NSMutableArray *)picArr
             priority:(int)priority
+        priorityType:(int)priorityType
            tradeType:(int)tradeType{
     
     self.msg = msg;
     self.picArr = picArr;
     self.priority = priority;
+    self.priorityType = priorityType;
     self.tradeType = tradeType;
     
     self.picDataArr = [[NSMutableArray alloc] init];
@@ -159,7 +162,7 @@
     NSString *sendMsg = _msg ? _msg : @"";
     
     
-    [[HttpRequest shared] tradePublish:sendMsg picArr:_picDataArr type:_tradeType priority:_priority success:^{
+    [[HttpRequest shared] tradePublish:sendMsg picArr:_picDataArr type:_tradeType priority:_priority priorityType:_priorityType success:^{
         
         [SVProgressHUD dismiss];
         if(_inputView)

+ 6 - 3
NIMDemo/NIMDemo/SectionTrade/TradeTableViewCell.m

@@ -257,10 +257,13 @@ return self;
     
     NSLog(@"show image %ld", (long)viewClicked.tag);
     
-    ImagePagerViewController *imagePageVC = [[ImagePagerViewController alloc] init];
-    [imagePageVC setImages:_data.picArr thumbs:_data.thumbArr startIndex:(int)viewClicked.tag];
+//    ImagePagerViewController *imagePageVC = [[ImagePagerViewController alloc] init];
+//    [imagePageVC setImages:_data.picArr thumbs:_data.thumbArr startIndex:(int)viewClicked.tag];
+//    
+//    [self.viewController.navigationController pushViewController:imagePageVC animated:YES];
     
-    [self.viewController.navigationController pushViewController:imagePageVC animated:YES];
+    TradeDetailViewController *detailVC = [[TradeDetailViewController alloc] initWithTradeData:_data];
+    [self.viewController.navigationController pushViewController:detailVC animated:YES];
 }
 
 - (void)onTouchContent:(UITapGestureRecognizer *)gestureRecognizer{

+ 137 - 66
NIMDemo/NIMDemo/SectionTrade/TradeViewController.m

@@ -17,11 +17,21 @@
 #import "TradePublishManager.h"
 #import "UIView+Toast.h"
 #import "TradeTopBarItem.h"
+#import "SVProgressHUD.h"
 
 
-@interface TradeViewController () <UIScrollViewDelegate, TradeInputDelegate, TradePublishDelegate>
+@interface TradeViewController () <
+UIScrollViewDelegate,
+TradeInputDelegate,
+TradePublishDelegate,
+UISearchBarDelegate,
+UISearchControllerDelegate>
 
 @property (nonatomic, strong) NSMutableArray            *dataList;
+
+@property (nonatomic, strong) NSString                  *searchKey;
+@property (nonatomic, strong) NSMutableArray            *searchList;
+
 @property (nonatomic, assign) BOOL                      isFetching;
 @property (nonatomic, assign) BOOL                      flagRefresh;
 @property (nonatomic, assign) TradeSort                 tradeSort;
@@ -42,7 +52,7 @@
 @property (nonatomic,strong)  TradeTopBarItem           *tradeItem2;
 @property (nonatomic,strong)  NSTimer                   *timer;
 
-@property (nonatomic, strong) UISearchController        *seachController;
+@property (nonatomic, strong) UISearchController        *searchController;
 
 @end
 
@@ -75,8 +85,9 @@ float postHeight = 30;
     
     
     float tabbarHeight = self.tabBarController.tabBar.frame.size.height;
-    _tradeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tradePublishView.width, 272)];
-    _tradeContainer.bottom = _tradePublishView.bottom - tabbarHeight;
+    _tradeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tradePublishView.width, 272+tabbarHeight)];
+    _tradeContainer.bottom = _tradePublishView.bottom;
+    _tradeContainer.tag = 99;
     [_tradePublishView addSubview:_tradeContainer];
     
     
@@ -146,6 +157,9 @@ float postHeight = 30;
     [_tradeContainer addSubview:_tradeInput];
     
     
+    [_tradeInput fillItemData:[User sharedInfo].tradePriorityItemArr];
+    
+    
     [self hideTradeInput:nil];
     
     
@@ -164,12 +178,16 @@ float postHeight = 30;
     
     
     
-    _seachController = [[UISearchController alloc] initWithSearchResultsController:nil];
-    _seachController.searchBar.barTintColor = User.orangeColor;
-    _seachController.hidesNavigationBarDuringPresentation = YES;
-    _seachController.searchBar.tintColor = UIColor.whiteColor;
+    _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
+    _searchController.searchBar.barTintColor = User.orangeColor;
+    _searchController.hidesNavigationBarDuringPresentation = YES;
+    _searchController.searchBar.tintColor = UIColor.whiteColor;
+    _searchController.delegate = self;
+    _searchController.dimsBackgroundDuringPresentation = NO;
+    
+    _searchController.searchBar.delegate = self;
     
-    [self.view addSubview:_seachController.searchBar];
+    [self.view addSubview:_searchController.searchBar];
     
 }
 
@@ -183,7 +201,7 @@ float postHeight = 30;
 - (void)viewWillAppear:(BOOL)animated{
     [super viewWillAppear:animated];
     
-    [_timer setFireDate:[NSDate distantPast]];
+    //[_timer setFireDate:[NSDate distantPast]];
     
     User *user = [User sharedInfo];
     
@@ -270,7 +288,30 @@ float postHeight = 30;
 }
 
 
+- (void)onTouchSearch:(int)sender{
+    NSLog(@"onTouchSearch");
+    [_searchController setActive:YES];
+    
+}
+
+- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
+    NSLog(@"searchBarTextDidEndEditing %@", searchBar.text);
+    
+    if(searchBar.text.length > 0)
+    {
+        _searchKey = searchBar.text;
+        [SVProgressHUD show];
+        [self reset];
+        [self fetchSearchDataList];
+    }
+}
 
+- (void)didDismissSearchController:(UISearchController *)searchController{
+    NSLog(@"didDismissSearchController %@", searchController.searchBar.text);
+    
+    [self reset];
+    [self fetchDataList];
+}
 
 
 - (UITableView *)tableView
@@ -328,18 +369,14 @@ float postHeight = 30;
 }
 
 
-- (void)onTouchSearch:(int)sender{
-    NSLog(@"onTouchSearch");
-    [_seachController setActive:YES];
-    
-}
+
 
 
 - (void)reset{
     
     _page = 1;
     _dataList = nil;
-    
+    _searchList = nil;
 }
 
 - (void)fetchDataList{
@@ -369,6 +406,38 @@ float postHeight = 30;
     }];
 }
 
+
+- (void)fetchSearchDataList{
+    
+    if(_isFetching)
+        return;
+    
+    _isFetching = YES;
+    
+    _page = MAX(1, _page);
+    
+    
+    __weak typeof(self) wself = self;
+    [[HttpRequest shared] tradeSearchList:_searchKey tradeSort:_tradeSort page:_page success:^(NSMutableArray * _Nullable dataList) {
+        if(!wself.searchList)
+            wself.searchList = dataList;
+        else
+            [wself.searchList addObjectsFromArray:dataList];
+        
+        [wself.tableView reloadData];
+        
+        if(dataList.count > 0)
+            wself.page++;
+        
+        wself.isFetching = NO;
+        
+        [SVProgressHUD dismiss];
+    } failure:^{
+        wself.isFetching = NO;
+    }];
+}
+
+
 #pragma mark - Table view data source
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
@@ -376,70 +445,63 @@ float postHeight = 30;
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    if(_dataList)
-        return _dataList.count;
+    
+    if(_searchController.isActive)
+    {
+        if(_searchList)
+            return _searchList.count;
+    }
+    else
+    {
+        if(_dataList)
+            return _dataList.count;
+    }
     return 0;
 }
 
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
-    NSObject *dataObj = [_dataList objectAtIndex:indexPath.row];
+    NSObject *dataObj = nil;
+    
+    if(_searchController.isActive)
+    {
+        dataObj = [_searchList objectAtIndex:indexPath.row];
+    }
+    else
+    {
+        dataObj = [_dataList objectAtIndex:indexPath.row];
+    }
     
     UITableViewCell *baseCell = nil;
     
-//    if([dataObj isKindOfClass:[SocialItemData class]])
-//    {
-//        NSString *cellId = @"social";
-//        SocialDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
-//        
-//        if(!cell)
-//        {
-//            cell = [[SocialDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
-//            [cell initWidth:self.view.frame.size.width];
-//        }
-//        
-//        [cell setSocialData:(SocialItemData *)dataObj];
-//        _infoHeight = cell.cellHeight;
-//        
-//        baseCell = cell;
-//    }
-//    else if([dataObj isKindOfClass:[SocialCommentData class]])
-//    {
-//        NSString *cellId = @"comment";
-//        SocialCommentDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
-//        
-//        if(!cell)
-//        {
-//            cell = [[SocialCommentDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
-//            [cell initWidth:self.view.frame.size.width];
-//        }
-//        
-//        [cell setSocialCommentData:(SocialCommentData *)dataObj];
-//        baseCell = cell;
-//    }
-    
-    if(true)
-    {
-        NSString *cellId = @"trade";
-        TradeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
+    NSString *cellId = @"trade";
+    TradeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
 
-        if(!cell)
-        {
-            cell = [[TradeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
-            [cell initWidth:self.view.frame.size.width];
-        }
-
-        [cell setData:(TradeData *)dataObj];
-        baseCell = cell;
+    if(!cell)
+    {
+        cell = [[TradeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
+        [cell initWidth:self.view.frame.size.width];
     }
+
+    [cell setData:(TradeData *)dataObj];
+    baseCell = cell;
     
     return baseCell;
 }
 
 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
     
-    NSObject *dataObj = [_dataList objectAtIndex:indexPath.row];
+    NSObject *dataObj = nil;
+    
+    if(_searchController.isActive)
+    {
+        dataObj = [_searchList objectAtIndex:indexPath.row];
+    }
+    else
+    {
+        dataObj = [_dataList objectAtIndex:indexPath.row];
+    }
     
     if([dataObj isKindOfClass:[TradeData class]])
     {
@@ -473,7 +535,15 @@ float postHeight = 30;
         {
             _flagRefresh = NO;
             NSLog(@"下拉刷新");
-            [self fetchDataList];
+            
+            if(_searchController.isActive)
+            {
+                [self fetchSearchDataList];
+            }
+            else
+            {
+                [self fetchDataList];
+            }
         }
     }
     
@@ -495,6 +565,7 @@ float postHeight = 30;
 }
 
 - (void)hideTradeInput:(id)sender{
+    [_tradeInput.growTextView resignFirstResponder];
     [_tradePublishView setHidden:YES];
 }
 
@@ -516,7 +587,7 @@ float postHeight = 30;
 }
 
 
-- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority type:(int)type{
+- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority priorityType:(int)priorityType type:(int)type{
     
     if((!msg || msg.length == 0) && picArr.count == 0)
     {
@@ -527,7 +598,7 @@ float postHeight = 30;
     
     TradePublishManager *tradePublishManager = [[TradePublishManager alloc] init];
     tradePublishManager.delegate = self;
-    [tradePublishManager tradePublish:msg picArr:picArr priority:priority tradeType:type];
+    [tradePublishManager tradePublish:msg picArr:picArr priority:priority priorityType:priorityType tradeType:type];
     
     [self hideTradeInput:nil];
 }

+ 46 - 3
NIMDemo/NIMDemo/SocialPublishViewController.m

@@ -14,8 +14,14 @@
 #import "SVProgressHUD.h"
 #import "UIImage+NIM.h"
 #import "AFNetworking/AFNetworking.h"
+#import "LocationManager.h"
+#import "HttpRequest.h"
 
-@interface SocialPublishViewController ()<UITextViewDelegate>
+@interface SocialPublishViewController ()<UITextViewDelegate, LocationDelegate>
+
+@property (nonatomic, strong) LocationManager       *locationManager;
+@property (nonatomic, assign) double                longitude;
+@property (nonatomic, assign) double                latitude;
 
 @property (nonatomic, strong) UITextView            *msgTxtView;
 @property (nonatomic, strong) UILabel               *msgReplaceHolder;
@@ -120,11 +126,21 @@ int picColumns = 5;
     publishBtn.layer.cornerRadius = 5;
     [publishBtn addTarget:self action:@selector(onTouchPublish:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:publishBtn];
+    
+    
+    
+    _locationManager = [LocationManager sharedManager];
+    _locationManager.delegate = self;
+    [_locationManager startUpdate];
 }
 
 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
+    
+    [_locationManager stopUpdate];
+    _locationManager.delegate = nil;
+    
 }
 
 
@@ -134,6 +150,33 @@ int picColumns = 5;
 }
 
 
+- (void)coordinateUpdate:(double)longitude latitude:(double)latitude{
+    
+    self.longitude = longitude;
+    self.latitude = latitude;
+    
+    __weak typeof(self) wself = self;
+    [[HttpRequest shared] location:longitude latitude:latitude success:^(NSString * _Nullable province, NSString * _Nullable city, NSString * _Nullable district, NSString * _Nullable provinceRoomId, NSString * _Nullable cityRoomId, NSString * _Nullable districtRoomId) {
+        
+        if(city && district && city.length > 0 && district.length > 0)
+        {
+            if([city isEqualToString:district])
+            {
+                wself.locationLabel.text = district;
+            }
+            else
+            {
+                wself.locationLabel.text = [NSString stringWithFormat:@"%@%@", city, district];
+            }
+            [wself.locationManager stopUpdate];
+        }
+        
+    } failure:^{
+        
+    }];
+}
+
+
 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
 {
     if (![text isEqualToString:@""])
@@ -347,8 +390,8 @@ int picColumns = 5;
     [parameters setObject:local forKey:@"local"];
     [parameters setObject:msg forKey:@"msg"];
     [parameters setObject:_picDataArr forKey:@"pic"];
-    [parameters setObject:[NSString stringWithFormat:@"%F", user.longitude] forKey:@"longitude"];
-    [parameters setObject:[NSString stringWithFormat:@"%F", user.latitude] forKey:@"latitude"];
+    [parameters setObject:[NSString stringWithFormat:@"%F", _longitude] forKey:@"longitude"];
+    [parameters setObject:[NSString stringWithFormat:@"%F", _latitude] forKey:@"latitude"];
     
     NSString *urlString = @"http://whosay.dashgame.com/index.php?m=who&c=social&a=publish";
     //请求的managers

+ 8 - 3
NIMDemo/NIMDemo/User.h

@@ -10,6 +10,7 @@
 #import "GiftInputContainer.h"
 #import "NIMSDK/NIMSDK.h"
 
+
 @interface User : NSObject
 
 + (instancetype _Nonnull ) sharedInfo;
@@ -26,26 +27,30 @@
 @property (nonatomic, nullable) NSString *city;
 @property (nonatomic, nullable) NSString *district;
 
+
+//chat
 @property (nonatomic, nullable) NSString *countryRoomId;
 @property (nonatomic, nullable) NSString *provinceRoomId;
 @property (nonatomic, nullable) NSString *cityRoomId;
 @property (nonatomic, nullable) NSString *districtRoomId;
 
-
 @property (nonatomic, assign) int       newCreateTeamId;
 @property (nonatomic, assign) BOOL      firstTimeJoin;
 @property (nonatomic, assign) BOOL      hasNewSocial;
 
+@property (nonatomic, nullable, strong) NSString *currentChatRoomId;
 @property (nonatomic, strong, nonnull)   NSMutableDictionary * giftGotDict;
 @property (nonatomic, strong, nonnull)   NSMutableDictionary * tradeGotDict;
 
 
-
+//social
 @property (nonatomic, strong, nonnull)  NSMutableArray *picArr;
 @property (nonatomic, strong, nonnull)  NSMutableArray *thumbArr;
 
 
-@property (nonatomic, nullable, strong) NSString *currentChatRoomId;
+//trade
+@property (nonatomic, strong, nonnull) NSMutableArray *tradePriorityItemArr;
+
 
 
 + (UIColor *_Nonnull)greenColor;

+ 16 - 0
NIMDemo/NIMDemo/User.m

@@ -9,6 +9,7 @@
 #import "User.h"
 #import "AFHTTPSessionManager.h"
 #import "GiftInputContainer.h"
+#import <CoreLocation/CoreLocation.h>
 
 
 @interface User()
@@ -66,12 +67,27 @@ int newCreateTeamId;
         sharedInfo = [[User alloc] init];
         sharedInfo.giftGotDict = [[NSMutableDictionary alloc] init];
         sharedInfo.tradeGotDict = [[NSMutableDictionary alloc] init];
+        sharedInfo.tradePriorityItemArr = [[NSMutableArray alloc] init];
     });
     return sharedInfo;
 }
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 + (NSString *_Nonnull)distance:(double)originLat originLng:(double)originLng targetLat:(double)targetLat targetLng:(double)targetLng{
     
     double pow1 = pow(sin((targetLat*M_PI/180 - originLat*M_PI/180)/2), 2);

+ 6 - 4
NIMDemo/NIMDemo/ViewController.m

@@ -17,6 +17,7 @@
 #import "NTESLoginManager.h"
 #import "HttpRequest.h"
 #import "SVProgressHUD.h"
+#import "LocationManager.h"
 
 @interface ViewController ()
 
@@ -59,10 +60,7 @@
         [[NTESServiceManager sharedManager] start];
         
         [[HttpRequest shared] loginAccount:account password:token success:^{
-            UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
-            UIViewController *next = [board instantiateViewControllerWithIdentifier:@"TabBarView"];
-            [self.navigationController pushViewController:next animated:NO];
-            [SVProgressHUD dismiss];
+            [[LocationManager sharedManager] relocationWhenEnter];
         } failure:^{
             [SVProgressHUD dismiss];
         }];
@@ -73,4 +71,8 @@
     }
 }
 
+
+
+
+
 @end

+ 6 - 0
NIMKit/NIMKit.xcodeproj/project.pbxproj

@@ -109,6 +109,7 @@
 		BDEF44778342E8508CD2214A /* NIMSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 343C48179E89F3CDB6D1EBD0 /* NIMSDK.framework */; };
 		C01F4353A19B845A75054965 /* libopus.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A9B4ACE8E4B6986E4BC851B /* libopus.a */; };
 		C482C2F81F09DB6D00EF2B71 /* TradeInputContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C2F71F09DB6D00EF2B71 /* TradeInputContainer.m */; };
+		C482C3441F162C7F00EF2B71 /* TradePriorityItemData.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3431F162C7F00EF2B71 /* TradePriorityItemData.m */; };
 		C4B7C4931EEE90A8001CEA87 /* GiftInputContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B7C4921EEE90A8001CEA87 /* GiftInputContainer.m */; };
 		C4B7C4971EEEA9B6001CEA87 /* GiftInputButton.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B7C4961EEEA9B6001CEA87 /* GiftInputButton.m */; };
 		C5354972B4A7419E04058CF6 /* NIMAVChat.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AAB4EA99569F4B8975DDD9A /* NIMAVChat.framework */; };
@@ -352,6 +353,8 @@
 		BC8242AE825D231FFC920107 /* libevent.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libevent.a; path = ./NIMKit/Vendors/NIMSDK/Libs/libevent.a; sourceTree = SOURCE_ROOT; };
 		C482C2F61F09DB6D00EF2B71 /* TradeInputContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TradeInputContainer.h; sourceTree = "<group>"; };
 		C482C2F71F09DB6D00EF2B71 /* TradeInputContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TradeInputContainer.m; sourceTree = "<group>"; };
+		C482C3421F162C7F00EF2B71 /* TradePriorityItemData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TradePriorityItemData.h; sourceTree = "<group>"; };
+		C482C3431F162C7F00EF2B71 /* TradePriorityItemData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TradePriorityItemData.m; sourceTree = "<group>"; };
 		C4B7C4911EEE90A8001CEA87 /* GiftInputContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GiftInputContainer.h; sourceTree = "<group>"; };
 		C4B7C4921EEE90A8001CEA87 /* GiftInputContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GiftInputContainer.m; sourceTree = "<group>"; };
 		C4B7C4951EEEA9B6001CEA87 /* GiftInputButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GiftInputButton.h; sourceTree = "<group>"; };
@@ -833,6 +836,8 @@
 				C4B7C4961EEEA9B6001CEA87 /* GiftInputButton.m */,
 				C482C2F61F09DB6D00EF2B71 /* TradeInputContainer.h */,
 				C482C2F71F09DB6D00EF2B71 /* TradeInputContainer.m */,
+				C482C3421F162C7F00EF2B71 /* TradePriorityItemData.h */,
+				C482C3431F162C7F00EF2B71 /* TradePriorityItemData.m */,
 			);
 			path = Input;
 			sourceTree = "<group>";
@@ -1165,6 +1170,7 @@
 				E477F11E1DE2E5CF00AAB41C /* NIMTextContentConfig.m in Sources */,
 				61A2C8A91BA6D797006304F9 /* NIMGroupedDataCollection.m in Sources */,
 				61D99FB31BAFF4770059D369 /* NIMAdvancedTeamCardViewController.m in Sources */,
+				C482C3441F162C7F00EF2B71 /* TradePriorityItemData.m in Sources */,
 				E41160AA1DE2EFEB00E426FB /* NIMKitLocationPoint.m in Sources */,
 				E477F1191DE2E5CF00AAB41C /* NIMBaseSessionContentConfig.m in Sources */,
 				C4B7C4931EEE90A8001CEA87 /* GiftInputContainer.m in Sources */,

+ 2 - 0
NIMKit/NIMKit/Classes/Protocols/NIMMessageCellProtocol.h

@@ -24,6 +24,8 @@
 
 - (BOOL)onTapAvatar:(NSString *)userId;
 
+- (BOOL)onLongPressAvatar:(NSString *)userId;
+
 - (void)onRetryMessage:(NIMMessage *)message;
 
 @end

+ 22 - 7
NIMKit/NIMKit/Classes/Sections/Input/GiftInputContainer.m

@@ -14,6 +14,7 @@
 #import "NIMGrowingTextView.h"
 #import "NIMContactSelectConfig.h"
 #import "NIMContactSelectViewController.h"
+#import "NIMInputView.h"
 
 
 NSInteger GiftPageControlHeight = 20;
@@ -609,6 +610,10 @@ NSInteger TradeTypeDemand = 2;
 
 - (void)keyboardWillChangeFrame:(NSNotification *)notification
 {
+    if(self.isHidden)
+    {
+        return;
+    }
     
     NSDictionary *userInfo = notification.userInfo;
     CGRect endFrame   = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
@@ -616,15 +621,25 @@ NSInteger TradeTypeDemand = 2;
     
     float keyBoardFrameTop = endFrame.origin.y;
     
-    if(keyBoardFrameTop == self.nim_viewController.view.nim_height)
-    {
-        _inputTextBkgImage.nim_top = 100;
-        _inputTextView.nim_top = 102;
+    NIMInputView *inputView = nil;
+    
+    for (UIView* next = self; next; next = next.superview) {
+        UIResponder* nextResponder = [next nextResponder];
+        if ([nextResponder isKindOfClass:[NIMInputView class]]) {
+            inputView = (NIMInputView *)nextResponder;
+        }
     }
-    else
+    
+    if(inputView)
     {
-        _inputTextBkgImage.nim_top = 100 - endFrame.size.height + 120;
-        _inputTextView.nim_top = 102 - endFrame.size.height + 120;
+        if(keyBoardFrameTop == self.nim_viewController.view.nim_height)
+        {
+            inputView.nim_bottom = keyBoardFrameTop;
+        }
+        else
+        {
+            inputView.nim_bottom = keyBoardFrameTop + 54;
+        }
     }
 }
 @end

+ 4 - 0
NIMKit/NIMKit/Classes/Sections/Input/NIMInputView.h

@@ -38,6 +38,8 @@ typedef NS_ENUM(NSInteger, NIMAudioRecordPhase) {
 
 - (void)inputViewSizeToHeight:(CGFloat)toHeight
                 showInputView:(BOOL)show;
+
+- (void)inputTabSelected;
 @end
 
 @interface NIMInputView : UIView
@@ -73,4 +75,6 @@ typedef NS_ENUM(NSInteger, NIMAudioRecordPhase) {
 - (void)updateAudioRecordTime:(NSTimeInterval)time;
 - (void)updateVoicePower:(float)power;
 
+- (void)addAtItem:(NSString *)uid;
+
 @end

+ 41 - 0
NIMKit/NIMKit/Classes/Sections/Input/NIMInputView.m

@@ -297,6 +297,11 @@
         self.status = NIMInputStatusText;
         self.toolBar.showsKeyboard = YES;
     }
+    
+    if(_inputDelegate && [_inputDelegate respondsToSelector:@selector(inputTabSelected)])
+    {
+        [_inputDelegate inputTabSelected];
+    }
 }
 
 - (NIMInputMoreContainerView *)moreContainer
@@ -607,6 +612,12 @@
 - (BOOL)textViewShouldBeginEditing
 {
     self.status = NIMInputStatusText;
+    
+    if(_inputDelegate && [_inputDelegate respondsToSelector:@selector(inputTabSelected)])
+    {
+        [_inputDelegate inputTabSelected];
+    }
+    
     return YES;
 }
 
@@ -680,6 +691,36 @@
     [self.toolBar insertText:str];
 }
 
+- (void)addAtItem:(NSString *)uid{
+    
+    NSMutableString *str = [[NSMutableString alloc] initWithString:@""];
+    NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
+    option.session = self.session;
+    option.forbidaAlias = YES;
+
+    NSString *nick = [[NIMKit sharedKit].provider infoByUser:uid option:option].showName;
+    [str appendString:NIMInputAtStartChar];
+    [str appendString:nick];
+    [str appendString:NIMInputAtEndChar];
+    
+    
+    //check exist
+    NIMInputAtItem *existItem = [self.atCache item:nick];
+    if(existItem)
+    {
+        return;
+    }
+    
+    
+    NIMInputAtItem *item = [[NIMInputAtItem alloc] init];
+    item.uid  = uid;
+    item.name = nick;
+    [self.atCache addAtItem:item];
+
+    [self.toolBar insertText:str];
+    
+}
+
 #pragma mark - InputEmoticonProtocol
 - (void)selectedEmoticon:(NSString*)emoticonID catalog:(NSString*)emotCatalogID description:(NSString *)description{
     if (!emotCatalogID) { //删除键

+ 5 - 2
NIMKit/NIMKit/Classes/Sections/Input/TradeInputContainer.h

@@ -7,11 +7,11 @@
 //
 
 #import <UIKit/UIKit.h>
-
+#import "NIMGrowingTextView.h"
 
 @protocol TradeInputDelegate <NSObject>
 
-- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority type:(int)type;
+- (void)sendTrade:(NSString *)msg picArr:(NSMutableArray *)picArr priority:(int)priority priorityType:(int)priorityType type:(int)type;
 
 @end
 
@@ -22,6 +22,9 @@
 @property (nonatomic, assign) int                   tradeType;
 @property (nonatomic, assign) BOOL                  layoutHold;
 
+@property (nonatomic, strong) NIMGrowingTextView    *growTextView;
+
 - (void)reset;
+- (void)fillItemData:(NSMutableArray *)dataArr;
 
 @end

+ 135 - 13
NIMKit/NIMKit/Classes/Sections/Input/TradeInputContainer.m

@@ -7,21 +7,22 @@
 //
 
 #import "TradeInputContainer.h"
-#import "NIMGrowingTextView.h"
 #import "UIView+NIM.h"
 #import <NIMSDK/NIMSDK.h>
 #import "NIMKitMediaFetcher.h"
 #import "SVProgressHUD.h"
+#import "NIMInputView.h"
+#import "TradePriorityItemData.h"
 
 
 @interface TradeInputContainer()<NIMGrowingTextViewDelegate, UIScrollViewDelegate>
 
 @property (nonatomic, strong) UILabel               *countLabel;
 @property (nonatomic, strong) UIButton              *countBtn;
+@property (nonatomic, strong) UIView                *typeContainer;
 @property (nonatomic, strong) UISlider              *slider;
 @property (nonatomic, strong) UIView                *textViewContainer;
 @property (nonatomic, strong) UIView                *textViewBg;
-@property (nonatomic, strong) NIMGrowingTextView    *growTextView;
 @property (nonatomic, strong) UIButton              *sendBtn;
 @property (nonatomic, strong) UIScrollView          *picContainer;
 @property (nonatomic, strong) UIButton              *picAddBtn;
@@ -33,6 +34,10 @@
 @property (nonatomic, assign) int                   picUploadIndex;
 @property (nonatomic, strong) NIMKitMediaFetcher    *mediaFetcher;
 
+
+@property (nonatomic, strong) TradePriorityItemData *priorityItem;
+@property (nonatomic, strong) NSMutableArray        *priorityItemArr;
+
 @end
 
 @implementation TradeInputContainer
@@ -61,7 +66,7 @@
     titleLabel.text = @"置顶";
     [self addSubview:titleLabel];
     
-    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nim_width - 150, 5, 100, 40)];
+    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, self.nim_width-50, 40)];
     _countLabel.textAlignment = NSTextAlignmentRight;
     [self addSubview:_countLabel];
     
@@ -71,6 +76,7 @@
     [countBtn addTarget:self action:@selector(toggleSlider:) forControlEvents:UIControlEventTouchUpInside];
     [self addSubview:countBtn];
     
+    
     _slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 40, self.nim_width-40, 40)];
     _slider.minimumValue = 1;
     _slider.maximumValue = 100;
@@ -108,7 +114,7 @@
     [_sendBtn addTarget:self action:@selector(onTouchPublish:) forControlEvents:UIControlEventTouchUpInside];
     [_textViewContainer addSubview:_sendBtn];
     
-    _picContainer = [[UIScrollView alloc] initWithFrame:CGRectMake(10, self.nim_height-55, self.nim_width-20, 50)];
+    _picContainer = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 130, self.nim_width-20, 50)];
     [self addSubview:_picContainer];
     
     _picAddBtn = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -116,6 +122,13 @@
     [_picAddBtn setImage:[UIImage imageNamed:@"帮助与反馈_03"] forState:UIControlStateNormal];
     [_picAddBtn addTarget:self action:@selector(onTouchPicAdd:) forControlEvents:UIControlEventTouchUpInside];
     [self addSubview:_picAddBtn];
+    
+    
+    _typeContainer = [[UIView alloc] initWithFrame:CGRectMake(0, countBtn.nim_bottom, self.nim_width, 0)];
+    _typeContainer.backgroundColor = UIColor.lightGrayColor;
+    _typeContainer.layer.borderWidth = 0.5;
+    _typeContainer.layer.borderColor = UIColor.lightGrayColor.CGColor;
+    [self addSubview:_typeContainer];
 }
 
 
@@ -130,12 +143,94 @@
 }
 
 
+
+- (void)fillItemData:(NSMutableArray *)dataArr{
+    
+    _priorityItemArr = dataArr;
+    
+    int i=0;
+    float startY = 0;
+    float maxWidth = 0;
+    for(i=0; i<dataArr.count; i++)
+    {
+        TradePriorityItemData *item = [dataArr objectAtIndex:i];
+        UIButton *btn = nil;
+        if(i < _typeContainer.subviews.count)
+        {
+            btn = [_typeContainer.subviews objectAtIndex:i];
+            btn.hidden = NO;
+        }
+        else
+        {
+            btn = [UIButton buttonWithType:UIButtonTypeCustom];
+            btn.backgroundColor = UIColor.whiteColor;
+            [btn setTitleColor:UIColor.grayColor forState:UIControlStateNormal];
+            [btn setContentEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 10)];
+            [btn addTarget:self action:@selector(selectPriorityType:) forControlEvents:UIControlEventTouchUpInside];
+            [_typeContainer addSubview:btn];
+        }
+        btn.tag = item.type;
+        [btn setTitle:item.name forState:UIControlStateNormal];
+        [btn sizeToFit];
+        
+        btn.nim_top = startY;
+        startY += btn.nim_height + 1;
+        
+        if(btn.nim_width > maxWidth)
+        {
+            maxWidth = btn.nim_width;
+        }
+        
+        if(i == dataArr.count-1)
+        {
+            [self selectPriorityType:btn];
+        }
+    }
+    
+    for(int i=0; i<_typeContainer.subviews.count; i++)
+    {
+        UIButton *btn = [_typeContainer.subviews objectAtIndex:i];
+        btn.nim_width = maxWidth;
+        
+        if(i >= dataArr.count)
+            [btn setHidden:YES];
+    }
+    
+    _typeContainer.nim_width = maxWidth;
+    _typeContainer.nim_height = startY;
+    _typeContainer.nim_right = self.nim_width-50;
+    
+}
+
+
+
 - (void)toggleSlider:(int)sender{
-    _slider.hidden = !_slider.isHidden;
+    _typeContainer.hidden = !_typeContainer.isHidden;
 }
 
+
+- (void)selectPriorityType:(id)sender{
+    
+    UIButton *btn = sender;
+    int priorityType = (int)btn.tag;
+    
+    for(int i=0; i<_priorityItemArr.count; i++)
+    {
+        TradePriorityItemData *itemData = [_priorityItemArr objectAtIndex:i];
+        if(itemData.type == priorityType)
+        {
+            _priorityItem = itemData;
+            break;
+        }
+    }
+    
+    [self sliderValueChanged];
+    [_typeContainer setHidden:YES];
+}
+
+
 - (void)sliderValueChanged{
-    _countLabel.text = [NSString stringWithFormat:@"x%.0f", roundf(_slider.value)];
+    _countLabel.text = [NSString stringWithFormat:@"x%.0f (%@ 单价%d)", roundf(_slider.value), _priorityItem.name, _priorityItem.price];
 }
 
 - (void)didChangeHeight:(CGFloat)height
@@ -252,10 +347,12 @@
 
 - (void)onTouchPublish:(int)sender{
     
-    if (self.delegate && [self.delegate respondsToSelector:@selector(sendTrade:picArr:priority:type:)]) {
+    [_growTextView resignFirstResponder];
+    
+    if (self.delegate && [self.delegate respondsToSelector:@selector(sendTrade:picArr:priority:priorityType:type:)]) {
         
         int count = (int)roundf(_slider.value);
-        [self.delegate sendTrade:_growTextView.text picArr:_picArr priority:count type:self.tradeType];
+        [self.delegate sendTrade:_growTextView.text picArr:_picArr priority:count priorityType:_priorityItem.type type:self.tradeType];
         
     }
 
@@ -263,6 +360,10 @@
 
 - (void)keyboardWillChangeFrame:(NSNotification *)notification
 {
+    if(self.isHidden)
+    {
+        return;
+    }
     
     NSDictionary *userInfo = notification.userInfo;
     CGRect endFrame   = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
@@ -270,13 +371,34 @@
     
     float keyBoardFrameTop = endFrame.origin.y;
     
-    if(keyBoardFrameTop == self.nim_viewController.view.nim_height)
-    {
-        _textViewContainer.nim_top = 80;
+    UIView *containerView = nil;
+    
+    for (UIView* next = self; next; next = next.superview) {
+        UIResponder* nextResponder = [next nextResponder];
+        if ([nextResponder isKindOfClass:[NIMInputView class]]) {
+            containerView = (UIView *)nextResponder;
+            break;
+        }
+        if([nextResponder isKindOfClass:[UIView class]])
+        {
+            if(((UIView *)nextResponder).tag == 99)
+            {
+                containerView = (UIView *)nextResponder;
+                break;
+            }
+        }
     }
-    else
+    
+    if(containerView)
     {
-        _textViewContainer.nim_top = 80 - endFrame.size.height + 110;
+        if(keyBoardFrameTop == self.nim_viewController.view.nim_height)
+        {
+            containerView.nim_bottom = keyBoardFrameTop;
+        }
+        else
+        {
+            containerView.nim_bottom = keyBoardFrameTop + 54;
+        }
     }
 }
 

+ 27 - 0
NIMKit/NIMKit/Classes/Sections/Input/TradePriorityItemData.h

@@ -0,0 +1,27 @@
+//
+//  TradePriorityItemData.h
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef NS_ENUM(NSInteger, TradePriorityType) {
+    TradePriorityCountry = 0,
+    TradePriorityProvince = 1,
+    TradePriorityCity = 2,
+    TradePriorityDistrict = 3
+};
+
+@interface TradePriorityItemData : NSObject
+
+@property (nonatomic, strong) NSString          *itemId;
+@property (nonatomic, strong) NSString          *name;
+@property (nonatomic, assign) int               price;
+@property (nonatomic, assign) int               type;
+
+- (instancetype)initByJson:(NSDictionary *)json;
+
+@end

+ 27 - 0
NIMKit/NIMKit/Classes/Sections/Input/TradePriorityItemData.m

@@ -0,0 +1,27 @@
+//
+//  TradePriorityItemData.m
+//  NIMDemo
+//
+//  Created by Fenix Wang on 2017/7/12.
+//  Copyright © 2017年 Netease. All rights reserved.
+//
+
+#import "TradePriorityItemData.h"
+
+@implementation TradePriorityItemData
+
+- (instancetype)initByJson:(NSDictionary *)json{
+    
+    self = [super init];
+    if(self)
+    {
+        _itemId = [json objectForKey:@"id"];
+        _name = [json objectForKey:@"name"];
+        _price = [[json objectForKey:@"price"] intValue];
+        _type = [[json objectForKey:@"type"] intValue];
+    }
+    
+    return self;
+}
+
+@end

+ 18 - 0
NIMKit/NIMKit/Classes/Sections/Session/View/NIMMessageCell.m

@@ -23,6 +23,7 @@
 
 @interface NIMMessageCell()<NIMPlayAudioUIDelegate,NIMMessageContentViewDelegate>{
     UILongPressGestureRecognizer *_longPressGesture;
+    UILongPressGestureRecognizer *_longPressAvatarGesture;
     UIMenuController             *_menuController;
 }
 
@@ -71,6 +72,7 @@
     //headerView
     _headImageView = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
     [_headImageView addTarget:self action:@selector(onTapAvatar:) forControlEvents:UIControlEventTouchUpInside];
+    
     [self.contentView addSubview:_headImageView];
     
     //nicknamel
@@ -95,6 +97,10 @@
 }
 
 - (void)makeGesture{
+    
+    _longPressAvatarGesture= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGesturePressAvatar:)];
+    [_headImageView addGestureRecognizer:_longPressAvatarGesture];
+    
     _longPressGesture= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGesturePress:)];
     [self addGestureRecognizer:_longPressGesture];
 }
@@ -327,6 +333,18 @@
     }
 }
 
+- (void)longGesturePressAvatar:(UIGestureRecognizer*)gestureRecognizer
+{
+    if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] &&
+        gestureRecognizer.state == UIGestureRecognizerStateBegan) {
+        if (self.delegate && [self.delegate respondsToSelector:@selector(onLongPressAvatar:)]) {
+            [self.delegate onLongPressAvatar:self.model.message.from];
+        }
+    }
+}
+
+
+
 
 #pragma mark - NIMPlayAudioUIDelegate
 - (void)startPlayingAudioUI