CommonWorkVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 referenceSizeForHeaderInSection:(NSInteger)section {
  158. // return CGSizeMake(kGXScreenWidth-14, 39);
  159. //}
  160. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  161. // return CGSizeMake(kGXScreenWidth-14, 20);
  162. //}
  163. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  164. return CGSizeMake((kGXScreenWidth -14)/3 ,(kGXScreenWidth -14)/3);
  165. }
  166. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  167. return UIEdgeInsetsMake(0, 0, 0, 0);
  168. }
  169. //func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
  170. // return UIEdgeInsetsZero
  171. //}
  172. //
  173. // func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
  174. // return 1
  175. //}
  176. //
  177. //func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
  178. // return 5
  179. //}
  180. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  181. WorkFLowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WorkFLowCellID" forIndexPath:indexPath];
  182. WorkFLowModel *model = (indexPath.section == 0) ? self.dataArray[indexPath.item]:self.dataReportArray[indexPath.item];
  183. if (model.workNumber > 0) {
  184. NSString * count = [NSString stringWithFormat:@"%ld",(long)model.workNumber];
  185. UILabel * label = [UILabel new];
  186. label.font = [UIFont systemFontOfSize:12];
  187. label.text = count;
  188. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  189. cell.workNumberLab.layer.cornerRadius = 8;
  190. cell.workNumberLab.layer.masksToBounds = YES;
  191. if ((width + 5) < 16) {
  192. cell.width.constant = 16;
  193. }else{
  194. cell.width.constant = width + 8;
  195. }
  196. cell.workNumberLab.text = count;
  197. }
  198. if (model.workNumber == 0 ) {
  199. cell.workNumberLab.hidden = YES;
  200. cell.workNumberLab.layer.cornerRadius = 10;
  201. cell.workNumberLab.layer.masksToBounds = YES;
  202. }else{
  203. cell.workNumberLab.hidden = NO;
  204. }
  205. cell.titleLabel.text = model.Name;
  206. [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IconUrl] placeholder:IMG(@"work_flow_approvalme")];
  207. cell.leftLine.hidden = NO;
  208. cell.rightLine.hidden = NO;
  209. cell.bottomLine.hidden= NO;
  210. cell.topLine.hidden = NO;
  211. if (indexPath.section == 1) {
  212. cell.titleLabel.text = model.Title;
  213. [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IocUrl] placeholder:IMG(@"work_flow_approvalme")];
  214. }
  215. return cell;
  216. }
  217. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  218. WorkFLowModel *model = (indexPath.section == 0) ? self.dataArray[indexPath.item]:self.dataReportArray[indexPath.item];
  219. if (indexPath.section == 0) {
  220. // if (indexPath.item == 0 || indexPath.item == 1 || indexPath.item == 2) {
  221. // MyApprovalPageVC *myApprovalPageVC = [[MyApprovalPageVC alloc]init];
  222. // myApprovalPageVC.title = model.Name;
  223. // if (indexPath.item == 0) {
  224. // myApprovalPageVC.pageType = Type_ONEA;
  225. // }
  226. // if (indexPath.item == 1) {
  227. // myApprovalPageVC.pageType = Type_ONEB;
  228. // }
  229. // if (indexPath.item == 2) {
  230. // myApprovalPageVC.pageType = Type_ONEC;
  231. // }
  232. // myApprovalPageVC.numberDic = self.numberDic;
  233. // [self.navigationController pushViewController:myApprovalPageVC animated:YES];
  234. // }else{
  235. // if ([model.Name isEqualToString:@"会议"]) {
  236. // [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] animated:YES];
  237. // } else {
  238. // MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init];
  239. // workWordVC.title = model.Name;
  240. // workWordVC.pageType = Type_GongWen;
  241. // workWordVC.indexID = model.Id;
  242. // [self.navigationController pushViewController:workWordVC animated:YES];
  243. // }
  244. // }
  245. if ([model.Name isEqualToString:@"会议"]) {
  246. [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] animated:YES];
  247. } else {
  248. MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init];
  249. workWordVC.title = model.Name;
  250. workWordVC.pageType = Type_GongWen;
  251. workWordVC.indexID = model.Id;
  252. [self.navigationController pushViewController:workWordVC animated:YES];
  253. }
  254. }
  255. if (indexPath.section == 1) {
  256. WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath];
  257. if ([cell.titleLabel.text isEqualToString:@"财务统计"]) {
  258. CountDataVC *vc = [CountDataVC initCountDataVC];
  259. vc.index = 0;
  260. vc.titleStr = @"财务统计";
  261. [self.navigationController pushViewController:vc animated:YES];
  262. }
  263. if ([cell.titleLabel.text isEqualToString:@"人事统计"]) {
  264. CountDataVC *vc = [CountDataVC initCountDataVC];
  265. vc.index = 1;
  266. vc.titleStr = @"人事统计";
  267. [self.navigationController pushViewController:vc animated:YES];
  268. }
  269. if ([cell.titleLabel.text isEqualToString:@"出版统计"]) {
  270. CountDataVC *vc = [CountDataVC initCountDataVC];
  271. vc.index = 2;
  272. vc.titleStr = @"出版统计";
  273. [self.navigationController pushViewController:vc animated:YES];
  274. }
  275. // WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath];
  276. // if ([cell.titleLabel.text isEqualToString:@"财务统计"]) {
  277. // VersionDataVC *vc = [VersionDataVC initVersionDataVC];
  278. // vc.pageType = 1;
  279. // [self.navigationController pushViewController:vc animated:YES];
  280. // }
  281. // if ([cell.titleLabel.text isEqualToString:@"人事统计"]) {
  282. // VersionDataVC *vc = [VersionDataVC initVersionData3VC];
  283. // vc.pageType = 3;
  284. // [self.navigationController pushViewController:vc animated:YES];
  285. // }
  286. // if ([cell.titleLabel.text isEqualToString:@"出版统计"]) {
  287. // VersionDataVC *vc = [VersionDataVC initVersionData2VC];
  288. // vc.pageType = 2;
  289. // [self.navigationController pushViewController:vc animated:YES];
  290. // }
  291. }
  292. }
  293. #pragma mark - Setter
  294. - (NSMutableArray<WorkFLowModel*> *)dataArray{
  295. if (!_dataArray) {
  296. _dataArray = [NSMutableArray new];
  297. }
  298. return _dataArray;
  299. }
  300. - (NSMutableArray<WorkFLowModel *> *)dataReportArray{
  301. if (!_dataReportArray) {
  302. _dataReportArray = [NSMutableArray new];
  303. }
  304. return _dataReportArray;
  305. }
  306. - (void)createCollectionView {
  307. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  308. layout.minimumLineSpacing = 0;
  309. layout.minimumInteritemSpacing = 0;
  310. [self.collectionView setCollectionViewLayout:layout];
  311. self.collectionView.dataSource = self;
  312. self.collectionView.delegate = self;
  313. self.collectionView.layer.cornerRadius = 2;
  314. self.collectionView.layer.masksToBounds = YES;
  315. self.collectionView.backgroundColor = UIColorHex(F7F7F7);
  316. [self.collectionView registerNib:[UINib nibWithNibName:@"WorkFLowCell" bundle:nil] forCellWithReuseIdentifier:@"WorkFLowCellID"];
  317. [self.collectionView registerNib:[UINib nibWithNibName:@"MyChanelCollectionReusableViewTop" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyChanelCollectionReusableViewTop"];
  318. [self.collectionView registerNib:[UINib nibWithNibName:@"FootCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FootCollectionReusableView"];
  319. self.collectionView.backgroundColor = [UIColor whiteColor];
  320. [self.collectionView setShowsVerticalScrollIndicator:NO];
  321. [self.collectionView setShowsHorizontalScrollIndicator:NO];
  322. [self.view addSubview:self.collectionView];
  323. self.collectionView.backgroundColor = UIColorHex(F7F7F7);
  324. }
  325. @end