PurchaseintentionViewController.m 16 KB

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