dkahgld

DataViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // DataViewController.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/3/26.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "DataViewController.h"
  9. #import "ZBEaingingTitleView.h"
  10. #import "ZBIncomeViewController.h"
  11. #import "ZBEarnHeadModel.h"
  12. #import "ZBEarnModel.h"
  13. @interface DataViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. {
  15. BOOL changeAccount;//近期结算和近期预估的切换,yes为预估
  16. BOOL monthAccount;
  17. NSString *chartTyep;//0今天、1昨天、2本月
  18. NSString *btnType;//结算和预估的切换
  19. CGFloat _oldY;
  20. }
  21. @property(nonatomic,strong)UITableView *tableViews;
  22. @property(nonatomic,strong)NSMutableArray *listArray;
  23. @property(nonatomic,strong)UILabel *accountMoneyL;
  24. @property(nonatomic,strong)ZBEaingingTitleView *titleView;
  25. @property(nonatomic,strong)ZBEarnHeadModel *headModel;
  26. @property(nonatomic,strong)ZBTipeView *tipView;
  27. @end
  28. @implementation DataViewController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self initNav];
  32. //接收通知
  33. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leftSliderClickWithRow:) name:@"data" object:nil];
  34. //接收通知
  35. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeHeadInfo) name:@"datahead" object:nil];
  36. [[UIApplication sharedApplication].keyWindow addSubview:self.tipView];
  37. [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.top.bottom.right.mas_equalTo(0);
  39. }];
  40. }
  41. -(void)changeHeadInfo
  42. {
  43. ZBUserInfoViewController *setV =[[ZBUserInfoViewController alloc]init];
  44. [self.navigationController pushViewController:setV animated:YES];
  45. }
  46. #pragma mark -- 左边控制器页面push方法
  47. -(void)leftSliderClickWithRow:(NSNotification *)noti{
  48. NSIndexPath *indexPaht =[noti object];
  49. NSInteger row =indexPaht.row;
  50. if (row == 0 ) {//收藏夹
  51. ZBCollectionVC *collV =[[ZBCollectionVC alloc]init];
  52. [self.navigationController pushViewController:collV animated:YES];
  53. return;
  54. }else if (row == 1) {//客服小蜜
  55. ZBAdWebViewController *adWeb = [[ZBAdWebViewController alloc] init];
  56. adWeb.url =jiaochengUrl;
  57. [self.navigationController pushViewController:adWeb animated:YES];
  58. return;
  59. }
  60. //过审.没有快手
  61. if (![PublicFunction canOpenURL:kwaiUrl]) {
  62. ZBSetViewController *setv=[[ZBSetViewController alloc]init];
  63. [self.navigationController pushViewController:setv animated:YES];
  64. }else{
  65. if (row == 2){//招商合作
  66. ZBWebViewController *web = [[ZBWebViewController alloc] init];
  67. web.url = CooperationURl;
  68. [self.navigationController pushViewController:web animated:YES];
  69. }else if (row == 3) {//PId
  70. ZBPIdViewController *pidV =[[ZBPIdViewController alloc]init];
  71. [self.navigationController pushViewController:pidV animated:YES];
  72. }else if (row == 4){//设置
  73. ZBSetViewController *setv=[[ZBSetViewController alloc]init];
  74. [self.navigationController pushViewController:setv animated:YES];
  75. }
  76. }
  77. }
  78. #pragma mark -- 移除通知
  79. -(void)dealloc{
  80. [[NSNotificationCenter defaultCenter]removeObserver:self];
  81. }
  82. -(void)viewWillAppear:(BOOL)animated
  83. {
  84. [super viewWillAppear:animated];
  85. [self getAccounthead];
  86. if (monthAccount) {
  87. [self getMonthWithtype:chartTyep AndCate:@"0"];
  88. }else{
  89. [self getMonthWithtype:chartTyep AndCate:@"1"];
  90. }
  91. if ([AccountTool isLogin]) {
  92. AccountModel *infomodels =[AccountTool account];
  93. NSLog(@"%@",infomodels.img);
  94. [self.headImgV sd_setImageWithURL:[NSURL URLWithString:infomodels.img]];
  95. }
  96. [PublicFunction saveAccountWithPush:@"data"];
  97. [PublicFunction saveAccountChangeInfoWithPush:@"datahead"];
  98. }
  99. #pragma mark----收益
  100. //头部信息
  101. -(void)getAccounthead
  102. {
  103. if (![AccountTool isLogin]) {
  104. return;
  105. }
  106. [LoadingView showInView:self.view];
  107. [ZBHTTP post:getMyEarnURL params:nil success:^(id _Nonnull json) {
  108. [LoadingView dismiss];
  109. NSLog(@"%@",json);
  110. self.headModel=[ZBEarnHeadModel yy_modelWithJSON:json];
  111. [self.titleView.orderNum setTitle:self.headModel.allIncomePredict forState:UIControlStateNormal];
  112. [self.titleView.orderMoney setTitle:self.headModel.allIncomeEnd forState:UIControlStateNormal];
  113. self.accountMoneyL.text=[NSString stringWithFormat:@"¥%@",self.headModel.account_balance];
  114. self.titleView.model=self.headModel;
  115. [self.tableViews reloadData];
  116. } failure:^(NSError * _Nonnull error) {
  117. [LoadingView dismiss];
  118. // [MBProgressHUD showMessage:@"网络错误"];
  119. }];
  120. }
  121. #pragma mark---预估折线图
  122. #pragma mark---每月预估
  123. -(void)getMonthWithtype:(NSString *)type AndCate:(NSString *)cate
  124. {//预估1,结算2
  125. if (![AccountTool isLogin]) {
  126. return;
  127. }
  128. NSDictionary *dic =@{@"type":type,@"cate":cate};
  129. [LoadingView showInView:self.view];
  130. [ZBHTTP post:[NSString stringWithFormat:@"%@api/order/myEarningOrderStatistics",BASEURL] params:dic success:^(id _Nonnull json) {
  131. [LoadingView dismiss];
  132. NSArray *array =(NSArray *)json;
  133. [self.listArray removeAllObjects];
  134. [self.listArray addObjectsFromArray:array];
  135. [self.tableViews reloadData];
  136. NSLog(@"%@",json);
  137. } failure:^(NSError * _Nonnull error) {
  138. [LoadingView dismiss];
  139. // [MBProgressHUD showMessage:@"网络错误"];
  140. }];
  141. }
  142. -(void)initNav
  143. {
  144. chartTyep = @"0";//默认是今天
  145. self.backView.hidden=NO;
  146. self.navBar.navTitleLabel.font=[UIFont systemFontOfSize:18];
  147. self.navBar.hidden=NO;
  148. changeAccount = YES;//近期预估
  149. monthAccount =YES;
  150. btnType =@"1";//预估
  151. UIButton *rightBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  152. [rightBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
  153. [rightBtn addTarget:self action:@selector(rightClickIncomeBtn) forControlEvents:UIControlEventTouchUpInside];
  154. [self.navBar setCustomRightButtons:@[rightBtn]];
  155. //收益
  156. self.titleView =[[ZBEaingingTitleView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 124)];
  157. __weak typeof(self) weakself = self;
  158. self.titleView.Incomeblock = ^{
  159. [weakself getYUGU];
  160. };
  161. [self.view addSubview:self.tableViews];
  162. [self.tableViews mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.top.mas_equalTo(15+NavBarHeight);
  164. make.bottom.mas_equalTo(self.view.mas_bottom);
  165. make.left.mas_equalTo(10);
  166. make.right.mas_equalTo(-10);
  167. }];
  168. [self.view addSubview:self.titleView];
  169. ZBIncomeView *headV= [[ZBIncomeView alloc]initWithFrame:CGRectMake(0, 124, SCREEN_WIDTH-20, 64)];
  170. headV.IncomeClickVc = ^{
  171. [self clickMyWithMoney];
  172. };
  173. headV.myOrderListVc = ^{
  174. [self selectedTextHeader];
  175. };
  176. UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 188)];
  177. headView.backgroundColor=[UIColor clearColor];
  178. [headView addSubview:self.titleView];
  179. [headView addSubview:headV];
  180. self.tableViews.tableHeaderView=headView;
  181. }
  182. #pragma mark---TableViewDelegate&&DataSource
  183. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. if (indexPath.section == 1) {
  186. ZBIncomeChartCell *chartC =[tableView dequeueReusableCellWithIdentifier:@"chartC"];
  187. if (!chartC) {
  188. chartC=[[ZBIncomeChartCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"chartC"];
  189. chartC.selectionStyle=UITableViewCellSelectionStyleNone;
  190. }
  191. chartC.changeType = ^(NSString * _Nonnull Type) {
  192. chartTyep = Type;
  193. };
  194. if (monthAccount) {
  195. chartC.cateType = @"0";//销量
  196. }else{
  197. chartC.cateType=@"1";//收益
  198. }
  199. chartC.array = self.listArray;
  200. return chartC;
  201. }
  202. ZBAccountListCell *listC =[tableView dequeueReusableCellWithIdentifier:@"list"];
  203. if (!listC) {
  204. listC=[[ZBAccountListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"list"];
  205. listC.selectionStyle=UITableViewCellSelectionStyleNone;
  206. }
  207. listC.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  208. if (indexPath.row == self.listArray.count-1) {
  209. listC.lineV.hidden = YES;
  210. }else{
  211. listC.lineV.hidden=NO;
  212. }
  213. if (indexPath.section == 1) {
  214. listC.yearLabel.hidden=NO;
  215. [listC.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  216. make.height.mas_equalTo(25);
  217. make.top.mas_equalTo(5);
  218. }];
  219. listC.model = self.listArray[indexPath.row];
  220. }else if (indexPath.section == 0 && self.headModel != nil)
  221. {
  222. if (indexPath.row == 0) {
  223. listC.timeLabel.text=@"今日";
  224. if (changeAccount) {//近期预估
  225. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.thisDayOrderCount];
  226. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.thisDayIncomePredict];
  227. }else{//结算
  228. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.thisDayOrderCountEnd];
  229. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.thisDayIncomeEnd];
  230. }
  231. }else if (indexPath.row == 1) {
  232. listC.timeLabel.text=@"昨日";
  233. if (changeAccount) {//近期预估
  234. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.lastDayOrderCount];
  235. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.lastDayIncomePredict];
  236. }else{//结算
  237. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.lastDayOrderCountEnd];
  238. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.lastDayIncomeEnd];
  239. }
  240. }else if (indexPath.row == 2) {
  241. listC.timeLabel.text=@"本月";
  242. if (changeAccount) {//近期预估
  243. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.currentMonthOrderCount];
  244. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.currentMonthIncomePredict];
  245. }else{//结算
  246. listC.numLabel.text=[NSString stringWithFormat:@"共%@单",self.headModel.currentMonthCountEnd];
  247. listC.moneyLabel.text=[NSString stringWithFormat:@"¥%@",self.headModel.currentMonthIncomeEnd];
  248. }
  249. }
  250. }
  251. return listC;
  252. }
  253. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  254. {
  255. if (section==0) {
  256. return 3;
  257. }
  258. return 1;
  259. }
  260. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  261. {
  262. return 2;
  263. }
  264. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  265. {
  266. if (indexPath.section == 1) {
  267. return 280;
  268. }
  269. return 52;
  270. }
  271. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  272. {
  273. return 55;
  274. }
  275. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  276. {
  277. ZBAccountHeadView *headV =[[ZBAccountHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 55)];
  278. if (section == 0) {
  279. headV.recently = changeAccount;
  280. }else{
  281. headV.recently = monthAccount;
  282. }
  283. if (section == 0) {
  284. [headV.frastBtn setTitle:@"近期预估" forState:UIControlStateNormal];
  285. [headV.accountBtn setTitle:@"近期结算" forState:UIControlStateNormal];
  286. headV.allBtn.hidden =NO;
  287. headV.allBlock = ^{
  288. [self getYUGU];
  289. };
  290. }else{
  291. headV.allBtn.hidden=YES;
  292. [headV.frastBtn setTitle:@"销量走势" forState:UIControlStateNormal];
  293. [headV.accountBtn setTitle:@"收益走势" forState:UIControlStateNormal];
  294. }
  295. headV.changeBtnBlock = ^(UIButton * _Nonnull button) {
  296. if (section == 0) {
  297. if (button.tag == 1234) {
  298. changeAccount = YES;
  299. }else{
  300. changeAccount = NO;
  301. }
  302. [self.tableViews reloadData];
  303. }else{
  304. if (button.tag == 1234) {
  305. monthAccount = YES;//销量
  306. [self getMonthWithtype:chartTyep AndCate:@"0"];//热销商品
  307. }else{
  308. monthAccount = NO;//收益
  309. [self getMonthWithtype:chartTyep AndCate:@"1"];//销量走势
  310. }
  311. }
  312. if (button.tag == 1234) {//近期预估
  313. btnType=@"1";
  314. }else{//结算
  315. btnType =@"2";
  316. }
  317. };
  318. return headV;
  319. }
  320. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  321. {
  322. ZBIncomeViewController *incomV =[[ZBIncomeViewController alloc]init];
  323. if (indexPath.section == 0) {//当天结算列表
  324. incomV.isDay =1;//按天
  325. if (indexPath.row == 0) {//今日
  326. incomV.yearMonthDay=[PublicFunction getCurrentDay];
  327. }else if(indexPath.row == 1){//昨日
  328. incomV.yearMonthDay=[PublicFunction getYestDay];
  329. }else{//本月
  330. incomV.isDay =0;
  331. incomV.yearMonthDay=[PublicFunction backToPassedTimeWithMonthNumber:0];
  332. }
  333. incomV.type=btnType;//1:预估收入 2:结算收入
  334. [self.navigationController pushViewController:incomV animated:YES];
  335. }
  336. }
  337. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  338. if ([scrollView isEqual: self.tableViews] && self.tableViews.contentSize.height > SCREEN_HEIGHT-95) {
  339. if (self.tableViews.contentOffset.y > NavBarHeight) {
  340. // 上滑
  341. [UIView animateWithDuration:0.5 animations:^{
  342. self.backView.frame=CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 0);
  343. [self.tableViews mas_updateConstraints:^(MASConstraintMaker *make) {
  344. make.top.mas_equalTo(NavBarHeight);
  345. }];
  346. }];
  347. }
  348. else{
  349. // 下滑
  350. [UIView animateWithDuration:0.5 animations:^{
  351. self.backView.frame=CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 95);
  352. [self.tableViews mas_updateConstraints:^(MASConstraintMaker *make) {
  353. make.top.mas_equalTo(NavBarHeight+15);
  354. }];
  355. }];
  356. }
  357. }
  358. }
  359. -(UITableView *)tableViews
  360. {
  361. if (!_tableViews) {
  362. _tableViews =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
  363. _tableViews.delegate=self;
  364. _tableViews.dataSource=self;
  365. _tableViews.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4];
  366. _tableViews.separatorStyle=UITableViewCellSeparatorStyleNone;
  367. _tableViews.sectionHeaderHeight=55;
  368. _tableViews.layer.cornerRadius=8;
  369. _tableViews.layer.masksToBounds=YES;
  370. _tableViews.showsHorizontalScrollIndicator=NO;
  371. _tableViews.showsVerticalScrollIndicator=NO;
  372. }
  373. return _tableViews;
  374. }
  375. -(NSMutableArray *)listArray
  376. {
  377. if (!_listArray) {
  378. _listArray=[NSMutableArray array];
  379. }
  380. return _listArray;
  381. }
  382. #pragma mark---我的账户
  383. -(void)clickMyWithMoney
  384. {
  385. ZBWithDrawalViewController *drawV =[[ZBWithDrawalViewController alloc]init];
  386. [self.navigationController pushViewController:drawV animated:YES];
  387. }
  388. #pragma mark---订单结算明细
  389. -(void)selectedTextHeader
  390. {
  391. ZBOrderListViewController *listV =[[ZBOrderListViewController alloc]init];
  392. [self.navigationController pushViewController:listV animated:YES];
  393. }
  394. -(UILabel *)accountMoneyL
  395. {
  396. if (!_accountMoneyL ) {
  397. _accountMoneyL =[[UILabel alloc]init];
  398. _accountMoneyL.textAlignment=NSTextAlignmentRight;
  399. _accountMoneyL.text=@"Y--.--";
  400. _accountMoneyL.textColor=[UIColor YHColorWithHex:0xFF7D00];
  401. _accountMoneyL.font=[UIFont boldSystemFontOfSize:18];
  402. }
  403. return _accountMoneyL;
  404. }
  405. #pragma mark----收益统计
  406. -(void)rightClickIncomeBtn
  407. {
  408. ZBIncomeStatisticsViewController *incomeV =[[ZBIncomeStatisticsViewController alloc]init];
  409. [self.navigationController pushViewController:incomeV animated:YES];
  410. }
  411. #pragma mark----提示视图
  412. -(ZBTipeView *)tipView
  413. {
  414. if (!_tipView) {
  415. _tipView =[[ZBTipeView alloc]init];
  416. _tipView.hidden=YES;
  417. _tipView.tag=1010;
  418. }
  419. return _tipView;
  420. }
  421. #pragma mark---预估明细
  422. -(void)getYUGU
  423. {
  424. ZBMonthOrderVC *orderV =[[ZBMonthOrderVC alloc]init];
  425. [self.navigationController pushViewController:orderV animated:YES];
  426. }
  427. @end