SalesOutStorageSalesSlipGoodsListVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. //
  2. // SalesSlipGoodsDetailVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/17.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SalesOutStorageSalesSlipGoodsListVC.h"
  9. @interface SalesOutStorageSalesSlipGoodsListVC (){
  10. BOOL isCheckAll;
  11. }
  12. @end
  13. @implementation SalesOutStorageSalesSlipGoodsListVC
  14. #pragma mark 公共函数
  15. /**
  16. 视图加载完成函数
  17. */
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self loadNavStyle];
  21. [self initUI];
  22. if(_salesSlipModel.goodsDetailArray==nil||_salesSlipModel.goodsDetailArray.count==0){
  23. [self loadData];
  24. }
  25. else{
  26. NSInteger num= [self getCheckedGoodsCount:_salesSlipModel.goodsDetailArray];
  27. if(num>0&&num==_salesSlipModel.goodsDetailArray.count){
  28. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  29. isCheckAll=YES;
  30. }
  31. else if(num==0||num!=_salesSlipModel.goodsDetailArray.count){
  32. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  33. isCheckAll=NO;
  34. }
  35. NSString *sureCount=[NSString stringWithFormat:@"%@%lu%@",@"确定(",num,@")"];
  36. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  37. }
  38. }
  39. /**
  40. 安全区变化函数
  41. */
  42. -(void)viewSafeAreaInsetsDidChange{
  43. _vTableView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  44. _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40);
  45. [super viewSafeAreaInsetsDidChange];
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. }
  50. #pragma mark 委托函数
  51. /**
  52. 隐藏键盘
  53. @param scrollView <#scrollView description#>
  54. */
  55. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  56. {
  57. [self.view endEditing:YES];
  58. }
  59. /**
  60. 产品数据加载成功回调
  61. @param sender <#sender description#>
  62. */
  63. - (void)onSalesSlipGoodsDetailLoadFinish:(ASIDownManager *)sender {
  64. NSDictionary *dic = [sender.mWebStr JSONValue];
  65. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  66. // 服务器返回数据状态值
  67. int iStatus = [[dic objectForKey:@"Status"] intValue];
  68. // 服务器返回数据消息
  69. NSString *message=[dic objectForKey:@"Message"];
  70. // 服务器返回数据状态值正确
  71. if (iStatus == 0) {
  72. NSArray * infoArr=[dic objectForKey:@"Result"];
  73. // 返回结果
  74. if(infoArr!=nil&& infoArr.count>0)
  75. {
  76. _salesSlipModel.goodsDetailArray=[[NSMutableArray alloc]init];
  77. for (int i = 0; i < infoArr.count; i++) {
  78. NSDictionary * dic=infoArr[i];
  79. SalesOutStorageSalesSlipGoodsListModel *goodsListModel=[[SalesOutStorageSalesSlipGoodsListModel alloc]init];
  80. [goodsListModel parseDic:dic];
  81. [goodsListModel setCustomerId:_salesSlipModel.customerId];
  82. [_salesSlipModel.goodsDetailArray addObject:goodsListModel];
  83. }
  84. [_vTableView reloadData];
  85. }
  86. }
  87. else if(iStatus==ActionResultStatusAuthError
  88. ||iStatus==ActionResultStatusNoLogin
  89. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  90. [self showReLoginDialog:message];
  91. }
  92. else{
  93. [self showAlertViewText:message];
  94. }
  95. [self stopLoading];
  96. }
  97. }
  98. /**
  99. 产品数据加载失败回调
  100. @param sender <#sender description#>
  101. */
  102. - (void)onSalesSlipGoodsDetailLoadFail:(ASIDownManager *)sender {
  103. [self stopLoading];
  104. [self showAlertViewText:@"加载失败"];
  105. }
  106. /**
  107. 单元格cell个数
  108. @param tableView <#tableView description#>
  109. @param section <#section description#>
  110. @return <#return value description#>
  111. */
  112. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  113. {
  114. return [_salesSlipModel.goodsDetailArray count];
  115. }
  116. /**
  117. tableview的分区数
  118. @param tableView <#tableView description#>
  119. @return <#return value description#>
  120. */
  121. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  122. return 1;
  123. }
  124. /**
  125. 高度
  126. @param tableView <#tableView description#>
  127. @param indexPath <#indexPath description#>
  128. @return <#return value description#>
  129. */
  130. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  131. return 306;
  132. }
  133. /**
  134. 每个单元格cell
  135. @param tableView <#tableView description#>
  136. @param indexPath <#indexPath description#>
  137. @return <#return value description#>
  138. */
  139. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. NSString *cellIdentifier = @"GoodsListCell";
  142. SalesOutStorageGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  143. if (!cell) {
  144. cell=[[SalesOutStorageGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  145. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  146. }
  147. else
  148. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  149. {
  150. while ([cell.contentView.subviews lastObject] != nil) {
  151. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  152. }
  153. }
  154. SalesOutStorageSalesSlipGoodsListModel *goodsListModel= [_salesSlipModel.goodsDetailArray objectAtIndex:indexPath.row];
  155. [cell setSalesOutStorageGoodsListModel:goodsListModel];
  156. [cell setCheckBackground:goodsListModel.checkedFlag];
  157. cell.checkDelegate=self;
  158. cell.cellIndex=indexPath.row;
  159. return cell;
  160. }
  161. /**
  162. checkbox选中的状态
  163. @param index <#index description#>
  164. */
  165. -(void)btnCheckPressed:(NSInteger)index{
  166. SalesOutStorageSalesSlipGoodsListModel *goodsListModel= [_salesSlipModel.goodsDetailArray objectAtIndex:index];
  167. goodsListModel.checkedFlag=!goodsListModel.checkedFlag;
  168. //1.当前所要刷新的cell,传入要刷新的 行数 和 组数
  169. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
  170. //2.将indexPath添加到数组
  171. NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
  172. //3.传入数组,对当前cell进行刷新
  173. [_vTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
  174. if([self isCheckedAll]){
  175. isCheckAll=YES;
  176. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  177. }
  178. else{
  179. isCheckAll=NO;
  180. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  181. }
  182. NSInteger num=[self getCheckedGoodsCount:_salesSlipModel.goodsDetailArray];
  183. NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
  184. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  185. }
  186. #pragma mark 私有函数
  187. /**
  188. 初始化UI
  189. */
  190. -(void)initUI{
  191. [self.view setBackgroundColor:[UIColor whiteColor]];
  192. _vTableView = [[UITableView alloc]
  193. initWithFrame:CGRectMake(0,0,self.view.frame.size.width,
  194. Screen_Height-40)];
  195. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  196. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  197. _vTableView.backgroundColor = [UIColor whiteColor];
  198. _vTableView.delegate = self;
  199. _vTableView.dataSource=self;
  200. [self.view addSubview:_vTableView];
  201. //保存
  202. _bottomView=[UIView new];
  203. _bottomView.frame=CGRectMake(0, Screen_Height-103, self.view.frame.size.width, 40);
  204. [self.view addSubview:_bottomView];
  205. _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
  206. _btnCheckAll.frame=CGRectMake(15,8, 25, 25);
  207. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  208. [_btnCheckAll addTarget:self action:@selector(btnCheckall)
  209. forControlEvents:UIControlEventTouchUpInside];
  210. [_bottomView addSubview:_btnCheckAll];
  211. UILabel *lblall=[UILabel new];
  212. lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,8, 60, 25);
  213. lblall.text=@"全选";
  214. [_bottomView addSubview:lblall];
  215. //提交结算
  216. _sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  217. [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
  218. [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  219. _sureBtn.frame=CGRectMake(Screen_Width-114,0, 114,40);
  220. [_sureBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  221. [_sureBtn addTarget:self action:@selector(submitData) forControlEvents:UIControlEventTouchUpInside];
  222. [_bottomView addSubview:_sureBtn];
  223. }
  224. /**
  225. 提交数据
  226. */
  227. -(void)submitData{
  228. NSMutableArray *checkedGoodsList=[[NSMutableArray alloc]init];
  229. for(int i=0;i<_salesSlipModel.goodsDetailArray.count;i++){
  230. SalesOutStorageSalesSlipGoodsListModel *model=[_salesSlipModel.goodsDetailArray objectAtIndex:i];
  231. if(model.checkedFlag){
  232. [checkedGoodsList addObject:model];
  233. }
  234. }
  235. if([self.goodsListDelegate respondsToSelector:@selector(btnGetCheckedGoodsList:position: )]){
  236. [self.goodsListDelegate btnGetCheckedGoodsList:checkedGoodsList position:_position];
  237. }
  238. [self.navigationController popViewControllerAnimated:YES];
  239. }
  240. /**
  241. 导航按钮样式
  242. */
  243. -(void)loadNavStyle
  244. {
  245. self.navigationItem.title=@"商品列表信息";
  246. //返回
  247. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  248. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  249. forState:UIControlStateNormal];
  250. [button addTarget:self action:@selector(goBack)
  251. forControlEvents:UIControlEventTouchUpInside];
  252. button.frame = CGRectMake(0, 0, 15, 18);
  253. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  254. self.navigationItem.leftBarButtonItem = menuButton;
  255. }
  256. /**
  257. 返回函数
  258. */
  259. - (void)goBack
  260. {
  261. if([self.goodsListDelegate respondsToSelector:@selector(recoveryData)]){
  262. [self.goodsListDelegate recoveryData];
  263. }
  264. [self.navigationController popViewControllerAnimated:YES];
  265. }
  266. /**
  267. 更新checkbox状态
  268. */
  269. -(void)btnCheckall{
  270. [self updateAllCellCheck];
  271. NSInteger num= [self getCheckedGoodsCount:_salesSlipModel.goodsDetailArray];
  272. NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",(long)num,@")"];
  273. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  274. [_vTableView reloadData];
  275. }
  276. /**
  277. 获取选中的产品数
  278. @param goodsList <#goodsList description#>
  279. @return <#return value description#>
  280. */
  281. -(NSInteger) getCheckedGoodsCount:(NSMutableArray*)goodsList{
  282. int num=0;
  283. NSMutableArray *goodsSubmitList=[[NSMutableArray alloc]init];
  284. NSInteger count=goodsList.count;
  285. for(int i=0;i<count;i++){
  286. SalesOutStorageSalesSlipGoodsListModel *model= goodsList[i];
  287. if(model.checkedFlag){
  288. num++;
  289. [goodsSubmitList addObject:model];
  290. }
  291. }
  292. NSInteger checkedCount=goodsSubmitList.count;
  293. return checkedCount;
  294. }
  295. /**
  296. 全选或者不选
  297. @return <#return value description#>
  298. */
  299. -(BOOL)updateAllCellCheck
  300. {
  301. if(!isCheckAll){
  302. isCheckAll=YES;
  303. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  304. for(SalesOutStorageSalesSlipGoodsListModel *goodsModel in _salesSlipModel.goodsDetailArray) {
  305. goodsModel.checkedFlag=YES;
  306. }
  307. }
  308. else
  309. {
  310. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  311. isCheckAll=NO;
  312. for(SalesOutStorageSalesSlipGoodsListModel *goodsModel in _salesSlipModel.goodsDetailArray) {
  313. goodsModel.checkedFlag=NO;
  314. }
  315. }
  316. return NO;
  317. }
  318. /**
  319. 加载产品数据源
  320. */
  321. -(void)loadData{
  322. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  323. [dict setObject:@"GetSalesDataSearchDetailIphone" forKey:@"Action"];
  324. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  325. [dict setObject:kkUserCode forKey:@"UserCode"];
  326. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  327. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  328. [dict setObject:_salesSlipModel.salesId== nil? @"" : _salesSlipModel.salesId forKey:@"SalesID"];
  329. [self startLoading];
  330. _downManager = [[ASIDownManager alloc] init];
  331. _downManager.delegate = self;
  332. _downManager.OnImageDown = @selector(onSalesSlipGoodsDetailLoadFinish:);
  333. _downManager.OnImageFail = @selector(onSalesSlipGoodsDetailLoadFail:);
  334. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  335. }
  336. /**
  337. 跳转到更多信息页面
  338. @param goodsModel <#goodsModel description#>
  339. */
  340. -(void)goMoreInfo:(SalesOutStorageSalesSlipGoodsListModel *)goodsModel{
  341. SalesOutStorageSalesSlipGoodsDetailVC *goodsDetailVc=[[SalesOutStorageSalesSlipGoodsDetailVC alloc]init];
  342. goodsDetailVc.goodsModel=goodsModel;
  343. [self.navigationController pushViewController:goodsDetailVc animated:YES];
  344. }
  345. /**
  346. 判断是否全选
  347. @return <#return value description#>
  348. */
  349. -(BOOL)isCheckedAll
  350. {
  351. BOOL ischecked=YES;
  352. for(SalesOutStorageSalesSlipGoodsListModel *model in _salesSlipModel.goodsDetailArray) {
  353. if( !model.checkedFlag)
  354. {
  355. ischecked=NO;
  356. break;
  357. }
  358. }
  359. return ischecked;
  360. }
  361. @end