From 59d665b2ec75ea073785827de3bf0adc7dd7a067 Mon Sep 17 00:00:00 2001 From: Sandy <1074472615@qq.com> Date: Tue, 8 Aug 2017 18:30:27 +0800 Subject: [PATCH] bug fix --- HDMall.xcodeproj/project.pbxproj | 24 + .../Business/SaleInput/SaleInput.storyboard | 6 +- .../SaleInputAddViewController.h | 1 + .../SaleInputAddViewController.m | 10 +- .../SaleInputDetailViewController.m | 6 +- .../SaleInputListViewController.m | 59 +- .../ViewModels/SaleInputListViewModel.h | 24 + .../ViewModels/SaleInputListViewModel.m | 94 ++ .../SaleInput/ViewModels/SaleInputState.h | 4 +- .../SaleInput/ViewModels/SaleInputState.m | 17 + .../SaleInput/ViewModels/SaleInputViewModel.m | 2 +- .../SaleInput/Views/SaleInputTopView.m | 42 +- HDMall/HDMall_TEST.plist | 2 +- .../Tools/BaseClass/BaseListViewController.m | 2 +- .../Category/UIViewController+Additions.h | 1 + .../Category/UIViewController+Additions.m | 39 + HDMall/Tools/JSDropDownMenu/JSDropDownMenu.h | 91 ++ HDMall/Tools/JSDropDownMenu/JSDropDownMenu.m | 1015 +++++++++++++++++ HDMall/Tools/JSDropDownMenu/ico_make.png | Bin 0 -> 356 bytes HDMall/Tools/ZJAppInstance/ZJAppInstance.h | 3 + HDMall/Tools/ZJAppInstance/ZJAppInstance.m | 17 + .../ZJBaseHttpManager/ZJBaseHttpManager.m | 6 +- 22 files changed, 1415 insertions(+), 50 deletions(-) create mode 100644 HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.h create mode 100644 HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.m create mode 100755 HDMall/Tools/JSDropDownMenu/JSDropDownMenu.h create mode 100755 HDMall/Tools/JSDropDownMenu/JSDropDownMenu.m create mode 100755 HDMall/Tools/JSDropDownMenu/ico_make.png diff --git a/HDMall.xcodeproj/project.pbxproj b/HDMall.xcodeproj/project.pbxproj index b7d6c9e..43a8fa0 100644 --- a/HDMall.xcodeproj/project.pbxproj +++ b/HDMall.xcodeproj/project.pbxproj @@ -81,6 +81,9 @@ 8F973C271F21FD54003D3ADB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8F973BF01F21F6DD003D3ADB /* Main.storyboard */; }; 8F973C321F21FE32003D3ADB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F973C2F1F21FE32003D3ADB /* AppDelegate.m */; }; 8F973C341F21FE32003D3ADB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F973C301F21FE32003D3ADB /* main.m */; }; + 8FC2BE8F1F39AC270023FA6B /* SaleInputListViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FC2BE8E1F39AC270023FA6B /* SaleInputListViewModel.m */; }; + 8FC2BE941F39AC430023FA6B /* ico_make.png in Resources */ = {isa = PBXBuildFile; fileRef = 8FC2BE911F39AC430023FA6B /* ico_make.png */; }; + 8FC2BE951F39AC430023FA6B /* JSDropDownMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FC2BE931F39AC430023FA6B /* JSDropDownMenu.m */; }; 8FED0FB41F38602F004916CC /* AboutTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FED0FB31F38602F004916CC /* AboutTableViewController.m */; }; 8FEF5E641F285E56001496E3 /* CALayer+Addtions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FEF5E481F285E56001496E3 /* CALayer+Addtions.m */; }; 8FEF5E661F285E56001496E3 /* ChineseLogHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FEF5E4A1F285E56001496E3 /* ChineseLogHelper.m */; }; @@ -267,6 +270,11 @@ 8F973C2E1F21FE32003D3ADB /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; 8F973C2F1F21FE32003D3ADB /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; 8F973C301F21FE32003D3ADB /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; + 8FC2BE8D1F39AC270023FA6B /* SaleInputListViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaleInputListViewModel.h; sourceTree = "<group>"; }; + 8FC2BE8E1F39AC270023FA6B /* SaleInputListViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SaleInputListViewModel.m; sourceTree = "<group>"; }; + 8FC2BE911F39AC430023FA6B /* ico_make.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ico_make.png; sourceTree = "<group>"; }; + 8FC2BE921F39AC430023FA6B /* JSDropDownMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDropDownMenu.h; sourceTree = "<group>"; }; + 8FC2BE931F39AC430023FA6B /* JSDropDownMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSDropDownMenu.m; sourceTree = "<group>"; }; 8FED0FB21F38602F004916CC /* AboutTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AboutTableViewController.h; sourceTree = "<group>"; }; 8FED0FB31F38602F004916CC /* AboutTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutTableViewController.m; sourceTree = "<group>"; }; 8FEF5E471F285E56001496E3 /* CALayer+Addtions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CALayer+Addtions.h"; sourceTree = "<group>"; }; @@ -680,6 +688,8 @@ 8F4BFCE71F2F07C1003EA16B /* SaleInputViewModel.m */, 8FF9F6E11F347517006B0EC0 /* SaleInputState.h */, 8FF9F6E21F347517006B0EC0 /* SaleInputState.m */, + 8FC2BE8D1F39AC270023FA6B /* SaleInputListViewModel.h */, + 8FC2BE8E1F39AC270023FA6B /* SaleInputListViewModel.m */, ); path = ViewModels; sourceTree = "<group>"; @@ -788,6 +798,7 @@ 8F973C041F21FB67003D3ADB /* Tools */ = { isa = PBXGroup; children = ( + 8FC2BE901F39AC430023FA6B /* JSDropDownMenu */, 8FF9F6E71F37FF6C006B0EC0 /* CustomMMSpreadSheetView */, 8F4BFCF51F2F3238003EA16B /* PictureTableViewCell */, 8F6C923F1F2AE4AD0060E983 /* LocationHelper */, @@ -965,6 +976,16 @@ path = ..; sourceTree = "<group>"; }; + 8FC2BE901F39AC430023FA6B /* JSDropDownMenu */ = { + isa = PBXGroup; + children = ( + 8FC2BE911F39AC430023FA6B /* ico_make.png */, + 8FC2BE921F39AC430023FA6B /* JSDropDownMenu.h */, + 8FC2BE931F39AC430023FA6B /* JSDropDownMenu.m */, + ); + path = JSDropDownMenu; + sourceTree = "<group>"; + }; 8FEF5E461F285E56001496E3 /* Category */ = { isa = PBXGroup; children = ( @@ -1132,6 +1153,7 @@ buildActionMask = 2147483647; files = ( 8F973C251F21FD54003D3ADB /* LaunchScreen.storyboard in Resources */, + 8FC2BE941F39AC430023FA6B /* ico_make.png in Resources */, 8F250D2F1F297DA80031B4BC /* restrictedshine.tiff in Resources */, 8F250D2D1F297DA80031B4BC /* mask.jpg in Resources */, 8F4BFCC71F2EDCD8003EA16B /* BusinessItems.plist in Resources */, @@ -1211,6 +1233,7 @@ 8F6C92381F2ADF4F0060E983 /* HomeWeatherBoard.m in Sources */, 8F250D961F29D86E0031B4BC /* ZJPermissionManager.m in Sources */, 8F4BFD061F2F3314003EA16B /* GalleryCollectionViewCell.m in Sources */, + 8FC2BE8F1F39AC270023FA6B /* SaleInputListViewModel.m in Sources */, 8F250D921F29D4B40031B4BC /* UserInfo.m in Sources */, 8F1040B91F25C8A000B4C16E /* MineTableViewController.m in Sources */, 8F6C923B1F2ADFEC0060E983 /* WeatherModel.m in Sources */, @@ -1272,6 +1295,7 @@ 8FF9F7021F37FF6C006B0EC0 /* MMTopRowCell.m in Sources */, 8F250D271F297DA80031B4BC /* XWInteractiveTransition.m in Sources */, 8F250D391F297DA80031B4BC /* XWCoolAnimator+XWMiddlePageFlip.m in Sources */, + 8FC2BE951F39AC430023FA6B /* JSDropDownMenu.m in Sources */, 8FF9F7031F37FF6C006B0EC0 /* MMViewController.m in Sources */, 8F250D531F297DA80031B4BC /* XWFilterAnimator+XWRipple.m in Sources */, 8F4BFCD61F2EF56A003EA16B /* SaleInputListTableViewCell.m in Sources */, diff --git a/HDMall/CodeClass/Business/SaleInput/SaleInput.storyboard b/HDMall/CodeClass/Business/SaleInput/SaleInput.storyboard index 68efe8e..b20228a 100644 --- a/HDMall/CodeClass/Business/SaleInput/SaleInput.storyboard +++ b/HDMall/CodeClass/Business/SaleInput/SaleInput.storyboard @@ -22,7 +22,7 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="159" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="AOL-sy-21t"> - <rect key="frame" x="0.0" y="20" width="375" height="647"/> + <rect key="frame" x="0.0" y="64" width="375" height="603"/> <color key="backgroundColor" red="0.90188914539999998" green="0.89984929560000004" blue="0.93195199969999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <inset key="separatorInset" minX="15" minY="0.0" maxX="0.0" maxY="0.0"/> <prototypes> @@ -196,7 +196,7 @@ <constraints> <constraint firstAttribute="trailing" secondItem="aQG-ol-2ju" secondAttribute="trailing" constant="30" id="3C9-JN-WBq"/> <constraint firstAttribute="trailing" secondItem="AOL-sy-21t" secondAttribute="trailing" id="Kdx-SC-TsM"/> - <constraint firstItem="AOL-sy-21t" firstAttribute="top" secondItem="fKx-QB-8T3" secondAttribute="bottom" id="QOO-8v-8hV"/> + <constraint firstItem="AOL-sy-21t" firstAttribute="top" secondItem="fKx-QB-8T3" secondAttribute="bottom" constant="44" id="QOO-8v-8hV"/> <constraint firstItem="AOL-sy-21t" firstAttribute="leading" secondItem="j2C-xo-rlz" secondAttribute="leading" id="iu7-Rm-0Jn"/> <constraint firstAttribute="bottom" secondItem="aQG-ol-2ju" secondAttribute="bottom" constant="30" id="mt7-Yx-faA"/> <constraint firstItem="dCI-SM-A4p" firstAttribute="top" secondItem="AOL-sy-21t" secondAttribute="bottom" id="wkx-IT-CW7"/> @@ -1346,7 +1346,7 @@ <color key="textColor" red="1" green="0.9999405146" blue="0.99998033050000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <nil key="highlightedColor"/> </label> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="商铺" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tk7-yh-1u7"> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="åˆåŒ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tk7-yh-1u7"> <rect key="frame" x="32" y="31" width="37" height="22"/> <fontDescription key="fontDescription" type="system" pointSize="18"/> <color key="textColor" red="1" green="0.9999405146" blue="0.99998033050000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> diff --git a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.h b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.h index 5b9e68a..54724f9 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.h +++ b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.h @@ -24,4 +24,5 @@ - (void)httpPayments; - (void)allInputMoney; +- (IBAction)actionSubmit:(id)sender; @end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.m b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.m index f73f727..374df67 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.m +++ b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputAddViewController.m @@ -18,9 +18,10 @@ [super viewDidLoad]; self.title = @"新建销售录入"; self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 84, 0); - UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"åŽ†å²æŸ¥è¯¢" style:UIBarButtonItemStylePlain target:self action:@selector(actionGoHistory)]; + UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"历å²" style:UIBarButtonItemStylePlain target:self action:@selector(actionGoHistory)]; self.navigationItem.rightBarButtonItem = rightBtn; + [self httpPayments]; } @@ -104,13 +105,16 @@ - (IBAction)actionSubmit:(id)sender { self.viewModel.request.saleCount = @(self.totalView.textFieldBillCount.text.integerValue); self.viewModel.request.contract = self.topView.contract; + self.viewModel.request.saleDate = self.topView.textFieldDate.text; WS(weakSelf); //赋值 - kCanNotBeNil(self.viewModel.request.contract, @"请选择åˆåŒ"); + kCanNotBeNil(self.viewModel.request.contract, @"请选择åˆåŒ!"); - [self alertTitle:@"温馨æç¤º" msg:@"确认æäº¤ï¼Ÿ" okAction:^(UIAlertAction * _Nullable action) { + NSString *msg = [NSString stringWithFormat:@"销售日期:%@\n总金é¢ï¼š %@\n\n确认æäº¤ï¼Ÿ",self.topView.textFieldDate.text, self.totalView.labelTotal.text]; + [self alertTitle:@"温馨æç¤º" msg:msg okAction:^(UIAlertAction * _Nullable action) { [weakSelf.viewModel httpSubmit:^(BOOL isSuccess) { if (isSuccess) { + weakSelf.commplete(); [weakSelf.navigationController popViewControllerAnimated:YES]; } }]; diff --git a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputDetailViewController.m b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputDetailViewController.m index 589ef3a..39a24f6 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputDetailViewController.m +++ b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputDetailViewController.m @@ -23,7 +23,7 @@ self.topView.right2.hidden = YES; self.topView.userInteractionEnabled = NO; self.totalView.textFieldBillCount.userInteractionEnabled = NO; - self.btnBottom.hidden = YES; + [self.btnBottom setTitle:@"返回" forState:UIControlStateNormal]; self.title = @"销售录入详情"; WS(weakSelf); [self.viewModel httpDetailWithUuid:self.listModel.billNumber callBack:^(BOOL isSuccess) { @@ -46,6 +46,10 @@ CLog(@"空实现父类httpPayments方法"); } +- (IBAction)actionSubmit:(id)sender { + [self.navigationController popViewControllerAnimated:YES]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. diff --git a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputListViewController.m b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputListViewController.m index d503e0d..7e580c2 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputListViewController.m +++ b/HDMall/CodeClass/Business/SaleInput/ViewControllers/SaleInputListViewController.m @@ -12,8 +12,11 @@ #import "HMSaleInputDetail.h" #import "SaleInputDetailViewController.h" #import "HMSaleInputQuery.h" +#import "JSDropDownMenu.h" +#import "SaleInputListViewModel.h" @interface SaleInputListViewController () -@property (strong, nonatomic) HMSaleInputQuery *query; + +@property (strong, nonatomic) SaleInputListViewModel *viewModel; @end @@ -26,6 +29,23 @@ [self refresh]; self.tableView.rowHeight = 159; self.btnAdd.hidden = !AppGlobal.permission.saleinput.newField; + [self configDropMenu]; +} + +- (void)configDropMenu { + JSDropDownMenu *menu = [[JSDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:45]; + menu.indicatorColor = [UIColor colorWithRed:175.0f / 255.0f green:175.0f / 255.0f blue:175.0f / 255.0f alpha:1.0]; + menu.separatorColor = [UIColor colorWithRed:210.0f / 255.0f green:210.0f / 255.0f blue:210.0f / 255.0f alpha:1.0]; + menu.textColor = [UIColor colorWithRed:83.f / 255.0f green:83.f / 255.0f blue:83.f / 255.0f alpha:1.0f]; + menu.dataSource = self.viewModel; + menu.delegate = self.viewModel; + [self.view addSubview:menu]; + + WS(weakSelf); + self.viewModel.blockRequest = ^{ + weakSelf.page = 1; + [weakSelf httpRequest]; + }; } - (void)viewWillAppear:(BOOL)animated { @@ -34,16 +54,14 @@ } - (void)httpRequest { - self.query.contracts = [AppGlobal getUserContractUuids]; - self.query.page = @(self.page); - self.query.pageSize = @(self.pageSize); - self.query.dateRange = [HMSaleInputQuery_dateRange new]; - self.query.dateRange.beginDate = @"2016-07-12"; - self.query.dateRange.endDate = [NSDate date].yearMonthDayString; + self.viewModel.query.page = @(self.page); + self.viewModel.query.pageSize = @(self.pageSize); WS(weakSelf); - [ZJHttpManager POST:@"hdmall/salesinput/query" parameters:self.query.toDictionary complete:^(id responseObject, NSError *error) { + [MBProgressHUD j_loading]; + [ZJHttpManager POST:@"hdmall/salesinput/query" parameters:self.viewModel.query.toDictionary complete:^(id responseObject, NSError *error) { + [MBProgressHUD j_hideLoadingView]; if (kIsResponse) { - if (weakSelf.page == 0) { + if (weakSelf.page == 1) { [weakSelf.arrData removeAllObjects]; } @@ -75,25 +93,14 @@ - (void)actionAdd:(UIButton *)sender { SaleInputAddViewController *addVC = [SaleInputAddViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_SALEINPUT]; - + WS(weakSelf); + addVC.commplete = ^{ + weakSelf.page = 1; + [weakSelf httpRequest]; + }; [self listPushCustomAnimate:addVC]; } -ZJLazy(HMSaleInputQuery, query); - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -/* -#pragma mark - Navigation - -// In a storyboard-based application, you will often want to do a little preparation before navigation -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. -} -*/ +ZJLazy(SaleInputListViewModel, viewModel); @end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.h b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.h new file mode 100644 index 0000000..4cc6a62 --- /dev/null +++ b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.h @@ -0,0 +1,24 @@ +// +// SaleInputListViewModel.h +// HDMall +// +// Created by Javen on 2017/8/8. +// Copyright © 2017å¹´ 上海勾芒信æ¯ç§‘技. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "JSDropDownMenu.h" +#import "HMSaleInputQuery.h" +#import "SaleInputState.h" +@interface SaleInputListViewModel : NSObject<JSDropDownMenuDataSource, JSDropDownMenuDelegate> +@property (strong, nonatomic) NSArray *arrDropMenu; +@property (strong, nonatomic) NSArray *arrDateTitles; +@property (strong, nonatomic) NSArray *arrStateTitles; + +@property (assign, nonatomic) NSInteger dateTag; +@property (assign, nonatomic) NSInteger stateTag; + +@property (strong, nonatomic) HMSaleInputQuery *query; +@property (copy, nonatomic) void (^blockRequest)(void); + +@end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.m b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.m new file mode 100644 index 0000000..9c27889 --- /dev/null +++ b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputListViewModel.m @@ -0,0 +1,94 @@ +// +// SaleInputListViewModel.m +// HDMall +// +// Created by Javen on 2017/8/8. +// Copyright © 2017å¹´ 上海勾芒信æ¯ç§‘技. All rights reserved. +// + +#import "SaleInputListViewModel.h" +#import "NSDate+Additions.h" +#define KDateRangeTypeWeek @"最近一周" +#define KDateRangeTypeOneMonth @"最近一月" +#define KDateRangeTypeThreeMonth @"最近三月" +@implementation SaleInputListViewModel + +- (instancetype)init { + self = [super init]; + if (self) { + self.arrDateTitles = @[KDateRangeTypeWeek, KDateRangeTypeOneMonth, KDateRangeTypeThreeMonth]; + self.arrStateTitles = @[@"全部",@"未生效", @"已生效"]; + self.arrDropMenu = @[self.arrDateTitles, self.arrStateTitles]; + + //第一次请求,默认是最近一周 + NSDate *end = [NSDate date]; + NSDate *begin = [NSDate dateWithTimeInterval:-7 * 24 * 60 * 60 sinceDate:end]; + self.query.contracts = [AppGlobal getUserContractUuids]; + self.query.dateRange = [HMSaleInputQuery_dateRange new]; + self.query.dateRange.beginDate = begin.yearMonthDayString; + self.query.dateRange.endDate = end.yearMonthDayString; + } + return self; +} + +- (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu { + return 2; +} + +- (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow { + return [self.arrDropMenu[column] count]; +} + +- (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column { + return [self.arrDropMenu[column] firstObject]; +} + +- (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath { + return [self.arrDropMenu[indexPath.column] objectAtIndex:indexPath.row]; +} + +- (BOOL)haveRightTableViewInColumn:(NSInteger)column { + return NO; +} + +- (CGFloat)widthRatioOfLeftColumn:(NSInteger)column { + return 1; +} + +- (NSInteger)currentLeftSelectedRow:(NSInteger)column { + if (column == 0) { + return self.dateTag; + } else { + return self.stateTag; + } +} + +- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath { + NSString *title = [self.arrDropMenu[indexPath.column] objectAtIndex:indexPath.row]; + if (indexPath.column == 0) { + self.dateTag = indexPath.row; + NSDate *end = [NSDate date]; + NSDate *begin = nil; + if ([title isEqualToString:KDateRangeTypeWeek]) { + begin = [NSDate dateWithTimeInterval:-7 * 24 * 60 * 60 sinceDate:end]; + }else if ([title isEqualToString:KDateRangeTypeOneMonth]){ + begin = [NSDate dateWithTimeInterval:-30 * 24 * 60 * 60 sinceDate:end]; + }else if ([title isEqualToString:KDateRangeTypeThreeMonth]){ + begin = [NSDate dateWithTimeInterval:-90 * 24 * 60 * 60 sinceDate:end]; + } + self.query.dateRange.beginDate = begin.yearMonthDayString; + self.query.dateRange.endDate = end.yearMonthDayString; + } else { + self.stateTag = indexPath.row; + if (indexPath.row == 0) { + self.query.state = nil; + }else{ + self.query.state = [SaleInputState stateWithText:title].code; + } + } + self.blockRequest(); +} + +ZJLazy(HMSaleInputQuery, query); + +@end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.h b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.h index ab0223f..3c46407 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.h +++ b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.h @@ -20,5 +20,7 @@ */ @property (strong, nonatomic) NSDictionary *dicData; -//+ (SaleInputState *)stateWithText:(NSString *)text; ++ (SaleInputState *)stateWithText:(NSString *)text; + ++ (NSArray *)allStateCodes; @end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.m b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.m index 0eeedcc..31a7d4a 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.m +++ b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputState.m @@ -26,4 +26,21 @@ self.text = [[self.dicData objectForKey:code] objectForKey:@"text"]; self.img = [[self.dicData objectForKey:code] objectForKey:@"img"]; } + ++ (SaleInputState *)stateWithText:(NSString *)text { + SaleInputState *state = [SaleInputState new]; + for (NSString *key in state.dicData.allKeys) { + NSDictionary *dic = [state.dicData objectForKey:key]; + if ([[dic objectForKey:@"text"] isEqualToString:text]) { + state.code = key; + break; + } + } + return state; +} + ++ (NSArray *)allStateCodes { + SaleInputState *state = [SaleInputState new]; + return state.dicData.allKeys; +} @end diff --git a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputViewModel.m b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputViewModel.m index 87a4ccb..0d4adcc 100644 --- a/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputViewModel.m +++ b/HDMall/CodeClass/Business/SaleInput/ViewModels/SaleInputViewModel.m @@ -41,7 +41,7 @@ self.request.store = [HMSaleInputDetail_store modelWithDic:AppGlobal.user.store.toDictionary]; self.request.receiver = @"contract"; self.request.balance = false; - self.request.saleDate = [[NSDate date] yearMonthDayString]; +// self.request.saleDate = [[NSDate date] yearMonthDayString]; self.request.payments = (id)[NSMutableArray array]; for (HMSaleInputDetail_payments *payments in self.arrPayments) { HMSaleInputDetail_payments *paymentsCopy = [HMSaleInputDetail_payments modelWithDic:payments.toDictionary]; diff --git a/HDMall/CodeClass/Business/SaleInput/Views/SaleInputTopView.m b/HDMall/CodeClass/Business/SaleInput/Views/SaleInputTopView.m index 8c04a28..386efe8 100644 --- a/HDMall/CodeClass/Business/SaleInput/Views/SaleInputTopView.m +++ b/HDMall/CodeClass/Business/SaleInput/Views/SaleInputTopView.m @@ -14,24 +14,43 @@ - (void)awakeFromNib { [super awakeFromNib]; + self.textFieldDate.type = DateTextFieldYearMonthDay; + self.textFieldDate.rangeType = DateTextFieldRangeBefore; + WS(weakSelf); + self.textFieldDate.blockEndEdit = ^{ + kCanNotBeNil(weakSelf.contract.uuid, @"请先选择åˆåŒ!"); + [weakSelf httpToDayData]; + }; + if (!AppGlobal.isMall) { self.btnStore.userInteractionEnabled = NO; self.right1.hidden = YES; UserInfo_contracts *contract = AppGlobal.user.contracts[0]; self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary]; [self.btnStore setTitle:contract.name forState:UIControlStateNormal]; + [self actionContract:nil]; + } + + //如果是æ¯å¤©æ—©æ™¨11点之å‰è¿›å…¥é”€å”®å½•入页é¢ï¼Œåˆ™æ˜¾ç¤ºæ—¥æœŸä¸ºæ˜¨å¤© + NSDate *dateNow = [NSDate date]; + //时间点å—符串 + NSString *point = [dateNow.yearMonthDayString stringByAppendingString:@" 11:00:00"]; + NSDateFormatter *f = [NSDateFormatter new]; + [f setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; + NSDate *datePoint = [f dateFromString:point]; + NSComparisonResult result = [dateNow compare:datePoint]; + + if (result == NSOrderedAscending) {//å°äºŽ + NSDate *yesterDay = [NSDate dateWithTimeInterval:- 24 * 60 * 60 sinceDate:dateNow]; + self.textFieldDate.text = yesterDay.yearMonthDayString; + }else{ + self.textFieldDate.text = [dateNow yearMonthDayString]; } - self.textFieldDate.type = DateTextFieldYearMonthDay; - self.textFieldDate.rangeType = DateTextFieldRangeBefore; - WS(weakSelf); - self.textFieldDate.blockEndEdit = ^{ - [weakSelf httpToDayData]; - }; } - (IBAction)actionContract:(id)sender { - if (AppGlobal.user.contracts.count == 1) { - UserInfo_contracts *contract = AppGlobal.user.contracts[0]; + if (!AppGlobal.isMall) { + UserInfo_contracts *contract = [AppGlobal getTenantContract]; self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary]; [self.btnStore setTitle:contract.name forState:UIControlStateNormal]; [self httpToDayData]; @@ -39,7 +58,8 @@ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择åˆåŒ" message:nil preferredStyle:(UIAlertControllerStyleAlert)]; for (UserInfo_contracts *contract in AppGlobal.user.contracts) { - UIAlertAction *action = [UIAlertAction actionWithTitle:contract.name style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + NSString *title = [NSString stringWithFormat:@"%@ã€%@】", contract.name, contract.code]; + UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary]; [self.btnStore setTitle:contract.name forState:UIControlStateNormal]; [self httpToDayData]; @@ -58,7 +78,9 @@ * 获å–ä»Šæ—¥çš„é”€å”®å½•å…¥æ•°æ® */ - (void)httpToDayData { - kCanNotBeNil(self.contract.uuid, @"请选择åˆåŒï¼"); + if (self.contract == nil) { + return; + } NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:self.contract.uuid, @"contract", [NSDictionary dictionaryWithObjectsAndKeys:[self.textFieldDate.text stringByAppendingString:@" 00:00:00"], @"beginDate", [self.textFieldDate.text stringByAppendingString:@" 23:59:59"], @"endDate", nil], @"dateRange", nil]; [MBProgressHUD j_loading]; WS(weakSelf); diff --git a/HDMall/HDMall_TEST.plist b/HDMall/HDMall_TEST.plist index 23ff070..5931afe 100644 --- a/HDMall/HDMall_TEST.plist +++ b/HDMall/HDMall_TEST.plist @@ -17,7 +17,7 @@ <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> - <string>1.0</string> + <string>1.0.0</string> <key>CFBundleVersion</key> <string>1</string> <key>LSRequiresIPhoneOS</key> diff --git a/HDMall/Tools/BaseClass/BaseListViewController.m b/HDMall/Tools/BaseClass/BaseListViewController.m index 5938197..5e22321 100644 --- a/HDMall/Tools/BaseClass/BaseListViewController.m +++ b/HDMall/Tools/BaseClass/BaseListViewController.m @@ -145,7 +145,7 @@ } - (void)listTableViewReloadData { - [MBProgressHUD j_hideLoadingView]; +// [MBProgressHUD j_hideLoadingView]; self.tableView.emptyDataSetSource = self; self.tableView.emptyDataSetDelegate = self; [self.tableView reloadData]; diff --git a/HDMall/Tools/Category/UIViewController+Additions.h b/HDMall/Tools/Category/UIViewController+Additions.h index 5a2cc61..d979913 100644 --- a/HDMall/Tools/Category/UIViewController+Additions.h +++ b/HDMall/Tools/Category/UIViewController+Additions.h @@ -114,4 +114,5 @@ typedef NS_ENUM(NSInteger, STORYBOARD_TYPE_) { */ - (void)hasPermission:(BOOL)permission yes:(void (^__nonnull)(void))yes no:(void (^__nonnull)(void))no; ++ (UIViewController *_Nullable)getCurrentVC; @end diff --git a/HDMall/Tools/Category/UIViewController+Additions.m b/HDMall/Tools/Category/UIViewController+Additions.m index 889cbad..4c4dc1a 100644 --- a/HDMall/Tools/Category/UIViewController+Additions.m +++ b/HDMall/Tools/Category/UIViewController+Additions.m @@ -151,4 +151,43 @@ return [numberPre evaluateWithObject:futureString]; } +//获å–当å‰å±å¹•显示的viewcontroller ++ (UIViewController *)getCurrentVC +{ + UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; + + UIViewController *currentVC = [self getCurrentVCFrom:rootViewController]; + + return currentVC; +} + ++ (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC +{ + UIViewController *currentVC; + + if ([rootVC presentedViewController]) { + // 视图是被presented出æ¥çš„ + + rootVC = [rootVC presentedViewController]; + } + + if ([rootVC isKindOfClass:[UITabBarController class]]) { + // æ ¹è§†å›¾ä¸ºUITabBarController + + currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]]; + + } else if ([rootVC isKindOfClass:[UINavigationController class]]){ + // æ ¹è§†å›¾ä¸ºUINavigationController + + currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]]; + + } else { + // æ ¹è§†å›¾ä¸ºéžå¯¼èˆªç±» + + currentVC = rootVC; + } + + return currentVC; +} + @end diff --git a/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.h b/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.h new file mode 100755 index 0000000..2e26859 --- /dev/null +++ b/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.h @@ -0,0 +1,91 @@ +// +// JSDropDownMenu.h +// JSDropDownMenu +// +// Created by Jsfu on 15-1-12. +// Copyright (c) 2015å¹´ jsfu. All rights reserved. +// + +#import <UIKit/UIKit.h> + +#import <UIKit/UIKit.h> + +@interface JSIndexPath : NSObject + +@property (nonatomic, assign) NSInteger column; +// 0 左边 1 å³è¾¹ +@property (nonatomic, assign) NSInteger leftOrRight; +// 左边行 +@property (nonatomic, assign) NSInteger leftRow; +// å³è¾¹è¡Œ +@property (nonatomic, assign) NSInteger row; + +- (instancetype)initWithColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row; ++ (instancetype)indexPathWithCol:(NSInteger)col leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row; + +@end + +#pragma mark - data source protocol +@class JSDropDownMenu; + +@protocol JSDropDownMenuDataSource <NSObject> + +@required +- (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow; +- (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath; +- (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column; +/** + * 表视图显示时,左边表显示比例 + */ +- (CGFloat)widthRatioOfLeftColumn:(NSInteger)column; +/** + * 表视图显示时,是å¦éœ€è¦ä¸¤ä¸ªè¡¨æ˜¾ç¤º + */ +- (BOOL)haveRightTableViewInColumn:(NSInteger)column; + +/** + * 返回当å‰èœå•左边表选ä¸è¡Œ + */ +- (NSInteger)currentLeftSelectedRow:(NSInteger)column; + +@optional +//default value is 1 +- (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu; + +/** + * 是å¦éœ€è¦æ˜¾ç¤ºä¸ºUICollectionView é»˜è®¤ä¸ºå¦ + */ +- (BOOL)displayByCollectionViewInColumn:(NSInteger)column; + +@end + +#pragma mark - delegate +@protocol JSDropDownMenuDelegate <NSObject> +@optional +- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath; +- (void)menu:(JSDropDownMenu *)menu didTapMenuAtIndex:(NSInteger)index; +@end + +#pragma mark - interface +@interface JSDropDownMenu : UIView <UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout> + +@property (nonatomic, weak) id <JSDropDownMenuDataSource> dataSource; +@property (nonatomic, weak) id <JSDropDownMenuDelegate> delegate; + +@property (nonatomic, strong) UIColor *indicatorColor; +@property (nonatomic, strong) UIColor *textColor; +@property (nonatomic, strong) UIColor *separatorColor; +@property (nonatomic, copy) void (^blockTapMenu)(NSInteger index); +/** + * the width of menu will be set to screen width defaultly + * + * @param origin the origin of this view's frame + * @param height menu's height + * + * @return menu + */ +- (instancetype)initWithOrigin:(CGPoint)origin andHeight:(CGFloat)height; +- (NSString *)titleForRowAtIndexPath:(JSIndexPath *)indexPath; +- (void)updateMenuTitle:(NSString *)string; +- (void)backgroundTapped:(UITapGestureRecognizer *)paramSender; +@end diff --git a/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.m b/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.m new file mode 100755 index 0000000..0e57500 --- /dev/null +++ b/HDMall/Tools/JSDropDownMenu/JSDropDownMenu.m @@ -0,0 +1,1015 @@ +// +// JSDropDownMenu.m +// JSDropDownMenu +// +// Created by Jsfu on 15-1-12. +// Copyright (c) 2015å¹´ jsfu. All rights reserved. +// + +#import "JSDropDownMenu.h" + +#define BackColor [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0] +// 选ä¸é¢œè‰²åŠ æ·± +#define SelectColor [UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0] + +@interface NSString (Size) + +- (CGSize)textSizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode; + +@end + +@implementation NSString (Size) + +- (CGSize)textSizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode +{ + CGSize textSize; + if (CGSizeEqualToSize(size, CGSizeZero)) + { + NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + + textSize = [self sizeWithAttributes:attributes]; + } + else + { + NSStringDrawingOptions option = NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading; + //NSStringDrawingTruncatesLastVisibleLine如果文本内容超出指定的矩形é™åˆ¶ï¼Œæ–‡æœ¬å°†è¢«æˆªåŽ»å¹¶åœ¨æœ€åŽä¸€ä¸ªå—符åŽåŠ ä¸Šçœç•¥å·ã€‚ 如果指定了NSStringDrawingUsesLineFragmentOrigin选项,则该选项被忽略 NSStringDrawingUsesFontLeading计算行高时使用行间è·ã€‚(å—体大å°+行间è·=行高) + NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + CGRect rect = [self boundingRectWithSize:size + options:option + attributes:attributes + context:nil]; + + textSize = rect.size; + } + return textSize; +} + +@end + +@interface JSCollectionViewCell:UICollectionViewCell + +@property(nonatomic,strong) UILabel *textLabel; +@property(nonatomic,strong) UIImageView *accessoryView; + +-(void)removeAccessoryView; + +@end + +@implementation JSCollectionViewCell + +-(instancetype)initWithFrame:(CGRect)frame{ + + self = [super initWithFrame:frame]; + if (self) { + _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; + _textLabel.textAlignment = NSTextAlignmentCenter; + [self addSubview:_textLabel]; + } + return self; +} + +-(void)setAccessoryView:(UIImageView *)accessoryView{ + + [self removeAccessoryView]; + + _accessoryView = accessoryView; + + _accessoryView.frame = CGRectMake(self.frame.size.width-10-16, (self.frame.size.height-12)/2, 16, 12); + + [self addSubview:_accessoryView]; +} + +-(void)removeAccessoryView{ + + if(_accessoryView){ + + [_accessoryView removeFromSuperview]; + } +} + +@end + + + +@interface JSTableViewCell : UITableViewCell + +@property(nonatomic,readonly) UILabel *cellTextLabel; +@property(nonatomic,strong) UIImageView *cellAccessoryView; + +-(void)setCellText:(NSString *)text align:(NSString*)align; + +@end + +@implementation JSTableViewCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + // Initialization code + _cellTextLabel = [[UILabel alloc] init]; + _cellTextLabel.textAlignment = NSTextAlignmentCenter; + _cellTextLabel.font = [UIFont systemFontOfSize:14.0f]; + [self addSubview:_cellTextLabel]; + } + return self; +} + +-(void)setCellText:(NSString *)text align:(NSString*)align{ + + _cellTextLabel.text = text; + // åªå–宽度 + CGSize textSize = [text textSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(MAXFLOAT, 14) lineBreakMode:NSLineBreakByWordWrapping]; +// CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(MAXFLOAT, 14)]; + + CGFloat marginX = 20; + + if (![@"left" isEqualToString:align]) { + marginX = (self.frame.size.width-textSize.width)/2; + } + + _cellTextLabel.frame = CGRectMake(marginX, 0, textSize.width, self.frame.size.height); + + if(_cellAccessoryView){ + _cellAccessoryView.frame = CGRectMake(_cellTextLabel.frame.origin.x+_cellTextLabel.frame.size.width+10, (self.frame.size.height-12)/2, 16, 12); + } +} + +-(void)setCellAccessoryView:(UIImageView *)accessoryView{ + + if (_cellAccessoryView) { + [_cellAccessoryView removeFromSuperview]; + } + + _cellAccessoryView = accessoryView; + + _cellAccessoryView.frame = CGRectMake(_cellTextLabel.frame.origin.x+_cellTextLabel.frame.size.width+10, (self.frame.size.height-12)/2, 16, 12); + + [self addSubview:_cellAccessoryView]; +} + +@end + +@implementation JSIndexPath +- (instancetype)initWithColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row { + self = [super init]; + if (self) { + _column = column; + _leftOrRight = leftOrRight; + _leftRow = leftRow; + _row = row; + } + return self; +} + ++ (instancetype)indexPathWithCol:(NSInteger)col leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row { + JSIndexPath *indexPath = [[self alloc] initWithColumn:col leftOrRight:leftOrRight leftRow:leftRow row:row]; + return indexPath; +} +@end + +#pragma mark - menu implementation + +@interface JSDropDownMenu () +@property (nonatomic, assign) NSInteger currentSelectedMenudIndex; +@property (nonatomic, assign) BOOL show; +@property (nonatomic, assign) NSInteger numOfMenu; +@property (nonatomic, assign) CGPoint origin; +@property (nonatomic, strong) UIView *backGroundView; +@property (nonatomic, strong) UIView *bottomShadow; +@property (nonatomic, strong) UITableView *leftTableView; +@property (nonatomic, strong) UITableView *rightTableView; +@property (nonatomic, strong) UICollectionView *collectionView; +//data source +@property (nonatomic, copy) NSArray *array; +//layers array +@property (nonatomic, copy) NSArray *titles; +@property (nonatomic, copy) NSArray *indicators; +@property (nonatomic, copy) NSArray *bgLayers; +@property (nonatomic, assign) NSInteger leftSelectedRow; +@property (nonatomic, assign) BOOL hadSelected; + +@end + + +@implementation JSDropDownMenu + +- (void)removeFromSuperview +{ + [super removeFromSuperview]; + [self.backGroundView removeFromSuperview]; + [self.bottomShadow removeFromSuperview]; + [self.leftTableView removeFromSuperview]; + [self.rightTableView removeFromSuperview]; + [self.collectionView removeFromSuperview]; + +} + +#pragma mark - getter +- (UIColor *)indicatorColor { + if (!_indicatorColor) { + _indicatorColor = [UIColor blackColor]; + } + return _indicatorColor; +} + +- (UIColor *)textColor { + if (!_textColor) { + _textColor = [UIColor blackColor]; + } + return _textColor; +} + +- (UIColor *)separatorColor { + if (!_separatorColor) { + _separatorColor = [UIColor blackColor]; + } + return _separatorColor; +} + +- (NSString *)titleForRowAtIndexPath:(JSIndexPath *)indexPath { + return [self.dataSource menu:self titleForRowAtIndexPath:indexPath]; +} + +#pragma mark - setter +- (void)setDataSource:(id<JSDropDownMenuDataSource>)dataSource { + _dataSource = dataSource; + + //configure view + if ([_dataSource respondsToSelector:@selector(numberOfColumnsInMenu:)]) { + _numOfMenu = [_dataSource numberOfColumnsInMenu:self]; + } else { + _numOfMenu = 1; + } + + CGFloat textLayerInterval = self.frame.size.width / ( _numOfMenu * 2); + + CGFloat separatorLineInterval = self.frame.size.width / _numOfMenu; + + CGFloat bgLayerInterval = self.frame.size.width / _numOfMenu; + + NSMutableArray *tempTitles = [[NSMutableArray alloc] initWithCapacity:_numOfMenu]; + NSMutableArray *tempIndicators = [[NSMutableArray alloc] initWithCapacity:_numOfMenu]; + NSMutableArray *tempBgLayers = [[NSMutableArray alloc] initWithCapacity:_numOfMenu]; + + for (int i = 0; i < _numOfMenu; i++) { + //bgLayer + CGPoint bgLayerPosition = CGPointMake((i+0.5)*bgLayerInterval, self.frame.size.height/2); + CALayer *bgLayer = [self createBgLayerWithColor:BackColor andPosition:bgLayerPosition]; + [self.layer addSublayer:bgLayer]; + [tempBgLayers addObject:bgLayer]; + //title + CGPoint titlePosition = CGPointMake( (i * 2 + 1) * textLayerInterval , self.frame.size.height / 2); + NSString *titleString = [_dataSource menu:self titleForColumn:i]; + CATextLayer *title = [self createTextLayerWithNSString:titleString withColor:self.textColor andPosition:titlePosition]; + [self.layer addSublayer:title]; + [tempTitles addObject:title]; + //indicator + CAShapeLayer *indicator = [self createIndicatorWithColor:self.indicatorColor andPosition:CGPointMake(titlePosition.x + title.bounds.size.width / 2 + 8, self.frame.size.height / 2)]; + [self.layer addSublayer:indicator]; + [tempIndicators addObject:indicator]; + + //separator + if (i != _numOfMenu - 1) { + CGPoint separatorPosition = CGPointMake((i + 1) * separatorLineInterval, self.frame.size.height/2); + CAShapeLayer *separator = [self createSeparatorLineWithColor:self.separatorColor andPosition:separatorPosition]; + [self.layer addSublayer:separator]; + } + } + + _bottomShadow.backgroundColor = self.separatorColor; + + _titles = [tempTitles copy]; + _indicators = [tempIndicators copy]; + _bgLayers = [tempBgLayers copy]; +} + +#pragma mark - init method +- (instancetype)initWithOrigin:(CGPoint)origin andHeight:(CGFloat)height { + CGSize screenSize = [UIScreen mainScreen].bounds.size; + self = [self initWithFrame:CGRectMake(origin.x, origin.y, screenSize.width, height)]; + if (self) { + _origin = origin; + _currentSelectedMenudIndex = -1; + _show = NO; + + _hadSelected = NO; + + //tableView init + _leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(origin.x, self.frame.origin.y + self.frame.size.height, 0, 0) style:UITableViewStyleGrouped]; + _leftTableView.rowHeight = 38; + _leftTableView.separatorColor = [UIColor colorWithRed:220.f/255.0f green:220.f/255.0f blue:220.f/255.0f alpha:1.0]; + _leftTableView.dataSource = self; + _leftTableView.delegate = self; + + _rightTableView = [[UITableView alloc] initWithFrame:CGRectMake(self.frame.size.width, self.frame.origin.y + self.frame.size.height, 0, 0) style:UITableViewStyleGrouped]; + _rightTableView.rowHeight = 38; + _rightTableView.separatorColor = [UIColor colorWithRed:220.f/255.0f green:220.f/255.0f blue:220.f/255.0f alpha:1.0]; + _rightTableView.dataSource = self; + _rightTableView.delegate = self; + + UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init]; + flowLayout.minimumInteritemSpacing = 0; + _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width, 0) collectionViewLayout:flowLayout]; + + [_collectionView registerClass:[JSCollectionViewCell class] forCellWithReuseIdentifier:@"CollectionCell"]; + _collectionView.backgroundColor = [UIColor colorWithRed:220.f/255.0f green:220.f/255.0f blue:220.f/255.0f alpha:1.0]; + _collectionView.dataSource = self; + _collectionView.delegate = self; + + + self.autoresizesSubviews = NO; + _leftTableView.autoresizesSubviews = NO; + _rightTableView.autoresizesSubviews = NO; + _collectionView.autoresizesSubviews = NO; + + //self tapped + self.backgroundColor = [UIColor whiteColor]; + UIGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuTapped:)]; + [self addGestureRecognizer:tapGesture]; + + //background init and tapped + _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(origin.x, origin.y, screenSize.width, screenSize.height)]; + _backGroundView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0]; + _backGroundView.opaque = NO; + UIGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped:)]; + [_backGroundView addGestureRecognizer:gesture]; + + //add bottom shadow + _bottomShadow = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-0.5, screenSize.width, 0.5)]; + [self addSubview:_bottomShadow]; + } + return self; +} + +#pragma mark - init support +- (CALayer *)createBgLayerWithColor:(UIColor *)color andPosition:(CGPoint)position { + CALayer *layer = [CALayer layer]; + + layer.position = position; + layer.bounds = CGRectMake(0, 0, self.frame.size.width/self.numOfMenu, self.frame.size.height-1); + layer.backgroundColor = color.CGColor; + + return layer; +} + +- (CAShapeLayer *)createIndicatorWithColor:(UIColor *)color andPosition:(CGPoint)point { + CAShapeLayer *layer = [CAShapeLayer new]; + + UIBezierPath *path = [UIBezierPath new]; + [path moveToPoint:CGPointMake(0, 0)]; + [path addLineToPoint:CGPointMake(8, 0)]; + [path addLineToPoint:CGPointMake(4, 5)]; + [path closePath]; + + layer.path = path.CGPath; + layer.lineWidth = 1.0; + layer.fillColor = color.CGColor; + + CGPathRef bound = CGPathCreateCopyByStrokingPath(layer.path, nil, layer.lineWidth, kCGLineCapButt, kCGLineJoinMiter, layer.miterLimit); + layer.bounds = CGPathGetBoundingBox(bound); + + CGPathRelease(bound); + + layer.position = point; + + return layer; +} + +- (CAShapeLayer *)createSeparatorLineWithColor:(UIColor *)color andPosition:(CGPoint)point { + CAShapeLayer *layer = [CAShapeLayer new]; + + UIBezierPath *path = [UIBezierPath new]; + [path moveToPoint:CGPointMake(160,0)]; + [path addLineToPoint:CGPointMake(160, self.frame.size.height)]; + + layer.path = path.CGPath; + layer.lineWidth = 1.0; + layer.strokeColor = color.CGColor; + + CGPathRef bound = CGPathCreateCopyByStrokingPath(layer.path, nil, layer.lineWidth, kCGLineCapButt, kCGLineJoinMiter, layer.miterLimit); + layer.bounds = CGPathGetBoundingBox(bound); + + CGPathRelease(bound); + + layer.position = point; + + return layer; +} + +- (CATextLayer *)createTextLayerWithNSString:(NSString *)string withColor:(UIColor *)color andPosition:(CGPoint)point { + + CGSize size = [self calculateTitleSizeWithString:string]; + + CATextLayer *layer = [CATextLayer new]; + CGFloat sizeWidth = (size.width < (self.frame.size.width / _numOfMenu) - 25) ? size.width : self.frame.size.width / _numOfMenu - 25; + layer.bounds = CGRectMake(0, 0, sizeWidth, size.height); + layer.string = string; + layer.fontSize = 14.0; + layer.alignmentMode = kCAAlignmentCenter; + layer.foregroundColor = color.CGColor; + + layer.contentsScale = [[UIScreen mainScreen] scale]; + + layer.position = point; + + return layer; +} + +- (CGSize)calculateTitleSizeWithString:(NSString *)string +{ + CGFloat fontSize = 14.0; + NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:fontSize]}; + CGSize size = [string boundingRectWithSize:CGSizeMake(280, 0) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil].size; + return size; +} + +#pragma mark - gesture handle +- (void)menuTapped:(UITapGestureRecognizer *)paramSender { + CGPoint touchPoint = [paramSender locationInView:self]; + //calculate index + NSInteger tapIndex = touchPoint.x / (self.frame.size.width / _numOfMenu); + if ([_delegate respondsToSelector:@selector(menu:didTapMenuAtIndex:)]) { + [_delegate menu:self didTapMenuAtIndex:tapIndex]; + } + for (int i = 0; i < _numOfMenu; i++) { + if (i != tapIndex) { + [self animateIndicator:_indicators[i] Forward:NO complete:^{ + [self animateTitle:_titles[i] show:NO complete:^{ + + }]; + }]; + [(CALayer *)self.bgLayers[i] setBackgroundColor:BackColor.CGColor]; + } + } + + BOOL displayByCollectionView = NO; + + if ([_dataSource respondsToSelector:@selector(displayByCollectionViewInColumn:)]) { + + displayByCollectionView = [_dataSource displayByCollectionViewInColumn:tapIndex]; + } + + if (displayByCollectionView) { + + UICollectionView *collectionView = _collectionView; + + if (tapIndex == _currentSelectedMenudIndex && _show) { + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView collectionView:collectionView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _currentSelectedMenudIndex = tapIndex; + _show = NO; + }]; + + [(CALayer *)self.bgLayers[tapIndex] setBackgroundColor:BackColor.CGColor]; + } else { + + _currentSelectedMenudIndex = tapIndex; + + [_collectionView reloadData]; + + if (_currentSelectedMenudIndex!=-1) { + // 需è¦éšè—tableview + [self animateLeftTableView:_leftTableView rightTableView:_rightTableView show:NO complete:^{ + + [self animateIdicator:_indicators[tapIndex] background:_backGroundView collectionView:collectionView title:_titles[tapIndex] forward:YES complecte:^{ + _show = YES; + }]; + }]; + } else{ + [self animateIdicator:_indicators[tapIndex] background:_backGroundView collectionView:collectionView title:_titles[tapIndex] forward:YES complecte:^{ + _show = YES; + }]; + } + [(CALayer *)self.bgLayers[tapIndex] setBackgroundColor:SelectColor.CGColor]; + } + + } else{ + + BOOL haveRightTableView = [_dataSource haveRightTableViewInColumn:tapIndex]; +// UITableView *leftTableView = _leftTableView; + UITableView *rightTableView = nil; + + if (haveRightTableView) { + rightTableView = _rightTableView; + // 修改左å³tableview显示比例 + + } + + if (tapIndex == _currentSelectedMenudIndex && _show) { + + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _currentSelectedMenudIndex = tapIndex; + _show = NO; + }]; + + [(CALayer *)self.bgLayers[tapIndex] setBackgroundColor:BackColor.CGColor]; + } else { + + _hadSelected = NO; + + _currentSelectedMenudIndex = tapIndex; + + if ([_dataSource respondsToSelector:@selector(currentLeftSelectedRow:)]) { + + _leftSelectedRow = [_dataSource currentLeftSelectedRow:_currentSelectedMenudIndex]; + } + + if (rightTableView) { + [rightTableView reloadData]; + } + [_leftTableView reloadData]; + + CGFloat ratio = [_dataSource widthRatioOfLeftColumn:_currentSelectedMenudIndex]; + if (_leftTableView) { + + _leftTableView.frame = CGRectMake(_leftTableView.frame.origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width*ratio, 0); + } + + if (_rightTableView) { + + _rightTableView.frame = CGRectMake(_origin.x+_leftTableView.frame.size.width, self.frame.origin.y + self.frame.size.height, self.frame.size.width*(1-ratio), 0); + } + + if (_currentSelectedMenudIndex!=-1) { + // 需è¦éšè—collectionview + [self animateCollectionView:_collectionView show:NO complete:^{ + + [self animateIdicator:_indicators[tapIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[tapIndex] forward:YES complecte:^{ + _show = YES; + }]; + }]; + + } else{ + [self animateIdicator:_indicators[tapIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[tapIndex] forward:YES complecte:^{ + _show = YES; + }]; + } + [(CALayer *)self.bgLayers[tapIndex] setBackgroundColor:SelectColor.CGColor]; + } + } +} + +- (void)backgroundTapped:(UITapGestureRecognizer *)paramSender +{ + BOOL displayByCollectionView = NO; + + if ([_dataSource respondsToSelector:@selector(displayByCollectionViewInColumn:)]) { + + displayByCollectionView = [_dataSource displayByCollectionViewInColumn:_currentSelectedMenudIndex]; + } + if (displayByCollectionView) { + + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView collectionView:_collectionView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _show = NO; + }]; + + } else{ + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _show = NO; + }]; + } + + [(CALayer *)self.bgLayers[_currentSelectedMenudIndex] setBackgroundColor:BackColor.CGColor]; +} + +#pragma mark - animation method +- (void)animateIndicator:(CAShapeLayer *)indicator Forward:(BOOL)forward complete:(void(^)())complete { + [CATransaction begin]; + [CATransaction setAnimationDuration:0.25]; + [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithControlPoints:0.4 :0.0 :0.2 :1.0]]; + + CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"]; + anim.values = forward ? @[ @0, @(M_PI) ] : @[ @(M_PI), @0 ]; + + if (!anim.removedOnCompletion) { + [indicator addAnimation:anim forKey:anim.keyPath]; + } else { + [indicator addAnimation:anim forKey:anim.keyPath]; + [indicator setValue:anim.values.lastObject forKeyPath:anim.keyPath]; + } + + [CATransaction commit]; + + complete(); +} + +- (void)animateBackGroundView:(UIView *)view show:(BOOL)show complete:(void(^)())complete { + if (show) { + [self.superview addSubview:view]; + [view.superview addSubview:self]; + + [UIView animateWithDuration:0.2 animations:^{ + view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; + }]; + } else { + [UIView animateWithDuration:0.2 animations:^{ + view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0]; + } completion:^(BOOL finished) { + [view removeFromSuperview]; + }]; + } + complete(); +} + +/** + *动画显示下拉èœå• + */ +- (void)animateLeftTableView:(UITableView *)leftTableView rightTableView:(UITableView *)rightTableView show:(BOOL)show complete:(void(^)())complete { + + CGFloat ratio = [_dataSource widthRatioOfLeftColumn:_currentSelectedMenudIndex]; + NSInteger rowMaxNumber = (kHeight - 128)/ 38; + if (show) { + + CGFloat leftTableViewHeight = 0; + + CGFloat rightTableViewHeight = 0; + + if (leftTableView) { + + leftTableView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width*ratio, 0); + [self.superview addSubview:leftTableView]; + + leftTableViewHeight = ([leftTableView numberOfRowsInSection:0] > rowMaxNumber) ? (rowMaxNumber * leftTableView.rowHeight) : ([leftTableView numberOfRowsInSection:0] * leftTableView.rowHeight); + + } + + if([self.dataSource haveRightTableViewInColumn:_currentSelectedMenudIndex]){ + if (rightTableView) { + + rightTableView.frame = CGRectMake(_origin.x+leftTableView.frame.size.width, self.frame.origin.y + self.frame.size.height, self.frame.size.width*(1-ratio), 0); + + [self.superview addSubview:rightTableView]; + + rightTableViewHeight = ([rightTableView numberOfRowsInSection:0] > rowMaxNumber) ? (rowMaxNumber * rightTableView.rowHeight) : ([rightTableView numberOfRowsInSection:0] * rightTableView.rowHeight); + } + } + + CGFloat tableViewHeight = MAX(leftTableViewHeight, rightTableViewHeight); + + [UIView animateWithDuration:0.2 animations:^{ + if (leftTableView) { + leftTableView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width*ratio, tableViewHeight); + } + if (rightTableView) { + rightTableView.frame = CGRectMake(_origin.x+leftTableView.frame.size.width, self.frame.origin.y + self.frame.size.height, self.frame.size.width*(1-ratio), tableViewHeight); + } + }]; + } else { + [UIView animateWithDuration:0.2 animations:^{ + + if (leftTableView) { + leftTableView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width*ratio, 0); + } + if (rightTableView) { + rightTableView.frame = CGRectMake(_origin.x+leftTableView.frame.size.width, self.frame.origin.y + self.frame.size.height, self.frame.size.width*(1-ratio), 0); + } + + } completion:^(BOOL finished) { + + if (leftTableView) { + [leftTableView removeFromSuperview]; + } + if (rightTableView) { + [rightTableView removeFromSuperview]; + } + }]; + } + complete(); +} + +/** + *动画显示下拉èœå• + */ +- (void)animateCollectionView:(UICollectionView *)collectionView show:(BOOL)show complete:(void(^)())complete { + + if (show) { + + CGFloat collectionViewHeight = 0; + + if (collectionView) { + + collectionView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width, 0); + [self.superview addSubview:collectionView]; + + collectionViewHeight = (ceil([collectionView numberOfItemsInSection:0]/2.0) * 38); + } + + [UIView animateWithDuration:0.2 animations:^{ + if (collectionView) { + collectionView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width, collectionViewHeight); + } + }]; + } else { + [UIView animateWithDuration:0.2 animations:^{ + + if (collectionView) { + collectionView.frame = CGRectMake(_origin.x, self.frame.origin.y + self.frame.size.height, self.frame.size.width, 0); + } + } completion:^(BOOL finished) { + + if (collectionView) { + [collectionView removeFromSuperview]; + } + }]; + } + complete(); +} + +- (void)animateTitle:(CATextLayer *)title show:(BOOL)show complete:(void(^)())complete { + CGSize size = [self calculateTitleSizeWithString:title.string]; + CGFloat sizeWidth = (size.width < (self.frame.size.width / _numOfMenu) - 25) ? size.width : self.frame.size.width / _numOfMenu - 25; + title.bounds = CGRectMake(0, 0, sizeWidth, size.height); + complete(); +} + +- (void)animateIdicator:(CAShapeLayer *)indicator background:(UIView *)background leftTableView:(UITableView *)leftTableView rightTableView:(UITableView *)rightTableView title:(CATextLayer *)title forward:(BOOL)forward complecte:(void(^)())complete{ + + [self animateIndicator:indicator Forward:forward complete:^{ + [self animateTitle:title show:forward complete:^{ + [self animateBackGroundView:background show:forward complete:^{ + [self animateLeftTableView:leftTableView rightTableView:rightTableView show:forward complete:^{ + }]; + }]; + }]; + }]; + + complete(); +} + +- (void)animateIdicator:(CAShapeLayer *)indicator background:(UIView *)background collectionView:(UICollectionView *)collectionView title:(CATextLayer *)title forward:(BOOL)forward complecte:(void(^)())complete{ + + [self animateIndicator:indicator Forward:forward complete:^{ + [self animateTitle:title show:forward complete:^{ + [self animateBackGroundView:background show:forward complete:^{ + [self animateCollectionView:collectionView show:forward complete:^{ + + }]; + + }]; + }]; + }]; + + complete(); +} + +#pragma mark - table datasource +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + // 0 左边 1 å³è¾¹ + NSInteger leftOrRight = 0; + if (_rightTableView==tableView) { + leftOrRight = 1; + } + + NSAssert(self.dataSource != nil, @"menu's dataSource shouldn't be nil"); + if ([self.dataSource respondsToSelector:@selector(menu:numberOfRowsInColumn:leftOrRight: leftRow:)]) { + return [self.dataSource menu:self numberOfRowsInColumn:self.currentSelectedMenudIndex leftOrRight:leftOrRight leftRow:_leftSelectedRow]; + } else { + NSAssert(0 == 1, @"required method of dataSource protocol should be implemented"); + return 0; + } +} + +-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ + return 0.1; +} + +-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ + return 0.1; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *identifier = @"DropDownMenuCell"; + + UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; + + cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame]; + cell.selectedBackgroundView.backgroundColor = BackColor; + + UILabel *titleLabel = [[UILabel alloc] init]; + titleLabel.textColor = self.textColor; + titleLabel.tag = 1; + titleLabel.font = [UIFont systemFontOfSize:14.0]; + + [cell addSubview:titleLabel]; + + + NSInteger leftOrRight = 0; + + if (_rightTableView==tableView) { + + leftOrRight = 1; + } + +// UILabel *titleLabel = (UILabel*)[cell viewWithTag:1]; + + CGSize textSize; + + if ([self.dataSource respondsToSelector:@selector(menu:titleForRowAtIndexPath:)]) { + + titleLabel.text = [self.dataSource menu:self titleForRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:leftOrRight leftRow:_leftSelectedRow row:indexPath.row]]; + // åªå–宽度 + textSize = [titleLabel.text textSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(MAXFLOAT, 14) lineBreakMode:NSLineBreakByWordWrapping]; + + } + + cell.backgroundColor = [UIColor whiteColor]; + cell.textLabel.font = [UIFont systemFontOfSize:14.0]; + cell.separatorInset = UIEdgeInsetsZero; + + + if (leftOrRight == 1) { + + CGFloat marginX = 20; + + titleLabel.frame = CGRectMake(marginX, 0, textSize.width, cell.frame.size.height); + //å³è¾¹tableview + cell.backgroundColor = BackColor; + + if ([titleLabel.text isEqualToString:[(CATextLayer *)[_titles objectAtIndex:_currentSelectedMenudIndex] string]]) { + + UIImageView *accessoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ico_make"]]; + + accessoryImageView.frame = CGRectMake(titleLabel.frame.origin.x+titleLabel.frame.size.width+10, (self.frame.size.height-12)/2, 16, 12); + + [cell addSubview:accessoryImageView]; + } else{ + + + } + } else{ + + CGFloat ratio = [_dataSource widthRatioOfLeftColumn:_currentSelectedMenudIndex]; + + CGFloat marginX = (self.frame.size.width*ratio-textSize.width)/2; + + titleLabel.frame = CGRectMake(marginX, 0, textSize.width, cell.frame.size.height); + + if (!_hadSelected && _leftSelectedRow == indexPath.row) { + cell.backgroundColor = BackColor; + BOOL haveRightTableView = [_dataSource haveRightTableViewInColumn:_currentSelectedMenudIndex]; + if(!haveRightTableView){ + UIImageView *accessoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ico_make"]]; + + accessoryImageView.frame = CGRectMake(titleLabel.frame.origin.x+titleLabel.frame.size.width+10, (self.frame.size.height-12)/2, 16, 12); + + [cell addSubview:accessoryImageView]; + } + } else{ + + } + } + + return cell; +} + +#pragma mark - tableview delegate +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + + NSInteger leftOrRight = 0; + if (_rightTableView==tableView) { + leftOrRight = 1; + } else { + _leftSelectedRow = indexPath.row; + } + + if (self.delegate || [self.delegate respondsToSelector:@selector(menu:didSelectRowAtIndexPath:)]) { + + BOOL haveRightTableView = [_dataSource haveRightTableViewInColumn:_currentSelectedMenudIndex]; + + if ((leftOrRight==0 && !haveRightTableView) || leftOrRight==1) { + [self confiMenuWithSelectRow:indexPath.row leftOrRight:leftOrRight]; + } + + [self.delegate menu:self didSelectRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:leftOrRight leftRow:_leftSelectedRow row:indexPath.row]]; + + if (leftOrRight==0 && haveRightTableView) { + if (!_hadSelected) { + _hadSelected = YES; + [_leftTableView reloadData]; + NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:_leftSelectedRow inSection:0]; + + [_leftTableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; + } + + [_rightTableView reloadData]; + } + + } else { + //TODO: delegate is nil + } +} + +- (void)confiMenuWithSelectRow:(NSInteger)row leftOrRight:(NSInteger)leftOrRight{ + CATextLayer *title = (CATextLayer *)_titles[_currentSelectedMenudIndex]; + title.string = [self.dataSource menu:self titleForRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:leftOrRight leftRow:_leftSelectedRow row:row]]; + + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _show = NO; + }]; + [(CALayer *)self.bgLayers[_currentSelectedMenudIndex] setBackgroundColor:BackColor.CGColor]; + + CAShapeLayer *indicator = (CAShapeLayer *)_indicators[_currentSelectedMenudIndex]; + indicator.position = CGPointMake(title.position.x + title.frame.size.width / 2 + 8, indicator.position.y); +} + +- (void)updateMenuTitle:(NSString *)string { + CATextLayer *title = (CATextLayer *)_titles[_currentSelectedMenudIndex]; + title.string = string; + + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView leftTableView:_leftTableView rightTableView:_rightTableView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _show = NO; + }]; + [(CALayer *)self.bgLayers[_currentSelectedMenudIndex] setBackgroundColor:BackColor.CGColor]; + + CAShapeLayer *indicator = (CAShapeLayer *)_indicators[_currentSelectedMenudIndex]; + indicator.position = CGPointMake(title.position.x + title.frame.size.width / 2 + 8, indicator.position.y); +} + +#pragma mark - UICollectionViewDataSource + +-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ + return 1; +} + +-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ + + // 为collectionviewæ—¶ leftOrRight 为-1 + if ([self.dataSource respondsToSelector:@selector(menu:numberOfRowsInColumn:leftOrRight: leftRow:)]) { + return [self.dataSource menu:self numberOfRowsInColumn:self.currentSelectedMenudIndex leftOrRight:-1 leftRow:-1]; + } else { + NSAssert(0 == 1, @"required method of dataSource protocol should be implemented"); + return 0; + } +} + +-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ + + static NSString *collectionCell = @"CollectionCell"; + JSCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCell forIndexPath:indexPath]; + + if ([self.dataSource respondsToSelector:@selector(menu:titleForRowAtIndexPath:)]) { + cell.textLabel.text = [self.dataSource menu:self titleForRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:-1 leftRow:-1 row:indexPath.row]]; + } else { + NSAssert(0 == 1, @"dataSource method needs to be implemented"); + } + cell.backgroundColor = [UIColor whiteColor]; + cell.selectedBackgroundView.backgroundColor = BackColor; + cell.textLabel.font = [UIFont systemFontOfSize:14.0]; + cell.textLabel.textColor = self.textColor; + + if ([cell.textLabel.text isEqualToString:[(CATextLayer *)[_titles objectAtIndex:_currentSelectedMenudIndex] string]]) { + cell.backgroundColor = BackColor; + cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ico_make"]]; + } else{ + + [cell removeAccessoryView]; + } + + return cell; +} + +#pragma mark --UICollectionViewDelegateFlowLayout +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath +{ + return CGSizeMake((collectionView.frame.size.width-1)/2, 38); +} + +-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section +{ + return UIEdgeInsetsMake(0, 0, 1, 0.5); +} + +#pragma mark --UICollectionViewDelegate +-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.delegate || [self.delegate respondsToSelector:@selector(menu:didSelectRowAtIndexPath:)]) { + + [self confiMenuWithSelectRow:indexPath.row]; + + [self.delegate menu:self didSelectRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:-1 leftRow:-1 row:indexPath.row]]; + } else { + //TODO: delegate is nil + } +} + +- (void)confiMenuWithSelectRow:(NSInteger)row{ + CATextLayer *title = (CATextLayer *)_titles[_currentSelectedMenudIndex]; + title.string = [self.dataSource menu:self titleForRowAtIndexPath:[JSIndexPath indexPathWithCol:self.currentSelectedMenudIndex leftOrRight:-1 leftRow:-1 row:row]]; + + [self animateIdicator:_indicators[_currentSelectedMenudIndex] background:_backGroundView collectionView:_collectionView title:_titles[_currentSelectedMenudIndex] forward:NO complecte:^{ + _show = NO; + }]; + + [(CALayer *)self.bgLayers[_currentSelectedMenudIndex] setBackgroundColor:BackColor.CGColor]; + + CAShapeLayer *indicator = (CAShapeLayer *)_indicators[_currentSelectedMenudIndex]; + indicator.position = CGPointMake(title.position.x + title.frame.size.width / 2 + 8, indicator.position.y); +} + +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ + + return 0.5; +} + +@end diff --git a/HDMall/Tools/JSDropDownMenu/ico_make.png b/HDMall/Tools/JSDropDownMenu/ico_make.png new file mode 100755 index 0000000000000000000000000000000000000000..7ba9501212164ab1b464f27567dad8c4b99fe176 GIT binary patch literal 356 zcmV-q0h|7bP)<h;3K|Lk000e1NJLTq001BW000;W1^@s6n^XTZ0000PbVXQnQ*UN; zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBUz21!IgRCwBA{2v*`Kxg0w#5bXsfr-wR zhXC<vAU*)Z>hyL1$nvE?%m%~~Fh?*AfaNd%a)cAp09g(K#XvlrX#g$nqjee}XgMt% zK$PXQasbhm)4~BHS&r@iP?0E21Ix>BS&r<0WT@r?WI6($<=yx+GC?h$1Ldob;Rv!V zhdCetO^g&rP-HpG0iHm7gbYVeY&pyUU&wF-RV+tNgdj(_5$On!<twORIeIqyPJ|<1 zmNQesa%=?=K1ZCSw&l1=LR^lJ#$tITC6?nWieZj8h(|BT@(xPNZhUpYcWCaw=7?5m zSWZl3gv}8ki)*M=d$ACq2Ihz@Kzs@s^i%@?0R{lqR7v!ZpxH$L0000<MNUMnLSTX` CW`~FX literal 0 HcmV?d00001 diff --git a/HDMall/Tools/ZJAppInstance/ZJAppInstance.h b/HDMall/Tools/ZJAppInstance/ZJAppInstance.h index 1f6c8a1..9638af2 100644 --- a/HDMall/Tools/ZJAppInstance/ZJAppInstance.h +++ b/HDMall/Tools/ZJAppInstance/ZJAppInstance.h @@ -35,6 +35,9 @@ /** 获å–用户的所有åˆåŒuuid */ - (NSMutableArray *)getUserContractUuids; +/** 获å–商户用户的åˆåŒï¼ˆé»˜è®¤æ˜¯ç¬¬ä¸€ä¸ªï¼Œå¼‚常状况会æç¤º */ +- (UserInfo_contracts *)getTenantContract; + /** ä¿å˜åŸºç¡€ä¿¡æ¯ */ - (void)saveBaseInfo; diff --git a/HDMall/Tools/ZJAppInstance/ZJAppInstance.m b/HDMall/Tools/ZJAppInstance/ZJAppInstance.m index d5e7b1f..d8d7407 100644 --- a/HDMall/Tools/ZJAppInstance/ZJAppInstance.m +++ b/HDMall/Tools/ZJAppInstance/ZJAppInstance.m @@ -46,5 +46,22 @@ static NSString *const zj_saved_isMall = @"zj_saved_isMall"; return arr; } +/** 获å–商户用户的åˆåŒï¼ˆé»˜è®¤æ˜¯ç¬¬ä¸€ä¸ªï¼‰ */ +- (UserInfo_contracts *)getTenantContract{ + if (self.isMall) { + [MBProgressHUD j_warningMessage:@"该用户是商场用户"]; + return nil; + } + + UserInfo_contracts *contract = [self.user.contracts firstObject]; + if (!contract) { + [MBProgressHUD j_warningMessage:@"该商户没有åˆåŒ"];; + }else if(self.user.contracts.count > 1){ + [MBProgressHUD j_warningMessage:@"该商户有多个åˆåŒï¼Œé»˜è®¤é€‰å–第一个"]; + } + + return contract; +} + ZJLazy(ZJPermissionManager, permission) @end diff --git a/HDMall/Tools/ZJBaseHttpManager/ZJBaseHttpManager.m b/HDMall/Tools/ZJBaseHttpManager/ZJBaseHttpManager.m index a88e71c..d4f99f4 100644 --- a/HDMall/Tools/ZJBaseHttpManager/ZJBaseHttpManager.m +++ b/HDMall/Tools/ZJBaseHttpManager/ZJBaseHttpManager.m @@ -154,7 +154,7 @@ return; } WS(weakSelf); - [self.manager POST:@"hdmall/media/upload" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { + [self.manager POST:@"hdmall/media/upload/list" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { for (ZJBaseFileModel *file in files) { [formData appendPartWithFileData:file.data //data name:file.keyName //接å£key值 @@ -171,10 +171,10 @@ kFalseHttpTips; } - [weakSelf logWithUrl:@"hdmall/media/upload" Method:@"UPLOAD" param:params respones:responseObject]; + [weakSelf logWithUrl:@"hdmall/media/upload/list" Method:@"UPLOAD" param:params respones:responseObject]; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [MBProgressHUD j_error:@"ä¸Šä¼ å¤±è´¥" complete:nil]; - [weakSelf logWithUrl:@"hdmall/media/upload" Method:@"UPLOAD" param:params respones:error]; + [weakSelf logWithUrl:@"hdmall/media/upload/list" Method:@"UPLOAD" param:params respones:error]; }]; } -- 2.18.1