LogListViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. //
  2. // LogListViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2017/5/5.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "LogListViewController.h"
  9. #import "SideSlipModel.h"
  10. #import "LogSearchModel.h"
  11. @interface LogListViewController ()
  12. @end
  13. static int navcount = 4;
  14. @implementation LogListViewController
  15. #pragma mark - 公共函数
  16. /**
  17. viewDidLoad函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title=@"日志";
  22. [self initUI];
  23. [self setMainSrollView];
  24. [self sliderWithTag:self.currentIndex+1];
  25. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  26. [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  27. forState:UIControlStateNormal];
  28. [button addTarget:self action:@selector(goBack)
  29. forControlEvents:UIControlEventTouchUpInside];
  30. button.frame = CGRectMake(0, 0, 15, 18);
  31. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  32. self.navigationItem.leftBarButtonItem = menuButton;
  33. //保存
  34. UIButton* btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  35. [btnAdd setBackgroundImage:[UIImage imageNamed:@"title_add.png"]
  36. forState:UIControlStateNormal];
  37. [btnAdd addTarget:self action:@selector(newLog)
  38. forControlEvents:UIControlEventTouchUpInside];
  39. // UIImage *pic =[UIImage imageNamed:@"title_add"];
  40. btnAdd.frame = CGRectMake(0, 0,18,18);
  41. UIBarButtonItem* _menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  42. self.navigationItem.rightBarButtonItem = _menuButton2;
  43. __weak typeof(self) weakself=self;
  44. // 抽屉对象
  45. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  46. for (SideSlipModel *model in dataList) {
  47. model.selectedItemList = nil;
  48. model.customDict = nil;
  49. }
  50. } commitBlock:^(NSArray *dataList) {
  51. // 查询条件
  52. SideSlipModel *serviceRegionModel = dataList[0];
  53. LogSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  54. if(self.currentIndex==1){
  55. _allVC.recordStatus=@"";
  56. _allVC.startDate=m.startDate;
  57. _allVC.endDate=m.endDate;
  58. _allVC.createUserIds=m.createUserId;
  59. [ _allVC.dataList removeAllObjects];
  60. [_allVC refresh];
  61. }
  62. else if(self.currentIndex==2){
  63. _noCommentVC.recordStatus=@"0";
  64. _noCommentVC.startDate=m.startDate;
  65. _noCommentVC.endDate=m.endDate;
  66. _noCommentVC.createUserIds=m.createUserId;
  67. [_noCommentVC.dataList removeAllObjects];
  68. [_noCommentVC refresh];
  69. }
  70. else if(self.currentIndex==3){
  71. _haveCommentVC.recordStatus=@"1";
  72. _haveCommentVC.startDate=m.startDate;
  73. _haveCommentVC.endDate=m.endDate;
  74. [_haveCommentVC.dataList removeAllObjects];
  75. _haveCommentVC.createUserIds=m.createUserId;
  76. [_haveCommentVC refresh];
  77. }
  78. [weakself.filterController dismiss];
  79. }];
  80. _filterController.animationDuration = AnimationDuration;
  81. _filterController.hasHeadView = YES;
  82. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  83. _filterController.dataList = [self packageDataList];
  84. }
  85. /**
  86. 安全区视图发生变化
  87. */
  88. -(void)viewSafeAreaInsetsDidChange{
  89. self.view.backgroundColor = [UIColor whiteColor];
  90. _mainScrollView.frame = CGRectMake(0, 40, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  91. for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
  92. _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
  93. }
  94. [self.allVC viewSafeAreaInsetsDidChange];
  95. [self.noCommentVC viewSafeAreaInsetsDidChange];
  96. [self.haveCommentVC viewSafeAreaInsetsDidChange];
  97. [super viewSafeAreaInsetsDidChange];
  98. }
  99. #pragma mark - 委托函数
  100. -(void)refreshData{
  101. if(self.currentIndex==1){
  102. _allVC.recordStatus=@"";
  103. [ _allVC.dataList removeAllObjects];
  104. [_allVC refresh];
  105. }
  106. else if(self.currentIndex==2){
  107. _noCommentVC.recordStatus=@"0";
  108. [_noCommentVC.dataList removeAllObjects];
  109. [_noCommentVC refresh];
  110. }
  111. else if(self.currentIndex==3){
  112. _haveCommentVC.recordStatus=@"1";
  113. [_haveCommentVC.dataList removeAllObjects];
  114. [_haveCommentVC refresh];
  115. }
  116. }
  117. #pragma mark - 私有函数
  118. - (void)searchLogData{
  119. [_filterController show];
  120. }
  121. /**
  122. 数据源
  123. @return <#return value description#>
  124. */
  125. - (NSArray *)packageDataList {
  126. NSMutableArray *dataArray = [NSMutableArray array];
  127. SideSlipModel *model = [[SideSlipModel alloc] init];
  128. model.containerCellClass = @"LogSearchTableViewCell";
  129. model.regionTitle = @"查询条件";
  130. [dataArray addObject:model];
  131. return [dataArray mutableCopy];
  132. }
  133. /**
  134. * 新增日志
  135. */
  136. -(void)newLog{
  137. self.hidesBottomBarWhenPushed=YES;
  138. LogAddViewController *newVC=[[LogAddViewController alloc] init];
  139. newVC.refreshDelegate=self;
  140. [self.navigationController pushViewController:newVC animated:YES];
  141. }
  142. /**
  143. * 返回函数
  144. */
  145. -(void)goBack
  146. {
  147. [self.navigationController popViewControllerAnimated:YES];
  148. }
  149. -(void)initUI{
  150. UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
  151. [self.view addSubview:navView];
  152. [self.view setBackgroundColor:[UIColor whiteColor]];
  153. _allButton = [UIButton buttonWithType:UIButtonTypeCustom];
  154. [_allButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  155. [_allButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  156. _allButton.frame = CGRectMake(0, 0, Screen_Width/navcount, navView.frame.size.height);
  157. _allButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  158. [_allButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  159. [_allButton setTitle:@"全部" forState:UIControlStateNormal];
  160. _allButton.tag = 1;
  161. _allButton.selected = YES;
  162. [navView addSubview:_allButton];
  163. _noCommentButton= [UIButton buttonWithType:UIButtonTypeCustom];
  164. _noCommentButton.frame = CGRectMake(CGRectGetMaxX(_allButton.frame),0, Screen_Width/navcount, navView.frame.size.height);
  165. [ _noCommentButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  166. [ _noCommentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  167. _noCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  168. [ _noCommentButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  169. [_noCommentButton setTitle:@"未点评" forState:UIControlStateNormal];
  170. _noCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  171. _noCommentButton.tag = 2;
  172. [navView addSubview:_noCommentButton];
  173. _haveCommentButton= [UIButton buttonWithType:UIButtonTypeCustom];
  174. _haveCommentButton.frame = CGRectMake(CGRectGetMaxX(_noCommentButton.frame),0, Screen_Width/navcount, navView.frame.size.height);
  175. [_haveCommentButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  176. [_haveCommentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  177. [ _haveCommentButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  178. [_haveCommentButton setTitle:@"已点评" forState:UIControlStateNormal];
  179. _haveCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  180. _haveCommentButton.tag = 3;
  181. [navView addSubview:_haveCommentButton];
  182. _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_allButton.frame.origin.x, 40-2, Screen_Width/navcount, 2)];
  183. _sliderLabel.backgroundColor = [UIColor redColor];
  184. [navView addSubview:_sliderLabel];
  185. _filterButton=[UIButton buttonWithType:UIButtonTypeCustom];
  186. _filterButton.frame=CGRectMake(CGRectGetMaxX(_haveCommentButton.frame),0,Screen_Width/navcount, navView.frame.size.height);
  187. UIImageView *filterImg=[[UIImageView alloc] initWithFrame:CGRectMake(_filterButton.bounds.size.width/2-25,15,10, 10)];
  188. [filterImg setImage:[UIImage imageNamed:@"icon_filter"]];
  189. [_filterButton addSubview:filterImg];
  190. filterImg.userInteractionEnabled=NO;
  191. UILabel *filterLbl=[[UILabel alloc]init];
  192. filterLbl.frame=CGRectMake(CGRectGetMaxX(filterImg.frame)+3,10,50, 20);
  193. filterLbl.text=@"筛选";
  194. filterLbl.font=[UIFont systemFontOfSize:ButtonFontOfSize];
  195. [_filterButton addSubview:filterLbl];
  196. [_filterButton addTarget:self action:@selector(searchLogData)
  197. forControlEvents:UIControlEventTouchUpInside];
  198. [navView addSubview:_filterButton];
  199. }
  200. /**
  201. 全部vc
  202. @return <#return value description#>
  203. */
  204. - (LogAllViewController *)allVC{
  205. if (_allVC==nil) {
  206. _allVC = [[LogAllViewController alloc] init];
  207. _allVC.cNav=self.navigationController;
  208. }
  209. return _allVC;
  210. }
  211. /**
  212. 未点评vc
  213. @return <#return value description#>
  214. */
  215. - (LogAllViewController *)noCommentVC{
  216. if (_noCommentVC==nil) {
  217. _noCommentVC = [[LogAllViewController alloc] init];
  218. _noCommentVC.cNav=self.navigationController;
  219. }
  220. return _noCommentVC;
  221. }
  222. /**
  223. 装修信息vc
  224. @return <#return value description#>
  225. */
  226. - (LogAllViewController *)haveCommentVC{
  227. if (_haveCommentVC==nil) {
  228. _haveCommentVC = [[LogAllViewController alloc] init];
  229. _haveCommentVC.cNav=self.navigationController;
  230. }
  231. return _haveCommentVC;
  232. }
  233. /**
  234. 按钮点击事件
  235. @param sender <#sender description#>
  236. */
  237. - (void)sliderAction:(UIButton *)sender{
  238. if (self.currentIndex==sender.tag) {
  239. return;
  240. }
  241. [self sliderAnimationWithTag:sender.tag];
  242. [UIView animateWithDuration:0.3 animations:^{
  243. _mainScrollView.contentOffset = CGPointMake(Screen_Width*(sender.tag-1), 0);
  244. } completion:^(BOOL finished) {
  245. }];
  246. if(_currentIndex==1){
  247. self.allVC.recordStatus=@"";
  248. [_allVC refresh];
  249. }
  250. else if(_currentIndex==2){
  251. self.noCommentVC.recordStatus=@"0";
  252. [_noCommentVC refresh];
  253. }
  254. else if(_currentIndex==3){
  255. self.haveCommentVC.recordStatus=@"1";
  256. [_haveCommentVC refresh];
  257. }
  258. }
  259. /**
  260. 滑动tag
  261. @param tag <#tag description#>
  262. */
  263. - (void)sliderWithTag:(NSInteger)tag{
  264. self.currentIndex = tag;
  265. _allButton.selected = NO;
  266. _noCommentButton.selected = NO;
  267. _haveCommentButton.selected = NO;
  268. UIButton *sender = [self buttonWithTag:tag];
  269. sender.selected = YES;
  270. //动画
  271. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  272. if(_currentIndex==1){
  273. self.allVC.recordStatus=@"";
  274. [_allVC refresh];
  275. }
  276. else if(_currentIndex==2){
  277. self.noCommentVC.recordStatus=@"0";
  278. [_noCommentVC refresh];
  279. }
  280. else if(_currentIndex==3){
  281. self.haveCommentVC.recordStatus=@"1";
  282. [_haveCommentVC refresh];
  283. }
  284. }
  285. /**
  286. 滑动tag
  287. @param tag <#tag description#>
  288. */
  289. - (void)sliderAnimationWithTag:(NSInteger)tag{
  290. self.currentIndex = tag;
  291. _allButton.selected = NO;
  292. _noCommentButton.selected = NO;
  293. _haveCommentButton.selected = NO;
  294. UIButton *sender = [self buttonWithTag:tag];
  295. sender.selected = YES;
  296. //动画
  297. [UIView animateWithDuration:0.3 animations:^{
  298. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  299. } completion:^(BOOL finished) {
  300. }];
  301. }
  302. - (UIButton *)buttonWithTag:(NSInteger )tag{
  303. if (tag==1) {
  304. return _allButton;
  305. }else if (tag==2){
  306. return _noCommentButton;
  307. }
  308. else if (tag==3){
  309. return _haveCommentButton;
  310. }
  311. else{
  312. return nil;
  313. }
  314. }
  315. /**
  316. 初始化srollView
  317. */
  318. - (void)setMainSrollView{
  319. _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, Screen_Width, self.view.frame.size.height)];
  320. _mainScrollView.delegate = self;
  321. _mainScrollView.backgroundColor = [UIColor whiteColor];
  322. _mainScrollView.pagingEnabled = YES;
  323. _mainScrollView.showsHorizontalScrollIndicator = NO;
  324. _mainScrollView.showsVerticalScrollIndicator = NO;
  325. [self.view addSubview:_mainScrollView];
  326. NSArray *views = @[self.allVC.view,self.noCommentVC.view ,
  327. self.haveCommentVC.view];
  328. for (NSInteger i = 0; i< views.count; i++) {
  329. //把三个vc的view依次贴到mainScrollView上面
  330. UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height-100)];
  331. //将子view的高度与父view的高度相同
  332. ((UIView*)views[i]).frame = CGRectMake(0,0,self.view.frame.size.width,pageView.frame.size.height);
  333. [pageView addSubview:views[i]];
  334. [_mainScrollView addSubview:pageView];
  335. }
  336. _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
  337. //滚动到_currentIndex对应的tab
  338. [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
  339. }
  340. /**
  341. 滑动label位置
  342. @param scrollView <#scrollView description#>
  343. */
  344. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  345. //实时计算当前位置,实现和titleView上的按钮的联动
  346. CGFloat contentOffSetX = scrollView.contentOffset.x;
  347. CGFloat X = contentOffSetX/ navcount;
  348. CGRect frame = _sliderLabel.frame;
  349. frame.origin.x = X;
  350. _sliderLabel.frame = frame;
  351. [self.allVC closeKeyboard];
  352. [self.noCommentVC closeKeyboard];
  353. [self.haveCommentVC closeKeyboard];
  354. }
  355. /**
  356. 滑动完成
  357. @param scrollView <#scrollView description#>
  358. */
  359. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  360. CGFloat contentOffSetX = scrollView.contentOffset.x;
  361. int index_ = contentOffSetX/Screen_Width;
  362. [self sliderWithTag:index_+1];
  363. }
  364. @end