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

DRAchievementViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. //
  2. // DRAchievementViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/8/2.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRAchievementViewController.h"
  9. #import "DRAchievementDetailView.h"
  10. #import "DRAchievementHeader.h"
  11. #import "DRIncomeViewController.h"
  12. #import "DRAccountInfoModel.h"
  13. #import "DRCommissionMainViewController.h"
  14. #import "DRAchievementListCell.h"
  15. #import "DRChildAccountViewController.h"
  16. #import "DRIncomeViewController.h"
  17. #import "DRWebDetailController.h"
  18. #import "DRAccountModel.h"
  19. #import "DRNoDataCell.h"
  20. #import "DRPrivilegeReferralViewController.h"
  21. @interface DRAchievementViewController ()<UITableViewDelegate,UITableViewDataSource>
  22. {
  23. UILabel *guiEstimateLb;
  24. UILabel *guiFinalLb;
  25. UIButton *forecastBtn;
  26. UIButton *accoutnBtn ;
  27. NSDictionary *userinfoDic;
  28. }
  29. @property (nonatomic, strong) UITableView *tableView;
  30. @property (nonatomic, strong) UIView *header;
  31. @property (nonatomic, strong) DRAchievementDetailView *dayView;//日预估
  32. @property (nonatomic, strong) DRAchievementDetailView *monthEstimateView;//月预估
  33. @property (nonatomic, strong) DRAchievementDetailView *monthFinalView; //月结算
  34. @property (nonatomic, strong) DRAchievementHeader *achievementHeader;
  35. @property (nonatomic, strong) DRAccountInfoModel *accountInfoModel;
  36. @property(nonatomic,strong)NSArray *TodayArray;
  37. @property(nonatomic,strong)NSArray *dataArray;
  38. //结算收入类型
  39. @property(nonatomic,copy)NSString *acctountType;
  40. @end
  41. @implementation DRAchievementViewController
  42. - (void)viewWillAppear:(BOOL)animated {
  43. [super viewWillAppear:animated];
  44. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  45. }
  46. - (void)viewWillDisappear:(BOOL)animated {
  47. [super viewWillDisappear:animated];
  48. [SVProgressHUD dismiss];
  49. }
  50. -(void)viewDidAppear:(BOOL)animated
  51. {
  52. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. [self configNavigationBar];
  57. [self configTableViewHeader];
  58. [self requestData];
  59. [self accountMonthSWithType:@"1"];//1预估收入2结算收入
  60. }
  61. - (void)configTableViewHeader {
  62. self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(110))];
  63. __weak typeof(self) weakSelf = self;
  64. //头视图
  65. self.achievementHeader = [[DRAchievementHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(110))];
  66. self.achievementHeader.carryOrderClick = ^{
  67. DRChildAccountViewController *accountDetail = [[DRChildAccountViewController alloc] init];//提现
  68. [weakSelf.navigationController pushViewController:accountDetail animated:YES];
  69. };
  70. [self.header addSubview:self.achievementHeader];
  71. [self.view addSubview:self.tableView];
  72. //判断是否是会员。
  73. //取值(key值同名的时候会覆盖的)
  74. userinfoDic =[DRUserInfoManager shareManager].userInfoDic;
  75. if ([userinfoDic[@"user_level"] integerValue]==1) {
  76. self.header.frame=CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(135));
  77. UIButton *accountBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, FITSIZE(115), SCREEN_WIDTH, FITSIZE(30))];
  78. [accountBtn setImage:[UIImage imageNamed:@"goto_detail"] forState:UIControlStateNormal];
  79. [accountBtn setImageEdgeInsets:UIEdgeInsetsMake(FITSIZE(7.5), SCREEN_WIDTH-FITSIZE(30), FITSIZE(7.5), FITSIZE(15))];
  80. accountBtn.backgroundColor =[UIColor whiteColor];
  81. [accountBtn addTarget:self action:@selector(accountClickBtn) forControlEvents:UIControlEventTouchUpInside];
  82. [self.header addSubview:accountBtn];
  83. UIImageView *imgv =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(15), FITSIZE(7.5), FITSIZE(15), FITSIZE(15))];
  84. imgv.image =[UIImage imageNamed:@"order_notice"];
  85. [accountBtn addSubview:imgv];
  86. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), 0, FITSIZE(300), FITSIZE(30))];
  87. label.text=@"你还不是超级会员,成为超级会员就能购物有收益啦";
  88. label.textColor=[UIColor YHColorWithHex:0xFB6526];
  89. label.font=[UIFont systemFontOfSize:FITSIZE(12)];
  90. [accountBtn addSubview:label];
  91. }
  92. self.tableView.tableHeaderView = self.header;
  93. }
  94. #pragma mark-特权介绍
  95. -(void)accountClickBtn
  96. {
  97. DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init];
  98. [self.navigationController pushViewController:Privilege animated:YES];
  99. }
  100. - (void)configNavigationBar {
  101. [self.navigationBar setNavTitle:@"我的收益"];
  102. self.navigationBar.backgroundColor = [UIColor changeColor];
  103. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  104. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  105. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  106. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  107. UIButton * nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-Fitsize(50), 0, Fitsize(100), Fitsize(30))];
  108. nextBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  109. [nextBtn setTitle:@"订单明细" forState:UIControlStateNormal];
  110. nextBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(13)];
  111. nextBtn.titleLabel.textAlignment = NSTextAlignmentRight;
  112. [nextBtn setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:-5];
  113. [nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
  114. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  115. [self.navigationBar setCustomRightButtons:@[nextBtn]];
  116. }
  117. -(void)nextBtnAction
  118. {
  119. DRCommissionMainViewController *commissionMain = [[DRCommissionMainViewController alloc] init];
  120. commissionMain.showIndex = 2;
  121. [self.navigationController pushViewController:commissionMain animated:YES];
  122. }
  123. - (void)backAction {
  124. [self.navigationController popViewControllerAnimated:YES];
  125. }
  126. - (void)setUpNoDataView {
  127. self.tableView.showNoDataView = YES;
  128. self.tableView.noDataImageOffsetY = -70;
  129. self.tableView.defaultNoDataText = @"您还没有收益~";
  130. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
  131. }
  132. - (void)requestData {
  133. if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
  134. [self.achievementHeader setAllCommission:@"0" orderNum:@"0"];
  135. [self setUpNoDataView];
  136. [self.tableView.mj_header endRefreshing];
  137. [self.tableView reloadData];
  138. }else{
  139. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/myEarnings",BaseURL];
  140. [DRCacheHttp post:url params:nil success:^(id json, BOOL isCache) {
  141. self.accountInfoModel = [DRAccountInfoModel yy_modelWithJSON:json];
  142. [self.achievementHeader setAllCommission:self.accountInfoModel.all_settlement_income orderNum:self.accountInfoModel.account_balance];
  143. [self setAccountInfoView];
  144. [self.tableView.mj_header endRefreshing];
  145. } failure:^(NSError *error) {
  146. [self.tableView.mj_header endRefreshing];
  147. }];
  148. }
  149. }
  150. #pragma mark----按月计算收益
  151. -(void)accountMonthSWithType:(NSString *)types
  152. {
  153. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/monthEarnings",BaseURL];
  154. [self changeType];
  155. [DRCacheHttp post:url params:@{@"type":types} success:^(id json, BOOL isCache) {
  156. _acctountType =types;
  157. self.dataArray=[NSArray yy_modelArrayWithClass:[DRAccountModel class] json:json];
  158. [self.tableView reloadData];
  159. } failure:^(NSError *error) {
  160. [self.tableView.mj_header endRefreshing];
  161. }];
  162. }
  163. - (void)setAccountInfoView {
  164. if (self.accountInfoModel) {
  165. self.TodayArray = [self.accountInfoModel getTodayInfoArr];
  166. NSArray *monthEstimateArr = [self.accountInfoModel getMonthEstimateInfoArr];
  167. NSArray *monthFinalArr = [self.accountInfoModel getMonthFinalInfoArr];
  168. [self.monthEstimateView setAccountInfo:monthEstimateArr];
  169. [self.monthFinalView setAccountInfo:monthFinalArr];
  170. }
  171. [self.tableView reloadData];
  172. }
  173. #pragma mark
  174. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  175. if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
  176. return 0;
  177. }
  178. if (section == 1) {
  179. if (self.dataArray.count ==0) {
  180. return 1;
  181. }
  182. return self.dataArray.count;
  183. }
  184. return 2;
  185. }
  186. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  187. if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
  188. return 0;
  189. }
  190. return 2;
  191. }
  192. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  193. return FITSIZE(45);
  194. }
  195. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  196. {
  197. UIView *views =[[UIView alloc]initWithFrame:CGRectMake(0, FITSIZE(0), SCREEN_WIDTH, FITSIZE(45))];
  198. views.backgroundColor =[UIColor whiteColor];
  199. UILabel *finalBottomLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(10))];
  200. finalBottomLine.backgroundColor = [UIColor yhGrayColor];
  201. [views addSubview:finalBottomLine];
  202. UIButton *addbtn =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-FITSIZE(30), FITSIZE(20), FITSIZE(15), FITSIZE(15))];
  203. [views addSubview:addbtn];
  204. addbtn.tag = section;
  205. [addbtn addTarget:self action:@selector(ClickBtn:) forControlEvents:UIControlEventTouchUpInside];
  206. if (section ==0) {
  207. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(10), FITSIZE(100), FITSIZE(35))];
  208. label.text=@"近期收入";
  209. [views addSubview:label];
  210. [addbtn setImage:[UIImage imageNamed:@"calendar_gray"] forState:UIControlStateNormal];
  211. }else{
  212. [addbtn setImage:[UIImage imageNamed:@"yiwen"] forState:UIControlStateNormal];
  213. forecastBtn =[[UIButton alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(10), FITSIZE(60), FITSIZE(35))];
  214. [forecastBtn setTitle:@"预估收入" forState:UIControlStateNormal];
  215. forecastBtn.tag = 10000;
  216. [views addSubview:forecastBtn];
  217. [forecastBtn addTarget:self action:@selector(changeOrderBtn:) forControlEvents:UIControlEventTouchUpInside];
  218. UILabel *finalLine = [[UILabel alloc] initWithFrame:CGRectMake(FITSIZE(72), FITSIZE(17.5), 1, FITSIZE(20))];
  219. finalLine.backgroundColor = [UIColor yhGrayColor];
  220. [views addSubview:finalLine];
  221. accoutnBtn =[[UIButton alloc]initWithFrame:CGRectMake(FITSIZE(75), FITSIZE(10), FITSIZE(60), FITSIZE(35))];
  222. [accoutnBtn setTitle:@"结算收入" forState:UIControlStateNormal];
  223. accoutnBtn.tag = 10001;
  224. [accoutnBtn addTarget:self action:@selector(changeOrderBtn:) forControlEvents:UIControlEventTouchUpInside];
  225. [views addSubview:accoutnBtn];
  226. }
  227. [self changeType];
  228. return views;
  229. }
  230. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  231. if (self.dataArray.count ==0 && indexPath.section == 1) {
  232. DRNoDataCell *cell = [[DRNoDataCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"nodata"];
  233. cell.selectionStyle =UITableViewCellSelectionStyleNone;
  234. return cell;
  235. }
  236. DRAchievementListCell *cell = [[DRAchievementListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
  237. cell.selectionStyle =UITableViewCellSelectionStyleNone;
  238. if (indexPath.section == 0) {
  239. cell.yearLabel.hidden=YES;
  240. if (indexPath.row == 0) {
  241. cell.titleLabel.text=@"今日";
  242. }else{
  243. cell.titleLabel.text=@"昨日";
  244. }
  245. cell.titleLabel.frame=CGRectMake(0, 0, FITSIZE(50), FITSIZE(50));
  246. if (self.TodayArray.count !=0) {
  247. cell.pricelabel.text=[NSString stringWithFormat:@"¥%.2f",[self.TodayArray[indexPath.row][1]floatValue]];
  248. cell.ordernumLabel.text=[NSString stringWithFormat:@"共%ld单",(long)[self.TodayArray[indexPath.row][0]integerValue]];
  249. }
  250. }else{
  251. cell.yearLabel.hidden=NO;
  252. if (self.dataArray.count !=0) {
  253. cell.model=self.dataArray[indexPath.row];
  254. }
  255. }
  256. cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  257. return cell;
  258. }
  259. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  260. {
  261. if (indexPath.section ==0 ) {
  262. if (indexPath.row == 1) {//昨日预估收入
  263. [self changeType:last_day_forecast_income AndDate:nil YearMonth:@""];
  264. }
  265. if (indexPath.row == 0) {//今日预估
  266. [self changeType:this_day_forecast_income AndDate:nil YearMonth:@""];
  267. }
  268. }
  269. if (indexPath.section ==1 && self.dataArray.count !=0) {//指定月份的结算收入
  270. DRAccountModel *models =self.dataArray[indexPath.row];
  271. if (_acctountType.integerValue == 1) {//预估收入
  272. [self changeType:last_month_forecast_income AndDate:[self StringTODate:models.yearAndMonth] YearMonth:models.yearAndMonth];
  273. }else{
  274. [self changeType:last_month_settlement_income AndDate:[self StringTODate:models.yearAndMonth] YearMonth:models.yearAndMonth];
  275. }
  276. }
  277. }
  278. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  279. if (indexPath.section == 1) {
  280. if (self.dataArray.count ==0) {
  281. return FITSIZE(200);
  282. }
  283. }
  284. return FITSIZE(50);
  285. }
  286. #pragma mark--点击
  287. -(void)ClickBtn:(UIButton *)btn
  288. {
  289. if (btn.tag == 0) {//日历
  290. [self changeType:near_day_forecast_income AndDate:nil YearMonth:@""];
  291. }else{//提示
  292. DRWebDetailController *findbook = [[DRWebDetailController alloc] init];
  293. findbook.pageType = 2;
  294. [self.navigationController pushViewController:findbook animated:YES];
  295. }
  296. }
  297. -(void)changeType:(UserInfoIncomeType)type AndDate:(NSDate *)date YearMonth:(NSString *)yearmonth
  298. {
  299. DRIncomeViewController *income = [[DRIncomeViewController alloc] init];
  300. income.infoIncomeType =type;
  301. income.startDate=date;
  302. income.yearMonth=yearmonth;
  303. [self.navigationController pushViewController:income animated:YES];
  304. }
  305. - (NSDate *)StringTODate:(NSString *)sender
  306. {
  307.     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  308.     dateFormatter.dateFormat = @"YYYY-MM";
  309.     [dateFormatter setMonthSymbols:[NSArray arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12", nil]];
  310.     NSDate * ValueDate = [dateFormatter dateFromString:sender];
  311.     return ValueDate;
  312. }
  313. #pragma mark-----收入切换
  314. -(void)changeOrderBtn:(UIButton *)btn
  315. {
  316. if (btn.tag == 10000) {//预估收入
  317. [self accountMonthSWithType:@"1"];
  318. }else{
  319. [self accountMonthSWithType:@"2"];
  320. }
  321. }
  322. -(void)changeType
  323. {
  324. if (_acctountType.integerValue ==1) {
  325. [forecastBtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
  326. [accoutnBtn setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
  327. forecastBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(14)];
  328. accoutnBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(11)];
  329. }else{
  330. [accoutnBtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
  331. [forecastBtn setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
  332. accoutnBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(14)];
  333. forecastBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(11)];
  334. }
  335. }
  336. #pragma mark ===================== layezer ==============
  337. - (UITableView *)tableView {
  338. if (!_tableView) {
  339. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
  340. _tableView.estimatedSectionHeaderHeight = 0;
  341. _tableView.estimatedSectionFooterHeight = 0;
  342. _tableView.sectionFooterHeight = 0;
  343. _tableView.sectionHeaderHeight = 0;
  344. _tableView.delegate = self;
  345. _tableView.dataSource = self;
  346. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  347. _tableView.backgroundColor = [UIColor clearColor];
  348. _tableView.bounces = YES;
  349. _tableView.showsVerticalScrollIndicator = NO;
  350. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  351. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  352. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  353. [self requestData];
  354. }];
  355. }
  356. return _tableView;
  357. }
  358. @end