No Description

FKSubmitOrderController.m 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. //
  2. // FKSubmitOrderController.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/1/19.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKSubmitOrderController.h"
  9. #import "FKSubmitOrderViewModel.h"
  10. #import "FKProductSubmitRequest.h"
  11. #import "FKBindIdCardReform.h"
  12. #import "FKProductSubmitReform.h"
  13. #import "FKCashCouponReform.h"
  14. #import "FKProDetailRequest.h"
  15. #import "FKProductDetailReform.h"
  16. #import "FKSubmitOrderBottomView.h"
  17. #import "FKSubmitDiscountView.h"
  18. #import "SubmitDiscountPickView.h"
  19. #import "FKSubmitProductHeaderView.h"
  20. #import "FKDirectBuyRiskView.h"
  21. #import "FKCouponSelectView.h"
  22. #import "FKDiscountInfoView.h"
  23. #import "FKSubmitOrderInfoCell.h"
  24. #import "FKSubmitChannelChoiceCell.h"
  25. #import "FKSubmitChannelCell.h"
  26. #import "SubmitAddNewCell.h"
  27. #import "PindanCommonCell.h"
  28. #import "FKSubmitProductDetailCell.h"
  29. #import "ConnectServiceHeaderCell.h"
  30. #import "SubmitDefaultAddressCell.h"
  31. #import "SubmitDefaultIDCardCell.h"
  32. #import "FKSubmitIdentityCardCell.h"
  33. #import "SubmitInputCell.h"
  34. #import "FKSubmitCountryInfoCell.h"
  35. #import "FKSubmitUnitCountCell.h"
  36. #import "FKSubmitLawCell.h"
  37. #import "FKSubmitDiscountCell.h"
  38. #import "FKSubmitkActivityCell.h"
  39. #import "FKSubmitNationFeeCell.h"
  40. #import "OrderPayController.h"
  41. #import "FKAddressDetailController.h"
  42. #import "FKAddressListController.h"
  43. #import "FKAddIdCardController.h"
  44. #import "FKIdCardManageController.h"
  45. #import "FKActivityCardController.h"
  46. #import "WebViewController.h"
  47. #import "FLControllerHelper.h"
  48. #import "FKTaxShowView.h"
  49. typedef NS_ENUM(NSUInteger, KSubmitReqTag) {
  50. KSubmitReqTagInitial = 0x0,
  51. KSubmitReqTagOrderCount = 1 << 0,
  52. KSubmitReqTagChannel = 1 << 1,
  53. KSubmitReqTagAddress = 1 << 2,
  54. KSubmitReqTagFinish = 0x7
  55. };
  56. const int USER_ADDRESS_REQ_IDENTIFY = 1001;
  57. const int DISCOUNT_REQ_IDENTIFY = 1002;
  58. const int SHIP_CHANNEL_REQ_IDENTIFY = 1003;
  59. const int ORDER_COUNT_REQ_IDENTIFY = 1004;
  60. const int ID_CARD_LIST_REQ_IDENTIFY = 1005;
  61. const int TRADE_NO_REQ_IDENTIFY = 1006;
  62. const int COUPON_LIST_REQ_IDENTIFY = 1007;
  63. const int COUPON_AMOUNT_REQ_IDENTIFY = 1008;
  64. const int VIP_DISCOUNT_ITEM_IDENTIFY = 1009;
  65. static NSString *FK_SUBMIT_ORDER_INFO_CELL_ID = @"FKSUBMIT_ORDER_INFO_CELL_ID";
  66. static NSString *FK_SUBMIT_ORDER_CHANNEL_CELL_ID = @"FKSUBMIT_ORDER_CHANNEL_CELL_ID";
  67. #define kDeleteSpecAlertTag 900
  68. #define kMessageTextFieldTag 901
  69. @interface FKSubmitOrderController ()
  70. <UITableViewDataSource,
  71. UITableViewDelegate,
  72. UITextFieldDelegate,
  73. FLNetworkDelegate,
  74. FKIdCardManageControllerDataSource,
  75. FKIdCardManageControllerDelegate,
  76. FKAddressListControllerDataSource,
  77. FKAddressListControllerDelegate,
  78. FKSubmitChannelCellDelegate,
  79. SubmitProductDetailCellDelegate>
  80. @property (nonatomic, strong) UITableView *tableView;
  81. @property (nonatomic, strong) FKDiscountInfoView *discountInfoView;
  82. @property (nonatomic, strong) FKSubmitOrderBottomView *bottomView;
  83. @property (nonatomic, strong) FKCouponSelectView *couponSelectView;
  84. @property (nonatomic, strong) FKSubmitOrderViewModel *viewModel;
  85. @property (nonatomic, assign) KSubmitReqTag reqTag;
  86. @end
  87. @implementation FKSubmitOrderController
  88. - (instancetype)initWithUnitItemArray:(NSArray *)itemArray
  89. userLevel:(kUserLevel)userLevel
  90. entranSouce:(kSubmitEnterSource)entranSource{
  91. self = [super init];
  92. if (self) {
  93. self.viewModel.userLevel = userLevel;
  94. self.viewModel.unitItemArray = itemArray;
  95. self.viewModel.entranSource = 1;
  96. if (entranSource == kSubmitEnterSourceDetail) self.viewModel.entranSource = 2;
  97. // [self.viewModel setDefaultChannelForUserLevel:userLevel];
  98. }
  99. return self;
  100. }
  101. - (void)viewDidLoad{
  102. [super viewDidLoad];
  103. self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
  104. [self.view addSubview:self.tableView];
  105. [self.view addSubview:self.discountInfoView];
  106. [self.view addSubview:self.bottomView];
  107. [self setupViews];
  108. [self configNavItems];
  109. [self requestDiscountItem];
  110. }
  111. - (void)viewWillAppear:(BOOL)animated{
  112. [super viewWillAppear:animated];
  113. self.navigationItem.title = @"提交订单";
  114. [self.navigationController setNavigationBarHidden:NO animated:YES];
  115. // 从地址选择页面回来就不需要请求
  116. if (![self.viewModel hasAddressProvince]){
  117. [self requestForInitalData];
  118. }else{
  119. [self.tableView reloadData];
  120. }
  121. }
  122. - (void)viewDidAppear:(BOOL)animated{
  123. [super viewDidAppear:animated];
  124. if (![self.viewModel isHasShowRiskAlert]){
  125. [self.viewModel setHasShowRiskAlert];
  126. [self clickRightNavItem];
  127. };
  128. }
  129. - (void)viewWillDisappear:(BOOL)animated {
  130. [super viewWillDisappear:animated];
  131. [self.view endEditing:YES];
  132. if ([self.couponSelectView isShowing]) {
  133. [self.couponSelectView dismissAnimated];
  134. }
  135. }
  136. - (void)setupViews {
  137. if (IS_IPHONE_X) {
  138. [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
  139. make.left.right.equalTo(self.view);
  140. make.height.equalTo(@50);
  141. make.bottom.equalTo(self.view).offset(-34);
  142. }];
  143. } else {
  144. [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
  145. make.left.right.bottom.equalTo(self.view);
  146. make.height.equalTo(@50);
  147. }];
  148. }
  149. self.discountInfoView.hidden = YES;
  150. if ([self.viewModel isVipDiscountValid]) {
  151. self.discountInfoView.hidden = NO;
  152. [self.discountInfoView mas_remakeConstraints:^(MASConstraintMaker *make) {
  153. make.left.right.equalTo(self.bottomView);
  154. make.bottom.equalTo(self.bottomView.mas_top);
  155. make.height.equalTo(@48);
  156. }];
  157. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  158. make.left.right.top.equalTo(self.view);
  159. make.bottom.equalTo(self.discountInfoView.mas_top);
  160. }];
  161. } else {
  162. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  163. make.left.right.top.equalTo(self.view);
  164. make.bottom.equalTo(self.bottomView.mas_top);
  165. }];
  166. }
  167. }
  168. #pragma mark - Request
  169. - (void)requestForInitalData {
  170. self.reqTag = KSubmitReqTagInitial;
  171. [self.hudView show:YES];
  172. [self requestOrderCount];
  173. [self requestCouponList];
  174. [FKProductSubmitRequest reqShipChannelWithChannelIDArray:[self.viewModel shipChannelIdArray]
  175. identify:SHIP_CHANNEL_REQ_IDENTIFY
  176. delegate:self];
  177. [FKProductSubmitRequest requestUserAddressWithIdentify:USER_ADDRESS_REQ_IDENTIFY delegate:self];
  178. [FKProductSubmitRequest requestDiscountDataWithIdentify:DISCOUNT_REQ_IDENTIFY
  179. delegate:self];
  180. [FKProductSubmitRequest requestIdCardListIdentify:ID_CARD_LIST_REQ_IDENTIFY delegate:self];
  181. }
  182. - (void)requestOrderCount {
  183. [FKProductSubmitRequest reqOrderCountWithUnitItemArray:self.viewModel.unitItemArray
  184. identify:ORDER_COUNT_REQ_IDENTIFY
  185. delegate:self];
  186. }
  187. - (void)requestToCreateOrder {
  188. NSString *paymentOrderJson = [self.viewModel getPaymentOrderJson];
  189. NSString *supplyJson = [self.viewModel getSupplyJson];
  190. NSString *goodsJson = [self.viewModel getGoodsJsonString];
  191. if (!paymentOrderJson.length) return;
  192. if (!supplyJson.length) return;
  193. if (!goodsJson.length) return;
  194. [self.hudView show:YES];
  195. [FKProductSubmitRequest requestTradeNoWithPaymentJson:paymentOrderJson
  196. supplyJson:supplyJson
  197. goodsJson:goodsJson
  198. identify:TRADE_NO_REQ_IDENTIFY
  199. delegate:self];
  200. }
  201. - (void)requestCouponAmont{
  202. if ([FLStringHelper isValidString:self.viewModel.couponItem.itemID]){
  203. [FKProductSubmitRequest requestCouponAmountWith:COUPON_AMOUNT_REQ_IDENTIFY
  204. couponID:self.viewModel.couponItem.itemID
  205. itemArray:self.viewModel.unitItemArray
  206. delegate:self];
  207. }
  208. }
  209. - (void)requestDiscountItem {
  210. [FKProDetailRequest reqVipDiscountWithIdentify:VIP_DISCOUNT_ITEM_IDENTIFY delegate:self];
  211. }
  212. - (void)requestCouponList {
  213. [FKProductSubmitRequest requestCouponListWithUnitItemArray:self.viewModel.unitItemArray
  214. identify:COUPON_LIST_REQ_IDENTIFY delegate:self];
  215. }
  216. #pragma mark - response
  217. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  218. if (identify == USER_ADDRESS_REQ_IDENTIFY){
  219. self.reqTag = self.reqTag ^ KSubmitReqTagAddress;
  220. }else if (identify == SHIP_CHANNEL_REQ_IDENTIFY){
  221. self.reqTag = self.reqTag ^ KSubmitReqTagChannel;
  222. }else if (identify == ORDER_COUNT_REQ_IDENTIFY){
  223. self.reqTag = self.reqTag ^ KSubmitReqTagOrderCount;
  224. }
  225. if (self.reqTag == KSubmitReqTagFinish){
  226. [self.hudView hide:NO];
  227. }
  228. [FLProgressHUDHelper showText:header.msg inView:self.view];
  229. }
  230. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
  231. if (identify == USER_ADDRESS_REQ_IDENTIFY){
  232. self.reqTag = self.reqTag ^ KSubmitReqTagAddress;
  233. } else if (identify == SHIP_CHANNEL_REQ_IDENTIFY){
  234. self.reqTag = self.reqTag ^ KSubmitReqTagChannel;
  235. } else if (identify == ORDER_COUNT_REQ_IDENTIFY){
  236. self.reqTag = self.reqTag ^ KSubmitReqTagOrderCount;
  237. }
  238. if (self.reqTag == KSubmitReqTagFinish){
  239. [self.hudView hide:NO];
  240. }
  241. if (header.code.intValue == RESPONSE_MSG_NORMAL){
  242. if (identify == ID_CARD_LIST_REQ_IDENTIFY) {
  243. NSArray *idCardArray = [FKBindIdCardReform parserIdCardListWithData:response];
  244. self.viewModel.selectedIdCardItem = [FKSubmitOrderViewModel validIdCardItemFromArray:idCardArray];
  245. if (self.viewModel.isNeedIdCard){
  246. [self.tableView reloadData];
  247. }
  248. } else if (identify == USER_ADDRESS_REQ_IDENTIFY) {
  249. self.viewModel.selectedAddress = [FKProductSubmitReform parserAddresModelWithDict:response];
  250. [self.tableView reloadData];
  251. [self refreshBottomView];
  252. } else if (identify == DISCOUNT_REQ_IDENTIFY) {
  253. self.viewModel.discountModel.disCountArray = [FKProductSubmitReform parserDiscountArrayWithDict:response];
  254. [self.viewModel.discountModel ruledDiscount];
  255. [self.viewModel allocateDiscount];
  256. [self.tableView reloadData];
  257. [self refreshBottomView];
  258. } else if (identify == SHIP_CHANNEL_REQ_IDENTIFY) {
  259. NSArray *tranformItemArray = [FKProductSubmitReform parserChannelArrayWithData:response];
  260. [self.viewModel filterWithTransformItemArray:tranformItemArray];
  261. [self.tableView reloadData];
  262. [self.viewModel hasShowChannel];
  263. } else if (identify == ORDER_COUNT_REQ_IDENTIFY) {
  264. NSArray *proFeeArray = [FKProductSubmitReform parserProFeeArrayWithDict:response];
  265. [self.viewModel filterWithProFeeItemArray:proFeeArray];
  266. [self.viewModel setDefaultChannel];
  267. self.viewModel.isNeedIdCard = [FKProductSubmitReform parserIsNeedIdCardWithDict:response];
  268. self.viewModel.needIdCardType = [FKProductSubmitReform parserNeedIdCardTypeWithDict:response];
  269. self.viewModel.serveTime = [FKProductSubmitReform parseServeTime:response];
  270. [self.viewModel allocateDiscount];
  271. [self.tableView reloadData];
  272. [self refreshBottomView];
  273. } else if (identify == TRADE_NO_REQ_IDENTIFY) {
  274. self.viewModel.paymentModel = [FKProductSubmitReform parserPaymentItemWithDict:response];
  275. if (!self.viewModel.paymentModel) {
  276. [FLProgressHUDHelper showText:header.msg inView:self.view];
  277. return;
  278. }
  279. [self pushOrderPayController:self.viewModel.paymentModel];
  280. } else if (identify == COUPON_LIST_REQ_IDENTIFY) {
  281. self.viewModel.couponArray = [FKCashCouponReform parseCouponItems:response];
  282. self.viewModel.couponItem = [self.viewModel firstValidCounponItem];
  283. self.viewModel.couponAmount = nil;
  284. [self requestCouponAmont];
  285. [self.tableView reloadData];
  286. } else if (identify == COUPON_AMOUNT_REQ_IDENTIFY) {
  287. self.viewModel.couponAmount = [FKProductSubmitReform parseCouponAmount:response];
  288. self.viewModel.deratedSupplierArray = [FKProductSubmitReform parseDeratedSupplierArray:response];
  289. [self.tableView reloadData];
  290. [self refreshBottomView];
  291. } else if (identify == VIP_DISCOUNT_ITEM_IDENTIFY) {
  292. self.viewModel.discountItem = [FKProductDetailReform parserVipDiscountItem:response];
  293. self.discountInfoView.countLabel.text = [NSString stringWithFormat:@"%@次", [self.viewModel.discountItem quantity] ? : @"0"];
  294. [self.tableView reloadData];
  295. [self setupViews];
  296. }
  297. } else {
  298. [FLProgressHUDHelper showText:header.msg inView:self.view];
  299. }
  300. }
  301. #pragma mark - tableView dataSource
  302. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  303. return [self.viewModel numberOfSectionsInTableView];
  304. }
  305. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  306. return [self.viewModel numberOfRowsInSection:section];
  307. }
  308. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  309. NSString *reuseStr = [self.viewModel cellReuseIdentifyWithIndexPath:indexPath];
  310. kSubmitProCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
  311. WeakSelf(weakSelf);
  312. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseStr];
  313. if (!cell) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
  314. switch (cellType) {
  315. case kSubmitProCellTypeDiscount:{
  316. FKSubmitDiscountCell *discountCell = (FKSubmitDiscountCell *)cell;
  317. [discountCell.actionButton addTarget:self
  318. action:@selector(disCountButtonClick:)
  319. forControlEvents:UIControlEventTouchUpInside];
  320. break;
  321. }
  322. case kSubmitProCellTypeMessage:{
  323. SubmitInputCell *messageCell = (SubmitInputCell *)cell;
  324. messageCell.inputField.delegate = self;
  325. messageCell.inputField.tag = kMessageTextFieldTag;
  326. break;
  327. }
  328. case kSubmitProCellTypeChannelChoice: {
  329. FKSubmitChannelChoiceCell *choiceCell = (FKSubmitChannelChoiceCell *)cell;
  330. [choiceCell.dropListBtn addTarget:self action:@selector(clickChannelArrow:) forControlEvents:UIControlEventTouchUpInside];
  331. [choiceCell.channelExplainBtn addTarget:self action:@selector(clickChannelExplainButton:) forControlEvents:UIControlEventTouchUpInside];
  332. break;
  333. }
  334. case kSubmitProCellTypeChannelList:{
  335. FKSubmitChannelCell *channelCell = (FKSubmitChannelCell *)cell;
  336. channelCell.delegate = self;
  337. break;
  338. }
  339. case kSubmitProCellTypeDutyFee: {
  340. FKSubmitOrderInfoCell *infoCell = (FKSubmitOrderInfoCell *)cell;
  341. [infoCell.infoBtn addTarget:self action:@selector(clickFeeInfoBtn:) forControlEvents:UIControlEventTouchUpInside];
  342. break;
  343. }
  344. case kSubmitProCellTypeServeFee: {
  345. FKSubmitOrderInfoCell *serveCell = (FKSubmitOrderInfoCell *)cell;
  346. [serveCell.infoBtn addTarget:self action:@selector(clickServeFeeInfoBtn:) forControlEvents:UIControlEventTouchUpInside];
  347. break;
  348. }
  349. case kSubmitProCellTypeLaw:{
  350. FKSubmitLawCell *lawCell = (FKSubmitLawCell *)cell;
  351. [lawCell.checkBox addTarget:self action:@selector(clickLawBox:) forControlEvents:UIControlEventTouchUpInside];
  352. break;
  353. }
  354. case kSubmitProCellTypeActivity: {
  355. FKSubmitkActivityCell *activityCell = (FKSubmitkActivityCell *)cell;
  356. [activityCell setSelectedCoupon:self.viewModel.couponItem
  357. amount:self.viewModel.couponAmount
  358. count:[self.viewModel validCouponCount]];
  359. break;
  360. }
  361. case kSubmitProCellTypeVipDiscount: {
  362. FKSubmitkActivityCell *activityCell = (FKSubmitkActivityCell *)cell;
  363. [activityCell setVipDiscountInfoWithViewModel:self.viewModel];
  364. activityCell.didUseVipDiscount = ^(BOOL isUseVipDiscount) {
  365. weakSelf.viewModel.discountItem.isUseVipDiscount = isUseVipDiscount;
  366. [weakSelf.tableView reloadData];
  367. [weakSelf refreshBottomView];
  368. };
  369. break;
  370. }
  371. case kSubmitProCellTypeUnitCount:{
  372. FKSubmitUnitCountCell *unitCell = (FKSubmitUnitCountCell *)cell;
  373. [unitCell.latePayButton addTarget:self
  374. action:@selector(clickLatePayBtn)
  375. forControlEvents:UIControlEventTouchUpInside];
  376. }
  377. break;
  378. case kSubmitProCellTypeOfficalCarriage:{
  379. PindanCommonCell *officalCell = (PindanCommonCell *)cell;
  380. [officalCell.infoBtn addTarget:self
  381. action:@selector(clickOfficalCarriageInfo)
  382. forControlEvents:UIControlEventTouchUpInside];
  383. break;
  384. }
  385. case kSubmitProCellTypeProductDetail:{
  386. FKSubmitProductDetailCell *productCell = (FKSubmitProductDetailCell *)cell;
  387. productCell.delegate = self;
  388. [productCell.productTagBtn addTarget:self
  389. action:@selector(clickThirdSellBtn:)
  390. forControlEvents:UIControlEventTouchUpInside];
  391. break;
  392. }
  393. default:
  394. break;
  395. }
  396. [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  397. return cell;
  398. }
  399. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  400. return [self.viewModel cellHeightForIndexPath:indexPath];
  401. }
  402. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  403. return 10.0f;
  404. }
  405. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  406. return CGFLOAT_MIN;
  407. }
  408. #pragma mark - tableView delegate
  409. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  410. kSubmitProCellType type = [self.viewModel cellTypeForIndexPath:indexPath];
  411. WeakSelf(weakSelf);
  412. switch (type) {
  413. case kSubmitProCellTypeAddAddress: {
  414. UIViewController *controller = [[FKAddressDetailController alloc] initWithAddress:nil type:FKAddressDetailControllerTypeAdd];
  415. controller.hidesBottomBarWhenPushed = YES;
  416. [self.navigationController pushViewController:controller animated:YES];
  417. break;
  418. }
  419. case kSubmitProCellTypeAddress: {
  420. FKAddressListController *controller = [[FKAddressListController alloc] initWithType:FKAddressListControllerTypeChoice];
  421. controller.dataSource = self;
  422. controller.delegate = self;
  423. controller.hidesBottomBarWhenPushed = YES;
  424. [self.navigationController pushViewController:controller animated:YES];
  425. break;
  426. }
  427. case kSubmitProCellTypeAddIDCard: {
  428. FKAddIdCardController *controller = [FKAddIdCardController new];
  429. controller.hidesBottomBarWhenPushed = YES;
  430. controller.finishToBack = ^{
  431. [FKProductSubmitRequest requestIdCardListIdentify:ID_CARD_LIST_REQ_IDENTIFY delegate:weakSelf];
  432. };
  433. [self.navigationController pushViewController:controller animated:YES];
  434. break;
  435. }
  436. case kSubmitProCellTypeIDCard: {
  437. FKIdCardManageController *controller = [FKIdCardManageController new];
  438. controller.dataSource = self;
  439. controller.delegate = self;
  440. controller.hidesBottomBarWhenPushed = YES;
  441. [self.navigationController pushViewController:controller animated:YES];
  442. break;
  443. }
  444. case kSubmitProCellTypeActivity: {
  445. FKActivityCardController *controller = [[FKActivityCardController alloc] initWithData:self.viewModel.couponArray serverTime:self.viewModel.serveTime];
  446. controller.hidesBottomBarWhenPushed = YES;
  447. controller.isDisplayRightNaviItem = YES;
  448. controller.didSelectCallback = ^(FKCouponItem *item) {
  449. weakSelf.viewModel.couponItem = item;
  450. [weakSelf.navigationController popViewControllerAnimated:YES];
  451. if (item) {
  452. [weakSelf requestCouponAmont];
  453. } else {
  454. weakSelf.viewModel.couponAmount = nil;
  455. [weakSelf.tableView reloadData];
  456. [weakSelf refreshBottomView];
  457. }
  458. };
  459. [self.navigationController pushViewController:controller animated:YES];
  460. break;
  461. }
  462. default:
  463. break;
  464. }
  465. }
  466. #pragma mark - FKAddressListController DataSource & Delegate
  467. - (NSString *)currentSelectedAddressID {
  468. return self.viewModel.selectedAddress.addressID;
  469. }
  470. - (void)addressListController:(FKAddressListController *)controller didSelectAddress:(ShipAddress *)address {
  471. if (address){
  472. self.viewModel.selectedAddress = address;
  473. [self.tableView reloadData];
  474. [self.navigationController popToViewController:self animated:YES];
  475. }
  476. }
  477. - (void)addressListController:(FKAddressListController *)controller didUpdateAddress:(ShipAddress *)address {
  478. self.viewModel.selectedAddress = address;
  479. [self.tableView reloadData];
  480. }
  481. #pragma mark - FKIdCardManageController DataSource & Delegate
  482. - (NSString *)currentSelectedIDCard {
  483. return self.viewModel.selectedIdCardItem.itemID;
  484. }
  485. - (void)idCardManageController:(FKIdCardManageController *)controller didSelectItem:(FKIdCardItem *)item {
  486. if (item) {
  487. self.viewModel.selectedIdCardItem = item;
  488. [self.navigationController popToViewController:self animated:YES];
  489. }
  490. }
  491. - (void)idCardManageController:(FKIdCardManageController *)controller didRemoveItem:(FKIdCardItem *)item {
  492. self.viewModel.selectedIdCardItem = nil;
  493. }
  494. - (void)idCardManageController:(FKIdCardManageController *)controller didUpdateItem:(FKIdCardItem *)item {
  495. self.viewModel.selectedIdCardItem = item;
  496. }
  497. #pragma mark - textFieldDelegate
  498. - (void)textFieldDidEndEditing:(UITextField *)textField {
  499. if (textField.tag == kMessageTextFieldTag) {
  500. self.viewModel.messageText = textField.text;
  501. }
  502. }
  503. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  504. [textField resignFirstResponder];
  505. return YES;
  506. }
  507. #pragma mark - channelCell delegate
  508. - (void)channelCell:(FKSubmitChannelCell *)cell changeToChannel:(kSubmitChannelType)type{
  509. if (kSubmitChannelTypeNone == type || kSubmitChannelTypeAirNormal == type) return;
  510. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  511. if (indexPath){
  512. FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:indexPath.section - 1];
  513. unitItem.selectedChannelType = type;
  514. [self.tableView reloadData];
  515. [self requestOrderCount];
  516. [self requestCouponList];
  517. }
  518. }
  519. #pragma mark - SubmitProductDetailCellDelegate
  520. - (void)productCell:(FKSubmitProductDetailCell *)cell didChangeQuantity:(NSInteger)quantity atIndexPath:(NSIndexPath *)indexPath {
  521. if (quantity > 0) {
  522. FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:indexPath.section - 1];
  523. FKSubmitProductItem *productItem = [unitItem getProductItemAtIndex:indexPath.row - 1];
  524. productItem.quality = quantity;
  525. [self requestForInitalData];
  526. [FKProductSubmitRequest requestCouponListWithUnitItemArray:self.viewModel.unitItemArray
  527. identify:COUPON_LIST_REQ_IDENTIFY delegate:self];
  528. } else {
  529. [FLProgressHUDHelper showText:@"商品数量必须大于0" inView:self.view];
  530. }
  531. }
  532. #pragma mark - method
  533. - (void)configNavItems{
  534. [self configLeftNaviItem];
  535. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"submit_info"]
  536. style:UIBarButtonItemStylePlain
  537. target:self
  538. action:@selector(clickRightNavItem)];
  539. rightItem.width = 80;
  540. rightItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, - 9);
  541. self.navigationItem.rightBarButtonItem = rightItem;
  542. }
  543. - (void)couponSelectDoneWithID:(NSString *)couponID{
  544. FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:self.couponSelectView.tag];
  545. if (unitItem){
  546. if (!couponID) {
  547. unitItem.selectedDiscount = nil;
  548. } else {
  549. unitItem.selectedDiscount = [self.viewModel.discountModel couponItemWithID:couponID];
  550. [self.viewModel.discountModel removeCashItemWithID:couponID];
  551. }
  552. [self.viewModel.discountModel ruledDiscount];
  553. [self.tableView reloadData];
  554. [self refreshBottomView];
  555. }
  556. }
  557. - (void)refreshBottomView {
  558. // 邮费券或活动卡优惠
  559. CGFloat totalFee = [self.viewModel getTotalFee];
  560. CGFloat payFee = [self.viewModel getPayTotalFee];
  561. NSUInteger allCount = [self.viewModel getTotalQuality];
  562. [self.bottomView refreshPriceWithAmount:allCount
  563. totalFee:MAX(0, payFee)
  564. discountFee:MAX(0, totalFee - payFee)];
  565. }
  566. #pragma mark - action
  567. - (void)clickLeftNaviItem{
  568. [BehaviorTrackManger requestBehaviorType:kBehaviorCancelSubmitOrder jsonString:nil];
  569. [self.navigationController popViewControllerAnimated:YES];
  570. }
  571. - (void)clickOfficalCarriageInfo{
  572. // 官网运费说明
  573. NSString *url = [NSString stringWithFormat:@"%@/support/shipment-rule.html?supplier_id=11", [[FKServerUtil sharedInstance] webServer]];
  574. [self pushWebViewController:url segmentStr:nil];
  575. }
  576. - (void)clickLatePayBtn{
  577. // 跳转到超时赔付H5
  578. NSString *url = [NSString stringWithFormat:@"%@/support/timeout-pay.html", [[FKServerUtil sharedInstance] webServer]];
  579. [self pushWebViewController:url segmentStr:nil];
  580. }
  581. - (void)clickLawBox:(UIButton *)sender{
  582. sender.selected = !sender.selected;
  583. self.bottomView.enabled = sender.selected;
  584. // self.agreeProtocol = sender.selected;
  585. }
  586. - (void)clickSeeProtocolBtn{
  587. NSString *url = [NSString stringWithFormat:@"%@/support/special-clause.html", [[FKServerUtil sharedInstance] webServer]];
  588. [self pushWebViewController:url segmentStr:nil];
  589. }
  590. - (void)clickRightNavItem{
  591. [self.view endEditing:YES];
  592. FKDirectBuyRiskView *riskView = [[FKDirectBuyRiskView alloc]init];
  593. [riskView showInView:self.navigationController.view];
  594. }
  595. - (IBAction)clickFeeInfoBtn:(UIButton *)sender{
  596. // 弹框
  597. FKTaxShowView *taxView = [[FKTaxShowView alloc] init];
  598. [taxView showInView:self.view];
  599. taxView.showDetailBlock = ^{
  600. [self pushFeeInfoDetail];
  601. };
  602. }
  603. - (IBAction)clickServeFeeInfoBtn:(UIButton *)sender {
  604. FKTaxShowView *taxView = [[FKTaxShowView alloc] init];
  605. taxView.titleLabel.text = @"保险费说明";
  606. taxView.secondTitleLabel.text = @"保险费";
  607. taxView.contentLabel.text = @"根据转运公司规定,当您走该转运渠道的订单超过1000元时,将收取商品总价1.5%的保险费用,来预防包裹的丢失和破损。";
  608. taxView.moreView.hidden = YES;
  609. taxView.moreLabel.hidden = YES;
  610. taxView.moreControl.userInteractionEnabled = NO;
  611. [taxView showInView:self.view];
  612. }
  613. - (void)pushFeeInfoDetail{
  614. NSString *url = [NSString stringWithFormat:@"%@/support/about-clearance.html", [[FKServerUtil sharedInstance] webServer]];
  615. [self pushWebViewController:url segmentStr:@"#tariff"];
  616. }
  617. - (void)disCountButtonClick:(UIButton *)sender {
  618. [self.view endEditing:YES];
  619. self.couponSelectView.tag = sender.tag;
  620. FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:sender.tag];
  621. // 无国际运费不适用代金券
  622. if ([unitItem needShowInternationPostage] && [unitItem getTotalInternationalPostage] > 0){
  623. CashCouponItem *oldCash = unitItem.selectedDiscount;
  624. [self.viewModel.discountModel receiveCashItemAtFirst:oldCash];
  625. NSArray *validCouponArray = [self.viewModel.discountModel getValidCashItemForUnitItem:unitItem];
  626. if (validCouponArray.count) {
  627. [self.couponSelectView refreshCouponArray:[self.viewModel.discountModel getValidCashItemForUnitItem:unitItem] selectFirst:(oldCash ? YES : NO)];
  628. [self.couponSelectView showInView:self.navigationController.view animated:YES];
  629. } else {
  630. [FLProgressHUDHelper showText:@"无可用代金券" inView:self.view];
  631. }
  632. }
  633. }
  634. - (void)clickSubmitConfirmBtn {
  635. // 判断收件地址是否为空
  636. if (![self.viewModel hasAddress]){
  637. [FLProgressHUDHelper showTipAlert:@"请填写收货地址"];
  638. return;
  639. }
  640. if ([self.viewModel.needIdCardType isEqualToString:@"3"] ) {
  641. if (self.viewModel.selectedIdCardItem == nil) {
  642. [FLProgressHUDHelper showTipAlert:@"因海关清关需要,请添加收货人身份证信息"];
  643. return;
  644. }
  645. } else {
  646. if (![self.viewModel isIDCardValid]) {
  647. [FLProgressHUDHelper showTipAlert:@"因海关清关需要,请填写并保存收货人身份证号"];
  648. return;
  649. }
  650. }
  651. [self requestToCreateOrder];
  652. [[NSNotificationCenter defaultCenter] postNotificationName:BASKET_NEED_TO_REFRESH object:nil];
  653. }
  654. - (void)clickThirdSellBtn:(UIButton *)sender{
  655. NSString *url = [NSString stringWithFormat:@"%@/support/about-goods.html", [[FKServerUtil sharedInstance] webServer]];
  656. [self pushWebViewController:url segmentStr:@"#third-party"];
  657. }
  658. - (void)clickChannelArrow:(UIButton *)sender{
  659. self.viewModel.openChannel = !self.viewModel.openChannel;
  660. [self.tableView reloadData];
  661. }
  662. - (IBAction)clickChannelExplainButton:(id)sender {
  663. NSString *url = [NSString stringWithFormat:@"%@/support/trans-channel-desc.html", [[FKServerUtil sharedInstance] webServer]];
  664. [self pushWebViewController:url segmentStr:nil];
  665. }
  666. #pragma mark - push controller
  667. - (void)pushOrderPayController:(SubmitPaymentItem *)paymentItem {
  668. // if (self.viewModel.isNeedIdCard && self.viewModel.selectedIdCardItem.idCardNum.length == 0){
  669. // paymentItem.successController = FKOrderPaymentSuccessControllerBindIDCard;
  670. // } else {
  671. paymentItem.successController = FKOrderPaymentSuccessControllerRedpacket;
  672. // }
  673. OrderPayController *payController = [[OrderPayController alloc] initWithPaymentItem:paymentItem];
  674. payController.hidesBottomBarWhenPushed = YES;
  675. NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
  676. [viewControllers removeLastObject];
  677. [viewControllers addObject:payController];
  678. [self.navigationController setViewControllers:viewControllers animated:YES];
  679. }
  680. - (void)pushWebViewController:(NSString *)urlString segmentStr:(NSString *)segmentStr{
  681. WebViewController *newViewController = [[FLControllerHelper currentStoryBoard] instantiateViewControllerWithIdentifier:@"WebViewController"];
  682. newViewController.url = urlString;
  683. newViewController.urlSegment = segmentStr;
  684. newViewController.hidesBottomBarWhenPushed = YES;
  685. [self.navigationController pushViewController:newViewController animated:YES];
  686. }
  687. #pragma mark - property
  688. - (FKSubmitOrderViewModel *)viewModel{
  689. if (_viewModel == nil) {
  690. _viewModel = [[FKSubmitOrderViewModel alloc]init];
  691. }
  692. return _viewModel;
  693. }
  694. - (UITableView *)tableView {
  695. if (_tableView == nil) {
  696. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  697. _tableView.dataSource = self;
  698. _tableView.delegate = self;
  699. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  700. _tableView.sectionFooterHeight = 0;
  701. _tableView.contentInset = UIEdgeInsetsMake(0, 0, 10, 0);
  702. _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  703. if (@available(iOS 11.0, *)) {
  704. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  705. }
  706. [_tableView registerClass:[PindanBaseCell class] forCellReuseIdentifier:NSStringFromClass([PindanBaseCell class])];
  707. [_tableView registerClass:[PindanCommonCell class] forCellReuseIdentifier:NSStringFromClass([PindanCommonCell class])];
  708. [_tableView registerClass:[FKSubmitProductDetailCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitProductDetailCell class])];
  709. [_tableView registerClass:[SubmitAddNewCell class] forCellReuseIdentifier:NSStringFromClass([SubmitAddNewCell class])];
  710. [_tableView registerClass:[SubmitDefaultAddressCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultAddressCell class])];
  711. [_tableView registerClass:[SubmitDefaultIDCardCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultIDCardCell class])];
  712. [_tableView registerClass:[FKSubmitIdentityCardCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitIdentityCardCell class])];
  713. [_tableView registerClass:[SubmitInputCell class] forCellReuseIdentifier:NSStringFromClass([SubmitInputCell class])];
  714. [_tableView registerClass:[FKSubmitDiscountCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitDiscountCell class])];
  715. [_tableView registerClass:[FKSubmitOrderInfoCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitOrderInfoCell class])];
  716. [_tableView registerClass:[FKSubmitChannelChoiceCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitChannelChoiceCell class])];
  717. [_tableView registerClass:[FKSubmitChannelCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitChannelCell class])];
  718. [_tableView registerClass:[FKSubmitCountryInfoCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitCountryInfoCell class])];
  719. [_tableView registerClass:[FKSubmitUnitCountCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitUnitCountCell class])];
  720. [_tableView registerClass:[FKSubmitLawCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitLawCell class])];
  721. [_tableView registerClass:[FKSubmitkActivityCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitkActivityCell class])];
  722. [_tableView registerClass:[FKSubmitNationFeeCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitNationFeeCell class])];
  723. }
  724. return _tableView;
  725. }
  726. - (FKDiscountInfoView *)discountInfoView {
  727. if (!_discountInfoView) {
  728. _discountInfoView = [FKDiscountInfoView new];
  729. _discountInfoView.backgroundColor = [UIColor whiteColor];
  730. }
  731. return _discountInfoView;
  732. }
  733. - (FKSubmitOrderBottomView *)bottomView {
  734. if (_bottomView == nil) {
  735. _bottomView = [[FKSubmitOrderBottomView alloc]init];
  736. [_bottomView.confirmBtn addTarget:self action:@selector(clickSubmitConfirmBtn) forControlEvents:UIControlEventTouchUpInside];
  737. }
  738. return _bottomView;
  739. }
  740. - (FKCouponSelectView *)couponSelectView{
  741. if (_couponSelectView == nil) {
  742. _couponSelectView = [[FKCouponSelectView alloc]initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, UISCREENHEIGH)];
  743. WeakSelf(weakSelf);
  744. _couponSelectView.finish = ^(NSString* couponID) {
  745. [weakSelf couponSelectDoneWithID:couponID];
  746. };
  747. }
  748. return _couponSelectView;
  749. }
  750. @end