FwzBaseView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. //
  2. // FwzBaseView.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/12.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "FwzBaseView.h"
  9. #import "WorkListCell.h"
  10. #import "HomeTableViewCell.h"
  11. #import "DocumentModel.h"
  12. #import "ChannelModel.h"
  13. #import "MyApprovalBCell.h"
  14. #import <YYModel/YYModel.h>
  15. @interface FwzBaseView()
  16. @property (nonatomic, assign)NSInteger currentChannel; //暂存id
  17. @property (nonatomic, assign)NSInteger page; //暂存id
  18. @property (nonatomic, strong) NSMutableArray *dataArr;
  19. @property (nonatomic, strong) NSMutableArray *waitArray;
  20. @property (nonatomic, strong) ChannelModel *channelModel;
  21. @property (nonatomic, strong) UILabel *noDataMessageLbl;
  22. @property (nonatomic, assign)NSInteger currentChannelID; // groupId
  23. @end
  24. @implementation FwzBaseView
  25. - (instancetype)initWithFrame:(CGRect)frame channel:(NSInteger)channel ChannelId:(NSInteger)channelId {
  26. if (self = [super initWithFrame:frame]) {
  27. _currentChannel = channel;
  28. _currentChannelID = channelId;
  29. self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
  30. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 67, 0);
  31. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  32. self.tableView.showsHorizontalScrollIndicator = NO;
  33. self.tableView.showsVerticalScrollIndicator = NO;
  34. [self addSubview:self.tableView];
  35. self.tableView.delegate = self;
  36. self.tableView.dataSource = self;
  37. self.page = 1;
  38. [self.tableView registerNib:[UINib nibWithNibName:@"MyApprovalBCell" bundle:nil] forCellReuseIdentifier:@"MyApprovalBCell"];
  39. self.tableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
  40. if (self.currentChannel == 1){
  41. [self.waitArray removeAllObjects];
  42. [self updateNewWaitWork];
  43. }
  44. else {
  45. [self.dataArr removeAllObjects];
  46. [self updateNew];
  47. }
  48. }];
  49. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  50. if (self.currentChannel == 1){
  51. [self addMoreWaitWork];
  52. }else{
  53. [self addMore];
  54. }
  55. }];
  56. }
  57. return self;
  58. }
  59. - (UILabel *)noDataMessageLbl {
  60. if (!_noDataMessageLbl) {
  61. _noDataMessageLbl = [[UILabel alloc] init];
  62. _noDataMessageLbl.font = [UIFont systemFontOfSize:15];
  63. _noDataMessageLbl.text = @"暂无数据";
  64. _noDataMessageLbl.textColor = [UIColor colorWithHexString:@"BBBBBB"];
  65. _noDataMessageLbl.textAlignment = NSTextAlignmentCenter;
  66. _noDataMessageLbl.hidden = YES;
  67. }
  68. return _noDataMessageLbl;
  69. }
  70. - (void)addNoDataMessageToViewCenter:(UIView *)contentView message:(NSString *)message {
  71. [self.noDataMessageLbl removeFromSuperview];
  72. self.noDataMessageLbl.text = message;
  73. [contentView addSubview:self.noDataMessageLbl];
  74. [self.noDataMessageLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.centerY.equalTo(contentView.mas_centerY);
  76. make.centerX.equalTo(contentView.mas_centerX);
  77. make.height.mas_equalTo(30);
  78. }];
  79. }
  80. - (void)changeMessageStatusWithNumber:(NSInteger)number {
  81. if (number > 0) {
  82. self.noDataMessageLbl.hidden = YES;
  83. }else {
  84. self.noDataMessageLbl.hidden = NO;
  85. }
  86. }
  87. - (void)reloadData {
  88. [self.tableView.mj_header beginRefreshing];
  89. }
  90. /// 根据channelID刷新对应的tableview
  91. - (void)renderUIWithInfoChannelId:(NSInteger)channelId withFrame:(CGRect) frame{
  92. [self requestContent];
  93. // if ([_channelModel.channelId integerValue] == 1) {
  94. // [self updateNewWaitWork];
  95. // }else{
  96. // [self updateNew];
  97. // }
  98. //[self requestContent];
  99. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptMsg:) name:TABLETOP object:nil];
  100. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptMsg:) name:TABLELEAVETOP object:nil];
  101. }
  102. - (void)requestContent {
  103. self.dataArr = [NSMutableArray arrayWithArray:self.artModel.Items];
  104. NSLog(@"FwzBaseView - requestContent首页数据%@",self.dataArr);
  105. self.waitArray = [NSMutableArray arrayWithArray:self.waitModel.Items];
  106. [self.tableView reloadData];
  107. if (_currentChannel == 1) {
  108. [self changeMessageStatusWithNumber:self.waitArray.count];
  109. }else {
  110. [self changeMessageStatusWithNumber:self.dataArr.count];
  111. }
  112. }
  113. - (void)acceptMsg:(NSNotification *)notification{
  114. NSString *notificationName = notification.name;
  115. if ([notificationName isEqualToString:TABLETOP]) {
  116. NSDictionary *userInfo = notification.userInfo;
  117. NSString *canScroll = userInfo[@"canScroll"];
  118. if ([canScroll isEqualToString:@"1"]) {
  119. self.canScroll = YES;
  120. self.tableView.showsVerticalScrollIndicator = YES;
  121. }
  122. }else if ([notificationName isEqualToString:TABLELEAVETOP]){
  123. self.tableView.showsVerticalScrollIndicator = NO;
  124. self.tableView.contentOffset = CGPointZero;
  125. }
  126. }
  127. - (void)dealloc{
  128. [[NSNotificationCenter defaultCenter] removeObserver:self];
  129. }
  130. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  131. if (_currentChannel == 1) {
  132. return self.waitArray.count;
  133. } else {
  134. return self.dataArr.count;
  135. }
  136. }
  137. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  138. if (_currentChannel == 1) {
  139. return 159.f;
  140. }
  141. Item *model = self.dataArr[indexPath.row];
  142. if (model.ImageUrls.count == 0) {
  143. model.cellID = 1;
  144. }else if(model.ImageUrls.count == 1){
  145. model.cellID = 2;
  146. }else{
  147. model.cellID = 3;
  148. }
  149. switch (model.cellID) {
  150. case 1:
  151. {
  152. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
  153. label.text = model.Title;
  154. label.font = [UIFont systemFontOfSize:18];
  155. label.numberOfLines = 2;
  156. CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
  157. CGSize newSize = [label sizeThatFits:maxSize];
  158. int height = 50 + newSize.height;
  159. return height;
  160. }
  161. break;
  162. case 2:
  163. return 115;
  164. break;
  165. case 3:
  166. {
  167. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
  168. label.text = model.Title;
  169. label.font = [UIFont systemFontOfSize:18];
  170. label.numberOfLines = 2;
  171. CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
  172. CGSize newSize = [label sizeThatFits:maxSize];
  173. int height = 86 * (kGXScreenWidth / 375.0) + 67 + newSize.height;
  174. return height;
  175. }
  176. break;
  177. default:
  178. return 70;
  179. break;
  180. }
  181. }
  182. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  183. // 待办工作
  184. if (_currentChannel == 1) {
  185. NSString *cellIdentifier = @"MyApprovalBCell";
  186. MyApprovalBCell *cell = (MyApprovalBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  187. cell.falgLab.hidden =YES;
  188. [cell loadDictionArray:self.waitArray[indexPath.row]];
  189. return cell;
  190. }
  191. // 推荐
  192. Item *model = self.dataArr[indexPath.row];
  193. if (model.ImageUrls.count == 0) {
  194. model.cellID = 1;
  195. }else if(model.ImageUrls.count == 1){
  196. model.cellID = 2;
  197. }else{
  198. model.cellID = 3;
  199. }
  200. HomeTableViewCell *cell = [HomeTableViewCell cellWithTableView:tableView AndIndex:model.cellID];
  201. [cell loadCurrentItemModel:model];
  202. WEAKSELF
  203. cell.buttonBlock = ^{
  204. STRONGSELF
  205. if ([strongSelf.delegate respondsToSelector:@selector(didCloseAddButtonChannel:andWith:)]) {
  206. NSLog(@"1点击不感兴趣的");
  207. [strongSelf.delegate didCloseAddButtonChannel:strongSelf.channelModel andWith: model];
  208. NSLog(@"2点击不感兴趣的");
  209. }
  210. };
  211. return cell;
  212. }
  213. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  214. if(_currentChannel == 1){
  215. NSLog(@"待办事项1");
  216. if ([self.delegate respondsToSelector:@selector(didClickWaitWorkChannel:andWith:)]) {
  217. NSLog(@"待办事项2");
  218. [self.delegate didClickWaitWorkChannel:self.channelModel andWith:self.waitArray[indexPath.row]];
  219. }
  220. } else {
  221. if ([self.delegate respondsToSelector:@selector(didClickAddButtonChannel:andWith:)]) {
  222. [self.delegate didClickAddButtonChannel:self.channelModel andWith:self.dataArr[indexPath.row]];
  223. }
  224. }
  225. }
  226. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  227. }
  228. - (NSMutableArray *)dataArr{
  229. if (!_dataArr) {
  230. _dataArr = [NSMutableArray array];
  231. }
  232. return _dataArr;
  233. }
  234. - (ChannelModel *)channelModel{
  235. if (!_channelModel) {
  236. _channelModel = [[ChannelModel alloc]init];
  237. }
  238. return _channelModel;
  239. }
  240. #pragma mark -文章数据刷新。
  241. /// 推荐数据
  242. - (void)updateNew{
  243. WS(weakSelf);
  244. self.page = 1;
  245. [self homeDataSecondAdd:self.page success:^(id responseObject) {
  246. [weakSelf.tableView.mj_footer resetNoMoreData];
  247. NSDictionary *dic = (NSDictionary *)responseObject;
  248. HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic];
  249. // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil];
  250. weakSelf.dataArr = [[NSMutableArray alloc] initWithArray:model.Items];
  251. [weakSelf.tableView.mj_header endRefreshing];
  252. [weakSelf changeMessageStatusWithNumber:weakSelf.dataArr.count];
  253. dispatch_async(dispatch_get_main_queue(), ^{
  254. [weakSelf.tableView reloadData];
  255. });
  256. } failure:^(NSError *error) {
  257. [weakSelf.tableView.mj_header endRefreshing];
  258. SHOWERROR([ZYCTool handerResultData:error]);
  259. }];
  260. }
  261. - (void)addMore{
  262. self.page += 1;
  263. WS(weakSelf);
  264. [self homeDataSecondAdd:self.page success:^(id responseObject) {
  265. [weakSelf.tableView.mj_footer endRefreshing];
  266. NSDictionary *dic = (NSDictionary *)responseObject;
  267. HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic];
  268. // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil];
  269. [weakSelf.dataArr addObjectsFromArray:model.Items];
  270. if (model.Items.count < 10) {
  271. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  272. }
  273. dispatch_async(dispatch_get_main_queue(), ^{
  274. [weakSelf.tableView reloadData];
  275. });
  276. } failure:^(NSError *error) {
  277. [weakSelf.tableView.mj_footer endRefreshing];
  278. SHOWERROR([ZYCTool handerResultData:error]);
  279. }];
  280. }
  281. // 网络请求
  282. - (void)homeDataSecondAdd:(NSInteger)page success:(void (^)(id responseObject))successful failure:(void (^) (NSError *error))failure {
  283. NSDictionary *paraDic = @{
  284. @"page":@(page),
  285. @"perPage":@10,
  286. @"GroupId":@(self.currentChannelID)
  287. };
  288. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: paraDic responseStyle:JOSN success:^(id _Nonnull responseObject) {
  289. successful(responseObject);
  290. } failure:^(NSError * _Nonnull error) {
  291. failure(error);
  292. }];
  293. }
  294. /// 待办事项数据
  295. - (void)updateNewWaitWork{
  296. self.page = 1;
  297. [self.waitArray removeAllObjects];
  298. WS(weakSelf);
  299. [self homeWaitWorkAdd:self.page success:^(id responseObject) {
  300. NSDictionary *dic = (NSDictionary *)responseObject;
  301. TDWaitWorkModel *model = [[TDWaitWorkModel alloc] initWithDictionary:dic error:nil];
  302. [weakSelf.waitArray addObjectsFromArray:model.Items.mutableCopy];
  303. [weakSelf.tableView.mj_header endRefreshing];
  304. if (model.Count == weakSelf.waitArray.count) {
  305. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  306. }
  307. [weakSelf.tableView.mj_footer resetNoMoreData];
  308. dispatch_async(dispatch_get_main_queue(), ^{
  309. [weakSelf.tableView reloadData];
  310. });
  311. [weakSelf changeMessageStatusWithNumber:self.waitArray.count];
  312. } failure:^(NSError *error) {
  313. [weakSelf.tableView.mj_header endRefreshing];
  314. SHOWERROR([ZYCTool handerResultData:error]);
  315. }];
  316. }
  317. - (void)addMoreWaitWork{
  318. WS(weakSelf);
  319. self.page += 1;
  320. [self homeWaitWorkAdd:self.page success:^(id responseObject) {
  321. [weakSelf.tableView.mj_footer endRefreshing];
  322. NSDictionary *dic = (NSDictionary *)responseObject;
  323. TDWaitWorkModel *model = [[TDWaitWorkModel alloc] initWithDictionary:dic error:nil];
  324. [weakSelf.waitArray addObjectsFromArray:model.Items];
  325. if (model.Count == weakSelf.waitArray.count) {
  326. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  327. }
  328. dispatch_async(dispatch_get_main_queue(), ^{
  329. [weakSelf.tableView reloadData];
  330. });
  331. } failure:^(NSError *error) {
  332. [weakSelf.tableView.mj_footer endRefreshing];
  333. SHOWERROR([ZYCTool handerResultData:error]);
  334. }];
  335. }
  336. - (void)homeWaitWorkAdd:(NSInteger)page success:(void (^)(id responseObject))successful failure:(void (^) (NSError *error))failure {
  337. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowWaitFlowHande_Get] parameters:@{@"page":@(page),@"PerPage":@(10)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  338. successful(responseObject);
  339. } failure:^(NSError * _Nonnull error) {
  340. failure(error);
  341. }];
  342. }
  343. @end