OrderListVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. //
  2. // OrderListVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/2/6.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "OrderListVC.h"
  9. #import "SPPageMenu.h"
  10. #import "OrderListCell.h"
  11. #import "OrderModel.h"
  12. #import "OrderDetailVC.h"
  13. #import "PayOrderView.h"
  14. #import "PublishEvaluateVC.h"
  15. #import "AppendEvaluateVC.h"
  16. #import "BuyerRefundDetailVC.h"
  17. @interface OrderListVC ()<SPPageMenuDelegate,UITableViewDataSource, UITableViewDelegate,orderCellBtnDelegate>
  18. {
  19. int pageIndex;
  20. }
  21. @property(nonatomic, strong)NSArray *titles;
  22. @property(nonatomic, strong)NSArray *typeArr;
  23. @property (nonatomic, strong) SPPageMenu *pageMenu;
  24. @property (nonatomic, strong)UITableView *orderTable;
  25. @property(nonatomic, strong)NSString *orderType;
  26. @property (nonatomic, strong)NSMutableArray *dataArr;
  27. @property (nonatomic, strong)NSArray *models;
  28. @property (nonatomic, strong)PayOrderView *payView;
  29. @end
  30. @implementation OrderListVC
  31. -(NSArray *)models{
  32. NSMutableArray *array = [NSMutableArray array];
  33. for (NSDictionary *dic in self.dataArr) {
  34. OrderModel *model = [OrderModel modelWithDic:dic];
  35. [array addObject:model];
  36. }
  37. _models = array;
  38. return _models;
  39. }
  40. -(void)requestOrderData{
  41. YBWeakSelf;
  42. NSString *url = [purl stringByAppendingFormat:@"?service=Buyer.getGoodsOrderList"];
  43. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  44. NSString *sign = [PublicObj sortString:signdic];
  45. NSDictionary *dic = @{
  46. @"uid":[Config getOwnID],
  47. @"token":[Config getOwnToken],
  48. @"type":self.orderType,
  49. @"p":@(pageIndex),
  50. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  51. @"sign":sign
  52. };
  53. [YBNetworking postWithUrl:@"Buyer.getGoodsOrderList" Dic:dic Suc:^(int code, id info, NSString *msg) {
  54. [self.orderTable.mj_header endRefreshing];
  55. [self.orderTable.mj_footer endRefreshing];
  56. if (code ==0) {
  57. NSArray *infos = info;
  58. if (pageIndex == 1) {
  59. [self.dataArr removeAllObjects];
  60. if (infos.count < 1) {
  61. [PublicView showImgNoData:self.orderTable name:@"shop_无数据" text:YZMsg(@"你还没有相关订单")];
  62. [self.orderTable reloadData];
  63. return ;
  64. }else{
  65. [PublicView hiddenImgNoData:self.orderTable];
  66. }
  67. }
  68. [self.dataArr addObjectsFromArray:infos];
  69. [self.orderTable reloadData];
  70. }else{
  71. [MBProgressHUD showError:msg];
  72. }
  73. } Fail:^(id fail) {
  74. [self.orderTable.mj_header endRefreshing];
  75. [self.orderTable.mj_footer endRefreshing];
  76. }];
  77. }
  78. -(void)viewWillAppear:(BOOL)animated
  79. {
  80. [super viewWillAppear:YES];
  81. [self.orderTable.mj_header beginRefreshing];
  82. }
  83. - (UIStatusBarStyle)preferredStatusBarStyle {
  84. if (@available(iOS 13.0,*)) {
  85. return UIStatusBarStyleDarkContent;
  86. }
  87. return UIStatusBarStyleDefault;
  88. }
  89. - (void)viewDidLoad {
  90. [super viewDidLoad];
  91. self.titleL.text = YZMsg(@"我的订单");
  92. self.view.backgroundColor = UIColor.whiteColor;
  93. self.subNavi.backgroundColor = UIColor.whiteColor;
  94. self.titleL.textColor = UIColor.blackColor;
  95. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  96. self.naviLine.hidden = NO;
  97. self.naviLine.backgroundColor = RGB(245, 245, 245);
  98. _titles = @[YZMsg(@"全部"),YZMsg(@"待付款"),YZMsg(@"待发货"),YZMsg(@"待收货"),YZMsg(@"待评价"),YZMsg(@"退款")];
  99. _typeArr = @[@"all",@"wait_payment",@"wait_shipment",@"wait_receive",@"wait_evaluate",@"refund"];
  100. self.orderType = _typeArr[self.selectIndex];
  101. pageIndex = 1;
  102. self.dataArr = [NSMutableArray array];
  103. _pageMenu = [SPPageMenu pageMenuWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, 40) trackerStyle:SPPageMenuTrackerStyleLineAttachment];
  104. _pageMenu.tracker.backgroundColor = Pink_Cor;
  105. [_pageMenu setItems:self.titles selectedItemIndex:self.selectIndex];
  106. _pageMenu.delegate = self;
  107. _pageMenu.backgroundColor = UIColor.whiteColor;
  108. _pageMenu.dividingLine.hidden = YES;
  109. _pageMenu.selectedItemTitleColor = [UIColor blackColor];
  110. _pageMenu.unSelectedItemTitleColor = [UIColor grayColor];
  111. _pageMenu.selectedItemTitleFont = [UIFont systemFontOfSize:14];
  112. _pageMenu.unSelectedItemTitleFont = [UIFont systemFontOfSize:14];
  113. _pageMenu.permutationWay = SPPageMenuPermutationWayScrollAdaptContent;
  114. [self.view addSubview:_pageMenu];
  115. [self.view addSubview:self.orderTable];
  116. [self requestOrderData];
  117. }
  118. - (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index {
  119. NSLog(@"sssssss::::%zd",index);
  120. pageIndex = 1;
  121. self.orderType = _typeArr[index];
  122. [self requestOrderData];
  123. }
  124. -(UITableView *)orderTable{
  125. if (!_orderTable) {
  126. _orderTable = [[UITableView alloc]initWithFrame:CGRectMake(0, self.pageMenu.bottom, _window_width, _window_height-64-statusbarHeight-40) style:UITableViewStylePlain];
  127. _orderTable.delegate = self;
  128. _orderTable.dataSource = self;
  129. _orderTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  130. _orderTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  131. pageIndex = 1;
  132. [self requestOrderData];
  133. }];
  134. _orderTable.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
  135. pageIndex ++;
  136. [self requestOrderData];
  137. }];
  138. _orderTable.backgroundColor = UIColor.whiteColor;
  139. }
  140. return _orderTable;
  141. }
  142. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  143. {
  144. return 1;
  145. }
  146. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  147. {
  148. return self.models.count;
  149. }
  150. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  151. {
  152. OrderModel *modelsss =self.models[indexPath.row];
  153. if ([modelsss.status isEqual:@"1"]) {
  154. return 190;
  155. }else{
  156. return 230;
  157. }
  158. }
  159. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  160. {
  161. OrderModel *models =self.models[indexPath.row];
  162. OrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderListCell"];
  163. //['status'] 订单状态 -1 已关闭 0 待付款 1 待发货 2 待收货 3 待评价 4 已评价 5 退款
  164. //['is_append_evaluate'] 订单是否可追加评价 1 可以 0 不可以
  165. //['refund_status'] 退款处理结果 -1 失败 0 处理中 1 成功
  166. if ([models.status isEqual:@"0"]) {
  167. if (!cell) {
  168. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:0];
  169. }
  170. }else if ([models.status isEqual:@"-1"]){
  171. if (!cell) {
  172. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:5];
  173. }
  174. }else if ([models.status isEqual:@"1"]){
  175. if (!cell) {
  176. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:1];
  177. }
  178. }else if ([models.status isEqual:@"2"]){
  179. if (!cell) {
  180. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:2];
  181. }
  182. }else if ([models.status isEqual:@"3"]){
  183. if (!cell) {
  184. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:3];
  185. }
  186. }else if ([models.status isEqual:@"4"] &&[models.is_append_evaluate isEqual:@"1"]){
  187. if (!cell) {
  188. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:7];
  189. }
  190. }else if ([models.status isEqual:@"4"] &&[models.is_append_evaluate isEqual:@"0"]){
  191. if (!cell) {
  192. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:8];
  193. }
  194. }else if ([models.status isEqual:@"5"] && ![models.refund_status isEqual:@"0"]){
  195. if (!cell) {
  196. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:4];
  197. }
  198. }else if ([models.status isEqual:@"5"] && [models.refund_status isEqual:@"0"]){
  199. if (!cell) {
  200. cell = [[[NSBundle mainBundle]loadNibNamed:@"OrderListCell" owner:nil options:nil]objectAtIndex:6];
  201. }
  202. }
  203. cell.backgroundColor = UIColor.whiteColor;
  204. cell.delegate = self;
  205. cell.model = models;
  206. return cell;
  207. }
  208. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  209. {
  210. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  211. OrderModel *models =self.models[indexPath.row];
  212. if ([models.status isEqual:@"5"]) {
  213. BuyerRefundDetailVC *refund = [[BuyerRefundDetailVC alloc]init];
  214. refund.orderId = models.idStr;
  215. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:refund animated:YES];
  216. }else{
  217. OrderDetailVC *detail = [[OrderDetailVC alloc]init];
  218. detail.orderId =models.idStr;
  219. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:detail animated:YES];
  220. }
  221. }
  222. -(void)btnClickWithTitle:(NSString *)titls AndModel:(OrderModel *)models
  223. {
  224. if ([titls isEqual:YZMsg(@"删除订单")]) {
  225. UIAlertController *deleteAlert = [UIAlertController alertControllerWithTitle:YZMsg(@"确定删除订单?") message:nil preferredStyle:UIAlertControllerStyleAlert];
  226. UIAlertAction *cancle = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  227. }];
  228. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  229. [self deleteOrder:models];
  230. }];
  231. [deleteAlert addAction:cancle];
  232. [deleteAlert addAction:sureAction];
  233. [cancle setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
  234. [sureAction setValue:Pink_Cor forKey:@"titleTextColor"];
  235. [self presentViewController:deleteAlert animated:YES completion:nil];
  236. }else if ([titls isEqual:YZMsg(@"取消订单")]){
  237. UIAlertController *cancelAlert = [UIAlertController alertControllerWithTitle:YZMsg(@"确定取消订单?") message:nil preferredStyle:UIAlertControllerStyleAlert];
  238. UIAlertAction *cancle = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  239. }];
  240. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  241. [self cancelOrder:models];
  242. }];
  243. [cancelAlert addAction:cancle];
  244. [cancelAlert addAction:sureAction];
  245. [cancle setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
  246. [sureAction setValue:Pink_Cor forKey:@"titleTextColor"];
  247. [self presentViewController:cancelAlert animated:YES completion:nil];
  248. }else if ([titls isEqual:YZMsg(@"付款")]){
  249. [self showPayView:models];
  250. }else if ([titls isEqual:YZMsg(@"查看物流")]){
  251. [self lookExpress:models];
  252. }else if ([titls isEqual:YZMsg(@"确认收货")]){
  253. UIAlertController *cancelAlert = [UIAlertController alertControllerWithTitle:YZMsg(@"确定已收到商品?") message:nil preferredStyle:UIAlertControllerStyleAlert];
  254. UIAlertAction *cancle = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  255. }];
  256. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  257. [self receiveGoods:models];
  258. }];
  259. [cancelAlert addAction:cancle];
  260. [cancelAlert addAction:sureAction];
  261. [cancle setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
  262. [sureAction setValue:Pink_Cor forKey:@"titleTextColor"];
  263. [self presentViewController:cancelAlert animated:YES completion:nil];
  264. }else if ([titls isEqual:YZMsg(@"评价")]){
  265. [self evaluate:models];
  266. }else if ([titls isEqual:YZMsg(@"追加评价")]){
  267. [self appendEvaluate:models];
  268. }else if ([titls isEqual:YZMsg(@"退款详情")]){
  269. // [self appendEvaluate:models];
  270. [self refundOrderDetail:models];
  271. }
  272. }
  273. #pragma mark------退款----------
  274. -(void)refundOrderDetail:(OrderModel *)model{
  275. BuyerRefundDetailVC *refund = [[BuyerRefundDetailVC alloc]init];
  276. refund.orderId = model.idStr;
  277. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:refund animated:YES];
  278. }
  279. #pragma mark ---删除订单---------
  280. -(void)deleteOrder:(OrderModel *)model{
  281. NSString *url = [purl stringByAppendingFormat:@"?service=Buyer.delGoodsOrder"];
  282. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  283. NSString *sign = [PublicObj sortString:signdic];
  284. NSDictionary *dic = @{
  285. @"uid":[Config getOwnID],
  286. @"token":[Config getOwnToken],
  287. @"orderid":model.idStr,
  288. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  289. @"sign":sign
  290. };
  291. [YBNetworking postWithUrl:@"Buyer.delGoodsOrder" Dic:dic Suc:^(int code, id info, NSString *msg) {
  292. if (code ==0) {
  293. [MBProgressHUD showError:msg];
  294. pageIndex = 1;
  295. [self requestOrderData];
  296. }else{
  297. [MBProgressHUD showError:msg];
  298. }
  299. } Fail:^(id fail) {
  300. }];
  301. }
  302. #pragma mark-----取消订单--------
  303. -(void)cancelOrder:(OrderModel *)model{
  304. NSString *url = [purl stringByAppendingFormat:@"?service=Buyer.cancelGoodsOrder"];
  305. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  306. NSString *sign = [PublicObj sortString:signdic];
  307. NSDictionary *dic = @{
  308. @"uid":[Config getOwnID],
  309. @"token":[Config getOwnToken],
  310. @"orderid":model.idStr,
  311. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  312. @"sign":sign
  313. };
  314. [YBNetworking postWithUrl:@"Buyer.cancelGoodsOrder" Dic:dic Suc:^(int code, id info, NSString *msg) {
  315. if (code ==0) {
  316. [MBProgressHUD showError:msg];
  317. pageIndex = 1;
  318. [self requestOrderData];
  319. }else{
  320. [MBProgressHUD showError:msg];
  321. }
  322. } Fail:^(id fail) {
  323. }];
  324. }
  325. -(void)showPayView:(OrderModel *)model{
  326. YBWeakSelf;
  327. if (_payView) {
  328. [_payView removeFromSuperview];
  329. _payView = nil;
  330. }
  331. _payView = [[PayOrderView alloc]initWithPrice:model.price AndOrderId:model.idStr AndShopName:[model.shop_info valueForKey:@"name"]];
  332. _payView.frame = CGRectMake(0, 0, _window_width, _window_height);
  333. _payView.hideEvent = ^(BOOL paySuccess) {
  334. [weakSelf.payView removeFromSuperview];
  335. weakSelf.payView = nil;
  336. OrderDetailVC *detail = [[OrderDetailVC alloc]init];
  337. detail.orderId =model.idStr;
  338. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:detail animated:YES];
  339. };
  340. // _payView.hideEvent = ^{
  341. // [weakSelf.payView removeFromSuperview];
  342. // weakSelf.payView = nil;
  343. // };
  344. [self.view addSubview:_payView];
  345. }
  346. #pragma mark-----查看物流--------
  347. -(void)lookExpress:(OrderModel *)model{
  348. NSString *url =[NSString stringWithFormat:@"%@/appapi/express/index",h5url];
  349. PubH5 *h5VC = [[PubH5 alloc]init];
  350. h5VC.url = [self addurl:url addModel:model];
  351. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:h5VC animated:YES];
  352. }
  353. //所有h5需要拼接uid和token
  354. -(NSString *)addurl:(NSString *)url addModel:(OrderModel *)models{
  355. return [url stringByAppendingFormat:@"&uid=%@&token=%@&orderid=%@&user_type=buyer",[Config getOwnID],[Config getOwnToken],models.idStr];
  356. }
  357. #pragma mark------确认收货-------
  358. -(void)receiveGoods:(OrderModel *)model{
  359. NSString *url = [purl stringByAppendingFormat:@"?service=Buyer.receiveGoodsOrder"];
  360. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  361. NSString *sign = [PublicObj sortString:signdic];
  362. NSDictionary *dic = @{
  363. @"uid":[Config getOwnID],
  364. @"token":[Config getOwnToken],
  365. @"orderid":model.idStr,
  366. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  367. @"sign":sign
  368. };
  369. [YBNetworking postWithUrl:@"Buyer.receiveGoodsOrder" Dic:dic Suc:^(int code, id info, NSString *msg) {
  370. if (code ==0) {
  371. [MBProgressHUD showError:msg];
  372. pageIndex = 1;
  373. [self requestOrderData];
  374. }else{
  375. [MBProgressHUD showError:msg];
  376. }
  377. } Fail:^(id fail) {
  378. }];
  379. }
  380. #pragma mark-----评价-------
  381. -(void)evaluate:(OrderModel *)model{
  382. PublishEvaluateVC *evaluate = [[PublishEvaluateVC alloc]init];
  383. evaluate.model = model;
  384. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:evaluate animated:YES];
  385. }
  386. #pragma mark------追加评价-------
  387. -(void)appendEvaluate:(OrderModel *)model{
  388. AppendEvaluateVC *append = [[AppendEvaluateVC alloc]init];
  389. append.model = model;
  390. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:append animated:YES];
  391. }
  392. @end