123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // XYSkillOrderListViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/11/4.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYSkillOrderListViewController.h"
- #import "XYSkillOrderListViewModel.h"
- #import "XYSkillOrderListCellModel.h"
- #import "XYSkillOrderListTableViewCell.h"
- #import "XYSkillOrderDetailsViewController.h"
- #import "XYFamilyAPIManager.h"
- #import "XYRechargeItemsViewController.h"
- @interface XYSkillOrderListViewController ()<XYSkillOrderListTableViewCellDelegate>
- @property (nonatomic, strong) XYSkillOrderListViewModel *viewModel;
- @end
- @implementation XYSkillOrderListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- #pragma mark — Override
- - (void)bindViewModel {
- self.viewModel = XYSkillOrderListViewModel.new;
- self.viewModel.orderType = self.orderType;
- self.viewModel.orderStatus = self.orderStatus;
- }
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, NAVGATION_HEIGHT + 48.0f, 0);
- }
- - (void)tableViewDidTriggerHeaderRefresh {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id _Nullable responseModel) {
-
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- } failure:^(ZYLNetworkError * _Nullable error) {
- [self tableViewDidFinishTriggerHeader:YES reload:NO];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- }];
- }
- - (void)tableViewDidTriggerFooterRefresh {
- [super tableViewDidTriggerFooterRefresh];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- return [XYSkillOrderListTableViewCell cellWithTableView:tableView];
- }
- - (void)configureCell:(XYSkillOrderListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell configureModel:object];
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
- cell.delegate = self;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
- return model.cellHeight;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
-
- XYSkillOrderDetailsViewController *controller = XYSkillOrderDetailsViewController.new;
- controller.orderId = [model.orderId copy];
- [self.navigationController pushViewController:controller animated:YES];
- }
- #pragma mark — XYSkillOrderListTableViewCellDelegate
- - (void)cellRightButtonClickAtIndexPath:(NSIndexPath *)indexPath {
- XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
- if (model.listType == 1) {
- // 接单
- if (model.orderStatus == XYPeiPeiOrderStatusWaitReceive) {
- // 待接单 接单
- [[XYFamilyAPIManager new] receiveOrderWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD showSuccessWithStatus:@"接单成功"];
- [self tableViewDidTriggerHeaderRefresh];
- });
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
-
- }else if (model.orderStatus == XYPeiPeiOrderStatusWaitService) {
- // 待服务 开始服务
- [[XYFamilyAPIManager new] startServiceWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self tableViewDidTriggerHeaderRefresh];
- });
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- }else {
- // 点单
- if (model.payStatus == 11) {
- // 待支付 立即付款
- [[XYFamilyAPIManager new] payOrderWithOrderWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self tableViewDidTriggerHeaderRefresh];
- });
- } failureHandler:^(ZYLNetworkError *error) {
- if ([error.codeStr isEqualToString:@"OPERATION_FAILED"]) {
- // 余额不足
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"温馨提示") message:kLocalizedString(@"账户余额不足,请前去充值") sure:kLocalizedString(@"去充值") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"去充值")]) {
- [self.navigationController pushViewController:XYRechargeItemsViewController.new animated:YES];
- }
- }];
- [al show];
- }else {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }
- }];
- }else {
- if (model.orderStatus == XYPeiPeiOrderStatusInService) {
- // 服务中 服务完成
- [[XYFamilyAPIManager new] confirmServiceWithOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self tableViewDidTriggerHeaderRefresh];
- });
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- }
- }
- }
- - (void)cellLeftButtonClickAtIndexPath:(NSIndexPath *)indexPath {
- XYSkillOrderListCellModel *model = self.viewModel.dataSource[indexPath.row];
- if (model.listType == 1) {
- // 接单
- if (model.orderStatus == XYPeiPeiOrderStatusWaitReceive) {
- // 待接单 拒单
- [[XYFamilyAPIManager new] rejectOrderWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
-
- [self tableViewDidTriggerHeaderRefresh];
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- }else {
- // 点单
- if (model.payStatus == 11) {
- // 待支付 取消订单
- [[XYFamilyAPIManager new] cancelPayWithOrderId:model.orderId successHandler:^(ZYLResponseModel *responseModel) {
-
- [self tableViewDidTriggerHeaderRefresh];
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- }
- }
- - (void)cellRefreshOrderStatusClickAtIndexPath:(NSIndexPath *)indexPath {
- [self tableViewDidTriggerHeaderRefresh];
- }
- #pragma mark — JXCategoryListContentViewDelegate
- /**
- 如果列表是VC,就返回VC.view
- 如果列表是View,就返回View自己
- @return 返回列表视图
- */
- - (UIView *)listView {
- return self.view;
- }
- @end
|