OrderdetailViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. //
  2. // OrderdetailViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/24.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "OrderdetailViewController.h"
  9. #import "OrderdetailCell.h"
  10. #import "OrdercontentCell.h"
  11. #import "PaymentinformationCell.h"
  12. #import "OrderdetailModel.h"
  13. #import "BusinesswaterDetaiViewController.h"
  14. #import "CommoditysCell.h"
  15. @interface OrderdetailViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>{
  16. UITableView *newtableView;
  17. NSMutableArray *dataArray;
  18. NSString *money;
  19. }
  20. @end
  21. @implementation OrderdetailViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self setNavTitle:@"订单详情"];
  25. [self dataInitialization];
  26. [self loadsView];
  27. [self networkRequest];
  28. // Do any additional setup after loading the view.
  29. }
  30. - (void)networkRequest{
  31. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  32. NSMutableDictionary *dic = NewMutableDictionaryInit;
  33. [dic safeSetObject:_orderID forKey:@"orderNo"];
  34. [NetworkRequestManager requestGetWithInterfacePrefix:JT_orderDetails parameters:dic onSuccess:^(id requestData) {
  35. [MBProgressHUD hideHUDForView:self.view];
  36. NSLog(@"服务器返回数据 :%@",requestData);
  37. if ([requestData[@"error"] count] !=0) {
  38. for (NSDictionary *dic in requestData[@"error"]) {
  39. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  40. }
  41. }else{
  42. OrderdetailModel *model = [[OrderdetailModel alloc] initWithDictionary:requestData[@"data"] error:nil];
  43. [dataArray addObject:model];
  44. money = model.orderAmount;
  45. [newtableView reloadData];
  46. }
  47. } onFailure:^{
  48. }];
  49. }
  50. #pragma mark - 数据初始化
  51. - (void)dataInitialization{
  52. dataArray = NewMutableArrayInit;
  53. money = @"";
  54. }
  55. #pragma mark ----加载界面
  56. - (void)loadsView{
  57. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  58. newtableView.separatorStyle = NO;
  59. }
  60. #pragma mark-------------------------UITableView------------------------------------
  61. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  62. {
  63. return 1;
  64. }
  65. //返回每段行数
  66. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  67. {
  68. if (dataArray.count>0) {
  69. OrderdetailModel *model = dataArray[0];
  70. NSDictionary *dic = model.operatorActive;
  71. NSString *a2 = [NSString stringWithFormat:@"%@",dic[@"payForFirst"]];
  72. NSString *a3 = [NSString stringWithFormat:@"%@",dic[@"payForLast"]];
  73. if ([a2 isEqualToString:@"1"]||[a3 isEqualToString:@"1"]) {
  74. return 4;
  75. }else{
  76. return 3;
  77. }
  78. }
  79. return 2;
  80. }
  81. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  82. {
  83. static NSString *Cell = @"Cell";
  84. static NSString *Cell1 = @"Cell1";
  85. static NSString *Cell2 = @"Cell2";
  86. static NSString *Cell3 = @"Cell3";
  87. if (indexPath.row == 0) {
  88. OrderdetailCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  89. if (cell == nil) {
  90. cell = [[OrderdetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  91. }
  92. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  93. cell.accessoryType = UITableViewCellAccessoryNone;
  94. if (dataArray.count>0) {
  95. cell.price.delegate = self;
  96. [cell.price addTarget:self action:@selector(textfieldclick:) forControlEvents:UIControlEventEditingChanged];
  97. [cell assignment:dataArray[0]];
  98. }
  99. return cell;
  100. }else if (indexPath.row == 1){
  101. CommoditysCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell3];
  102. if (cell == nil) {
  103. cell = [[CommoditysCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell3];
  104. }
  105. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  106. cell.accessoryType = UITableViewCellAccessoryNone;
  107. if (dataArray.count>0) {
  108. [cell assignment:dataArray[0]];
  109. }
  110. return cell;
  111. }else if (indexPath.row == 2){
  112. OrdercontentCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1];
  113. if (cell == nil) {
  114. cell = [[OrdercontentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1];
  115. }
  116. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  117. cell.accessoryType = UITableViewCellAccessoryNone;
  118. if (dataArray.count>0) {
  119. [cell assignment:dataArray[0]];
  120. }
  121. return cell;
  122. }else if (indexPath.row == 3){
  123. PaymentinformationCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell2];
  124. if (cell == nil) {
  125. cell = [[PaymentinformationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell2];
  126. }
  127. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  128. cell.accessoryType = UITableViewCellAccessoryNone;
  129. // [cell assignment:dataArray[indexPath.row]];
  130. return cell;
  131. }
  132. return [[UITableViewCell alloc] init];
  133. }
  134. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  135. {
  136. if (indexPath.row == 0) {
  137. return fitScreenWidth(130+44);
  138. }else if (indexPath.row == 1){
  139. if (dataArray.count>0) {
  140. OrderdetailModel *model = dataArray[0];
  141. return 20+model.commoditys.count*30;
  142. }else{
  143. return 0;
  144. }
  145. }else if (indexPath.row == 2){
  146. if (dataArray.count>0) {
  147. OrderdetailModel *model = dataArray[0];
  148. CGFloat height = [NewUtils heightforString:model.introduction andWidth:SCREEN_WIDTH-30 fontSize:fitScreenWidth(12)];
  149. return height+30;
  150. }else{
  151. return 0;
  152. }
  153. }else{
  154. return fitScreenWidth(150);
  155. }
  156. }
  157. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  158. }
  159. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  160. return 75+65+54;
  161. }
  162. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  163. return CGFLOAT_MIN;
  164. }
  165. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  166. return [[UIView alloc] init];
  167. }
  168. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  169. if (dataArray.count>0) {
  170. OrderdetailModel *model = dataArray[0];
  171. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 75)];
  172. view.backgroundColor = NewGroupTableViewBackgroundColor;
  173. UIButton *flowingwaterBT = [UIButton new];
  174. flowingwaterBT.frame = CGRectMake(0, 10, SCREEN_WIDTH, 44);
  175. [flowingwaterBT setTitle:@"查看往来流水" forState:UIControlStateNormal];
  176. flowingwaterBT.backgroundColor = NewWhiteColor;
  177. [flowingwaterBT setTitleColor:NewBlackColor forState:UIControlStateNormal];
  178. flowingwaterBT.titleLabel.font = NewFont(fitScreenWidth(14));
  179. flowingwaterBT.titleLabel.textAlignment = NSTextAlignmentLeft;
  180. NewTouchUpInside(flowingwaterBT, flowingwaterBTclick:);
  181. [view addSubview:flowingwaterBT];
  182. UIButton *_cancelintention;
  183. _cancelintention = [UIButton new];
  184. [_cancelintention setTitleColor:NewWhiteColor forState:UIControlStateNormal];
  185. _cancelintention.titleLabel.font = NewFont(16);
  186. _cancelintention.frame = CGRectMake(30, 30+54, SCREEN_WIDTH-60, 45);
  187. [_cancelintention setBackgroundColor:NewButtonColor];
  188. NewTouchUpInside(_cancelintention, _cancelintentionclick:);
  189. ViewRadius(_cancelintention, 5);
  190. [view addSubview:_cancelintention];
  191. UIButton *_cancelintention1111;
  192. _cancelintention1111 = [UIButton new];
  193. [_cancelintention1111 setTitleColor:NewWhiteColor forState:UIControlStateNormal];
  194. _cancelintention1111.titleLabel.font = NewFont(16);
  195. _cancelintention1111.frame = CGRectMake(30, 95+54, SCREEN_WIDTH-60, 45);
  196. [_cancelintention1111 setBackgroundColor:NewButtonColor];
  197. ViewRadius(_cancelintention1111, 5);
  198. NewTouchUpInside(_cancelintention1111, _cancelintentionclick:);
  199. [view addSubview:_cancelintention1111];
  200. NSDictionary *dic = model.operatorActive;
  201. NSString *a = [NSString stringWithFormat:@"%@",dic[@"refuseIntention"]];
  202. NSString *a1 = [NSString stringWithFormat:@"%@",dic[@"applyForCancel"]];
  203. NSString *a2 = [NSString stringWithFormat:@"%@",dic[@"payForFirst"]];
  204. NSString *a3 = [NSString stringWithFormat:@"%@",dic[@"payForLast"]];
  205. NSString *a4 = [NSString stringWithFormat:@"%@",dic[@"applyForWithdraw"]];
  206. NSString *a5 = [NSString stringWithFormat:@"%@",dic[@"confirmPayForLast"]];
  207. NSString *a6 = [NSString stringWithFormat:@"%@",dic[@"confirmRefund"]];
  208. NSString *a7 = [NSString stringWithFormat:@"%@",dic[@"confirmWithdraw"]];
  209. NSString *a8 = [NSString stringWithFormat:@"%@",dic[@"confirmIntention"]];
  210. NSString *a9 = [NSString stringWithFormat:@"%@",dic[@"confirmPayForFirst"]];
  211. NSArray *array = @[a.length>0?a:@"0",
  212. a1.length>0?a1:@"0",
  213. a2.length>0?a2:@"0",
  214. a3.length>0?a3:@"0",
  215. a4.length>0?a4:@"0",
  216. a5.length>0?a5:@"0",
  217. a6.length>0?a6:@"0",
  218. a7.length>0?a7:@"0",
  219. a8.length>0?a8:@"0",
  220. a9.length>0?a9:@"0"];
  221. NSMutableArray *dataArray = [NSMutableArray array];
  222. for (int i=0; i<array.count; i++) {
  223. NSString *state = array[i];
  224. if ([state isEqualToString:@"1"]) {
  225. switch (i) {
  226. case 0:
  227. [dataArray addObject:@{@"title":@"拒绝意向",@"state":@"1"}];
  228. break;
  229. case 1:
  230. [dataArray addObject:@{@"title":@"取消订单",@"state":@"1"}];
  231. break;
  232. case 2:
  233. [dataArray addObject:@{@"title":@"支付首付",@"state":@"1"}];
  234. break;
  235. case 3:
  236. [dataArray addObject:@{@"title":@"支付尾款",@"state":@"1"}];
  237. break;
  238. case 4:
  239. [dataArray addObject:@{@"title":@"提现",@"state":@"1"}];
  240. break;
  241. case 5:
  242. [dataArray addObject:@{@"title":@"确认支付尾款",@"state":@"1"}];
  243. break;
  244. case 6:
  245. [dataArray addObject:@{@"title":@"确认退款",@"state":@"1"}];
  246. break;
  247. case 7:
  248. [dataArray addObject:@{@"title":@"确认提现",@"state":@"1"}];
  249. break;
  250. case 8:
  251. [dataArray addObject:@{@"title":@"确认意向",@"state":@"1"}];
  252. break;
  253. case 9:
  254. [dataArray addObject:@{@"title":@"确认支付首付",@"state":@"1"}];
  255. break;
  256. default:
  257. break;
  258. }
  259. }
  260. }
  261. if (dataArray.count==0||dataArray.count>2) {
  262. _cancelintention.hidden = YES;
  263. _cancelintention1111.hidden = YES;
  264. }else if (dataArray.count==1) {
  265. [_cancelintention setTitle:dataArray[0][@"title"] forState:UIControlStateNormal];
  266. _cancelintention.hidden = NO;
  267. _cancelintention1111.hidden = YES;
  268. }else if (dataArray.count==2) {
  269. [_cancelintention setTitle:dataArray[0][@"title"] forState:UIControlStateNormal];
  270. [_cancelintention1111 setTitle:dataArray[1][@"title"] forState:UIControlStateNormal];
  271. _cancelintention.hidden = NO;
  272. _cancelintention1111.hidden = NO;
  273. }
  274. return view;
  275. }
  276. return [[UIView alloc] init];
  277. }
  278. #pragma mark ------操作按钮网络请求-----
  279. - (void)_cancelintentionclick:(UIButton*)button{
  280. NSString *str = [NSString stringWithFormat:@"是否%@?",button.titleLabel.text];
  281. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:(UIAlertControllerStyleAlert)];
  282. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
  283. [self faafa:button];
  284. }];
  285. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
  286. //NSLog(@"取消");
  287. }];
  288. [alertController addAction:okAction];
  289. [alertController addAction:cancelAction];
  290. [self presentViewController:alertController animated:YES completion:nil];
  291. }
  292. - (void)faafa:(UIButton *)button{
  293. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  294. OrderdetailModel *model = dataArray[0];
  295. /*
  296. 拒绝意向 和 确认意向 调取 /api/user/order/confirmIntention
  297. */
  298. NSMutableDictionary *dic = NewMutableDictionaryInit;
  299. NSString *url;
  300. if ([button.titleLabel.text isEqualToString:@"取消订单"]) {
  301. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  302. url = JT_applyForCancel;//取消订单
  303. }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){
  304. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  305. [dic safeSetObject:money forKey:@"fundAmount"];
  306. [dic safeSetObject:@"" forKey:@"remarks"];
  307. url = JT_payForFirst;//支付首付
  308. }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){
  309. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  310. [dic safeSetObject:money forKey:@"fundAmount"];
  311. [dic safeSetObject:@"" forKey:@"remarks"];
  312. url = JT_payForLast;//支付尾款
  313. }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]||[button.titleLabel.text isEqualToString:@"确认意向"]){
  314. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  315. if ([button.titleLabel.text isEqualToString:@"拒绝意向"]) {
  316. [dic safeSetObject:@"true" forKey:@"confirm"];
  317. }else{
  318. [dic safeSetObject:@"false" forKey:@"confirm"];
  319. }
  320. url = JT_confirmIntention;
  321. }else if ([button.titleLabel.text isEqualToString:@"提现"]){
  322. [dic safeSetObject:model.orderNo forKey:@"orderNo"];
  323. url = JT_applyForWithdraw;
  324. }
  325. [NetworkRequestManager requestPostWithInterfacePrefix:url parameters:dic onSuccess:^(id requestData) {
  326. [MBProgressHUD hideHUDForView:self.view];
  327. if ([requestData[@"error"] count] !=0) {
  328. for (NSDictionary *dic in requestData[@"error"]) {
  329. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  330. }
  331. }else{
  332. if ([button.titleLabel.text isEqualToString:@"取消订单"]) {
  333. [MBProgressHUD showSuccess:@"取消订单成功" toView:self.view];
  334. }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){
  335. [MBProgressHUD showSuccess:@"支付首付成功" toView:self.view];
  336. }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){
  337. [MBProgressHUD showSuccess:@"支付尾款成功" toView:self.view];
  338. }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]){
  339. [MBProgressHUD showSuccess:@"拒绝意向成功" toView:self.view];
  340. }else if ([button.titleLabel.text isEqualToString:@"确认意向"]){
  341. [MBProgressHUD showSuccess:@"确认意向成功" toView:self.view];
  342. }else if ([button.titleLabel.text isEqualToString:@"提现"]){
  343. [MBProgressHUD showSuccess:@"提现成功" toView:self.view];
  344. }
  345. //其它通过名门项目协议唤醒APP
  346. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  347. NewPopViewController;
  348. });
  349. }
  350. } onFailure:^{
  351. [MBProgressHUD hideHUDForView:self.view];
  352. }];
  353. }
  354. #pragma mark -------查看业务流水--------
  355. - (void)flowingwaterBTclick:(UIButton *)sender {
  356. NSLog(@"%@",@"查看业务流水");
  357. BusinesswaterDetaiViewController *vc = [[BusinesswaterDetaiViewController alloc] init];
  358. vc.orderID = _orderID;
  359. NewPushViewController(vc);
  360. }
  361. - (void)textfieldclick:(UITextField *)textField {
  362. money = textField.text;
  363. NSLog(@"%@",textField.text);
  364. }
  365. - (void)didReceiveMemoryWarning {
  366. [super didReceiveMemoryWarning];
  367. // Dispose of any resources that can be recreated.
  368. }
  369. /*
  370. #pragma mark - Navigation
  371. // In a storyboard-based application, you will often want to do a little preparation before navigation
  372. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  373. // Get the new view controller using [segue destinationViewController].
  374. // Pass the selected object to the new view controller.
  375. }
  376. */
  377. @end