123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- //
- // FwzBaseView.m
- // smartRhino
- //
- // Created by tederen on 2019/11/12.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "FwzBaseView.h"
- #import "WorkListCell.h"
- #import "HomeTableViewCell.h"
- #import "DocumentModel.h"
- #import "ChannelModel.h"
- #import "MyApprovalBCell.h"
- #import <YYModel/YYModel.h>
- @interface FwzBaseView()
- @property (nonatomic, assign)NSInteger currentChannel; //暂存id
- @property (nonatomic, assign)NSInteger page; //暂存id
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, strong) NSMutableArray *waitArray;
- @property (nonatomic, strong) ChannelModel *channelModel;
- @property (nonatomic, strong) UILabel *noDataMessageLbl;
- @property (nonatomic, assign)NSInteger currentChannelID; // groupId
- @end
- @implementation FwzBaseView
- - (instancetype)initWithFrame:(CGRect)frame channel:(NSInteger)channel ChannelId:(NSInteger)channelId {
- if (self = [super initWithFrame:frame]) {
- _currentChannel = channel;
- _currentChannelID = channelId;
- self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
- self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 67, 0);
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.showsHorizontalScrollIndicator = NO;
- self.tableView.showsVerticalScrollIndicator = NO;
- [self addSubview:self.tableView];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.page = 1;
- [self.tableView registerNib:[UINib nibWithNibName:@"MyApprovalBCell" bundle:nil] forCellReuseIdentifier:@"MyApprovalBCell"];
- self.tableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
- if (self.currentChannel == 1){
- [self.waitArray removeAllObjects];
- [self updateNewWaitWork];
- }
- else {
- [self.dataArr removeAllObjects];
- [self updateNew];
- }
- }];
-
- self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- if (self.currentChannel == 1){
- [self addMoreWaitWork];
- }else{
- [self addMore];
- }
- }];
- }
- return self;
- }
- - (UILabel *)noDataMessageLbl {
- if (!_noDataMessageLbl) {
- _noDataMessageLbl = [[UILabel alloc] init];
- _noDataMessageLbl.font = [UIFont systemFontOfSize:15];
- _noDataMessageLbl.text = @"暂无数据";
- _noDataMessageLbl.textColor = [UIColor colorWithHexString:@"BBBBBB"];
- _noDataMessageLbl.textAlignment = NSTextAlignmentCenter;
- _noDataMessageLbl.hidden = YES;
- }
- return _noDataMessageLbl;
- }
- - (void)addNoDataMessageToViewCenter:(UIView *)contentView message:(NSString *)message {
- [self.noDataMessageLbl removeFromSuperview];
- self.noDataMessageLbl.text = message;
- [contentView addSubview:self.noDataMessageLbl];
- [self.noDataMessageLbl mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(contentView.mas_centerY);
- make.centerX.equalTo(contentView.mas_centerX);
- make.height.mas_equalTo(30);
- }];
- }
- - (void)changeMessageStatusWithNumber:(NSInteger)number {
- if (number > 0) {
- self.noDataMessageLbl.hidden = YES;
- }else {
- self.noDataMessageLbl.hidden = NO;
- }
- }
- - (void)reloadData {
- [self.tableView.mj_header beginRefreshing];
- }
- /// 根据channelID刷新对应的tableview
- - (void)renderUIWithInfoChannelId:(NSInteger)channelId withFrame:(CGRect) frame{
-
- [self requestContent];
- // if ([_channelModel.channelId integerValue] == 1) {
- // [self updateNewWaitWork];
- // }else{
- // [self updateNew];
- // }
-
- //[self requestContent];
-
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptMsg:) name:TABLETOP object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptMsg:) name:TABLELEAVETOP object:nil];
- }
- - (void)requestContent {
- self.dataArr = [NSMutableArray arrayWithArray:self.artModel.Items];
- NSLog(@"FwzBaseView - requestContent首页数据%@",self.dataArr);
- self.waitArray = [NSMutableArray arrayWithArray:self.waitModel.Items];
- [self.tableView reloadData];
- if (_currentChannel == 1) {
- [self changeMessageStatusWithNumber:self.waitArray.count];
- }else {
- [self changeMessageStatusWithNumber:self.dataArr.count];
- }
- }
- - (void)acceptMsg:(NSNotification *)notification{
- NSString *notificationName = notification.name;
- if ([notificationName isEqualToString:TABLETOP]) {
- NSDictionary *userInfo = notification.userInfo;
- NSString *canScroll = userInfo[@"canScroll"];
- if ([canScroll isEqualToString:@"1"]) {
- self.canScroll = YES;
- self.tableView.showsVerticalScrollIndicator = YES;
- }
- }else if ([notificationName isEqualToString:TABLELEAVETOP]){
- self.tableView.showsVerticalScrollIndicator = NO;
- self.tableView.contentOffset = CGPointZero;
- }
- }
- - (void)dealloc{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (_currentChannel == 1) {
- return self.waitArray.count;
- } else {
- return self.dataArr.count;
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (_currentChannel == 1) {
- return 159.f;
- }
- Item *model = self.dataArr[indexPath.row];
- if (model.ImageUrls.count == 0) {
- model.cellID = 1;
- }else if(model.ImageUrls.count == 1){
- model.cellID = 2;
- }else{
- model.cellID = 3;
- }
- switch (model.cellID) {
- case 1:
- {
- UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
- label.text = model.Title;
- label.font = [UIFont systemFontOfSize:18];
- label.numberOfLines = 2;
- CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
- CGSize newSize = [label sizeThatFits:maxSize];
- int height = 50 + newSize.height;
- return height;
- }
- break;
- case 2:
- return 115;
- break;
- case 3:
- {
- UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
- label.text = model.Title;
- label.font = [UIFont systemFontOfSize:18];
- label.numberOfLines = 2;
- CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
- CGSize newSize = [label sizeThatFits:maxSize];
- int height = 86 * (kGXScreenWidth / 375.0) + 67 + newSize.height;
- return height;
- }
- break;
- default:
- return 70;
- break;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- // 待办工作
- if (_currentChannel == 1) {
- NSString *cellIdentifier = @"MyApprovalBCell";
- MyApprovalBCell *cell = (MyApprovalBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- cell.falgLab.hidden =YES;
- [cell loadDictionArray:self.waitArray[indexPath.row]];
- return cell;
- }
-
- // 推荐
- Item *model = self.dataArr[indexPath.row];
- if (model.ImageUrls.count == 0) {
- model.cellID = 1;
- }else if(model.ImageUrls.count == 1){
- model.cellID = 2;
- }else{
- model.cellID = 3;
- }
- HomeTableViewCell *cell = [HomeTableViewCell cellWithTableView:tableView AndIndex:model.cellID];
- [cell loadCurrentItemModel:model];
- WEAKSELF
- cell.buttonBlock = ^{
- STRONGSELF
- if ([strongSelf.delegate respondsToSelector:@selector(didCloseAddButtonChannel:andWith:)]) {
- NSLog(@"1点击不感兴趣的");
- [strongSelf.delegate didCloseAddButtonChannel:strongSelf.channelModel andWith: model];
- NSLog(@"2点击不感兴趣的");
- }
- };
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if(_currentChannel == 1){
- NSLog(@"待办事项1");
- if ([self.delegate respondsToSelector:@selector(didClickWaitWorkChannel:andWith:)]) {
- NSLog(@"待办事项2");
- [self.delegate didClickWaitWorkChannel:self.channelModel andWith:self.waitArray[indexPath.row]];
- }
- } else {
- if ([self.delegate respondsToSelector:@selector(didClickAddButtonChannel:andWith:)]) {
- [self.delegate didClickAddButtonChannel:self.channelModel andWith:self.dataArr[indexPath.row]];
- }
- }
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
- }
- - (NSMutableArray *)dataArr{
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (ChannelModel *)channelModel{
- if (!_channelModel) {
- _channelModel = [[ChannelModel alloc]init];
- }
- return _channelModel;
- }
- #pragma mark -文章数据刷新。
- /// 推荐数据
- - (void)updateNew{
- WS(weakSelf);
- self.page = 1;
- [self homeDataSecondAdd:self.page success:^(id responseObject) {
- [weakSelf.tableView.mj_footer resetNoMoreData];
- NSDictionary *dic = (NSDictionary *)responseObject;
- HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic];
- // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil];
- weakSelf.dataArr = [[NSMutableArray alloc] initWithArray:model.Items];
- [weakSelf.tableView.mj_header endRefreshing];
- [weakSelf changeMessageStatusWithNumber:weakSelf.dataArr.count];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- } failure:^(NSError *error) {
- [weakSelf.tableView.mj_header endRefreshing];
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)addMore{
- self.page += 1;
- WS(weakSelf);
- [self homeDataSecondAdd:self.page success:^(id responseObject) {
- [weakSelf.tableView.mj_footer endRefreshing];
- NSDictionary *dic = (NSDictionary *)responseObject;
- HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic];
- // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil];
- [weakSelf.dataArr addObjectsFromArray:model.Items];
- if (model.Items.count < 10) {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- } failure:^(NSError *error) {
- [weakSelf.tableView.mj_footer endRefreshing];
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- // 网络请求
- - (void)homeDataSecondAdd:(NSInteger)page success:(void (^)(id responseObject))successful failure:(void (^) (NSError *error))failure {
- NSDictionary *paraDic = @{
- @"page":@(page),
- @"perPage":@10,
- @"GroupId":@(self.currentChannelID)
- };
- [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: paraDic responseStyle:JOSN success:^(id _Nonnull responseObject) {
- successful(responseObject);
- } failure:^(NSError * _Nonnull error) {
- failure(error);
- }];
- }
- /// 待办事项数据
- - (void)updateNewWaitWork{
- self.page = 1;
- [self.waitArray removeAllObjects];
- WS(weakSelf);
- [self homeWaitWorkAdd:self.page success:^(id responseObject) {
- NSDictionary *dic = (NSDictionary *)responseObject;
- TDWaitWorkModel *model = [[TDWaitWorkModel alloc] initWithDictionary:dic error:nil];
- [weakSelf.waitArray addObjectsFromArray:model.Items.mutableCopy];
- [weakSelf.tableView.mj_header endRefreshing];
- if (model.Count == weakSelf.waitArray.count) {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- [weakSelf.tableView.mj_footer resetNoMoreData];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- [weakSelf changeMessageStatusWithNumber:self.waitArray.count];
- } failure:^(NSError *error) {
- [weakSelf.tableView.mj_header endRefreshing];
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)addMoreWaitWork{
- WS(weakSelf);
- self.page += 1;
- [self homeWaitWorkAdd:self.page success:^(id responseObject) {
- [weakSelf.tableView.mj_footer endRefreshing];
- NSDictionary *dic = (NSDictionary *)responseObject;
- TDWaitWorkModel *model = [[TDWaitWorkModel alloc] initWithDictionary:dic error:nil];
- [weakSelf.waitArray addObjectsFromArray:model.Items];
- if (model.Count == weakSelf.waitArray.count) {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- } failure:^(NSError *error) {
- [weakSelf.tableView.mj_footer endRefreshing];
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)homeWaitWorkAdd:(NSInteger)page success:(void (^)(id responseObject))successful failure:(void (^) (NSError *error))failure {
- [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowWaitFlowHande_Get] parameters:@{@"page":@(page),@"PerPage":@(10)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- successful(responseObject);
- } failure:^(NSError * _Nonnull error) {
- failure(error);
- }];
- }
- @end
|