Brak opisu

SubmitOrderController.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. //
  2. // SubmitOrderControllerViewController.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/6/18.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "SubmitOrderController.h"
  9. #import "SubmitAddNewCell.h"
  10. #import "SubmitDefaultAddressCell.h"
  11. #import "SubmitDefaultIDCardCell.h"
  12. #import "ConnectServiceHeaderCell.h"
  13. #import "ProductDetailTableCell.h"
  14. #import "FKSubmitDiscountView.h"
  15. #import "SubmitInputCell.h"
  16. #import "PindanCommonCell.h"
  17. #import "SubmitCarriageMoneyCell.h"
  18. #import "SubmitDiscountCardCell.h"
  19. #import "FKGroupStepCell.h"
  20. #import "SubmitBottomView.h"
  21. #import "SubmitSelectTransportView.h"
  22. #import "SubmitDiscountPickView.h"
  23. #import "FKAddressDetailController.h"
  24. #import "FKAddressListController.h"
  25. #import "FKAddIdCardController.h"
  26. #import "FKIdCardManageController.h"
  27. #import "ChatViewController.h"
  28. #import "FLControllerHelper.h"
  29. #import "OrderPayController.h"
  30. #import "WebViewController.h"
  31. #import "FKSubmitOrderRequest.h"
  32. #import "FKSubmitOrderReform.h"
  33. #import "FKBindIdCardRequest.h"
  34. #import "FKBindIdCardReform.h"
  35. #define kMessageTextFieldTag 40
  36. #define kInviteTextFiedlTag 41
  37. #define kInviteAlertTag 100
  38. #define kDeleteSpecAlertTag 900
  39. @interface SubmitOrderController ()
  40. <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UIAlertViewDelegate, FLNetworkDelegate, FKAddressListControllerDataSource, FKAddressListControllerDelegate, FKIdCardManageControllerDataSource, FKIdCardManageControllerDelegate>
  41. @property (nonatomic, strong) UITableView *tableView;
  42. @property (nonatomic, strong) SubmitBottomView *bottomView;
  43. @property (nonatomic, strong) FKSubmitDiscountView *discountView;
  44. @property (nonatomic, strong) SubmitDiscountPickView *pickerView;
  45. @end
  46. @implementation SubmitOrderController
  47. - (instancetype)initWithPurchaseCache:(FKPurchaseCache *)cache {
  48. self = [super init];
  49. if (self) {
  50. self.viewModel.cache = cache;
  51. }
  52. return self;
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. [self initializeLayout];
  57. [self registerTableViewCells];
  58. }
  59. - (void)dealloc {
  60. [[NSNotificationCenter defaultCenter] removeObserver:self];
  61. }
  62. - (void)viewWillAppear:(BOOL)animated {
  63. [super viewWillAppear:animated];
  64. self.navigationItem.title = @"提交订单";
  65. [self.navigationController setNavigationBarHidden:NO animated:YES];
  66. // 如果有省份请求运费(地址选择页面回来)
  67. if ([self.viewModel hasAddressProvince]){
  68. [self requestForCarriage];
  69. } else {
  70. [self requestForInitalData];
  71. }
  72. if (self.viewModel.cache.isPindanNeedIDCard && !self.viewModel.selectedIdCardItem) {
  73. [FKBindIdCardRequest requestIdCardListDelegate:self];
  74. }
  75. }
  76. - (void)viewDidAppear:(BOOL)animated {
  77. [super viewDidAppear:animated];
  78. }
  79. - (void)viewWillDisappear:(BOOL)animated {
  80. [super viewWillDisappear:animated];
  81. self.navigationItem.title = @" ";
  82. [self.view endEditing:YES];
  83. if ([self.pickerView isShowing]) {
  84. [self.pickerView dismissAnimated];
  85. }
  86. }
  87. - (void)viewDidDisappear:(BOOL)animated {
  88. [super viewDidDisappear:animated];
  89. }
  90. #pragma mark - Request
  91. - (void)requestForInitalData {
  92. [self.hudView show:YES];
  93. [FKSubmitOrderRequest requestUserAddressWithDelegate:self];
  94. [FKSubmitOrderRequest requestDiscountDataWithPostID:self.viewModel.cache.postID delegate:self];
  95. [FKSubmitOrderRequest requestPostageFreeWithDelegate:self];
  96. }
  97. - (void)requestForCarriage {
  98. // 请求运费
  99. NSString *province = [self.viewModel province];
  100. if (!province || province.length == 0) return;
  101. [self.hudView show:YES];
  102. long allWeight = [self.viewModel.cache getAllWeight];
  103. NSString *allWeightString = [NSString stringWithFormat:@"%ld", allWeight];
  104. [FKSubmitOrderRequest requestCarriagePriceWithProvince:province
  105. allWight:allWeightString
  106. delegate:self];
  107. }
  108. - (void)requestToCreateOrder {
  109. [self.hudView show:YES];
  110. [FKSubmitOrderRequest requestTradeNoWithJson:[self.viewModel getJsonStringForTradeNoRequset]
  111. subClassJsonStr:[self.viewModel getSubClassJsonStringForTradeNoRequset]
  112. delegate:self];
  113. }
  114. #pragma mark - response
  115. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  116. [self.hudView hide:NO];
  117. if (identify == CARRIAGE_PRICE_REQ) {
  118. [self.tableView reloadData]; // 刷新代金券的bug
  119. [self refreshBottomView];
  120. } else if (identify == INVITE_CHECK_REQ){
  121. [FLProgressHUDHelper showText:@"邀请码验证失败" inView:self.view];
  122. self.viewModel.isInviteTrue = NO;
  123. [self refreshBottomView];
  124. return;
  125. }
  126. if (header.code.intValue == RESPONSE_MSG_BUSINESS_EXCEPTION) {
  127. [FLProgressHUDHelper showText:header.msg inView:self.view];
  128. } else if (header.code.intValue == RESPONSE_MSG_ACCESS_EXCEPTION){
  129. [FLProgressHUDHelper showText:@"请求失败" inView:self.view];
  130. }
  131. }
  132. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
  133. [self.hudView hide:NO];
  134. if (identify == ID_CARD_LIST_REQUEST) {
  135. NSArray *idCardArray = [FKBindIdCardReform parserIdCardListWithData:response];
  136. self.viewModel.selectedIdCardItem = [SubmitOrderViewModel validIdCardItemFromArray:idCardArray];
  137. [self.tableView reloadData];
  138. } else if (identify == USER_ADDRESS_REQ) {
  139. ShipAddress *addressModel = [FKSubmitOrderReform parserAddresModelWithDict:response];
  140. if (addressModel) {
  141. self.viewModel.selectedAddress = addressModel;
  142. if ([self.viewModel isPostageFree]) {
  143. [self.tableView reloadData];
  144. [self refreshBottomView];
  145. return;
  146. }
  147. NSString *allWeightString = [NSString stringWithFormat:@"%ld", [self.viewModel.cache getAllWeight]];
  148. [FKSubmitOrderRequest requestCarriagePriceWithProvince:[self.viewModel province]
  149. allWight:allWeightString delegate:self];
  150. } else {
  151. [self.tableView reloadData];
  152. [self refreshBottomView];
  153. }
  154. } else if (identify == CARRIAGE_PRICE_REQ) {
  155. self.viewModel.carriagePrice = [FKSubmitOrderReform parserCarriagePriceWithDict:response];
  156. [self.tableView reloadData];
  157. [self refreshBottomView];
  158. } else if (identify == DISCOUNT_DATA_REQ) {
  159. self.viewModel.discountModel = [FKSubmitOrderReform parserDiscountItemWithDict:response];
  160. self.viewModel.inviteCutFee = [FKSubmitOrderReform parserInviteCutFeeWithDict:response];
  161. [self.viewModel ruledDiscount];
  162. [self.tableView reloadData];
  163. [self refreshBottomView];
  164. } else if (identify == TRADE_NO_REQ) {
  165. self.viewModel.paymentModel = [FKSubmitOrderReform parserPaymentItemWithDict:response];
  166. if (!self.viewModel.paymentModel) {
  167. [FLProgressHUDHelper showText:header.msg inView:self.view];
  168. return;
  169. }
  170. [self pushOrderPayController:self.viewModel.paymentModel];
  171. } else if (identify == INVITE_CHECK_REQ) {
  172. self.viewModel.isInviteTrue = [FKSubmitOrderReform parserInviteResWithDict:response];
  173. if (!self.viewModel.isInviteTrue) {
  174. [FLProgressHUDHelper showText:@"邀请码错误" inView:self.view];
  175. }
  176. [self refreshBottomView];
  177. } else if (identify == POSTAGE_FREE_REQ) {
  178. self.viewModel.isInternationalPostageFree = [FKSubmitOrderReform parseInternationalPostageFree:response];
  179. self.viewModel.activityText = [FKSubmitOrderReform parseActivityText:response];
  180. if (self.viewModel.isInternationalPostageFree) {
  181. [self.viewModel ruledDiscount];
  182. [self.tableView reloadData];
  183. self.discountView.hidden = NO;
  184. self.discountView.textLabel.text = self.viewModel.activityText;
  185. } else {
  186. self.discountView.hidden = YES;
  187. }
  188. }
  189. }
  190. #pragma mark - tableView dataSoure && delegate
  191. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  192. return [self.viewModel numberOfSectionsInTableView];
  193. }
  194. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  195. return [self.viewModel numberOfRowsInSection:section];
  196. }
  197. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  198. int cellType = 0;
  199. UITableViewCell *cell = [self.viewModel buildCellWithTableView:tableView forIndexPath:indexPath cellType:&cellType];
  200. switch (cellType) {
  201. case kSubmitCellTypeProductDetail:{
  202. WeakSelf(weakSelf);
  203. ProductDetailTableCell *detailCell = (ProductDetailTableCell *)cell;
  204. detailCell.numberChangeAction = ^(NSInteger number, NSIndexPath *indexPath){
  205. return [weakSelf refreshWithNewNumber:number indexPath:indexPath];
  206. };
  207. if (self.viewModel.cache.orderType == kOrderTypeGroup) {
  208. [detailCell configCellForGroup];
  209. } else {
  210. [detailCell configCellForNormal];
  211. }
  212. }
  213. break;
  214. case kSubmitCellTypeDiscount:{
  215. SubmitDiscountCardCell *discountCell = (SubmitDiscountCardCell *)cell;
  216. [discountCell.actionButton addTarget:self
  217. action:@selector(disCountButtonClick)
  218. forControlEvents:UIControlEventTouchUpInside];
  219. }
  220. break;
  221. case kSubmitCellTypeInvite:{
  222. SubmitInputCell *inviteCell = (SubmitInputCell *)cell;
  223. inviteCell.inputField.delegate = self;
  224. inviteCell.inputField.tag = kInviteTextFiedlTag;
  225. return inviteCell;
  226. }
  227. break;
  228. case kSubmitCellTypeMessage:{
  229. SubmitInputCell *messageCell = (SubmitInputCell *)cell;
  230. messageCell.inputField.delegate = self;
  231. messageCell.inputField.tag = kMessageTextFieldTag;
  232. return messageCell;
  233. }
  234. default:
  235. break;
  236. }
  237. return cell;
  238. }
  239. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  240. return [self.viewModel cellHeightForIndexPath:indexPath];
  241. }
  242. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  243. return 10;
  244. }
  245. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  246. if (section == ([self.viewModel numberOfSectionsInTableView] - 1)) {
  247. if ([self.viewModel isInternationalPostageFree]) {
  248. return 32;
  249. }
  250. return 10;
  251. }
  252. return CGFLOAT_MIN;
  253. }
  254. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  255. kSubmitCellType type = [self.viewModel cellTypeForIndexPath:indexPath];
  256. switch (type) {
  257. case kSubmitCellTypeAddAddress: {
  258. UIViewController *controller = [[FKAddressDetailController alloc] initWithAddress:nil type:FKAddressDetailControllerTypeAdd];
  259. controller.hidesBottomBarWhenPushed = YES;
  260. [self.navigationController pushViewController:controller animated:YES];
  261. break;
  262. }
  263. case kSubmitCellTypeAddress: {
  264. FKAddressListController *controller = [[FKAddressListController alloc] initWithType:FKAddressListControllerTypeChoice];
  265. controller.dataSource = self;
  266. controller.delegate = self;
  267. controller.hidesBottomBarWhenPushed = YES;
  268. [self.navigationController pushViewController:controller animated:YES];
  269. break;
  270. }
  271. case kSubmitCellTypeAddIDCard: {
  272. UIViewController *controller = [FKAddIdCardController new];
  273. controller.hidesBottomBarWhenPushed = YES;
  274. [self.navigationController pushViewController:controller animated:YES];
  275. break;
  276. }
  277. case kSubmitCellTypeIDCard: {
  278. FKIdCardManageController *controller = [FKIdCardManageController new];
  279. controller.dataSource = self;
  280. controller.delegate = self;
  281. controller.hidesBottomBarWhenPushed = YES;
  282. [self.navigationController pushViewController:controller animated:YES];
  283. break;
  284. }
  285. case kSubmitCellTypeGroupProgress: {
  286. WebViewController *web = [[WebViewController alloc]init];
  287. web.url = [FKGroupStepCell pushExplainUrl];
  288. web.hidesBottomBarWhenPushed = YES;
  289. [self.navigationController pushViewController:web animated:YES];
  290. break;
  291. }
  292. default:
  293. break;
  294. }
  295. }
  296. #pragma mark - FKAddressListController DataSource & Delegate
  297. - (NSString *)currentSelectedAddressID {
  298. return self.viewModel.selectedAddress.addressID;
  299. }
  300. - (void)addressListController:(FKAddressListController *)controller didSelectAddress:(ShipAddress *)address {
  301. if (address){
  302. self.viewModel.selectedAddress = address;
  303. [self.navigationController popToViewController:self animated:YES];
  304. }
  305. }
  306. - (void)addressListController:(FKAddressListController *)controller didUpdateAddress:(ShipAddress *)address {
  307. self.viewModel.selectedAddress = address;
  308. }
  309. #pragma mark - FKIdCardManageController DataSource & Delegate
  310. - (NSString *)currentSelectedIDCard {
  311. return self.viewModel.selectedIdCardItem.itemID;
  312. }
  313. - (void)idCardManageController:(FKIdCardManageController *)controller didSelectItem:(FKIdCardItem *)item {
  314. if (item) {
  315. self.viewModel.selectedIdCardItem = item;
  316. [self.navigationController popToViewController:self animated:YES];
  317. }
  318. }
  319. - (void)idCardManageController:(FKIdCardManageController *)controller didRemoveItem:(FKIdCardItem *)item {
  320. self.viewModel.selectedIdCardItem = nil;
  321. }
  322. - (void)idCardManageController:(FKIdCardManageController *)controller didUpdateItem:(FKIdCardItem *)item {
  323. self.viewModel.selectedIdCardItem = item;
  324. }
  325. #pragma mark - action
  326. - (void)disCountButtonClick {
  327. [self.view endEditing:YES];
  328. NSArray *titleArray = [self.viewModel.discountModel getDiscountStringArray];
  329. NSUInteger selectedIndex = [self.viewModel.discountModel usefulIndexWithDiscount:self.viewModel.selectedDiscount] + 1;
  330. [self.pickerView refreshTitleArray:titleArray withSelectedIndex:selectedIndex];
  331. [self.pickerView showInView:self.navigationController.view animated:YES];
  332. }
  333. - (void)submitConfirmBtnClick {
  334. // 判断收件地址是否为空
  335. if (![self.viewModel hasAddress]){
  336. [FLProgressHUDHelper showTipAlert:@"收货地址不能为空"];
  337. return;
  338. }
  339. // 判断邀请码是否正确,是否需要提示
  340. if ([self.viewModel shouldShowInviteAssert]) {
  341. UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示"
  342. message:@"邀请码不正确,是否继续下单"
  343. delegate:self
  344. cancelButtonTitle:@"取消"
  345. otherButtonTitles:@"继续", nil];
  346. alertView.tag = kInviteAlertTag;
  347. [alertView show];
  348. return;
  349. }
  350. [self requestToCreateOrder];
  351. }
  352. #pragma mark - push controller
  353. - (void)pushLawList{
  354. }
  355. - (void)pushOrderPayController:(SubmitPaymentItem *)paymentItem {
  356. [self.viewModel saveDataIntoCache:self.viewModel.cache];
  357. if (self.viewModel.cache.isNeedBindIDCard) {
  358. paymentItem.successController = FKOrderPaymentSuccessControllerBindIDCard;
  359. } else {
  360. if (self.viewModel.cache.orderType == kOrderTypeGroup) {
  361. paymentItem.successController = FKOrderPaymentSuccessControllerGroupOrder;
  362. } else {
  363. paymentItem.successController = FKOrderPaymentSuccessControllerRedpacket;
  364. }
  365. }
  366. OrderPayController *payController = [[OrderPayController alloc] initWithPaymentItem:paymentItem];
  367. NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
  368. [viewControllers removeLastObject];
  369. [viewControllers addObject:payController];
  370. [self.navigationController setViewControllers:viewControllers animated:YES];
  371. }
  372. #pragma mark - method
  373. - (void)discountSelectDoneWithIndex:(NSInteger)index {
  374. // 选择代金券
  375. if (index == 0) { // 不使用代金券
  376. self.viewModel.selectedDiscount = nil;
  377. }else{
  378. self.viewModel.selectedDiscount = [self.viewModel.discountModel usefulDiscountAtIndex:index - 1];
  379. }
  380. [self refreshBottomView];
  381. [self.tableView reloadData];
  382. }
  383. - (BOOL)refreshWithNewNumber:(NSInteger)number indexPath:(NSIndexPath *)indexPath {
  384. if (number == 0){
  385. if (self.viewModel.cache.specArray.count <= 1) return NO;
  386. UIAlertView *alerView = [[UIAlertView alloc]initWithTitle:@"提示"
  387. message:@"确定要删除该规格吗?"
  388. delegate:self
  389. cancelButtonTitle:@"取消"
  390. otherButtonTitles:@"确认", nil];
  391. alerView.tag = (indexPath.row - 1) + kDeleteSpecAlertTag;
  392. [alerView show];
  393. return NO;
  394. }
  395. NSInteger specIndex = indexPath.row - 1;
  396. NSInteger allCount = number;
  397. for (NSInteger i = 0; i < self.viewModel.cache.specArray.count; i++) {
  398. PindanSpecItem *item = self.viewModel.cache.specArray[i];
  399. if (i != specIndex) allCount += item.selectedAmount;
  400. }
  401. if (allCount > [self.viewModel.cache getRealAmountLimit]) {
  402. NSString *warnString = [NSString stringWithFormat:@"每个账号只能购买%ld件哦", (long)[self.viewModel.cache getRealAmountLimit]];
  403. [FLProgressHUDHelper showText:warnString inView:self.view];
  404. return NO;
  405. }
  406. if (number > [self.viewModel.cache getStockLimitAtIndex:specIndex]) {
  407. NSString *warnString = [NSString stringWithFormat:@"该商品库存仅剩%ld件", (long)[self.viewModel.cache getStockLimitAtIndex:specIndex]];
  408. [FLProgressHUDHelper showText:warnString inView:self.view];
  409. return NO;
  410. }
  411. // 数量改变
  412. [self refreshSpecNumber:number atIndex:specIndex];
  413. return YES;
  414. }
  415. - (void)refreshSpecNumber:(NSUInteger)number atIndex:(NSInteger)index{
  416. [self.viewModel.cache changeSpecAmount:number AtIndex:index];
  417. [self.viewModel ruledDiscount]; // 对代金券重新判断
  418. long allWeight = [self.viewModel.cache getAllWeight];
  419. NSString *allWeightString = [NSString stringWithFormat:@"%ld", allWeight];
  420. [self.tableView reloadData];
  421. [self refreshBottomView];
  422. // 如果改变数字时,用户并未选择收货地址,下条请求里面已经中断
  423. [FKSubmitOrderRequest requestCarriagePriceWithProvince:[self.viewModel province]
  424. allWight:allWeightString
  425. delegate:self];
  426. }
  427. - (void)refreshBottomView {
  428. CGFloat totalFee = [self.viewModel.cache getTotalPrice] + [self.viewModel getCountryInCarriage];
  429. // 减去代金券
  430. CGFloat discountFee = [self.viewModel getCurrentDiscountFee];
  431. // 减去邀请码抵用
  432. CGFloat inviteFee = [self.viewModel getCurrentInviteFee];
  433. /**
  434. * 减去国际运费
  435. */
  436. CGFloat internationalPostageFee = [self.viewModel freeInternationalPostageFee];
  437. CGFloat allFee = totalFee - discountFee - inviteFee - internationalPostageFee;
  438. if (allFee < 0) allFee = 0;
  439. long allCount = [self.viewModel.cache getAllAmount];
  440. [self.bottomView refreshPriceWithAmount:allCount
  441. totalFee:allFee];
  442. }
  443. - (void)initializeLayout {
  444. [self.view addSubview:self.tableView];
  445. [self.view addSubview:self.bottomView];
  446. [self.view addSubview:self.discountView];
  447. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  448. make.left.right.bottom.equalTo(self.view);
  449. make.height.equalTo(@50);
  450. }];
  451. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  452. make.left.right.top.equalTo(self.view);
  453. make.bottom.equalTo(self.bottomView.mas_top);
  454. }];
  455. [self.discountView mas_makeConstraints:^(MASConstraintMaker *make) {
  456. make.left.right.equalTo(self.bottomView);
  457. make.bottom.equalTo(self.bottomView.mas_top);
  458. make.height.mas_equalTo(22);
  459. }];
  460. }
  461. - (void)registerTableViewCells {
  462. [self.tableView registerClass:[PindanBaseCell class] forCellReuseIdentifier:NSStringFromClass([PindanBaseCell class])];
  463. [self.tableView registerClass:[PindanCommonCell class] forCellReuseIdentifier:NSStringFromClass([PindanCommonCell class])];
  464. [self.tableView registerClass:[ProductDetailTableCell class] forCellReuseIdentifier:NSStringFromClass([ProductDetailTableCell class])];
  465. [self.tableView registerClass:[SubmitAddNewCell class] forCellReuseIdentifier:NSStringFromClass([SubmitAddNewCell class])];
  466. [self.tableView registerClass:[SubmitDefaultAddressCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultAddressCell class])];
  467. [self.tableView registerClass:[SubmitDefaultIDCardCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultIDCardCell class])];
  468. [self.tableView registerClass:[SubmitCarriageMoneyCell class] forCellReuseIdentifier:NSStringFromClass([SubmitCarriageMoneyCell class])];
  469. [self.tableView registerClass:[SubmitInputCell class] forCellReuseIdentifier:NSStringFromClass([SubmitInputCell class])];
  470. [self.tableView registerClass:[SubmitDiscountCardCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDiscountCardCell class])];
  471. [self.tableView registerClass:[FKGroupStepCell class] forCellReuseIdentifier:NSStringFromClass([FKGroupStepCell class])];
  472. }
  473. #pragma mark - UIAlertView delegate
  474. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  475. if (alertView.tag >= kDeleteSpecAlertTag) {
  476. if (buttonIndex == 1) {
  477. NSInteger row = alertView.tag - kDeleteSpecAlertTag;
  478. // 数量改变
  479. [self refreshSpecNumber:0 atIndex:row];
  480. [self.tableView reloadData];
  481. }
  482. return;
  483. } else if (buttonIndex == 1 && alertView.tag == kInviteAlertTag) {
  484. // 继续付款
  485. [self requestToCreateOrder];
  486. }
  487. }
  488. #pragma mark - textFieldDelegate
  489. - (void)textFieldDidEndEditing:(UITextField *)textField {
  490. if (textField.tag == kMessageTextFieldTag) {
  491. self.viewModel.messageText = textField.text;
  492. } else if (textField.tag == kInviteTextFiedlTag){
  493. if (textField.text.length == 0) {
  494. self.viewModel.inviteText = nil;
  495. return;
  496. }
  497. self.viewModel.inviteText = textField.text;
  498. [FKSubmitOrderRequest requestToCheckInvite:textField.text
  499. withDelegate:self];
  500. }
  501. }
  502. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  503. [textField resignFirstResponder];
  504. return YES;
  505. }
  506. #pragma mark - geter && setter
  507. - (UITableView *)tableView {
  508. if (_tableView == nil) {
  509. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  510. _tableView.dataSource = self;
  511. _tableView.delegate = self;
  512. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  513. _tableView.sectionFooterHeight = 0;
  514. }
  515. return _tableView;
  516. }
  517. - (SubmitBottomView *)bottomView {
  518. if (_bottomView == nil) {
  519. _bottomView = [[SubmitBottomView alloc]init];
  520. [_bottomView.confirmBtn addTarget:self action:@selector(submitConfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  521. }
  522. return _bottomView;
  523. }
  524. - (FKSubmitDiscountView *)discountView {
  525. if (_discountView == nil) {
  526. _discountView = [[FKSubmitDiscountView alloc]init];
  527. _discountView.hidden = YES;
  528. }
  529. return _discountView;
  530. }
  531. - (SubmitDiscountPickView *)pickerView {
  532. if (_pickerView == nil) {
  533. _pickerView = [[SubmitDiscountPickView alloc] initWithFrame:CGRectZero];
  534. [_pickerView refreshTitleArray:[self.viewModel.discountModel getDiscountStringArray] withSelectedIndex:0];
  535. WeakSelf(weakSelf);
  536. _pickerView.selectDone = ^(NSInteger selectedIndex){
  537. [weakSelf discountSelectDoneWithIndex:selectedIndex];
  538. };
  539. }
  540. return _pickerView;
  541. }
  542. - (SubmitOrderViewModel *)viewModel {
  543. if (_viewModel == nil) {
  544. _viewModel = [[SubmitOrderViewModel alloc]init];
  545. }
  546. return _viewModel;
  547. }
  548. @end