123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903 |
- //
- // FKSubmitOrderController.m
- // FirstLink
- //
- // Created by jack on 16/1/19.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKSubmitOrderController.h"
- #import "FKSubmitOrderViewModel.h"
- #import "FKProductSubmitRequest.h"
- #import "FKBindIdCardReform.h"
- #import "FKProductSubmitReform.h"
- #import "FKCashCouponReform.h"
- #import "FKProDetailRequest.h"
- #import "FKProductDetailReform.h"
- #import "FKSubmitOrderBottomView.h"
- #import "FKSubmitDiscountView.h"
- #import "SubmitDiscountPickView.h"
- #import "FKSubmitProductHeaderView.h"
- #import "FKDirectBuyRiskView.h"
- #import "FKCouponSelectView.h"
- #import "FKDiscountInfoView.h"
- #import "FKSubmitOrderInfoCell.h"
- #import "FKSubmitChannelChoiceCell.h"
- #import "FKSubmitChannelCell.h"
- #import "SubmitAddNewCell.h"
- #import "PindanCommonCell.h"
- #import "FKSubmitProductDetailCell.h"
- #import "ConnectServiceHeaderCell.h"
- #import "SubmitDefaultAddressCell.h"
- #import "SubmitDefaultIDCardCell.h"
- #import "FKSubmitIdentityCardCell.h"
- #import "SubmitInputCell.h"
- #import "FKSubmitCountryInfoCell.h"
- #import "FKSubmitUnitCountCell.h"
- #import "FKSubmitLawCell.h"
- #import "FKSubmitDiscountCell.h"
- #import "FKSubmitkActivityCell.h"
- #import "FKSubmitNationFeeCell.h"
- #import "OrderPayController.h"
- #import "FKAddressDetailController.h"
- #import "FKAddressListController.h"
- #import "FKAddIdCardController.h"
- #import "FKIdCardManageController.h"
- #import "FKActivityCardController.h"
- #import "WebViewController.h"
- #import "FLControllerHelper.h"
- #import "FKTaxShowView.h"
- typedef NS_ENUM(NSUInteger, KSubmitReqTag) {
- KSubmitReqTagInitial = 0x0,
- KSubmitReqTagOrderCount = 1 << 0,
- KSubmitReqTagChannel = 1 << 1,
- KSubmitReqTagAddress = 1 << 2,
- KSubmitReqTagFinish = 0x7
- };
- const int USER_ADDRESS_REQ_IDENTIFY = 1001;
- const int DISCOUNT_REQ_IDENTIFY = 1002;
- const int SHIP_CHANNEL_REQ_IDENTIFY = 1003;
- const int ORDER_COUNT_REQ_IDENTIFY = 1004;
- const int ID_CARD_LIST_REQ_IDENTIFY = 1005;
- const int TRADE_NO_REQ_IDENTIFY = 1006;
- const int COUPON_LIST_REQ_IDENTIFY = 1007;
- const int COUPON_AMOUNT_REQ_IDENTIFY = 1008;
- const int VIP_DISCOUNT_ITEM_IDENTIFY = 1009;
- static NSString *FK_SUBMIT_ORDER_INFO_CELL_ID = @"FKSUBMIT_ORDER_INFO_CELL_ID";
- static NSString *FK_SUBMIT_ORDER_CHANNEL_CELL_ID = @"FKSUBMIT_ORDER_CHANNEL_CELL_ID";
- #define kDeleteSpecAlertTag 900
- #define kMessageTextFieldTag 901
- @interface FKSubmitOrderController ()
- <UITableViewDataSource,
- UITableViewDelegate,
- UITextFieldDelegate,
- FLNetworkDelegate,
- FKIdCardManageControllerDataSource,
- FKIdCardManageControllerDelegate,
- FKAddressListControllerDataSource,
- FKAddressListControllerDelegate,
- FKSubmitChannelCellDelegate,
- SubmitProductDetailCellDelegate>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) FKDiscountInfoView *discountInfoView;
- @property (nonatomic, strong) FKSubmitOrderBottomView *bottomView;
- @property (nonatomic, strong) FKCouponSelectView *couponSelectView;
- @property (nonatomic, strong) FKSubmitOrderViewModel *viewModel;
- @property (nonatomic, assign) KSubmitReqTag reqTag;
- @end
- @implementation FKSubmitOrderController
- - (instancetype)initWithUnitItemArray:(NSArray *)itemArray
- userLevel:(kUserLevel)userLevel
- entranSouce:(kSubmitEnterSource)entranSource{
- self = [super init];
- if (self) {
- self.viewModel.userLevel = userLevel;
- self.viewModel.unitItemArray = itemArray;
- self.viewModel.entranSource = 1;
- if (entranSource == kSubmitEnterSourceDetail) self.viewModel.entranSource = 2;
- // [self.viewModel setDefaultChannelForUserLevel:userLevel];
- }
- return self;
- }
- - (void)viewDidLoad{
- [super viewDidLoad];
-
- self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- [self.view addSubview:self.tableView];
- [self.view addSubview:self.discountInfoView];
- [self.view addSubview:self.bottomView];
-
- [self setupViews];
-
- [self configNavItems];
-
- [self requestDiscountItem];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.navigationItem.title = @"提交订单";
- [self.navigationController setNavigationBarHidden:NO animated:YES];
-
- // 从地址选择页面回来就不需要请求
- if (![self.viewModel hasAddressProvince]){
- [self requestForInitalData];
- }else{
- [self.tableView reloadData];
- }
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
-
- if (![self.viewModel isHasShowRiskAlert]){
- [self.viewModel setHasShowRiskAlert];
- [self clickRightNavItem];
- };
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [self.view endEditing:YES];
- if ([self.couponSelectView isShowing]) {
- [self.couponSelectView dismissAnimated];
- }
- }
- - (void)setupViews {
- if (IS_IPHONE_X) {
- [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.height.equalTo(@50);
- make.bottom.equalTo(self.view).offset(-34);
- }];
- } else {
- [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.height.equalTo(@50);
- }];
- }
-
- self.discountInfoView.hidden = YES;
- if ([self.viewModel isVipDiscountValid]) {
- self.discountInfoView.hidden = NO;
- [self.discountInfoView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.bottomView);
- make.bottom.equalTo(self.bottomView.mas_top);
- make.height.equalTo(@48);
- }];
-
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self.view);
- make.bottom.equalTo(self.discountInfoView.mas_top);
- }];
- } else {
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self.view);
- make.bottom.equalTo(self.bottomView.mas_top);
- }];
- }
- }
- #pragma mark - Request
- - (void)requestForInitalData {
-
- self.reqTag = KSubmitReqTagInitial;
-
- [self.hudView show:YES];
-
- [self requestOrderCount];
-
- [self requestCouponList];
-
- [FKProductSubmitRequest reqShipChannelWithChannelIDArray:[self.viewModel shipChannelIdArray]
- identify:SHIP_CHANNEL_REQ_IDENTIFY
- delegate:self];
-
- [FKProductSubmitRequest requestUserAddressWithIdentify:USER_ADDRESS_REQ_IDENTIFY delegate:self];
-
- [FKProductSubmitRequest requestDiscountDataWithIdentify:DISCOUNT_REQ_IDENTIFY
- delegate:self];
-
- [FKProductSubmitRequest requestIdCardListIdentify:ID_CARD_LIST_REQ_IDENTIFY delegate:self];
- }
- - (void)requestOrderCount {
- [FKProductSubmitRequest reqOrderCountWithUnitItemArray:self.viewModel.unitItemArray
- identify:ORDER_COUNT_REQ_IDENTIFY
- delegate:self];
- }
- - (void)requestToCreateOrder {
-
- NSString *paymentOrderJson = [self.viewModel getPaymentOrderJson];
- NSString *supplyJson = [self.viewModel getSupplyJson];
- NSString *goodsJson = [self.viewModel getGoodsJsonString];
-
- if (!paymentOrderJson.length) return;
- if (!supplyJson.length) return;
- if (!goodsJson.length) return;
-
- [self.hudView show:YES];
- [FKProductSubmitRequest requestTradeNoWithPaymentJson:paymentOrderJson
- supplyJson:supplyJson
- goodsJson:goodsJson
- identify:TRADE_NO_REQ_IDENTIFY
- delegate:self];
- }
- - (void)requestCouponAmont{
-
- if ([FLStringHelper isValidString:self.viewModel.couponItem.itemID]){
- [FKProductSubmitRequest requestCouponAmountWith:COUPON_AMOUNT_REQ_IDENTIFY
- couponID:self.viewModel.couponItem.itemID
- itemArray:self.viewModel.unitItemArray
- delegate:self];
- }
- }
- - (void)requestDiscountItem {
- [FKProDetailRequest reqVipDiscountWithIdentify:VIP_DISCOUNT_ITEM_IDENTIFY delegate:self];
- }
- - (void)requestCouponList {
- [FKProductSubmitRequest requestCouponListWithUnitItemArray:self.viewModel.unitItemArray
- identify:COUPON_LIST_REQ_IDENTIFY delegate:self];
- }
- #pragma mark - response
- - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
-
- if (identify == USER_ADDRESS_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagAddress;
- }else if (identify == SHIP_CHANNEL_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagChannel;
- }else if (identify == ORDER_COUNT_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagOrderCount;
- }
-
- if (self.reqTag == KSubmitReqTagFinish){
- [self.hudView hide:NO];
- }
-
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
-
- if (identify == USER_ADDRESS_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagAddress;
- } else if (identify == SHIP_CHANNEL_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagChannel;
- } else if (identify == ORDER_COUNT_REQ_IDENTIFY){
- self.reqTag = self.reqTag ^ KSubmitReqTagOrderCount;
- }
- if (self.reqTag == KSubmitReqTagFinish){
- [self.hudView hide:NO];
- }
-
- if (header.code.intValue == RESPONSE_MSG_NORMAL){
- if (identify == ID_CARD_LIST_REQ_IDENTIFY) {
- NSArray *idCardArray = [FKBindIdCardReform parserIdCardListWithData:response];
- self.viewModel.selectedIdCardItem = [FKSubmitOrderViewModel validIdCardItemFromArray:idCardArray];
- if (self.viewModel.isNeedIdCard){
- [self.tableView reloadData];
- }
- } else if (identify == USER_ADDRESS_REQ_IDENTIFY) {
- self.viewModel.selectedAddress = [FKProductSubmitReform parserAddresModelWithDict:response];
- [self.tableView reloadData];
- [self refreshBottomView];
- } else if (identify == DISCOUNT_REQ_IDENTIFY) {
- self.viewModel.discountModel.disCountArray = [FKProductSubmitReform parserDiscountArrayWithDict:response];
- [self.viewModel.discountModel ruledDiscount];
- [self.viewModel allocateDiscount];
- [self.tableView reloadData];
- [self refreshBottomView];
- } else if (identify == SHIP_CHANNEL_REQ_IDENTIFY) {
- NSArray *tranformItemArray = [FKProductSubmitReform parserChannelArrayWithData:response];
- [self.viewModel filterWithTransformItemArray:tranformItemArray];
- [self.tableView reloadData];
- [self.viewModel hasShowChannel];
- } else if (identify == ORDER_COUNT_REQ_IDENTIFY) {
- NSArray *proFeeArray = [FKProductSubmitReform parserProFeeArrayWithDict:response];
- [self.viewModel filterWithProFeeItemArray:proFeeArray];
- [self.viewModel setDefaultChannel];
- self.viewModel.isNeedIdCard = [FKProductSubmitReform parserIsNeedIdCardWithDict:response];
- self.viewModel.needIdCardType = [FKProductSubmitReform parserNeedIdCardTypeWithDict:response];
- self.viewModel.serveTime = [FKProductSubmitReform parseServeTime:response];
- [self.viewModel allocateDiscount];
- [self.tableView reloadData];
- [self refreshBottomView];
- } else if (identify == TRADE_NO_REQ_IDENTIFY) {
- self.viewModel.paymentModel = [FKProductSubmitReform parserPaymentItemWithDict:response];
- if (!self.viewModel.paymentModel) {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- return;
- }
- [self pushOrderPayController:self.viewModel.paymentModel];
- } else if (identify == COUPON_LIST_REQ_IDENTIFY) {
- self.viewModel.couponArray = [FKCashCouponReform parseCouponItems:response];
- self.viewModel.couponItem = [self.viewModel firstValidCounponItem];
- self.viewModel.couponAmount = nil;
- [self requestCouponAmont];
- [self.tableView reloadData];
- } else if (identify == COUPON_AMOUNT_REQ_IDENTIFY) {
- self.viewModel.couponAmount = [FKProductSubmitReform parseCouponAmount:response];
- self.viewModel.deratedSupplierArray = [FKProductSubmitReform parseDeratedSupplierArray:response];
- [self.tableView reloadData];
- [self refreshBottomView];
- } else if (identify == VIP_DISCOUNT_ITEM_IDENTIFY) {
- self.viewModel.discountItem = [FKProductDetailReform parserVipDiscountItem:response];
- self.discountInfoView.countLabel.text = [NSString stringWithFormat:@"%@次", [self.viewModel.discountItem quantity] ? : @"0"];
- [self.tableView reloadData];
-
- [self setupViews];
- }
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- #pragma mark - tableView dataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return [self.viewModel numberOfSectionsInTableView];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.viewModel numberOfRowsInSection:section];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *reuseStr = [self.viewModel cellReuseIdentifyWithIndexPath:indexPath];
- kSubmitProCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
-
- WeakSelf(weakSelf);
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseStr];
- if (!cell) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
-
- switch (cellType) {
- case kSubmitProCellTypeDiscount:{
- FKSubmitDiscountCell *discountCell = (FKSubmitDiscountCell *)cell;
- [discountCell.actionButton addTarget:self
- action:@selector(disCountButtonClick:)
- forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeMessage:{
- SubmitInputCell *messageCell = (SubmitInputCell *)cell;
- messageCell.inputField.delegate = self;
- messageCell.inputField.tag = kMessageTextFieldTag;
- break;
- }
- case kSubmitProCellTypeChannelChoice: {
- FKSubmitChannelChoiceCell *choiceCell = (FKSubmitChannelChoiceCell *)cell;
- [choiceCell.dropListBtn addTarget:self action:@selector(clickChannelArrow:) forControlEvents:UIControlEventTouchUpInside];
- [choiceCell.channelExplainBtn addTarget:self action:@selector(clickChannelExplainButton:) forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeChannelList:{
- FKSubmitChannelCell *channelCell = (FKSubmitChannelCell *)cell;
- channelCell.delegate = self;
- break;
- }
- case kSubmitProCellTypeDutyFee: {
- FKSubmitOrderInfoCell *infoCell = (FKSubmitOrderInfoCell *)cell;
- [infoCell.infoBtn addTarget:self action:@selector(clickFeeInfoBtn:) forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeServeFee: {
- FKSubmitOrderInfoCell *serveCell = (FKSubmitOrderInfoCell *)cell;
- [serveCell.infoBtn addTarget:self action:@selector(clickServeFeeInfoBtn:) forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeLaw:{
- FKSubmitLawCell *lawCell = (FKSubmitLawCell *)cell;
- [lawCell.checkBox addTarget:self action:@selector(clickLawBox:) forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeActivity: {
- FKSubmitkActivityCell *activityCell = (FKSubmitkActivityCell *)cell;
- [activityCell setSelectedCoupon:self.viewModel.couponItem
- amount:self.viewModel.couponAmount
- count:[self.viewModel validCouponCount]];
- break;
- }
- case kSubmitProCellTypeVipDiscount: {
- FKSubmitkActivityCell *activityCell = (FKSubmitkActivityCell *)cell;
- [activityCell setVipDiscountInfoWithViewModel:self.viewModel];
- activityCell.didUseVipDiscount = ^(BOOL isUseVipDiscount) {
- weakSelf.viewModel.discountItem.isUseVipDiscount = isUseVipDiscount;
- [weakSelf.tableView reloadData];
- [weakSelf refreshBottomView];
- };
- break;
- }
- case kSubmitProCellTypeUnitCount:{
- FKSubmitUnitCountCell *unitCell = (FKSubmitUnitCountCell *)cell;
- [unitCell.latePayButton addTarget:self
- action:@selector(clickLatePayBtn)
- forControlEvents:UIControlEventTouchUpInside];
- }
- break;
- case kSubmitProCellTypeOfficalCarriage:{
- PindanCommonCell *officalCell = (PindanCommonCell *)cell;
- [officalCell.infoBtn addTarget:self
- action:@selector(clickOfficalCarriageInfo)
- forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- case kSubmitProCellTypeProductDetail:{
- FKSubmitProductDetailCell *productCell = (FKSubmitProductDetailCell *)cell;
- productCell.delegate = self;
- [productCell.productTagBtn addTarget:self
- action:@selector(clickThirdSellBtn:)
- forControlEvents:UIControlEventTouchUpInside];
- break;
- }
- default:
- break;
- }
-
- [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return [self.viewModel cellHeightForIndexPath:indexPath];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 10.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- #pragma mark - tableView delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- kSubmitProCellType type = [self.viewModel cellTypeForIndexPath:indexPath];
- WeakSelf(weakSelf);
- switch (type) {
- case kSubmitProCellTypeAddAddress: {
- UIViewController *controller = [[FKAddressDetailController alloc] initWithAddress:nil type:FKAddressDetailControllerTypeAdd];
- controller.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:controller animated:YES];
- break;
- }
- case kSubmitProCellTypeAddress: {
-
- FKAddressListController *controller = [[FKAddressListController alloc] initWithType:FKAddressListControllerTypeChoice];
- controller.dataSource = self;
- controller.delegate = self;
-
- controller.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:controller animated:YES];
- break;
- }
- case kSubmitProCellTypeAddIDCard: {
- FKAddIdCardController *controller = [FKAddIdCardController new];
- controller.hidesBottomBarWhenPushed = YES;
- controller.finishToBack = ^{
- [FKProductSubmitRequest requestIdCardListIdentify:ID_CARD_LIST_REQ_IDENTIFY delegate:weakSelf];
- };
- [self.navigationController pushViewController:controller animated:YES];
- break;
- }
- case kSubmitProCellTypeIDCard: {
- FKIdCardManageController *controller = [FKIdCardManageController new];
- controller.dataSource = self;
- controller.delegate = self;
- controller.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:controller animated:YES];
- break;
- }
- case kSubmitProCellTypeActivity: {
- FKActivityCardController *controller = [[FKActivityCardController alloc] initWithData:self.viewModel.couponArray serverTime:self.viewModel.serveTime];
- controller.hidesBottomBarWhenPushed = YES;
- controller.isDisplayRightNaviItem = YES;
- controller.didSelectCallback = ^(FKCouponItem *item) {
- weakSelf.viewModel.couponItem = item;
- [weakSelf.navigationController popViewControllerAnimated:YES];
-
- if (item) {
- [weakSelf requestCouponAmont];
- } else {
- weakSelf.viewModel.couponAmount = nil;
- [weakSelf.tableView reloadData];
- [weakSelf refreshBottomView];
- }
- };
- [self.navigationController pushViewController:controller animated:YES];
- break;
- }
- default:
- break;
- }
- }
- #pragma mark - FKAddressListController DataSource & Delegate
- - (NSString *)currentSelectedAddressID {
- return self.viewModel.selectedAddress.addressID;
- }
- - (void)addressListController:(FKAddressListController *)controller didSelectAddress:(ShipAddress *)address {
- if (address){
- self.viewModel.selectedAddress = address;
- [self.tableView reloadData];
- [self.navigationController popToViewController:self animated:YES];
- }
- }
- - (void)addressListController:(FKAddressListController *)controller didUpdateAddress:(ShipAddress *)address {
- self.viewModel.selectedAddress = address;
- [self.tableView reloadData];
- }
- #pragma mark - FKIdCardManageController DataSource & Delegate
- - (NSString *)currentSelectedIDCard {
- return self.viewModel.selectedIdCardItem.itemID;
- }
- - (void)idCardManageController:(FKIdCardManageController *)controller didSelectItem:(FKIdCardItem *)item {
- if (item) {
- self.viewModel.selectedIdCardItem = item;
- [self.navigationController popToViewController:self animated:YES];
- }
- }
- - (void)idCardManageController:(FKIdCardManageController *)controller didRemoveItem:(FKIdCardItem *)item {
- self.viewModel.selectedIdCardItem = nil;
- }
- - (void)idCardManageController:(FKIdCardManageController *)controller didUpdateItem:(FKIdCardItem *)item {
- self.viewModel.selectedIdCardItem = item;
- }
- #pragma mark - textFieldDelegate
- - (void)textFieldDidEndEditing:(UITextField *)textField {
- if (textField.tag == kMessageTextFieldTag) {
- self.viewModel.messageText = textField.text;
- }
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- #pragma mark - channelCell delegate
- - (void)channelCell:(FKSubmitChannelCell *)cell changeToChannel:(kSubmitChannelType)type{
-
- if (kSubmitChannelTypeNone == type || kSubmitChannelTypeAirNormal == type) return;
-
- NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
- if (indexPath){
- FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:indexPath.section - 1];
- unitItem.selectedChannelType = type;
-
- [self.tableView reloadData];
-
- [self requestOrderCount];
- [self requestCouponList];
- }
- }
- #pragma mark - SubmitProductDetailCellDelegate
- - (void)productCell:(FKSubmitProductDetailCell *)cell didChangeQuantity:(NSInteger)quantity atIndexPath:(NSIndexPath *)indexPath {
- if (quantity > 0) {
- FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:indexPath.section - 1];
- FKSubmitProductItem *productItem = [unitItem getProductItemAtIndex:indexPath.row - 1];
- productItem.quality = quantity;
-
- [self requestForInitalData];
- [FKProductSubmitRequest requestCouponListWithUnitItemArray:self.viewModel.unitItemArray
- identify:COUPON_LIST_REQ_IDENTIFY delegate:self];
- } else {
- [FLProgressHUDHelper showText:@"商品数量必须大于0" inView:self.view];
- }
- }
- #pragma mark - method
- - (void)configNavItems{
- [self configLeftNaviItem];
-
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"submit_info"]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(clickRightNavItem)];
- rightItem.width = 80;
-
- rightItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, - 9);
- self.navigationItem.rightBarButtonItem = rightItem;
- }
- - (void)couponSelectDoneWithID:(NSString *)couponID{
-
- FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:self.couponSelectView.tag];
-
- if (unitItem){
-
- if (!couponID) {
- unitItem.selectedDiscount = nil;
- } else {
- unitItem.selectedDiscount = [self.viewModel.discountModel couponItemWithID:couponID];
- [self.viewModel.discountModel removeCashItemWithID:couponID];
- }
-
- [self.viewModel.discountModel ruledDiscount];
- [self.tableView reloadData];
- [self refreshBottomView];
- }
- }
- - (void)refreshBottomView {
- // 邮费券或活动卡优惠
- CGFloat totalFee = [self.viewModel getTotalFee];
- CGFloat payFee = [self.viewModel getPayTotalFee];
-
- NSUInteger allCount = [self.viewModel getTotalQuality];
- [self.bottomView refreshPriceWithAmount:allCount
- totalFee:MAX(0, payFee)
- discountFee:MAX(0, totalFee - payFee)];
- }
- #pragma mark - action
- - (void)clickLeftNaviItem{
-
- [BehaviorTrackManger requestBehaviorType:kBehaviorCancelSubmitOrder jsonString:nil];
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)clickOfficalCarriageInfo{
- // 官网运费说明
- NSString *url = [NSString stringWithFormat:@"%@/support/shipment-rule.html?supplier_id=11", [[FKServerUtil sharedInstance] webServer]];
- [self pushWebViewController:url segmentStr:nil];
- }
- - (void)clickLatePayBtn{
- // 跳转到超时赔付H5
- NSString *url = [NSString stringWithFormat:@"%@/support/timeout-pay.html", [[FKServerUtil sharedInstance] webServer]];
- [self pushWebViewController:url segmentStr:nil];
- }
- - (void)clickLawBox:(UIButton *)sender{
- sender.selected = !sender.selected;
- self.bottomView.enabled = sender.selected;
- // self.agreeProtocol = sender.selected;
- }
- - (void)clickSeeProtocolBtn{
-
- NSString *url = [NSString stringWithFormat:@"%@/support/special-clause.html", [[FKServerUtil sharedInstance] webServer]];
- [self pushWebViewController:url segmentStr:nil];
- }
- - (void)clickRightNavItem{
-
- [self.view endEditing:YES];
-
- FKDirectBuyRiskView *riskView = [[FKDirectBuyRiskView alloc]init];
- [riskView showInView:self.navigationController.view];
- }
- - (IBAction)clickFeeInfoBtn:(UIButton *)sender{
- // 弹框
- FKTaxShowView *taxView = [[FKTaxShowView alloc] init];
- [taxView showInView:self.view];
- taxView.showDetailBlock = ^{
- [self pushFeeInfoDetail];
- };
- }
- - (IBAction)clickServeFeeInfoBtn:(UIButton *)sender {
- FKTaxShowView *taxView = [[FKTaxShowView alloc] init];
-
- taxView.titleLabel.text = @"保险费说明";
- taxView.secondTitleLabel.text = @"保险费";
- taxView.contentLabel.text = @"根据转运公司规定,当您走该转运渠道的订单超过1000元时,将收取商品总价1.5%的保险费用,来预防包裹的丢失和破损。";
- taxView.moreView.hidden = YES;
- taxView.moreLabel.hidden = YES;
- taxView.moreControl.userInteractionEnabled = NO;
- [taxView showInView:self.view];
- }
- - (void)pushFeeInfoDetail{
- NSString *url = [NSString stringWithFormat:@"%@/support/about-clearance.html", [[FKServerUtil sharedInstance] webServer]];
-
- [self pushWebViewController:url segmentStr:@"#tariff"];
- }
- - (void)disCountButtonClick:(UIButton *)sender {
- [self.view endEditing:YES];
-
- self.couponSelectView.tag = sender.tag;
- FKSubmitUnitItem *unitItem = [self.viewModel getUnitItemAtIndex:sender.tag];
-
- // 无国际运费不适用代金券
- if ([unitItem needShowInternationPostage] && [unitItem getTotalInternationalPostage] > 0){
-
- CashCouponItem *oldCash = unitItem.selectedDiscount;
- [self.viewModel.discountModel receiveCashItemAtFirst:oldCash];
-
- NSArray *validCouponArray = [self.viewModel.discountModel getValidCashItemForUnitItem:unitItem];
- if (validCouponArray.count) {
- [self.couponSelectView refreshCouponArray:[self.viewModel.discountModel getValidCashItemForUnitItem:unitItem] selectFirst:(oldCash ? YES : NO)];
- [self.couponSelectView showInView:self.navigationController.view animated:YES];
- } else {
- [FLProgressHUDHelper showText:@"无可用代金券" inView:self.view];
- }
- }
- }
- - (void)clickSubmitConfirmBtn {
- // 判断收件地址是否为空
- if (![self.viewModel hasAddress]){
- [FLProgressHUDHelper showTipAlert:@"请填写收货地址"];
- return;
- }
-
- if ([self.viewModel.needIdCardType isEqualToString:@"3"] ) {
- if (self.viewModel.selectedIdCardItem == nil) {
- [FLProgressHUDHelper showTipAlert:@"因海关清关需要,请添加收货人身份证信息"];
- return;
- }
- } else {
- if (![self.viewModel isIDCardValid]) {
- [FLProgressHUDHelper showTipAlert:@"因海关清关需要,请填写并保存收货人身份证号"];
- return;
- }
- }
-
- [self requestToCreateOrder];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:BASKET_NEED_TO_REFRESH object:nil];
- }
- - (void)clickThirdSellBtn:(UIButton *)sender{
- NSString *url = [NSString stringWithFormat:@"%@/support/about-goods.html", [[FKServerUtil sharedInstance] webServer]];
- [self pushWebViewController:url segmentStr:@"#third-party"];
- }
- - (void)clickChannelArrow:(UIButton *)sender{
- self.viewModel.openChannel = !self.viewModel.openChannel;
- [self.tableView reloadData];
- }
- - (IBAction)clickChannelExplainButton:(id)sender {
- NSString *url = [NSString stringWithFormat:@"%@/support/trans-channel-desc.html", [[FKServerUtil sharedInstance] webServer]];
- [self pushWebViewController:url segmentStr:nil];
- }
- #pragma mark - push controller
- - (void)pushOrderPayController:(SubmitPaymentItem *)paymentItem {
-
- // if (self.viewModel.isNeedIdCard && self.viewModel.selectedIdCardItem.idCardNum.length == 0){
- // paymentItem.successController = FKOrderPaymentSuccessControllerBindIDCard;
- // } else {
- paymentItem.successController = FKOrderPaymentSuccessControllerRedpacket;
- // }
-
- OrderPayController *payController = [[OrderPayController alloc] initWithPaymentItem:paymentItem];
- payController.hidesBottomBarWhenPushed = YES;
-
- NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
- [viewControllers removeLastObject];
- [viewControllers addObject:payController];
- [self.navigationController setViewControllers:viewControllers animated:YES];
- }
- - (void)pushWebViewController:(NSString *)urlString segmentStr:(NSString *)segmentStr{
- WebViewController *newViewController = [[FLControllerHelper currentStoryBoard] instantiateViewControllerWithIdentifier:@"WebViewController"];
- newViewController.url = urlString;
- newViewController.urlSegment = segmentStr;
- newViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:newViewController animated:YES];
- }
- #pragma mark - property
- - (FKSubmitOrderViewModel *)viewModel{
- if (_viewModel == nil) {
- _viewModel = [[FKSubmitOrderViewModel alloc]init];
- }
- return _viewModel;
- }
- - (UITableView *)tableView {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.sectionFooterHeight = 0;
- _tableView.contentInset = UIEdgeInsetsMake(0, 0, 10, 0);
- _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- [_tableView registerClass:[PindanBaseCell class] forCellReuseIdentifier:NSStringFromClass([PindanBaseCell class])];
- [_tableView registerClass:[PindanCommonCell class] forCellReuseIdentifier:NSStringFromClass([PindanCommonCell class])];
- [_tableView registerClass:[FKSubmitProductDetailCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitProductDetailCell class])];
- [_tableView registerClass:[SubmitAddNewCell class] forCellReuseIdentifier:NSStringFromClass([SubmitAddNewCell class])];
- [_tableView registerClass:[SubmitDefaultAddressCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultAddressCell class])];
- [_tableView registerClass:[SubmitDefaultIDCardCell class] forCellReuseIdentifier:NSStringFromClass([SubmitDefaultIDCardCell class])];
- [_tableView registerClass:[FKSubmitIdentityCardCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitIdentityCardCell class])];
- [_tableView registerClass:[SubmitInputCell class] forCellReuseIdentifier:NSStringFromClass([SubmitInputCell class])];
- [_tableView registerClass:[FKSubmitDiscountCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitDiscountCell class])];
- [_tableView registerClass:[FKSubmitOrderInfoCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitOrderInfoCell class])];
- [_tableView registerClass:[FKSubmitChannelChoiceCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitChannelChoiceCell class])];
- [_tableView registerClass:[FKSubmitChannelCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitChannelCell class])];
- [_tableView registerClass:[FKSubmitCountryInfoCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitCountryInfoCell class])];
- [_tableView registerClass:[FKSubmitUnitCountCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitUnitCountCell class])];
- [_tableView registerClass:[FKSubmitLawCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitLawCell class])];
- [_tableView registerClass:[FKSubmitkActivityCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitkActivityCell class])];
- [_tableView registerClass:[FKSubmitNationFeeCell class] forCellReuseIdentifier:NSStringFromClass([FKSubmitNationFeeCell class])];
- }
- return _tableView;
- }
- - (FKDiscountInfoView *)discountInfoView {
- if (!_discountInfoView) {
- _discountInfoView = [FKDiscountInfoView new];
- _discountInfoView.backgroundColor = [UIColor whiteColor];
- }
- return _discountInfoView;
- }
- - (FKSubmitOrderBottomView *)bottomView {
- if (_bottomView == nil) {
- _bottomView = [[FKSubmitOrderBottomView alloc]init];
- [_bottomView.confirmBtn addTarget:self action:@selector(clickSubmitConfirmBtn) forControlEvents:UIControlEventTouchUpInside];
- }
- return _bottomView;
- }
- - (FKCouponSelectView *)couponSelectView{
- if (_couponSelectView == nil) {
- _couponSelectView = [[FKCouponSelectView alloc]initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, UISCREENHEIGH)];
-
- WeakSelf(weakSelf);
- _couponSelectView.finish = ^(NSString* couponID) {
- [weakSelf couponSelectDoneWithID:couponID];
- };
- }
- return _couponSelectView;
- }
- @end
|