猎豆优选

LDIncomeViewController.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //
  2. // LDIncomeViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/8/3.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDIncomeViewController.h"
  9. #import "LDChildCommissionCell.h"
  10. #import "LDChildCommissionModel.h"
  11. #import "LDMonthCenterTipView.h"
  12. #import "LDCalendarView.h"
  13. #import "CCAlertShowView.h"
  14. #import "LDIncomeTopView.h"
  15. #import "LDIncomeDateTool.h"
  16. #import "ITDatePickerController.h"
  17. #import "LDWebDetailController.h"
  18. #import "LDFindBookWebViewController.h"
  19. #import "LDAdWebViewController.h"
  20. @interface LDIncomeViewController ()
  21. <
  22. UITableViewDelegate,
  23. UITableViewDataSource,
  24. ITDatePickerControllerDelegate,
  25. LDChildCommissionCellDelegate
  26. >{
  27. __block NSInteger page;
  28. NSInteger type; //类型 0 预估 1 完结
  29. NSString *yearMonthDay; //日期 isDay为1:2018-08-08 isDay为0:2018-08
  30. NSInteger isDay; //是否有日 0无 1有
  31. }
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) LDIncomeTopView *topView;
  34. @property (nonatomic, strong) NSMutableArray *dataArr;
  35. @property (nonatomic, strong) LDCalendarView *calendarView ;
  36. @property (nonatomic, strong) CCAlertShowView *alertShowView;
  37. @end
  38. @implementation LDIncomeViewController
  39. - (void)viewWillDisappear:(BOOL)animated {
  40. [super viewWillDisappear:animated];
  41. [SVProgressHUD dismiss];
  42. }
  43. - (void)viewWillAppear:(BOOL)animated {
  44. [super viewWillAppear:animated];
  45. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. [self configNavigationBar];
  50. [self configTableView];
  51. [self configRequestParam];
  52. if (_infoIncomeType ==near_day_forecast_income) {
  53. [self canlendarAction];
  54. }
  55. if (_yearMonth.length !=0) {//判断是否是按月统计
  56. yearMonthDay=_yearMonth;
  57. [self changeDateS:_startDate AndString:yearMonthDay];
  58. }else{
  59. [self requestAndRefresh:YES];
  60. }
  61. }
  62. - (void)configTableView {
  63. page = 1;
  64. __weak typeof(self) weakSelf = self;
  65. self.topView = [[LDIncomeTopView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, Fitsize(40))];
  66. self.topView.calendarClick = ^{
  67. [weakSelf canlendarAction];
  68. };
  69. [self.view addSubview:self.topView];
  70. [self.view addSubview:self.tableView];
  71. }
  72. - (void)configRequestParam {
  73. switch (self.infoIncomeType) {
  74. case this_day_forecast_income: //今日预估收入
  75. case near_day_forecast_income://近期收入
  76. {
  77. type = 0;
  78. isDay = 1;
  79. yearMonthDay = [LDIncomeDateTool getTodayString];
  80. [self.navigationBar setNavTitle:@"今日预估收入"];
  81. [self.topView setTitleStr:@"今日"];
  82. }
  83. break;
  84. case last_day_forecast_income: //昨日预估收入
  85. {
  86. type = 0;
  87. isDay = 1;
  88. yearMonthDay = [LDIncomeDateTool getYestodayString];
  89. [self.navigationBar setNavTitle:@"昨日预估收入"];
  90. [self.topView setTitleStr:@"昨日"];
  91. }
  92. break;
  93. case last_month_forecast_income: //月预估收入
  94. {
  95. type = 0;
  96. isDay = 0;
  97. yearMonthDay = [LDIncomeDateTool getLastMonthString];
  98. [self.navigationBar setNavTitle:@"月预估收入"];
  99. [self.topView setTitleStr:_yearMonth];
  100. NSArray *array =[_yearMonth componentsSeparatedByString:@"-"];
  101. if ( array.count >1) {
  102. [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@年%@月预估收入",array[0],array[1]]];
  103. }
  104. }
  105. break;
  106. case last_month_settlement_income: //月结算收入
  107. {
  108. type = 1;
  109. isDay = 0;
  110. yearMonthDay = [LDIncomeDateTool getLastMonthString];
  111. [self.navigationBar setNavTitle:@"月结算收入"];
  112. [self.topView setTitleStr:_yearMonth];
  113. NSArray *array =[_yearMonth componentsSeparatedByString:@"-"];
  114. if ( array.count >1) {
  115. [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@年%@月结算收入",array[0],array[1]]];
  116. }
  117. }
  118. break;
  119. default:
  120. break;
  121. }
  122. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  123. }
  124. - (void)configNavigationBar {
  125. self.view.backgroundColor = [UIColor whiteColor];
  126. self.navigationBar.backgroundColor = [UIColor changeColor];
  127. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  128. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  129. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  130. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  131. UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  132. [rightBtn setImage:[UIImage imageNamed:@"helpmonth"] forState:UIControlStateNormal];
  133. [rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
  134. [self.navigationBar setCustomRightButtons:@[rightBtn]];
  135. }
  136. - (void)backAction {
  137. [self.navigationController popViewControllerAnimated:YES];
  138. }
  139. - (void)rightAction {
  140. LDWebDetailController *findbook = [[LDWebDetailController alloc] init];
  141. findbook.pageType = 2;
  142. [self.navigationController pushViewController:findbook animated:YES];
  143. }
  144. /**
  145. 日历事件
  146. */
  147. - (void)canlendarAction {
  148. if (isDay == 1) {
  149. if (self.alertShowView) {
  150. [self.alertShowView show];
  151. return;
  152. }
  153. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:self.calendarView backgroundDismissEnable:YES];
  154. self.alertShowView = showView;
  155. [self.alertShowView show];
  156. }else {
  157. ITDatePickerController *datePickerController = [[ITDatePickerController alloc] init];
  158. datePickerController.tag = 100;
  159. datePickerController.delegate = self;
  160. datePickerController.showToday = NO;
  161. datePickerController.defaultDate = self.startDate;
  162. datePickerController.minimumDate = nil;
  163. datePickerController.maximumDate = nil;
  164. datePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
  165. [self presentViewController:datePickerController animated:YES completion:nil];
  166. }
  167. }
  168. #pragma mark - ITDatePickerControllerDelegate
  169. - (void)datePickerController:(ITDatePickerController *)datePickerController didSelectedDate:(NSDate *)date dateString:(NSString *)dateString {
  170. [self changeDateS:date AndString:dateString];
  171. }
  172. -(void)changeDateS:(NSDate *)date AndString:(NSString *)dateString
  173. {
  174. page = 1;
  175. self.startDate = date;
  176. yearMonthDay = dateString;
  177. [self requestAndRefresh:YES];
  178. [self.topView setTitleStr:dateString];
  179. if (_infoIncomeType == last_month_forecast_income) {//预估
  180. [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@预估收入",dateString]];
  181. }else{//结算
  182. [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@结算收入",dateString]];
  183. }
  184. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  185. }
  186. #pragma mark -------- UITableView Delegate -----
  187. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  188. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  189. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  190. }
  191. }
  192. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  193. return self.dataArr.count;
  194. }
  195. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  196. LDChildCommissionModel *model=self.dataArr[indexPath.row];
  197. if (model.order_status.integerValue == 1) {
  198. return 140;
  199. }
  200. return 110;
  201. }
  202. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  203. return 0.1;
  204. }
  205. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  206. return 0.1;
  207. }
  208. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  209. LDChildCommissionCell *cell = [LDChildCommissionCell cellWithTableView:tableView];
  210. LDChildCommissionModel *model=self.dataArr[indexPath.row];
  211. cell.model=model;
  212. cell.delegatre=self;
  213. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  214. return cell;
  215. }
  216. #pragma mark -网络请求
  217. #pragma mark - request
  218. - (void)requestAndRefresh:(BOOL)refresh{
  219. if (refresh) {
  220. [SVProgressHUD show];
  221. }
  222. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/incomeListNew",BaseURL];
  223. NSDictionary *dic=@{
  224. @"type":@(type),
  225. @"page":@(page),
  226. @"isDay":@(isDay),
  227. @"yearMonthDay":yearMonthDay
  228. };
  229. [LDHttp post:url params:dic success:^(id json) {
  230. if (refresh) {
  231. [self.dataArr removeAllObjects];
  232. }
  233. [self setTopViewInfoWithJson:json];
  234. NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildCommissionModel class] json:json[@"data"]];
  235. if (arr.count>0) {
  236. [self.dataArr addObjectsFromArray:arr];
  237. [self.tableView.mj_footer endRefreshing];
  238. }else {
  239. [self setUpNoDataView];
  240. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  241. }
  242. [self.tableView reloadData];
  243. [SVProgressHUD dismiss];
  244. } failure:^(NSError *error) {
  245. [SVProgressHUD dismiss];
  246. [self.tableView.mj_footer endRefreshing];
  247. }];
  248. }
  249. - (void)setTopViewInfoWithJson:(NSDictionary *)json {
  250. NSInteger orderNum = [json[@"num"] integerValue];
  251. CGFloat allCom = [json[@"allRebate"] floatValue];
  252. [self.topView setOrderNum:orderNum allCommission:allCom];
  253. }
  254. - (void)setUpNoDataView {
  255. self.tableView.showNoDataView = YES;
  256. self.tableView.defaultNoDataText = @"您还没有任何订单";
  257. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  258. }
  259. -(void)ClickModel:(LDChildCommissionModel *)model
  260. {
  261. LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
  262. web.url = model.red_url;
  263. [self.navigationController pushViewController:web animated:YES];
  264. }
  265. #pragma mark ------- layzer ------
  266. - (UITableView *)tableView {
  267. if (!_tableView) {
  268. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight+self.topView.height, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-self.topView.height) style:UITableViewStyleGrouped];
  269. _tableView.estimatedSectionHeaderHeight = 0;
  270. _tableView.estimatedSectionFooterHeight = 0;
  271. _tableView.sectionFooterHeight = 0;
  272. _tableView.sectionHeaderHeight = 0;
  273. _tableView.estimatedRowHeight = 0;
  274. _tableView.delegate = self;
  275. _tableView.dataSource = self;
  276. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  277. _tableView.backgroundColor = [UIColor yhGrayColor];
  278. _tableView.bounces = YES;
  279. _tableView.showsVerticalScrollIndicator = NO;
  280. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  281. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  282. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  283. page ++;
  284. [self requestAndRefresh:NO];
  285. }];
  286. }
  287. return _tableView;
  288. }
  289. - (LDCalendarView *)calendarView {
  290. if (!_calendarView) {
  291. __weak typeof(self) weakSelf = self;
  292. _calendarView = [[LDCalendarView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, 0)];
  293. _calendarView.cancelBlock = ^{
  294. [weakSelf.alertShowView dismiss];
  295. };
  296. _calendarView.makeSureBlock = ^(NSString *dateStr) {
  297. if (dateStr) {
  298. yearMonthDay = dateStr;
  299. page = 1;
  300. [weakSelf requestAndRefresh:YES];
  301. [weakSelf.topView setTitleStr:dateStr];
  302. [weakSelf.navigationBar setNavTitle:dateStr];
  303. weakSelf.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  304. [weakSelf.alertShowView dismiss];
  305. }else {
  306. [weakSelf.alertShowView dismiss];
  307. }
  308. };
  309. }
  310. return _calendarView;
  311. }
  312. -(NSMutableArray *)dataArr{
  313. if (!_dataArr) {
  314. _dataArr=[NSMutableArray array];
  315. }
  316. return _dataArr;
  317. }
  318. @end