MySkillsController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. //
  2. // MySkillsController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/16.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 我的技能
  8. #import "MySkillsController.h"
  9. #import "PostSkillsController.h"
  10. #import "EditorSkillsController.h"
  11. #import "SkillsOrderCell.h"
  12. #import "MineNewViewController.h"
  13. #import "Masonry.h"
  14. @interface MySkillsController () <UITableViewDelegate, UITableViewDataSource>
  15. @property(nonatomic, strong) UITableView *tableView;
  16. @property(nonatomic, strong) UIView *remindView; //提示view
  17. @property(nonatomic, strong) NSMutableArray *dataArr;
  18. @property(nonatomic, strong) UIView *footerView;
  19. @end
  20. @implementation MySkillsController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self creatNavBar];
  24. [self creatSubViews];
  25. [self addRemindView];
  26. }
  27. - (void)viewWillAppear:(BOOL)animated {
  28. [super viewWillAppear:animated];
  29. [self.navigationController setNavigationBarHidden:NO animated:YES];
  30. [self getDataFromNetworking];
  31. }
  32. #pragma mark -- 网络请求
  33. - (void)getDataFromNetworking {
  34. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  35. ModelUser *modelUser = [ModelUser user];
  36. NSDictionary *dic = @{@"modelpk": modelUser.modelpk};
  37. [YanCNetWorkManager requestPostWithURLStr:Url_getSkillData(PublicUrl) parameters:dic finish:^(id dataDic) {
  38. [MBProgressHUD hideHUDForView:self.view animated:YES];
  39. NSString *issuccess = dataDic[@"msg"];
  40. if ([issuccess isEqualToString:@"success"]) {
  41. self.dataArr = dataDic[@"data"];
  42. if (self.dataArr.count == 0) {
  43. self.remindView.hidden = NO;
  44. //
  45. } else {
  46. self.remindView.hidden = YES;
  47. [self.tableView reloadData];
  48. }
  49. } else {
  50. [MBProgressHUD showInfo:@"请求失败!"];
  51. }
  52. } enError:^(NSError *error) {
  53. [MBProgressHUD hideHUDForView:self.view animated:YES];
  54. }];
  55. }
  56. - (void)creatNavBar {
  57. self.title = @"我的技能";
  58. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  59. btn.frame = CGRectMake(0, 0, 40, 40);
  60. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  61. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
  62. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  63. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  64. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  65. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  66. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  67. rightBtn.frame = CGRectMake(0, 0, 40, 40);
  68. [rightBtn setImage:[UIImage imageNamed:@"tianjia-1"] forState:UIControlStateNormal];
  69. rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -20);
  70. [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  71. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
  72. UIBarButtonItem *nagetiveRightSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  73. self.navigationItem.rightBarButtonItems = @[rightItem, nagetiveRightSpacer];
  74. }
  75. - (void)backClick {
  76. [self.navigationController popViewControllerAnimated:YES];
  77. }
  78. - (void)rightBtnClick {
  79. PostSkillsController *postVC = [[PostSkillsController alloc] init];
  80. [self.navigationController pushViewController:postVC animated:YES];
  81. }
  82. - (void)creatSubViews {
  83. self.tableView = [[UITableView alloc] init];
  84. self.tableView.backgroundColor = [UIColor whiteColor];
  85. self.tableView.delegate = self;
  86. self.tableView.dataSource = self;
  87. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  88. self.tableView.tableFooterView = self.footerView;
  89. [self.view addSubview:self.tableView];
  90. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.right.equalTo(self.view);
  92. make.top.equalTo(self.mas_topLayoutGuide);
  93. make.bottom.equalTo(self.mas_bottomLayoutGuide);
  94. }];
  95. }
  96. - (UIView *)footerView {
  97. if (!_footerView) {
  98. _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 74)];
  99. UIButton *button = [[UIButton alloc] init];
  100. [button setTitle:@"完成" forState:UIControlStateNormal];
  101. button.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  102. button.layer.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1].CGColor;
  103. button.layer.cornerRadius = 22;
  104. button.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor;
  105. button.layer.shadowOffset = CGSizeMake(0, 8);
  106. button.layer.shadowOpacity = 1;
  107. button.layer.shadowRadius = 10;
  108. [button addTarget:self action:@selector(finish) forControlEvents:UIControlEventTouchUpInside];
  109. [_footerView addSubview:button];
  110. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.centerY.equalTo(_footerView);
  112. make.leftMargin.equalTo(_footerView).offset(20);
  113. make.right.equalTo(_footerView).offset(-20);
  114. make.height.mas_equalTo(44);
  115. }];
  116. }
  117. return _footerView;
  118. }
  119. - (void)finish {
  120. for (UIViewController *temp in self.navigationController.viewControllers) {
  121. if ([temp isKindOfClass:[MineNewViewController class]]) {
  122. [self.navigationController popToViewController:temp animated:YES];
  123. }
  124. }
  125. }
  126. #pragma mark -- UITableViewDelegate, UITableViewDataSource
  127. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  128. return YES;
  129. }
  130. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  131. return UITableViewCellEditingStyleDelete;
  132. }
  133. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  134. return @"删除";
  135. }
  136. - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
  137. return NO;
  138. }
  139. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  140. if (editingStyle == UITableViewCellEditingStyleDelete) {
  141. [self getRemoveModelSkillFromNetworkingWithIndex:indexPath];
  142. }
  143. }
  144. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  145. return self.dataArr.count;
  146. }
  147. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  148. return 1;
  149. }
  150. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  151. static NSString *cellid = @"cellid";
  152. SkillsOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  153. if (!cell) {
  154. cell = [[SkillsOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
  155. }
  156. NSDictionary *dic = self.dataArr[indexPath.section];
  157. cell.smallLabel.hidden = YES;
  158. cell.lineView.hidden = YES;
  159. cell.completeBtn.hidden = YES;
  160. cell.cancelBtn.hidden = YES;
  161. cell.receiveBtn.hidden = YES;
  162. NSString *skillphoto = dic[@"skillphoto"];
  163. NSString *urlStr;
  164. if ([skillphoto containsString:@"http"]) {
  165. urlStr = [NSString stringWithFormat:@"%@", skillphoto];
  166. } else {
  167. urlStr = [NSString stringWithFormat:@"%@/%@", PublicUrl, skillphoto];
  168. }
  169. [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"tu"]];
  170. cell.titleLabel.text = dic[@"name"];
  171. cell.subTitleLabel.text = [NSString stringWithFormat:@"%@元/小时", dic[@"price"]];
  172. cell.subTitleLabel.textColor = RGBValueColor(0x333333, 1.0);
  173. cell.childTitleLabel.text = dic[@"lname"];
  174. return cell;
  175. }
  176. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  177. NSDictionary *dic = self.dataArr[indexPath.section];
  178. EditorSkillsController *editorVC = [[EditorSkillsController alloc] init];
  179. editorVC.skilldic = dic;
  180. [self.navigationController pushViewController:editorVC animated:YES];
  181. }
  182. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  183. return 116;
  184. }
  185. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  186. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
  187. footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  188. return footerView;
  189. }
  190. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  191. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
  192. headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  193. return headerView;
  194. }
  195. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  196. return 0.01;
  197. }
  198. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  199. if (section == 0) {
  200. return 0.01;
  201. } else {
  202. return 10;
  203. }
  204. }
  205. #pragma mark -- 删除
  206. - (void)getRemoveModelSkillFromNetworkingWithIndex:(NSIndexPath *)indexPath {
  207. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  208. NSDictionary *dic = _dataArr[indexPath.section];
  209. NSString *modelpk = dic[@"modelpk"];
  210. NSString *skillpk = dic[@"modelpricepk"];
  211. NSLog(@"%@/%@", modelpk, skillpk);
  212. NSDictionary *parameter = @{@"modelpk": modelpk, @"skillpk": skillpk};
  213. NSLog(@"%@/%@", modelpk, parameter);
  214. [YanCNetWorkManager requestPostWithURLStr:Url_removemodelskill(PublicUrl) parameters:parameter finish:^(id dataDic) {
  215. [MBProgressHUD hideHUDForView:self.view animated:YES];
  216. NSString *issuccess = dataDic[@"msg"];
  217. if ([issuccess isEqualToString:@"success"]) {
  218. [MBProgressHUD showInfo:@"删除成功!"];
  219. [self.dataArr removeObjectAtIndex:indexPath.section];
  220. [self.tableView reloadData];
  221. } else {
  222. [MBProgressHUD showInfo:@"操作失败!"];
  223. }
  224. } enError:^(NSError *error) {
  225. [MBProgressHUD hideHUDForView:self.view animated:YES];
  226. }];
  227. }
  228. - (void)addRemindView {
  229. self.remindView = [[UIView alloc] initWithFrame:self.view.bounds];
  230. self.remindView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  231. self.remindView.hidden = YES;
  232. [self.view addSubview:self.remindView];
  233. UIImageView *remindView = [[UIImageView alloc] init];
  234. remindView.frame = CGRectMake(ScreenWidth / 2 - 65.5, 75 * AutoSizeSalseX, 130.5, 90);
  235. remindView.image = [UIImage imageNamed:@"biaoqing"];
  236. [self.remindView addSubview:remindView];
  237. UILabel *remindLabel = [[UILabel alloc] init];
  238. remindLabel.frame = CGRectMake(0, CGRectGetMaxY(remindView.frame) + 20, ScreenWidth, 15);
  239. remindLabel.textAlignment = NSTextAlignmentCenter;
  240. remindLabel.font = [UIFont systemFontOfSize:15.0];
  241. remindLabel.textColor = RGBValueColor(0xc5c5c7, 1.0);
  242. remindLabel.text = @"还没有发布过技能";
  243. [self.remindView addSubview:remindLabel];
  244. //
  245. UILabel *subRemindLabel = [[UILabel alloc] init];
  246. subRemindLabel.frame = CGRectMake(0, CGRectGetMaxY(remindLabel.frame) + 20, ScreenWidth, 15);
  247. subRemindLabel.textAlignment = NSTextAlignmentCenter;
  248. subRemindLabel.font = [UIFont systemFontOfSize:15.0];
  249. subRemindLabel.textColor = RGBValueColor(0xc5c5c7, 1.0);
  250. subRemindLabel.text = @"快去添加你的技能吧";
  251. [self.remindView addSubview:subRemindLabel];
  252. UIButton *addBtnAction = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 110, CGRectGetMaxY(subRemindLabel.frame) + 60, 220, 44)];
  253. [addBtnAction setTitle:@"立即添加" forState:UIControlStateNormal];
  254. [addBtnAction setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  255. addBtnAction.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  256. addBtnAction.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:64/255.0 blue:149/255.0 alpha:1].CGColor;
  257. addBtnAction.layer.cornerRadius = 22;
  258. addBtnAction.layer.shadowColor = [UIColor colorWithRed:255/255.0 green:64/255.0 blue:149/255.0 alpha:0.36].CGColor;
  259. addBtnAction.layer.shadowOffset = CGSizeMake(0,8);
  260. addBtnAction.layer.shadowOpacity = 1;
  261. addBtnAction.layer.shadowRadius = 10;
  262. [addBtnAction addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  263. [self.remindView addSubview:addBtnAction];
  264. }
  265. @end