CommonWorkVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // CommonWorkVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/4/28.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "CommonWorkVC.h"
  9. #import "WorkFLowModel.h"
  10. #import "WorkFLowCell.h"
  11. #import "myApprovalPageVC.h"
  12. #import "WorkFlowTabbarController.h"
  13. #import "MyWorkWordVC.h"
  14. #import "CountDataVC.h"
  15. #import "CommonToolMoveVC.h"
  16. @interface CommonWorkVC ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  17. @property (weak, nonatomic) IBOutlet UIButton *setBtn;
  18. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  19. /// 协同工作
  20. @property (nonatomic, strong) NSMutableArray<WorkFLowModel*> *dataArray;
  21. /// 数据报表
  22. @property (nonatomic, strong) NSMutableArray <WorkFLowModel*>*dataReportArray;
  23. @property (nonatomic, strong) WorkNumberModel *numberDic;
  24. @property (nonatomic,assign) NSInteger loadFlag;
  25. @end
  26. @implementation CommonWorkVC
  27. +(CommonWorkVC *)initCommonWorkVC{
  28. CommonWorkVC *controller = [StoryboardManager.shared.Common instantiateViewControllerWithIdentifier:@"CommonWorkVC"];
  29. return controller;
  30. }
  31. - (void)viewWillAppear:(BOOL)animated{
  32. [super viewWillAppear:animated];
  33. [self getData];
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.fd_prefersNavigationBarHidden = YES;
  38. [self.view setBackgroundColor:UIColorHex(0xf7f7f7)];
  39. [self createCollectionView];
  40. self.loadFlag = 1;
  41. WS(weakSelf);
  42. [self.setBtn setAction:^{
  43. CommonToolMoveVC * vc = [CommonToolMoveVC initCommonToolMoveVC];
  44. [weakSelf.navigationController pushViewController:vc animated:YES];
  45. }];
  46. }
  47. #pragma mark - 数据加载
  48. - (void)getData{
  49. [self.dataArray removeAllObjects];
  50. [self.dataReportArray removeAllObjects];
  51. // [self testData];
  52. self.loadFlag = 1;
  53. WS(weakSelf);
  54. [[HttpManager sharedHttpManager] GETUrl: [NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowHomeData_Post]parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  55. NSArray *array = responseObject;
  56. NSMutableArray *arr = [NSMutableArray array];
  57. for (NSDictionary *dic in array) {
  58. WorkFLowModel *mode = [[WorkFLowModel alloc] initWithDictionary:dic error:nil];
  59. [weakSelf.dataArray addObject:mode];
  60. }
  61. [weakSelf.dataArray addObjectsFromArray:arr];
  62. weakSelf.loadFlag += 1;
  63. if (weakSelf.loadFlag == 3) {
  64. REMOVESHOW
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. [weakSelf.collectionView reloadData];
  67. });
  68. }
  69. } failure:^(NSError * _Nonnull error) {
  70. }];
  71. //获取我审批和我发起以及抄送我的未读数
  72. // [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/user/user-uread-count"] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  73. // NSDictionary *dic = responseObject;
  74. // weakSelf.numberDic = [[WorkNumberModel alloc] initWithDictionary:dic error:nil];
  75. // weakSelf.navigationController.tabBarItem.badgeValue = [weakSelf.numberDic allNumber];
  76. // /// 我的审批未读数
  77. // weakSelf.dataArray.firstObject.workNumber = [dic[@"FlowAuditUReadCount"] integerValue];
  78. // for (WorkFLowModel *model in self.dataArray) {
  79. // if ([model.Name isEqualToString:@"我发起的"]) {
  80. // model.workNumber = [dic[@"FlowSendUReadCount"] integerValue];
  81. // }
  82. // if ([model.Name isEqualToString:@"抄送我的"]) {
  83. // model.workNumber = [dic[@"FlowCcUReadCount"] integerValue];
  84. // }
  85. // }
  86. // weakSelf.loadFlag += 1;
  87. // if (weakSelf.loadFlag == 4) {
  88. // REMOVESHOW
  89. // dispatch_async(dispatch_get_main_queue(), ^{
  90. // [weakSelf.collectionView reloadData];
  91. // });
  92. // }
  93. // } failure:^(NSError * _Nonnull error) {
  94. // }];
  95. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowHomeData2_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  96. NSArray *array = responseObject;
  97. NSLog(@"%@",responseObject);
  98. for (NSDictionary *dic in array) {
  99. WorkFLowModel *mode = [[WorkFLowModel alloc]initWithDictionary:dic error:nil];
  100. [weakSelf.dataReportArray addObject:mode];
  101. }
  102. weakSelf.loadFlag += 1;
  103. if (weakSelf.loadFlag == 3) {
  104. REMOVESHOW
  105. dispatch_async(dispatch_get_main_queue(), ^{
  106. [weakSelf.collectionView reloadData];
  107. });
  108. }
  109. } failure:^(NSError * _Nonnull error) {
  110. }];
  111. }
  112. - (void)testData{
  113. WorkFLowModel *mode1 = [[WorkFLowModel alloc] init];
  114. mode1.Name = @"我的审批";
  115. mode1.iconImage = IMG(@"work_flow_approvalme");
  116. mode1.workNumber = 0;
  117. [self.dataArray addObject:mode1];
  118. WorkFLowModel *mode2 = [[WorkFLowModel alloc] init];
  119. mode2.Name = @"我发起的";
  120. mode2.iconImage = IMG(@"work_flow_fromme");
  121. mode2.workNumber = 0;
  122. [self.dataArray addObject:mode2];
  123. WorkFLowModel *mode3 = [[WorkFLowModel alloc] init];
  124. mode3.Name = @"抄送我的";
  125. mode3.iconImage = IMG(@"work_flow_forme");
  126. mode3.workNumber = 0;
  127. [self.dataArray addObject:mode3];
  128. //
  129. // WorkFLowModel *mode13 = [[WorkFLowModel alloc] init];
  130. // mode13.Name = @"财务数据";
  131. // mode13.iconImage = IMG(@"work_flow_money_data");
  132. // mode13.workNumber = 0;
  133. // [self.dataReportArray addObject:mode13];
  134. //
  135. // WorkFLowModel *mode14 = [[WorkFLowModel alloc] init];
  136. // mode14.Name = @"出版数据";
  137. // mode14.iconImage = IMG(@"work_flow_version_data");
  138. // mode14.workNumber = 0;
  139. // [self.dataReportArray addObject:mode14];
  140. //
  141. // WorkFLowModel *mode15 = [[WorkFLowModel alloc] init];
  142. // mode15.Name = @"人事数据";
  143. // mode15.iconImage = IMG(@"work_flow_hr_data");
  144. // mode15.workNumber = 0;
  145. // [self.dataReportArray addObject:mode15];
  146. }
  147. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  148. return 2;
  149. }
  150. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  151. if (section == 0) {
  152. return self.dataArray.count;
  153. }else{
  154. return self.dataReportArray.count;
  155. }
  156. }
  157. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  158. return CGSizeMake((kGXScreenWidth -14)/3 ,(kGXScreenWidth -14)/3);
  159. }
  160. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  161. return UIEdgeInsetsMake(0, 0, 0, 0);
  162. }
  163. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  164. WorkFLowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WorkFLowCellID" forIndexPath:indexPath];
  165. WorkFLowModel *model = (indexPath.section == 0) ? self.dataArray[indexPath.item]:self.dataReportArray[indexPath.item];
  166. if (model.workNumber > 0) {
  167. NSString * count = [NSString stringWithFormat:@"%ld",(long)model.workNumber];
  168. UILabel * label = [UILabel new];
  169. label.font = [UIFont systemFontOfSize:12];
  170. label.text = count;
  171. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  172. cell.workNumberLab.layer.cornerRadius = 8;
  173. cell.workNumberLab.layer.masksToBounds = YES;
  174. if ((width + 5) < 16) {
  175. cell.width.constant = 16;
  176. }else{
  177. cell.width.constant = width + 8;
  178. }
  179. cell.workNumberLab.text = count;
  180. }
  181. if (model.workNumber == 0 ) {
  182. cell.workNumberLab.hidden = YES;
  183. cell.workNumberLab.layer.cornerRadius = 10;
  184. cell.workNumberLab.layer.masksToBounds = YES;
  185. }else{
  186. cell.workNumberLab.hidden = NO;
  187. }
  188. cell.titleLabel.text = model.Name;
  189. [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IconUrl] placeholder:IMG(@"work_flow_approvalme")];
  190. cell.leftLine.hidden = NO;
  191. cell.rightLine.hidden = NO;
  192. cell.bottomLine.hidden= NO;
  193. cell.topLine.hidden = NO;
  194. if (indexPath.section == 1) {
  195. cell.titleLabel.text = model.Title;
  196. [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IocUrl] placeholder:IMG(@"work_flow_approvalme")];
  197. }
  198. return cell;
  199. }
  200. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  201. WorkFLowModel *model = (indexPath.section == 0) ? self.dataArray[indexPath.item]:self.dataReportArray[indexPath.item];
  202. if (indexPath.section == 0) {
  203. // if (indexPath.item == 0 || indexPath.item == 1 || indexPath.item == 2) {
  204. // MyApprovalPageVC *myApprovalPageVC = [[MyApprovalPageVC alloc]init];
  205. // myApprovalPageVC.title = model.Name;
  206. // if (indexPath.item == 0) {
  207. // myApprovalPageVC.pageType = Type_ONEA;
  208. // }
  209. // if (indexPath.item == 1) {
  210. // myApprovalPageVC.pageType = Type_ONEB;
  211. // }
  212. // if (indexPath.item == 2) {
  213. // myApprovalPageVC.pageType = Type_ONEC;
  214. // }
  215. // myApprovalPageVC.numberDic = self.numberDic;
  216. // [self.navigationController pushViewController:myApprovalPageVC animated:YES];
  217. // }else{
  218. // if ([model.Name isEqualToString:@"会议"]) {
  219. // [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] animated:YES];
  220. // } else {
  221. // MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init];
  222. // workWordVC.title = model.Name;
  223. // workWordVC.pageType = Type_GongWen;
  224. // workWordVC.indexID = model.Id;
  225. // [self.navigationController pushViewController:workWordVC animated:YES];
  226. // }
  227. // }
  228. if ([model.Name isEqualToString:@"会议"]) {
  229. [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] animated:YES];
  230. } else {
  231. MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init];
  232. workWordVC.title = model.Name;
  233. workWordVC.pageType = Type_GongWen;
  234. workWordVC.indexID = model.Id;
  235. [self.navigationController pushViewController:workWordVC animated:YES];
  236. }
  237. }
  238. if (indexPath.section == 1) {
  239. WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath];
  240. if ([cell.titleLabel.text isEqualToString:@"财务统计"]) {
  241. CountDataVC *vc = [CountDataVC initCountDataVC];
  242. vc.index = 0;
  243. vc.titleStr = @"财务统计";
  244. [self.navigationController pushViewController:vc animated:YES];
  245. }
  246. if ([cell.titleLabel.text isEqualToString:@"人事统计"]) {
  247. CountDataVC *vc = [CountDataVC initCountDataVC];
  248. vc.index = 1;
  249. vc.titleStr = @"人事统计";
  250. [self.navigationController pushViewController:vc animated:YES];
  251. }
  252. if ([cell.titleLabel.text isEqualToString:@"出版统计"]) {
  253. CountDataVC *vc = [CountDataVC initCountDataVC];
  254. vc.index = 2;
  255. vc.titleStr = @"出版统计";
  256. [self.navigationController pushViewController:vc animated:YES];
  257. }
  258. // WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath];
  259. // if ([cell.titleLabel.text isEqualToString:@"财务统计"]) {
  260. // VersionDataVC *vc = [VersionDataVC initVersionDataVC];
  261. // vc.pageType = 1;
  262. // [self.navigationController pushViewController:vc animated:YES];
  263. // }
  264. // if ([cell.titleLabel.text isEqualToString:@"人事统计"]) {
  265. // VersionDataVC *vc = [VersionDataVC initVersionData3VC];
  266. // vc.pageType = 3;
  267. // [self.navigationController pushViewController:vc animated:YES];
  268. // }
  269. // if ([cell.titleLabel.text isEqualToString:@"出版统计"]) {
  270. // VersionDataVC *vc = [VersionDataVC initVersionData2VC];
  271. // vc.pageType = 2;
  272. // [self.navigationController pushViewController:vc animated:YES];
  273. // }
  274. }
  275. }
  276. #pragma mark - Setter
  277. - (NSMutableArray<WorkFLowModel*> *)dataArray{
  278. if (!_dataArray) {
  279. _dataArray = [NSMutableArray new];
  280. }
  281. return _dataArray;
  282. }
  283. - (NSMutableArray<WorkFLowModel *> *)dataReportArray{
  284. if (!_dataReportArray) {
  285. _dataReportArray = [NSMutableArray new];
  286. }
  287. return _dataReportArray;
  288. }
  289. - (void)createCollectionView {
  290. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  291. layout.minimumLineSpacing = 0;
  292. layout.minimumInteritemSpacing = 0;
  293. [self.collectionView setCollectionViewLayout:layout];
  294. self.collectionView.dataSource = self;
  295. self.collectionView.delegate = self;
  296. self.collectionView.layer.cornerRadius = 2;
  297. self.collectionView.layer.masksToBounds = YES;
  298. self.collectionView.backgroundColor = UIColorHex(F7F7F7);
  299. [self.collectionView registerNib:[UINib nibWithNibName:@"WorkFLowCell" bundle:nil] forCellWithReuseIdentifier:@"WorkFLowCellID"];
  300. [self.collectionView registerNib:[UINib nibWithNibName:@"MyChanelCollectionReusableViewTop" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyChanelCollectionReusableViewTop"];
  301. [self.collectionView registerNib:[UINib nibWithNibName:@"FootCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FootCollectionReusableView"];
  302. self.collectionView.backgroundColor = [UIColor whiteColor];
  303. [self.collectionView setShowsVerticalScrollIndicator:NO];
  304. [self.collectionView setShowsHorizontalScrollIndicator:NO];
  305. [self.view addSubview:self.collectionView];
  306. self.collectionView.backgroundColor = UIColorHex(F7F7F7);
  307. }
  308. @end