JXCollectMoneyVC.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // JXCollectMoneyVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/3/6.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXCollectMoneyVC.h"
  9. #import "QRImage.h"
  10. #import "JXInputMoneyVC.h"
  11. @interface JXCollectMoneyVC ()
  12. @property (nonatomic, strong) NSString *money;
  13. @property (nonatomic, strong) NSString *desStr;
  14. @property (nonatomic, strong) UIImageView *getQrCode;
  15. @property (nonatomic, strong) UILabel *leftLabel;
  16. @property (nonatomic, strong) UILabel *rigLabel;
  17. @property (nonatomic, strong) UIView *baseView;
  18. @property (nonatomic, strong) UILabel *moneyLab;
  19. @property (nonatomic, strong) UILabel *descLab;
  20. @property (nonatomic, strong) UILabel *barCodeLab;
  21. @end
  22. @implementation JXCollectMoneyVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.heightHeader = 0;
  26. self.heightFooter = 0;
  27. [self createHeadAndFoot];
  28. [self setupViews];
  29. [self setupNav];
  30. [g_notify addObserver:self selector:@selector(notifyPaymentGet:) name:kXMPPMessageQrPaymentNotification object:nil];
  31. }
  32. - (void)viewWillAppear:(BOOL)animated {
  33. [super viewWillAppear:animated];
  34. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  35. }
  36. - (void)notifyPaymentGet:(NSNotification *)noti {
  37. JXMessageObject *msg = noti.object;
  38. if ([msg.type intValue] == kWCMessageTypeReceiptGet) {
  39. [g_server showMsg:Localized(@"JX_PaymentReceived")];
  40. [self updateQr];
  41. }
  42. }
  43. - (void)setupNav {
  44. UIView *nav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_TOP)];
  45. // nav.backgroundColor = HEXCOLOR(0x449ad4);
  46. [self.view addSubview:nav];
  47. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(8, JX_SCREEN_TOP - 38, 31, 31)];
  48. [btn setBackgroundImage:[UIImage imageNamed:@"title_back"] forState:UIControlStateNormal];
  49. [btn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  50. [nav addSubview:btn];
  51. UILabel *p = [[UILabel alloc]initWithFrame:CGRectMake(40, JX_SCREEN_TOP - 32, JX_SCREEN_WIDTH-40*2, 20)];
  52. p.backgroundColor = [UIColor clearColor];
  53. p.textAlignment = NSTextAlignmentCenter;
  54. p.textColor = [UIColor whiteColor];
  55. p.text = Localized(@"JX_QrCodeCollection");
  56. [nav addSubview:p];
  57. }
  58. - (void)setupViews {
  59. // self.tableBody.backgroundColor = HEXCOLOR(0x449ad4);
  60. [self setupView:self.view colors:@[(__bridge id)HEXCOLOR(0x449ad4).CGColor,(__bridge id)HEXCOLOR(0x1953AF).CGColor]];
  61. _baseView = [[UIView alloc] initWithFrame:CGRectMake(20, JX_SCREEN_TOP+20, JX_SCREEN_WIDTH-40, JX_SCREEN_WIDTH-40)];
  62. _baseView.backgroundColor = [UIColor whiteColor];
  63. _baseView.layer.masksToBounds = YES;
  64. _baseView.layer.cornerRadius = 3.f;
  65. [self.view addSubview:_baseView];
  66. UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 25, 25)];
  67. img.image = [UIImage imageNamed:@"pay_wallet_blue"];
  68. [_baseView addSubview:img];
  69. UILabel *payLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(img.frame)+10, 13, 100, 18)];
  70. payLabel.text = Localized(@"JX_QrCodeCollection");
  71. payLabel.textColor = HEXCOLOR(0x449ad4);
  72. [_baseView addSubview:payLabel];
  73. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(payLabel.frame)+13, _baseView.frame.size.width, LINE_WH)];
  74. line.backgroundColor = THE_LINE_COLOR;
  75. [_baseView addSubview:line];
  76. _barCodeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame)+30, _baseView.frame.size.width, 15)];
  77. _barCodeLab.text = Localized(@"JX_ScanQrCodeToPayMe");
  78. _barCodeLab.textColor = [UIColor lightGrayColor];
  79. _barCodeLab.font = SYSFONT(14);
  80. _barCodeLab.textAlignment = NSTextAlignmentCenter;
  81. [_baseView addSubview:_barCodeLab];
  82. //金额
  83. _moneyLab = [[UILabel alloc] init];
  84. _moneyLab.font = SYSFONT(20);
  85. _moneyLab.textAlignment = NSTextAlignmentCenter;
  86. [_baseView addSubview:_moneyLab];
  87. //说明
  88. _descLab = [[UILabel alloc] init];
  89. _descLab.font = SYSFONT(14);
  90. _descLab.textColor = [UIColor lightGrayColor];
  91. _descLab.textAlignment = NSTextAlignmentCenter;
  92. [_baseView addSubview:_descLab];
  93. // 二维码
  94. _getQrCode = [[UIImageView alloc] init];
  95. [_baseView addSubview:_getQrCode];
  96. // 设置金额
  97. _leftLabel = [[UILabel alloc] init];
  98. _leftLabel.font = SYSFONT(14);
  99. _leftLabel.textColor = HEXCOLOR(0x383893);
  100. _leftLabel.userInteractionEnabled = YES;
  101. _leftLabel.textAlignment = NSTextAlignmentCenter;
  102. [_baseView addSubview:_leftLabel];
  103. UITapGestureRecognizer *tapL = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(setMoneyCount)];
  104. [_leftLabel addGestureRecognizer:tapL];
  105. UIView *botLine = [[UIView alloc] initWithFrame:CGRectMake(_leftLabel.frame.size.width-LINE_WH, -5, LINE_WH, 25)];
  106. botLine.backgroundColor = THE_LINE_COLOR;
  107. [_leftLabel addSubview:botLine];
  108. // 保存收款码
  109. _rigLabel = [[UILabel alloc] init];
  110. _rigLabel.text = Localized(@"JX_SaveCollectionCode");
  111. _rigLabel.font = SYSFONT(14);
  112. _rigLabel.textColor = HEXCOLOR(0x383893);
  113. _rigLabel.userInteractionEnabled = YES;
  114. _rigLabel.textAlignment = NSTextAlignmentCenter;
  115. [_baseView addSubview:_rigLabel];
  116. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(saveQr)];
  117. [_rigLabel addGestureRecognizer:tap];
  118. [self updateViews];
  119. }
  120. #pragma mark - 更新界面
  121. - (void)updateViews {
  122. //金额
  123. CGSize mSize = [self.money sizeWithAttributes:@{NSFontAttributeName:SYSFONT(20)}];
  124. _moneyLab.text = [NSString stringWithFormat:@"¥%.2f",[self.money doubleValue]];
  125. _moneyLab.frame = CGRectMake(0, CGRectGetMaxY(_barCodeLab.frame)+10, _baseView.frame.size.width, mSize.height);
  126. //说明
  127. CGSize dSize = [self.desStr sizeWithAttributes:@{NSFontAttributeName:SYSFONT(14)}];
  128. _descLab.text = self.desStr;
  129. _descLab.frame = CGRectMake(0, CGRectGetMaxY(_moneyLab.frame)+10, _baseView.frame.size.width, dSize.height);
  130. //二维码
  131. _getQrCode.frame = CGRectMake((_baseView.frame.size.width - 140)/2, CGRectGetMaxY(_descLab.frame)+10, 140, 140);
  132. //设置金额
  133. _leftLabel.text = self.money.length > 0 ? Localized(@"JX_RemoveTheAmount") : Localized(@"JX_SetTheAmount");
  134. _leftLabel.frame = CGRectMake(0, CGRectGetMaxY(_getQrCode.frame)+30, _baseView.frame.size.width*0.5, 15);
  135. // 保存收款码
  136. _rigLabel.frame = CGRectMake(CGRectGetMaxX(_leftLabel.frame), _leftLabel.frame.origin.y, _baseView.frame.size.width*0.5, 15);
  137. _baseView.frame = CGRectMake(20, JX_SCREEN_TOP+20, JX_SCREEN_WIDTH-40, CGRectGetMaxY(_leftLabel.frame)+30);
  138. [self updateQr];
  139. }
  140. - (void)setMoneyCount {
  141. if (self.money.length > 0) {
  142. self.money = nil;
  143. self.desStr = nil;
  144. [self updateViews];
  145. return;
  146. }
  147. JXInputMoneyVC *inputVC = [[JXInputMoneyVC alloc] init];
  148. inputVC.type = JXInputMoneyTypeSetMoney;
  149. inputVC.delegate = self;
  150. inputVC.onInputMoney = @selector(onInputMoney:);
  151. [g_navigation pushViewController:inputVC animated:YES];
  152. }
  153. - (void)onInputMoney:(NSDictionary *)dict {
  154. if ([dict objectForKey:@"money"]) {
  155. self.money = [dict objectForKey:@"money"];
  156. }
  157. if ([dict objectForKey:@"desc"]) {
  158. self.desStr = [dict objectForKey:@"desc"];
  159. }
  160. [self updateViews];
  161. }
  162. #pragma mark - 保存二维码到相册
  163. - (void)saveQr {
  164. UIImageWriteToSavedPhotosAlbum(self.getQrCode.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  165. }
  166. -(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
  167. if(error){
  168. [g_server showMsg:Localized(@"ImageBrowser_saveFaild")];
  169. }else{
  170. [g_server showMsg:Localized(@"ImageBrowser_saveSuccess")];
  171. }
  172. }
  173. #pragma mark - 更新二维码
  174. - (void)updateQr {
  175. UIImageView *imageView = [[UIImageView alloc] init];
  176. [g_server getHeadImageLarge:MY_USER_ID userName:MY_USER_NAME imageView:imageView];
  177. _getQrCode.image = [QRImage qrImageForString:[self getQrCodeStr] imageSize:_getQrCode.frame.size.width logoImage:imageView.image logoImageSize:30];
  178. }
  179. - (NSString *)getQrCodeStr {
  180. NSMutableDictionary *dict = @{@"userId":MY_USER_ID,@"userName":MY_USER_NAME}.mutableCopy;
  181. if (self.money.length > 0) {
  182. [dict addEntriesFromDictionary:@{@"money":self.money}];
  183. }
  184. if (self.desStr.length > 0) {
  185. [dict addEntriesFromDictionary:@{@"description":self.desStr}];
  186. }
  187. SBJsonWriter * OderJsonwriter = [SBJsonWriter new];
  188. NSString * jsonString = [OderJsonwriter stringWithObject:dict];
  189. return jsonString;
  190. }
  191. - (void)setupView:(UIView *)view colors:(NSArray *)colors {
  192. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  193. gradientLayer.frame = CGRectMake(0, THE_DEVICE_HAVE_HEAD ? -44 : -20, JX_SCREEN_WIDTH, THE_DEVICE_HAVE_HEAD ? JX_SCREEN_HEIGHT+44 : JX_SCREEN_HEIGHT+20); // 设置显示的frame
  194. gradientLayer.colors = colors; // 设置渐变颜色
  195. gradientLayer.startPoint = CGPointMake(0, 0);
  196. gradientLayer.endPoint = CGPointMake(0, 1);
  197. [view.layer addSublayer:gradientLayer];
  198. }
  199. @end