SingleProfitViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. //
  2. // SingleProfitViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by apple on 2017/5/15.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "SingleProfitViewController.h"
  9. #import "SingleProfitDetailViewController.h"
  10. #import "SingleProfitSearchModel.h"
  11. #import "SingleProfitCell.h"
  12. #import "DateFormat.h"
  13. @interface SingleProfitViewController ()<UITableViewDelegate,UITableViewDataSource>{
  14. //TableView对象
  15. UITableView *_vTableView;
  16. UIView *_headView;
  17. }
  18. /**
  19. 原始数据源
  20. */
  21. @property (strong, nonatomic) NSMutableArray *dataList;
  22. /**
  23. 原始数据源
  24. */
  25. @property (strong, nonatomic) NSMutableArray *dataNewList;
  26. /**
  27. 请求数据对象
  28. */
  29. @property(nonatomic,strong) ASIDownManager *downManager;
  30. @end
  31. @implementation SingleProfitViewController
  32. #pragma mark - 公共函数
  33. /**
  34. viewDidLoad函数
  35. */
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. //[self showTitle:@"每单利润表"];
  39. [self loadNavStyle];
  40. [self initUI];
  41. [self initSlideSlip];
  42. [self reloadData];
  43. }
  44. /**
  45. 安全区视图发生变化
  46. */
  47. -(void)viewSafeAreaInsetsDidChange{
  48. self.view.backgroundColor = [UIColor whiteColor];
  49. _vTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;
  50. [super viewSafeAreaInsetsDidChange];
  51. }
  52. #pragma mark - 数据源list属性
  53. /**
  54. 原始数据源
  55. @return <#return value description#>
  56. */
  57. - (NSMutableArray *)dataList{
  58. if(_dataList== nil){
  59. _dataList = [NSMutableArray new];
  60. }
  61. return _dataList;
  62. }
  63. /**
  64. 新数据源
  65. @return <#return value description#>
  66. */
  67. - (NSMutableArray *)dataNewList{
  68. if(_dataNewList== nil){
  69. _dataNewList = [NSMutableArray new];
  70. }
  71. return _dataNewList;
  72. }
  73. #pragma mark - 委托回调函数
  74. #pragma mark 委托接口回调函数
  75. /**
  76. 调用接口成功回调
  77. @param sender <#sender description#>
  78. */
  79. - (void)onLoadFinish:(ASIDownManager *)sender {
  80. // 服务器返回数据
  81. NSDictionary *dic = [sender.mWebStr JSONValue];
  82. [self cancel];
  83. // 服务器返回数据是否正确
  84. if (dic && [dic isKindOfClass:[NSDictionary class]])
  85. {
  86. // 服务器返回数据状态值
  87. int iStatus = [[dic objectForKey:@"Status"] intValue];
  88. // 服务器返回数据消息
  89. NSString *message=[dic objectForKey:@"Message"];
  90. _vTableView.tableHeaderView=nil;
  91. _vTableView.backgroundView = nil;
  92. // 服务器返回数据状态值正确
  93. if (iStatus == 0) {
  94. NSArray *approvArr =[dic objectForKey:@"Result"];
  95. [self.dataList removeAllObjects];
  96. [self.dataNewList removeAllObjects];
  97. if(approvArr!=nil)
  98. {
  99. [self.dataList addObjectsFromArray:approvArr];
  100. if(self.dataList.count==0){
  101. //无数据
  102. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  103. UIView *noDataView=[[UIView alloc]init];
  104. noDataView.frame=_vTableView.bounds;
  105. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  106. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  107. [noDataView addSubview:nodataImgView];
  108. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  109. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  110. label.text = @"无数据";
  111. label.numberOfLines = 2;
  112. label.textColor = [UIColor lightGrayColor];
  113. [noDataView addSubview:label];
  114. // 有刷新数据的时候
  115. if(self.dataList == nil || self.dataList.count==0){
  116. _vTableView.backgroundView = noDataView;
  117. [self showAlertViewBackText:@"未找到匹配结果"];
  118. }
  119. }else{
  120. float totalCostValue = 0;
  121. float totalIncometValue = 0;
  122. float totalProfitValue = 0;
  123. for (int i = 0; i < self.dataList.count; i++) {
  124. NSDictionary *dicValue = self.dataList[i];
  125. // 去除空数据
  126. if ([[dicValue objectForKey:@"InvoiceID"] intValue]>0) {
  127. _vTableView.tableHeaderView = _headView;
  128. [self.dataNewList addObject:self.dataList[i]];
  129. }
  130. totalCostValue = totalCostValue + [[dicValue objectForKey:@"CostAmount"] floatValue];
  131. totalProfitValue = totalProfitValue + [[dicValue objectForKey:@"MarginAmount"] floatValue];
  132. totalIncometValue = totalIncometValue + [[dicValue objectForKey:@"Amount"] floatValue];
  133. }
  134. if(self.dataNewList!=nil&&self.dataNewList.count==0){
  135. UIView *noDataView=[[UIView alloc]init];
  136. noDataView.frame=_vTableView.bounds;
  137. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  138. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  139. [noDataView addSubview:nodataImgView];
  140. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  141. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  142. label.text = @"无数据";
  143. label.numberOfLines = 2;
  144. label.textColor = [UIColor lightGrayColor];
  145. [noDataView addSubview:label];
  146. _vTableView.backgroundView = noDataView;
  147. [self showAlertViewBackText:@"未找到匹配结果"];
  148. }
  149. self.lbtotalCostValue.text = [NSString stringWithFormat:@"¥%.2f",totalCostValue];
  150. self.lbtotalIncometValue.text = [NSString stringWithFormat:@"¥%.2f",totalIncometValue];
  151. self.lbtotalProfitValue.text = [NSString stringWithFormat:@"¥%.2f",totalProfitValue];
  152. }
  153. [_vTableView reloadData];
  154. }
  155. else{
  156. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  157. UIView *noDataView=[[UIView alloc]init];
  158. noDataView.frame=_vTableView.bounds;
  159. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  160. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  161. [noDataView addSubview:nodataImgView];
  162. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  163. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  164. label.text = @"无数据";
  165. label.numberOfLines = 2;
  166. label.textColor = [UIColor lightGrayColor];
  167. [noDataView addSubview:label];
  168. // 有刷新数据的时候
  169. _vTableView.backgroundView = noDataView;
  170. [self showAlertViewBackText:@"未找到匹配结果"];
  171. }
  172. }
  173. // 服务器返回数据状态值异常
  174. else if(iStatus==ActionResultStatusAuthError
  175. ||iStatus==ActionResultStatusNoLogin
  176. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  177. [self showReLoginDialog:message];
  178. }
  179. else {
  180. [_vTableView reloadData];
  181. [self showAlertViewText:message];
  182. }
  183. }
  184. }
  185. /**
  186. 调用接口失败回调
  187. @param sender <#sender description#>
  188. */
  189. - (void)onLoadFail:(ASIDownManager *)sender {
  190. [self cancel];
  191. [_vTableView reloadData];
  192. [self showAlertViewText:@"加载失败"];
  193. }
  194. #pragma mark 委托tablview回调函数
  195. /**
  196. 行数
  197. @param tableView tableView description
  198. @param section section description
  199. @return return value description
  200. */
  201. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  202. {
  203. return [self.dataNewList count];
  204. }
  205. /**
  206. Sections数
  207. @param tableView <#tableView description#>
  208. @return <#return value description#>
  209. */
  210. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  211. return 1;
  212. }
  213. /**
  214. 高度
  215. @param tableView <#tableView description#>
  216. @param indexPath <#indexPath description#>
  217. @return <#return value description#>
  218. */
  219. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  220. return 170;
  221. }
  222. /**
  223. 单元格
  224. @param tableView <#tableView description#>
  225. @param indexPath <#indexPath description#>
  226. @return <#return value description#>
  227. */
  228. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  229. {
  230. static NSString *CellIdentifier = @"SingleProfitCell";
  231. SingleProfitCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  232. if (cell == nil) {
  233. cell=[[SingleProfitCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  234. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  235. }
  236. // SingleProfitCell *cell = [[ SingleProfitCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SingleProfitCell"];
  237. NSDictionary *dic= self.dataNewList[indexPath.row];
  238. if(dic!=nil)
  239. {
  240. cell.lblValueCustomerName.text=[dic objectForKey:@"CustomerName"];
  241. // 格式化日期
  242. DateFormat *df = [DateFormat new];
  243. cell.lblValueCreateTime.text=[df dateFormat:[dic objectForKey:@"AccountDate"]];
  244. //业务类型
  245. cell.lblValueCustomerType.text=[dic objectForKey:@"InvoiceTypeName"];
  246. cell.lblValueStaff.text=[dic objectForKey:@"StaffName"];
  247. cell.lblValueOrg.text=[dic objectForKey:@"OrganizationName"];
  248. NSString *str = [NSString stringWithFormat:@"收入:¥%.2f;成本:¥%.2f;毛利:¥%.2f",[[dic objectForKey:@"Amount"]floatValue],[[dic objectForKey:@"CostAmount"]floatValue],[[dic objectForKey:@"MarginAmount"]floatValue]];
  249. cell.lblValueIncomeAndCostAndProfit.text = str;
  250. }
  251. return cell;
  252. }
  253. /**
  254. 单元格选择事件
  255. @param tableView <#tableView description#>
  256. @param indexPath <#indexPath description#>
  257. */
  258. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  259. {
  260. NSDictionary *dic = self.dataNewList[indexPath.row];
  261. if(dic!=nil)
  262. {
  263. self.hidesBottomBarWhenPushed=YES;
  264. SingleProfitDetailViewController *detailVC =[[SingleProfitDetailViewController alloc]init];
  265. detailVC.sInvoiceNo=[dic objectForKey:@"InvoiceNo"];
  266. detailVC.sInvoiceType=[dic objectForKey:@"InvoiceTypeName"];
  267. detailVC.sOrganizationCode=[dic objectForKey:@"OrganizationCode"];
  268. detailVC.sCustomerCode=[dic objectForKey:@"CustomerCode"];
  269. detailVC.sTelephone=[dic objectForKey:@"Telephone"];
  270. detailVC.sCustomerAddress=[dic objectForKey:@"CustomerAddress"];
  271. detailVC.sChannelName=[dic objectForKey:@"ChannelName"];
  272. detailVC.sRemarks=[dic objectForKey:@"Remarks"];
  273. detailVC.sCustomerName=[dic objectForKey:@"CustomerName"];
  274. // 格式化日期
  275. DateFormat *df = [DateFormat new];
  276. detailVC.sAccountDate=[df dateFormat:[dic objectForKey:@"AccountDate"]];
  277. detailVC.sCustomerTypeName=[dic objectForKey:@"CustomerTypeName"];
  278. detailVC.sStaffName=[dic objectForKey:@"StaffName"];
  279. detailVC.sOrganizationName=[dic objectForKey:@"OrganizationName"];
  280. detailVC.sMarginAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"MarginAmount"]floatValue]];
  281. detailVC.sIncomeAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"Amount"]floatValue]];
  282. detailVC.sCostAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"CostAmount"]floatValue]];;
  283. detailVC.sCustomerAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"CustomerAmount"]floatValue]];;
  284. detailVC.sStaffAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"StaffAmount"]floatValue]];;
  285. detailVC.sServiceAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"ServiceAmount"]floatValue]];;
  286. detailVC.sFeesAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"FeesAmount"]floatValue]];;
  287. detailVC.sProfitAmount=[NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"ProfitAmount"]floatValue]];;
  288. [self.navigationController pushViewController:detailVC animated:YES];
  289. }
  290. }
  291. #pragma mark - 私有函数
  292. /**
  293. 初始化ui
  294. */
  295. - (void)initUI {
  296. CGFloat height = 170;
  297. self.navigationItem.title=@"每单利润表";
  298. self.view.backgroundColor = [UIColor whiteColor];
  299. //分割线
  300. UIView *viewBackgroud = [UIView new];
  301. viewBackgroud.frame = CGRectMake(0, 0, Screen_Width, 0);
  302. viewBackgroud.backgroundColor = LineBackgroundColor;
  303. [self.view addSubview:viewBackgroud];
  304. _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, Screen_Width, Screen_Height )];
  305. _vTableView.rowHeight = UITableViewAutomaticDimension;
  306. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  307. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  308. _vTableView.backgroundColor = [UIColor whiteColor];
  309. _vTableView.delegate = self;
  310. _vTableView.dataSource=self;
  311. _vTableView.tableHeaderView = nil;
  312. [self.view addSubview:_vTableView];
  313. //头布局
  314. _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, height)];
  315. UIButton *btnHead=[UIButton buttonWithType:UIButtonTypeCustom];
  316. btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  317. CGFloat titleHeight = 50;
  318. CGFloat lblx = 20;
  319. CGFloat lblwidth = 130;
  320. CGFloat fontsize = 14;
  321. //CGFloat valuex = 125;
  322. CGFloat valuey = 10;
  323. CGFloat valuewidth = 200;
  324. CGFloat valueheight = 25;
  325. CGFloat heightLine =1;
  326. //总合计==================
  327. UIView *vtotal=[UIView new];
  328. vtotal.frame=CGRectMake(0, 0, Screen_Width, titleHeight);
  329. [_headView addSubview:vtotal];
  330. UILabel *lbtotal = [UILabel new];
  331. lbtotal.frame=CGRectMake(lblx, valuey, lblwidth, valueheight);
  332. lbtotal.font = [UIFont boldSystemFontOfSize:fontsize];
  333. lbtotal.text=@"合计";
  334. [vtotal addSubview:lbtotal];
  335. //分割线
  336. viewBackgroud = [UIView new];
  337. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotal.frame), Screen_Width, heightLine);
  338. viewBackgroud.backgroundColor = LineBackgroundColor;
  339. [_headView addSubview:viewBackgroud];
  340. //收入总额==================
  341. UIView *vtotalIncome=[UIView new];
  342. vtotalIncome.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  343. [_headView addSubview:vtotalIncome];
  344. UIImageView *imgview = [UIImageView new];
  345. imgview.frame=CGRectMake(lblx, valuey+5, 21, 16);
  346. [imgview setImage:[UIImage imageNamed:@"profit_income"]];
  347. [vtotalIncome addSubview:imgview];
  348. UILabel *lbtotalReceipt = [UILabel new];
  349. lbtotalReceipt.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey, lblwidth, valueheight);
  350. lbtotalReceipt.font = [UIFont systemFontOfSize:fontsize];
  351. lbtotalReceipt.text=@"收入";
  352. [vtotalIncome addSubview:lbtotalReceipt];
  353. self.lbtotalIncometValue = [UILabel new];
  354. self.lbtotalIncometValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey, valuewidth, valueheight);
  355. self.lbtotalIncometValue.font = [UIFont systemFontOfSize:fontsize];
  356. //lbtotalIncometValue = @"¥0";
  357. self.lbtotalIncometValue.textAlignment = NSTextAlignmentRight;
  358. [vtotalIncome addSubview:self.lbtotalIncometValue];
  359. viewBackgroud = [UIView new];
  360. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalIncome.frame), Screen_Width, heightLine);
  361. viewBackgroud.backgroundColor = LineBackgroundColor;
  362. [_headView addSubview:viewBackgroud];
  363. //成本总额==================
  364. UIView *vtotalCost=[UIView new];
  365. vtotalCost.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  366. [_headView addSubview:vtotalCost];
  367. UIImageView *imgviewReceivable = [UIImageView new];
  368. imgviewReceivable.frame=CGRectMake(lblx, valuey+1, 20, 20);
  369. [imgviewReceivable setImage:[UIImage imageNamed:@"profit_cost"]];
  370. [vtotalCost addSubview:imgviewReceivable];
  371. UILabel *lbtotalReceivable = [UILabel new];
  372. lbtotalReceivable.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey, lblwidth, valueheight);
  373. lbtotalReceivable.font = [UIFont systemFontOfSize:fontsize];
  374. lbtotalReceivable.text=@"成本";
  375. [vtotalCost addSubview:lbtotalReceivable];
  376. self.lbtotalCostValue = [UILabel new];
  377. self.lbtotalCostValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey, valuewidth, valueheight);
  378. self.lbtotalCostValue.font = [UIFont systemFontOfSize:fontsize];
  379. //lbtotalCostValue = @"¥0";
  380. self.lbtotalCostValue.textAlignment = NSTextAlignmentRight;
  381. [vtotalCost addSubview:self.lbtotalCostValue];
  382. viewBackgroud = [UIView new];
  383. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalCost.frame), Screen_Width,heightLine);
  384. viewBackgroud.backgroundColor = LineBackgroundColor;
  385. [_headView addSubview:viewBackgroud];
  386. //==================
  387. UIView *vtotalProfit=[UIView new];
  388. vtotalProfit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  389. [_headView addSubview:vtotalProfit];
  390. UIImageView *imgviewProfit = [UIImageView new];
  391. imgviewProfit.frame=CGRectMake(lblx, valuey+1, 20, 20);
  392. [imgviewProfit setImage:[UIImage imageNamed:@"profit_value"]];
  393. [vtotalProfit addSubview:imgviewProfit];
  394. UILabel *lbtotalProfit = [UILabel new];
  395. lbtotalProfit.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey, lblwidth, valueheight);
  396. lbtotalProfit.font = [UIFont systemFontOfSize:fontsize];
  397. lbtotalProfit.text=@"毛利";
  398. [vtotalProfit addSubview:lbtotalProfit];
  399. self.lbtotalProfitValue = [UILabel new];
  400. self.lbtotalProfitValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey, valuewidth, valueheight);
  401. self.lbtotalProfitValue.font = [UIFont systemFontOfSize:fontsize];
  402. //lbtotalProfitValue = @"¥0";
  403. self.lbtotalProfitValue.textAlignment = NSTextAlignmentRight;
  404. [vtotalProfit addSubview:self.lbtotalProfitValue];
  405. viewBackgroud = [UIView new];
  406. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalProfit.frame), Screen_Width, 10);
  407. viewBackgroud.backgroundColor = LineBackgroundColor;
  408. //[headView addSubview:viewBackgroud];
  409. _headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(vtotalProfit.frame));
  410. _vTableView.tableHeaderView = _headView;
  411. //开始结束日期 初始值
  412. // 格式化日期
  413. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  414. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  415. NSTimeInterval time = 31 * 24 * 60 * 60; //31天的秒数
  416. self.sEndDate = [dateFormatter stringFromDate:[NSDate new]];
  417. self.sStartDate = [dateFormatter stringFromDate: [[NSDate new] dateByAddingTimeInterval:-time]];
  418. self.sBusinessType = @"7";
  419. }
  420. /**
  421. 进度条隐藏
  422. */
  423. - (void)cancel {
  424. [self stopLoading];
  425. }
  426. /**
  427. 加载数据
  428. */
  429. - (void)reloadData
  430. {
  431. [self startLoading];
  432. NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL];
  433. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  434. [dict setObject:@"GetSingleProfitIphone" forKey:@"Action"];
  435. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  436. [dict setObject:kkUserCode forKey:@"UserCode"];
  437. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  438. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  439. [dict setObject:self.sOrgCode forKeyedSubscript:@"OrganizationCode"];
  440. [dict setObject:self.sStaffName forKeyedSubscript:@"StaffName"];
  441. [dict setObject:self.sStartDate forKeyedSubscript:@"AccountDateFrom"];
  442. [dict setObject:self.sEndDate forKeyedSubscript:@"AccountDateTo"];
  443. [dict setObject:self.sCustomerCode forKeyedSubscript:@"CustomerCode"];
  444. [dict setObject:self.sCustomerName forKeyedSubscript:@"CustomerName"];
  445. [dict setObject:self.sBusinessType forKeyedSubscript:@"BusinessType"];
  446. _downManager = [[ASIDownManager alloc] init];
  447. _downManager.delegate = self;
  448. _downManager.OnImageDown = @selector(onLoadFinish:);
  449. _downManager.OnImageFail = @selector(onLoadFail:);
  450. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  451. }
  452. /**
  453. 返回
  454. */
  455. - (void)goBack
  456. {
  457. [self.navigationController popViewControllerAnimated:YES];
  458. }
  459. /**
  460. 导航按钮样式
  461. */
  462. - (void)loadNavStyle
  463. {
  464. //右边
  465. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 16)];
  466. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  467. [btnfilter addTarget:self action:@selector(search)
  468. forControlEvents:UIControlEventTouchUpInside];
  469. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  470. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  471. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  472. forState:UIControlStateNormal];
  473. [v addSubview:btnfilter];
  474. UIButton *filterLbl=[[UIButton alloc]init];
  475. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  476. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  477. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  478. filterLbl.titleLabel.font=[UIFont systemFontOfSize:ButtonFontOfSize];
  479. [filterLbl addTarget:self action:@selector(search)
  480. forControlEvents:UIControlEventTouchUpInside];
  481. [v addSubview:filterLbl];
  482. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  483. self.navigationItem.rightBarButtonItem = menubtnAdd;
  484. //返回
  485. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  486. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  487. forState:UIControlStateNormal];
  488. [button addTarget:self action:@selector(goBack)
  489. forControlEvents:UIControlEventTouchUpInside];
  490. button.frame = CGRectMake(0, 0, 15, 18);
  491. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  492. self.navigationItem.leftBarButtonItem = menuButton;
  493. }
  494. /**
  495. 抽屉弹出
  496. */
  497. - (void)search{
  498. [_filterController show];
  499. }
  500. /**
  501. 抽屉初始化
  502. */
  503. - (void)initSlideSlip{
  504. // 抽屉对象
  505. __weak typeof(self) weakself=self;
  506. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  507. for (SideSlipModel *model in dataList) {
  508. //selectedItem
  509. model.selectedItemList = nil;
  510. model.customDict = nil;
  511. }
  512. } commitBlock:^(NSArray *dataList) {
  513. // 查询条件
  514. SideSlipModel *serviceRegionModel = dataList[0];
  515. SingleProfitSearchModel *m = [serviceRegionModel.customDict objectForKey:SINGLE_PROFIT_SEARCH_RANGE_MODEL];
  516. //NSLog(@"%@--%@--%@--%@--%@",m.startDate,m.endDate,m.sCustomerName,m.sOrg,m.sStaff);
  517. self.sOrgCode = m.sOrg;
  518. self.sStaffName = m.sStaff;
  519. self.sStartDate = m.sStartDate;
  520. self.sEndDate = m.sEndDate;
  521. self.sCustomerCode=m.sCustomerCode;
  522. self.sCustomerName = m.sCustomerName;
  523. self.sBusinessType = m.sBusinessType;
  524. if(self.sStartDate == nil || self.sStartDate.length == 0){
  525. [self showAlertViewText:@"请选择开始日期"];
  526. return;
  527. }
  528. if(self.sEndDate == nil || self.sEndDate.length == 0){
  529. [self showAlertViewText:@"请选择结束日期"];
  530. return;
  531. }
  532. NSUInteger result= [DateFormat compareDate:self.sStartDate withDate:self.sEndDate];
  533. if(result == -1){
  534. [self showAlertViewText:@"开始日期不能大于结束日期"];
  535. return;
  536. }
  537. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  538. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  539. NSDate *startD =[dateFormat dateFromString:self.sStartDate];
  540. NSDate *endD = [dateFormat dateFromString:self.sEndDate];
  541. NSInteger days= [DateFormat calculateDaysFromBegin:startD end:endD];
  542. if(days > 31){
  543. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  544. return;
  545. }
  546. [weakself.filterController dismiss];
  547. [self reloadData];
  548. }];
  549. _filterController.animationDuration = AnimationDuration;
  550. _filterController.hasHeadView = YES;
  551. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  552. _filterController.dataList = [self packageDataList];
  553. }
  554. /**
  555. 数据源
  556. @return <#return value description#>
  557. */
  558. - (NSArray *)packageDataList {
  559. NSMutableArray *dataArray = [NSMutableArray array];
  560. SideSlipModel *model = [[SideSlipModel alloc] init];
  561. model.containerCellClass = @"SingleProfitSearchCell";
  562. model.regionTitle = @"查询条件";
  563. [dataArray addObject:model];
  564. return [dataArray mutableCopy];
  565. }
  566. @end