| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- //
- // MySkillsController.m
- // model
- //
- // Created by JuYi on 2018/7/16.
- // Copyright © 2018年 Mine. All rights reserved.
- // 我的技能
- #import "MySkillsController.h"
- #import "PostSkillsController.h"
- #import "EditorSkillsController.h"
- #import "SkillsOrderCell.h"
- #import "MineNewViewController.h"
- #import "Masonry.h"
- @interface MySkillsController () <UITableViewDelegate, UITableViewDataSource>
- @property(nonatomic, strong) UITableView *tableView;
- @property(nonatomic, strong) UIView *remindView; //提示view
- @property(nonatomic, strong) NSMutableArray *dataArr;
- @property(nonatomic, strong) UIView *footerView;
- @end
- @implementation MySkillsController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self creatNavBar];
- [self creatSubViews];
- [self addRemindView];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- [self getDataFromNetworking];
- }
- #pragma mark -- 网络请求
- - (void)getDataFromNetworking {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- ModelUser *modelUser = [ModelUser user];
- NSDictionary *dic = @{@"modelpk": modelUser.modelpk};
- [YanCNetWorkManager requestPostWithURLStr:Url_getSkillData(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
- self.dataArr = dataDic[@"data"];
- if (self.dataArr.count == 0) {
- self.remindView.hidden = NO;
- //
- } else {
- self.remindView.hidden = YES;
- [self.tableView reloadData];
- }
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- - (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];
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- rightBtn.frame = CGRectMake(0, 0, 40, 40);
- [rightBtn setImage:[UIImage imageNamed:@"tianjia-1"] forState:UIControlStateNormal];
- rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -20);
- [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
- UIBarButtonItem *nagetiveRightSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- self.navigationItem.rightBarButtonItems = @[rightItem, nagetiveRightSpacer];
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)rightBtnClick {
- PostSkillsController *postVC = [[PostSkillsController alloc] init];
- [self.navigationController pushViewController:postVC animated:YES];
- }
- - (void)creatSubViews {
- self.tableView = [[UITableView alloc] init];
- self.tableView.backgroundColor = [UIColor whiteColor];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.tableFooterView = self.footerView;
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.mas_topLayoutGuide);
- make.bottom.equalTo(self.mas_bottomLayoutGuide);
- }];
- }
- - (UIView *)footerView {
- if (!_footerView) {
- _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 74)];
- UIButton *button = [[UIButton alloc] init];
- [button setTitle:@"完成" forState:UIControlStateNormal];
- button.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
- button.layer.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1].CGColor;
- button.layer.cornerRadius = 22;
- button.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor;
- button.layer.shadowOffset = CGSizeMake(0, 8);
- button.layer.shadowOpacity = 1;
- button.layer.shadowRadius = 10;
- [button addTarget:self action:@selector(finish) forControlEvents:UIControlEventTouchUpInside];
- [_footerView addSubview:button];
- [button mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(_footerView);
- make.leftMargin.equalTo(_footerView).offset(20);
- make.right.equalTo(_footerView).offset(-20);
- make.height.mas_equalTo(44);
- }];
- }
- return _footerView;
- }
- - (void)finish {
- for (UIViewController *temp in self.navigationController.viewControllers) {
- if ([temp isKindOfClass:[MineNewViewController class]]) {
- [self.navigationController popToViewController:temp animated:YES];
- }
- }
- }
- #pragma mark -- UITableViewDelegate, UITableViewDataSource
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
- return UITableViewCellEditingStyleDelete;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
- return @"删除";
- }
- - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
- return NO;
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [self getRemoveModelSkillFromNetworkingWithIndex:indexPath];
- }
- }
- - (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];
- }
- NSDictionary *dic = self.dataArr[indexPath.section];
- cell.smallLabel.hidden = YES;
- cell.lineView.hidden = YES;
- cell.completeBtn.hidden = YES;
- cell.cancelBtn.hidden = YES;
- cell.receiveBtn.hidden = YES;
- NSString *skillphoto = dic[@"skillphoto"];
- NSString *urlStr;
- if ([skillphoto containsString:@"http"]) {
- urlStr = [NSString stringWithFormat:@"%@", skillphoto];
- } else {
- urlStr = [NSString stringWithFormat:@"%@/%@", PublicUrl, skillphoto];
- }
- [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"tu"]];
- cell.titleLabel.text = dic[@"name"];
- cell.subTitleLabel.text = [NSString stringWithFormat:@"%@元/小时", dic[@"price"]];
- cell.subTitleLabel.textColor = RGBValueColor(0x333333, 1.0);
- cell.childTitleLabel.text = dic[@"lname"];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- NSDictionary *dic = self.dataArr[indexPath.section];
- EditorSkillsController *editorVC = [[EditorSkillsController alloc] init];
- editorVC.skilldic = dic;
- [self.navigationController pushViewController:editorVC animated:YES];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 116;
- }
- - (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;
- }
- }
- #pragma mark -- 删除
- - (void)getRemoveModelSkillFromNetworkingWithIndex:(NSIndexPath *)indexPath {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- NSDictionary *dic = _dataArr[indexPath.section];
- NSString *modelpk = dic[@"modelpk"];
- NSString *skillpk = dic[@"modelpricepk"];
- NSLog(@"%@/%@", modelpk, skillpk);
- NSDictionary *parameter = @{@"modelpk": modelpk, @"skillpk": skillpk};
- NSLog(@"%@/%@", modelpk, parameter);
- [YanCNetWorkManager requestPostWithURLStr:Url_removemodelskill(PublicUrl) parameters:parameter finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- NSString *issuccess = dataDic[@"msg"];
- if ([issuccess isEqualToString:@"success"]) {
- [MBProgressHUD showInfo:@"删除成功!"];
- [self.dataArr removeObjectAtIndex:indexPath.section];
- [self.tableView reloadData];
- } else {
- [MBProgressHUD showInfo:@"操作失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- - (void)addRemindView {
- self.remindView = [[UIView alloc] initWithFrame:self.view.bounds];
- self.remindView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- self.remindView.hidden = YES;
- [self.view addSubview:self.remindView];
- UIImageView *remindView = [[UIImageView alloc] init];
- remindView.frame = CGRectMake(ScreenWidth / 2 - 65.5, 75 * AutoSizeSalseX, 130.5, 90);
- remindView.image = [UIImage imageNamed:@"biaoqing"];
- [self.remindView addSubview:remindView];
- UILabel *remindLabel = [[UILabel alloc] init];
- remindLabel.frame = CGRectMake(0, CGRectGetMaxY(remindView.frame) + 20, ScreenWidth, 15);
- remindLabel.textAlignment = NSTextAlignmentCenter;
- remindLabel.font = [UIFont systemFontOfSize:15.0];
- remindLabel.textColor = RGBValueColor(0xc5c5c7, 1.0);
- remindLabel.text = @"还没有发布过技能";
- [self.remindView addSubview:remindLabel];
- //
- UILabel *subRemindLabel = [[UILabel alloc] init];
- subRemindLabel.frame = CGRectMake(0, CGRectGetMaxY(remindLabel.frame) + 20, ScreenWidth, 15);
- subRemindLabel.textAlignment = NSTextAlignmentCenter;
- subRemindLabel.font = [UIFont systemFontOfSize:15.0];
- subRemindLabel.textColor = RGBValueColor(0xc5c5c7, 1.0);
- subRemindLabel.text = @"快去添加你的技能吧";
- [self.remindView addSubview:subRemindLabel];
- UIButton *addBtnAction = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 110, CGRectGetMaxY(subRemindLabel.frame) + 60, 220, 44)];
- [addBtnAction setTitle:@"立即添加" forState:UIControlStateNormal];
- [addBtnAction setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- addBtnAction.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
- addBtnAction.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:64/255.0 blue:149/255.0 alpha:1].CGColor;
- addBtnAction.layer.cornerRadius = 22;
- addBtnAction.layer.shadowColor = [UIColor colorWithRed:255/255.0 green:64/255.0 blue:149/255.0 alpha:0.36].CGColor;
- addBtnAction.layer.shadowOffset = CGSizeMake(0,8);
- addBtnAction.layer.shadowOpacity = 1;
- addBtnAction.layer.shadowRadius = 10;
- [addBtnAction addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.remindView addSubview:addBtnAction];
- }
- @end
|