MGAddWishViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // MGAddWithViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/5.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGAddWishViewController.h"
  9. @interface MGAddWishViewController ()<UITableViewDelegate,UITableViewDataSource,MGLiveAddWishCellDelegate>
  10. @property(nonatomic, strong) UITableView *tableView;
  11. @property(nonatomic, strong) NSMutableArray *listArr;
  12. //@property(nonatomic, strong) NSMutableArray *listGiftArr;
  13. //@property(nonatomic, strong) NSMutableArray *listWishArr;
  14. @property(nonatomic, strong) MGLiveWishModel *model;
  15. @end
  16. @implementation MGAddWishViewController
  17. -(instancetype)initWithWishType:(MGADD_WISH)wishType{
  18. MGAddWishViewController *vc = [MGAddWishViewController new];
  19. vc.wishType = wishType;
  20. return vc;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self setModel];
  26. self.navigationController.navigationBar.hidden = YES;
  27. self.navigationController.navigationBarHidden = YES;
  28. UILabel *titleL = [UILabel new];
  29. titleL.frame = CGRectMake(0, MG_TOP_MARGIN + 4, kScreenW / 2, kRealValue(44));
  30. titleL.textAlignment = NSTextAlignmentCenter;
  31. titleL.centerX = kScreenW / 2;
  32. titleL.text = self.wishType == MGWISHTYPE_ADD ? ASLocalizedString(@"添加礼物和数量"): ASLocalizedString(@"选择礼物");
  33. titleL.text = self.wishType == MGWISHTYPE_LIST ? ASLocalizedString(@"心愿单"): titleL.text;
  34. titleL.font = [UIFont systemFontOfSize:15];
  35. [self.view addSubview:titleL];
  36. UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW - kRealValue(80), MG_TOP_MARGIN, kRealValue(80), kNavigationBarHeight)];
  37. // [rightButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
  38. [rightButton setTitle:ASLocalizedString(@"完成")forState:UIControlStateNormal];
  39. [rightButton setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  40. [rightButton addTarget:self action:@selector(clickRightBtn:) forControlEvents:UIControlEventTouchUpInside];
  41. [self.view addSubview:rightButton];
  42. // 左上角按钮
  43. UIButton *leftButton = [[UIButton alloc]initWithFrame:CGRectMake(20, MG_TOP_MARGIN + 4, 35, kNavigationBarHeight)];
  44. [leftButton setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  45. [leftButton addTarget:self action:@selector(clickLefttBtn:) forControlEvents:UIControlEventTouchUpInside];
  46. leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  47. [self.view addSubview:leftButton];
  48. self.view.backgroundColor = kWhiteColor;
  49. [self setUpView];
  50. if (self.wishType == MGWISHTYPE_ADD_GIFT || self.wishType == MGWISHTYPE_LIST) {
  51. self.tableView.height = kScreenH - kTopHeight;
  52. rightButton.hidden = YES;
  53. }
  54. }
  55. -(void)setModel{
  56. self.listArr = [NSMutableArray array];
  57. if (self.wishType == MGWISHTYPE_ADD_GIFT) {
  58. self.model = [MGLiveWishModel new];
  59. }else{
  60. }
  61. self.model = [MGLiveWishModel new];
  62. [self requestModel];
  63. }
  64. -(void)requestModel{
  65. //4-16 3.心愿单无效。
  66. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  67. NSString *actStr = @"";
  68. // //心愿单礼物列表
  69. if (self.wishType == MGWISHTYPE_ADD_GIFT) {
  70. actStr = @"gift_list";
  71. }else if (self.wishType == MGWISHTYPE_LIST){
  72. actStr = @"wish_list";
  73. [mDict setObject:_roomId forKey:@"room_id"];
  74. }
  75. if ([BGUtils isBlankString:actStr]) {
  76. return;
  77. }
  78. [mDict setObject:@"user_wish" forKey:@"ctl"];
  79. [mDict setObject:actStr forKey:@"act"];
  80. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  81. if ([responseJson toInt:@"status"] == 1)
  82. {
  83. [self.listArr removeAllObjects];
  84. NSArray *arr = [responseJson valueForKey:@"list"];
  85. if (arr.count > 0) {
  86. for (NSDictionary *dic in arr)
  87. {
  88. MGLiveWishModel *model = [MGLiveWishModel mj_objectWithKeyValues:dic];
  89. [self.listArr addObject:model];
  90. }
  91. }
  92. [self.tableView reloadData];
  93. }
  94. } FailureBlock:^(NSError *error) {
  95. }];
  96. }
  97. - (void)viewWillAppear:(BOOL)animated {
  98. [super viewWillAppear:animated];
  99. self.navigationController.navigationBarHidden = YES;
  100. }
  101. -(void)clickRightBtn:(UIBarButtonItem *)item{
  102. MGLiveAddWishCell *numCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
  103. MGLiveAddWishCell *txtCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
  104. self.model.g_num = numCell.textField.text;
  105. self.model.txt = txtCell.textField.text;
  106. if ([BGUtils isBlankString:self.model.g_id]) {
  107. [FanweMessage alert:ASLocalizedString(@"请选择礼物")];
  108. return;
  109. }
  110. if ([BGUtils isBlankString:self.model.g_num]) {
  111. [FanweMessage alert:ASLocalizedString(@"请填写礼物数量")];
  112. return;
  113. }
  114. if ([BGUtils isBlankString:self.model.txt]) {
  115. self.model.txt = @"";
  116. }
  117. if (self.clickGiftCellBlcok) {
  118. self.clickGiftCellBlcok(self.model);
  119. }
  120. [self.navigationController popViewControllerAnimated:YES];
  121. }
  122. -(void)clickLefttBtn:(UIBarButtonItem *)item{
  123. [self.navigationController popViewControllerAnimated:YES];
  124. }
  125. -(void)protocolClickLiveAddWishModel:(MGLiveWishModel *)model{
  126. self.model.g_id = model.id;
  127. }
  128. -(void)setUpView{
  129. [self.view addSubview:self.tableView];
  130. }
  131. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  132. return 1;
  133. }
  134. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  135. return self.wishType == MGWISHTYPE_ADD ? 3 : self.listArr.count;
  136. }
  137. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  138. if (self.wishType == MGWISHTYPE_LIST) {
  139. return kRealValue(185);
  140. }
  141. return kRealValue(44);
  142. }
  143. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  144. MGLiveAddWishCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MGLiveAddWishCell"];
  145. if (self.wishType == MGWISHTYPE_ADD){
  146. MGLiveAddWishCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MGLiveAddWishCell"];
  147. cell.delegate = self;
  148. [cell resetCellWithWishType:self.wishType WithModel:nil];
  149. NSArray *arr = @[ASLocalizedString(@"选择礼物"),ASLocalizedString(@"添加数量"),ASLocalizedString(@"报答方式(选填)")];
  150. NSArray *placeHolderArr = @[ASLocalizedString(@"无"),ASLocalizedString(@"数量最多输入5个"),ASLocalizedString(@"编辑8字以内")];
  151. cell.topicL.text = arr[indexPath.row];
  152. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  153. cell.textField.enabled = indexPath.row != 0;
  154. if (indexPath.row == 1) {
  155. cell.textField.keyboardType = UIKeyboardTypeNumberPad;
  156. }
  157. cell.textField.placeholder = placeHolderArr[indexPath.row];
  158. cell.textFieldBlock = ^(NSString * _Nonnull str) {
  159. if (indexPath.row == 1) self.model.g_num = str;
  160. if (indexPath.row == 2) self.model.txt = str;
  161. };
  162. return cell;
  163. }else if (self.wishType == MGWISHTYPE_ADD_GIFT) {
  164. MGLiveAddWishCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MGLiveAddWishCell"];
  165. [cell resetCellWithWishType:self.wishType WithModel:self.listArr[indexPath.row]];
  166. return cell;
  167. }else if (self.wishType == MGWISHTYPE_LIST){
  168. MGLiveWishListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MGLiveWishListCell"];
  169. [cell resetCellWithWishType:self.wishType WithModel:self.listArr[indexPath.row]];
  170. NSString *str = ASLocalizedString(@"心愿一");
  171. if (indexPath.row == 1) {
  172. str = ASLocalizedString(@"心愿二");
  173. }else if (indexPath.row == 2){
  174. str = ASLocalizedString(@"心愿三");
  175. }
  176. cell.titleL.text = str;
  177. return cell;
  178. }
  179. return cell;
  180. }
  181. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  182. __weak __typeof(self)weakSelf = self;
  183. if (indexPath.row == 0 && self.wishType == MGWISHTYPE_ADD) {
  184. MGAddWishViewController *vc = [[MGAddWishViewController alloc]initWithWishType:MGWISHTYPE_ADD_GIFT];
  185. vc.clickGiftCellBlcok = ^(MGLiveWishModel * _Nonnull wishModel) {
  186. weakSelf.model = wishModel;
  187. weakSelf.model.g_id = wishModel.id;
  188. weakSelf.model.g_icon = wishModel.icon;
  189. weakSelf.model.g_name = wishModel.name;
  190. MGLiveAddWishCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
  191. cell.textField.text = wishModel.name;
  192. [cell.iconImgView sd_setImageWithURL:[NSURL URLWithString:wishModel.icon] placeholderImage:nil];
  193. };
  194. [self.navigationController pushViewController:vc animated:YES];
  195. }
  196. if (self.wishType == MGWISHTYPE_ADD_GIFT) {//点击选择礼物后返回
  197. MGLiveWishModel *model = self.listArr[indexPath.row];
  198. if (self.clickGiftCellBlcok) {
  199. self.clickGiftCellBlcok(model);
  200. }
  201. [weakSelf.navigationController popViewControllerAnimated:YES];
  202. }
  203. }
  204. -(UITableView *)tableView{
  205. if (!_tableView) {
  206. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kTopHeight, kScreenW, kScreenH / 2 - kTopHeight) style:UITableViewStylePlain];
  207. _tableView.delegate = self;
  208. _tableView.dataSource = self;
  209. [_tableView registerClass:[MGLiveAddWishCell class] forCellReuseIdentifier:@"MGLiveAddWishCell"];
  210. [_tableView registerClass:[MGLiveWishListCell class] forCellReuseIdentifier:@"MGLiveWishListCell"];
  211. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  212. _tableView.tableFooterView = [UIView new];
  213. }
  214. return _tableView;
  215. }
  216. @end