《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRIncomeViewController.m 12KB

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