| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- //
- // SkillOrderController.m
- // model
- //
- // Created by JuYi on 2018/7/17.
- // Copyright © 2018年 Mine. All rights reserved.
- // 技能订单
- #import "SkillOrderController.h"
- #import "SkillsOrderCell.h"
- #import "ModelTitleView.h" // 选择按钮
- #import "OrderDetailViewController.h"
- #import "MessageViewController.h"
- @interface SkillOrderController ()<UITableViewDelegate, UITableViewDataSource>
- {
- NSInteger index;
- NSString *selectState;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, assign) NSInteger selectIndex; //0 1 2 3 4
- @end
- @implementation SkillOrderController
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray arrayWithCapacity:0];
- }
- return _dataArr;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- index = 1;
- selectState = @"all";
- self.selectIndex = 0;
- //设置导航条
- [self creatNavBar];
- //设置子试图
- [self creatSubViews];
- [self getDataFromNetworking:selectState];
- }
- - (void)viewWillAppear:(BOOL)animated{
- self.tabBarController.tabBar.hidden = YES;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)creatNavBar {
- self.title = @"技能订单";
- //
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark -- 网络请求
- - (void)getDataFromNetworking:(NSString *)state {
-
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- NSString *indexStr = [NSString stringWithFormat:@"%zd",index];
-
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",state,@"state",indexStr,@"index",@"10",@"size", nil];
-
- [YanCNetWorkManager requestPostWithURLStr:Url_dogetorderlist(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
-
- if (index == 1) {
- [self.dataArr removeAllObjects];
- }
-
- [self.dataArr addObjectsFromArray:dataDic[@"data"]];
-
- [self.tableView reloadData];
-
- NSString *number = dataDic[@"count"];
- NSInteger num = [number integerValue];
-
- [self.tableView.mj_header endRefreshing];
- if (num == self.dataArr.count || num == 0) {
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }else{
- [self.tableView.mj_footer endRefreshing];
- }
-
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- //
- - (void)creatSubViews {
-
- NSArray *stateArr = @[@"all",@"1",@"2",@"3"];
-
- ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
- titlesView.titleArr = @[@"全部", @"待接单", @"进行中", @"已完成"];
- __weak typeof (self) weakself = self;
- titlesView.ModelTitleViewBlock = ^(NSInteger tag) {
- NSLog(@"tag %ld", tag);
- weakself.selectIndex = tag;
-
- if (self.dataArr.count>0) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
- }
-
- selectState = stateArr[tag];
- index = 1;
- [self getDataFromNetworking:selectState];
- };
- [self.view addSubview:titlesView];
-
- //
- float height = Height_NaviBar;
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenHeight-40-height) style:UITableViewStyleGrouped];
- self.tableView.backgroundColor = [UIColor whiteColor];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- self.tableView.showsVerticalScrollIndicator = NO;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)];
- self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
- [self.view addSubview:self.tableView];
- }
- -(void)refreshList{
-
- index = 1;
- [self getDataFromNetworking:selectState];
- }
- - (void)loadMoreData{
-
- index++;
- [self getDataFromNetworking:selectState];
- }
- #pragma mark -- UITableViewDelegate, UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.dataArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- static NSString *cellid = @"cellid";
- SkillsOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
- if (!cell) {
- cell = [[SkillsOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
- }
- cell.arrowView.hidden = YES;
- [cell setSkillsOrderCellValueWithDic:self.dataArr[indexPath.section]];
-
- cell.cancelBtn.tag = indexPath.section;
- cell.receiveBtn.tag = indexPath.section;
- cell.completeBtn.tag = indexPath.section;
-
- cell.iconImageView.tag = indexPath.section;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toMessageView:)];
- [cell.iconImageView addGestureRecognizer:tap];
- cell.iconImageView.userInteractionEnabled = YES;
-
- [cell.cancelBtn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
- [cell.receiveBtn addTarget:self action:@selector(receive:) forControlEvents:UIControlEventTouchUpInside];
- [cell.completeBtn addTarget:self action:@selector(complete:) forControlEvents:UIControlEventTouchUpInside];
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSDictionary *dic = self.dataArr[indexPath.section];
- OrderDetailViewController *vc = [[OrderDetailViewController alloc]initWithOrderpk:dic[@"pk"]];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 156;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
- footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- return footerView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
- headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- return headerView;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.01;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 0.01;
- } else {
- return 10;
- }
- }
- -(void)cancel:(UIButton *)button{
-
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
- NSDictionary *orderDic = self.dataArr[button.tag];
-
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",[orderDic objectForKey:@"pk"],@"orderpk", nil];
-
- [YanCNetWorkManager requestPostWithURLStr:Url_cancelordermodel(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
-
- [MBProgressHUD showInfo:@"已取消"];
- [self refreshList];
- [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"提示,模特取消了您的订单"];
- } else {
- [MBProgressHUD showInfo:dataDic[@"desc"]];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- -(void)receive:(UIButton *)button{
-
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
- NSDictionary *orderDic = self.dataArr[button.tag];
-
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].modelpk,@"modelpk",[orderDic objectForKey:@"pk"],@"orderpk", nil];
-
- [YanCNetWorkManager requestPostWithURLStr:Url_confirmordermodel(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
-
- [MBProgressHUD showInfo:@"接单成功"];
- [self refreshList];
- [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"恭喜,模特已经接单啦!"];
- } else {
- [MBProgressHUD showInfo:dataDic[@"desc"]];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- -(void)complete:(UIButton *)button{
-
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
- NSDictionary *orderDic = self.dataArr[button.tag];
-
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[orderDic objectForKey:@"pk"],@"orderpk", nil];
-
- [YanCNetWorkManager requestPostWithURLStr:Url_dosettlementorder(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
-
- [MBProgressHUD showInfo:@"已确认完成"];
- [self refreshList];
- [self postNotification:[orderDic objectForKey:@"memberpk"] andMsg:@"模特已经确认完成订单了"];
- } else {
- [MBProgressHUD showInfo:dataDic[@"desc"]];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- -(void)postNotification:(NSString *)memberpk andMsg:(NSString *)msg{
-
- NSString *str = [NSString stringWithFormat:@"%@/netease?action=sendAttachMsg&from=%@&to=%@&pushcontent=%@",PublicUrl,[ModelUser modelUser].pk,memberpk,msg];
- [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
- NSLog(@"%@",responseObject);
- if ([[responseObject objectForKey:@"msg"]isEqualToString:@"200"]) {
-
- }else{
-
- }
- } failure:^(NSError *error) {
- NSLog(@"error = %@",error);
- }];
- }
- - (void)toMessageView:(UIGestureRecognizer *)recognizer{
-
- UIImageView *img = (UIImageView *)recognizer.view;
- NSDictionary *orderDic = self.dataArr[img.tag];
-
- NIMSession *session = [NIMSession session:[orderDic objectForKey:@"memberpk"] type:NIMSessionTypeP2P];
- MessageViewController *mVc = [[MessageViewController alloc]initWithSession:session];
- [self.navigationController pushViewController:mVc animated:YES];
- }
- @end
|