SearchComment.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. #import "SearchComment.h"
  3. #import "CommentCell.h"
  4. #import "CommentScoreView.h"
  5. @interface SearchComment ()<UITableViewDataSource,UITableViewDelegate>
  6. {
  7. //模型。
  8. NSArray* models;
  9. UITableView* myTableView;
  10. UILabel* lblEmpty;
  11. /**每次下载后。就判断.
  12. 如果cnt为0就显示。否则隐藏
  13. */
  14. UIView* placeHolder;
  15. CommentScoreView *CSView;
  16. UIButton *upBtn;
  17. NSInteger commentID;
  18. }
  19. @end
  20. /**整体UI搭建为。下面为tableview。上面是tableheader
  21. */
  22. @implementation SearchComment
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self myInit];
  26. [self getSchOrCoachEvaluates];
  27. }
  28. - (void)didReceiveMemoryWarning {
  29. [super didReceiveMemoryWarning];
  30. }
  31. -(void)myInit
  32. {
  33. [self configNavigationBar];
  34. [self.view setBackgroundColor:[UIColor whiteColor]];
  35. [self setTitle:@"学员点评"];
  36. CGFloat x,y,w,h;
  37. UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet)];
  38. [tv setDelegate:self];
  39. [tv setDataSource:self];
  40. [self.view addSubview:tv];
  41. CSView = [[CommentScoreView alloc] initWithFrame:CGRectMake(0, kSize.width, 0, 130)];
  42. CSView.type = _type;
  43. CSView.sfbh = _bpjr;
  44. [CSView setBoardWid:2 Color:KlineColor];
  45. tv.tableHeaderView = CSView;
  46. tv.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, .1)];
  47. myTableView = tv;
  48. //placeHolder
  49. UIView* vi = [[UIView alloc] initWithFrame:kFrame];
  50. vi.y += 30;
  51. [self.view addSubview:vi];
  52. vi.hidden = YES;
  53. placeHolder = vi;
  54. w = h = kSize.width/3.0;
  55. x = y = w;
  56. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  57. [iv setImage:[UIImage imageNamed:@"community4.png"]];
  58. [iv setContentMode:UIViewContentModeScaleAspectFit];
  59. [placeHolder addSubview:iv];
  60. y += h + 20;
  61. x = 0;
  62. w = kSize.width;
  63. h = 40;
  64. UILabel* label;
  65. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  66. [label setText:@"暂无相关点评~"];
  67. [label setTextAlignment:NSTextAlignmentCenter];
  68. [label setTextColor:contentTextColor];
  69. [placeHolder addSubview:label];
  70. }
  71. -(void)btnClick:(UIButton *)sender
  72. {
  73. commentID = sender.tag;
  74. [self uploadSchOrCoachEvaluatePoint];
  75. }
  76. #pragma mark tableView delegate
  77. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. return 150;
  80. }
  81. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  82. {
  83. return models.count;
  84. }
  85. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  86. {
  87. CommentCell* cell = [CommentCell cellForTableView:tableView Style:CommentCellStyleSchool];
  88. cell.VCName = @"SearchComment";
  89. [cell setDict:models[indexPath.row]];
  90. upBtn = cell.upBtn;
  91. [upBtn target:self tag:indexPath.row];
  92. return cell;
  93. }
  94. #pragma mark 数据请求
  95. -(void)getSchOrCoachEvaluates
  96. {
  97. if (![Util connectedToNetWork]) {
  98. showMsgUnconnect();
  99. return;
  100. }
  101. NSMutableArray* arr = [NSMutableArray array];
  102. [arr addPro:@"bpjz" Value:self.bpjr];
  103. [arr addPro:@"type" Value:self.type];
  104. [arr addPro:@"outId" Value:defUser.userDict[@"outId"]];
  105. [arr addPro:@"isPage" Value:@"1"];
  106. [arr addPro:@"pageSize" Value:@"60"];
  107. [arr addPro:@"currentPage" Value:@"1"];
  108. // NSLog(@"评论列表参数 ---->%@",arr);
  109. NSString* method = @"getSchOrCoachEvaluates";
  110. [MBProgressHUD showLoadToView:self.view];
  111. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  112. [MBProgressHUD hideHUDForView:self.view];
  113. if (!root) {
  114. ShowMsgFailed();
  115. return;
  116. }
  117. if ([root[@"code"] isEqualToString:@"1"]) {
  118. ShowMsg(root[@"body"]);
  119. return;
  120. }
  121. models = root[@"body"];
  122. if (models.count < 1) {
  123. placeHolder.hidden = NO;
  124. }else{
  125. placeHolder.hidden = YES;
  126. CSView.countLabel.text = [NSString stringWithFormat:@"%d人评价",(int)models.count];
  127. [myTableView reloadData];
  128. }
  129. }];
  130. }
  131. -(void)uploadSchOrCoachEvaluatePoint
  132. {
  133. if (![Util connectedToNetWork]) {
  134. showMsgUnconnect();
  135. return;
  136. }
  137. NSDictionary *dic = models[commentID];
  138. NSMutableArray* arr = [NSMutableArray array];
  139. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  140. [arr addPro:@"id" Value:dic[@"ID"]];
  141. NSString* method = @"uploadSchOrCoachEvaluatePoint";
  142. if (![dic[@"ISPOINT"] isEqualToString:@"0"]) {
  143. method = @"deleteSchOrCoachEvaluatePoint";
  144. }
  145. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  146. //NSLog(@"点赞结果---->%@",root);
  147. if (!root) {
  148. ShowMsgFailed();
  149. return;
  150. }
  151. if ([root[@"code"] isEqualToString:@"1"]) {
  152. ShowMsg(root[@"body"]);
  153. return;
  154. }
  155. [self getSchOrCoachEvaluates];
  156. // dispatch_async(dispatch_get_main_queue(), ^{
  157. //
  158. // if (![dic[@"ISPOINT"] isEqualToString:@"0"]) {
  159. // [upBtn setTitle:[NSString stringWithFormat:@"%d",[dic[@"POINTNUM"] intValue] - 1] forState:UIControlStateNormal];
  160. // }else{
  161. // [upBtn setTitle:[NSString stringWithFormat:@"%d",[dic[@"POINTNUM"] intValue] + 1] forState:UIControlStateNormal];
  162. // }
  163. // });
  164. }];
  165. }
  166. @end