JXVIPDetailViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // JXVIPDetailViewController.m
  3. // shiku_im
  4. //
  5. // Created by cindy on 2020/5/29.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXVIPDetailViewController.h"
  9. #import "XFStepView.h"
  10. #import "JXVipCenterView.h"
  11. #import "JXMyModel.h"
  12. #import "JXVipDetailHeaderView.h"
  13. #import "JXVipDetailCenterView.h"
  14. #import "JXVipDetailBottomView.h"
  15. #import "LabelSize.h"
  16. #import "Common.h"
  17. @interface JXVIPDetailViewController ()<JXVipDetailCenterViewDelegate>
  18. @property (nonatomic, strong) UIScrollView *mainScrollView;
  19. @property (nonatomic, strong) JXVipDetailHeaderView *headerView;//头部UI
  20. @property (nonatomic, strong)JXVipDetailCenterView *centerView;
  21. @property (nonatomic, strong)JXVipDetailBottomView *bottomView;
  22. @property (nonatomic,strong) NSMutableArray *dataArr;
  23. @property (nonatomic,assign) int page;
  24. @property (nonatomic,strong) NSDictionary *getUserDict;
  25. @end
  26. @implementation JXVIPDetailViewController
  27. - (void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. [self.navigationController setNavigationBarHidden:NO];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. _getUserDict=[NSDictionary dictionary];
  34. _dataArr=[NSMutableArray array];
  35. //自定义导航栏
  36. [self _createdNavigationBar];
  37. //创建View
  38. [self _createdViews];
  39. }
  40. //自定义导航栏
  41. - (void)_createdNavigationBar {
  42. self.navigationItem.title=@"VIP特权";
  43. long time = (long)[[NSDate date] timeIntervalSince1970];
  44. time = (time *1000 + g_server.timeDifference);
  45. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  46. ///user/vip/info /user/vip/info
  47. //[g_server getact_act_userGradelistGrade:salt andToView:self];
  48. [SVProgressHUD show];
  49. [g_server getUserVipInformation:salt andToView:self];
  50. [g_server getUser:g_server.myself.userId toView:self];
  51. }
  52. #pragma mark --- 请求成功
  53. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  54. //NSLog(@"dict: %@ --- arry: %@",dict ,array1 );
  55. if([aDownload.action isEqualToString:act_UserGet]){
  56. //头像
  57. [g_server delHeadImage:g_server.myself.userId];
  58. [g_server getHeadImageSmall:g_server.myself.userId userName:g_server.myself.userNickname imageView:self.headerView.headerImageView];
  59. //昵称
  60. self.headerView.nameLabel.text = [NSString stringWithFormat:@"%@",dict[@"membershipAccount"]];
  61. if ([dict[@"gradeIndex"] isEqualToNumber:@0]) {
  62. self.headerView.myGradeBigBackView.image=[UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",@"1"]];
  63. }
  64. self.headerView.myGradeBigBackView.image=[UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",dict[@"gradeIndex"]]];
  65. if ([dict[@"gradeIndex"] intValue]>=2) {
  66. self.headerView.myGradeView.image = [UIImage imageNamed:[NSString stringWithFormat:@"组%d",[dict[@"gradeIndex"] intValue]+43]];
  67. }else{
  68. self.headerView.myGradeView.image = [UIImage imageNamed:[NSString stringWithFormat:@"组%d",[dict[@"gradeIndex"] intValue]+42]];
  69. }
  70. //右边等级值
  71. self.headerView.numberLabel.text = [NSString stringWithFormat:@"%@",dict[@"gradeIndex"]];
  72. // rechargeMoney
  73. //进度条左右按钮
  74. // dict[@"gradeIndex"] = @"10";
  75. if ([dict[@"gradeIndex"] intValue]>=10) {
  76. [self.headerView.leftGradeButton setTitle:[NSString stringWithFormat:@"%d级",9] forState:UIControlStateNormal];
  77. [self.headerView.nextGradeButton setTitle:[NSString stringWithFormat:@"%d级",10] forState:UIControlStateNormal];
  78. }else {
  79. NSString *vipleftIMG=[NSString stringWithFormat:@"%d级",[dict[@"gradeIndex"] intValue]];
  80. NSString *viprightIMG=[NSString stringWithFormat:@"%d级",[dict[@"gradeIndex"] intValue]+1];
  81. [self.headerView.leftGradeButton setTitle:vipleftIMG forState:UIControlStateNormal];
  82. [self.headerView.nextGradeButton setTitle:viprightIMG forState:UIControlStateNormal];
  83. }
  84. _getUserDict=dict;
  85. long time = (long)[[NSDate date] timeIntervalSince1970];
  86. time = (time *1000 + g_server.timeDifference);
  87. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  88. ///user/vip/info /user/vip/info
  89. [g_server getact_act_userGradelistGrade:salt andToView:self];
  90. //累计存款值
  91. self.headerView.currentPriceLabel.text =[NSString stringWithFormat:@"%@",dict[@"totalRecharge"]];
  92. //中间View赋值
  93. NSString *sss = [NSString stringWithFormat:@"%@",dict[@"gradeIndex"]];
  94. int p = [sss intValue];
  95. self.page = p;
  96. }if([aDownload.action isEqualToString:act_userGradelistGrade]){
  97. [SVProgressHUD dismiss];
  98. NSArray *array =[[array1 reverseObjectEnumerator] allObjects];
  99. _dataArr=[vipDetailModel mj_objectArrayWithKeyValuesArray:array];
  100. [self _createdCenterView:_dataArr];
  101. [self _createdBottomView];
  102. NSLog(@"page===%d",self.page);
  103. self.centerView.stepView.stepIndex =_page-1;
  104. NSDictionary *dictCurrent = _getUserDict[@"vipInfo"];
  105. //当前用户的钱
  106. CGFloat aaaaMoney= [_getUserDict[@"totalRecharge"] intValue]*1.0;
  107. //当前用户的等级
  108. int aaaa= [dictCurrent[@"current"][@"gradeIndex"] intValue];
  109. //int aaaaMoney= [dictCurrent[@"current"][@"rechargeMoney"] intValue];
  110. // 进度 = (累计-当前级)/(下一级晋级-当前级)
  111. CGFloat aaaaxx=0.0;
  112. if (aaaa==0) {
  113. aaaa=1;
  114. }
  115. // 当前级
  116. vipDetailModel *model1 = _dataArr[aaaa-1];
  117. int chaMoney1= [model1.rechargeMoney intValue];
  118. // 下一级
  119. vipDetailModel *model2 = _dataArr[aaaa];
  120. int chaMoney2= [model2.rechargeMoney intValue];
  121. if (aaaa==10) {
  122. aaaaxx= 1;
  123. }else {
  124. aaaaxx = (aaaaMoney-chaMoney1)/(chaMoney2-chaMoney1)*1.0;
  125. }
  126. if (aaaaxx>1) {
  127. aaaaxx=1;
  128. }
  129. /* */
  130. //进度值
  131. self.headerView.progressLabel.text=[NSString stringWithFormat:@"%.f%%",floor(aaaaxx*100)];
  132. if ( aaaaxx !=0) {
  133. //更新进度Label的x坐标
  134. [self.headerView.progressLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  135. make.left.equalTo(self.headerView.leftGradeButton.mas_right).offset(aaaaxx* self.headerView.progressImageView.frame.size.width);
  136. }];
  137. //当前进度View
  138. [self.headerView.currentProgressImageView mas_updateConstraints:^(MASConstraintMaker *make) {
  139. make.width.offset(aaaaxx* self.headerView.progressImageView.frame.size.width);
  140. }];
  141. }
  142. if (self.page*100 >kScreenWidth) { //判断是否超出屏幕
  143. self.centerView.grapeScrollView.contentOffset = CGPointMake((self.page *100)-kScreenWidth, 0);
  144. }else {
  145. self.centerView.grapeScrollView.contentOffset = CGPointMake(0, 0);
  146. }
  147. self.centerView.currentPageLabel.text = [NSString stringWithFormat:@"%d",self.page];
  148. //底部View赋值
  149. self.bottomView.zunxiangLabel.text = [NSString stringWithFormat:@"VIP%d尊享",self.page];
  150. self.centerView.pictureScrollView.contentOffset = CGPointMake(self.centerView.pictureScrollView.width*(self.page-1), 0);
  151. //int aaaa2222= [dictCurrent[@"current"][@"gradeIndex"] intValue];
  152. // if (i == self.page) {
  153. if (aaaa<1) {
  154. return;
  155. }
  156. NSArray *images=@[@"sjlj",@"群聊等级VIp标识",@"meirhb",@"bqb",@"bqb"];
  157. for (int i=0; i<images.count; i++) {
  158. vipDetailModel *model = _dataArr[aaaa-1];
  159. UIButton *but = (UIButton *)[_bottomView viewWithTag:10+i];
  160. UILabel *titleLabel = (UILabel *)[but viewWithTag:200+i];
  161. UILabel *titleLabel2 = (UILabel *)[but viewWithTag:300+i];
  162. UIImageView *imageLevel = (UIImageView *)[but viewWithTag:100+i];
  163. if (i==0) {
  164. titleLabel.text = model.upgradeAward;
  165. }if (i==2) {
  166. // titleLabel2.text = [NSString stringWithFormat:@"%zd ",model.bubbleFontSet.count];
  167. titleLabel.text = @"1";
  168. titleLabel2.text = @"准点红包(群聊专属)";
  169. }if (i==1) {
  170. [imageLevel sd_setImageWithURL:[NSURL URLWithString:model.vipUrl] placeholderImage:[UIImage imageNamed:@"群聊等级VIp标识"]];
  171. titleLabel.text = model.vipName;
  172. }if (i==3) {
  173. titleLabel.text = [NSString stringWithFormat:@"特殊表情包"];
  174. titleLabel2.text = [NSString stringWithFormat:@"%@",@"VIP8级以上会员专享"];
  175. if ([model.grade intValue]>=8) {
  176. but.hidden=NO;
  177. } else{
  178. but.hidden=YES;
  179. }
  180. }if (i==4) {
  181. titleLabel.text = [NSString stringWithFormat:@"视频服务"];
  182. if ([model.grade intValue]>=8) {
  183. but.hidden=NO;
  184. } else{
  185. but.hidden=YES;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. -(CGSize)titleBtnWight:(NSString *)titBtnW and:(UILabel *)titBtn {
  192. CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(MAXFLOAT, 17) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.font} context:nil].size;
  193. return titleSize;
  194. }
  195. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  196. [SVProgressHUD dismiss];
  197. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  198. if([errorCode isEqualToString:@"权限验证失败"])
  199. {
  200. if ([aDownload.action isEqualToString:act_userViplist])
  201. {
  202. }if([aDownload.action isEqualToString:actuservipinfo]){
  203. }
  204. }
  205. return [errorCode intValue];
  206. }
  207. - (void)goback{
  208. [g_navigation dismissViewController:self animated:NO];
  209. }
  210. - (void)_createdViews {
  211. _dataArr=[NSMutableArray array];
  212. //顶部UI
  213. [self _createdTopView];
  214. }
  215. - (void)gobackBtnClick{
  216. [g_navigation dismissViewController:self animated:NO];
  217. }
  218. - (void)_createdTopView {
  219. //顶部UI
  220. self.headerView = [[JXVipDetailHeaderView alloc] init];
  221. [self.headerView.gobackBtn addTarget:self action:@selector(gobackBtnClick) forControlEvents:UIControlEventTouchUpInside];
  222. self.headerView.headerImageView.image = [UIImage imageNamed:@"组1"];
  223. self.headerView.nameLabel.text = self.name;
  224. self.headerView.numberLabel.text = self.dengji;
  225. [self.headerView.leftGradeButton setTitle:[NSString stringWithFormat:@"%@级",self.dengji] forState:UIControlStateNormal];
  226. [self.headerView.nextGradeButton setTitle:[NSString stringWithFormat:@"%d级",[self.dengji intValue]+1] forState:UIControlStateNormal];
  227. self.headerView.progressLabel.text = @"0%";
  228. self.headerView.currentPriceLabel.text = @"0";
  229. [self.mainScrollView addSubview:self.headerView];
  230. [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.left.equalTo(@0);
  232. make.top.equalTo(@0);
  233. make.centerX.offset(0);
  234. make.right.equalTo(@0);
  235. make.height.equalTo(@280);
  236. }];
  237. }
  238. - (void)_createdCenterView:(NSMutableArray *)array {
  239. self.centerView = [[JXVipDetailCenterView alloc] initWithFrame:CGRectZero Titles:array];
  240. self.centerView.delegate = self;
  241. [self.mainScrollView addSubview:self.centerView];
  242. [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) {
  243. make.left.equalTo(@0);
  244. make.top.equalTo(self.headerView.mas_bottom).offset(20);
  245. make.right.equalTo(@0);
  246. make.height.equalTo(@210);
  247. }];
  248. }
  249. - (void)_createdBottomView {
  250. self.bottomView = [[JXVipDetailBottomView alloc] init];
  251. [self.mainScrollView addSubview:self.bottomView];
  252. _bottomView.userInteractionEnabled=YES;
  253. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.left.equalTo(@0);
  255. make.top.equalTo(self.centerView.mas_bottom).offset(10);
  256. make.right.equalTo(@0);
  257. make.height.equalTo(@200);
  258. }];
  259. }
  260. #pragma mark -UIScrollView delegate
  261. - (void)scrollViewDidEndDeceleratingWithCenterView:(UIScrollView *)scrollView {
  262. int page = (scrollView.contentOffset.x /scrollView.width)+1;
  263. int p = scrollView.contentOffset.x /scrollView.width;
  264. self.centerView.currentPageLabel.text = [NSString stringWithFormat:@"%d",page];
  265. //当前显示的图片数量
  266. self.centerView.stepView.stepIndex = p;
  267. if (page*100 >kScreenWidth) { //判断是否超出屏幕
  268. self.centerView.grapeScrollView.contentOffset = CGPointMake((page *100)-kScreenWidth, 0);
  269. }else {
  270. self.centerView.grapeScrollView.contentOffset = CGPointMake(0, 0);
  271. }
  272. NSArray *images=@[@"sjlj",@"群聊等级VIp标识",@"meirhb",@"bqb",@"bqb",@"bqb"];
  273. for (int i=0; i<=p; i++) {
  274. self.bottomView.zunxiangLabel.text = [NSString stringWithFormat:@"VIP%d尊享",p+1];
  275. for (int a=0; a<images.count; a++) {
  276. vipDetailModel *stringModel = _dataArr[p];
  277. UIButton *but = (UIButton *)[_bottomView viewWithTag:10+a];
  278. UILabel *titleLabel = (UILabel *)[but viewWithTag:200+a];
  279. UILabel *titleLabel2 = (UILabel *)[but viewWithTag:300+a];
  280. UIImageView *imageLevel = (UIImageView *)[but viewWithTag:100+i];
  281. if (a==0) {
  282. titleLabel.text = stringModel.upgradeAward;
  283. }if (a==2) {
  284. titleLabel.text = @"1";
  285. titleLabel2.text = @"准点红包(群聊专属)";
  286. }if (a==1) {
  287. [imageLevel sd_setImageWithURL:[NSURL URLWithString:stringModel.vipUrl] placeholderImage:[UIImage imageNamed:@"群聊等级VIp标识"]];
  288. titleLabel.text = stringModel.vipName;
  289. titleLabel2.text = @"荣誉称号";
  290. }if (a==3) {
  291. titleLabel2.text = [NSString stringWithFormat:@"%@",@"VIP8级以上会员专享"];
  292. if ([stringModel.grade intValue]>=8) {
  293. but.hidden=NO;
  294. } else{
  295. but.hidden=YES;
  296. }
  297. }
  298. if (a==4) {
  299. if ([stringModel.grade intValue]>=8) {
  300. but.hidden=NO;
  301. titleLabel.text = [NSString stringWithFormat:@"视频服务"];
  302. } else{
  303. but.hidden=YES;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. - (UIScrollView *)mainScrollView {
  310. if (!_mainScrollView) {
  311. _mainScrollView = [[UIScrollView alloc] init];
  312. // _mainScrollView.bounces = NO;
  313. _mainScrollView.backgroundColor = kWhiteColor;
  314. [self.view addSubview:_mainScrollView];
  315. [_mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  316. make.left.equalTo(@0);
  317. make.top.equalTo(@0);
  318. make.right.equalTo(@0);
  319. make.bottom.equalTo(@0);
  320. }];
  321. if (JX_SCREEN_HEIGHT>=812) {
  322. }else{
  323. UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]
  324. initWithTarget:self
  325. action:@selector(foundSwipe:)];
  326. //设置识别滑动方向
  327. recognizer.direction =UISwipeGestureRecognizerDirectionUp;
  328. //Swipe手势识别器关联到View
  329. [_mainScrollView addGestureRecognizer:recognizer];
  330. UISwipeGestureRecognizer *recognizer2 = [[UISwipeGestureRecognizer alloc]
  331. initWithTarget:self
  332. action:@selector(foundSwipe2:)];
  333. recognizer2.direction =UISwipeGestureRecognizerDirectionDown;
  334. [_mainScrollView addGestureRecognizer:recognizer2];
  335. }
  336. }
  337. return _mainScrollView;
  338. }
  339. - (void)foundSwipe2:(UISwipeGestureRecognizer *)sender {
  340. //设置识别滑动方向
  341. sender.direction =UISwipeGestureRecognizerDirectionDown;
  342. //Swipe手势识别器关联到View
  343. [self.view addGestureRecognizer:sender];
  344. [UIView animateWithDuration:0.2 animations:^{
  345. CGRect bounds=self.view.bounds;
  346. bounds.origin.y=0;
  347. _mainScrollView.bounds=bounds;
  348. }];
  349. }
  350. - (void)foundSwipe:(UISwipeGestureRecognizer *)sender {
  351. [UIView animateWithDuration:0.2 animations:^{
  352. CGRect bounds=_mainScrollView.bounds;
  353. if (JX_SCREEN_WIDTH>=414) {
  354. bounds.origin.y=15;
  355. }else{
  356. bounds.origin.y=80;
  357. }
  358. _mainScrollView.bounds=bounds;
  359. }];
  360. }
  361. @end