Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,22 @@
//
// IfishShopCerNewViewController.h
// Ifish
//
// Created by imac on 2017/5/4.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "BaseVIewContorller.h"
#import "ShopCertifyStausModel.h"
typedef NS_ENUM(NSInteger, ShopCerProgressType){
ShopCerProgressTypeStart = 0,
ShopCerProgressTypeSub = 1,
ShopCerProgressTypeDone = 2
};
@interface IfishShopCerNewViewController : BaseVIewContorller
@property(nonatomic) ShopCerProgressType cerProgressType;
@property (nonatomic,strong) ShopCertifyStausModel *statusM;
@end
@@ -0,0 +1,594 @@
//
// IfishShopCerNewViewController.m
// Ifish
//
// Created by imac on 2017/5/4.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishShopCerNewViewController.h"
#import "FishShopCer.h"
#import "ShopCerPart1InfoViewCell.h"
#import "ShopCerProgressHeaderView.h"
#import "ShopCerSelectImgViewCell.h"
#import "ShopCerPart3DoneViewCell.h"
#import "FishShopCer.h"
#define CELLUPLOADIMG_TAG 1
#import "CusomeCameraViewController.h"
#import "WFPhotosViewController.h"
#import "MBProgressHUD.h"
#import "UIImageView+WebCache.h"
@interface IfishShopCerNewViewController ()<UITableViewDelegate,UITableViewDataSource,ShopCerPart1InfoViewDelegate,UIActionSheetDelegate,MBProgressHUDDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) ShopCerProgressHeaderView *headerView;
@property (nonatomic,strong) FishShopCer *cerdata;
@property (nonatomic,strong) NSArray *uploadImgs;
@property(nonatomic) NSInteger selectTmg;
@property(nonatomic,strong)UIActionSheet*photosheet;
@property(nonatomic,strong)MBProgressHUD *HUD;
@property (nonatomic) BOOL isEditedInfo;
@property (nonatomic) BOOL sufaceUpload;
@property (nonatomic) BOOL backUpload;
@property (nonatomic) BOOL cerUpload;
@end
extern BOOL cerViewFormRootVC;
@implementation IfishShopCerNewViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"商家认证"];
_isEditedInfo =NO;
_sufaceUpload = NO;
_backUpload = NO;
_cerUpload = NO;
_cerdata = [[FishShopCer alloc] init];
_uploadImgs = [[NSArray alloc] init];
_cerProgressType = ShopCerProgressTypeStart;
[self creatTab];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
-(void)goBackAction{
//IOS 8
if (!_isEditedInfo) {
UIAlertController*al=[UIAlertController alertControllerWithTitle:@"" message:@"是否放弃当前操作" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:al animated:YES completion:nil];
[al addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
}]];
[al addAction:[UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
if (cerViewFormRootVC) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
return;
}
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}]];
}else{
if (cerViewFormRootVC) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
return;
}
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR;
self.tableView.bounces = NO;
[self.view addSubview:self.tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (_cerProgressType) {
case ShopCerProgressTypeStart:
{
ShopCerPart1InfoViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopCerPart1InfoViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"ShopCerPart1InfoViewCell" owner:self options:nil]lastObject];
}
cell.delegate = self;
if (self.statusM) {
[cell setStatem:self.statusM];
}
return cell;
}
break;
case ShopCerProgressTypeSub:
{
ShopCerSelectImgViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopCerSelectImgViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"ShopCerSelectImgViewCell" owner:self options:nil]lastObject];
}
[cell.supStepBtn addTarget:self action:@selector(supStepBtnAction) forControlEvents:UIControlEventTouchUpInside];
[cell.subBtn addTarget:self action:@selector(subBtnAction) forControlEvents:UIControlEventTouchUpInside];
cell.tag = CELLUPLOADIMG_TAG;
cell.iDsurface.userInteractionEnabled = YES;
UITapGestureRecognizer *surfaceTapgs =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(surfaceIDTap)];
[cell.iDsurface addGestureRecognizer:surfaceTapgs];
cell.iDback.userInteractionEnabled = YES;
UITapGestureRecognizer *idbackTapges =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(idbackTap)];
[cell.iDback addGestureRecognizer:idbackTapges];
cell.shopCer.userInteractionEnabled = YES;
UITapGestureRecognizer *shopCerTapgs =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shopCerTap)];
[cell.shopCer addGestureRecognizer:shopCerTapgs];
//获取系统当前的时间戳
if (self.statusM) {
_sufaceUpload = YES;
_backUpload = YES;
_cerUpload = YES;
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval time=[dat timeIntervalSince1970]*1000;
NSString *timeString = [NSString stringWithFormat:@"%.0f",time];
NSString *iDsurfaceUrl =[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture1,timeString];
[cell.iDsurface sd_setImageWithURL:[NSURL URLWithString:iDsurfaceUrl] placeholderImage:[UIImage imageNamed:@"live_hold.png"]];
NSString *iDbackUrl =[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture2,timeString];
[cell.iDback sd_setImageWithURL:[NSURL URLWithString:iDbackUrl] placeholderImage:[UIImage imageNamed:@"live_hold.png"]];
NSString *shopCerUrl =[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture3,timeString];
[cell.shopCer sd_setImageWithURL:[NSURL URLWithString:shopCerUrl] placeholderImage:[UIImage imageNamed:@"live_hold.png"]];
}
return cell;
}
break;
case ShopCerProgressTypeDone:
{
ShopCerPart3DoneViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopCerPart3DoneViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"ShopCerPart3DoneViewCell" owner:self options:nil]lastObject];
}
return cell;
}
break;
default:
break;
}
}
#pragma mark - 身份证正面
-(void)surfaceIDTap{
_selectTmg = 1;
[self picImgHandler];
}
#pragma mark - 身份证反面
-(void)idbackTap{
_selectTmg = 2;
[self picImgHandler];
}
#pragma mark - 营业执照
-(void)shopCerTap{
_selectTmg = 3;
[self picImgHandler];
}
-(void)picImgHandler{
self.photosheet=[[UIActionSheet alloc]initWithTitle:@"获取图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册选择", nil];
[self.photosheet showInView:self.view];
}
#pragma mark--UIActionSheetDelegate IOS7
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet==self.photosheet) {
if (buttonIndex==actionSheet.cancelButtonIndex) {
return;
}
switch (buttonIndex) {
case 0:
{
//相机
[self loadImgfromCamera];
}
break;
case 1:
{
//相册
[self loadImgfromPhotoBrowser];
}
break;
default:
break;
}
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return self.view.frame.size.height - 44 - 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10 + 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (!_headerView) {
_headerView =[[ShopCerProgressHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 54)];
}
[_headerView refreshLabeColor:_cerProgressType];
return _headerView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 下一步 part1
-(void)nextBtnClickAction:(FishShopCer *)cermodel{
[self upDateViewData:cermodel];
_cerProgressType = ShopCerProgressTypeSub;
[self.tableView reloadData];
}
//获取填写信息
-(void)upDateViewData:(FishShopCer *)cermodel{
self.cerdata = cermodel;
}
#pragma mark - 上一步part2
-(void)supStepBtnAction{
_cerProgressType = ShopCerProgressTypeStart;
[self.tableView reloadData];
[self.tableView setContentOffset:CGPointMake(0, -64) animated:NO];
}
#pragma mark - part1ImgDetagate
-(void)loadImgfromCamera{
//相机
CusomeCameraViewController *customVC= [[CusomeCameraViewController alloc] init]
;
customVC.tailoredImage = ^ (UIImage *image){
ShopCerSelectImgViewCell *cell = [self.view viewWithTag:CELLUPLOADIMG_TAG];
switch (self.selectTmg) {
case 1:
{
_sufaceUpload = YES;
cell.iDsurface.image = image;
}
break;
case 2:
{
_backUpload = YES;
cell.iDback.image = image;
}
break;
case 3:
{
_cerUpload = YES;
cell.shopCer.image= image;
}
break;
default:
break;
}
};
[self presentViewController:customVC animated:YES completion:nil];
}
-(void)loadImgfromPhotoBrowser{
//相册
UIImageWriteToSavedPhotosAlbum([[UIImage alloc] init], nil, nil, nil);
WFPhotosViewController *photosVC = [[WFPhotosViewController alloc] init];
UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:photosVC];
photosVC.tailoredImage = ^ (UIImage *image){
ShopCerSelectImgViewCell *cell = [self.view viewWithTag:CELLUPLOADIMG_TAG];
switch (self.selectTmg) {
case 1:
{
_sufaceUpload = YES;
cell.iDsurface.image = image;
}
break;
case 2:
{
_backUpload = YES;
cell.iDback.image = image;
}
break;
case 3:
{
_cerUpload = YES;
cell.shopCer.image= image;
}
break;
default:
break;
}
};
[self presentViewController:naviVC animated:YES completion:nil];
}
#pragma mark --选取完成后调用方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
[picker dismissViewControllerAnimated:YES completion:nil]
;
UIImage*img=[info objectForKey:UIImagePickerControllerEditedImage];
//UIImage *smallImage = [self thumbnailWithImageWithoutScale:img size:CGSizeMake(300.0f, 200.0f)];
UIImage *smallImage = [self scaleFromImage:img toSize:CGSizeMake(kScreenSize.width,kScreenSize.width*2/3)];
// NSData*imageData=UIImageJPEGRepresentation(smallImage,1.0f);// 1 不缩放保存
ShopCerSelectImgViewCell *cell = [self.view viewWithTag:CELLUPLOADIMG_TAG];
switch (self.selectTmg) {
case 1:
{
cell.iDsurface.image = smallImage;
}
break;
case 2:
{
cell.iDback.image = smallImage;
}
break;
case 3:
{
cell.shopCer.image= smallImage;
}
break;
default:
break;
}
}
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#pragma mark - 提交信息
-(void)subBtnAction
{
_HUD=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
_HUD.delegate=self;
ShopCerSelectImgViewCell *cell = [self.view viewWithTag:CELLUPLOADIMG_TAG];
//NSLog(@"提交信息:名字 %@,店铺 %@,电话 %@,地址 %@,详细地址 %@,img1 %@,img2 %@,img3 %@",_cerdata.userName,_cerdata.shopName,_cerdata.phoneNumber, _cerdata.shopPCA, _cerdata.shopAddress,cell.iDsurface.image,cell.iDback.image,cell.shopCer.image);
// if (cell.iDsurface.image==nil) {
//
// [self.view makeToast:@"请上传身份证正面图片"];
// return;
// }
//
// if (cell.iDback.image==nil) {
//
// [self.view makeToast:@"请上传身份证反面图片"];
// return;
// }
//
// if (cell.shopCer.image==nil) {
//
// [self.view makeToast:@"请上传营业执照图片"];
// return;
// }
if (!_sufaceUpload) {
[self.view makeToast:@"请上传身份证正面图片"];
return;
}
if (!_backUpload) {
[self.view makeToast:@"请上传身份证反面图片"];
return;
}
if (!_cerUpload) {
[self.view makeToast:@"请上传营业执照图片"];
return;
}
UserModel*user=[dataContorl getUserInfo];
NSData*imgdataFace=UIImagePNGRepresentation(cell.iDsurface.image);
NSData*imgdataBack=UIImagePNGRepresentation(cell.iDback.image);
NSData*imgdataZhiZhao=UIImagePNGRepresentation(cell.shopCer.image);
NSArray *imgDataArr=@[imgdataFace,imgdataBack,imgdataZhiZhao];
NSString *url = nil;
NSDictionary *paras=nil;
if (self.statusM) {
url=IfishUpdateShopsInfoV3;
//更新
paras= @{
@"shopsId":self.statusM.shopsId,
@"userId" :self.statusM.userId,
@"userName":_cerdata.userName,
@"shopsName":_cerdata.shopName,
@"shopsPhone":_cerdata.phoneNumber,
@"shopsProvince":_cerdata.privence,
@"shopsCity":_cerdata.city,
@"shopsArea":_cerdata.area,
@"shopsAddress":_cerdata.shopAddress,
@"file1":@"png",
@"file2":@"png",
@"file3":@"png",
@"weixinCode":@"",
@"shopLink":@""
};
}else{
//新加
paras= @{
@"userId":user.userId,
@"userName":_cerdata.userName,
@"shopsName":_cerdata.shopName,
@"shopsPhone":_cerdata.phoneNumber,
@"shopsProvince":_cerdata.privence,
@"shopsCity":_cerdata.city,
@"shopsArea":_cerdata.area,
@"shopsAddress":_cerdata.shopAddress,
@"file1":@"png",
@"file2":@"png",
@"file3":@"png",
@"weixinCode":@"",
@"shopLink":@""
};
url =IfishSaveShopsInfoV3;
}
__weak typeof (self)weskSelf=self;
[AFHttpTool saveShopsInfo:paras formatImgArr:imgDataArr requsetUrl:url success:^(id response) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSLog(@"result:%@",resultDic[@"result"]);
_isEditedInfo = YES;
if ([resultDic[@"result"] isEqualToString:@"100"]) {
NSDictionary*shopsInfoDic= resultDic[@"data"];
CertificationShopModel *shopInfo=[[CertificationShopModel alloc] initWithDict:shopsInfoDic];
[[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"];
_cerProgressType = ShopCerProgressTypeDone;
[_HUD hide:YES];
[weskSelf.tableView reloadData];
[weskSelf.tableView setContentOffset:CGPointMake(0, -64) animated:NO];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
[weskSelf.view makeToast:@"提交失败错误码101"];
}else if ([resultDic[@"result"] isEqualToString:@"206"]){
[weskSelf.view makeToast:@"提交失败错误码206上传图片太大"];
}else if ([resultDic[@"result"] isEqualToString:@"211"]){
[weskSelf.view makeToast:@"提交失败错误码211用户ID不能存在"];
}
[_HUD hide:YES];
} failure:^(NSError *err) {
[_HUD hide:YES];
[weskSelf.view makeToast:@"请求异常"];
_isEditedInfo = YES;
}];
}
/*
#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