FamilyDesViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. //
  2. // FamilyDesViewController.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 16/9/26.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "FamilyDesViewController.h"
  9. #import "GetHeadImgViewController.h"
  10. #import "EditFamilyViewController.h"
  11. #import "FamilyDesModel.h"
  12. #import "FamilyMemberViewController.h"
  13. #import "FamilyListModel.h"
  14. @interface FamilyDesViewController ()<UITextViewDelegate>
  15. @property (nonatomic, strong) UIView * view1;
  16. @property (nonatomic, strong) UIView * view2;
  17. @property (nonatomic, strong) UIView * view3;
  18. @property (nonatomic, strong) UIView * view4;
  19. @property (nonatomic, strong) UIView * view5;
  20. @property (nonatomic, strong) UIButton * headBtn;
  21. @property (nonatomic, strong) UILabel * familyLabel;
  22. @property (nonatomic, strong) UITextView * nameTextView;//公会名称
  23. @property (nonatomic, strong) UITextView * desTextView;//公会宣言
  24. @property (nonatomic, strong) UIButton * editBtn; //编辑按钮
  25. @property (nonatomic, strong) UIButton * managerBtn; //成员管理
  26. @property (nonatomic, strong) UIButton * memberBtn; //公会成员
  27. @property (nonatomic, strong) UIButton * leaveBtn; //退出公会
  28. @property (nonatomic, strong) UIButton * applyBtn; //申请加入公会
  29. @property (nonatomic, strong) FamilyDesModel * model; //公会信息Model;
  30. @property (nonatomic, strong) UILabel * familyHeaderName; //公会族长名
  31. @property (nonatomic, strong) UILabel * numberLable; //公会人数
  32. @property (nonatomic, assign) int canEditAll;
  33. @end
  34. @implementation FamilyDesViewController
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. [self createView];
  39. [self loadData];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated
  42. {
  43. [super viewWillAppear:animated];
  44. [self loadData];
  45. }
  46. - (void)createView
  47. {
  48. self.navigationItem.title = ASLocalizedString(@"公会详情");
  49. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(comeBack) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  50. self.view.backgroundColor = kFamilyBackGroundColor;
  51. _view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenH-64)*375/1200)];
  52. [self.view addSubview:_view1];
  53. _view2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_view1.frame), kScreenW, (kScreenH-64)*115/1200)];
  54. [self.view addSubview:_view2];
  55. _view3 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_view2.frame), kScreenW, (kScreenH-64)*115/1200)];
  56. [self.view addSubview:_view3];
  57. _view4 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_view3.frame), kScreenW, (kScreenH-64)*115/1200)];
  58. [self.view addSubview:_view4];
  59. _view5 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_view4.frame), kScreenW, (kScreenH-64)*490/1200)];
  60. [self.view addSubview:_view5];
  61. _nameTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenH-64)*95/1200)];
  62. _nameTextView.backgroundColor = [UIColor whiteColor];
  63. _nameTextView.textAlignment = NSTextAlignmentCenter;
  64. // _nameTextView.text =ASLocalizedString(@"道道道非常道");
  65. _nameTextView.font = [UIFont systemFontOfSize:15];
  66. _nameTextView.editable = NO;
  67. [_view2 addSubview:_nameTextView];
  68. _familyHeaderName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenH-64)*95/1200)];
  69. _familyHeaderName.backgroundColor = [UIColor whiteColor];
  70. _familyHeaderName.font = [UIFont systemFontOfSize:15];
  71. _familyHeaderName.textAlignment = NSTextAlignmentCenter;
  72. // _familyHeaderName.text = ASLocalizedString(@"公会族长");
  73. [_view3 addSubview:_familyHeaderName];
  74. _numberLable= [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenH-64)*95/1200)];
  75. _numberLable.backgroundColor = [UIColor whiteColor];
  76. _numberLable.font = [UIFont systemFontOfSize:15];
  77. _numberLable.textAlignment = NSTextAlignmentCenter;
  78. // _numberLable.text = ASLocalizedString(@"公会人数");
  79. [_view4 addSubview:_numberLable];
  80. _desTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenH-64)*310/1200)];
  81. _desTextView.backgroundColor = [UIColor whiteColor];
  82. // _desTextView.text = ASLocalizedString(@"公会详情描述");
  83. _desTextView.editable = NO;
  84. _desTextView.font = [UIFont systemFontOfSize:15];
  85. [_view5 addSubview:_desTextView];
  86. [self createBtn];
  87. }
  88. - (void)createBtn
  89. {
  90. //如果是公会族长
  91. if (_isFamilyHeder==1)
  92. {
  93. _headBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  94. _headBtn.frame = CGRectMake((kScreenW-90)/2, (CGRectGetHeight(_view1.frame)-117)/2, 90, 90);
  95. _headBtn.backgroundColor = [UIColor whiteColor];
  96. _headBtn.layer.cornerRadius = 45;
  97. _headBtn.layer.masksToBounds = YES;
  98. [_headBtn addTarget:self action:@selector(clickHeadImage) forControlEvents:UIControlEventTouchUpInside];
  99. [_view1 addSubview:_headBtn];
  100. _familyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_headBtn.frame)+10, kScreenW, 17)];
  101. _familyLabel.text = ASLocalizedString(@"编辑公会头像");
  102. _familyLabel.textAlignment = NSTextAlignmentCenter;
  103. _familyLabel.font = [UIFont systemFontOfSize:17];
  104. _familyLabel.textColor = kAppGrayColor2;
  105. [_view1 addSubview:_familyLabel];
  106. _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  107. _editBtn.frame = CGRectMake(25, 25+CGRectGetMaxY(_desTextView.frame), (kScreenW-75)/2, 40 );
  108. _editBtn.backgroundColor = kAppMainColor;
  109. _editBtn.layer.cornerRadius = 20;
  110. _editBtn.layer.masksToBounds = YES;
  111. [_editBtn setTitle:ASLocalizedString(@"编辑资料")forState:UIControlStateNormal];
  112. [_editBtn addTarget:self action:@selector(clickEditBtn) forControlEvents:UIControlEventTouchUpInside];
  113. [_view5 addSubview:_editBtn];
  114. _managerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  115. _managerBtn.frame = CGRectMake(50+(kScreenW-75)/2, 25+CGRectGetMaxY(_desTextView.frame), (kScreenW-75)/2, 40);
  116. _managerBtn.backgroundColor = kAppFamilyBtnColor;
  117. _managerBtn.layer.cornerRadius = 20;
  118. _managerBtn.layer.masksToBounds = YES;
  119. [_managerBtn setTitle:ASLocalizedString(@"成员管理")forState:UIControlStateNormal];
  120. [_managerBtn addTarget:self action:@selector(clickManagerBtn) forControlEvents:UIControlEventTouchUpInside];
  121. [_view5 addSubview:_managerBtn];
  122. }
  123. else
  124. {
  125. _headBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  126. _headBtn.frame = CGRectMake((kScreenW-90)/2, (CGRectGetHeight(_view1.frame)-90)/2, 90, 90);
  127. _headBtn.backgroundColor = [UIColor whiteColor];
  128. _headBtn.layer.cornerRadius = 45;
  129. _headBtn.layer.masksToBounds = YES;
  130. _headBtn.userInteractionEnabled = NO;
  131. [_view1 addSubview:_headBtn];
  132. if (_isFamilyHeder==0)
  133. {
  134. _memberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  135. _memberBtn.frame = CGRectMake(25, 25+CGRectGetMaxY(_desTextView.frame), (kScreenW-75)/2, 40);
  136. _memberBtn.backgroundColor = kAppMainColor;
  137. _memberBtn.layer.cornerRadius = 20;
  138. _memberBtn.layer.masksToBounds = YES;
  139. [_memberBtn setTitle:ASLocalizedString(@"公会成员")forState:UIControlStateNormal];
  140. [_memberBtn addTarget:self action:@selector(clickMemberBtn) forControlEvents:UIControlEventTouchUpInside];
  141. [_view5 addSubview:_memberBtn];
  142. _leaveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  143. _leaveBtn.frame = CGRectMake(50+(kScreenW-75)/2, 25+CGRectGetMaxY(_desTextView.frame), (kScreenW-75)/2, 40);
  144. _leaveBtn.backgroundColor = kAppFamilyBtnColor;
  145. _leaveBtn.layer.cornerRadius = 20;
  146. _leaveBtn.layer.masksToBounds = YES;
  147. [_leaveBtn setTitle:ASLocalizedString(@"退出公会")forState:UIControlStateNormal];
  148. [_leaveBtn addTarget:self action:@selector(clickLeaveBtn) forControlEvents:UIControlEventTouchUpInside];
  149. [_view5 addSubview:_leaveBtn];
  150. }
  151. else if (_isFamilyHeder ==2)
  152. {
  153. _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  154. _applyBtn.frame = CGRectMake(25, 25+CGRectGetMaxY(_desTextView.frame), kScreenW-50, 40);
  155. _applyBtn.layer.cornerRadius = 20;
  156. _applyBtn.layer.masksToBounds = YES;
  157. [_headBtn sd_setImageWithURL:[NSURL URLWithString:_listModel.family_logo] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  158. _nameTextView.text = _listModel.family_name;
  159. // _desTextView.text =_model.family_manifesto;
  160. _familyHeaderName.text = [NSString stringWithFormat:ASLocalizedString(@"公会族长 : %@"),_listModel.nick_name];
  161. _numberLable.text = [NSString stringWithFormat:ASLocalizedString(@"公会人数 : %@人"),_listModel.user_count];
  162. if([_is_apply isEqualToString:@"0"])
  163. {
  164. _applyBtn.backgroundColor = kAppMainColor;
  165. [_applyBtn setTitle:ASLocalizedString(@"加入公会")forState:UIControlStateNormal];
  166. [_applyBtn addTarget:self action:@selector(clickApplyBtn) forControlEvents:UIControlEventTouchUpInside];
  167. }
  168. else if ([_is_apply isEqualToString:@"1"])
  169. {
  170. _applyBtn.backgroundColor = kAppGrayColor3;
  171. [_applyBtn setTitle:ASLocalizedString(@"申请中")forState:UIControlStateNormal];
  172. _applyBtn.enabled = NO;
  173. }
  174. else if ([_is_apply isEqualToString:@"2"])
  175. {
  176. _applyBtn.backgroundColor = kAppGrayColor3;
  177. [_applyBtn setTitle:ASLocalizedString(@"已加入")forState:UIControlStateNormal];
  178. _applyBtn.enabled = NO;
  179. }
  180. [_view5 addSubview:_applyBtn];
  181. }
  182. }
  183. }
  184. //点击编辑资料按钮
  185. - (void)clickEditBtn
  186. {
  187. EditFamilyViewController * editFamilyVC = [[EditFamilyViewController alloc] init];
  188. editFamilyVC.type = 1;
  189. editFamilyVC.model = self.model;
  190. editFamilyVC.user_id = self.user_id;
  191. editFamilyVC.canEditAll = self.canEditAll;
  192. [self.navigationController pushViewController:editFamilyVC animated:YES];
  193. }
  194. //点击成员管理按钮
  195. - (void)clickManagerBtn
  196. {
  197. FamilyMemberViewController * familyMemberVC = [[FamilyMemberViewController alloc] init];
  198. familyMemberVC.isFamilyHeder = 1;
  199. familyMemberVC.jid = self.model.family_id;
  200. [self.navigationController pushViewController:familyMemberVC animated:YES];
  201. }
  202. //点击公会成员按钮
  203. - (void)clickMemberBtn
  204. {
  205. FamilyMemberViewController * familyMemberVC = [[FamilyMemberViewController alloc] init];
  206. familyMemberVC.isFamilyHeder = 0;
  207. familyMemberVC.jid = self.model.family_id;
  208. [self.navigationController pushViewController:familyMemberVC animated:YES];
  209. }
  210. //点击编辑公会头像
  211. - (void)clickHeadImage
  212. {
  213. EditFamilyViewController * editFamilyVC = [[EditFamilyViewController alloc] init];
  214. editFamilyVC.type = 1;
  215. editFamilyVC.model = self.model;
  216. editFamilyVC.user_id = self.user_id;
  217. [self.navigationController pushViewController:editFamilyVC animated:YES];
  218. }
  219. //点击退出公会
  220. - (void)clickLeaveBtn
  221. {
  222. FWWeakify(self)
  223. [FanweMessage alert:nil message:ASLocalizedString(@"是否退出该公会")destructiveAction:^{
  224. FWStrongify(self)
  225. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  226. [parmDict setObject:@"family_user" forKey:@"ctl"];
  227. [parmDict setObject:@"logout" forKey:@"act"];
  228. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  229. if ([responseJson toInt:@"status"]==1)
  230. {
  231. [self.navigationController popViewControllerAnimated:YES];
  232. }
  233. } FailureBlock:^(NSError *error) {
  234. }];
  235. } cancelAction:^{
  236. }];
  237. }
  238. //申请加入公会
  239. - (void)clickApplyBtn
  240. {
  241. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  242. [parmDict setObject:@"family_user" forKey:@"ctl"];
  243. [parmDict setObject:@"user_join" forKey:@"act"];
  244. [parmDict setObject:_jid forKey:@"family_id"];
  245. FWWeakify(self)
  246. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  247. FWStrongify(self)
  248. if ([responseJson toInt:@"status"]==1)
  249. {
  250. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"申请已提交")];
  251. self.applyBtn.backgroundColor = kAppGrayColor3;
  252. [self.applyBtn setTitle:ASLocalizedString(@"申请中")forState:UIControlStateNormal];
  253. self.applyBtn.enabled = NO;
  254. }
  255. } FailureBlock:^(NSError *error) {
  256. }];
  257. }
  258. //点击返回按钮
  259. - (void)comeBack
  260. {
  261. [self.navigationController popViewControllerAnimated:YES];
  262. }
  263. - (void)loadData
  264. {
  265. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  266. [parmDict setObject:@"family" forKey:@"ctl"];
  267. [parmDict setObject:@"index" forKey:@"act"];
  268. [parmDict setObject:_jid forKey:@"family_id"];
  269. __weak typeof(self) ws = self;
  270. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  271. NSDictionary * dic = [responseJson objectForKey:@"family_info"];
  272. if (dic && [dic isKindOfClass:[NSDictionary class]])
  273. {
  274. _model = [FamilyDesModel mj_objectWithKeyValues:dic];
  275. [_headBtn sd_setImageWithURL:[NSURL URLWithString:_model.family_logo] forState:UIControlStateNormal placeholderImage:kDefaultPreloadHeadImg];
  276. _nameTextView.text = _model.family_name;
  277. _desTextView.text =_model.family_manifesto;
  278. _familyHeaderName.text = [NSString stringWithFormat:ASLocalizedString(@"公会族长 : %@"),_model.nick_name];
  279. _numberLable.text = [NSString stringWithFormat:ASLocalizedString(@"公会人数 : %@人"),_model.user_count];
  280. }
  281. if ([responseJson toInt:@"status"]==1)
  282. {
  283. if (_isFamilyHeder==1)
  284. {
  285. _headBtn.userInteractionEnabled = YES;
  286. _editBtn.userInteractionEnabled = YES;
  287. _editBtn.backgroundColor = kAppMainColor;
  288. _managerBtn.userInteractionEnabled = YES;
  289. _managerBtn.backgroundColor = kAppFamilyBtnColor;
  290. _canEditAll = 0;
  291. }
  292. if (_isFamilyHeder==0)
  293. {
  294. _memberBtn.userInteractionEnabled = YES;
  295. _memberBtn.backgroundColor = kAppMainColor;
  296. }
  297. }
  298. else if ([responseJson toInt:@"status"] ==0 ) // 申请正在审核
  299. {
  300. if (_isFamilyHeder==1) {
  301. _headBtn.userInteractionEnabled = NO;
  302. _editBtn.userInteractionEnabled = NO;
  303. _editBtn.backgroundColor = kAppGrayColor3;
  304. _managerBtn.userInteractionEnabled = NO;
  305. _managerBtn.backgroundColor = kAppGrayColor3;
  306. }
  307. else if (_isFamilyHeder==0)
  308. {
  309. _memberBtn.userInteractionEnabled = NO;
  310. _memberBtn.backgroundColor = kAppGrayColor3;
  311. }
  312. }
  313. else if ([responseJson toInt:@"status"]==2) // 审核未通过
  314. {
  315. if (_isFamilyHeder==1)
  316. {
  317. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您的公会未通过审核")];
  318. _headBtn.userInteractionEnabled = YES;
  319. _editBtn.userInteractionEnabled = YES;
  320. _editBtn.backgroundColor = kAppMainColor;
  321. _managerBtn.userInteractionEnabled = NO;
  322. _managerBtn.backgroundColor = kAppGrayColor3;
  323. _canEditAll = 1;
  324. }
  325. if (_isFamilyHeder==0)
  326. {
  327. _memberBtn.userInteractionEnabled = NO;
  328. _memberBtn.backgroundColor = kAppGrayColor3;
  329. }
  330. }
  331. else if ([responseJson toInt:@"status"] == 3) // 公会已解散
  332. {
  333. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您的公会已解散")];
  334. [ws.navigationController popViewControllerAnimated:YES];
  335. }
  336. } FailureBlock:^(NSError *error) {
  337. }];
  338. }
  339. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  340. {
  341. [UIMenuController sharedMenuController].menuVisible = NO; //donot display the menu
  342. [_desTextView resignFirstResponder]; //do not allow the user to selected anything
  343. [_nameTextView resignFirstResponder];
  344. return NO;
  345. }
  346. @end