XYSkillOrderListViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // XYSkillOrderListViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/11/4.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYSkillOrderListViewController.h"
  9. #import "XYSkillOrderListViewModel.h"
  10. #import "XYSkillOrderListCellModel.h"
  11. #import "XYSkillOrderListTableViewCell.h"
  12. #import "XYSkillOrderDetailsViewController.h"
  13. #import "XYFamilyAPIManager.h"
  14. #import "XYRechargeItemsViewController.h"
  15. @interface XYSkillOrderListViewController ()<XYSkillOrderListTableViewCellDelegate>
  16. @property (nonatomic, strong) XYSkillOrderListViewModel *viewModel;
  17. @end
  18. @implementation XYSkillOrderListViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. }
  23. #pragma mark — Override
  24. - (void)bindViewModel {
  25. self.viewModel = XYSkillOrderListViewModel.new;
  26. self.viewModel.orderType = self.orderType;
  27. self.viewModel.orderStatus = self.orderStatus;
  28. }
  29. - (UIEdgeInsets)contentInset {
  30. return UIEdgeInsetsMake(0, 0, NAVGATION_HEIGHT + 48.0f, 0);
  31. }
  32. - (void)tableViewDidTriggerHeaderRefresh {
  33. self.viewModel.pullDown = YES;
  34. [self.viewModel loadData:^(id _Nullable responseModel) {
  35. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  36. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  37. } failure:^(ZYLNetworkError * _Nullable error) {
  38. [self tableViewDidFinishTriggerHeader:YES reload:NO];
  39. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  40. }];
  41. }
  42. - (void)tableViewDidTriggerFooterRefresh {
  43. [super tableViewDidTriggerFooterRefresh];
  44. }
  45. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  46. return [XYSkillOrderListTableViewCell cellWithTableView:tableView];
  47. }
  48. - (void)configureCell:(XYSkillOrderListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  49. [cell configureModel:object];
  50. [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
  51. cell.delegate = self;
  52. }
  53. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  54. XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
  55. return model.cellHeight;
  56. }
  57. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  58. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  59. XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
  60. XYSkillOrderDetailsViewController *controller = XYSkillOrderDetailsViewController.new;
  61. controller.orderId = [model.orderId copy];
  62. [self.navigationController pushViewController:controller animated:YES];
  63. }
  64. #pragma mark — XYSkillOrderListTableViewCellDelegate
  65. - (void)cellRightButtonClickAtIndexPath:(NSIndexPath *)indexPath {
  66. XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
  67. if (model.listType == 1) {
  68. // 接单
  69. if (model.orderStatus == XYPeiPeiOrderStatusWaitReceive) {
  70. // 待接单 接单
  71. [[XYFamilyAPIManager new] receiveOrderWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. [SVProgressHUD showSuccessWithStatus:@"接单成功"];
  74. [self tableViewDidTriggerHeaderRefresh];
  75. });
  76. } failureHandler:^(ZYLNetworkError *error) {
  77. [SVProgressHUD showInfoWithStatus:error.domain];
  78. }];
  79. }else if (model.orderStatus == XYPeiPeiOrderStatusWaitService) {
  80. // 待服务 开始服务
  81. [[XYFamilyAPIManager new] startServiceWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  82. dispatch_async(dispatch_get_main_queue(), ^{
  83. [self tableViewDidTriggerHeaderRefresh];
  84. });
  85. } failureHandler:^(ZYLNetworkError *error) {
  86. [SVProgressHUD showInfoWithStatus:error.domain];
  87. }];
  88. }
  89. }else {
  90. // 点单
  91. if (model.payStatus == 11) {
  92. // 待支付 立即付款
  93. [[XYFamilyAPIManager new] payOrderWithOrderWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  94. dispatch_async(dispatch_get_main_queue(), ^{
  95. [self tableViewDidTriggerHeaderRefresh];
  96. });
  97. } failureHandler:^(ZYLNetworkError *error) {
  98. if ([error.codeStr isEqualToString:@"OPERATION_FAILED"]) {
  99. // 余额不足
  100. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"温馨提示") message:kLocalizedString(@"账户余额不足,请前去充值") sure:kLocalizedString(@"去充值") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  101. if ([title isEqualToString:kLocalizedString(@"去充值")]) {
  102. [self.navigationController pushViewController:XYRechargeItemsViewController.new animated:YES];
  103. }
  104. }];
  105. [al show];
  106. }else {
  107. [SVProgressHUD showInfoWithStatus:error.domain];
  108. }
  109. }];
  110. }else {
  111. if (model.orderStatus == XYPeiPeiOrderStatusInService) {
  112. // 服务中 服务完成
  113. [[XYFamilyAPIManager new] confirmServiceWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  114. dispatch_async(dispatch_get_main_queue(), ^{
  115. [self tableViewDidTriggerHeaderRefresh];
  116. });
  117. } failureHandler:^(ZYLNetworkError *error) {
  118. [SVProgressHUD showInfoWithStatus:error.domain];
  119. }];
  120. }
  121. }
  122. }
  123. }
  124. - (void)cellLeftButtonClickAtIndexPath:(NSIndexPath *)indexPath {
  125. XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
  126. if (model.listType == 1) {
  127. // 接单
  128. if (model.orderStatus == XYPeiPeiOrderStatusWaitReceive) {
  129. // 待接单 拒单
  130. [[XYFamilyAPIManager new] rejectOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  131. [self tableViewDidTriggerHeaderRefresh];
  132. } failureHandler:^(ZYLNetworkError *error) {
  133. [SVProgressHUD showInfoWithStatus:error.domain];
  134. }];
  135. }
  136. }else {
  137. // 点单
  138. if (model.payStatus == 11) {
  139. // 待支付 取消订单
  140. [[XYFamilyAPIManager new] cancelPayWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
  141. [self tableViewDidTriggerHeaderRefresh];
  142. } failureHandler:^(ZYLNetworkError *error) {
  143. [SVProgressHUD showInfoWithStatus:error.domain];
  144. }];
  145. }
  146. }
  147. }
  148. - (void)cellRefreshOrderStatusClickAtIndexPath:(NSIndexPath *)indexPath {
  149. [self tableViewDidTriggerHeaderRefresh];
  150. }
  151. #pragma mark — JXCategoryListContentViewDelegate
  152. /**
  153. 如果列表是VC,就返回VC.view
  154. 如果列表是View,就返回View自己
  155. @return 返回列表视图
  156. */
  157. - (UIView *)listView {
  158. return self.view;
  159. }
  160. @end