123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // ASOrderListSubController.m
- // Asteria
- //
- // Created by iOS on 2024/5/13.
- //
- #import "ASOrderListSubController.h"
- #import "ASOrderListCell.h"
- #import "ASOrderListViewModel.h"
- #import "ASOrderDetailsViewController.h"
- @interface ASOrderListSubController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableV;
- @property (nonatomic, strong) NSMutableArray<KWMineHomeOrderModel *> *orderArr;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic, strong) ASOrderListViewModel *vm;
- @property (nonatomic, assign) NSInteger addCartCount;
- @end
- @implementation ASOrderListSubController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.customNavBar.hidden = true;
- self.statusBgV.hidden = true;
- self.vm = [ASOrderListViewModel new];
- self.page = 1;
- [self getOrderData];
- [self loadSubV];
- [self viewAction];
- self.view.backgroundColor = _F8F8F8;
-
-
- }
- - (void)refreshListData {
- [self.tableV.mj_header beginRefreshing];
- }
- - (void)checkEmpty {
- if (self.orderArr.count == 0) {
- [self showEmptyV: self.tableV];
- } else {
- [self hiddenEmpty];
- }
- }
- - (void)viewAction {
- __weak typeof(self) weakSelf = self;
- self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- weakSelf.page = 1;
- [weakSelf getOrderData];
- }];
- self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- weakSelf.page += 1;
- [weakSelf getOrderData];
- }];
- }
- // MARK: - net
- - (void)getOrderData {
- [MBProgressHUD showHUDAddedTo:self.view animated:true];
- __weak typeof(self) weakSelf = self;
- [self.vm getOrderNet:self.status page:self.page com:^(NSArray<KWMineHomeOrderModel *> * _Nonnull arr) {
- [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
- [weakSelf.tableV.mj_header endRefreshing];
- if (arr.count < 10) {
- [weakSelf.tableV.mj_footer endRefreshingWithNoMoreData];
- } else {
- [weakSelf.tableV.mj_footer endRefreshing];
- }
- if (weakSelf.page == 1) {
- weakSelf.orderArr = [NSMutableArray arrayWithArray:arr];
- } else {
- [weakSelf.orderArr addObjectsFromArray:arr];
- }
- [weakSelf.tableV reloadData];
- [weakSelf checkEmpty];
- }];
- }
- // MARK: - loadSubv
- - (void)loadSubV {
- [self.view addSubview:self.tableV];
- [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
- }
- // MARK: - subvs
- - (UITableView *)tableV {
- if (!_tableV) {
- UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- [v registerClass:[ASOrderListCell class] forCellReuseIdentifier:@"ASOrderListCell"];
- v.delegate = self;
- v.dataSource = self;
- [v baseSet];
- v.backgroundColor = _F8F8F8;
-
- _tableV = v;
- }
- return _tableV;
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.orderArr.count;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- ASOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASOrderListCell" forIndexPath:indexPath];
- if (self.orderArr.count <= indexPath.row) {
- return cell;
- }
- KWMineHomeOrderModel *m = self.orderArr[indexPath.row];
- [cell setData:m];
- @weakify(self);
- [cell setViewOrderCall:^(NSInteger type, KWMineHomeOrderModel *model){
- @strongify(self)
- // type 0: view Order 1: trackOrder 2: reorder 3: pay now
- if (![ASUserInfoManager.shared isLogin]) {
- [self popAndToLogin];
- return;
- }
- // 查看订单
-
- if (type == 0) {//订单详情
- ASOrderDetailsViewController *orderDetailsVC = [[ASOrderDetailsViewController alloc] init];
- orderDetailsVC.orderId = model.entity_id;
- [self.navigationController pushViewController:orderDetailsVC animated:YES];
- } else if (type == 1) {//Track Order
- ASOrderDetailsViewController *orderDetailsVC = [[ASOrderDetailsViewController alloc] init];
- orderDetailsVC.orderId = model.entity_id;
- [self.navigationController pushViewController:orderDetailsVC animated:YES];
- } else if (type == 2) {
- [self reorderClickWithData:model];
- }
-
-
-
- // KWM_OrderViewC *vc = [[KWM_OrderViewC alloc]init];
- // vc.order_id = m.orderId;
- // [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
- }];
- return cell;
-
- }
- - (void)reorderClickWithData:(KWMineHomeOrderModel *)orderModel {
-
- NSMutableArray *itemOptionArr = [[NSMutableArray alloc] initWithCapacity:1];
-
- for (KWMineOrderProInfoModel *proModel in orderModel.items) {
-
- if (![proModel.name hasPrefix:@"FREE"]) {
- if (AS_Array_valid(proModel.custom_options)) {
-
- NSMutableDictionary *optionParam = [NSMutableDictionary dictionary];
- for (NSDictionary *optionsDic in proModel.custom_options) {
- [optionParam setValue:optionsDic[@"option_value"] forKey:[NSString stringWithFormat:@"options[%@]", optionsDic[@"option_id"]]];
- }
- [optionParam setValue:proModel.product_id forKey:@"product"];
- [optionParam setValue:@"1" forKey:@"qty"];
-
- [itemOptionArr addObject:optionParam];
- }
- }
- }
-
- self.addCartCount = itemOptionArr.count;
- if (self.addCartCount == 0) {
- return;
- }
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
- for (NSDictionary *param in itemOptionArr) {
- [self requestAddCartWithParams:param];
- }
- }
- - (void)requestAddCartWithParams:(NSDictionary *)params {
- K_WEAK_SELF;
- [self.vm orderGoodsAddCartWithParam:params complete:^(BOOL isSuccess, NSString * _Nonnull msg) {
-
- K_STRONG_SELF;
- self.addCartCount--;
-
- if (self.addCartCount == 0) {
- [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
- [Fuction_Tool popToRootViewController:2];
- }];
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }
- }];
- }
- @end
|