Commit 608201ec authored by 曹云霄's avatar 曹云霄

增加我的卡卷包、上传小票激活卡劵、订单促销

parent 586d2884
......@@ -6,7 +6,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="259" id="KGk-i7-Jjw" customClass="AdditionalTableViewCell">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="259" id="KGk-i7-Jjw" customClass="AdditionalTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="768" height="75"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
......
//
// CardAmplificationViewController.h
// Lighting
//
// Created by 曹云霄 on 2016/10/20.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "BaseViewController.h"
@interface CardAmplificationViewController : BaseViewController
/**
* 取消
*/
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
/**
* 确认
*/
@property (weak, nonatomic) IBOutlet UIButton *sureButton;
@end
//
// CardAmplificationViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/10/20.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardAmplificationViewController.h"
@interface CardAmplificationViewController ()
@end
@implementation CardAmplificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
self.view.superview.layer.cornerRadius = 0;
}
#pragma mark - 取消
- (IBAction)cancelButtonClickAction:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 确认
- (IBAction)sureButtonClickAction:(UIButton *)sender {
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CardAmplificationViewController">
<connections>
<outlet property="cancelButton" destination="fSg-ii-Gn4" id="wVG-sn-NH6"/>
<outlet property="sureButton" destination="f9T-ak-TEq" id="vnn-d3-9GZ"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="500" height="370"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="00登录-谭" translatesAutoresizingMaskIntoConstraints="NO" id="4rL-ti-mfn">
<rect key="frame" x="0.0" y="0.0" width="500" height="309"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="f9T-ak-TEq">
<rect key="frame" x="315" y="332" width="120" height="30"/>
<color key="backgroundColor" red="0.34901960780000002" green="0.67450980390000004" blue="0.86274509799999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="确认">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="sureButtonClickAction:" destination="-1" eventType="touchUpInside" id="7CT-T8-qpC"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fSg-ii-Gn4">
<rect key="frame" x="64" y="332" width="120" height="30"/>
<color key="backgroundColor" red="0.34901960780000002" green="0.67450980390000004" blue="0.86274509799999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="取消">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="cancelButtonClickAction:" destination="-1" eventType="touchUpInside" id="KWa-ug-wjw"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="4rL-ti-mfn" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="1KA-cY-Iy4"/>
<constraint firstAttribute="trailing" secondItem="4rL-ti-mfn" secondAttribute="trailing" id="8cB-Ma-qfw"/>
<constraint firstAttribute="bottom" secondItem="4rL-ti-mfn" secondAttribute="bottom" constant="61" id="DpK-EL-Z6i"/>
<constraint firstItem="4rL-ti-mfn" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="EAG-QZ-ddA"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="407" y="156"/>
</view>
</objects>
<resources>
<image name="00登录-谭" width="1024" height="768"/>
</resources>
</document>
//
// CardBeenUseViewController.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CardBeenUseViewController : BaseViewController
/**
* 已使用卡劵
*/
@property (weak, nonatomic) IBOutlet UICollectionView *beenUseCardCollectionView;
/**
* FlowLayout
*/
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *beenUseLayout;
@end
//
// CardBeenUseViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardBeenUseViewController.h"
#import "CardCollectionViewCell.h"
#import "CardOrderInformationReusableView.h"
#import "CardAmplificationViewController.h"
@interface CardBeenUseViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic,strong) RsJingDongECardRequest *requestModel;
/**
* 数据源
*/
@property (nonatomic,strong) NSMutableArray *datasArray;
/**
* 总页数
*/
@property (nonatomic,assign) NSInteger totalPage;
@end
@implementation CardBeenUseViewController
#pragma mark - lazy
- (RsJingDongECardRequest *)requestModel
{
if (!_requestModel) {
_requestModel = [[RsJingDongECardRequest alloc]init];
DataPage *page = [[DataPage alloc]init];
page.page = 0;
page.rows = 10;
page.order = @"desc";
_requestModel.guideIdEquals = [Shoppersmanager manager].Shoppers.employee.fid;
_requestModel.stateEquals = @"actived";
_requestModel.page = page;
}
return _requestModel;
}
- (NSMutableArray *)datasArray
{
if (!_datasArray) {
_datasArray = [NSMutableArray array];
}
return _datasArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupCollectionView];
[self setupRefreshAction];
}
#pragma mark - 设置刷新
- (void)setupRefreshAction
{
WS(weakSelf);
MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
weakSelf.requestModel.page.page = 0;
[weakSelf.beenUseCardCollectionView.mj_footer resetNoMoreData];
[weakSelf getCardDatasAction:YES];
}];
headerRefresh.stateLabel.hidden = YES;
headerRefresh.lastUpdatedTimeLabel.hidden = YES;
self.beenUseCardCollectionView.mj_header = headerRefresh;
[self.beenUseCardCollectionView.mj_header beginRefreshing];
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
if (++ weakSelf.requestModel.page.page >= weakSelf.totalPage) {
[weakSelf.beenUseCardCollectionView.mj_footer endRefreshingWithNoMoreData];
}else
{
[weakSelf getCardDatasAction:NO];
}
}];
footer.automaticallyHidden = YES;
self.beenUseCardCollectionView.mj_footer = footer;
}
#pragma mark - 获取未使用卡劵
- (void)getCardDatasAction:(BOOL)isRemove
{
WS(weakSelf);
[[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CARDINFORMATION) WithRequestType:Zero WithParameter:self.requestModel WithReturnValueBlock:^(id returnValue) {
weakSelf.beenUseCardCollectionView.emptyDataSetSource = self;
weakSelf.beenUseCardCollectionView.emptyDataSetDelegate = self;
[weakSelf endRefreshingForTableView:weakSelf.beenUseCardCollectionView];
if ([returnValue[@"code"] isEqualToNumber:@0]) {
[weakSelf.datasArray removeAllObjects];
RsJingDongECardResponse *cardInformation = [[RsJingDongECardResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
weakSelf.totalPage = cardInformation.totalpages;
[weakSelf.datasArray addObjectsFromArray:cardInformation.list];
[weakSelf.beenUseCardCollectionView reloadData];
}else{
[weakSelf ErrorMBProgressView:returnValue[@"message"]];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
[weakSelf ErrorMBProgressView:NETWORK];
} WithFailureBlock:^(NSError *error) {
[weakSelf ErrorMBProgressView:error.localizedDescription];
}];
}
#pragma mark - UICollectionView
- (void)setupCollectionView
{
self.beenUseLayout.itemSize = CGSizeMake((ScreenWidth-48-20*4)/3, 200);
self.beenUseLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
self.beenUseLayout.minimumLineSpacing = 20;
self.beenUseLayout.minimumInteritemSpacing = 20;
[self.beenUseCardCollectionView registerNib:[UINib nibWithNibName:@"CardOrderInformationReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CardOrderInformationReusableView"];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CardCollectionViewCell" forIndexPath:indexPath];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
GroupByOrderNumber *model = self.datasArray[section];
return model.ecards.count;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if (kind == UICollectionElementKindSectionHeader) {
CardOrderInformationReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CardOrderInformationReusableView" forIndexPath:indexPath];
headerView.model = self.datasArray[indexPath.section];
headerView.uploadReceiptsButton.hidden = true;
return headerView;
}
return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(0, 65);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return self.datasArray.count;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
CardAmplificationViewController *settlement = [[CardAmplificationViewController alloc]init];
settlement.preferredContentSize = CGSizeMake(500, 370);
settlement.modalPresentationStyle = UIModalPresentationFormSheet;
UIPopoverPresentationController *pop = settlement.popoverPresentationController;
pop.sourceView = settlement.view;
[self presentViewController:settlement animated:YES completion:nil];
}
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return kNoDataImage;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
return YES;
}
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// CardCollectionViewCell.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CardCollectionViewCell : UICollectionViewCell
/**
* 背景图片
*/
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
@end
//
// CardCollectionViewCell.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardCollectionViewCell.h"
@implementation CardCollectionViewCell
@end
//
// CardDetailsViewController.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "BaseViewController.h"
@interface CardDetailsViewController : BaseViewController
/**
* 未使用
*/
@property (weak, nonatomic) IBOutlet UIButton *dontUseButton;
/**
* 已使用
*/
@property (weak, nonatomic) IBOutlet UIButton *beenUseButton;
/**
* 指示线
*/
@property (weak, nonatomic) IBOutlet UIView *instructionsLineView;
/**
* 卡劵背景
*/
@property (weak, nonatomic) IBOutlet UIView *cardBackgroundView;
@end
//
// CardDetailsViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardDetailsViewController.h"
#import "CardDontUseViewController.h"
#import "CardBeenUseViewController.h"
@interface CardDetailsViewController ()
/**
* 当前的控制器
*/
@property (nonatomic,strong) UIViewController *currentVC;
@end
@implementation CardDetailsViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self addChildViewController];
}
#pragma mark - 添加卡劵详情vc
- (void)addChildViewController
{
CardDontUseViewController *dontUseVc = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"CardDontUseViewController"];
[self addChildViewController:dontUseVc];
CardBeenUseViewController *beenUseVc = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"CardBeenUseViewController"];
[self addChildViewController:beenUseVc];
dontUseVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
beenUseVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
[self.cardBackgroundView addSubview:dontUseVc.view];
self.currentVC = dontUseVc;
}
#pragma mark - 切换已使用卡劵、未使用卡劵
- (void)switchPaymentsVCAndWithdrawalVC:(UIViewController *)newViewController
{
[self transitionFromViewController:self.currentVC toViewController:newViewController duration:0.5 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
if (finished) {
[self.cardBackgroundView addSubview:newViewController.view];
self.currentVC = newViewController;
}
}];
}
#pragma mark - 切换ContentController
- (IBAction)paymentsButtonAndWithdrawalButtonClick:(UIButton *)sender {
if ([sender isEqual:self.dontUseButton]) {
sender.selected = YES;
self.beenUseButton.selected = NO;
}else
{
sender.selected = YES;
self.dontUseButton.selected = NO;
}
[self setupInstructionsViewOrigin:sender];
[self switchPaymentsVCAndWithdrawalVC:self.childViewControllers[sender.tag-100]];
}
#pragma mark - 设置指示线的位置
- (void)setupInstructionsViewOrigin:(UIButton *)sender
{
[UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.instructionsLineView.frame = CGRectMake(sender.mj_origin.x+(sender.mj_w-self.instructionsLineView.mj_w)/2, self.instructionsLineView.mj_origin.y, self.instructionsLineView.mj_w, 2);
} completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
//
// CardDontUseViewController.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CardDontUseViewController : BaseViewController
/**
* 未使用卡劵
*/
@property (weak, nonatomic) IBOutlet UICollectionView *dontUseCardCollectionView;
/**
* FlowLayout
*/
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *dontUseFlowLayout;
@end
This diff is collapsed.
//
// CardOrderInformationReusableView.h
//
//
// Created by 曹云霄 on 2016/10/20.
//
//
#import <UIKit/UIKit.h>
@protocol UploadReceiptsDelegate <NSObject>
- (void)startUploadReceipts:(NSInteger)sectionIndex;
@end
@interface CardOrderInformationReusableView : UICollectionReusableView
@property (nonatomic,weak) id<UploadReceiptsDelegate> delegate;
@property (nonatomic,assign) NSInteger sectionIndex;
/**
* 上传小票
*/
@property (weak, nonatomic) IBOutlet UIButton *uploadReceiptsButton;
/**
* 订单号
*/
@property (weak, nonatomic) IBOutlet UILabel *orderNumberLabel;
/**
* 订单时间
*/
@property (weak, nonatomic) IBOutlet UILabel *orderTimelabel;
/**
* 订单数据
*/
@property (nonatomic,strong) GroupByOrderNumber *model;
@end
//
// CardOrderInformationReusableView.m
//
//
// Created by 曹云霄 on 2016/10/20.
//
//
#import "CardOrderInformationReusableView.h"
@implementation CardOrderInformationReusableView
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadCompleteHiddenButton:) name:UPLOAD_COMPLETE object:nil];
}
#pragma mark - 上传小票
- (IBAction)uploadReceiptsButtonClickAction:(UIButton *)sender {
if ([self.delegate respondsToSelector:@selector(startUploadReceipts:)]) {
[self.delegate startUploadReceipts:self.sectionIndex];
}
}
- (void)setModel:(GroupByOrderNumber *)model
{
_model = model;
self.orderNumberLabel.text = _model.orderNumber;
}
#pragma mark - 上传完成隐藏按钮
- (void)uploadCompleteHiddenButton:(NSNotification *)sender
{
self.uploadReceiptsButton.hidden = YES;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="CardOrderInformationReusableView">
<rect key="frame" x="0.0" y="0.0" width="666" height="65"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Fje-v9-8h3">
<rect key="frame" x="563" y="15.5" width="96" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.34901960784313724" green="0.67450980392156867" blue="0.86274509803921573" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="上传小票">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="5"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="uploadReceiptsButtonClickAction:" destination="iN0-l3-epB" eventType="touchUpInside" id="M4p-LY-oPJ"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="123456789098" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Dyu-RA-dDY">
<rect key="frame" x="90" y="10" width="200" height="21"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="时间:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="B5J-F8-QRj">
<rect key="frame" x="36" y="35" width="42" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2016-10-20 13:51:10" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8zE-O4-90C">
<rect key="frame" x="90" y="35" width="164" height="21"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="订单号:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8yQ-hJ-RXU">
<rect key="frame" x="26" y="10" width="52" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.96470588235294119" green="0.96470588235294119" blue="0.96470588235294119" alpha="1" colorSpace="calibratedRGB"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="orderNumberLabel" destination="Dyu-RA-dDY" id="V8o-b5-YQu"/>
<outlet property="orderTimelabel" destination="8zE-O4-90C" id="9o1-2A-cY3"/>
<outlet property="uploadReceiptsButton" destination="Fje-v9-8h3" id="6ce-we-Qno"/>
</connections>
<point key="canvasLocation" x="356" y="192"/>
</view>
</objects>
</document>
//
// CardViewController.h
// Lighting
//
// Created by 曹云霄 on 2016/10/20.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "BaseViewController.h"
@interface CardViewController : BaseViewController
/**
* 卡劵
*/
@property (weak, nonatomic) IBOutlet UICollectionView *cardCollectionView;
/**
* Flowlayout
*/
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *cardFlowLayout;
@end
//
// CardViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/10/20.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardViewController.h"
#import "CardCollectionViewCell.h"
@interface CardViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
//** 查询最近10张卡劵 */
@property (nonatomic,strong) RsJingDongECardRequest *requestModel;
//** 数据源 */
@property (nonatomic,strong) NSMutableArray *datasArray;
@end
@implementation CardViewController
#pragma mark - lazy
- (RsJingDongECardRequest *)requestModel
{
if (!_requestModel) {
_requestModel = [[RsJingDongECardRequest alloc]init];
DataPage *page = [[DataPage alloc]init];
page.page = 0;
page.rows = 10;
page.order = @"desc";
_requestModel.guideIdEquals = [Shoppersmanager manager].Shoppers.employee.fid;
_requestModel.stateEquals = @"dispensed";
_requestModel.page = page;
}
return _requestModel;
}
- (NSMutableArray *)datasArray
{
if (!_datasArray) {
_datasArray = [NSMutableArray array];
}
return _datasArray;
}
- (void)viewDidAppear:(BOOL)animated
{
[self getCardDatasAction];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark - 查询卡劵
- (void)getCardDatasAction
{
WS(weakSelf);
[[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CARDINFORMATION) WithRequestType:Zero WithParameter:self.requestModel WithReturnValueBlock:^(id returnValue) {
if ([returnValue[@"code"] isEqualToNumber:@0]) {
[weakSelf.datasArray removeAllObjects];
for (NSDictionary *dict in returnValue[@"data"][@"list"]) {
RsJingDongECardResponse *cardInformation = [[RsJingDongECardResponse alloc]initWithDictionary:dict error:nil];
[weakSelf.datasArray addObject:cardInformation];
}
[weakSelf.cardCollectionView reloadData];
}else{
[weakSelf ErrorMBProgressView:returnValue[@"message"]];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
[weakSelf ErrorMBProgressView:NETWORK];
} WithFailureBlock:^(NSError *error) {
[weakSelf ErrorMBProgressView:error.localizedDescription];
}];
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.datasArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CardCollectionViewCell" forIndexPath:indexPath];
return cell;
}
@end
......@@ -440,26 +440,18 @@
} WithprogressBlock:^(double progress) {
if (progress >= 1) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传完成";
[weskSelf RemoveMBProgressHUDLoding];
});
weskSelf.TCHud.labelText = @"上传完成";
[weskSelf RemoveMBProgressHUDLoding];
}else
{
dispatch_async(dispatch_get_main_queue(), ^{
[weskSelf ShowProgressView:progress];
});
[weskSelf ShowProgressView:progress];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
});
weskSelf.TCHud.labelText = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
} WithFailureBlock:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
});
weskSelf.TCHud.labelText = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
}];
}
......
......@@ -258,27 +258,28 @@
}else if (self.orderRecordButton.selected)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
OrderdetailsViewController *orderdetails = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"orderdetails"];
TOOrderEntity *model = (TOOrderEntity *)[[self.orderRecordArray objectAtIndex_opple:indexPath.row] order];
orderdetails.orderCode = model.orderNumber;
orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
orderdetails.isShowattachment = YES;
if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
orderdetails.isShowPrintButton = YES;
orderdetails.isDelectedButton = NO;
orderdetails.isUserInteractionEnabled = NO;
}
if ([model.orderState isEqualToString:@"001"]) {
orderdetails.isShowPayButton = YES;
orderdetails.isDelectedButton = YES;
orderdetails.isShowPrintButton = YES;
orderdetails.isUserInteractionEnabled = YES;
}
//撤销、支付回调
WS(weakSelf);
[orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
OrderBill *model = [self.orderRecordArray objectAtIndex_opple:cellindex];
OrderBill *model = [weakSelf.orderRecordArray objectAtIndex_opple:cellindex];
model.order.orderState = orderSate;
NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
[self.ClientdetailsTableview reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
[weakSelf.ClientdetailsTableview reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
}];
[self.navigationController pushViewController:orderdetails animated:YES];
}
......
......@@ -202,17 +202,25 @@
OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:indexPath.row] order];
orderdetails.orderCode = model.orderNumber;
orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
orderdetails.isShowattachment = YES;
if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
orderdetails.isShowPrintButton = YES;
orderdetails.isDelectedButton = NO;
orderdetails.isUserInteractionEnabled = NO;
}
if ([model.orderState isEqualToString:@"001"]) {
if ([model.orderState isEqualToString:@"001"]) {//未付款
orderdetails.isShowPayButton = YES;
orderdetails.isDelectedButton = YES;
orderdetails.isShowPrintButton = YES;
orderdetails.isUserInteractionEnabled = YES;
}
//撤销、支付回调
[orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
OrderBill *model = [self.datasArray objectAtIndex_opple:cellindex];
model.order.orderState = orderSate;
NSIndexPath *indexapath = [NSIndexPath indexPathForRow:cellindex inSection:0];
[self.customerOrderTableView reloadRowsAtIndexPaths:@[indexapath] withRowAnimation:UITableViewRowAnimationNone];
}];
[self.navigationController pushViewController:orderdetails animated:YES];
}
......@@ -348,16 +356,17 @@
OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
TOOrderEntity *model = (TOOrderEntity *)[[self.datasArray objectAtIndex_opple:cellindex] order];
orderdetails.orderCode = model.orderNumber;
orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
orderdetails.isShowattachment = YES;
if ([model.orderState isEqualToString:@"006"] || [model.orderState isEqualToString:@"002"] || [model.orderState isEqualToString:@"003"]) {
orderdetails.isShowPrintButton = YES;
orderdetails.isDelectedButton = NO;
orderdetails.isUserInteractionEnabled = NO;
}
if ([model.orderState isEqualToString:@"001"]) {
orderdetails.isShowPayButton = YES;
orderdetails.isDelectedButton = YES;
orderdetails.isShowPrintButton = YES;
orderdetails.isUserInteractionEnabled = YES;
}
//撤销、支付回调
[orderdetails setDelecteAndPayButtonBlock:^(NSInteger cellindex, NSString *orderSate) {
......
......@@ -35,7 +35,7 @@
- (void)setResponseDatas:(DataDict *)responseDatas
{
_responseDatas = responseDatas;
self.titleLabe.text = _responseDatas.typename;
self.titleLabe.text = _responseDatas.typeName;
}
......
......@@ -151,7 +151,7 @@
#pragma mark -设置根视图控制器
- (void)SetTheRootViewController
{
RightViewController *rightVC = [[RightViewController alloc]init];
RightViewController *rightVC = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"RightViewController"];
rightVC.delegate = self;
UINavigationController *rightNav = [[UINavigationController alloc]initWithRootViewController:rightVC];
self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:self.customtabbar rightDrawerViewController:rightNav];
......@@ -199,6 +199,7 @@
[weakSelf RemoveMBProgressHUDLoding];
if ([returnValue[@"code"] isEqualToNumber:@0]) {
//保持导购信息
LoginResult *result = [[LoginResult alloc]initWithDictionary:returnValue[@"data"] error:nil];
[Shoppersmanager manager].Shoppers = result;
......
//
// OrderDetailsSectionHeaderView.h
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface OrderDetailsSectionHeaderView : UITableViewCell
/**
* title
*/
@property (weak, nonatomic) IBOutlet UILabel *sectionHeaderTitleLabel;
@end
//
// OrderDetailsSectionHeaderView.m
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "OrderDetailsSectionHeaderView.h"
@implementation OrderDetailsSectionHeaderView
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
......@@ -20,7 +20,6 @@
*/
@property (nonatomic,copy) NSString *orderCode;
/**
* 是否显示附件信息
*/
......@@ -29,7 +28,7 @@
/**
* 区头显示title
*/
@property (nonatomic,strong) NSArray *sectionTitle;
@property (nonatomic,strong) NSMutableArray *sectionTitle;
/**
* 是否显示支付按钮
......@@ -62,6 +61,12 @@
@property (nonatomic,assign) BOOL isSliding;
/**
* 是否开启交互
*/
@property (nonatomic,assign) BOOL isUserInteractionEnabled;
@end
This diff is collapsed.
......@@ -267,8 +267,8 @@
{
//价格字符串切割
NSArray *spacrArray = [weakSelf.selectedCode componentsSeparatedByString:@"到"];
weakSelf.condtionModel.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
weakSelf.condtionModel.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
weakSelf.condtionModel.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
weakSelf.condtionModel.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
}
break;
default:
......@@ -331,8 +331,8 @@
{
//价格字符串切割
NSArray *spacrArray = [weakSelf.selectedCode componentsSeparatedByString:@"到"];
weakSelf.condtionModel.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
weakSelf.condtionModel.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
weakSelf.condtionModel.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
weakSelf.condtionModel.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
}
break;
default:
......@@ -676,8 +676,8 @@
if (![priceTitle isEqualToString:@"全部"]) {
//价格字符串切割
NSArray *spacrArray = [priceTitle componentsSeparatedByString:@"到"];
condition.startprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
condition.endprice = [NSNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
condition.startprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:0] integerValue]];
condition.endprice = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:[[spacrArray objectAtIndex_opple:1] integerValue]];
}
self.condtionModel.styleEquals = condition.styleEquals;
self.condtionModel.categoryEquals = condition.categoryEquals;
......
//
// PromotionalDeductionModel.h
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PromotionalDeductionModel : JSONModel
//** 促销对象 */
@property (nonatomic, copy) NSString *body;
//** 类型 */
@property (nonatomic, copy) NSString *type;
//** 抵扣金额 */
@property (nonatomic, assign) NSInteger total;
//** 描述 */
@property (nonatomic, copy) NSString *descriptionString;
//** 是否选中 */
@property (nonatomic,assign) BOOL isSelected;
@end
//
// PromotionalDeductionModel.m
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "PromotionalDeductionModel.h"
@implementation PromotionalDeductionModel
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
+ (JSONKeyMapper *)keyMapper
{
return [[JSONKeyMapper alloc]initWithDictionary:@{@"description":@"descriptionString"}];
}
@end
//
// PromotionalGoodsModel.h
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
@class Goods;
@protocol Goods @end
@interface PromotionalGoodsModel : JSONModel
//** 促销对象 */
@property (nonatomic, copy) NSString *body;
//** 赠送数量 */
@property (nonatomic, assign) NSInteger count;
//** 类型 */
@property (nonatomic, copy) NSString *type;
//** 商品列表 */
@property (nonatomic, strong) Goods *goods;
//** 描述 */
@property (nonatomic, copy) NSString *descriptionString;
//** 是否选中 */
@property (nonatomic,assign) BOOL isSelected;
@end
@interface Goods : JSONModel
//** 商品名称 */
@property (nonatomic, copy) NSString *name;
//** ID */
@property (nonatomic, copy) NSString *uuid;
//** code */
@property (nonatomic, copy) NSString *code;
@end
//
// PromotionalGoodsModel.m
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "PromotionalGoodsModel.h"
@implementation PromotionalGoodsModel
+ (JSONKeyMapper *)keyMapper
{
return [[JSONKeyMapper alloc]initWithDictionary:@{@"description":@"descriptionString"}];
}
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
@end
@implementation Goods
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
@end
//
// PromotionalTableViewCell.h
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface PromotionalTableViewCell : UITableViewCell
/**
* 促销描述
*/
@property (weak, nonatomic) IBOutlet UILabel *promotionalTitleLabel;
@end
//
// PromotionalTableViewCell.m
// Lighting
//
// Created by 曹云霄 on 2016/10/18.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "PromotionalTableViewCell.h"
@implementation PromotionalTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
......@@ -11,7 +11,8 @@
#import "WithdrawalViewController.h"
#import "RebateDetailsViewController.h"
#import "WithdrawalTableViewController.h"
#import "CardViewController.h"
#import "CardDetailsViewController.h"
@interface RebateViewController ()
......@@ -75,6 +76,11 @@
*/
@property (nonatomic,strong) EarningsResponse *model;
/**
* 我的卡劵包
*/
@property (weak, nonatomic) IBOutlet UIView *cardBackgroundView;
@end
......@@ -99,17 +105,23 @@
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[Shoppersmanager manager].Shoppers.employee.picture] placeholderImage:ReplaceImage];
}
#pragma mark - 设置收支明细、提现进度
#pragma mark - 设置收支明细、提现进度、卡劵包
- (void)setupChildViewController
{
PaymentsViewController *payments = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"PaymentsViewController"];
[self addChildViewController:payments];
WithdrawalViewController *withdrawal = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"WithdrawalViewController"];
[self addChildViewController:withdrawal];
payments.view.frame = CGRectMake(0, 40, self.contentBackgroundView.mj_w, self.contentBackgroundView.mj_h-40);
withdrawal.view.frame = CGRectMake(0, 40, self.contentBackgroundView.mj_w, self.contentBackgroundView.mj_h-40);
[self.contentBackgroundView addSubview:payments.view];
self.currentVC = payments;
CardViewController *cardVc = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"CardViewController"];
[self addChildViewController:cardVc];
cardVc.view.frame = CGRectMake(10, 40, self.cardBackgroundView.mj_w-20, self.cardBackgroundView.mj_h-50);
[self.cardBackgroundView addSubview:cardVc.view];
}
......@@ -192,6 +204,12 @@
[self.navigationController pushViewController:rebateDetails animated:YES];
}
#pragma mark - 更多卡劵
- (IBAction)moreCardButtonClickAction:(UIButton *)sender {
CardDetailsViewController *cardDetails = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"CardDetailsViewController"];
[self.navigationController pushViewController:cardDetails animated:YES];
}
......
//
// RightControlSectionView.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RightControlSectionView : UITableViewHeaderFooterView
//** imageview */
@property (nonatomic,strong) UIImageView *sectionImageView;
//** title */
@property (nonatomic,strong) UILabel *sectionTitle;
@end
//
// RightControlSectionView.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "RightControlSectionView.h"
@implementation RightControlSectionView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
[self uiConfigAction];
}
return self;
}
- (void)uiConfigAction
{
self.sectionImageView = [[UIImageView alloc]init];
[self.contentView addSubview:self.sectionImageView];
[self.sectionImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(30);
make.centerY.mas_equalTo(self.mj_h/2);
make.size.mas_equalTo(CGSizeMake(25, 25));
}];
self.sectionTitle = [[UILabel alloc]init];
[self.contentView addSubview:self.sectionTitle];
[self.sectionTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.sectionImageView.mas_right).mas_offset(20);
make.centerY.mas_equalTo(self.mj_h/2);
make.size.mas_equalTo(CGSizeMake(100, 20));
}];
}
@end
//
// RightControlTableViewCell.h
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RightControlTableViewCell : UITableViewCell
//** title */
@property (weak, nonatomic) IBOutlet UILabel *sectionTitle;
@end
//
// RightControlTableViewCell.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "RightControlTableViewCell.h"
@implementation RightControlTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
This diff is collapsed.
......@@ -253,7 +253,7 @@
NSMutableArray *styleArray = [NSMutableArray arrayWithArray:self.filter.styles];
DataDict *style = [[DataDict alloc]init];
style.typename = @"全部";
style.typeName = @"全部";
[styleArray insertObject:style atIndex:0];
[self dismissViewControllerAnimated:NO completion:nil];
[self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:styleArray ShowButton:sender SelectedIndex:0];
......@@ -265,7 +265,7 @@
NSMutableArray *spaceArray = [NSMutableArray arrayWithArray:self.filter.space];
DataDict *space = [[DataDict alloc]init];
space.typename = @"全部";
space.typeName = @"全部";
[spaceArray insertObject:space atIndex:0];
[self dismissViewControllerAnimated:NO completion:nil];
[self ShowPopoverViewController:CGSizeMake(150, 200) Withdatas:spaceArray ShowButton:sender SelectedIndex:1];
......
......@@ -206,7 +206,7 @@
{
if ([collectionView isEqual:self.hotCollectionView]) {
[self.localSearchArray addObject:[[self.response.list objectAtIndex_opple:indexPath.item] typename]];
[self.localSearchArray addObject:[[self.response.list objectAtIndex_opple:indexPath.item] typeName]];
//调用商品控制器
ProductLibraryViewController *productVC = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"productlibrary"];
productVC.selectedCode = [[self.response.list objectAtIndex_opple:indexPath.item] typecode];
......
......@@ -18,7 +18,10 @@
*/
@property (nonatomic,strong) NSArray *goodsArray;
/**
* 促销信息
*/
@property (nonatomic,assign) NSArray *promotionalArray;
/**
* 商品总数量
......@@ -35,25 +38,21 @@
*/
@property (weak, nonatomic) IBOutlet UITextField *goodsAllPrice;
/**
* 商品总金额背景View
*/
@property (weak, nonatomic) IBOutlet UIView *goodsAllpriceBackView;
/**
* 支付方式
*/
@property (weak, nonatomic) IBOutlet UIButton *payTypeButton;
/**
* 微信支付
*/
@property (weak, nonatomic) IBOutlet UIButton *WeixiPayButton;
/**
* 支付宝支付
*/
......@@ -64,8 +63,6 @@
*/
@property (weak, nonatomic) IBOutlet UIImageView *showPayQrCodeImageView;
/**
* 是否开票
*/
......@@ -90,7 +87,6 @@
@property (weak, nonatomic) IBOutlet UIView *invoiceBackView;
/**
* 取消
*/
......
......@@ -8,6 +8,8 @@
#import "SettlementViewController.h"
#import "PayViewController.h"
#import "PromotionalDeductionModel.h"
#import "PromotionalGoodsModel.h"
@interface SettlementViewController ()<ReturnTableviewcellIndexpathdelegate,UITextFieldDelegate>
......@@ -92,6 +94,17 @@
goodsAllNumber += [model.goodsNum integerValue];
goodAllprice += [model.goodsPrice floatValue]*[model.goodsNum integerValue];
}
//** 促销金额 */
NSInteger totalNumber = 0;
for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
if (model.isSelected) {
totalNumber += model.total;
}
}
}
goodAllprice -= totalNumber;
self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",goodsAllNumber];
self.goodsAllPrice.text = [NSString stringWithFormat:@"¥%.2f",goodAllprice];
}
......@@ -100,23 +113,25 @@
#pragma mark -获取经营者支付二维码
- (void)getPayQrCode
{
WS(weakSelf);
[[NetworkRequestClassManager Manager ] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(QRCODE) WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
if ([returnValue[@"code"] isEqualToNumber:@0]) {
NSLog(@"获取二维码成功");
self.zhiFubaoLabe = returnValue[@"data"][@"zhifubao"];
self.weiXinLabe = returnValue[@"data"][@"weixin"];
weakSelf.zhiFubaoLabe = returnValue[@"data"][@"zhifubao"];
weakSelf.weiXinLabe = returnValue[@"data"][@"weixin"];
}else
{
NSLog(@"获取二维码失败");
[weakSelf ErrorMBProgressView:returnValue[@"message"]];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
} WithFailureBlock:^(id error) {
NSLog(@"%@",error);
[weakSelf ErrorMBProgressView:NETWORK];
} WithFailureBlock:^(NSError *error) {
[weakSelf ErrorMBProgressView:error.localizedDescription];
}];
}
......@@ -127,7 +142,6 @@
}
#pragma mark -取消支付
- (IBAction)CancelButtonClick:(UIButton *)sender {
......@@ -228,7 +242,6 @@
}
#pragma mark -弹出popover视图控制器
- (void)ShowPopoverViewController:(CGSize)size Withdatas:(NSArray *)datasArray ShowButton:(UIButton *)button SelectedIndex:(NSInteger)index GetTitle:(BOOL )istitle
{
......@@ -249,7 +262,6 @@
}
/**
* 选中筛选条件对象typecode
*
......@@ -292,6 +304,23 @@
order.orderNumber = _orderCode;
order.fnewstate = @"002";
order.oldstate = @"001";
//** 促销信息 */
order.realAmount = (NSDecimalNumber *)[NSDecimalNumber numberWithFloat:[[self.goodsAllPrice.text substringFromIndex:1] floatValue]];
NSMutableArray *goodsArray = [NSMutableArray array];
for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
PromotionalGoodsModel *model = (PromotionalGoodsModel *)object;
PromotionGoods *goods = [[PromotionGoods alloc]init];
UCN *goodDetails = [[UCN alloc]init];
goodDetails.code = model.goods.code;
goodDetails.uuid = model.goods.uuid;
goodDetails.name = model.goods.name;
goods.goods = goodDetails;
goods.promotionNumber = (NSDecimalNumber *)[NSDecimalNumber numberWithInteger:model.count];
[goodsArray addObject:goods];
}
}
order.promotionGoods = (NSArray<PromotionGoods> *)goodsArray;
//支付类型
if (self.payTreasureButton.selected) {
......@@ -330,22 +359,23 @@
[weakSelf RemoveMBProgressHUDLoding];
if ([returnValue[@"code"] isEqualToNumber:@0]) {
NSLog(@"支付成功");
[weakSelf ErrorMBProgressView:@"支付成功"];
if (weakSelf.PaySuccessReturnBlock) {
weakSelf.PaySuccessReturnBlock();
}
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}else{
[weakSelf ErrorMBProgressView:returnValue[@"message"]];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
} WithFailureBlock:^(id error) {
NSLog(@"支付失败");
[weakSelf CreateMBProgressHUDLoding];
[weakSelf RemoveMBProgressHUDLoding];
[weakSelf ErrorMBProgressView:NETWORK];
} WithFailureBlock:^(NSError *error) {
[weakSelf RemoveMBProgressHUDLoding];
[weakSelf ErrorMBProgressView:error.localizedDescription];
}];
}
#pragma mark -支付方式选择
- (NSString *)PayTypeSelected:(NSString *)selecte
{
......@@ -365,16 +395,6 @@
return nil;
}
//@synthesize orderNumber;
//@synthesize oldstate;
//@synthesize fnewstate;
//@synthesize payType;
//@synthesize isbill;
//@synthesize billType;
//@synthesize billTitle;
#pragma mark -汉字转码
- (NSString *)ReturnUrlString:(NSString *)ChineseString
{
......@@ -382,7 +402,6 @@
return encodedString;
}
#pragma mark -开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
......@@ -393,27 +412,16 @@
return YES;
}
#pragma mark -结束编辑
- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.myScrollView.contentOffset = CGPointMake(0, 0);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
......@@ -406,11 +406,12 @@
allPrice += model.goodsNum *[model.costPrice floatValue];
//总数量
allNumber += model.goodsNum;
orderGoods.goodsTotalPrice = [NSNumber numberWithFloat:model.goodsNum *[model.costPrice floatValue]];
orderGoods.goodsTotalPrice = (NSDecimalNumber *)[NSDecimalNumber numberWithFloat:model.goodsNum *[model.costPrice floatValue]];
[goodidArr addObject:orderGoods];
}
//总价
orderReceiver.orderPrice = [NSNumber numberWithFloat:allPrice];
orderReceiver.orderPrice = (NSDecimalNumber *)[NSDecimalNumber numberWithFloat:allPrice];
orderReceiver.oldPrice = (NSDecimalNumber *)[NSDecimalNumber numberWithFloat:allPrice];
//总数量
orderReceiver.goodsNum = [NSString stringWithFormat:@"%ld",allNumber];
order.orderdetailList = (NSArray<TOOrderdetailEntity> *)goodidArr;
......@@ -430,9 +431,9 @@
}
OrderdetailsViewController *orderDetails = [[weakSelf getStoryboardWithName] instantiateViewControllerWithIdentifier:@"orderdetails"];
orderDetails.orderCode = returnValue[@"data"];
orderDetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品清单"];
orderDetails.isShowattachment = NO;
orderDetails.isShowattachment = YES;
orderDetails.isShowPayButton = YES;
orderDetails.isUserInteractionEnabled = YES;
orderDetails.isSliding = YES;//取消滑动返回
[weakSelf.navigationController pushViewController:orderDetails animated:YES];
......
......@@ -411,12 +411,12 @@
model.goodsNum = goodsNumber;
//保存成交价格
ShopcarModel *Newmodel = [self.shopResponseArray objectAtIndex_opple:cellindex];
Newmodel.costPrice = [NSNumber numberWithFloat:costprice];
Newmodel.costPrice = (NSDecimalNumber *)[NSDecimalNumber numberWithFloat:costprice];
//在服务器保存数量、成交价
//购物车ID
NSString *carid = [[self.shopResponseArray objectAtIndex_opple:cellindex] fid];
//商品id
NSString *goodsis = [[[self.shopResponseArray objectAtIndex_opple:cellindex] goods] fid];
NSString *goodsis = [[[self.shopResponseArray objectAtIndex_opple:cellindex] goods] uuid];
//成交价
NSString *costpriceString = [NSString stringWithFormat:@"%.2f",costprice];
//商品数量
......
......@@ -131,40 +131,33 @@
#pragma mark -保存选中头像、并上传
- (void)uploadUserHeader:(UIImage *)image completeBlock:(void(^)(NSString *string))complete
{
WS(weakSelf);
NSData *data = UIImageJPEGRepresentation(image, 0.5);
[[NetworkRequestClassManager Manager] UploadImageWithURL:SERVERREQUESTURL(UPLOADHEADER) WithRequestType:1 WithImageDatas:data WithParameter:nil WithReturnValueBlock:^(id returnValue) {
if ([returnValue[@"code"] isEqualToNumber:@0]) {
[self modifyshoppersInformation:returnValue[@"data"] complete:^{
[weakSelf modifyshoppersInformation:returnValue[@"data"] complete:^{
complete(returnValue[@"data"]);
}];
}else
{
[self ErrorMBProgressView:returnValue[@"message"]];
[weakSelf ErrorMBProgressView:returnValue[@"message"]];
}
} WithprogressBlock:^(double progress) {
if (progress >= 1) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传完成";
[self RemoveMBProgressHUDLoding];
});
weakSelf.TCHud.labelText = @"上传完成";
[weakSelf RemoveMBProgressHUDLoding];
}else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self ShowProgressView:progress];
});
[weakSelf ShowProgressView:progress];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传失败";
[self RemoveMBProgressHUDLoding];
});
weakSelf.TCHud.labelText = @"上传失败";
[weakSelf RemoveMBProgressHUDLoding];
} WithFailureBlock:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传失败";
[self RemoveMBProgressHUDLoding];
});
weakSelf.TCHud.labelText = @"上传失败";
[weakSelf RemoveMBProgressHUDLoding];
}];
}
......
......@@ -65,7 +65,7 @@
}
else
{
[cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typename] forState:UIControlStateNormal];
[cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typeName] forState:UIControlStateNormal];
}
return cell;
}
......@@ -93,7 +93,7 @@
}else
{
[self.delegate selectedItem:[[self.datasArray objectAtIndex_opple:indexpath.row] typecode] withTitle:[[self.datasArray objectAtIndex_opple:indexpath.row] typename]];
[self.delegate selectedItem:[[self.datasArray objectAtIndex_opple:indexpath.row] typecode] withTitle:[[self.datasArray objectAtIndex_opple:indexpath.row] typeName]];
}
}
......
......@@ -125,7 +125,7 @@
}
else
{
[cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typename] forState:UIControlStateNormal];
[cell.titleLabe setTitle:[[self.datasArray objectAtIndex_opple:indexPath.row] typeName] forState:UIControlStateNormal];
}
return cell;
}
......@@ -217,7 +217,7 @@
}
else
{
selectedTitle = [[self.datasArray objectAtIndex_opple:indexpath.row] typename];
selectedTitle = [[self.datasArray objectAtIndex_opple:indexpath.row] typeName];
selectedTypecode = [[self.datasArray objectAtIndex_opple:indexpath.row] typecode];
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:selectedTitle,@"typename",selectedTypecode,@"typecode", nil];
......
This diff is collapsed.
......@@ -27,8 +27,6 @@
[self SetIQKeyboardManager];
[self RootViewcontroller];
[self setUMShare];
return YES;
}
......
This diff is collapsed.
......@@ -21,7 +21,6 @@ PODS:
- JSONModel (1.2.0)
- Masonry (1.0.2)
- MBProgressHUD (0.9.2)
- MJExtension (3.0.13)
- MJRefresh (3.1.12)
- MMDrawerController (0.6.0):
- MMDrawerController/Core (= 0.6.0)
......@@ -39,6 +38,7 @@ PODS:
- SDWebImage/Core (= 3.8.2)
- SDWebImage/Core (3.8.2)
- UMengSocial (5.0)
- ZYCornerRadius (1.0.1)
DEPENDENCIES:
- AFNetworking
......@@ -49,11 +49,11 @@ DEPENDENCIES:
- JSONModel (~> 1.2.0)
- Masonry
- MBProgressHUD (~> 0.9.1)
- MJExtension
- MJRefresh
- MMDrawerController
- SDWebImage
- UMengSocial
- ZYCornerRadius (~> 1.0.1)
SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
......@@ -64,10 +64,10 @@ SPEC CHECKSUMS:
JSONModel: 12523685c4b623553ccf844bbbf7007624317b2c
Masonry: 7c429b56da9d4ee0bbb3ed77a5ea710d6a5df39e
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
MJExtension: 5932755f451458eefa24239358817f8d291240c7
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
MMDrawerController: e3a54a5570388463ad3b36975251575b50c4e1a0
SDWebImage: 098e97e6176540799c27e804c96653ee0833d13c
UMengSocial: 48b67179c492a8cf7803fbb0438b8f55432e2fc1
ZYCornerRadius: 94720e8722acf30de5b73ae185ffe56a2240f6a3
COCOAPODS: 0.39.0
../../../MJExtension/MJExtension/MJExtension.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJExtensionConst.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJFoundation.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJProperty.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJPropertyKey.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJPropertyType.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJClass.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJCoding.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJKeyValue.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJProperty.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSString+MJExtension.h
\ No newline at end of file
../../../ZYCornerRadius/ZYCornerRadius/CornerRadiusCategory/UIImageView+CornerRadius.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJExtension.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJExtensionConst.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJFoundation.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJProperty.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJPropertyKey.h
\ No newline at end of file
../../../MJExtension/MJExtension/MJPropertyType.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJClass.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJCoding.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJKeyValue.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSObject+MJProperty.h
\ No newline at end of file
../../../MJExtension/MJExtension/NSString+MJExtension.h
\ No newline at end of file
../../../ZYCornerRadius/ZYCornerRadius/CornerRadiusCategory/UIImageView+CornerRadius.h
\ No newline at end of file
Copyright (c) 2013-2015 MJExtension (https://github.com/CoderMJLee/MJExtension)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
//
// MJExtension.h
// MJExtension
//
// Created by mj on 14-1-15.
// Copyright (c) 2014年 小码哥. All rights reserved.
// 代码地址:https://github.com/CoderMJLee/MJExtension
// 代码地址:http://code4app.com/ios/%E5%AD%97%E5%85%B8-JSON-%E4%B8%8E%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%BD%AC%E6%8D%A2/5339992a933bf062608b4c57
#import "NSObject+MJCoding.h"
#import "NSObject+MJProperty.h"
#import "NSObject+MJClass.h"
#import "NSObject+MJKeyValue.h"
#import "NSString+MJExtension.h"
#import "MJExtensionConst.h"
\ No newline at end of file
#ifndef __MJExtensionConst__H__
#define __MJExtensionConst__H__
#import <Foundation/Foundation.h>
// 过期
#define MJExtensionDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)
// 构建错误
#define MJExtensionBuildError(clazz, msg) \
NSError *error = [NSError errorWithDomain:msg code:250 userInfo:nil]; \
[clazz setMj_error:error];
// 日志输出
#ifdef DEBUG
#define MJExtensionLog(...) NSLog(__VA_ARGS__)
#else
#define MJExtensionLog(...)
#endif
/**
* 断言
* @param condition 条件
* @param returnValue 返回值
*/
#define MJExtensionAssertError(condition, returnValue, clazz, msg) \
[clazz setMj_error:nil]; \
if ((condition) == NO) { \
MJExtensionBuildError(clazz, msg); \
return returnValue;\
}
#define MJExtensionAssert2(condition, returnValue) \
if ((condition) == NO) return returnValue;
/**
* 断言
* @param condition 条件
*/
#define MJExtensionAssert(condition) MJExtensionAssert2(condition, )
/**
* 断言
* @param param 参数
* @param returnValue 返回值
*/
#define MJExtensionAssertParamNotNil2(param, returnValue) \
MJExtensionAssert2((param) != nil, returnValue)
/**
* 断言
* @param param 参数
*/
#define MJExtensionAssertParamNotNil(param) MJExtensionAssertParamNotNil2(param, )
/**
* 打印所有的属性
*/
#define MJLogAllIvars \
-(NSString *)description \
{ \
return [self mj_keyValues].description; \
}
#define MJExtensionLogAllProperties MJLogAllIvars
/**
* 类型(属性类型)
*/
extern NSString *const MJPropertyTypeInt;
extern NSString *const MJPropertyTypeShort;
extern NSString *const MJPropertyTypeFloat;
extern NSString *const MJPropertyTypeDouble;
extern NSString *const MJPropertyTypeLong;
extern NSString *const MJPropertyTypeLongLong;
extern NSString *const MJPropertyTypeChar;
extern NSString *const MJPropertyTypeBOOL1;
extern NSString *const MJPropertyTypeBOOL2;
extern NSString *const MJPropertyTypePointer;
extern NSString *const MJPropertyTypeIvar;
extern NSString *const MJPropertyTypeMethod;
extern NSString *const MJPropertyTypeBlock;
extern NSString *const MJPropertyTypeClass;
extern NSString *const MJPropertyTypeSEL;
extern NSString *const MJPropertyTypeId;
#endif
\ No newline at end of file
#ifndef __MJExtensionConst__M__
#define __MJExtensionConst__M__
#import <Foundation/Foundation.h>
/**
* 成员变量类型(属性类型)
*/
NSString *const MJPropertyTypeInt = @"i";
NSString *const MJPropertyTypeShort = @"s";
NSString *const MJPropertyTypeFloat = @"f";
NSString *const MJPropertyTypeDouble = @"d";
NSString *const MJPropertyTypeLong = @"l";
NSString *const MJPropertyTypeLongLong = @"q";
NSString *const MJPropertyTypeChar = @"c";
NSString *const MJPropertyTypeBOOL1 = @"c";
NSString *const MJPropertyTypeBOOL2 = @"b";
NSString *const MJPropertyTypePointer = @"*";
NSString *const MJPropertyTypeIvar = @"^{objc_ivar=}";
NSString *const MJPropertyTypeMethod = @"^{objc_method=}";
NSString *const MJPropertyTypeBlock = @"@?";
NSString *const MJPropertyTypeClass = @"#";
NSString *const MJPropertyTypeSEL = @":";
NSString *const MJPropertyTypeId = @"@";
#endif
\ No newline at end of file
//
// MJFoundation.h
// MJExtensionExample
//
// Created by MJ Lee on 14/7/16.
// Copyright (c) 2014年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MJFoundation : NSObject
+ (BOOL)isClassFromFoundation:(Class)c;
@end
//
// MJFoundation.m
// MJExtensionExample
//
// Created by MJ Lee on 14/7/16.
// Copyright (c) 2014年 小码哥. All rights reserved.
//
#import "MJFoundation.h"
#import "MJExtensionConst.h"
#import <CoreData/CoreData.h>
static NSSet *foundationClasses_;
@implementation MJFoundation
+ (NSSet *)foundationClasses
{
if (foundationClasses_ == nil) {
// 集合中没有NSObject,因为几乎所有的类都是继承自NSObject,具体是不是NSObject需要特殊判断
foundationClasses_ = [NSSet setWithObjects:
[NSURL class],
[NSDate class],
[NSValue class],
[NSData class],
[NSError class],
[NSArray class],
[NSDictionary class],
[NSString class],
[NSAttributedString class], nil];
}
return foundationClasses_;
}
+ (BOOL)isClassFromFoundation:(Class)c
{
if (c == [NSObject class] || c == [NSManagedObject class]) return YES;
__block BOOL result = NO;
[[self foundationClasses] enumerateObjectsUsingBlock:^(Class foundationClass, BOOL *stop) {
if ([c isSubclassOfClass:foundationClass]) {
result = YES;
*stop = YES;
}
}];
return result;
}
@end
//
// MJProperty.h
// MJExtensionExample
//
// Created by MJ Lee on 15/4/17.
// Copyright (c) 2015年 小码哥. All rights reserved.
// 包装一个成员属性
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import "MJPropertyType.h"
#import "MJPropertyKey.h"
/**
* 包装一个成员
*/
@interface MJProperty : NSObject
/** 成员属性 */
@property (nonatomic, assign) objc_property_t property;
/** 成员属性的名字 */
@property (nonatomic, readonly) NSString *name;
/** 成员属性的类型 */
@property (nonatomic, readonly) MJPropertyType *type;
/** 成员属性来源于哪个类(可能是父类) */
@property (nonatomic, assign) Class srcClass;
/**** 同一个成员属性 - 父类和子类的行为可能不一致(originKey、propertyKeys、objectClassInArray) ****/
/** 设置最原始的key */
- (void)setOriginKey:(id)originKey forClass:(Class)c;
/** 对应着字典中的多级key(里面存放的数组,数组里面都是MJPropertyKey对象) */
- (NSArray *)propertyKeysForClass:(Class)c;
/** 模型数组中的模型类型 */
- (void)setObjectClassInArray:(Class)objectClass forClass:(Class)c;
- (Class)objectClassInArrayForClass:(Class)c;
/**** 同一个成员变量 - 父类和子类的行为可能不一致(key、keys、objectClassInArray) ****/
/**
* 设置object的成员变量值
*/
- (void)setValue:(id)value forObject:(id)object;
/**
* 得到object的成员属性值
*/
- (id)valueForObject:(id)object;
/**
* 初始化
*/
+ (instancetype)cachedPropertyWithProperty:(objc_property_t)property;
@end
//
// MJProperty.m
// MJExtensionExample
//
// Created by MJ Lee on 15/4/17.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import "MJProperty.h"
#import "MJFoundation.h"
#import "MJExtensionConst.h"
#import <objc/message.h>
@interface MJProperty()
@property (strong, nonatomic) NSMutableDictionary *propertyKeysDict;
@property (strong, nonatomic) NSMutableDictionary *objectClassInArrayDict;
@end
@implementation MJProperty
#pragma mark - 初始化
- (instancetype)init
{
if (self = [super init]) {
_propertyKeysDict = [NSMutableDictionary dictionary];
_objectClassInArrayDict = [NSMutableDictionary dictionary];
}
return self;
}
#pragma mark - 缓存
+ (instancetype)cachedPropertyWithProperty:(objc_property_t)property
{
MJProperty *propertyObj = objc_getAssociatedObject(self, property);
if (propertyObj == nil) {
propertyObj = [[self alloc] init];
propertyObj.property = property;
objc_setAssociatedObject(self, property, propertyObj, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return propertyObj;
}
#pragma mark - 公共方法
- (void)setProperty:(objc_property_t)property
{
_property = property;
MJExtensionAssertParamNotNil(property);
// 1.属性名
_name = @(property_getName(property));
// 2.成员类型
NSString *attrs = @(property_getAttributes(property));
NSUInteger dotLoc = [attrs rangeOfString:@","].location;
NSString *code = nil;
NSUInteger loc = 1;
if (dotLoc == NSNotFound) { // 没有,
code = [attrs substringFromIndex:loc];
} else {
code = [attrs substringWithRange:NSMakeRange(loc, dotLoc - loc)];
}
_type = [MJPropertyType cachedTypeWithCode:code];
}
/**
* 获得成员变量的值
*/
- (id)valueForObject:(id)object
{
if (self.type.KVCDisabled) return [NSNull null];
return [object valueForKey:self.name];
}
/**
* 设置成员变量的值
*/
- (void)setValue:(id)value forObject:(id)object
{
if (self.type.KVCDisabled || value == nil) return;
[object setValue:value forKey:self.name];
}
/**
* 通过字符串key创建对应的keys
*/
- (NSArray *)propertyKeysWithStringKey:(NSString *)stringKey
{
if (stringKey.length == 0) return nil;
NSMutableArray *propertyKeys = [NSMutableArray array];
// 如果有多级映射
NSArray *oldKeys = [stringKey componentsSeparatedByString:@"."];
for (NSString *oldKey in oldKeys) {
NSUInteger start = [oldKey rangeOfString:@"["].location;
if (start != NSNotFound) { // 有索引的key
NSString *prefixKey = [oldKey substringToIndex:start];
NSString *indexKey = prefixKey;
if (prefixKey.length) {
MJPropertyKey *propertyKey = [[MJPropertyKey alloc] init];
propertyKey.name = prefixKey;
[propertyKeys addObject:propertyKey];
indexKey = [oldKey stringByReplacingOccurrencesOfString:prefixKey withString:@""];
}
/** 解析索引 **/
// 元素
NSArray *cmps = [[indexKey stringByReplacingOccurrencesOfString:@"[" withString:@""] componentsSeparatedByString:@"]"];
for (NSInteger i = 0; i<cmps.count - 1; i++) {
MJPropertyKey *subPropertyKey = [[MJPropertyKey alloc] init];
subPropertyKey.type = MJPropertyKeyTypeArray;
subPropertyKey.name = cmps[i];
[propertyKeys addObject:subPropertyKey];
}
} else { // 没有索引的key
MJPropertyKey *propertyKey = [[MJPropertyKey alloc] init];
propertyKey.name = oldKey;
[propertyKeys addObject:propertyKey];
}
}
return propertyKeys;
}
/** 对应着字典中的key */
- (void)setOriginKey:(id)originKey forClass:(Class)c
{
if ([originKey isKindOfClass:[NSString class]]) { // 字符串类型的key
NSArray *propertyKeys = [self propertyKeysWithStringKey:originKey];
if (propertyKeys.count) {
[self setPorpertyKeys:@[propertyKeys] forClass:c];
}
} else if ([originKey isKindOfClass:[NSArray class]]) {
NSMutableArray *keyses = [NSMutableArray array];
for (NSString *stringKey in originKey) {
NSArray *propertyKeys = [self propertyKeysWithStringKey:stringKey];
if (propertyKeys.count) {
[keyses addObject:propertyKeys];
}
}
if (keyses.count) {
[self setPorpertyKeys:keyses forClass:c];
}
}
}
/** 对应着字典中的多级key */
- (void)setPorpertyKeys:(NSArray *)propertyKeys forClass:(Class)c
{
if (propertyKeys.count == 0) return;
self.propertyKeysDict[NSStringFromClass(c)] = propertyKeys;
}
- (NSArray *)propertyKeysForClass:(Class)c
{
return self.propertyKeysDict[NSStringFromClass(c)];
}
/** 模型数组中的模型类型 */
- (void)setObjectClassInArray:(Class)objectClass forClass:(Class)c
{
if (!objectClass) return;
self.objectClassInArrayDict[NSStringFromClass(c)] = objectClass;
}
- (Class)objectClassInArrayForClass:(Class)c
{
return self.objectClassInArrayDict[NSStringFromClass(c)];
}
@end
//
// MJPropertyKey.h
// MJExtensionExample
//
// Created by MJ Lee on 15/8/11.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef enum {
MJPropertyKeyTypeDictionary = 0, // 字典的key
MJPropertyKeyTypeArray // 数组的key
} MJPropertyKeyType;
/**
* 属性的key
*/
@interface MJPropertyKey : NSObject
/** key的名字 */
@property (copy, nonatomic) NSString *name;
/** key的种类,可能是@"10",可能是@"age" */
@property (assign, nonatomic) MJPropertyKeyType type;
/**
* 根据当前的key,也就是name,从object(字典或者数组)中取值
*/
- (id)valueInObject:(id)object;
@end
//
// MJPropertyKey.m
// MJExtensionExample
//
// Created by MJ Lee on 15/8/11.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import "MJPropertyKey.h"
@implementation MJPropertyKey
- (id)valueInObject:(id)object
{
if ([object isKindOfClass:[NSDictionary class]] && self.type == MJPropertyKeyTypeDictionary) {
return object[self.name];
} else if ([object isKindOfClass:[NSArray class]] && self.type == MJPropertyKeyTypeArray) {
NSArray *array = object;
NSUInteger index = self.name.intValue;
if (index < array.count) return array[index];
return nil;
}
return nil;
}
@end
//
// MJPropertyType.h
// MJExtension
//
// Created by mj on 14-1-15.
// Copyright (c) 2014年 小码哥. All rights reserved.
// 包装一种类型
#import <Foundation/Foundation.h>
/**
* 包装一种类型
*/
@interface MJPropertyType : NSObject
/** 类型标识符 */
@property (nonatomic, copy) NSString *code;
/** 是否为id类型 */
@property (nonatomic, readonly, getter=isIdType) BOOL idType;
/** 是否为基本数字类型:int、float等 */
@property (nonatomic, readonly, getter=isNumberType) BOOL numberType;
/** 是否为BOOL类型 */
@property (nonatomic, readonly, getter=isBoolType) BOOL boolType;
/** 对象类型(如果是基本数据类型,此值为nil) */
@property (nonatomic, readonly) Class typeClass;
/** 类型是否来自于Foundation框架,比如NSString、NSArray */
@property (nonatomic, readonly, getter = isFromFoundation) BOOL fromFoundation;
/** 类型是否不支持KVC */
@property (nonatomic, readonly, getter = isKVCDisabled) BOOL KVCDisabled;
/**
* 获得缓存的类型对象
*/
+ (instancetype)cachedTypeWithCode:(NSString *)code;
@end
\ No newline at end of file
//
// MJPropertyType.m
// MJExtension
//
// Created by mj on 14-1-15.
// Copyright (c) 2014年 小码哥. All rights reserved.
//
#import "MJPropertyType.h"
#import "MJExtension.h"
#import "MJFoundation.h"
#import "MJExtensionConst.h"
@implementation MJPropertyType
static NSMutableDictionary *types_;
+ (void)initialize
{
types_ = [NSMutableDictionary dictionary];
}
+ (instancetype)cachedTypeWithCode:(NSString *)code
{
MJExtensionAssertParamNotNil2(code, nil);
@synchronized (self) {
MJPropertyType *type = types_[code];
if (type == nil) {
type = [[self alloc] init];
type.code = code;
types_[code] = type;
}
return type;
}
}
#pragma mark - 公共方法
- (void)setCode:(NSString *)code
{
_code = code;
MJExtensionAssertParamNotNil(code);
if ([code isEqualToString:MJPropertyTypeId]) {
_idType = YES;
} else if (code.length == 0) {
_KVCDisabled = YES;
} else if (code.length > 3 && [code hasPrefix:@"@\""]) {
// 去掉@"和",截取中间的类型名称
_code = [code substringWithRange:NSMakeRange(2, code.length - 3)];
_typeClass = NSClassFromString(_code);
_fromFoundation = [MJFoundation isClassFromFoundation:_typeClass];
_numberType = [_typeClass isSubclassOfClass:[NSNumber class]];
} else if ([code isEqualToString:MJPropertyTypeSEL] ||
[code isEqualToString:MJPropertyTypeIvar] ||
[code isEqualToString:MJPropertyTypeMethod]) {
_KVCDisabled = YES;
}
// 是否为数字类型
NSString *lowerCode = _code.lowercaseString;
NSArray *numberTypes = @[MJPropertyTypeInt, MJPropertyTypeShort, MJPropertyTypeBOOL1, MJPropertyTypeBOOL2, MJPropertyTypeFloat, MJPropertyTypeDouble, MJPropertyTypeLong, MJPropertyTypeLongLong, MJPropertyTypeChar];
if ([numberTypes containsObject:lowerCode]) {
_numberType = YES;
if ([lowerCode isEqualToString:MJPropertyTypeBOOL1]
|| [lowerCode isEqualToString:MJPropertyTypeBOOL2]) {
_boolType = YES;
}
}
}
@end
//
// NSObject+MJClass.h
// MJExtensionExample
//
// Created by MJ Lee on 15/8/11.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
* 遍历所有类的block(父类)
*/
typedef void (^MJClassesEnumeration)(Class c, BOOL *stop);
/** 这个数组中的属性名才会进行字典和模型的转换 */
typedef NSArray * (^MJAllowedPropertyNames)();
/** 这个数组中的属性名才会进行归档 */
typedef NSArray * (^MJAllowedCodingPropertyNames)();
/** 这个数组中的属性名将会被忽略:不进行字典和模型的转换 */
typedef NSArray * (^MJIgnoredPropertyNames)();
/** 这个数组中的属性名将会被忽略:不进行归档 */
typedef NSArray * (^MJIgnoredCodingPropertyNames)();
/**
* 类相关的扩展
*/
@interface NSObject (MJClass)
/**
* 遍历所有的类
*/
+ (void)mj_enumerateClasses:(MJClassesEnumeration)enumeration;
+ (void)mj_enumerateAllClasses:(MJClassesEnumeration)enumeration;
#pragma mark - 属性白名单配置
/**
* 这个数组中的属性名才会进行字典和模型的转换
*
* @param allowedPropertyNames 这个数组中的属性名才会进行字典和模型的转换
*/
+ (void)mj_setupAllowedPropertyNames:(MJAllowedPropertyNames)allowedPropertyNames;
/**
* 这个数组中的属性名才会进行字典和模型的转换
*/
+ (NSMutableArray *)mj_totalAllowedPropertyNames;
#pragma mark - 属性黑名单配置
/**
* 这个数组中的属性名将会被忽略:不进行字典和模型的转换
*
* @param ignoredPropertyNames 这个数组中的属性名将会被忽略:不进行字典和模型的转换
*/
+ (void)mj_setupIgnoredPropertyNames:(MJIgnoredPropertyNames)ignoredPropertyNames;
/**
* 这个数组中的属性名将会被忽略:不进行字典和模型的转换
*/
+ (NSMutableArray *)mj_totalIgnoredPropertyNames;
#pragma mark - 归档属性白名单配置
/**
* 这个数组中的属性名才会进行归档
*
* @param allowedCodingPropertyNames 这个数组中的属性名才会进行归档
*/
+ (void)mj_setupAllowedCodingPropertyNames:(MJAllowedCodingPropertyNames)allowedCodingPropertyNames;
/**
* 这个数组中的属性名才会进行字典和模型的转换
*/
+ (NSMutableArray *)mj_totalAllowedCodingPropertyNames;
#pragma mark - 归档属性黑名单配置
/**
* 这个数组中的属性名将会被忽略:不进行归档
*
* @param ignoredCodingPropertyNames 这个数组中的属性名将会被忽略:不进行归档
*/
+ (void)mj_setupIgnoredCodingPropertyNames:(MJIgnoredCodingPropertyNames)ignoredCodingPropertyNames;
/**
* 这个数组中的属性名将会被忽略:不进行归档
*/
+ (NSMutableArray *)mj_totalIgnoredCodingPropertyNames;
#pragma mark - 内部使用
+ (void)mj_setupBlockReturnValue:(id (^)())block key:(const char *)key;
@end
//
// NSObject+MJClass.m
// MJExtensionExample
//
// Created by MJ Lee on 15/8/11.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import "NSObject+MJClass.h"
#import "NSObject+MJCoding.h"
#import "NSObject+MJKeyValue.h"
#import "MJFoundation.h"
#import <objc/runtime.h>
static const char MJAllowedPropertyNamesKey = '\0';
static const char MJIgnoredPropertyNamesKey = '\0';
static const char MJAllowedCodingPropertyNamesKey = '\0';
static const char MJIgnoredCodingPropertyNamesKey = '\0';
static NSMutableDictionary *allowedPropertyNamesDict_;
static NSMutableDictionary *ignoredPropertyNamesDict_;
static NSMutableDictionary *allowedCodingPropertyNamesDict_;
static NSMutableDictionary *ignoredCodingPropertyNamesDict_;
@implementation NSObject (MJClass)
+ (void)load
{
allowedPropertyNamesDict_ = [NSMutableDictionary dictionary];
ignoredPropertyNamesDict_ = [NSMutableDictionary dictionary];
allowedCodingPropertyNamesDict_ = [NSMutableDictionary dictionary];
ignoredCodingPropertyNamesDict_ = [NSMutableDictionary dictionary];
}
+ (NSMutableDictionary *)dictForKey:(const void *)key
{
@synchronized (self) {
if (key == &MJAllowedPropertyNamesKey) return allowedPropertyNamesDict_;
if (key == &MJIgnoredPropertyNamesKey) return ignoredPropertyNamesDict_;
if (key == &MJAllowedCodingPropertyNamesKey) return allowedCodingPropertyNamesDict_;
if (key == &MJIgnoredCodingPropertyNamesKey) return ignoredCodingPropertyNamesDict_;
return nil;
}
}
+ (void)mj_enumerateClasses:(MJClassesEnumeration)enumeration
{
// 1.没有block就直接返回
if (enumeration == nil) return;
// 2.停止遍历的标记
BOOL stop = NO;
// 3.当前正在遍历的类
Class c = self;
// 4.开始遍历每一个类
while (c && !stop) {
// 4.1.执行操作
enumeration(c, &stop);
// 4.2.获得父类
c = class_getSuperclass(c);
if ([MJFoundation isClassFromFoundation:c]) break;
}
}
+ (void)mj_enumerateAllClasses:(MJClassesEnumeration)enumeration
{
// 1.没有block就直接返回
if (enumeration == nil) return;
// 2.停止遍历的标记
BOOL stop = NO;
// 3.当前正在遍历的类
Class c = self;
// 4.开始遍历每一个类
while (c && !stop) {
// 4.1.执行操作
enumeration(c, &stop);
// 4.2.获得父类
c = class_getSuperclass(c);
}
}
#pragma mark - 属性黑名单配置
+ (void)mj_setupIgnoredPropertyNames:(MJIgnoredPropertyNames)ignoredPropertyNames
{
[self mj_setupBlockReturnValue:ignoredPropertyNames key:&MJIgnoredPropertyNamesKey];
}
+ (NSMutableArray *)mj_totalIgnoredPropertyNames
{
return [self mj_totalObjectsWithSelector:@selector(mj_ignoredPropertyNames) key:&MJIgnoredPropertyNamesKey];
}
#pragma mark - 归档属性黑名单配置
+ (void)mj_setupIgnoredCodingPropertyNames:(MJIgnoredCodingPropertyNames)ignoredCodingPropertyNames
{
[self mj_setupBlockReturnValue:ignoredCodingPropertyNames key:&MJIgnoredCodingPropertyNamesKey];
}
+ (NSMutableArray *)mj_totalIgnoredCodingPropertyNames
{
return [self mj_totalObjectsWithSelector:@selector(mj_ignoredCodingPropertyNames) key:&MJIgnoredCodingPropertyNamesKey];
}
#pragma mark - 属性白名单配置
+ (void)mj_setupAllowedPropertyNames:(MJAllowedPropertyNames)allowedPropertyNames;
{
[self mj_setupBlockReturnValue:allowedPropertyNames key:&MJAllowedPropertyNamesKey];
}
+ (NSMutableArray *)mj_totalAllowedPropertyNames
{
return [self mj_totalObjectsWithSelector:@selector(mj_allowedPropertyNames) key:&MJAllowedPropertyNamesKey];
}
#pragma mark - 归档属性白名单配置
+ (void)mj_setupAllowedCodingPropertyNames:(MJAllowedCodingPropertyNames)allowedCodingPropertyNames
{
[self mj_setupBlockReturnValue:allowedCodingPropertyNames key:&MJAllowedCodingPropertyNamesKey];
}
+ (NSMutableArray *)mj_totalAllowedCodingPropertyNames
{
return [self mj_totalObjectsWithSelector:@selector(mj_allowedCodingPropertyNames) key:&MJAllowedCodingPropertyNamesKey];
}
#pragma mark - block和方法处理:存储block的返回值
+ (void)mj_setupBlockReturnValue:(id (^)())block key:(const char *)key
{
if (block) {
objc_setAssociatedObject(self, key, block(), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} else {
objc_setAssociatedObject(self, key, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
// 清空数据
[[self dictForKey:key] removeAllObjects];
}
+ (NSMutableArray *)mj_totalObjectsWithSelector:(SEL)selector key:(const char *)key
{
NSMutableArray *array = [self dictForKey:key][NSStringFromClass(self)];
if (array) return array;
// 创建、存储
[self dictForKey:key][NSStringFromClass(self)] = array = [NSMutableArray array];
if ([self respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
NSArray *subArray = [self performSelector:selector];
#pragma clang diagnostic pop
if (subArray) {
[array addObjectsFromArray:subArray];
}
}
[self mj_enumerateAllClasses:^(__unsafe_unretained Class c, BOOL *stop) {
NSArray *subArray = objc_getAssociatedObject(c, key);
[array addObjectsFromArray:subArray];
}];
return array;
}
@end
//
// NSObject+MJCoding.h
// MJExtension
//
// Created by mj on 14-1-15.
// Copyright (c) 2014年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MJExtensionConst.h"
/**
* Codeing协议
*/
@protocol MJCoding <NSObject>
@optional
/**
* 这个数组中的属性名才会进行归档
*/
+ (NSArray *)mj_allowedCodingPropertyNames;
/**
* 这个数组中的属性名将会被忽略:不进行归档
*/
+ (NSArray *)mj_ignoredCodingPropertyNames;
@end
@interface NSObject (MJCoding) <MJCoding>
/**
* 解码(从文件中解析对象)
*/
- (void)mj_decode:(NSCoder *)decoder;
/**
* 编码(将对象写入文件中)
*/
- (void)mj_encode:(NSCoder *)encoder;
@end
/**
归档的实现
*/
#define MJCodingImplementation \
- (id)initWithCoder:(NSCoder *)decoder \
{ \
if (self = [super init]) { \
[self mj_decode:decoder]; \
} \
return self; \
} \
\
- (void)encodeWithCoder:(NSCoder *)encoder \
{ \
[self mj_encode:encoder]; \
}
#define MJExtensionCodingImplementation MJCodingImplementation
\ No newline at end of file
//
// NSObject+MJCoding.m
// MJExtension
//
// Created by mj on 14-1-15.
// Copyright (c) 2014年 小码哥. All rights reserved.
//
#import "NSObject+MJCoding.h"
#import "NSObject+MJClass.h"
#import "NSObject+MJProperty.h"
#import "MJProperty.h"
@implementation NSObject (MJCoding)
- (void)mj_encode:(NSCoder *)encoder
{
Class clazz = [self class];
NSArray *allowedCodingPropertyNames = [clazz mj_totalAllowedCodingPropertyNames];
NSArray *ignoredCodingPropertyNames = [clazz mj_totalIgnoredCodingPropertyNames];
[clazz mj_enumerateProperties:^(MJProperty *property, BOOL *stop) {
// 检测是否被忽略
if (allowedCodingPropertyNames.count && ![allowedCodingPropertyNames containsObject:property.name]) return;
if ([ignoredCodingPropertyNames containsObject:property.name]) return;
id value = [property valueForObject:self];
if (value == nil) return;
[encoder encodeObject:value forKey:property.name];
}];
}
- (void)mj_decode:(NSCoder *)decoder
{
Class clazz = [self class];
NSArray *allowedCodingPropertyNames = [clazz mj_totalAllowedCodingPropertyNames];
NSArray *ignoredCodingPropertyNames = [clazz mj_totalIgnoredCodingPropertyNames];
[clazz mj_enumerateProperties:^(MJProperty *property, BOOL *stop) {
// 检测是否被忽略
if (allowedCodingPropertyNames.count && ![allowedCodingPropertyNames containsObject:property.name]) return;
if ([ignoredCodingPropertyNames containsObject:property.name]) return;
id value = [decoder decodeObjectForKey:property.name];
if (value == nil) { // 兼容以前的MJExtension版本
value = [decoder decodeObjectForKey:[@"_" stringByAppendingString:property.name]];
}
if (value == nil) return;
[property setValue:value forObject:self];
}];
}
@end
This diff is collapsed.
This diff is collapsed.
//
// NSObject+MJProperty.h
// MJExtensionExample
//
// Created by MJ Lee on 15/4/17.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MJExtensionConst.h"
@class MJProperty;
/**
* 遍历成员变量用的block
*
* @param property 成员的包装对象
* @param stop YES代表停止遍历,NO代表继续遍历
*/
typedef void (^MJPropertiesEnumeration)(MJProperty *property, BOOL *stop);
/** 将属性名换为其他key去字典中取值 */
typedef NSDictionary * (^MJReplacedKeyFromPropertyName)();
typedef id (^MJReplacedKeyFromPropertyName121)(NSString *propertyName);
/** 数组中需要转换的模型类 */
typedef NSDictionary * (^MJObjectClassInArray)();
/** 用于过滤字典中的值 */
typedef id (^MJNewValueFromOldValue)(id object, id oldValue, MJProperty *property);
/**
* 成员属性相关的扩展
*/
@interface NSObject (MJProperty)
#pragma mark - 遍历
/**
* 遍历所有的成员
*/
+ (void)mj_enumerateProperties:(MJPropertiesEnumeration)enumeration;
#pragma mark - 新值配置
/**
* 用于过滤字典中的值
*
* @param newValueFormOldValue 用于过滤字典中的值
*/
+ (void)mj_setupNewValueFromOldValue:(MJNewValueFromOldValue)newValueFormOldValue;
+ (id)mj_getNewValueFromObject:(__unsafe_unretained id)object oldValue:(__unsafe_unretained id)oldValue property:(__unsafe_unretained MJProperty *)property;
#pragma mark - key配置
/**
* 将属性名换为其他key去字典中取值
*
* @param replacedKeyFromPropertyName 将属性名换为其他key去字典中取值
*/
+ (void)mj_setupReplacedKeyFromPropertyName:(MJReplacedKeyFromPropertyName)replacedKeyFromPropertyName;
/**
* 将属性名换为其他key去字典中取值
*
* @param replacedKeyFromPropertyName121 将属性名换为其他key去字典中取值
*/
+ (void)mj_setupReplacedKeyFromPropertyName121:(MJReplacedKeyFromPropertyName121)replacedKeyFromPropertyName121;
#pragma mark - array model class配置
/**
* 数组中需要转换的模型类
*
* @param objectClassInArray 数组中需要转换的模型类
*/
+ (void)mj_setupObjectClassInArray:(MJObjectClassInArray)objectClassInArray;
@end
@interface NSObject (MJPropertyDeprecated_v_2_5_16)
+ (void)enumerateProperties:(MJPropertiesEnumeration)enumeration MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
+ (void)setupNewValueFromOldValue:(MJNewValueFromOldValue)newValueFormOldValue MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
+ (id)getNewValueFromObject:(__unsafe_unretained id)object oldValue:(__unsafe_unretained id)oldValue property:(__unsafe_unretained MJProperty *)property MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
+ (void)setupReplacedKeyFromPropertyName:(MJReplacedKeyFromPropertyName)replacedKeyFromPropertyName MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
+ (void)setupReplacedKeyFromPropertyName121:(MJReplacedKeyFromPropertyName121)replacedKeyFromPropertyName121 MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
+ (void)setupObjectClassInArray:(MJObjectClassInArray)objectClassInArray MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
@end
\ No newline at end of file
This diff is collapsed.
//
// NSString+MJExtension.h
// MJExtensionExample
//
// Created by MJ Lee on 15/6/7.
// Copyright (c) 2015年 小码哥. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MJExtensionConst.h"
@interface NSString (MJExtension)
/**
* 驼峰转下划线(loveYou -> love_you)
*/
- (NSString *)mj_underlineFromCamel;
/**
* 下划线转驼峰(love_you -> loveYou)
*/
- (NSString *)mj_camelFromUnderline;
/**
* 首字母变大写
*/
- (NSString *)mj_firstCharUpper;
/**
* 首字母变小写
*/
- (NSString *)mj_firstCharLower;
- (BOOL)mj_isPureInt;
- (NSURL *)mj_url;
@end
@interface NSString (MJExtensionDeprecated_v_2_5_16)
- (NSString *)underlineFromCamel MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
- (NSString *)camelFromUnderline MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
- (NSString *)firstCharUpper MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
- (NSString *)firstCharLower MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
- (BOOL)isPureInt MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
- (NSURL *)url MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***");
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment