| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- //
- // AveragePriceMonitorReportViewController.m
- // IBOSS
- //
- // Created by guan hong hou on 2017/9/7.
- // Copyright © 2017年 elongtian. All rights reserved.
- //
- // 功能描述:均价监控报表控制器
- #import "AveragePriceMonitorReportViewController.h"
- #import "SideSlipModel.h"
- #import "AveragePriceMonitorSearchModel.h"
- #import "DateFormat.h"
- #import "AveragePriceMonitorModel.h"
- #import "AveragePriceMonitorFrame.h"
- #import "AveragePriceMonitorItemTableViewCell.h"
- #import "DateFormat.h"
- @interface AveragePriceMonitorReportViewController (){
- /**
- 页号
- */
- int _pageNumber;
- /**
- 每页记录数
- */
- int _mRecorders;
-
- /**
- 是否最后一页
- */
- Boolean _isLastPage;
- }
- @end
- @implementation AveragePriceMonitorReportViewController
- #pragma mark - 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title = @"均价监控表";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
- UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
- [btnfilter addTarget:self action:@selector(search)
- forControlEvents:UIControlEventTouchUpInside];
- btnfilter.frame = CGRectMake(0, 0, 16, 16);
- [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
- [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
- forState:UIControlStateNormal];
- [v addSubview:btnfilter];
- UIButton *filterLbl = [[UIButton alloc]init];
- filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
- [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
- [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [filterLbl addTarget:self action:@selector(search)
- forControlEvents:UIControlEventTouchUpInside];
- [v addSubview:filterLbl];
- UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
- self.navigationItem.rightBarButtonItem = menubtnAdd;
- _pageNumber = 1;
- _mRecorders = 20;
- _dataList = [[NSMutableArray alloc]init];
- _dataPagingList=[[NSMutableArray alloc]init];
- _startDate= [DateFormat getDateBefore:31];
- _endDate = [DateFormat getCurrentDate];
- _invoiceType=@"1";
- _isIncludeOrderToSales=@"0";
- _kindListStr=@"";
- _organizationCodeListStr=@"";
- _isOnlySearchDetail=@"false";
- _isIncludeGift=@"0";
- [self initUI];
-
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _tableView.frame =CGRectMake(0, 0, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height);
- [super viewSafeAreaInsetsDidChange];
- }
- #pragma mark - 委托函数
- /**
- 数据加载完成函数
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
-
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- [self cancel];
- long iNewCount = 0;
- int iStatus = resultModel.status;
- NSString *message =resultModel.message;
- if (iStatus == 0) {
- NSArray * infoArr = (NSArray *)resultModel.result;
- if(infoArr != nil&&infoArr.count > 0)
- {
- for(int i=0;i<infoArr.count;i++){
- NSDictionary *dic= infoArr[i];
- AveragePriceMonitorModel *md = [AveragePriceMonitorModel dk_modelWithDictionary:dic];
- AveragePriceMonitorFrame *frm=[[AveragePriceMonitorFrame alloc]init];
- [frm setAveragePriceMonitorFrame:md];
- [_dataList addObject:frm];
- }
-
- _pageModel = [[PageModel alloc]init];
- [_pageModel setPage:_dataList pageRecorders:_mRecorders];
- NSArray *subArray = [_pageModel getObjects:_pageNumber];
- [_dataPagingList addObjectsFromArray:subArray];
-
- [_tableView reloadData];
- [_tableView FinishLoading];
- _tableView.mbMoreHidden=NO;
- }
- else{
- [_tableView FinishLoading];
- if(_pageNumber == 1)
- {
- UIView *noDataView = [self noDataViewByFrame:_tableView.mTableView.bounds];
- _tableView.mTableView.backgroundView =noDataView;
- [self showAlertViewText:@"未找到匹配结果"];
- return;
- }
- else{
- _tableView.mbMoreHidden = 1;
- }
-
- }
- }
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- return;
- }
-
- else{
- [self showAlertViewText:message];
- [_tableView FinishLoading];
- _tableView.mbMoreHidden=YES;
- return;
-
- }
- }
- /**
- 数据加载失败函数
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [_tableView reloadData];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- tableview的行数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_dataPagingList count];
- }
- /**
- tableview的分区数
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1 ;
- }
- /**
- 获取tableview cell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"CellId";
- AveragePriceMonitorItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- cell = [[ AveragePriceMonitorItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- NSUInteger row = [indexPath row];
- AveragePriceMonitorFrame *frame = [_dataPagingList objectAtIndex:row];
- [cell setAveragePriceMonitorCell:frame invoiceType:_invoiceType ];
- return cell;
-
- }
- /**
- tableview的高度
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSUInteger row = [indexPath section];
- AveragePriceMonitorFrame *frame = [_dataPagingList objectAtIndex:row];
- NSInteger cellHeight = [frame cellHeight];
- return cellHeight;
-
- }
- /**
- scrollview滚动代理
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
- if (scrollView.isDragging) {//显示下拉更新
-
- if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) {
- [_tableView.mRefreshHeader setState:PullRefreshNormal];
- }
- else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) {
- //显示松开更新
- [_tableView.mRefreshHeader setState:PullRefreshPulling];
- }
-
- }
- }
- /**
- 是否能刷新tableview
- @param sender <#sender description#>
- @return <#return value description#>
- */
- - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
- return YES;
- }
- /**
- 加载更多回调函数
- */
- - (void)LoadMoreList:(RefreshTableView *)sender {
- if (_dataList.count <= _mRecorders) {
- _isLastPage = true;
- _tableView.mbMoreHidden = YES;
- return;
- }
- _pageNumber++;
- if (_isLastPage) {
- return;
- }
- if (_pageNumber * _mRecorders >= _dataList.count) {// 判断是否为最后一页
- _isLastPage = true;
- } else {
- _isLastPage = false;
- }
- NSArray *subArray = [_pageModel getObjects:_pageNumber];
- [_dataPagingList addObjectsFromArray:subArray];
- [_tableView FinishLoading];
- _tableView.mbMoreHidden = NO;
- [_tableView reloadData];
-
- }
- /**
- 下拉刷新回调函数
- */
- - (void)ReloadList:(RefreshTableView *)sender{
- if(_dataList!=nil&&_dataList.count>0){
- [_dataList removeAllObjects];
- }
- if (_dataPagingList != nil && _dataPagingList.count > 0) {
- [_dataPagingList removeAllObjects];
- [_tableView reloadData];
- }
- _pageNumber = 1;
- _isLastPage = false;
- [self initData];
- }
- #pragma 私有函数
- /**
- 初始化UI
- */
- -(void)initUI{
- _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-rectNavHeight-rectStatusHeight)];
- _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.mTableView.showsVerticalScrollIndicator = NO;
- _tableView.delegate = self;
- [self.view addSubview:_tableView];
- __weak typeof(self) weakself = self;
- // 抽屉对象
- self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
- for (SideSlipModel *model in dataList) {
- model.selectedItemList = nil;
- model.customDict = nil;
- }
- } commitBlock:^(NSArray *dataList) {
- // 查询条件
- SideSlipModel *serviceRegionModel = dataList[0];
- AveragePriceMonitorSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
- [weakself.filterController dismiss];
- _organizationCodeListStr=m.businessDepartmentCode;
- _kindListStr=m.goodsType;
- _startDate=m.startDate;
- _endDate=m.endDate;
- _isIncludeOrderToSales=m.isIncludeOrderToSales;
- if(_startDate == nil){
- [self showAlertViewText:@"请选择开始日期"];
- return;
- }
- if(_endDate == nil){
- [self showAlertViewText:@"请选择结束日期"];
- return;
- }
- NSUInteger result = [DateFormat compareDate:_startDate withDate:_endDate];
- if(result == -1){
- [self showAlertViewText:@"开始日期不能大于结束日期"];
- return;
- }
- NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
- [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
-
- NSDate *startD = [dateFormat dateFromString:_startDate];
- NSDate *endD = [dateFormat dateFromString:_endDate];
- NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
-
- if(days > 31){
- [self showAlertViewText:@"日期间隔天数不能大于31天"];
- return;
- }
-
- _isIncludeGift=m.giftFlag;
- _invoiceType=m.invoiceType;
- if(_dataList!=nil&&_dataList.count>0){
- [_dataList removeAllObjects];
- }
- if (_dataPagingList != nil && _dataPagingList.count > 0) {
- [_dataPagingList removeAllObjects];
- [_tableView reloadData];
- }
- _tableView.mbMoreHidden=YES;
- _pageNumber = 1;
- _isLastPage = false;
- [self initData];
-
- }];
- _filterController.animationDuration = AnimationDuration;
- _filterController.hasHeadView = YES;
- _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
- _filterController.dataList = [self packageDataList];
- [self initData];
-
- }
- /**
- 初始化数据
- */
- -(void)initData{
- [self startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetOrderSaleMonitorDataIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_startDate forKeyedSubscript:@"AccountDateFrom"];
- [dict setObject:_endDate forKeyedSubscript:@"AccountDateTo"];
- [dict setObject:_invoiceType forKeyedSubscript:@"OperateType"];
- [dict setObject:_isOnlySearchDetail forKeyedSubscript:@"IsOnlySearchDetail"];
- [dict setObject:_isIncludeGift forKeyedSubscript:@"SalesDetailType"];
- [dict setObject:_kindListStr forKeyedSubscript:@"KindList"];
- [dict setObject:_isIncludeOrderToSales forKeyedSubscript:@"IsToSales"];
- [dict setObject:_organizationCodeListStr forKeyedSubscript:@"OrganizationCodeList"];
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager.delegate = self;
- self.mDownManager.onRequestSuccess = @selector(onLoadFinish:);
- self.mDownManager.onRequestFail = @selector(onLoadFail:);
- [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- /**
- 打开抽屉
- */
- -(void)search{
- [_filterController show];
- }
- /**
- 取消进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 数据源
-
- @return <#return value description#>
- */
- - (NSArray *)packageDataList {
- NSMutableArray *dataArray = [NSMutableArray array];
- SideSlipModel *model = [[SideSlipModel alloc] init];
- model.containerCellClass = @"AveragePriceMonitorSearchCellTableViewCell";
- model.regionTitle = @"查询条件";
- [dataArray addObject:model];
- return [dataArray mutableCopy];
- }
- @end
|