DepositViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. //
  2. // DepositViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/8/10.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. #import "DepositViewController.h"
  8. #import "SuctionMoneyCell.h"
  9. #import "SuctionContactWayCell.h"
  10. #import "SuctionDetailContactWayCell.h"
  11. #import "ProtocolTableViewCell.h"
  12. #import "AddressTableViewCell.h"
  13. #import "ConfirmTableViewCell.h"
  14. #import "PlaceTableViewCell.h"
  15. #import "AddressViewController.h"
  16. #import "ListModel.h"
  17. #import "MPersonCenterVC.h"
  18. @interface DepositViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UITextFieldDelegate>
  19. @property (nonatomic, strong) UITableView *myTableView;
  20. @property (nonatomic, strong) PlaceTableViewCell *placeCell;
  21. @property (nonatomic, strong) NSMutableArray *dataArray; //数据源
  22. @property (nonatomic, strong) SuctionDetailContactWayCell *cell;
  23. @property (nonatomic, assign) BOOL isFirst;
  24. @property (nonatomic, assign) NSInteger currentDiamonds; //当前红包的值
  25. @property (nonatomic, assign) int rs_count; //地址的个数
  26. @property (nonatomic, copy) NSString *consignee; //姓名
  27. @property (nonatomic, copy) NSString *consignee_mobile; //电话号码
  28. @property (nonatomic, copy) NSString *province; //省
  29. @property (nonatomic, copy) NSString *city; //市
  30. @property (nonatomic, copy) NSString *area; //区
  31. @property (nonatomic, copy) NSString *consignee_address; //详细地址
  32. @property (nonatomic, copy) NSString *placeUrl; //实物竞拍的地址链接
  33. @property (nonatomic, strong) UILabel *placePLabel; //收获信息的提示
  34. @end
  35. @implementation DepositViewController
  36. - (void)viewDidLoad
  37. {
  38. [super viewDidLoad];
  39. _dataArray = [[NSMutableArray alloc]init];
  40. _isFirst = YES;
  41. self.view.backgroundColor = kBackGroundColor;
  42. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  43. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  44. self.navigationItem.title = ASLocalizedString(@"参拍交保证金");
  45. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  46. self.placePLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,0, kScreenW-10, 45)];
  47. self.placePLabel.backgroundColor= kWhiteColor;
  48. self.placePLabel.font = [UIFont systemFontOfSize:14];
  49. self.placePLabel.textColor = kAppGrayColor1;
  50. self.placePLabel.text = ASLocalizedString(@"为保证竞拍成功后能顺利联系到您,请填写联系方式");
  51. _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-64)];
  52. _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  53. _myTableView.dataSource = self;
  54. _myTableView.delegate = self;
  55. [self.view addSubview:_myTableView];
  56. [_myTableView registerNib:[UINib nibWithNibName:@"SuctionMoneyCell" bundle:nil] forCellReuseIdentifier:@"SuctionMoneyCell"];
  57. [_myTableView registerNib:[UINib nibWithNibName:@"SuctionDetailContactWayCell" bundle:nil] forCellReuseIdentifier:@"SuctionDetailContactWayCell"];
  58. [_myTableView registerNib:[UINib nibWithNibName:@"PlaceTableViewCell" bundle:nil] forCellReuseIdentifier:@"PlaceTableViewCell"];
  59. [_myTableView registerNib:[UINib nibWithNibName:@"ConfirmTableViewCell" bundle:nil] forCellReuseIdentifier:@"ConfirmTableViewCell"];
  60. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
  61. // [_myTableView addGestureRecognizer:tap];
  62. if (self.type == 1)
  63. {
  64. [self loadNet];
  65. }
  66. }
  67. - (void)loadNet
  68. {
  69. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  70. [parmDict setObject:@"address" forKey:@"ctl"];
  71. [parmDict setObject:@"address" forKey:@"act"];
  72. [parmDict setObject:@"1" forKey:@"p"];
  73. [parmDict setObject:@"shop" forKey:@"itype"];
  74. FWWeakify(self)
  75. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  76. {
  77. FWStrongify(self)
  78. [self.dataArray removeAllObjects];
  79. if ([responseJson toInt:@"status"] == 1)
  80. {
  81. self.rs_count = [[responseJson objectForKey:@"data"] toInt:@"rs_count"];
  82. self.placeUrl = [[responseJson objectForKey:@"data"] toString:@"url"];
  83. NSArray *array = [[responseJson objectForKey:@"data"] objectForKey:@"list"];
  84. if (array && [array isKindOfClass:[NSArray class]])
  85. {
  86. if (array.count)
  87. {
  88. for (NSDictionary *dict in array)
  89. {
  90. if (dict && [dict isKindOfClass:[NSDictionary class]])
  91. {
  92. if (dict.count)
  93. {
  94. ListModel *model = [ListModel mj_objectWithKeyValues:dict];
  95. [self.dataArray addObject:model];
  96. }
  97. }
  98. }
  99. }
  100. }
  101. [self.myTableView reloadData];
  102. }
  103. } FailureBlock:^(NSError *error)
  104. {
  105. NSLog(@"error==%@",error);
  106. }];
  107. }
  108. - (void)tap
  109. {
  110. [self.cell.phoneTextFiled resignFirstResponder];
  111. [self.cell.personTextFiled resignFirstResponder];
  112. }
  113. - (void)viewWillAppear:(BOOL)animated
  114. {
  115. [super viewWillAppear:animated];
  116. [IQKeyboardManager sharedManager].enable = YES;
  117. [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  118. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  119. [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 5.0f;
  120. if (!self.isFirst)
  121. {
  122. [self loadNet];
  123. [self.myTableView reloadData];
  124. }
  125. self.isFirst = NO;
  126. }
  127. - (void)backClick
  128. {
  129. [self.navigationController popViewControllerAnimated:YES];
  130. }
  131. - (void)viewWillDisappear:(BOOL)animated
  132. {
  133. [super viewWillDisappear:animated];
  134. [IQKeyboardManager sharedManager].enable = NO;
  135. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  136. }
  137. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  138. {
  139. [textField resignFirstResponder];
  140. return YES;
  141. }
  142. #pragma mark -- dataSource/Delegate
  143. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  144. {
  145. return DepositTablevCount;
  146. }
  147. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  148. {
  149. if (section == DepositOneSection)
  150. {
  151. return 1;
  152. }
  153. else
  154. {
  155. if (section == DepositTwoSection && self.rs_count)//实物竞拍
  156. {
  157. return self.dataArray.count;
  158. }else
  159. {
  160. return 1;
  161. }
  162. }
  163. }
  164. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  165. {
  166. if (indexPath.section ==DepositZoneSection)
  167. {
  168. SuctionMoneyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SuctionMoneyCell"];
  169. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  170. [cell setCellWithMoney:self.bzMoney];
  171. return cell;
  172. }else if (indexPath.section == DepositOneSection)
  173. {
  174. static NSString *CellIdentifier1 = @"CellIdentifier1";
  175. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
  176. if (cell == nil)
  177. {
  178. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
  179. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  180. [cell.contentView addSubview:self.placePLabel];
  181. }
  182. return cell;
  183. }
  184. else if (indexPath.section == DepositTwoSection)
  185. {
  186. if (self.type == 0)//0虚拟1实物竞拍
  187. {
  188. self.cell = [tableView dequeueReusableCellWithIdentifier:@"SuctionDetailContactWayCell"];
  189. self.cell.selectionStyle = UITableViewCellSelectionStyleNone;
  190. self.cell.phoneTextFiled.delegate = self;
  191. self.cell.personTextFiled.delegate = self;
  192. return self.cell;
  193. }else
  194. {
  195. self.placeCell = [tableView dequeueReusableCellWithIdentifier:@"PlaceTableViewCell"];
  196. self.placeCell.selectionStyle = UITableViewCellSelectionStyleNone;
  197. if (self.rs_count)
  198. {
  199. ListModel *LModel = _dataArray[indexPath.row];
  200. [self.placeCell creatCellWithModel:LModel andRow:(int)indexPath.row];
  201. self.placeCell.nameLabel.hidden = NO;
  202. self.placeCell.placeLabel.hidden = NO;
  203. self.placeCell.rightImgView.hidden = NO;
  204. self.placeCell.addressButton.hidden = YES;
  205. }else
  206. {
  207. self.placeCell.addressButton.hidden = NO;
  208. self.placeCell.nameLabel.hidden = YES;
  209. self.placeCell.placeLabel.hidden = YES;
  210. self.placeCell.rightImgView.hidden = YES;
  211. }
  212. return self.placeCell;
  213. }
  214. }
  215. else
  216. {
  217. ConfirmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ConfirmTableViewCell"];
  218. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  219. [cell.comfirmButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  220. [cell.protocolButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  221. return cell;
  222. }
  223. }
  224. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  225. {
  226. if (indexPath.section == DepositZoneSection)
  227. {
  228. return 50;
  229. }
  230. else if (indexPath.section == DepositOneSection)
  231. {
  232. return 45;
  233. }
  234. else if (indexPath.section == DepositTwoSection)
  235. {
  236. if (self.type == 0)//0虚拟1实物竞拍
  237. {
  238. return 90;
  239. }else
  240. {
  241. return 70;
  242. }
  243. }
  244. else
  245. {
  246. return 100;
  247. }
  248. }
  249. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  250. {
  251. if (section == DepositZoneSection || section == DepositTwoSection|| section == DepositThreeSection)
  252. {
  253. return 10;
  254. }else
  255. {
  256. return 0;
  257. }
  258. }
  259. #pragma mark 进入充值页面
  260. - (void)chargerMoneyButton
  261. {
  262. MPersonCenterVC *acountVC = [[MPersonCenterVC alloc]init];
  263. [[AppDelegate sharedAppDelegate] pushViewController:acountVC animated:YES];
  264. }
  265. #pragma mark 同意并确认
  266. - (void)buttonClick:(UIButton *)sender
  267. {
  268. int index = (int)sender.tag;
  269. if (index == 0)//竞拍协议
  270. {
  271. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_auction_agreement isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  272. // tmpController.navTitleStr = ASLocalizedString(@"我的竞拍");
  273. [self.navigationController pushViewController:tmpController animated:YES];
  274. }else if (index == 1)//确认
  275. {
  276. int moneyCont = (int)[[IMAPlatform sharedInstance].host getDiamonds];
  277. if (moneyCont < [self.bzMoney intValue])
  278. {
  279. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"账户余额不够,请您先充值")];
  280. return;
  281. }
  282. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  283. if (self.type == 0)//虚拟
  284. {
  285. if (self.cell.personTextFiled.text.length <1)
  286. {
  287. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入联系人的姓名")];
  288. return;
  289. }
  290. [parmDict setObject:_cell.personTextFiled.text forKey:@"consignee"];
  291. if (self.cell.phoneTextFiled.text.length < 1)
  292. {
  293. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入11位电话号码")];
  294. return;
  295. }
  296. [parmDict setObject:self.cell.phoneTextFiled.text forKey:@"consignee_mobile"];
  297. }else//实物
  298. {
  299. if (self.rs_count < 1)
  300. {
  301. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请填写收货信息")];
  302. return;
  303. }else
  304. {
  305. ListModel *LModel = self.dataArray[0];
  306. if (LModel.consignee.length < 1)
  307. {
  308. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请填写联系人")];
  309. return;
  310. }
  311. [parmDict setObject:LModel.consignee forKey:@"consignee"];
  312. if (LModel.consignee_mobile.length < 1)
  313. {
  314. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请填写联系电话号码")];
  315. return;
  316. }
  317. [parmDict setObject:LModel.consignee_mobile forKey:@"consignee_mobile"];
  318. if (LModel.consignee_district.province.length > 0 && LModel.consignee_district.city.length > 0 && LModel.consignee_district.area.length > 0)
  319. {
  320. [parmDict setObject:[NSString stringWithFormat:@"{\"area\":\"%@\",\"city\":\"%@\",\"province\":\"%@\"}",LModel.consignee_district.area,LModel.consignee_district.city,LModel.consignee_district.province] forKey:@"consignee_district"];
  321. }
  322. if (LModel.consignee_address.length < 1)
  323. {
  324. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请填写详细地址")];
  325. return;
  326. }
  327. [parmDict setObject:LModel.consignee_address forKey:@"consignee_address"];
  328. }
  329. }
  330. [parmDict setObject:@"pai_user" forKey:@"ctl"];
  331. [parmDict setObject:@"dojoin" forKey:@"act"];
  332. if (self.productId)
  333. {
  334. [parmDict setObject:self.productId forKey:@"id"];
  335. }
  336. [parmDict setObject:@"shop" forKey:@"itype"];
  337. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  338. {
  339. if ([responseJson toInt:@"status"] == 1)
  340. {
  341. // [[LiveCenterManager sharedInstance] showChangeAuctionLiveScreenSOfIsSmallScreen:NO nextViewController:nil delegateWindowRCNameStr:@"BGTabBarController" complete:^(BOOL finished) {
  342. //
  343. // }];
  344. [self backLiveVC];
  345. }
  346. } FailureBlock:^(NSError *error)
  347. {
  348. NSLog(@"error===%@",error);
  349. }];
  350. }
  351. }
  352. - (void)viewDidDisappear:(BOOL)animated
  353. {
  354. [super viewDidDisappear:animated];
  355. [IQKeyboardManager sharedManager].enable = NO;
  356. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  357. }
  358. - (void)textFieldDidEndEditing:(UITextField *)textField
  359. {
  360. if (textField ==self.cell.phoneTextFiled)
  361. {
  362. if (self.cell.phoneTextFiled.text.length < 1)
  363. {
  364. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入电话号码")];
  365. return;
  366. }
  367. if (self.cell.phoneTextFiled.text.length < 1)
  368. {
  369. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入11位电话号码")];
  370. return;
  371. }
  372. // if (![self.cell.phoneTextFiled.text isTelephone])
  373. // {
  374. // [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入正确的电话号码")];
  375. // return;
  376. // }
  377. }
  378. }
  379. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  380. {
  381. if (textField == self.cell.phoneTextFiled)
  382. {
  383. textField.keyboardType = UIKeyboardTypeNumberPad;
  384. }
  385. return YES;
  386. }
  387. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  388. {
  389. if (textField == self.cell.phoneTextFiled)
  390. {
  391. if (![string isNumber])
  392. {
  393. return NO;
  394. }
  395. if (string.length == 0)
  396. return YES;
  397. NSInteger existedLength = textField.text.length;
  398. NSInteger selectedLength = range.length;
  399. NSInteger replaceLength = string.length;
  400. if (existedLength - selectedLength + replaceLength > 11)
  401. {
  402. return NO;
  403. }
  404. }
  405. return YES;
  406. }
  407. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  408. {
  409. if (indexPath.section == DepositTwoSection)
  410. {
  411. AddressViewController *addressVC = [[AddressViewController alloc]init];
  412. if (self.rs_count > 0)//修改地址
  413. {
  414. ListModel *model = _dataArray[0];
  415. addressVC.personName = model.consignee;
  416. addressVC.address_id = model.ID;
  417. addressVC.personPhone = model.consignee_mobile;
  418. addressVC.area = [NSString stringWithFormat:@"%@ %@ %@",model.consignee_district.province,model.consignee_district.city,model.consignee_district.area];
  419. addressVC.provinceStr = model.consignee_district.province;
  420. addressVC.cityStr = model.consignee_district.province;
  421. addressVC.provinceStr = model.consignee_district.city;
  422. addressVC.areaStr = model.consignee_district.area;
  423. addressVC.detailArea = model.consignee_address;
  424. addressVC.type = 1;
  425. [self.navigationController pushViewController:addressVC animated:YES];
  426. }else
  427. {
  428. addressVC.type = 0;
  429. [self.navigationController pushViewController:addressVC animated:YES];
  430. }
  431. }
  432. }
  433. //返回直播间
  434. - (void)backLiveVC
  435. {
  436. UIViewController *viewCtl;
  437. for (int i = 0; i < [self.navigationController.viewControllers count]; i ++)
  438. {
  439. viewCtl = [self.navigationController.viewControllers objectAtIndex:(i)];
  440. if ([viewCtl isKindOfClass:[BGTLiveController class]] || [viewCtl isKindOfClass:[BGKSYLiveController class]])
  441. {
  442. [self.navigationController popToViewController:viewCtl animated:YES];
  443. }
  444. }
  445. }
  446. @end