Commit e07121cd authored by Sandy's avatar Sandy

销售录入新建修改tableview/图片选取/删除/显示

parent 3f89c559
This diff is collapsed.
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
#import "SaleInputAddViewController.h" #import "SaleInputAddViewController.h"
#import "SaleInputViewModel.h" #import "SaleInputViewModel.h"
#import "SaleInputAmountCollectionViewCell.h" #import "SaleInputAmountCollectionViewCell.h"
@interface SaleInputAddViewController ()<UICollectionViewDelegate, UICollectionViewDataSource> #import "SaleInputAddAmountCell.h"
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView; #import "PicViewModel.h"
#import "InspectRepairAddPicTableViewCell.h"
@interface SaleInputAddViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *btnBottom; @property (weak, nonatomic) IBOutlet UIButton *btnBottom;
@property (strong, nonatomic) SaleInputViewModel *viewModel; @property (strong, nonatomic) SaleInputViewModel *viewModel;
@property (strong, nonatomic) NSMutableArray *arrData; @property (strong, nonatomic) NSMutableArray *arrData;
@property (strong, nonatomic) PicViewModel *picVM;
@end @end
@implementation SaleInputAddViewController @implementation SaleInputAddViewController
...@@ -24,81 +28,62 @@ ...@@ -24,81 +28,62 @@
WS(weakSelf); WS(weakSelf);
[self.viewModel httpAllPayments:^(NSMutableArray<HMSaleInputDetail_payments_payment *> *arrPayments) { [self.viewModel httpAllPayments:^(NSMutableArray<HMSaleInputDetail_payments_payment *> *arrPayments) {
weakSelf.arrData = arrPayments; weakSelf.arrData = arrPayments;
[weakSelf.collectionView reloadData]; [weakSelf.tableView reloadData];
CLog(@"%@", arrPayments); CLog(@"%@", arrPayments);
}]; }];
} }
#pragma mark - UICollectionViewDelegateFlowLayout - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#pragma mark - item的列间距 return 2;
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0;
} }
#pragma mark - item的行间距 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
if (0 == section) {
return 0;
} else {
return 5;
}
}
//定义每个UICollectionView item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (0 == indexPath.section) {
return CGSizeMake(kWidth, 50);
} else {
return CGSizeMake((kWidth - 30) / 2, kAutoValue(120));
}
}
//定义每个UICollectionView section的 margin
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
if (0 == section) {
return UIEdgeInsetsMake(0, 0, 0, 0);
} else {
return UIEdgeInsetsMake(0, 10, 0, 10);
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (section == 0) { if (section == 0) {
return CGSizeMake(0, 0); return self.arrData.count;
} else { }else{
return CGSizeMake(kWidth, 50); return 1;
} }
} }
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *header; if (indexPath.section == 0) {
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { return 50;
header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"picHeaderView" forIndexPath:indexPath]; }else{
return self.picVM.cellHeight;
} }
return header;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.arrData.count;
} }
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//输入各种支付方式的金额 if (indexPath.section == 0) {
SaleInputAmountCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SaleInputAmountCollectionViewCell" forIndexPath:indexPath]; //输入各种支付方式的金额
cell.isEdit = self.viewModel.type != SaleInputTypeReadOnly; SaleInputAddAmountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SaleInputAddAmountCell" forIndexPath:indexPath];
[cell configCellWithArray:self.arrData indexPath:indexPath]; cell.isEdit = self.viewModel.type != SaleInputTypeReadOnly;
// WS(weakSelf); [cell configCellWithArray:self.arrData indexPath:indexPath];
cell.blockNumberChanged = ^{ // WS(weakSelf);
// [weakSelf allInputMoney]; cell.blockNumberChanged = ^{
}; // [weakSelf allInputMoney];
return cell; };
return cell;
}else{
InspectRepairAddPicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InspectRepairAddPicTableViewCell" forIndexPath:indexPath];
[cell configCellWithViewModel:self.picVM
indexPath:indexPath
target:self];
WS(weakSelf);
cell.blockReloadData = ^{
[weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:UITableViewRowAnimationAutomatic];
};
return cell;
}
} }
//
- (void)httpPayments { - (void)httpPayments {
} }
ZJLazy(SaleInputViewModel, viewModel); ZJLazy(SaleInputViewModel, viewModel);
ZJLazy(NSMutableArray, arrData); ZJLazy(NSMutableArray, arrData);
ZJLazy(PicViewModel, picVM);
@end @end
//
// SaleInputAddAmountCell.h
// HDMall
//
// Created by Javen on 2017/7/31.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SaleInputViewModel.h"
@interface SaleInputAddAmountCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
@property (weak, nonatomic) IBOutlet UITextField *textFieldInput;
@property (nonatomic, strong) HMSaleInputDetail_payments *model;
@property (nonatomic, assign) BOOL isEdit;
@property (nonatomic, copy) void (^blockNumberChanged)(void);
- (void)configCellWithArray:(NSMutableArray *)array indexPath:(NSIndexPath *)indexPath;
@end
//
// SaleInputAddAmountCell.m
// HDMall
//
// Created by Javen on 2017/7/31.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "SaleInputAddAmountCell.h"
#import "CalculateHelper.h"
#import "NSString+Additions.h"
@interface SaleInputAddAmountCell ()<UITextFieldDelegate>
@end
@implementation SaleInputAddAmountCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.textFieldInput.delegate = self;
[self.textFieldInput addTarget:self action:@selector(textFieldDidChanged:) forControlEvents:UIControlEventEditingChanged];
}
/**
* 设置可编辑状态和不可编辑状态
*/
- (void)setIsEdit:(BOOL)isEdit {
_isEdit = isEdit;
if (isEdit) {
self.textFieldInput.userInteractionEnabled = YES;
self.textFieldInput.textColor = [UIColor blackColor];
}else{
self.textFieldInput.userInteractionEnabled = NO;
self.textFieldInput.textColor = [UIColor lightGrayColor];
}
}
//实时获取变化之后的数据
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//获取改变之后的字符串
NSMutableString *futureString = [NSMutableString stringWithString:textField.text];
[futureString insertString:string atIndex:range.location];
return [futureString isValidMoneyInput];
}
- (void)textFieldDidChanged:(UITextField *)textField {
self.model.total = [CalculateHelper decimalNumber:textField.text];
self.blockNumberChanged();
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
textField.textColor = [UIColor blackColor];
if ([textField.text isEqualToString:@"0.00"]) {
textField.text = @"";
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//输入框有文字则显示,避免没输入自动出现0.00的情况
if (textField.text.length > 0) {
if ([textField.text isEqualToString:@"0"]) {
textField.textColor = [UIColor lightGrayColor];
textField.text = @"0.00";
}else{
self.textFieldInput.text = [CalculateHelper getMoneyStringFrom:textField.text];
}
}
}
- (void)configCellWithArray:(NSMutableArray *)array indexPath:(NSIndexPath *)indexPath {
self.model = array[indexPath.row];
self.textFieldInput.text = self.model.total ? [CalculateHelper getMoneyStringFrom:self.model.total] : nil;
if ([self.textFieldInput.text isEqualToString:@"0.00"]) {
self.textFieldInput.textColor = [UIColor lightGrayColor];
}else{
self.textFieldInput.textColor = [UIColor blackColor];
}
self.labelTitle.text = self.model.payment.name;
}
@end
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
// Copyright © 2016年 上海勾芒信息科技. All rights reserved. // Copyright © 2016年 上海勾芒信息科技. All rights reserved.
// //
#import "CalculateHelper.h"
#import "SaleInputAmountCollectionViewCell.h" #import "SaleInputAmountCollectionViewCell.h"
#import "CalculateHelper.h"
#import "NSString+Additions.h" #import "NSString+Additions.h"
@interface SaleInputAmountCollectionViewCell () <UITextFieldDelegate> @interface SaleInputAmountCollectionViewCell () <UITextFieldDelegate>
......
...@@ -39,6 +39,32 @@ ...@@ -39,6 +39,32 @@
<array> <array>
<string>armv7</string> <string>armv7</string>
</array> </array>
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
......
//
// GalleryCollectionViewCell.h
// CapitalChamberlain
//
// Created by 张杰 on 15/12/3.
// Copyright © 2015年 SunShine. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SingleScrollView.h"
//#import "AttachmentModel.h"
@interface GalleryCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imgView;
//- (void)setUpCellWithModel:(AttachmentModel *)model;
- (void)cellWithImgName:(NSString *)imgUrl;
- (void)configCellWithArray:(NSMutableArray *)array indexPath:(NSIndexPath *)indexPath;
@end
//
// GalleryCollectionViewCell.m
// CapitalChamberlain
//
// Created by 张杰 on 15/12/3.
// Copyright © 2015年 SunShine. All rights reserved.
//
#import "GalleryCollectionViewCell.h"
#import "ZJBaseFileModel.h"
@interface GalleryCollectionViewCell ()
@property (nonatomic, strong) SingleScrollView *imageScrollView;
@end
@implementation GalleryCollectionViewCell
- (void)awakeFromNib {
[super awakeFromNib];
CLog(@"%f",self.width);
self.imageScrollView = [[SingleScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
self.backgroundColor = [UIColor blackColor];
[self.contentView addSubview:self.imageScrollView];
}
- (void)cellWithImgName:(NSString *)imgUrl {
}
- (void)configCellWithArray:(NSMutableArray *)array indexPath:(NSIndexPath *)indexPath {
ZJBaseFileModel *model = array[indexPath.row];
if ([model isKindOfClass:[ZJBaseFileModel class]]) {
if (model.image != nil) {
[self.imageScrollView setImage:model.image placeHolder:kPlaceHolderImage];
}else{
WS(weakSelf);
[model getFileUrlComplelet:^(NSString *fileUrl) {
[weakSelf.imageScrollView setImage:fileUrl placeHolder:kPlaceHolderImage];
}];
}
}else if([model isKindOfClass:[UIImage class]]){
[self.imageScrollView setImage:model placeHolder:kPlaceHolderImage];
}
}
@end
//
// GalleryViewController.h
// vanke
//
// Created by Z on 16/7/18.
// Copyright © 2016年 gomore. All rights reserved.
// storyboard
#import <UIKit/UIKit.h>
#import "GalleryCollectionViewCell.h"
typedef NS_ENUM(NSInteger, GalleryType) {
GalleryTypeReadOnly,
GalleryTypeEdit
};
typedef void (^closeBlock)(NSInteger index);
@interface GalleryViewController : UIViewController
@property (nonatomic, strong) NSMutableArray *arrData;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, assign) GalleryType type;
@property (nonatomic, strong) NSMutableArray *arrOnlineUuids;
@property (nonatomic, copy) closeBlock blockDelete;
@end
//
// GalleryViewController.m
// vanke
//
// Created by Z on 16/7/18.
// Copyright © 2016年 gomore. All rights reserved.
//
#import "ZJBaseFileModel.h"
#import "GalleryCollectionViewCell.h"
#import "GalleryViewController.h"
@interface GalleryViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;
@end
@implementation GalleryViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.flowLayout.itemSize = CGSizeMake(kWidth, kHeight);
self.flowLayout.minimumLineSpacing = 0;
self.flowLayout.minimumInteritemSpacing = 0;
self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
switch (self.type) {
case GalleryTypeReadOnly: {
break;
}
case GalleryTypeEdit: {
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deletePic)];
self.navigationItem.rightBarButtonItem = rightBtn;
break;
}
}
}
- (void)deletePic
{
WS(weakSelf);
[self alertTitle:@"确认删除这张图片?"
msg:nil
okAction:^(UIAlertAction *action) {
weakSelf.page = weakSelf.collectionView.contentOffset.x / weakSelf.view.frame.size.width;
[weakSelf.arrData removeObjectAtIndex:weakSelf.page];
if (self.arrData.count == 0) {
[weakSelf.navigationController popViewControllerAnimated:YES];
} else {
NSIndexPath *index = [NSIndexPath indexPathForRow:weakSelf.page inSection:0];
[weakSelf.collectionView deleteItemsAtIndexPaths:@[ index ]];
}
//删除之后的回调,这里的数字是随便传的
weakSelf.blockDelete(0);
}
cancelAction:nil];
}
- (void)viewDidLayoutSubviews
{
if (self.page < 0) {
return;
}
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.page inSection:0]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:NO];
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.arrData.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
GalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCollectionViewCell" forIndexPath:indexPath];
[cell configCellWithArray:self.arrData indexPath:indexPath];
self.title = [NSString stringWithFormat:@"(%ld/%.0lu)", indexPath.row + 1, (unsigned long)self.arrData.count];
return cell;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.title = [NSString stringWithFormat:@"(%.0f/%.0lu)", scrollView.contentOffset.x / kWidth + 1, (unsigned long)self.arrData.count];
self.page = scrollView.contentOffset.x / self.view.frame.size.width;
}
- (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
//
// SingleScrollView.h
// PhotoWallDemo
//
// Created by LZXuan on 14-8-18.
// Copyright (c) 2014年 LZXuan. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SingleScrollView : UIScrollView
//
- (SingleScrollView *)initWithFrame:(CGRect)frame image:(NSString *)image;
- (void)setImage:(id)image placeHolder:(UIImage *)placeHolder;
@end
//
// SingleScrollView.m
// PhotoWallDemo
//
// Created by LZXuan on 14-8-18.
// Copyright (c) 2014年 LZXuan. All rights reserved.
//
#import "SingleScrollView.h"
#import "UIImageView+WebCache.h"
@interface SingleScrollView()<UIScrollViewDelegate>
@end
@implementation SingleScrollView {
UIImageView *_imageView;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setUpViews];
}
return self;
}
- (SingleScrollView *)initWithFrame:(CGRect)frame image:(NSString *)image{
if (self = [super initWithFrame:frame]) {
[self setUpViews];
[self setImage:image placeHolder:nil];
}
return self;
}
- (void)setUpViews {
self.delegate = self;
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
//设置最大放大倍数
self.minimumZoomScale = 1.0;
self.maximumZoomScale = 2.0;
//粘贴一张图片
_imageView = [[UIImageView alloc] init];
_imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
_imageView.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 - 32);//保证居中
_imageView.contentMode = UIViewContentModeScaleAspectFit;
UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTapGesture setNumberOfTapsRequired:2];
[_imageView addGestureRecognizer:doubleTapGesture];
_imageView.userInteractionEnabled = YES;
[self addSubview:_imageView];
}
- (void)setImage:(id)image placeHolder:(UIImage *)placeHolder{
//每次重新设置图片的时候设置缩放比例(场景是在做相册的时候)
self.zoomScale = 1.0;
if ([image isKindOfClass:[NSString class]]) {
if ([image hasPrefix:@"http://"]) {
NSURL *url = [NSURL URLWithString:image];
[_imageView sd_setImageWithURL:url placeholderImage:placeHolder];
}else{
_imageView.image=[UIImage imageNamed:image];
}
}else if ([image isKindOfClass:[UIImage class]]){
_imageView.image = image;
}
}
//双击定点缩放
- (void)handleDoubleTap:(UIGestureRecognizer *)gesture {
CGFloat zoomScale = self.zoomScale;
zoomScale = (zoomScale == 1.0) ? 2.0 : 1.0;
CGRect zoomRect = [self zoomRectForScale:zoomScale withCenter:[gesture locationInView:gesture.view]];
[self zoomToRect:zoomRect animated:YES];
}
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {
CGRect zoomRect;
zoomRect.size.height = self.frame.size.height / scale;
zoomRect.size.width = self.frame.size.width / scale;
zoomRect.origin.x = center.x - (zoomRect.size.width /2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height /2.0);
return zoomRect;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _imageView;
}
@end
//
// RepairAddPicTableViewCell.h
// patrol
//
// Created by Javen on 2016/10/23.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PicViewModel.h"
typedef void (^repairBlock)(void);
@interface InspectRepairAddPicTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layOut;
@property (weak, nonatomic) UIViewController *vc;
@property (strong, nonatomic) PicViewModel *viewModel;
/** 是否显示添加按钮 */
@property (nonatomic, copy) repairBlock blockReloadData;
- (void)configCellWithViewModel:(PicViewModel *)viewModel indexPath:(NSIndexPath *)indexPath target:(UIViewController *)target;
@end
//
// RepairAddPicTableViewCell.m
// patrol
//
// Created by Javen on 2016/10/23.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "InspectRepairAddPicTableViewCell.h"
#import "RepairAddPicCollectionViewCell.h"
#import "TZImagePickerController.h"
#import "GalleryViewController.h"
@interface InspectRepairAddPicTableViewCell () <UICollectionViewDelegate,
UICollectionViewDataSource>
@end
@implementation InspectRepairAddPicTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.layOut.itemSize = kPicCellSize;
self.layOut.minimumInteritemSpacing = 10;
self.layOut.minimumLineSpacing = 10;
self.layOut.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
// Initialization code
}
- (void)configCellWithViewModel:(PicViewModel *)viewModel indexPath:(NSIndexPath *)indexPath target:(UIViewController *)target {
self.vc = target;
self.viewModel = viewModel;
//如果是只读的,则直接刷新。
if (self.viewModel.type == kPicCellTypeRead) {
[self.collectionView reloadData];
return;
}
//非只读情况,则是添加或者编辑
if (self.viewModel.arrPics.count == kMaxAddRepairImgNumber) {
self.viewModel.type = kPicCellTypeEdit;
} else {
self.viewModel.type = kPicCellTypeAdd;
}
[self.collectionView reloadData];
}
#pragma mark - collectionView DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
switch (self.viewModel.type) {
case kPicCellTypeAdd: {
return self.viewModel.arrPics.count + 1;
break;
}
default: {
return self.viewModel.arrPics.count;
break;
}
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RepairAddPicCollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"RepairAddPicCollectionViewCell"
forIndexPath:indexPath];
[cell configCellWithArr:self.viewModel.arrPics indexPath:indexPath];
//删除
cell.blockDelete = ^(NSInteger index) {
};
return cell;
}
#pragma mark - collectionView DataSource
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
switch (self.viewModel.type) {
case kPicCellTypeRead: {
UIStoryboard *board = [UIStoryboard storyboardWithName:@"ZJPicture" bundle:nil];
GalleryViewController *galleryVC = [board instantiateViewControllerWithIdentifier:@"GalleryViewController"];
galleryVC.arrData = [self.viewModel.arrPics mutableCopy];
galleryVC.page = indexPath.item;
[self.vc.navigationController pushViewController:galleryVC animated:YES];
break;
}
default: {
if (indexPath.row == self.viewModel.arrPics.count) { //说明点击的是添加图片的那个按钮
[self pushImagePickerController];
} else { //点击查看大图
[self seePicsWithIndex:indexPath.item];
}
break;
}
}
}
#pragma mark - TZImagePickerController
- (void)pushImagePickerController {
CGFloat canSelectNum = kMaxAddRepairImgNumber;
TZImagePickerController *imagePickerVc =
[[TZImagePickerController alloc] initWithMaxImagesCount:canSelectNum - self.viewModel.arrPics.count delegate:nil];
imagePickerVc.isSelectOriginalPhoto = NO;
imagePickerVc.navigationBar.barTintColor = kMainColor;
imagePickerVc.oKButtonTitleColorNormal = kMainColor;
imagePickerVc.allowPickingOriginalPhoto = NO;
imagePickerVc.showSelectBtn = YES;
WS(weakSelf);
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
[weakSelf.viewModel.arrPics addObjectsFromArray:photos];
[weakSelf.collectionView reloadData];
weakSelf.blockReloadData();
}];
[self.vc presentViewController:imagePickerVc animated:YES completion:nil];
}
/**
查看大图
@param index 点击中的图片下标
*/
- (void)seePicsWithIndex:(NSInteger)index {
UIStoryboard *board = [UIStoryboard storyboardWithName:@"ZJPicture" bundle:nil];
GalleryViewController *galleryVC = [board instantiateViewControllerWithIdentifier:@"GalleryViewController"];
galleryVC.arrData = self.viewModel.arrPics;
galleryVC.page = index;
galleryVC.type = GalleryTypeEdit;
[self.vc.navigationController pushViewController:galleryVC animated:YES];
WS(weakSelf);
galleryVC.blockDelete = ^(NSInteger index) {
[weakSelf.collectionView reloadData];
weakSelf.blockReloadData();
};
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
//
// PicViewModel.h
// RealEstateManagement
//
// Created by Javen on 2017/1/6.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, kPicCellType) {
kPicCellTypeAdd = 0,
kPicCellTypeEdit,
kPicCellTypeRead
};
//图片的size
#define kPicCellSize CGSizeMake((kWidth - 30) / 2.0, (kWidth - 120) / 2.0)
//允许的最大图片数量
static CGFloat const kMaxAddRepairImgNumber = 2;
@interface PicViewModel : NSObject
@property (strong, nonatomic) NSMutableArray *arrPics;
@property(nonatomic, strong) NSMutableArray *selectedAssets;
/**
图片cell的类型
*/
@property (nonatomic, assign) kPicCellType type;
/**
获取cell的高度
@return 高度
*/
- (CGFloat)cellHeight;
@end
//
// PicViewModel.m
// RealEstateManagement
//
// Created by Javen on 2017/1/6.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "PicViewModel.h"
@implementation PicViewModel
/**
获取cell的高度
@return 高度
*/
- (CGFloat)cellHeight {
NSInteger picCount = self.arrPics.count;
//如果非只读的情况,则还需要多计算一个添加按钮的位置
if (self.type != kPicCellTypeRead) {
if (self.arrPics.count != kMaxAddRepairImgNumber) {
picCount += 1;
}
}
NSInteger div = picCount / 2;
NSInteger remainder = picCount % 2;
if (remainder != 0) {
div = div + 1;
}
return div * (kPicCellSize.height + 20);
}
- (NSMutableArray *)arrPics {
if (!_arrPics) {
_arrPics = [NSMutableArray array];
}
return _arrPics;
}
@end
//
// RepairAddPicCollectionViewCell.h
// patrol
//
// Created by Javen on 2016/10/23.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RepairAddPicCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UIImageView *imgPicture;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, copy) void (^blockDelete)(NSInteger index);
- (void)configCellWithArr:(NSMutableArray *)array indexPath:(NSIndexPath *)indexPath;
@end
//
// RepairAddPicCollectionViewCell.m
// patrol
//
// Created by Javen on 2016/10/23.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "RepairAddPicCollectionViewCell.h"
#import "ZJBaseFileModel.h"
@implementation RepairAddPicCollectionViewCell
- (void)awakeFromNib {
self.layer.borderColor = [UIColor colorWithWhite:0.902 alpha:1.000].CGColor;
self.layer.borderWidth = 1;
UILongPressGestureRecognizer *longPress =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(actionDelete)];
[self addGestureRecognizer:longPress];
}
- (void)configCellWithArr:(NSMutableArray *)array
indexPath:(NSIndexPath *)indexPath {
if (indexPath.row == array.count) { //说明是添加按钮
self.img.hidden = NO;
self.imgPicture.hidden = YES;
self.index = 999;
} else {
self.img.hidden = YES;
self.imgPicture.hidden = NO;
id imageUrl = array[indexPath.row];
if ([imageUrl isKindOfClass:[NSString class]]) {
if ([imageUrl hasPrefix:@"http://"]) {
[self.imgPicture setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"AttachPhoto"]];
} else {
self.imgPicture.image = [UIImage imageNamed:imageUrl];
}
} else if ([imageUrl isKindOfClass:[UIImage class]]) {
self.imgPicture.image = imageUrl;
} else if([imageUrl isKindOfClass:[ZJBaseFileModel class]]){
[(ZJBaseFileModel *)imageUrl setImageView:self.imgPicture];
}else if ([imageUrl isKindOfClass:[UIImage class]]){
self.imgPicture.image = imageUrl;
}
self.index = indexPath.row;
}
}
- (void)actionDelete {
self.blockDelete(self.index);
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Gallery View Controller-->
<scene sceneID="waG-zj-w2k">
<objects>
<viewController storyboardIdentifier="GalleryViewController" id="I3m-uw-YGR" customClass="GalleryViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="GB2-cx-312"/>
<viewControllerLayoutGuide type="bottom" id="i5t-uh-9Fc"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="0dd-Qj-Qxv">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" misplaced="YES" pagingEnabled="YES" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Usg-4T-ohG">
<rect key="frame" x="0.0" y="20" width="600" height="580"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="10" minimumInteritemSpacing="10" id="OpI-qP-qvn">
<size key="itemSize" width="352" height="270"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="GalleryCollectionViewCell" id="m7W-zF-sf7" customClass="GalleryCollectionViewCell">
<rect key="frame" x="0.0" y="0.0" width="352" height="270"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="352" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<color key="backgroundColor" red="0.81379991770000004" green="0.81370532510000004" blue="0.81376242639999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</collectionViewCell>
</cells>
<connections>
<outlet property="dataSource" destination="I3m-uw-YGR" id="WQ2-MQ-zFm"/>
<outlet property="delegate" destination="I3m-uw-YGR" id="ger-wt-x8g"/>
</connections>
</collectionView>
</subviews>
<color key="backgroundColor" red="1" green="0.99989593030000001" blue="0.99996638299999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Usg-4T-ohG" secondAttribute="trailing" id="BhJ-ur-hvI"/>
<constraint firstItem="Usg-4T-ohG" firstAttribute="top" secondItem="GB2-cx-312" secondAttribute="bottom" id="FLL-8U-wTI"/>
<constraint firstItem="i5t-uh-9Fc" firstAttribute="top" secondItem="Usg-4T-ohG" secondAttribute="bottom" id="Fgk-2a-HiZ"/>
<constraint firstItem="Usg-4T-ohG" firstAttribute="leading" secondItem="0dd-Qj-Qxv" secondAttribute="leading" id="uX0-wb-lGI"/>
</constraints>
</view>
<connections>
<outlet property="collectionView" destination="Usg-4T-ohG" id="VE3-j8-gu9"/>
<outlet property="flowLayout" destination="OpI-qP-qvn" id="uvf-qr-u5t"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="lgx-4B-scg" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1223" y="4220"/>
</scene>
</scenes>
</document>
...@@ -15,6 +15,7 @@ abstract_target 'hdmall_base' do ...@@ -15,6 +15,7 @@ abstract_target 'hdmall_base' do
pod 'MBProgressHUD', '~> 1.0.0' pod 'MBProgressHUD', '~> 1.0.0'
pod 'JSONKit-NoWarning', '~> 1.2' pod 'JSONKit-NoWarning', '~> 1.2'
pod 'RadioButton' pod 'RadioButton'
pod 'TZImagePickerController', '~> 1.8.4'
# target 'HDMall' do # target 'HDMall' do
# end # end
target 'HDMall_TEST' do target 'HDMall_TEST' do
......
...@@ -25,6 +25,7 @@ PODS: ...@@ -25,6 +25,7 @@ PODS:
- SDWebImage (3.7.6): - SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6) - SDWebImage/Core (= 3.7.6)
- SDWebImage/Core (3.7.6) - SDWebImage/Core (3.7.6)
- TZImagePickerController (1.8.4)
- UMengAnalytics-NO-IDFA (4.2.5) - UMengAnalytics-NO-IDFA (4.2.5)
DEPENDENCIES: DEPENDENCIES:
...@@ -38,6 +39,7 @@ DEPENDENCIES: ...@@ -38,6 +39,7 @@ DEPENDENCIES:
- MJRefresh (~> 3.1.2) - MJRefresh (~> 3.1.2)
- RadioButton - RadioButton
- SDWebImage (~> 3.7.4) - SDWebImage (~> 3.7.4)
- TZImagePickerController (~> 1.8.4)
- UMengAnalytics-NO-IDFA - UMengAnalytics-NO-IDFA
SPEC CHECKSUMS: SPEC CHECKSUMS:
...@@ -51,8 +53,9 @@ SPEC CHECKSUMS: ...@@ -51,8 +53,9 @@ SPEC CHECKSUMS:
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806 MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
RadioButton: 7ef053baf6ff0e7f9e777016c28e9ba4e330edba RadioButton: 7ef053baf6ff0e7f9e777016c28e9ba4e330edba
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TZImagePickerController: 612c79b572efd0363c7a966daad7a974c2d6b458
UMengAnalytics-NO-IDFA: 16666e32edce5be44ae5b14aaaa7f3582e09d6ab UMengAnalytics-NO-IDFA: 16666e32edce5be44ae5b14aaaa7f3582e09d6ab
PODFILE CHECKSUM: 45d261b414e3e681e520815408aeab2135ff9722 PODFILE CHECKSUM: c017ac8a85d92e34ba60fa747d2d9eca3dd63550
COCOAPODS: 1.2.1 COCOAPODS: 1.2.1
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