SalesOutStorageListVC.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. //
  2. // SalesOutStorageListVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/10.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SalesOutStorageListVC.h"
  9. @interface SalesOutStorageListVC (){
  10. int pageNumber;
  11. }
  12. @end
  13. @implementation SalesOutStorageListVC
  14. #pragma mark 公共函数
  15. /**
  16. 视图加载完成函数
  17. */
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self loadNavStyle];
  21. [self initUI];
  22. [self initSlideSlip];
  23. pageNumber = 1;
  24. [self loadData];
  25. }
  26. /**
  27. 修改:2017-9-25
  28. 适配机型
  29. 安全区视图发生变化
  30. */
  31. -(void)viewSafeAreaInsetsDidChange{
  32. self.view.backgroundColor = [UIColor whiteColor];
  33. _vCustomTableView.frame = CGRectMake(0, CGRectGetMaxY(_topSeparatorView.frame),Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height- CGRectGetMaxY(_topSeparatorView.frame) );
  34. [super viewSafeAreaInsetsDidChange];
  35. }
  36. #pragma mark 委托函数
  37. /**
  38. 销售出库数据加载完成函数
  39. @param sender <#sender description#>
  40. */
  41. - (void)onOutStorageListFinish:(ASIDownManager *)sender {
  42. NSDictionary *dic = [sender.mWebStr JSONValue];
  43. _vCustomTableView.mTableView.backgroundView = nil;
  44. [self stopLoading];
  45. // 服务器返回数据是否正确
  46. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  47. // 服务器返回数据状态值
  48. int iStatus = [[dic objectForKey:@"Status"] intValue];
  49. int iNewCount = 0;
  50. // 服务器返回数据消息
  51. NSString *message=[dic objectForKey:@"Message"];
  52. // 服务器返回数据状态值正确
  53. if (iStatus == 0) {
  54. NSArray * infoArr=[dic objectForKey:@"Result"];
  55. // 返回结果
  56. if(infoArr!=nil&& infoArr.count>0)
  57. {
  58. for (int i = 0; i < infoArr.count; i++) {
  59. NSDictionary * dic=infoArr[i];
  60. SalesOutStorageListModel *salesOutStorageListModel=[[SalesOutStorageListModel alloc]init];
  61. [salesOutStorageListModel parseDic:dic];
  62. [_dataList addObject:salesOutStorageListModel];
  63. }
  64. iNewCount =(int)infoArr.count;
  65. _vCustomTableView.mbMoreHidden = (iNewCount == 0);
  66. [_vCustomTableView FinishLoading];
  67. [_vCustomTableView reloadData];
  68. }
  69. else{
  70. [_vCustomTableView FinishLoading];
  71. _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  72. UIView *noDataView=[[UIView alloc]init];
  73. noDataView.frame=_vCustomTableView.bounds;
  74. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  75. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  76. [noDataView addSubview:nodataImgView];
  77. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  78. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  79. label.text = @"无数据";
  80. label.numberOfLines = 2;
  81. label.textColor = [UIColor lightGrayColor];
  82. [noDataView addSubview:label];
  83. // 有刷新数据的时候
  84. if(_dataList == nil || _dataList.count==0){
  85. _vCustomTableView.mTableView.backgroundView =noDataView;
  86. [self showAlertViewBackText:@"未找到匹配结果"];
  87. }
  88. }
  89. }
  90. // 服务器返回数据状态值异常
  91. else if(iStatus==ActionResultStatusAuthError
  92. ||iStatus==ActionResultStatusNoLogin
  93. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  94. [self stopLoading];
  95. [self showReLoginDialog:message];
  96. }
  97. else{
  98. [self stopLoading];
  99. [_vCustomTableView FinishLoading];
  100. [self showAlertViewText:message];
  101. }
  102. }
  103. }
  104. /**
  105. 销售出库数据加载失败函数
  106. @param sender <#sender description#>
  107. */
  108. - (void)onOutStorageListFail:(ASIDownManager *)sender {
  109. [self stopLoading];
  110. [self showAlertViewText:@"加载失败"];
  111. }
  112. /**
  113. 刷新数据
  114. */
  115. -(void) refreshData{
  116. pageNumber = 1;
  117. [_dataList removeAllObjects];
  118. [_vCustomTableView reloadData];
  119. _vCustomTableView.mbMoreHidden=YES;
  120. [self startLoading];
  121. [self loadData];
  122. }
  123. /**
  124. 单元格cell个数
  125. @param tableView <#tableView description#>
  126. @param section <#section description#>
  127. @return <#return value description#>
  128. */
  129. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  130. {
  131. return [_dataList count];
  132. }
  133. /**
  134. tableview的分区数
  135. @param tableView <#tableView description#>
  136. @return <#return value description#>
  137. */
  138. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  139. return 1;
  140. }
  141. /**
  142. 高度
  143. @param tableView <#tableView description#>
  144. @param indexPath <#indexPath description#>
  145. @return <#return value description#>
  146. */
  147. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  148. return 315;
  149. }
  150. /**
  151. 每个单元格cell
  152. @param tableView <#tableView description#>
  153. @param indexPath <#indexPath description#>
  154. @return <#return value description#>
  155. */
  156. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  157. {
  158. NSString *cellIdentifier = @"OutStorageListCell";
  159. SalesOutStorageListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  160. if (!cell) {
  161. cell=[[SalesOutStorageListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  162. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  163. }
  164. else
  165. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  166. {
  167. while ([cell.contentView.subviews lastObject] != nil) {
  168. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  169. }
  170. }
  171. _outStorageListModel= [_dataList objectAtIndex:indexPath.row];
  172. cell.salesOutStorageDelegate = self;
  173. [cell setSalesOutStorageModel:_outStorageListModel];
  174. return cell;
  175. }
  176. /**
  177. 取消刷新
  178. @param sender sender description
  179. @return return value description
  180. */
  181. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  182. return YES;
  183. }
  184. /**
  185. 下拉刷新
  186. @param sender <#sender description#>
  187. */
  188. - (void)ReloadList:(RefreshTableView *)sender{
  189. pageNumber = 1;
  190. [_dataList removeAllObjects];
  191. [_vCustomTableView reloadData];
  192. _vCustomTableView.mbMoreHidden=YES;
  193. [self startLoading];
  194. [self loadData];
  195. }
  196. /**
  197. 加载更多
  198. @param sender sender description
  199. */
  200. - (void)LoadMoreList:(RefreshTableView *)sender {
  201. pageNumber++;
  202. [self startLoading];
  203. [self loadData];
  204. }
  205. /**
  206. 点击单元格事件
  207. @param tableView tableView description
  208. @param indexPath indexPath description
  209. */
  210. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  211. {
  212. self.hidesBottomBarWhenPushed=YES;
  213. SalesOutStorageDetailVC *detailVc=[[SalesOutStorageDetailVC alloc] init];
  214. SalesOutStorageListModel *salesOutStorageDetailModel= [_dataList objectAtIndex:indexPath.row];
  215. detailVc.salesOutStorageDetail= salesOutStorageDetailModel;
  216. [self.navigationController pushViewController:detailVc animated:YES];
  217. }
  218. /**
  219. 跳转到销售出库明细页面
  220. @param model <#model description#>
  221. */
  222. -(void)goDetail:(SalesOutStorageListModel *)model{
  223. self.hidesBottomBarWhenPushed = YES;
  224. SalesOutStorageListDetailVC *vc = [[SalesOutStorageListDetailVC alloc] init];
  225. vc.deliveryId=model.outStorageId;
  226. vc.outStorageNo=model.outStorageNo;
  227. [self.navigationController pushViewController:vc animated:YES];
  228. }
  229. /**
  230. 去冲正
  231. @param model <#model description#>
  232. */
  233. -(void)goCorrect:(SalesOutStorageListModel *)model{
  234. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
  235. message:@"确定要冲正吗?" preferredStyle:UIAlertControllerStyleAlert];
  236. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  237. style:UIAlertActionStyleDefault
  238. handler:^(UIAlertAction *action){
  239. [self correctData:model];
  240. }];
  241. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
  242. style:UIAlertActionStyleDefault
  243. handler:^(UIAlertAction *action){
  244. }];
  245. UIColor *cancelColor=[UIColor blackColor];
  246. UIColor *sureColor=[UIColor redColor];
  247. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  248. [okAction setValue:sureColor forKey:@"titleTextColor"];
  249. [alert addAction:okAction];
  250. [alert addAction:cancelAction];
  251. [self presentViewController:alert animated:YES completion:nil];
  252. }
  253. /**
  254. 冲正数据源加载成功回调
  255. @param sender <#sender description#>
  256. */
  257. - (void)onCorrectFinish:(ASIDownManager *)sender {
  258. NSDictionary *dic = [sender.mWebStr JSONValue];
  259. _vCustomTableView.mTableView.backgroundView = nil;
  260. [self stopLoading];
  261. // 服务器返回数据是否正确
  262. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  263. // 服务器返回数据状态值
  264. int iStatus = [[dic objectForKey:@"Status"] intValue];
  265. // 服务器返回数据消息
  266. NSString *message=[dic objectForKey:@"Message"];
  267. // 服务器返回数据状态值正确
  268. if (iStatus == 0) {
  269. pageNumber = 1;
  270. [_dataList removeAllObjects];
  271. [_vCustomTableView reloadData];
  272. _vCustomTableView.mbMoreHidden=YES;
  273. [self startLoading];
  274. [self loadData];
  275. [self showAlertViewText:@"冲正成功"];
  276. }
  277. // 服务器返回数据状态值异常
  278. else if(iStatus==ActionResultStatusAuthError
  279. ||iStatus==ActionResultStatusNoLogin
  280. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  281. [self showReLoginDialog:message];
  282. }
  283. else{
  284. [_vCustomTableView FinishLoading];
  285. [self showAlertViewText:message];
  286. }
  287. }
  288. }
  289. /**
  290. 冲正数据源加载失败回调
  291. @param sender <#sender description#>
  292. */
  293. - (void)onCorrectFail:(ASIDownManager *)sender {
  294. [self stopLoading];
  295. [self showAlertViewText:@"加载失败"];
  296. }
  297. #pragma mark 私有函数
  298. /**
  299. 导航按钮样式
  300. */
  301. -(void)loadNavStyle
  302. {
  303. //右边
  304. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  305. [btnAdd addTarget:self action:@selector(add)
  306. forControlEvents:UIControlEventTouchUpInside];
  307. UIImage *pic =[UIImage imageNamed:@"title_add"];
  308. btnAdd.frame = CGRectMake(0, 0, 18, 18);
  309. [btnAdd setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  310. [btnAdd setBackgroundImage:pic
  311. forState:UIControlStateNormal];
  312. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  313. self.navigationItem.title=@"销售出库列表";
  314. self.navigationItem.rightBarButtonItem = menubtnAdd;
  315. //返回
  316. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  317. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  318. forState:UIControlStateNormal];
  319. [button addTarget:self action:@selector(goBack)
  320. forControlEvents:UIControlEventTouchUpInside];
  321. button.frame = CGRectMake(0, 0, 15, 18);
  322. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  323. self.navigationItem.leftBarButtonItem = menuButton;
  324. }
  325. /**
  326. 加载出库数据源
  327. */
  328. -(void)loadData{
  329. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  330. [dict setObject:@"GetSalesInventoryListIphone" forKey:@"Action"];
  331. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  332. [dict setObject:kkUserCode forKey:@"UserCode"];
  333. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  334. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  335. [dict setObject:_outStorageNo== nil? @"" : _outStorageNo forKey:@"DeliveryNo"];
  336. [dict setObject:_salesNo == nil? @"" : _salesNo forKey:@"SalesNo"];
  337. [dict setObject:_customerName == nil? @"" : _customerName forKey:@"CustomerName"];
  338. [dict setObject:@"1" forKey:@"DeliveryType"];
  339. [dict setObject:_customerCode == nil? @"" : _customerCode forKey:@"CustomerCode"];
  340. [dict setObject:_startDate == nil? @"" : _startDate forKey:@"AccountDateFrom"];
  341. [dict setObject:_customerAddress == nil? @"" : _customerAddress forKey:@"Address"];
  342. [dict setObject:_endDate == nil? @"" : _endDate forKey:@"AccountDateTo"];
  343. [dict setObject:_invoiceStatus == nil? @"" : _invoiceStatus forKey:@"InvoiceStatus"];
  344. [dict setObject:@"20" forKey:@"PageSize"];
  345. [dict setObject:[NSString stringWithFormat:@"%d",pageNumber] forKey:@"PageNum"];
  346. _downManager = [[ASIDownManager alloc] init];
  347. [self startLoading];
  348. _downManager.delegate = self;
  349. _downManager.OnImageDown = @selector(onOutStorageListFinish:);
  350. _downManager.OnImageFail = @selector(onOutStorageListFail:);
  351. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  352. }
  353. /**
  354. 跳转到新增销售出库页面
  355. */
  356. -(void)add{
  357. self.hidesBottomBarWhenPushed=YES;
  358. NewSalesOutStorageHomeVC *homeVc=[[NewSalesOutStorageHomeVC alloc] init];
  359. homeVc.refreshDelegate=self;
  360. [self.navigationController pushViewController:homeVc animated:YES];
  361. }
  362. /**
  363. 返回函数
  364. */
  365. - (void)goBack
  366. {
  367. [self.navigationController popViewControllerAnimated:YES];
  368. }
  369. /**
  370. 抽屉初始化
  371. */
  372. - (void)initSlideSlip{
  373. // 抽屉对象
  374. __weak typeof(self) weakself=self;
  375. self.filterController = [[SideSlipFilterController alloc]
  376. initWithSponsor:self
  377. resetBlock:^(NSArray *dataList) {
  378. for (SideSlipModel *model in dataList) {
  379. model.selectedItemList = nil;
  380. model.customDict = nil;
  381. }
  382. } commitBlock:^(NSArray *dataList) {
  383. // 查询条件
  384. SideSlipModel *serviceRegionModel = dataList[0];
  385. SalesOutStorageSearchModel *m = [serviceRegionModel.customDict objectForKey:OUT_STORAGE_SEARCH_RANGE_MODEL];
  386. _outStorageNo =m.outStorageNo;
  387. _customerName=m.customerName;
  388. if([m.startDate isEqualToString:@"请选择开始账务日期"]){
  389. _startDate=@"";
  390. }
  391. else{
  392. _startDate=m.startDate;
  393. }
  394. if([m.endDate isEqualToString:@"请选择结束账务日期"]){
  395. _endDate=@"";
  396. }
  397. else{
  398. _endDate=m.endDate;
  399. }
  400. _salesNo=m.salesNo;
  401. _customerCode=m.customerCode;
  402. _customerAddress = m.customerAddress;
  403. _invoiceStatus=m.invoiceStatus;
  404. [weakself.filterController dismiss];
  405. pageNumber = 1;
  406. [_dataList removeAllObjects];
  407. [_vCustomTableView reloadData];
  408. _vCustomTableView.mbMoreHidden=YES;
  409. [self startLoading];
  410. [self loadData];
  411. }];
  412. _filterController.animationDuration = AnimationDuration;
  413. _filterController.hasHeadView = YES;
  414. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  415. _filterController.dataList = [self packageDataList];
  416. }
  417. /**
  418. 数据源
  419. @return <#return value description#>
  420. */
  421. - (NSArray *)packageDataList {
  422. NSMutableArray *dataArray = [NSMutableArray array];
  423. SideSlipModel *model = [[SideSlipModel alloc] init];
  424. model.containerCellClass = @"SalesOutStorageSearchCell";
  425. model.regionTitle = @"查询条件";
  426. [dataArray addObject:model];
  427. return [dataArray mutableCopy];
  428. }
  429. /**
  430. 初始化UI
  431. */
  432. -(void)initUI{
  433. CGFloat height = 40;
  434. UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 60)];
  435. searchView.backgroundColor = [UIColor whiteColor];
  436. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  437. btnSearch.frame = CGRectMake(20,10, Screen_Width-height, height);
  438. btnSearch.layer.cornerRadius = 6.0f;
  439. [btnSearch setTitle:@"搜索" forState:UIControlStateNormal];
  440. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  441. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  442. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  443. btnSearch.backgroundColor = LineBackgroundColor;
  444. [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
  445. [searchView addSubview:btnSearch];
  446. [self.view addSubview:searchView];
  447. _topSeparatorView = [UIView new];
  448. _topSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(searchView.frame), Screen_Width, 10);
  449. _topSeparatorView.backgroundColor = LineBackgroundColor;
  450. [self.view addSubview:_topSeparatorView];
  451. _dataList=[[NSMutableArray alloc]init];
  452. _vCustomTableView = [[RefreshTableView alloc]
  453. initWithFrame:CGRectMake(0,
  454. CGRectGetMaxY(_topSeparatorView.frame),
  455. self.view.frame.size.width,
  456. Screen_Height - CGRectGetMaxY(_topSeparatorView.frame))];
  457. _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  458. _vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  459. _vCustomTableView.backgroundColor = [UIColor whiteColor];
  460. _vCustomTableView.delegate = self;
  461. [self.view addSubview:_vCustomTableView];
  462. }
  463. /**
  464. 打开抽屉
  465. */
  466. -(void)dataSearch{
  467. [_filterController show];
  468. }
  469. /**
  470. 冲正数据
  471. @param model <#model description#>
  472. */
  473. -(void)correctData:(SalesOutStorageListModel *)model{
  474. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  475. [dict setObject:@"SaveReverseSalesInventoryIphone" forKey:@"Action"];
  476. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  477. [dict setObject:kkUserCode forKey:@"UserCode"];
  478. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  479. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  480. [dict setObject:@"1" forKey:@"IDevicesType"];
  481. [dict setObject:model.outStorageId == nil?@"":model.outStorageId forKey:@"DeliveryID"];
  482. NSString *statusStr = [NSString stringWithFormat:@"%ld",(long)model.invoiceStatusId];
  483. [dict setObject:statusStr == nil?@"":statusStr forKey:@"Status"];
  484. [dict setObject:model.outStorageTypeId forKey:@"DeliveryType"];
  485. [self startLoading];
  486. _downManager = [[ASIDownManager alloc] init];
  487. _downManager.delegate = self;
  488. _downManager.OnImageDown = @selector(onCorrectFinish:);
  489. _downManager.OnImageFail = @selector(onCorrectFail:);
  490. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  491. }
  492. @end