SkillOrderController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. //
  2. // SkillOrderController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/17.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 技能订单
  8. #import "SkillOrderController.h"
  9. #import "SkillsOrderCell.h"
  10. #import "ModelTitleView.h" // 选择按钮
  11. #import "OrderDetailViewController.h"
  12. #import "MessageViewController.h"
  13. @interface SkillOrderController ()<UITableViewDelegate, UITableViewDataSource>
  14. {
  15. NSInteger index;
  16. NSString *selectState;
  17. }
  18. @property (nonatomic, strong) UITableView *tableView;
  19. @property (nonatomic, strong) NSMutableArray *dataArr;
  20. @property (nonatomic, assign) NSInteger selectIndex; //0 1 2 3 4
  21. @end
  22. @implementation SkillOrderController
  23. - (NSMutableArray *)dataArr {
  24. if (!_dataArr) {
  25. _dataArr = [NSMutableArray arrayWithCapacity:0];
  26. }
  27. return _dataArr;
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. index = 1;
  32. selectState = @"all";
  33. self.selectIndex = 0;
  34. //设置导航条
  35. [self creatNavBar];
  36. //设置子试图
  37. [self creatSubViews];
  38. [self getDataFromNetworking:selectState];
  39. }
  40. - (void)viewWillAppear:(BOOL)animated{
  41. self.tabBarController.tabBar.hidden = YES;
  42. }
  43. - (void)didReceiveMemoryWarning {
  44. [super didReceiveMemoryWarning];
  45. // Dispose of any resources that can be recreated.
  46. }
  47. - (void)creatNavBar {
  48. self.title = @"技能订单";
  49. //
  50. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. btn.frame = CGRectMake(0, 0, 40, 40);
  52. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  53. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
  54. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  55. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  56. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  57. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  58. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  59. }
  60. - (void)backClick {
  61. [self.navigationController popViewControllerAnimated:YES];
  62. }
  63. #pragma mark -- 网络请求
  64. - (void)getDataFromNetworking:(NSString *)state {
  65. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  66. NSString *indexStr = [NSString stringWithFormat:@"%zd",index];
  67. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",state,@"state",indexStr,@"index",@"10",@"size", nil];
  68. [YanCNetWorkManager requestPostWithURLStr:Url_dogetorderlist(PublicUrl) parameters:dic finish:^(id dataDic) {
  69. [MBProgressHUD hideHUDForView:self.view animated:YES];
  70. NSString *issuccess = dataDic[@"msg"];
  71. if ([issuccess isEqualToString:@"success"]) {
  72. if (index == 1) {
  73. [self.dataArr removeAllObjects];
  74. }
  75. [self.dataArr addObjectsFromArray:dataDic[@"data"]];
  76. [self.tableView reloadData];
  77. NSString *number = dataDic[@"count"];
  78. NSInteger num = [number integerValue];
  79. [self.tableView.mj_header endRefreshing];
  80. if (num == self.dataArr.count || num == 0) {
  81. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  82. }else{
  83. [self.tableView.mj_footer endRefreshing];
  84. }
  85. } else {
  86. [MBProgressHUD showInfo:@"请求失败!"];
  87. }
  88. } enError:^(NSError *error) {
  89. [MBProgressHUD hideHUDForView:self.view animated:YES];
  90. }];
  91. }
  92. //
  93. - (void)creatSubViews {
  94. NSArray *stateArr = @[@"all",@"1",@"2",@"3"];
  95. ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
  96. titlesView.titleArr = @[@"全部", @"待接单", @"进行中", @"已完成"];
  97. __weak typeof (self) weakself = self;
  98. titlesView.ModelTitleViewBlock = ^(NSInteger tag) {
  99. NSLog(@"tag %ld", tag);
  100. weakself.selectIndex = tag;
  101. if (self.dataArr.count>0) {
  102. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  103. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  104. }
  105. selectState = stateArr[tag];
  106. index = 1;
  107. [self getDataFromNetworking:selectState];
  108. };
  109. [self.view addSubview:titlesView];
  110. //
  111. float height = Height_NaviBar;
  112. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenHeight-40-height) style:UITableViewStyleGrouped];
  113. self.tableView.backgroundColor = [UIColor whiteColor];
  114. self.tableView.delegate = self;
  115. self.tableView.dataSource = self;
  116. self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  117. self.tableView.showsVerticalScrollIndicator = NO;
  118. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  119. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)];
  120. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  121. [self.view addSubview:self.tableView];
  122. }
  123. -(void)refreshList{
  124. index = 1;
  125. [self getDataFromNetworking:selectState];
  126. }
  127. - (void)loadMoreData{
  128. index++;
  129. [self getDataFromNetworking:selectState];
  130. }
  131. #pragma mark -- UITableViewDelegate, UITableViewDataSource
  132. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  133. {
  134. return self.dataArr.count;
  135. }
  136. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  137. {
  138. return 1;
  139. }
  140. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  141. static NSString *cellid = @"cellid";
  142. SkillsOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  143. if (!cell) {
  144. cell = [[SkillsOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
  145. }
  146. cell.arrowView.hidden = YES;
  147. [cell setSkillsOrderCellValueWithDic:self.dataArr[indexPath.section]];
  148. cell.cancelBtn.tag = indexPath.section;
  149. cell.receiveBtn.tag = indexPath.section;
  150. cell.completeBtn.tag = indexPath.section;
  151. cell.iconImageView.tag = indexPath.section;
  152. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toMessageView:)];
  153. [cell.iconImageView addGestureRecognizer:tap];
  154. cell.iconImageView.userInteractionEnabled = YES;
  155. [cell.cancelBtn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
  156. [cell.receiveBtn addTarget:self action:@selector(receive:) forControlEvents:UIControlEventTouchUpInside];
  157. [cell.completeBtn addTarget:self action:@selector(complete:) forControlEvents:UIControlEventTouchUpInside];
  158. return cell;
  159. }
  160. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  161. NSDictionary *dic = self.dataArr[indexPath.section];
  162. OrderDetailViewController *vc = [[OrderDetailViewController alloc]initWithOrderpk:dic[@"pk"]];
  163. [self.navigationController pushViewController:vc animated:YES];
  164. }
  165. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  166. return 156;
  167. }
  168. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  169. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
  170. footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  171. return footerView;
  172. }
  173. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  174. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
  175. headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  176. return headerView;
  177. }
  178. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  179. return 0.01;
  180. }
  181. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  182. if (section == 0) {
  183. return 0.01;
  184. } else {
  185. return 10;
  186. }
  187. }
  188. -(void)cancel:(UIButton *)button{
  189. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  190. NSDictionary *orderDic = self.dataArr[button.tag];
  191. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",[orderDic objectForKey:@"pk"],@"orderpk", nil];
  192. [YanCNetWorkManager requestPostWithURLStr:Url_cancelordermodel(PublicUrl) parameters:dic finish:^(id dataDic) {
  193. [MBProgressHUD hideHUDForView:self.view animated:YES];
  194. NSString *issuccess = dataDic[@"msg"];
  195. if ([issuccess isEqualToString:@"success"]) {
  196. [MBProgressHUD showInfo:@"已取消"];
  197. [self refreshList];
  198. [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"提示,模特取消了您的订单"];
  199. } else {
  200. [MBProgressHUD showInfo:dataDic[@"desc"]];
  201. }
  202. } enError:^(NSError *error) {
  203. [MBProgressHUD hideHUDForView:self.view animated:YES];
  204. }];
  205. }
  206. -(void)receive:(UIButton *)button{
  207. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  208. NSDictionary *orderDic = self.dataArr[button.tag];
  209. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",[orderDic objectForKey:@"pk"],@"orderpk", nil];
  210. [YanCNetWorkManager requestPostWithURLStr:Url_confirmordermodel(PublicUrl) parameters:dic finish:^(id dataDic) {
  211. [MBProgressHUD hideHUDForView:self.view animated:YES];
  212. NSString *issuccess = dataDic[@"msg"];
  213. if ([issuccess isEqualToString:@"success"]) {
  214. [MBProgressHUD showInfo:@"接单成功"];
  215. [self refreshList];
  216. [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"恭喜,模特已经接单啦!"];
  217. } else {
  218. [MBProgressHUD showInfo:dataDic[@"desc"]];
  219. }
  220. } enError:^(NSError *error) {
  221. [MBProgressHUD hideHUDForView:self.view animated:YES];
  222. }];
  223. }
  224. -(void)complete:(UIButton *)button{
  225. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  226. NSDictionary *orderDic = self.dataArr[button.tag];
  227. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[orderDic objectForKey:@"pk"],@"orderpk", nil];
  228. [YanCNetWorkManager requestPostWithURLStr:Url_dosettlementorder(PublicUrl) parameters:dic finish:^(id dataDic) {
  229. [MBProgressHUD hideHUDForView:self.view animated:YES];
  230. NSString *issuccess = dataDic[@"msg"];
  231. if ([issuccess isEqualToString:@"success"]) {
  232. [MBProgressHUD showInfo:@"已确认完成"];
  233. [self refreshList];
  234. [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"模特已经确认完成订单了"];
  235. } else {
  236. [MBProgressHUD showInfo:dataDic[@"desc"]];
  237. }
  238. } enError:^(NSError *error) {
  239. [MBProgressHUD hideHUDForView:self.view animated:YES];
  240. }];
  241. }
  242. -(void)postNotification:(NSString *)memberpk andMsg:(NSString *)msg{
  243. NSString *str = [NSString stringWithFormat:@"%@/netease?action=sendAttachMsg&from=%@&to=%@&pushcontent=%@",PublicUrl,[ModelUser modelUser].pk,memberpk,msg];
  244. [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
  245. NSLog(@"%@",responseObject);
  246. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"200"]) {
  247. }else{
  248. }
  249. } failure:^(NSError *error) {
  250. NSLog(@"error = %@",error);
  251. }];
  252. }
  253. - (void)toMessageView:(UIGestureRecognizer *)recognizer{
  254. UIImageView *img = (UIImageView *)recognizer.view;
  255. NSDictionary *orderDic = self.dataArr[img.tag];
  256. NIMSession *session = [NIMSession session:[orderDic objectForKey:@"memberpk"] type:NIMSessionTypeP2P];
  257. MessageViewController *mVc = [[MessageViewController alloc]initWithSession:session];
  258. [self.navigationController pushViewController:mVc animated:YES];
  259. }
  260. @end