Commit f69d1d50 authored by Sandy's avatar Sandy

添加商品模块完成

parent 6cf9cecc
This diff is collapsed.
//
// JavenHotTagsModel.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@class JavenCategory, JavenLastModifyInfo, JavenCreateInfo;
@interface JavenHotTagsModel : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) NSString *domain;
@property (nonatomic, strong) JavenCategory *category;
@property (nonatomic, strong) JavenLastModifyInfo *lastModifyInfo;
@property (nonatomic, assign) double order;
@property (nonatomic, strong) NSString *uuid;
@property (nonatomic, strong) JavenCreateInfo *createInfo;
@property (nonatomic, assign) double version;
@property (nonatomic, assign) id internalBaseClassDescription;
@property (nonatomic, strong) NSString *name;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// JavenHotTagsModel.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "JavenHotTagsModel.h"
#import "JavenCategory.h"
#import "JavenLastModifyInfo.h"
#import "JavenCreateInfo.h"
NSString *const kJavenHotTagsModelDomain = @"domain";
NSString *const kJavenHotTagsModelCategory = @"category";
NSString *const kJavenHotTagsModelLastModifyInfo = @"lastModifyInfo";
NSString *const kJavenHotTagsModelOrder = @"order";
NSString *const kJavenHotTagsModelUuid = @"uuid";
NSString *const kJavenHotTagsModelCreateInfo = @"createInfo";
NSString *const kJavenHotTagsModelVersion = @"version";
NSString *const kJavenHotTagsModelDescription = @"description";
NSString *const kJavenHotTagsModelName = @"name";
@interface JavenHotTagsModel ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation JavenHotTagsModel
@synthesize domain = _domain;
@synthesize category = _category;
@synthesize lastModifyInfo = _lastModifyInfo;
@synthesize order = _order;
@synthesize uuid = _uuid;
@synthesize createInfo = _createInfo;
@synthesize version = _version;
@synthesize internalBaseClassDescription = _internalBaseClassDescription;
@synthesize name = _name;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.domain = [self objectOrNilForKey:kJavenHotTagsModelDomain fromDictionary:dict];
self.category = [JavenCategory modelObjectWithDictionary:[dict objectForKey:kJavenHotTagsModelCategory]];
self.lastModifyInfo = [JavenLastModifyInfo modelObjectWithDictionary:[dict objectForKey:kJavenHotTagsModelLastModifyInfo]];
self.order = [[self objectOrNilForKey:kJavenHotTagsModelOrder fromDictionary:dict] doubleValue];
self.uuid = [self objectOrNilForKey:kJavenHotTagsModelUuid fromDictionary:dict];
self.createInfo = [JavenCreateInfo modelObjectWithDictionary:[dict objectForKey:kJavenHotTagsModelCreateInfo]];
self.version = [[self objectOrNilForKey:kJavenHotTagsModelVersion fromDictionary:dict] doubleValue];
self.internalBaseClassDescription = [self objectOrNilForKey:kJavenHotTagsModelDescription fromDictionary:dict];
self.name = [self objectOrNilForKey:kJavenHotTagsModelName fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:self.domain forKey:kJavenHotTagsModelDomain];
[mutableDict setValue:[self.category dictionaryRepresentation] forKey:kJavenHotTagsModelCategory];
[mutableDict setValue:[self.lastModifyInfo dictionaryRepresentation] forKey:kJavenHotTagsModelLastModifyInfo];
[mutableDict setValue:[NSNumber numberWithDouble:self.order] forKey:kJavenHotTagsModelOrder];
[mutableDict setValue:self.uuid forKey:kJavenHotTagsModelUuid];
[mutableDict setValue:[self.createInfo dictionaryRepresentation] forKey:kJavenHotTagsModelCreateInfo];
[mutableDict setValue:[NSNumber numberWithDouble:self.version] forKey:kJavenHotTagsModelVersion];
[mutableDict setValue:self.internalBaseClassDescription forKey:kJavenHotTagsModelDescription];
[mutableDict setValue:self.name forKey:kJavenHotTagsModelName];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.domain = [aDecoder decodeObjectForKey:kJavenHotTagsModelDomain];
self.category = [aDecoder decodeObjectForKey:kJavenHotTagsModelCategory];
self.lastModifyInfo = [aDecoder decodeObjectForKey:kJavenHotTagsModelLastModifyInfo];
self.order = [aDecoder decodeDoubleForKey:kJavenHotTagsModelOrder];
self.uuid = [aDecoder decodeObjectForKey:kJavenHotTagsModelUuid];
self.createInfo = [aDecoder decodeObjectForKey:kJavenHotTagsModelCreateInfo];
self.version = [aDecoder decodeDoubleForKey:kJavenHotTagsModelVersion];
self.internalBaseClassDescription = [aDecoder decodeObjectForKey:kJavenHotTagsModelDescription];
self.name = [aDecoder decodeObjectForKey:kJavenHotTagsModelName];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_domain forKey:kJavenHotTagsModelDomain];
[aCoder encodeObject:_category forKey:kJavenHotTagsModelCategory];
[aCoder encodeObject:_lastModifyInfo forKey:kJavenHotTagsModelLastModifyInfo];
[aCoder encodeDouble:_order forKey:kJavenHotTagsModelOrder];
[aCoder encodeObject:_uuid forKey:kJavenHotTagsModelUuid];
[aCoder encodeObject:_createInfo forKey:kJavenHotTagsModelCreateInfo];
[aCoder encodeDouble:_version forKey:kJavenHotTagsModelVersion];
[aCoder encodeObject:_internalBaseClassDescription forKey:kJavenHotTagsModelDescription];
[aCoder encodeObject:_name forKey:kJavenHotTagsModelName];
}
- (id)copyWithZone:(NSZone *)zone
{
JavenHotTagsModel *copy = [[JavenHotTagsModel alloc] init];
if (copy) {
copy.domain = [self.domain copyWithZone:zone];
copy.category = [self.category copyWithZone:zone];
copy.lastModifyInfo = [self.lastModifyInfo copyWithZone:zone];
copy.order = self.order;
copy.uuid = [self.uuid copyWithZone:zone];
copy.createInfo = [self.createInfo copyWithZone:zone];
copy.version = self.version;
copy.internalBaseClassDescription = [self.internalBaseClassDescription copyWithZone:zone];
copy.name = [self.name copyWithZone:zone];
}
return copy;
}
@end
......@@ -8,9 +8,11 @@
#import <UIKit/UIKit.h>
#import "CatgoryModel.h"
#import "JavenHotTagsModel.h"
@interface AddCommodityCollectionViewCell : UICollectionViewCell
- (void)cellWithModel:(CatgoryModel *)model indexPath:(NSIndexPath *)indexPath;
- (void)cellWithHotTagsModel:(JavenHotTagsModel *)model indexPath:(NSIndexPath *)indexPath;
- (void)hideTopLine;
- (void)showTopLine;
......
......@@ -25,7 +25,6 @@
self.labelDsc.text = model.adescription;
self.labelTItle.text = model.name;
if ((int)indexPath.row / 4 == 0) {
[self showTopLine];
}else{
......@@ -40,6 +39,25 @@
}
- (void)cellWithHotTagsModel:(JavenHotTagsModel *)model indexPath:(NSIndexPath *)indexPath
{
//[self.imgView sd_setImageWithURL:[NSURL URLWithString:model.pictures] placeholderImage:nil];
//self.labelDsc.text = model.adescription;
self.labelTItle.text = model.name;
if ((int)indexPath.row / 4 == 0) {
[self showTopLine];
}else{
[self hideTopLine];
}
if ((int)indexPath.row % 4 == 0) {
[self showLeftLine];
}else{
[self hideLeftLine];
}
}
- (void)hideTopLine {
self.viewTopLine.hidden = YES;
}
......
......@@ -22,8 +22,8 @@
<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" misplaced="YES" text="简单说明文字" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JTo-s2-j2V">
<rect key="frame" x="71" y="226" width="84" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="简单说明文字" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JTo-s2-j2V">
<rect key="frame" x="3" y="226" width="220" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.40000000000000002" green="0.40000000000000002" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
......
......@@ -8,9 +8,12 @@
#import <UIKit/UIKit.h>
#import "CommodityListModel/CommotityListModel.h"
typedef void (^addSuccessBlock)(void);
@interface CommodityListCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *labelRealPrice;
@property (weak, nonatomic) IBOutlet UILabel *labelSalePrice;
@property (nonatomic, copy) addSuccessBlock successBlock;
- (void)cellWithModel:(CommotityListModel *)model;
@end
......@@ -7,15 +7,16 @@
//
#import "CommodityListCollectionViewCell.h"
#import "NSDate+FormatterAdditions.h"
#import "addCommodityRequestModel.h"
@interface CommodityListCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *imageViewTop;
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
@property (weak, nonatomic) IBOutlet UILabel *labelCommission;
@property (weak, nonatomic) IBOutlet UILabel *labelPrice;
@property (weak, nonatomic) IBOutlet UILabel *labelOriginalPrice;
@property (weak, nonatomic) IBOutlet UILabel *labelBrokerageRate;
@property (nonatomic, strong) CommotityListModel *model;
@end
......@@ -26,9 +27,54 @@
[self.imageViewTop sd_setImageWithURL:[NSURL URLWithString:model.pictures] placeholderImage:nil];
self.labelOriginalPrice.text = [NSString stringWithFormat:@"%.0f", model.originalPrice];
self.labelBrokerageRate.text = [NSString stringWithFormat:@"%.2f", model.brokerageRate];
self.labelTitle.text = model.name;
self.model = model;
}
- (IBAction)actionAdd:(id)sender {
CLog(@"添加商品");
UserInfo *info = [UserInfo shareInstance];
NSDictionary *param = @{
@"operCtx": @{
@"time": [[NSDate date] timeStampNumber],
@"domain": info.domain,
@"operator": @{
@"id": info.uuid,
@"fullName": info.name
}
},
@"shopUuid": info.shop.uuid,
@"goodsUuid":self.model.uuid
};
WS(weakSelf)
[[HTTPCilent shareCilent] POST:@"shop/addGoods" parameters:param success:^(NSURLSessionDataTask *task, id responseObject) {
if ([responseObject[@"code"] isEqualToNumber: @0]) {
weakSelf.successBlock();
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
}];
}
- (void)addSUccess {
//添加成功提示框
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.window];
[self.window addSubview:hud];
hud.animationType = MBProgressHUDAnimationFade;
hud.removeFromSuperViewOnHide = YES;
hud.labelText = @"添加成功!";
hud.mode = MBProgressHUDModeText;
[hud show:YES];
[hud hide:YES afterDelay:1];
}
- (void)awakeFromNib {
// Initialization code
......
......@@ -62,19 +62,14 @@
<constraint firstAttribute="height" constant="1" id="qzP-Z6-Apx"/>
</constraints>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="commodityUnAdded" translatesAutoresizingMaskIntoConstraints="NO" id="UMJ-W9-mQo">
<rect key="frame" x="6" y="10" width="40" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="8Hd-Aq-z5g"/>
<constraint firstAttribute="height" constant="25" id="WZz-YI-6s0"/>
</constraints>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aRu-lu-Ec8">
<rect key="frame" x="43" y="6" width="64" height="32"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="添加商品">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aRu-lu-Ec8">
<rect key="frame" x="6" y="9" width="115" height="25"/>
<state key="normal" title="添加到店铺" image="commodityUnAdded">
<color key="titleColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="actionAdd:" destination="gTV-IL-0wX" eventType="touchUpInside" id="pkV-cN-vIR"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleAspectFit" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dLe-Tm-qm6">
<rect key="frame" x="161" y="11" width="22" height="23"/>
......@@ -87,16 +82,14 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="UMJ-W9-mQo" firstAttribute="leading" secondItem="pU7-bv-8QS" secondAttribute="leading" constant="6" id="1rW-qL-mOd"/>
<constraint firstItem="aRu-lu-Ec8" firstAttribute="leading" secondItem="UMJ-W9-mQo" secondAttribute="trailing" constant="-3" id="2H2-RG-05O"/>
<constraint firstAttribute="height" constant="44" id="92V-hY-tjv"/>
<constraint firstItem="IC1-ZB-9GI" firstAttribute="top" secondItem="pU7-bv-8QS" secondAttribute="top" id="Bup-dM-Axi"/>
<constraint firstAttribute="trailing" secondItem="dLe-Tm-qm6" secondAttribute="trailing" constant="12" id="DMY-ta-tB1"/>
<constraint firstItem="IC1-ZB-9GI" firstAttribute="leading" secondItem="pU7-bv-8QS" secondAttribute="leading" id="JVz-Qb-8fs"/>
<constraint firstItem="aRu-lu-Ec8" firstAttribute="centerY" secondItem="pU7-bv-8QS" secondAttribute="centerY" id="KdK-b2-Phl"/>
<constraint firstItem="aRu-lu-Ec8" firstAttribute="leading" secondItem="pU7-bv-8QS" secondAttribute="leading" constant="6" id="Sk9-53-nyg"/>
<constraint firstItem="dLe-Tm-qm6" firstAttribute="centerY" secondItem="pU7-bv-8QS" secondAttribute="centerY" id="XM2-R2-Z3p"/>
<constraint firstAttribute="trailing" secondItem="IC1-ZB-9GI" secondAttribute="trailing" id="dzj-Dv-VRD"/>
<constraint firstItem="UMJ-W9-mQo" firstAttribute="centerY" secondItem="pU7-bv-8QS" secondAttribute="centerY" id="u1M-N2-xp5"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DLG-sh-uU2">
......@@ -156,7 +149,7 @@
<outlet property="labelSalePrice" destination="ig6-43-sUi" id="NaO-uj-sLU"/>
<outlet property="labelTitle" destination="vlk-5l-QDd" id="FAQ-2a-zdq"/>
</connections>
<point key="canvasLocation" x="227" y="355.5"/>
<point key="canvasLocation" x="-105" y="369.5"/>
</collectionViewCell>
</objects>
<resources>
......
......@@ -8,10 +8,9 @@
#import <UIKit/UIKit.h>
typedef void (^sortBlock)(BOOL);
typedef void (^sortBlock)(void);
typedef void (^selectedRow)(NSInteger);
@interface SortView : UIView
@property (nonatomic, copy) sortBlock leftSortAction;
@property (nonatomic, copy) sortBlock rightAction;
@property (nonatomic, copy) selectedRow selecedBlock;
......
......@@ -61,6 +61,9 @@
}
- (void)rightBtnAction {
self.rightAction();
[self.rightBtn setTitleColor:kCustomGreenColor forState:UIControlStateNormal];
[self.leftBtn setTitleColor:kTextColorBlack forState:UIControlStateNormal];
if (self.isTableOpen == YES) {
......@@ -90,7 +93,13 @@
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.bottom + 64, ScreenSize.width, 0) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_arrTitles = @[@"综合排序",@"新品排序",@"收藏排序",@"价格从低到高",@"价格从高到低",@"佣金从低到高",@"佣金从高到低"];
_arrTitles = @[@"综合排序",
@"价格从高到低",
@"价格从低到高",
@"佣金从高到低",
@"佣金从低到高",
@"点击量从高到低",
@"点击量从低到高"];
_arrSelectedMark = [NSMutableArray array];
for (int i = 0; i < self.arrTitles.count; i++) {
[self.arrSelectedMark addObject:@"NO"];
......@@ -110,7 +119,6 @@
#pragma mark ==============animate==============
- (void)showTableView {
[self.coverView show];
//self.leftSortAction(YES);
WS(weakSelf)
self.isTableOpen = YES;
......@@ -121,7 +129,6 @@
- (void)hideTableView {
[self.coverView hide];
// self.leftSortAction(NO);
self.isTableOpen = NO;
WS(weakSelf)
[UIView animateWithDuration:0.3 animations:^{
......
......@@ -15,13 +15,15 @@
#import "CommodityListViewController.h"
#import "HotBrandModel.h"
#import "CatgoryModel.h"
#import "JavenHotTagsModel.h"
#import "CommoditySearchViewController.h"
#define kHotCellId @"addCommodityCellHot"
#define kCellId @"addCommodityCell"
#define kHeaderId @"headerId"
#define kFooterId @"footerId"
#define kMargin 0
@interface AddCommodityViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@interface AddCommodityViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UISearchBarDelegate>
@property (nonatomic, strong) NSMutableArray *arrData;
@property (nonatomic, strong) UICollectionView *collectionView;
@end
......@@ -30,7 +32,12 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"添加商品";
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"searchIcon"] style:UIBarButtonItemStyleDone target:self action:@selector(searchAct)];
rightBtn.tintColor = kTextColorDarkGray;
self.navigationItem.rightBarButtonItem = rightBtn;
[self setUpCollectionView];
[self updateStatueBarAppearance];
[self setUpdata];
......@@ -43,6 +50,19 @@
return _arrData;
}
- (void)searchAct {
CLog(@"搜索");
CommoditySearchViewController *searchVC = [[CommoditySearchViewController alloc] init];
searchVC.isShowNavigationBar = YES;
IBTUINavigationController *nc = [[IBTUINavigationController alloc] initWithRootViewController:searchVC];
// [self.navigationController presentModalViewController:nc animated:NO];
[self.navigationController presentViewController:nc animated:YES completion:nil];
}
- (void)setUpdata {
WS(weakSelf)
[[HTTPCilent shareCilent] GET:[NSString stringWithFormat:@"app/getGoodsFilter/%@", @"0001"] parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
......@@ -60,6 +80,16 @@
}
[weakSelf.arrData addObject:arrHotBrand];
//热门标签
NSMutableArray *arrHotTags = [NSMutableArray array];
for (NSDictionary *dic in responseObject[@"hotTags"]) {
JavenHotTagsModel *model = [JavenHotTagsModel modelObjectWithDictionary:dic];
[arrHotTags addObject:model];
}
[weakSelf.arrData addObject:arrHotTags];
//品牌
NSMutableArray *arrCategory = [NSMutableArray array];
for (NSDictionary *dic in responseObject[@"categories"]) {
[CatgoryModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
......@@ -126,6 +156,8 @@
AddCommodityHeaderCollectionReusableView *reuseHeaderView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderId forIndexPath:indexPath];
if (indexPath.section == 0) {
[reuseHeaderView sectionHot];
}else if(indexPath.section == 1){
[reuseHeaderView sectionNormalWithTitle:@"标签"];
}else{
[reuseHeaderView sectionNormalWithTitle:@"分类"];
}
......@@ -176,7 +208,7 @@
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.arrData[section] count];
return section == 1 ? 4 : [self.arrData[section] count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
......@@ -188,18 +220,25 @@
return cell;
//分类
//标签
}else if(indexPath.section == 1){
AddCommodityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
[cell cellWithHotTagsModel:self.arrData[indexPath.section][indexPath.row] indexPath:indexPath];
return cell;
//分类
}else{
AddCommodityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
[cell cellWithModel:self.arrData[indexPath.section][indexPath.row] indexPath:indexPath];
return cell;
}
return nil;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CommodityListViewController *commodityVC = [[CommodityListViewController alloc] init];
commodityVC.hidesBottomBarWhenPushed = YES;
......
......@@ -13,14 +13,18 @@
#import "CommotityRequestModel.h"
#import "HotBrandModel.h"
#import "CatgoryModel.h"
#import "JavenHotTagsModel.h"
#import "CommodityListModel/CommotityListModel.h"
#define kCellID @"commodityCell"
#define kPageSize @10
@interface CommodityListViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) SortView *sortView;
@property (nonatomic, strong) NSMutableArray *arrItemDatas;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, copy) NSString *field; //排序的字段
@property (nonatomic, copy) NSString *direction; //排序的顺序 升序或降序
@end
......@@ -29,6 +33,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
//配置navigationbar
self.navigationItem.title = @"商品列表";
self.view.backgroundColor = kBacroundColor;
[self setUpSortView];
......@@ -46,30 +52,34 @@
- (void)setUpData {
//前期发送请求生成参数的方式,后来不这么做了
NSString *jsonString = @"{\"defintion\":{\"conditions\":[{\"operation\":\"string\",\"parameter\":{},\"parameters\":[{}]}],\"orders\":[{\"field\":\"string\",\"direction\":\"asc\"}],\"pageSize\":0,\"page\":0,\"probePages\":0},\"fetchParts\":[\"string\"]}";
NSDictionary *dic = [jsonString mj_JSONObject];
CommotityRequestModel *requstBody = [CommotityRequestModel modelObjectWithDictionary:dic];
requstBody.defintion.pageSize = kPageSize;
requstBody.defintion.page = @0;
requstBody.defintion.probePages = @0;
requstBody.defintion.orders[0].field = self.field;
requstBody.defintion.orders[0].direction = self.direction;
if ([self.model isKindOfClass:[HotBrandModel class]]) {//热门品牌
//设置请求模型
HotBrandModel *model = self.model;
requstBody.defintion.conditions[0].operation = [NSString stringWithFormat:@"goodsData brand %@ equals", model.uuid];
requstBody.defintion.conditions[0].operation = @"goodsData brand uuid equals";
requstBody.defintion.conditions[0].parameters = @[model.uuid];
requstBody.defintion.pageSize = 10;
requstBody.defintion.page = 0;
requstBody.defintion.probePages = 0;
}else if([self.model isKindOfClass:[CatgoryModel class]]){
}else if([self.model isKindOfClass:[CatgoryModel class]]){//分类
CatgoryModel *model = self.model;
requstBody.defintion.conditions[0].operation = [NSString stringWithFormat:@"goodsData brand %@ equals", model.uuid];
requstBody.defintion.conditions[0].operation = @"goodsData category uuid equals";
requstBody.defintion.conditions[0].parameters = @[model.uuid];
}else if ([self.model isKindOfClass:[JavenHotTagsModel class]]){//热门标签
CatgoryModel *model = self.model;
requstBody.defintion.conditions[0].operation = @"goodsData category uuid equals";
requstBody.defintion.conditions[0].parameters = @[model.uuid];
requstBody.defintion.pageSize = 10;
requstBody.defintion.page = 0;
requstBody.defintion.probePages = 0;
}
//请求模型转化为字典
NSDictionary *params = requstBody.mj_keyValues;
......@@ -103,11 +113,78 @@
_sortView.backgroundColor = [UIColor whiteColor];
//点击排序列表之后回调传入选中行数
//点击排序列表之后回调传入选中行数 筛选
WS(weakSelf)
_sortView.selecedBlock = ^(NSInteger row){
[weakSelf sortAction:row];
CLog(@"%ld", (long)row);
};
_sortView.rightAction = ^(){
weakSelf.field = @"salesvolume";
weakSelf.direction = @"desc";
[weakSelf resetReloadData];
};
}
//排序
- (void)sortAction:(NSInteger)row {
switch (row) {
case 0:
{
self.field = nil;
self.direction = nil;
}
break;
case 1://价格 高-低
{
self.field = @" spec price";
self.direction = @"desc";
}
break;
case 2://价格 低-高
{
self.field = @" spec price";
self.direction = @"asc";
}
break;
case 3://佣金
{
self.field = @"brokerageRate";
self.direction = @"desc";
}
break;
case 4:
{
self.field = @"brokerageRate";
self.direction = @"asc";
}
break;
case 5://点击量
{
self.field = @"visited";
self.direction = @"desc";
}
break;
case 6:
{
self.field = @"visited";
self.direction = @"asc";
}
break;
default:
break;
}
[self resetReloadData];
}
//改变排序条件之后重新请求数据
- (void)resetReloadData {
[self.arrItemDatas removeAllObjects];
[self setUpData];
}
......@@ -146,7 +223,6 @@
CommodityListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell cellWithModel:self.arrItemDatas[indexPath.row]];
return cell;
}
......
//
// CommoditySearchViewController.h
// ALand
//
// Created by Z on 16/4/12.
// Copyright © 2016年 Z. All rights reserved.
//
#import "IBTUIViewController.h"
@interface CommoditySearchViewController : IBTUIViewController
@end
//
// CommoditySearchViewController.m
// ALand
//
// Created by Z on 16/4/12.
// Copyright © 2016年 Z. All rights reserved.
//
#import "CommoditySearchViewController.h"
#import "CommodityListCollectionViewCell.h"
#import "SortView.h"
#import "CommodityDetailViewController.h"
#import "CommotityRequestModel.h"
#import "HotBrandModel.h"
#import "CatgoryModel.h"
#import "JavenHotTagsModel.h"
#import "CommodityListModel/CommotityListModel.h"
#define kCellID @"commodityCell"
#define kPageSize @10
@interface CommoditySearchViewController ()<UISearchBarDelegate,UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) SortView *sortView;
@property (nonatomic, strong) NSMutableArray *arrItemDatas;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, copy) NSString *field; //排序的字段
@property (nonatomic, copy) NSString *direction; //排序的顺序 升序或降序
@property (nonatomic, copy) NSString *searchText; //正在搜索的字段
@end
@implementation CommoditySearchViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpSearchBar];
[self setUpSortView];
[self setUpCollectionView];
// Do any additional setup after loading the view from its nib.
}
- (void)popAction
{
[self.navigationController.navigationBar endEditing:YES];
[self DismissModalViewControllerAnimated:YES];
}
- (void)setUpSearchBar {
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 35)];//allocate titleView
UIColor *color = self.navigationController.navigationBar.barTintColor;
[titleView setBackgroundColor:color];
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
searchBar.frame = CGRectMake(0, 0, 260, 35);
searchBar.centerX = titleView.centerX;
searchBar.backgroundImage = [UIImage imageWithColor:color];
[searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[titleView addSubview:searchBar];
self.navigationItem.titleView = titleView;
[searchBar becomeFirstResponder];
}
- (NSMutableArray *)arrItemDatas {
if (!_arrItemDatas) {
_arrItemDatas = [NSMutableArray array];
}
return _arrItemDatas;
}
- (void)setUpData {
//前期发送请求生成参数的方式,后来不这么做了
NSString *jsonString = @"{\"defintion\":{\"conditions\":[{\"operation\":\"string\",\"parameter\":{},\"parameters\":[{}]}],\"orders\":[{\"field\":\"string\",\"direction\":\"asc\"}],\"pageSize\":0,\"page\":0,\"probePages\":0},\"fetchParts\":[\"string\"]}";
NSDictionary *dic = [jsonString mj_JSONObject];
CommotityRequestModel *requstBody = [CommotityRequestModel modelObjectWithDictionary:dic];
requstBody.defintion.conditions[0].operation = @"goodsData name like";
requstBody.defintion.conditions[0].parameters = @[self.searchText];
requstBody.defintion.pageSize = kPageSize;
requstBody.defintion.page = @0;
requstBody.defintion.probePages = @0;
requstBody.defintion.orders[0].field = self.field;
requstBody.defintion.orders[0].direction = self.direction;
//请求模型转化为字典
NSDictionary *params = requstBody.mj_keyValues;
WS(weakSelf)
[[HTTPCilent shareCilent] POST:@"goods/query2" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
for (NSDictionary *dic in responseObject[@"queryResult"]) {
CommotityListModel *model = [CommotityListModel modelObjectWithDictionary:dic];
[weakSelf.arrItemDatas addObject:model];
}
[weakSelf.collectionView reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
}];
}
- (void)setUpSortView {
_sortView = [[[SortView alloc] init] customNew];
[self.view addSubview:_sortView];
_sortView.sd_layout.topSpaceToView(self.view,1).leftEqualToView(self.view).rightEqualToView(self.view).heightIs(44);
_sortView.backgroundColor = [UIColor whiteColor];
//点击排序列表之后回调传入选中行数 筛选
WS(weakSelf)
_sortView.selecedBlock = ^(NSInteger row){
[weakSelf sortAction:row];
CLog(@"%ld", (long)row);
};
_sortView.rightAction = ^(){
weakSelf.field = @"salesvolume";
weakSelf.direction = @"desc";
[weakSelf resetReloadData];
};
}
//排序
- (void)sortAction:(NSInteger)row {
switch (row) {
case 0:
{
self.field = nil;
self.direction = nil;
}
break;
case 1://价格 高-低
{
self.field = @" spec price";
self.direction = @"desc";
}
break;
case 2://价格 低-高
{
self.field = @" spec price";
self.direction = @"asc";
}
break;
case 3://佣金
{
self.field = @"brokerageRate";
self.direction = @"desc";
}
break;
case 4:
{
self.field = @"brokerageRate";
self.direction = @"asc";
}
break;
case 5://点击量
{
self.field = @"visited";
self.direction = @"desc";
}
break;
case 6:
{
self.field = @"visited";
self.direction = @"asc";
}
break;
default:
break;
}
[self resetReloadData];
}
//改变排序条件之后重新请求数据
- (void)resetReloadData {
[self.arrItemDatas removeAllObjects];
[self setUpData];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.sortView hide];
}
- (void)setUpCollectionView {
UICollectionViewFlowLayout *layOut = [[UICollectionViewFlowLayout alloc] init];
layOut.minimumLineSpacing = 10;
layOut.itemSize = CGSizeMake((ScreenSize.width - 30)/2, ScreenSize.height / 2.2);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layOut];
[self.view addSubview:_collectionView];
_collectionView.sd_layout.topSpaceToView(self.view, 50).leftEqualToView(self.view).bottomEqualToView(self.view).rightEqualToView(self.view);
_collectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = kBacroundColor;
[_collectionView registerNib:[UINib nibWithNibName:@"CommodityListCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kCellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.arrItemDatas.count;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CommodityDetailViewController *detailVC = [[CommodityDetailViewController alloc] init];
[self.navigationController pushViewController:detailVC animated:YES];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CommodityListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell cellWithModel:self.arrItemDatas[indexPath.row]];
return cell;
}
#pragma mark =========== searchBar Delegate ===========
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
CLog(@"点击搜索");
[self.navigationController.navigationBar endEditing:YES];
[self setUpData];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
self.searchText = searchText;
}
- (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
......@@ -39,7 +39,7 @@
// }];
// info = [UserInfo mj_objectWithKeyValues:responseObject[@"reseller"]];
info = [UserInfo modelObjectWithDictionary:responseObject[@"reseller"]];
[info UserInfoWithDictionary:responseObject[@"reseller"]];
[MBProgressHUD hideHUDForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
......
......@@ -58,6 +58,14 @@
- (NSDate *)endOfTheDay;
/**
* 生成十位数的number类型的时间戳
*
* @return timestamp
*/
- (NSNumber *)timeStampNumber;
///--------------------
/// @name Time In Words
///--------------------
......
......@@ -379,6 +379,16 @@
return result;
}
- (NSNumber *)timeStampNumber
{
NSString *timeStampString = [self timeStampStr];
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * time = [f numberFromString:timeStampString];
return time;
}
+ (NSString *)curTimeStamp {
return [[NSDate date] timeStampStr];
}
......
//
// JavenCategory.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface JavenCategory : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) id code;
@property (nonatomic, strong) NSString *uuid;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// JavenCategory.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "JavenCategory.h"
NSString *const kJavenCategoryName = @"name";
NSString *const kJavenCategoryCode = @"code";
NSString *const kJavenCategoryUuid = @"uuid";
@interface JavenCategory ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation JavenCategory
@synthesize name = _name;
@synthesize code = _code;
@synthesize uuid = _uuid;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.name = [self objectOrNilForKey:kJavenCategoryName fromDictionary:dict];
self.code = [self objectOrNilForKey:kJavenCategoryCode fromDictionary:dict];
self.uuid = [self objectOrNilForKey:kJavenCategoryUuid fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:self.name forKey:kJavenCategoryName];
[mutableDict setValue:self.code forKey:kJavenCategoryCode];
[mutableDict setValue:self.uuid forKey:kJavenCategoryUuid];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.name = [aDecoder decodeObjectForKey:kJavenCategoryName];
self.code = [aDecoder decodeObjectForKey:kJavenCategoryCode];
self.uuid = [aDecoder decodeObjectForKey:kJavenCategoryUuid];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_name forKey:kJavenCategoryName];
[aCoder encodeObject:_code forKey:kJavenCategoryCode];
[aCoder encodeObject:_uuid forKey:kJavenCategoryUuid];
}
- (id)copyWithZone:(NSZone *)zone
{
JavenCategory *copy = [[JavenCategory alloc] init];
if (copy) {
copy.name = [self.name copyWithZone:zone];
copy.code = [self.code copyWithZone:zone];
copy.uuid = [self.uuid copyWithZone:zone];
}
return copy;
}
@end
//
// JavenCreateInfo.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@class JavenOperator;
@interface JavenCreateInfo : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) JavenOperator *operator;
@property (nonatomic, assign) double time;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// JavenCreateInfo.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "JavenCreateInfo.h"
#import "JavenOperator.h"
NSString *const kJavenCreateInfoOperator = @"operator";
NSString *const kJavenCreateInfoTime = @"time";
@interface JavenCreateInfo ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation JavenCreateInfo
@synthesize operator = _operator;
@synthesize time = _time;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operator = [JavenOperator modelObjectWithDictionary:[dict objectForKey:kJavenCreateInfoOperator]];
self.time = [[self objectOrNilForKey:kJavenCreateInfoTime fromDictionary:dict] doubleValue];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[self.operator dictionaryRepresentation] forKey:kJavenCreateInfoOperator];
[mutableDict setValue:[NSNumber numberWithDouble:self.time] forKey:kJavenCreateInfoTime];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operator = [aDecoder decodeObjectForKey:kJavenCreateInfoOperator];
self.time = [aDecoder decodeDoubleForKey:kJavenCreateInfoTime];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operator forKey:kJavenCreateInfoOperator];
[aCoder encodeDouble:_time forKey:kJavenCreateInfoTime];
}
- (id)copyWithZone:(NSZone *)zone
{
JavenCreateInfo *copy = [[JavenCreateInfo alloc] init];
if (copy) {
copy.operator = [self.operator copyWithZone:zone];
copy.time = self.time;
}
return copy;
}
@end
//
// JavenLastModifyInfo.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@class JavenOperator;
@interface JavenLastModifyInfo : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) JavenOperator *operator;
@property (nonatomic, assign) double time;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// JavenLastModifyInfo.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "JavenLastModifyInfo.h"
#import "JavenOperator.h"
NSString *const kJavenLastModifyInfoOperator = @"operator";
NSString *const kJavenLastModifyInfoTime = @"time";
@interface JavenLastModifyInfo ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation JavenLastModifyInfo
@synthesize operator = _operator;
@synthesize time = _time;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operator = [JavenOperator modelObjectWithDictionary:[dict objectForKey:kJavenLastModifyInfoOperator]];
self.time = [[self objectOrNilForKey:kJavenLastModifyInfoTime fromDictionary:dict] doubleValue];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[self.operator dictionaryRepresentation] forKey:kJavenLastModifyInfoOperator];
[mutableDict setValue:[NSNumber numberWithDouble:self.time] forKey:kJavenLastModifyInfoTime];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operator = [aDecoder decodeObjectForKey:kJavenLastModifyInfoOperator];
self.time = [aDecoder decodeDoubleForKey:kJavenLastModifyInfoTime];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operator forKey:kJavenLastModifyInfoOperator];
[aCoder encodeDouble:_time forKey:kJavenLastModifyInfoTime];
}
- (id)copyWithZone:(NSZone *)zone
{
JavenLastModifyInfo *copy = [[JavenLastModifyInfo alloc] init];
if (copy) {
copy.operator = [self.operator copyWithZone:zone];
copy.time = self.time;
}
return copy;
}
@end
//
// JavenOperator.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface JavenOperator : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) NSString *operatorIdentifier;
@property (nonatomic, strong) NSString *fullName;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// JavenOperator.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "JavenOperator.h"
NSString *const kJavenOperatorId = @"id";
NSString *const kJavenOperatorFullName = @"fullName";
@interface JavenOperator ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation JavenOperator
@synthesize operatorIdentifier = _operatorIdentifier;
@synthesize fullName = _fullName;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operatorIdentifier = [self objectOrNilForKey:kJavenOperatorId fromDictionary:dict];
self.fullName = [self objectOrNilForKey:kJavenOperatorFullName fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:self.operatorIdentifier forKey:kJavenOperatorId];
[mutableDict setValue:self.fullName forKey:kJavenOperatorFullName];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operatorIdentifier = [aDecoder decodeObjectForKey:kJavenOperatorId];
self.fullName = [aDecoder decodeObjectForKey:kJavenOperatorFullName];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operatorIdentifier forKey:kJavenOperatorId];
[aCoder encodeObject:_fullName forKey:kJavenOperatorFullName];
}
- (id)copyWithZone:(NSZone *)zone
{
JavenOperator *copy = [[JavenOperator alloc] init];
if (copy) {
copy.operatorIdentifier = [self.operatorIdentifier copyWithZone:zone];
copy.fullName = [self.fullName copyWithZone:zone];
}
return copy;
}
@end
......@@ -7,15 +7,15 @@
#import <Foundation/Foundation.h>
#import "Conditions.h"
#import "Orders.h"
@interface Defintion : NSObject <NSCoding, NSCopying>
@property (nonatomic, assign) double pageSize;
@property (nonatomic, strong) NSArray *orders;
@property (nonatomic, strong) NSNumber *pageSize;
@property (nonatomic, strong) NSArray<Orders *> *orders;
@property (nonatomic, strong) NSArray<Conditions *> *conditions;
@property (nonatomic, assign) double probePages;
@property (nonatomic, assign) double page;
@property (nonatomic, assign) NSNumber *probePages;
@property (nonatomic, strong) NSNumber *page;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
......
......@@ -44,7 +44,7 @@ NSString *const kDefintionPage = @"page";
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.pageSize = [[self objectOrNilForKey:kDefintionPageSize fromDictionary:dict] doubleValue];
self.pageSize = [self objectOrNilForKey:kDefintionPageSize fromDictionary:dict];
NSObject *receivedOrders = [dict objectForKey:kDefintionOrders];
NSMutableArray *parsedOrders = [NSMutableArray array];
if ([receivedOrders isKindOfClass:[NSArray class]]) {
......@@ -71,8 +71,8 @@ NSString *const kDefintionPage = @"page";
}
self.conditions = [NSArray arrayWithArray:parsedConditions];
self.probePages = [[self objectOrNilForKey:kDefintionProbePages fromDictionary:dict] doubleValue];
self.page = [[self objectOrNilForKey:kDefintionPage fromDictionary:dict] doubleValue];
self.probePages = [self objectOrNilForKey:kDefintionProbePages fromDictionary:dict];
self.page = [self objectOrNilForKey:kDefintionPage fromDictionary:dict];
}
......@@ -83,7 +83,7 @@ NSString *const kDefintionPage = @"page";
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[NSNumber numberWithDouble:self.pageSize] forKey:kDefintionPageSize];
[mutableDict setValue:self.pageSize forKey:kDefintionPageSize];
NSMutableArray *tempArrayForOrders = [NSMutableArray array];
for (NSObject *subArrayObject in self.orders) {
if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
......@@ -106,8 +106,8 @@ NSString *const kDefintionPage = @"page";
}
}
[mutableDict setValue:[NSArray arrayWithArray:tempArrayForConditions] forKey:kDefintionConditions];
[mutableDict setValue:[NSNumber numberWithDouble:self.probePages] forKey:kDefintionProbePages];
[mutableDict setValue:[NSNumber numberWithDouble:self.page] forKey:kDefintionPage];
[mutableDict setValue:self.probePages forKey:kDefintionProbePages];
[mutableDict setValue:self.page forKey:kDefintionPage];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
......@@ -131,22 +131,22 @@ NSString *const kDefintionPage = @"page";
{
self = [super init];
self.pageSize = [aDecoder decodeDoubleForKey:kDefintionPageSize];
self.pageSize = [aDecoder decodeObjectForKey:kDefintionPageSize];
self.orders = [aDecoder decodeObjectForKey:kDefintionOrders];
self.conditions = [aDecoder decodeObjectForKey:kDefintionConditions];
self.probePages = [aDecoder decodeDoubleForKey:kDefintionProbePages];
self.page = [aDecoder decodeDoubleForKey:kDefintionPage];
self.probePages = [aDecoder decodeObjectForKey:kDefintionProbePages];
self.page = [aDecoder decodeObjectForKey:kDefintionPage];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:_pageSize forKey:kDefintionPageSize];
[aCoder encodeObject:_pageSize forKey:kDefintionPageSize];
[aCoder encodeObject:_orders forKey:kDefintionOrders];
[aCoder encodeObject:_conditions forKey:kDefintionConditions];
[aCoder encodeDouble:_probePages forKey:kDefintionProbePages];
[aCoder encodeDouble:_page forKey:kDefintionPage];
[aCoder encodeObject:_probePages forKey:kDefintionProbePages];
[aCoder encodeObject:_page forKey:kDefintionPage];
}
- (id)copyWithZone:(NSZone *)zone
......
//
// OperCtx.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@class Operator;
@interface OperCtx : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) Operator *operator;
@property (nonatomic, strong) NSDate *time;
@property (nonatomic, strong) NSString *domain;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// OperCtx.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "OperCtx.h"
#import "Operator.h"
NSString *const kOperCtxOperator = @"operator";
NSString *const kOperCtxTime = @"time";
NSString *const kOperCtxDomain = @"domain";
@interface OperCtx ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation OperCtx
@synthesize operator = _operator;
@synthesize time = _time;
@synthesize domain = _domain;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operator = [Operator modelObjectWithDictionary:[dict objectForKey:kOperCtxOperator]];
self.time = [self objectOrNilForKey:kOperCtxTime fromDictionary:dict];
self.domain = [self objectOrNilForKey:kOperCtxDomain fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[self.operator dictionaryRepresentation] forKey:kOperCtxOperator];
[mutableDict setValue:self.time forKey:kOperCtxTime];
[mutableDict setValue:self.domain forKey:kOperCtxDomain];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operator = [aDecoder decodeObjectForKey:kOperCtxOperator];
self.time = [aDecoder decodeObjectForKey:kOperCtxTime];
self.domain = [aDecoder decodeObjectForKey:kOperCtxDomain];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operator forKey:kOperCtxOperator];
[aCoder encodeObject:_time forKey:kOperCtxTime];
[aCoder encodeObject:_domain forKey:kOperCtxDomain];
}
- (id)copyWithZone:(NSZone *)zone
{
OperCtx *copy = [[OperCtx alloc] init];
if (copy) {
copy.operator = [self.operator copyWithZone:zone];
copy.time = self.time;
copy.domain = [self.domain copyWithZone:zone];
}
return copy;
}
@end
//
// Operator.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Operator : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) NSString *operatorIdentifier;
@property (nonatomic, strong) NSString *fullName;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// Operator.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "Operator.h"
NSString *const kOperatorId = @"id";
NSString *const kOperatorFullName = @"fullName";
@interface Operator ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation Operator
@synthesize operatorIdentifier = _operatorIdentifier;
@synthesize fullName = _fullName;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operatorIdentifier = [self objectOrNilForKey:kOperatorId fromDictionary:dict];
self.fullName = [self objectOrNilForKey:kOperatorFullName fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:self.operatorIdentifier forKey:kOperatorId];
[mutableDict setValue:self.fullName forKey:kOperatorFullName];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operatorIdentifier = [aDecoder decodeObjectForKey:kOperatorId];
self.fullName = [aDecoder decodeObjectForKey:kOperatorFullName];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operatorIdentifier forKey:kOperatorId];
[aCoder encodeObject:_fullName forKey:kOperatorFullName];
}
- (id)copyWithZone:(NSZone *)zone
{
Operator *copy = [[Operator alloc] init];
if (copy) {
copy.operatorIdentifier = [self.operatorIdentifier copyWithZone:zone];
copy.fullName = [self.fullName copyWithZone:zone];
}
return copy;
}
@end
//
// addCommodityRequestModel.h
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OperCtx.h"
@class OperCtx;
@interface addCommodityRequestModel : NSObject <NSCoding, NSCopying>
@property (nonatomic, strong) OperCtx *operCtx;
@property (nonatomic, strong) NSString *shopUuid;
@property (nonatomic, strong) NSString *goodsUuid;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
@end
//
// addCommodityRequestModel.m
//
// Created by Z on 16/4/12
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#import "addCommodityRequestModel.h"
#import "OperCtx.h"
NSString *const kaddCommodityRequestModelOperCtx = @"operCtx";
NSString *const kaddCommodityRequestModelShopUuid = @"shopUuid";
NSString *const kaddCommodityRequestModelGoodsUuid = @"goodsUuid";
@interface addCommodityRequestModel ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation addCommodityRequestModel
@synthesize operCtx = _operCtx;
@synthesize shopUuid = _shopUuid;
@synthesize goodsUuid = _goodsUuid;
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.operCtx = [OperCtx modelObjectWithDictionary:[dict objectForKey:kaddCommodityRequestModelOperCtx]];
self.shopUuid = [self objectOrNilForKey:kaddCommodityRequestModelShopUuid fromDictionary:dict];
self.goodsUuid = [self objectOrNilForKey:kaddCommodityRequestModelGoodsUuid fromDictionary:dict];
}
return self;
}
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:[self.operCtx dictionaryRepresentation] forKey:kaddCommodityRequestModelOperCtx];
[mutableDict setValue:self.shopUuid forKey:kaddCommodityRequestModelShopUuid];
[mutableDict setValue:self.goodsUuid forKey:kaddCommodityRequestModelGoodsUuid];
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
id object = [dict objectForKey:aKey];
return [object isEqual:[NSNull null]] ? nil : object;
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
self.operCtx = [aDecoder decodeObjectForKey:kaddCommodityRequestModelOperCtx];
self.shopUuid = [aDecoder decodeObjectForKey:kaddCommodityRequestModelShopUuid];
self.goodsUuid = [aDecoder decodeObjectForKey:kaddCommodityRequestModelGoodsUuid];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_operCtx forKey:kaddCommodityRequestModelOperCtx];
[aCoder encodeObject:_shopUuid forKey:kaddCommodityRequestModelShopUuid];
[aCoder encodeObject:_goodsUuid forKey:kaddCommodityRequestModelGoodsUuid];
}
- (id)copyWithZone:(NSZone *)zone
{
addCommodityRequestModel *copy = [[addCommodityRequestModel alloc] init];
if (copy) {
copy.operCtx = [self.operCtx copyWithZone:zone];
copy.shopUuid = [self.shopUuid copyWithZone:zone];
copy.goodsUuid = [self.goodsUuid copyWithZone:zone];
}
return copy;
}
@end
......@@ -6,7 +6,7 @@
//
#import <Foundation/Foundation.h>
#import "UserInfoShop.h"
@class UserInfoOwnerOrg, UserInfoLastModifyInfo, UserInfoCertificate, UserInfoPasswordControl, UserInfoShop, UserInfoCreateInfo, UserInfoLoginControl;
@interface UserInfoBaseClass : NSObject <NSCoding, NSCopying>
......@@ -41,5 +41,6 @@
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
- (NSDictionary *)dictionaryRepresentation;
- (void)UserInfoWithDictionary:(NSDictionary *)dict;
@end
......@@ -167,7 +167,43 @@ NSString *const kUserInfoBaseClassDescription = @"description";
return [NSDictionary dictionaryWithDictionary:mutableDict];
}
- (NSString *)description
- (void)UserInfoWithDictionary:(NSDictionary *)dict
{
// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.birthday = [self objectOrNilForKey:kUserInfoBaseClassBirthday fromDictionary:dict];
self.portrait = [self objectOrNilForKey:kUserInfoBaseClassPortrait fromDictionary:dict];
self.ownerOrg = [UserInfoOwnerOrg modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassOwnerOrg]];
self.code = [self objectOrNilForKey:kUserInfoBaseClassCode fromDictionary:dict];
self.telephone = [self objectOrNilForKey:kUserInfoBaseClassTelephone fromDictionary:dict];
self.mobilephone = [self objectOrNilForKey:kUserInfoBaseClassMobilephone fromDictionary:dict];
self.uuid = [self objectOrNilForKey:kUserInfoBaseClassUuid fromDictionary:dict];
self.lastModifyInfo = [UserInfoLastModifyInfo modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassLastModifyInfo]];
self.socialContact = [self objectOrNilForKey:kUserInfoBaseClassSocialContact fromDictionary:dict];
self.certificate = [UserInfoCertificate modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassCertificate]];
self.version = [[self objectOrNilForKey:kUserInfoBaseClassVersion fromDictionary:dict] doubleValue];
self.name = [self objectOrNilForKey:kUserInfoBaseClassName fromDictionary:dict];
self.invitationCode = [self objectOrNilForKey:kUserInfoBaseClassInvitationCode fromDictionary:dict];
self.state = [self objectOrNilForKey:kUserInfoBaseClassState fromDictionary:dict];
self.domain = [self objectOrNilForKey:kUserInfoBaseClassDomain fromDictionary:dict];
self.passwordControl = [UserInfoPasswordControl modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassPasswordControl]];
self.gender = [self objectOrNilForKey:kUserInfoBaseClassGender fromDictionary:dict];
self.roles = [self objectOrNilForKey:kUserInfoBaseClassRoles fromDictionary:dict];
self.postalAddresses = [self objectOrNilForKey:kUserInfoBaseClassPostalAddresses fromDictionary:dict];
self.idCard = [self objectOrNilForKey:kUserInfoBaseClassIdCard fromDictionary:dict];
self.referrer = [self objectOrNilForKey:kUserInfoBaseClassReferrer fromDictionary:dict];
self.shop = [UserInfoShop modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassShop]];
self.createInfo = [UserInfoCreateInfo modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassCreateInfo]];
self.order = [[self objectOrNilForKey:kUserInfoBaseClassOrder fromDictionary:dict] doubleValue];
self.loginControl = [UserInfoLoginControl modelObjectWithDictionary:[dict objectForKey:kUserInfoBaseClassLoginControl]];
self.internalBaseClassDescription = [self objectOrNilForKey:kUserInfoBaseClassDescription fromDictionary:dict];
}
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}
......
......@@ -22,6 +22,7 @@
- (BOOL)isPresentedIn;
- (BOOL)isPushedIn;
- (void)popAction;
- (void)disMissSelf;
......
......@@ -175,4 +175,8 @@
}
- (void)dealloc {
CLog(@"%@注销了",[NSString stringWithUTF8String:object_getClassName(self)]);
}
@end
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