OrderViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //
  2. // OrderViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/9.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "OrderViewController.h"
  9. #import "PurchaseintentionCell.h"
  10. #import "OrderdetailViewController.h"
  11. @interface OrderViewController ()<UITableViewDelegate,UITableViewDataSource,PurchaseintentionDelegate>{
  12. UITableView *newtableView;
  13. NSMutableArray *dataArray;
  14. int pageIndex;
  15. int pageSize;
  16. int pageNumber;
  17. UIView *showView;
  18. }
  19. @end
  20. @implementation OrderViewController
  21. - (void)viewWillAppear:(BOOL)animated
  22. {
  23. [super viewWillAppear:animated];
  24. if (newtableView) {
  25. [self autoRefresh];
  26. }
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. [self dataInitialization];
  31. [self loadsView];
  32. [self addRefreshing];
  33. // Do any additional setup after loading the view.
  34. }
  35. #pragma mark- 网络请求
  36. - (void)autoRefresh
  37. {
  38. __weak UITableView *tableView = newtableView;
  39. [tableView.mj_header beginRefreshing];
  40. }
  41. - (void)networkRequest:(id)object
  42. {
  43. int pageNumberIndex=1;
  44. if (!object) {
  45. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  46. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  47. pageNumberIndex = 1;
  48. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  49. pageNumberIndex = pageNumber+1;
  50. }
  51. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  52. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  53. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  54. [parameters safeSetObject:@"true" forKey:@"confirm"];
  55. [NetworkRequestManager requestPostWithInterfacePrefix:JT_orderList parameters:parameters onSuccess:^(id requestData) {
  56. [self dismiss:object];
  57. if ([requestData[@"error"] count] !=0) {
  58. for (NSDictionary *dic in requestData[@"error"]) {
  59. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  60. }
  61. }else{
  62. pageNumber = pageNumberIndex;
  63. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  64. [dataArray removeAllObjects];
  65. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  66. NSMutableArray *arr = requestData[@"data"][@"list"];
  67. if ([arr count]<=0) {
  68. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  69. }
  70. }
  71. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  72. PurchaseintentionModel *model = [[PurchaseintentionModel alloc] initWithDictionary:dic error:nil];
  73. [dataArray addObject:model];
  74. }
  75. //查询不到类型底图
  76. if (dataArray.count<=0) {
  77. [self addErrorLoadingFrame:CGRectMake(0, 44, newtableView.width, newtableView.height) title:@"咦,您还没有订单噢" buttonTitle:nil imageString:NewNoDataErrorImage];
  78. }else {
  79. [self hideReloadingview];
  80. [newtableView reloadData];
  81. }
  82. }
  83. } onFailure:^{
  84. [self dismiss:object];
  85. }];
  86. }
  87. #pragma mark - 数据初始化
  88. - (void)dataInitialization{
  89. dataArray = NewMutableArrayInit;
  90. pageIndex = 1;
  91. pageSize = 10;
  92. pageNumber = 1;
  93. }
  94. #pragma mark ----加载界面
  95. - (void)loadsView{
  96. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader+44)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  97. newtableView.separatorStyle = NO;
  98. }
  99. #pragma mark-------------------------UITableView------------------------------------
  100. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  101. {
  102. return 1;
  103. }
  104. //返回每段行数
  105. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  106. {
  107. return dataArray.count;
  108. }
  109. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. static NSString *Cell = @"Cell";
  112. PurchaseintentionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  113. if (cell == nil) {
  114. cell = [[PurchaseintentionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  115. }
  116. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  117. cell.accessoryType = UITableViewCellAccessoryNone;
  118. if (dataArray.count>0) {
  119. PurchaseintentionModel *model = dataArray[indexPath.row];
  120. [cell assignment:dataArray[indexPath.row] commoditysModel:model.commoditys];
  121. cell.delegate = self;
  122. }
  123. return cell;
  124. }
  125. #pragma mark ------操作按钮网络请求-----
  126. - (void)transButIndex:(UIButton*)button{
  127. NSString *str = [NSString stringWithFormat:@"是否%@?",button.titleLabel.text];
  128. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:(UIAlertControllerStyleAlert)];
  129. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
  130. [self faafa:button];
  131. }];
  132. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
  133. //NSLog(@"取消");
  134. }];
  135. [alertController addAction:okAction];
  136. [alertController addAction:cancelAction];
  137. [self presentViewController:alertController animated:YES completion:nil];
  138. }
  139. - (void)faafa:(UIButton *)button{
  140. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  141. PurchaseintentionCell *cell = (PurchaseintentionCell *)button.superview.superview;
  142. NSIndexPath *indexPath = [newtableView indexPathForCell:cell];
  143. PurchaseintentionModel *model = dataArray[indexPath.row];
  144. /*
  145. 拒绝意向 和 确认意向 调取 /api/user/order/confirmIntention
  146. */
  147. NSMutableDictionary *dic = NewMutableDictionaryInit;
  148. NSString *url;
  149. if ([button.titleLabel.text isEqualToString:@"取消订单"]) {
  150. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  151. url = JT_applyForCancel;//取消订单
  152. }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){
  153. // [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  154. // [dic safeSetObject:model.orderAmount forKey:@"fundAmount"];
  155. // [dic safeSetObject:@"" forKey:@"remarks"];
  156. // url = JT_payForFirst;//支付首付
  157. OrderdetailViewController *vc = [[OrderdetailViewController alloc] init];
  158. vc.orderID = model.orderNo;
  159. [MBProgressHUD hideHUDForView:self.view];
  160. NewPushViewController(vc);
  161. return;
  162. }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){
  163. // [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  164. // [dic safeSetObject:model.orderAmount forKey:@"fundAmount"];
  165. // [dic safeSetObject:@"" forKey:@"remarks"];
  166. // url = JT_payForLast;//支付尾款
  167. OrderdetailViewController *vc = [[OrderdetailViewController alloc] init];
  168. vc.orderID = model.orderNo;
  169. [MBProgressHUD hideHUDForView:self.view];
  170. NewPushViewController(vc);
  171. return;
  172. }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]||[button.titleLabel.text isEqualToString:@"确认意向"]){
  173. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  174. if ([button.titleLabel.text isEqualToString:@"拒绝意向"]) {
  175. [dic safeSetObject:@"true" forKey:@"confirm"];
  176. }else{
  177. [dic safeSetObject:@"false" forKey:@"confirm"];
  178. }
  179. url = JT_confirmIntention;
  180. }else if ([button.titleLabel.text isEqualToString:@"提现"]){
  181. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  182. url = JT_applyForWithdraw;
  183. OrderdetailViewController *vc = [[OrderdetailViewController alloc] init];
  184. vc.orderID = model.orderNo;
  185. NewPushViewController(vc);
  186. [MBProgressHUD hideHUDForView:self.view];
  187. return;
  188. }else if ([button.titleLabel.text isEqualToString:@"申请退款"]){
  189. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  190. url = JT_applyForRefund;
  191. }else if ([button.titleLabel.text isEqualToString:@"同意退款"]||[button.titleLabel.text isEqualToString:@"拒绝退款"]){
  192. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  193. if ([button.titleLabel.text isEqualToString:@"同意退款"]) {
  194. [dic safeSetObject:@"1" forKey:@"confirm"];
  195. }else{
  196. [dic safeSetObject:@"0" forKey:@"confirm"];
  197. }
  198. url = JT_confirmRefund;
  199. }
  200. [NetworkRequestManager requestPostWithInterfacePrefix:url parameters:dic onSuccess:^(id requestData) {
  201. [MBProgressHUD hideHUDForView:self.view];
  202. if ([requestData[@"error"] count] !=0) {
  203. for (NSDictionary *dic in requestData[@"error"]) {
  204. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  205. }
  206. }else{
  207. if ([button.titleLabel.text isEqualToString:@"取消订单"]) {
  208. [MBProgressHUD showSuccess:@"取消订单成功" toView:self.view];
  209. }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){
  210. [MBProgressHUD showSuccess:@"支付首付成功" toView:self.view];
  211. }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){
  212. [MBProgressHUD showSuccess:@"支付尾款成功" toView:self.view];
  213. }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]){
  214. [MBProgressHUD showSuccess:@"拒绝意向成功" toView:self.view];
  215. }else if ([button.titleLabel.text isEqualToString:@"确认意向"]){
  216. [MBProgressHUD showSuccess:@"确认意向成功" toView:self.view];
  217. }else if ([button.titleLabel.text isEqualToString:@"提现"]){
  218. [MBProgressHUD showSuccess:@"提现成功" toView:self.view];
  219. }else if ([button.titleLabel.text isEqualToString:@"申请退款"]){
  220. [MBProgressHUD showSuccess:@"申请退款" toView:self.view];
  221. }else if ([button.titleLabel.text isEqualToString:@"同意退款"]){
  222. [MBProgressHUD showSuccess:@"同意退款" toView:self.view];
  223. }else if ([button.titleLabel.text isEqualToString:@"拒绝退款"]){
  224. [MBProgressHUD showSuccess:@"拒绝退款" toView:self.view];
  225. }
  226. [self networkRequest:nil];
  227. }
  228. } onFailure:^{
  229. [MBProgressHUD hideHUDForView:self.view];
  230. }];
  231. }
  232. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  233. {
  234. return fitScreenWidth(187+30);
  235. }
  236. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  237. PurchaseintentionModel *model = dataArray[indexPath.row];
  238. OrderdetailViewController *vc = [[OrderdetailViewController alloc] init];
  239. vc.orderID = model.orderNo;
  240. NewPushViewController(vc);
  241. }
  242. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  243. return CGFLOAT_MIN;
  244. }
  245. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  246. return CGFLOAT_MIN;
  247. }
  248. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  249. return [[UIView alloc] init];
  250. }
  251. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  252. return [[UIView alloc] init];
  253. }
  254. #pragma mark - 上拉下拉初始化
  255. - (void)addRefreshing
  256. {
  257. __weak typeof(self) weakSelf = self;
  258. __weak UITableView *tableView = newtableView;
  259. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  260. if ([NetworkRequestManager connectedToNetwork]) {
  261. [weakSelf networkRequest:tableView.mj_header];
  262. }else{
  263. [tableView.mj_header endRefreshing];
  264. }
  265. }];
  266. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  267. if ([NetworkRequestManager connectedToNetwork]) {
  268. [weakSelf networkRequest:tableView.mj_footer];
  269. }else{
  270. [tableView.mj_footer endRefreshing];
  271. }
  272. }];
  273. }
  274. - (void)dismiss:(id)object
  275. {
  276. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  277. __weak UITableView *newvc = newtableView;
  278. [newvc.mj_header endRefreshing];
  279. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  280. __weak UITableView *newvc = newtableView;
  281. [newvc.mj_footer endRefreshing];
  282. }else {
  283. [MBProgressHUD hideHUDForView:self.view];
  284. }
  285. }
  286. #pragma mark- 外部触发自动刷新
  287. - (void)autoDownRefresh
  288. {
  289. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  290. [self autoRefresh];
  291. });
  292. }
  293. #pragma mark 初始化展示框
  294. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  295. {
  296. if(!showView)
  297. {
  298. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  299. [showView setHidden:NO];
  300. [showView setBackgroundColor:NewBgGrayColor];
  301. UIImage *NOimg = [UIImage imageNamed:image];
  302. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  303. [showView addSubview:tempIcon];
  304. tempIcon.sd_layout
  305. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  306. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  307. .widthIs(NOimg.size.width/2.0f)
  308. .heightIs(NOimg.size.height/2.0f);
  309. UILabel *tipLab = [UILabel new];
  310. [showView addSubview:tipLab];
  311. [tipLab setText:text];
  312. [tipLab setTextAlignment:NSTextAlignmentCenter];
  313. [tipLab setTextColor:NewLightGrayColor];
  314. [tipLab setBackgroundColor:NewClearColor];
  315. [tipLab setFont:NewAutoFont(16.0)];
  316. tipLab.sd_layout
  317. .leftEqualToView(showView)
  318. .rightEqualToView(showView)
  319. .topSpaceToView(tempIcon,10)
  320. .heightIs(20.0);
  321. if (buttonText.length>0) {
  322. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  323. [showView addSubview:button];
  324. [button setTitle:buttonText forState:UIControlStateNormal];
  325. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  326. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  327. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  328. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  329. button.sd_layout
  330. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  331. .topSpaceToView(tipLab, 30.0)
  332. .widthIs(width+35)
  333. .heightIs(34);
  334. }
  335. }
  336. [UIView beginAnimations:@"ShowArrow" context:nil];
  337. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  338. [UIView setAnimationDuration:0.25f];
  339. [UIView setAnimationDelegate:self];
  340. [showView setAlpha:1.0f];
  341. [UIView commitAnimations];
  342. }
  343. - (void)hideReloadingview
  344. {
  345. [UIView animateWithDuration:0.25 animations:^{
  346. showView.hidden = YES;
  347. } completion:^(BOOL finished) {
  348. for (id obj in showView.subviews) {
  349. [obj removeFromSuperview];
  350. }
  351. showView = nil;
  352. [showView removeFromSuperview];
  353. }];
  354. }
  355. - (void)didReceiveMemoryWarning {
  356. [super didReceiveMemoryWarning];
  357. // Dispose of any resources that can be recreated.
  358. }
  359. /*
  360. #pragma mark - Navigation
  361. // In a storyboard-based application, you will often want to do a little preparation before navigation
  362. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  363. // Get the new view controller using [segue destinationViewController].
  364. // Pass the selected object to the new view controller.
  365. }
  366. */
  367. @end