AveragePriceMonitorReportViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. //
  2. // AveragePriceMonitorReportViewController.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2017/9/7.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. // 功能描述:均价监控报表控制器
  9. #import "AveragePriceMonitorReportViewController.h"
  10. #import "SideSlipModel.h"
  11. #import "AveragePriceMonitorSearchModel.h"
  12. #import "DateFormat.h"
  13. #import "AveragePriceMonitorModel.h"
  14. #import "AveragePriceMonitorFrame.h"
  15. #import "AveragePriceMonitorItemTableViewCell.h"
  16. #import "DateFormat.h"
  17. @interface AveragePriceMonitorReportViewController (){
  18. /**
  19. 页号
  20. */
  21. int _pageNumber;
  22. /**
  23. 每页记录数
  24. */
  25. int _mRecorders;
  26. /**
  27. 是否最后一页
  28. */
  29. Boolean _isLastPage;
  30. }
  31. @end
  32. @implementation AveragePriceMonitorReportViewController
  33. #pragma mark - 公共函数
  34. /**
  35. 视图加载完成函数
  36. */
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. self.navigationItem.title = @"均价监控表";
  40. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  41. [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
  42. [button addTarget:self action:@selector(goBack)
  43. forControlEvents:UIControlEventTouchUpInside];
  44. button.frame = CGRectMake(0, 0,45,22);
  45. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  46. self.navigationItem.leftBarButtonItem = menuButton;
  47. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  48. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  49. [btnfilter addTarget:self action:@selector(search)
  50. forControlEvents:UIControlEventTouchUpInside];
  51. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  52. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  53. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  54. forState:UIControlStateNormal];
  55. [v addSubview:btnfilter];
  56. UIButton *filterLbl = [[UIButton alloc]init];
  57. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  58. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  59. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  60. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  61. [filterLbl addTarget:self action:@selector(search)
  62. forControlEvents:UIControlEventTouchUpInside];
  63. [v addSubview:filterLbl];
  64. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  65. self.navigationItem.rightBarButtonItem = menubtnAdd;
  66. _pageNumber = 1;
  67. _mRecorders = 20;
  68. _dataList = [[NSMutableArray alloc]init];
  69. _dataPagingList=[[NSMutableArray alloc]init];
  70. _startDate= [DateFormat getDateBefore:31];
  71. _endDate = [DateFormat getCurrentDate];
  72. _invoiceType=@"1";
  73. _isIncludeOrderToSales=@"0";
  74. _kindListStr=@"";
  75. _organizationCodeListStr=@"";
  76. _isOnlySearchDetail=@"false";
  77. _isIncludeGift=@"0";
  78. [self initUI];
  79. }
  80. /**
  81. 安全区视图发生变化
  82. */
  83. -(void)viewSafeAreaInsetsDidChange{
  84. [self.view setBackgroundColor:[UIColor whiteColor]];
  85. _tableView.frame =CGRectMake(0, 0, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height);
  86. [super viewSafeAreaInsetsDidChange];
  87. }
  88. #pragma mark - 委托函数
  89. /**
  90. 数据加载完成函数
  91. @param sender <#sender description#>
  92. */
  93. - (void)onLoadFinish:(ASIDownManager *)sender {
  94. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  95. [self cancel];
  96. long iNewCount = 0;
  97. int iStatus = resultModel.status;
  98. NSString *message =resultModel.message;
  99. if (iStatus == 0) {
  100. NSArray * infoArr = (NSArray *)resultModel.result;
  101. if(infoArr != nil&&infoArr.count > 0)
  102. {
  103. for(int i=0;i<infoArr.count;i++){
  104. NSDictionary *dic= infoArr[i];
  105. AveragePriceMonitorModel *md = [AveragePriceMonitorModel dk_modelWithDictionary:dic];
  106. AveragePriceMonitorFrame *frm=[[AveragePriceMonitorFrame alloc]init];
  107. [frm setAveragePriceMonitorFrame:md];
  108. [_dataList addObject:frm];
  109. }
  110. _pageModel = [[PageModel alloc]init];
  111. [_pageModel setPage:_dataList pageRecorders:_mRecorders];
  112. NSArray *subArray = [_pageModel getObjects:_pageNumber];
  113. [_dataPagingList addObjectsFromArray:subArray];
  114. [_tableView reloadData];
  115. [_tableView FinishLoading];
  116. _tableView.mbMoreHidden=NO;
  117. }
  118. else{
  119. [_tableView FinishLoading];
  120. if(_pageNumber == 1)
  121. {
  122. UIView *noDataView = [self noDataViewByFrame:_tableView.mTableView.bounds];
  123. _tableView.mTableView.backgroundView =noDataView;
  124. [self showAlertViewText:@"未找到匹配结果"];
  125. return;
  126. }
  127. else{
  128. _tableView.mbMoreHidden = 1;
  129. }
  130. }
  131. }
  132. else if(iStatus == ActionResultStatusAuthError
  133. ||iStatus == ActionResultStatusNoLogin
  134. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  135. [self showReLoginDialog:message];
  136. return;
  137. }
  138. else{
  139. [self showAlertViewText:message];
  140. [_tableView FinishLoading];
  141. _tableView.mbMoreHidden=YES;
  142. return;
  143. }
  144. }
  145. /**
  146. 数据加载失败函数
  147. @param sender <#sender description#>
  148. */
  149. - (void)onLoadFail:(ASIDownManager *)sender {
  150. [self cancel];
  151. [_tableView reloadData];
  152. [self showAlertViewText:@"网络异常"];
  153. }
  154. /**
  155. tableview的行数
  156. @param tableView <#tableView description#>
  157. @param section <#section description#>
  158. @return <#return value description#>
  159. */
  160. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  161. {
  162. return [_dataPagingList count];
  163. }
  164. /**
  165. tableview的分区数
  166. @param tableView <#tableView description#>
  167. @return <#return value description#>
  168. */
  169. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  170. return 1 ;
  171. }
  172. /**
  173. 获取tableview cell
  174. @param tableView <#tableView description#>
  175. @param indexPath <#indexPath description#>
  176. @return <#return value description#>
  177. */
  178. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  179. {
  180. static NSString *cellIdentifier = @"CellId";
  181. AveragePriceMonitorItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  182. cell = [[ AveragePriceMonitorItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  183. NSUInteger row = [indexPath row];
  184. AveragePriceMonitorFrame *frame = [_dataPagingList objectAtIndex:row];
  185. [cell setAveragePriceMonitorCell:frame invoiceType:_invoiceType ];
  186. return cell;
  187. }
  188. /**
  189. tableview的高度
  190. @param tableView <#tableView description#>
  191. @param indexPath <#indexPath description#>
  192. @return <#return value description#>
  193. */
  194. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  195. NSUInteger row = [indexPath section];
  196. AveragePriceMonitorFrame *frame = [_dataPagingList objectAtIndex:row];
  197. NSInteger cellHeight = [frame cellHeight];
  198. return cellHeight;
  199. }
  200. /**
  201. scrollview滚动代理
  202. @param scrollView <#scrollView description#>
  203. */
  204. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  205. if (scrollView.isDragging) {//显示下拉更新
  206. if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) {
  207. [_tableView.mRefreshHeader setState:PullRefreshNormal];
  208. }
  209. else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) {
  210. //显示松开更新
  211. [_tableView.mRefreshHeader setState:PullRefreshPulling];
  212. }
  213. }
  214. }
  215. /**
  216. 是否能刷新tableview
  217. @param sender <#sender description#>
  218. @return <#return value description#>
  219. */
  220. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  221. return YES;
  222. }
  223. /**
  224. 加载更多回调函数
  225. */
  226. - (void)LoadMoreList:(RefreshTableView *)sender {
  227. if (_dataList.count <= _mRecorders) {
  228. _isLastPage = true;
  229. _tableView.mbMoreHidden = YES;
  230. return;
  231. }
  232. _pageNumber++;
  233. if (_isLastPage) {
  234. return;
  235. }
  236. if (_pageNumber * _mRecorders >= _dataList.count) {// 判断是否为最后一页
  237. _isLastPage = true;
  238. } else {
  239. _isLastPage = false;
  240. }
  241. NSArray *subArray = [_pageModel getObjects:_pageNumber];
  242. [_dataPagingList addObjectsFromArray:subArray];
  243. [_tableView FinishLoading];
  244. _tableView.mbMoreHidden = NO;
  245. [_tableView reloadData];
  246. }
  247. /**
  248. 下拉刷新回调函数
  249. */
  250. - (void)ReloadList:(RefreshTableView *)sender{
  251. if(_dataList!=nil&&_dataList.count>0){
  252. [_dataList removeAllObjects];
  253. }
  254. if (_dataPagingList != nil && _dataPagingList.count > 0) {
  255. [_dataPagingList removeAllObjects];
  256. [_tableView reloadData];
  257. }
  258. _pageNumber = 1;
  259. _isLastPage = false;
  260. [self initData];
  261. }
  262. #pragma 私有函数
  263. /**
  264. 初始化UI
  265. */
  266. -(void)initUI{
  267. _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-rectNavHeight-rectStatusHeight)];
  268. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  269. _tableView.backgroundColor = [UIColor clearColor];
  270. _tableView.mTableView.showsVerticalScrollIndicator = NO;
  271. _tableView.delegate = self;
  272. [self.view addSubview:_tableView];
  273. __weak typeof(self) weakself = self;
  274. // 抽屉对象
  275. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  276. for (SideSlipModel *model in dataList) {
  277. model.selectedItemList = nil;
  278. model.customDict = nil;
  279. }
  280. } commitBlock:^(NSArray *dataList) {
  281. // 查询条件
  282. SideSlipModel *serviceRegionModel = dataList[0];
  283. AveragePriceMonitorSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  284. [weakself.filterController dismiss];
  285. _organizationCodeListStr=m.businessDepartmentCode;
  286. _kindListStr=m.goodsType;
  287. _startDate=m.startDate;
  288. _endDate=m.endDate;
  289. _isIncludeOrderToSales=m.isIncludeOrderToSales;
  290. if(_startDate == nil){
  291. [self showAlertViewText:@"请选择开始日期"];
  292. return;
  293. }
  294. if(_endDate == nil){
  295. [self showAlertViewText:@"请选择结束日期"];
  296. return;
  297. }
  298. NSUInteger result = [DateFormat compareDate:_startDate withDate:_endDate];
  299. if(result == -1){
  300. [self showAlertViewText:@"开始日期不能大于结束日期"];
  301. return;
  302. }
  303. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  304. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  305. NSDate *startD = [dateFormat dateFromString:_startDate];
  306. NSDate *endD = [dateFormat dateFromString:_endDate];
  307. NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
  308. if(days > 31){
  309. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  310. return;
  311. }
  312. _isIncludeGift=m.giftFlag;
  313. _invoiceType=m.invoiceType;
  314. if(_dataList!=nil&&_dataList.count>0){
  315. [_dataList removeAllObjects];
  316. }
  317. if (_dataPagingList != nil && _dataPagingList.count > 0) {
  318. [_dataPagingList removeAllObjects];
  319. [_tableView reloadData];
  320. }
  321. _tableView.mbMoreHidden=YES;
  322. _pageNumber = 1;
  323. _isLastPage = false;
  324. [self initData];
  325. }];
  326. _filterController.animationDuration = AnimationDuration;
  327. _filterController.hasHeadView = YES;
  328. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  329. _filterController.dataList = [self packageDataList];
  330. [self initData];
  331. }
  332. /**
  333. 初始化数据
  334. */
  335. -(void)initData{
  336. [self startLoading];
  337. NSString *urlStr = ServerURL;
  338. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  339. [dict setObject:@"GetOrderSaleMonitorDataIphone" forKey:@"Action"];
  340. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  341. [dict setObject:kkUserCode forKey:@"UserCode"];
  342. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  343. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  344. [dict setObject:_startDate forKeyedSubscript:@"AccountDateFrom"];
  345. [dict setObject:_endDate forKeyedSubscript:@"AccountDateTo"];
  346. [dict setObject:_invoiceType forKeyedSubscript:@"OperateType"];
  347. [dict setObject:_isOnlySearchDetail forKeyedSubscript:@"IsOnlySearchDetail"];
  348. [dict setObject:_isIncludeGift forKeyedSubscript:@"SalesDetailType"];
  349. [dict setObject:_kindListStr forKeyedSubscript:@"KindList"];
  350. [dict setObject:_isIncludeOrderToSales forKeyedSubscript:@"IsToSales"];
  351. [dict setObject:_organizationCodeListStr forKeyedSubscript:@"OrganizationCodeList"];
  352. self.mDownManager = [[ASIDownManager alloc] init];
  353. self.mDownManager.delegate = self;
  354. self.mDownManager.onRequestSuccess = @selector(onLoadFinish:);
  355. self.mDownManager.onRequestFail = @selector(onLoadFail:);
  356. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  357. }
  358. /**
  359. 打开抽屉
  360. */
  361. -(void)search{
  362. [_filterController show];
  363. }
  364. /**
  365. 取消进度条
  366. */
  367. - (void)cancel {
  368. [self stopLoading];
  369. }
  370. /**
  371. 数据源
  372. @return <#return value description#>
  373. */
  374. - (NSArray *)packageDataList {
  375. NSMutableArray *dataArray = [NSMutableArray array];
  376. SideSlipModel *model = [[SideSlipModel alloc] init];
  377. model.containerCellClass = @"AveragePriceMonitorSearchCellTableViewCell";
  378. model.regionTitle = @"查询条件";
  379. [dataArray addObject:model];
  380. return [dataArray mutableCopy];
  381. }
  382. @end