YOUPAILZIMCommonWordsVC.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // YOUPAILZIMCommonWordsVC.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/3/8.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZIMCommonWordsVC.h"
  9. #import "YOUPAILZCommonWordCell.h"
  10. #import "YOUPAILCIMTool.h"
  11. #import "NIMMessageMaker.h"
  12. @interface YOUPAILZIMCommonWordsVC ()<UITableViewDataSource,UITableViewDelegate>
  13. @property (nonatomic, weak) UITableView *youpaiptableView;
  14. @end
  15. @implementation YOUPAILZIMCommonWordsVC
  16. - (void)viewWillDisappear:(BOOL)animated{
  17. [super viewWillDisappear:animated];
  18. if (self.youpaipreloadDataSourceBlock != nil) {
  19. self.youpaipreloadDataSourceBlock(self.youpaipdataSource);
  20. }
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"聊天常用语";
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. [self youpaifinitUI];
  27. // [self youpaiploadData];
  28. }
  29. - (void)youpaifinitFooterView{
  30. UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 56.0f)];
  31. self.youpaiptableView.tableFooterView = footerV;
  32. UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  33. transformBtn.titleLabel.font = LCFont12;
  34. transformBtn.layer.cornerRadius = 20.0f;
  35. transformBtn.clipsToBounds = YES;
  36. [transformBtn setTitle:@"换一批" forState:0];
  37. [transformBtn addTarget:self action:@selector(youpaiploadData) forControlEvents:UIControlEventTouchUpInside];
  38. [transformBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal];
  39. transformBtn.layer.borderColor = LZ7C69FEColor.CGColor;
  40. transformBtn.layer.borderWidth = 1.0f;
  41. [footerV addSubview:transformBtn];
  42. [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.offset(16.0f);
  44. make.centerX.equalTo(footerV.mas_centerX);
  45. make.size.mas_offset(CGSizeMake(125.0f, 40.0f));
  46. }];
  47. }
  48. - (void)youpaifinitUI{
  49. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  50. tableView.dataSource = self;
  51. tableView.delegate = self;
  52. tableView.rowHeight = 54.0f;
  53. tableView.estimatedRowHeight = 54.0f;
  54. tableView.estimatedSectionHeaderHeight = 0.0f;
  55. tableView.estimatedSectionFooterHeight = 0.0f;
  56. tableView.backgroundColor = [UIColor clearColor];
  57. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  58. [self.view addSubview:tableView];
  59. self.youpaiptableView = tableView;
  60. [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  61. make.left.bottom.right.offset(0.0f);
  62. make.top.offset(NavBarHeight);
  63. }];
  64. [self youpaifinitFooterView];
  65. }
  66. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  67. return self.youpaipdataSource.count;
  68. }
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  70. YOUPAILZCommonWordCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(YOUPAILZCommonWordCell.class)];
  71. if (cell == nil) {
  72. cell = [[YOUPAILZCommonWordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(YOUPAILZCommonWordCell.class)];
  73. }
  74. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
  75. return cell;
  76. }
  77. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  78. return CGFLOAT_MIN;
  79. }
  80. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  81. return CGFLOAT_MIN;
  82. }
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  84. NIMSession *session = [NIMSession session:self.youpaipto_uid type:NIMSessionTypeP2P];
  85. NIMMessage *imMessage = [NIMMessageMaker msgWithText:self.youpaipdataSource[indexPath.row].youpaipword];
  86. @weakify(self);
  87. [YOUPAILCIMTool sendMessage:imMessage sessionid:session.sessionId completion:^(NIMMessage *resultMsg,NSInteger filter,NSString *contentStr) {
  88. @strongify(self);
  89. if (filter==0) {
  90. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  91. }else{
  92. resultMsg.text = contentStr;
  93. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  94. }
  95. [self.navigationController popViewControllerAnimated:YES];
  96. }];
  97. }
  98. - (void)youpaiploadData{
  99. @weakify(self);
  100. [LCHttpHelper requestWithURLString:GetCommonWord parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  101. @strongify(self);
  102. NSDictionary* dict = (NSDictionary*)responseObject;
  103. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  104. if (code==0) {//成功
  105. self.youpaipdataSource = [YOUPAILZIMCommonWordModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  106. [self.youpaiptableView reloadData];
  107. }
  108. } failure:^(NSError *error) {
  109. }];
  110. }
  111. @end