ifish/Ifish/controllers/IfishTabControllers/探索/shopCertification/ShopCertificationViewContro...

1171 lines
37 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ShopCertificationViewController.m
// Ifish
//
// Created by imac on 16/8/17.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "ShopCertificationViewController.h"
#import "CertifyListViewFirstCell.h"
#import "CertifyListThridCell.h"
#import "CertifyListSecondCell.h"
#import "CertifyListFourthCell.h"
#define CERTYVIEW_CELLTAGROW0 1010100
#define CERTYVIEW_CELLTAGROW1 2020200
#define CERTYVIEW_CELLTAGROW2 3030300
#define CERTYVIEW_CELLTAGROW3 4040400
#define CERTYVIEW_CELLTAGROW4 5050500
//#define CERTYVIEW_CELLTAGROW5 6060600
#define CERTYVIEW_CELLTAGROW9 9090900
#define CERTYVIEW_CELLTAGROW6 7070700
#define CERTYVIEW_CELLTAGROWADD1 101000
#define CERTYVIEW_CELLTAGROWADD2 102000
#define CERTYVIEW_CELLTAGROWADD3 103000
#define CERTYVIEW_ADDBTNTAG1 66006
#define CERTYVIEW_ADDBTNTAG2 77007
#define CERTYVIEW_ADDBTNTAG3 88008
#import "IfishCertifyImgFile.h"
#import "ShopCertificationHtmlController.h"
#import "ChinaPlckerView.h"
#import <BaiduMapAPI_Location/BMKLocationService.h>
#import <BaiduMapAPI_Search/BMKSearchComponent.h>
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
#import "UIImageView+WebCache.h"
#import "ShopCertifyCheckViewController.h"
#import "CertificationShopModel.h"
#import "CusomeCameraViewController.h"
#import "WFPhotosViewController.h"
//v4.4 后更改UI 此界面废弃
@interface ShopCertificationViewController ()<UITableViewDelegate,
UITableViewDataSource,
UIImagePickerControllerDelegate,
UIActionSheetDelegate,
UITextFieldDelegate,
UINavigationControllerDelegate,
ChinaPlckerViewDelegate,
BMKLocationServiceDelegate,
BMKGeoCodeSearchDelegate,
UIGestureRecognizerDelegate>
{
BMKGeoCodeSearch*_geocodesearch;
}
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong) NSArray *titles;
@property(nonatomic,strong) NSArray *placeHolders;
@property(nonatomic,strong) NSArray *pictitles;
@property(nonatomic,strong)UIActionSheet*photosheet;
@property(nonatomic) NSInteger selectTag;
@property(nonatomic)BMKLocationService*locService;
@property(nonatomic,strong) NSString *privence;
@property(nonatomic,strong) NSString *city;
@property(nonatomic,strong) NSString *area;
@property(nonatomic,strong) NSString *address;
@property(nonatomic,strong) NSArray *textFeildTexts;
@end
@implementation ShopCertificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self addTitleViewWithTitle:@"认证"];
// Do any additional setup after loading the view.
self.privence = @"";
self.city = @"";
self.area = @"";
[self initData];
[self creatTab];
[self getLocation];
}
-(void)goBackAction{
//IOS 8
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"是否放弃当前操作" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:ac animated:YES completion:nil];
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
}]];
[ac addAction:[UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
[self.navigationController popViewControllerAnimated:YES];
}]];
}
-(void)viewWillAppear:(BOOL)animated{
_geocodesearch.delegate=self;// 此处记得不用的时候需要置nil
_locService.delegate=self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 禁用 iOS7 返回手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
-(void)viewWillDisappear:(BOOL)animated{
_locService.delegate=nil;
[super viewWillDisappear:animated];
// 开启
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
#pragma mark 定位
-(void)getLocation{
//初始化BMKLocationService
_locService=[[BMKLocationService alloc]init];
_locService.delegate=self;
//启动LocationService
[_locService startUserLocationService];
_geocodesearch=[[BMKGeoCodeSearch alloc]init];
}
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
//NSLog(@"heading is %@",userLocation.heading);
}
//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
//NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
[self reverseGeoCodeWithlatitude:userLocation.location.coordinate.latitude addlongitude:userLocation.location.coordinate.longitude];
// static dispatch_once_t disOnce;
// dispatch_once(&disOnce, ^ {
//
// [self reverseGeoCodeWithlatitude:userLocation.location.coordinate.latitude addlongitude:userLocation.location.coordinate.longitude];
// });
}
/**
* 地理反编码
*/
-(void)reverseGeoCodeWithlatitude:(CLLocationDegrees)latitude addlongitude:(CLLocationDegrees)longitude{
CLLocationCoordinate2D pt=(CLLocationCoordinate2D){latitude,longitude};
BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
reverseGeocodeSearchOption.reverseGeoPoint=pt;
BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
if(flag)
{
NSLog(@"反geo检索发送成功");
}
else
{
NSLog(@"反geo检索发送失败");
}
}
-(void)dealloc{
if (_geocodesearch!=nil) {
_geocodesearch=nil;
}
}
#pragma mark BMKGeoCodeSearchDelegate
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
NSLog(@"address%@",result.address);
self.address = result.address;
// CertifyListSecondCell *cell = [self.view viewWithTag:CERTYVIEW_CELLTAGROW6];
//
// if (cell) {
//
// cell.loactionLabel.text= result.address;
//
// }
static dispatch_once_t disOnce;
dispatch_once(&disOnce, ^ {
[self.tableView reloadData];
});
}
- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
}
-(void)initData{
self.titles = @[@"姓名:",@"店铺:",@"电话:",@"地址:",@""];
self.placeHolders = @[@"请填写和营业执照中一致的姓名",@"店铺名称",@"联系电话",@"省、市、区",@"请填写和营业执照一致的详情地址"];
self.pictitles = @[@"身份证正面",@"身份证反面",@"添加营业执照"];
if (self.statusM) {
NSString *addressStr=[NSString stringWithFormat:@"%@%@%@",self.statusM.shopsProvince,self.statusM.shopsCity,self.statusM.shopsArea];
self.textFeildTexts = @[self.statusM.userName,
self.statusM.shopsName,
self.statusM.shopsPhone,
addressStr,
self.statusM.shopsAddress];
self.privence = self.statusM.shopsProvince;
self.city = self.statusM.shopsCity;
self.area = self.statusM.shopsArea;
}
}
-(void)creatTab{
self.tableView = [[UITableView alloc] init ];
self.tableView.frame =CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height);
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = TABLE_HEADER_COLOR;
[self.view addSubview:self.tableView];
UITapGestureRecognizer*tabGestrueRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tabViewGestrue)];
tabGestrueRecognizer.delegate =self;
[self.tableView addGestureRecognizer:tabGestrueRecognizer];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[CertifyListThridCell class]]) {
return YES;
}
return NO;
}
-(void)tabViewGestrue{
[self hiddenKeybord];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row<=4) {
CertifyListViewFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListViewFirstCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListViewFirstCell" owner:self options:nil]lastObject];
}
if (indexPath.row == 3) {
cell.infoDetailTextfeild.text = [NSString stringWithFormat:@"%@%@%@",self.privence,self.city,self.area];
}
if (self.statusM) {
//已认证过
cell.infoDetailTextfeild.text = self.textFeildTexts[indexPath.row];
}else{
//未认证过
}
cell.infoDetailTextfeild.placeholder = self.placeHolders[indexPath.row];
cell.titleCatelabel.text = self.titles[indexPath.row];
cell.tag = (indexPath.row + 1)*1010100;
cell.infoDetailTextfeild.layer.masksToBounds = YES;
cell.infoDetailTextfeild.layer.cornerRadius = 5;
cell.infoDetailTextfeild.delegate = self;
UIView*kongbaiView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)];
cell.infoDetailTextfeild.leftView=kongbaiView;
cell.infoDetailTextfeild.leftViewMode=UITextFieldViewModeAlways;
if (indexPath.row == 2) {
cell.infoDetailTextfeild.keyboardType= UIKeyboardTypeNumberPad;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if (indexPath.row == 5){
CertifyListSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListSecondCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListSecondCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.dingWeiBtn.layer.masksToBounds = YES;
cell.dingWeiBtn.layer.cornerRadius = 5;
[cell.dingWeiBtn addTarget:self action:@selector(useLocationArea) forControlEvents:UIControlEventTouchUpInside];
cell.tag= CERTYVIEW_CELLTAGROW6;
if (self.address) {
cell.loactionLabel.text = self.address;
}
return cell;
}else if (indexPath.row > 5 && indexPath.row <=8){
CertifyListThridCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListThridCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListThridCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backImgView.layer.masksToBounds = YES;
cell.backImgView.layer.cornerRadius = 5;
cell.backImgView.userInteractionEnabled = YES;
cell.addLeiIXing.text = self.pictitles[indexPath.row - 6];
if (self.statusM) {
cell.addImgBtn.hidden = YES;
cell.addLeiIXing.hidden = YES;
NSString *imgUrl= nil;
//获取系统当前的时间戳
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval time=[dat timeIntervalSince1970]*1000;
NSString *timeString = [NSString stringWithFormat:@"%.0f",time];
switch (indexPath.row ) {
case 6:
{
imgUrl=[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture1,timeString];
}
break;
case 7:
{
imgUrl=[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture2,timeString];
}
break;
case 8:
{
imgUrl=[NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.statusM.userId,self.statusM.picture3,timeString];
}
break;
default:
break;
}
[cell.picImgView sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
}
//cell.
cell.addImgBtn.tag = indexPath.row * 11001;
cell.tag = CERTYVIEW_CELLTAGROWADD1 + (indexPath.row -6)*1000;
cell.picImgView.userInteractionEnabled = YES;
[cell.addImgBtn addTarget:self action:@selector(addImgAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}else if (indexPath.row == 9){
CertifyListFourthCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListFourthCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListFourthCell" owner:self options:nil]lastObject];
}
cell.tag= CERTYVIEW_CELLTAGROW9;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.xieYiBtn addTarget:self action:@selector(xieYiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.xieYiBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_tick_uncheck.png"] forState:UIControlStateNormal];
[cell.xieYiBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_tick_selected.png"] forState:UIControlStateSelected];
[cell.tiJiaoRenZheng addTarget:self action:@selector(tiJiaoRenZheng:) forControlEvents:UIControlEventTouchUpInside];
[cell.xieYiButton addTarget:self action:@selector(pushXieYiView) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
return nil;
}
#pragma mark - textField 代理
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
CertifyListViewFirstCell *cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROW3];
if (textField==cell.infoDetailTextfeild) {
[self xuanzeAddress];
return NO;
}else{
return YES;
}
}
#pragma mark- 省市区选择器
-(void)xuanzeAddress{
[ChinaPlckerView customChinaPicker:self superView:self.view];
}
#pragma mark - ChinaPlckerViewDelegate
- (void)chinaPlckerViewDelegateChinaModel:(ChinaArea *)chinaModel{
// CertifyListViewFirstCell *cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROW3];
//
//
// cell.infoDetailTextfeild.text = [NSString stringWithFormat:@"%@%@%@",chinaModel.provinceModel.NAME,chinaModel.cityModel.NAME,chinaModel.areaModel.NAME];
self.privence = chinaModel.provinceModel.NAME;
self.city = chinaModel.cityModel.NAME;
self.area = chinaModel.areaModel.NAME;
if (self.statusM) {
NSString *addressStr=[NSString stringWithFormat:@"%@%@%@",self.privence, self.city,self.area];
self.textFeildTexts = @[self.statusM.userName,
self.statusM.shopsName,
self.statusM.shopsPhone,
addressStr,
self.statusM.shopsAddress];
}
[self.tableView reloadData];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat rowH = kScreenSize.width * 2/3;
if (indexPath.row <=4){
return 60;
}else if (indexPath.row == 5){
return 70;
}else if (indexPath.row > 5 && indexPath.row <=8){
return rowH;
}else if (indexPath.row == 9){
return 100;
}
return 0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 6) {
self.selectTag = 1;
[self picImgHandler];
}else if (indexPath.row == 7){
self.selectTag = 2;
[self picImgHandler];
}else if (indexPath.row == 8){
self.selectTag = 3;
[self picImgHandler];
}
}
#pragma mark- 使用定位地址
-(void)useLocationArea{
CertifyListViewFirstCell *cell5 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW4];
CertifyListSecondCell *cell6 = [self.view viewWithTag:CERTYVIEW_CELLTAGROW6];
cell5.infoDetailTextfeild.text =cell6.loactionLabel.text;
}
#pragma mark - 添加照片
-(void)addImgAction:(UIButton*)button{
switch (button.tag) {
case CERTYVIEW_ADDBTNTAG1:
{
self.selectTag = 1;
}
break;
case CERTYVIEW_ADDBTNTAG2:
{
self.selectTag = 2;
}
break;
case CERTYVIEW_ADDBTNTAG3:
{
self.selectTag = 3;
}
break;
default:
break;
}
[self picImgHandler];
}
-(void)picImgHandler{
/*if (IFISHIOS8) {
UIAlertController*alertCT=[UIAlertController alertControllerWithTitle:@"获取图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
// 判断是否支持相机 模拟器无相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertAction*action=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 相机
UIImagePickerController *imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate=self;
imagePicker.allowsEditing=YES;
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:nil];
}];
[alertCT addAction:action];
}
UIAlertAction*action1=[UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//相册
UIImagePickerController*imgpic=[[UIImagePickerController alloc]init];
imgpic.delegate=self;
imgpic.allowsEditing=YES;
imgpic.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imgpic animated:YES completion:nil];
}];
[alertCT addAction:action1];
UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alertCT addAction:cancelAction];
[self presentViewController:alertCT animated:YES completion:nil];
}else{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.photosheet=[[UIActionSheet alloc]initWithTitle:@"获取图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册选择", nil];
}
[self.photosheet showInView:self.view];
}*/
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 creatImagePickVCWithSourceType:UIImagePickerControllerSourceTypeCamera];
CusomeCameraViewController *customVc= [[CusomeCameraViewController alloc] init]
;
customVc.tailoredImage = ^ (UIImage *image){
CertifyListThridCell *cell = nil;
switch (self.selectTag) {
case 1:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD1];
}
break;
case 2:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD2];
}
break;
case 3:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD3];
}
break;
default:
break;
}
cell.picImgView.image = image;
cell.addImgBtn.hidden= YES;
cell.addLeiIXing.hidden = YES;
};
[self.navigationController presentViewController:customVc animated:YES completion:^{
}];
}
break;
case 1:
{
UIImageWriteToSavedPhotosAlbum([[UIImage alloc] init], nil, nil, nil);
WFPhotosViewController *photosVC = [[WFPhotosViewController alloc] init];
UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:photosVC];
photosVC.tailoredImage = ^ (UIImage *image){
CertifyListThridCell *cell = nil;
switch (self.selectTag) {
case 1:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD1];
}
break;
case 2:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD2];
}
break;
case 3:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD3];
}
break;
default:
break;
}
cell.picImgView.image = image;
cell.addImgBtn.hidden= YES;
cell.addLeiIXing.hidden = YES;
};
[self presentViewController:naviVC animated:YES completion:nil];
}
break;
default:
break;
}
}
}
#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 不缩放保存
CertifyListThridCell *cell = nil;
switch (self.selectTag) {
case 1:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD1];
}
break;
case 2:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD2];
}
break;
case 3:
{
cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROWADD3];
}
break;
default:
break;
}
cell.picImgView.image = smallImage;
cell.addImgBtn.hidden= YES;
cell.addLeiIXing.hidden = YES;
}
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
UIImage *newimage;
if (nil == image) {
newimage = nil;
}
else{
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height) {
rect.size.width = asize.width*oldsize.height/oldsize.width;
// rect.size.height = asize.height*oldsize.height/oldsize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
}
else{
//rect.size.width = asize.width;
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height*oldsize.width/oldsize.height;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
#pragma mark-处理收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self hiddenKeybord];
}
-(void)hiddenKeybord{
CertifyListViewFirstCell *cell1 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW0];
[cell1.infoDetailTextfeild resignFirstResponder];
CertifyListViewFirstCell *cell2 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW1];
[cell2.infoDetailTextfeild resignFirstResponder];
CertifyListViewFirstCell *cell3 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW2];
[cell3.infoDetailTextfeild resignFirstResponder];
CertifyListViewFirstCell *cell4 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW3];
[cell4.infoDetailTextfeild resignFirstResponder];
CertifyListViewFirstCell *cell5 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW4];
[cell5.infoDetailTextfeild resignFirstResponder];
}
#pragma mark- 协议
-(void)xieYiBtnClick:(UIButton*)btn{
btn.selected =! btn.selected;
CertifyListFourthCell *cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROW9];
if (btn.selected == YES) {
cell.tiJiaoRenZheng.userInteractionEnabled=NO;
cell.tiJiaoRenZheng.backgroundColor=[UIColor lightGrayColor];
}else{
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
cell.tiJiaoRenZheng.backgroundColor = COLOR_LABEL_TITLE;
}
}
#pragma mark- 商户接入协议
-(void)pushXieYiView{
ShopCertificationHtmlController *htmlview=[[ShopCertificationHtmlController alloc] init];
[self.navigationController pushViewController:htmlview animated:YES];
}
#pragma mark - 提交认证
-(void)tiJiaoRenZheng:(UIButton *)btn{
CertifyListViewFirstCell *cell1 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW0];
CertifyListViewFirstCell *cell2 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW1];
CertifyListViewFirstCell *cell3 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW2];
CertifyListViewFirstCell *cell4 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW3];
CertifyListViewFirstCell *cell5 =[self.view viewWithTag:CERTYVIEW_CELLTAGROW4];
CertifyListThridCell *celladd1 = [self.view viewWithTag:CERTYVIEW_CELLTAGROWADD1];
CertifyListThridCell *celladd2 = [self.view viewWithTag:CERTYVIEW_CELLTAGROWADD2];
CertifyListThridCell *celladd3 = [self.view viewWithTag:CERTYVIEW_CELLTAGROWADD3];
if (cell1.infoDetailTextfeild.text.length>6 ||cell1.infoDetailTextfeild.text.length == 0 ) {
[self.view makeToast:@"用户名不能超过6个汉字"];
return;
}
if (cell2.infoDetailTextfeild.text.length>10 ||cell2.infoDetailTextfeild.text.length == 0) {
[self.view makeToast:@"店铺名不能超过10汉字"];
return;
}
// NSString * MOBILE = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
// NSPredicate*regextestmobile=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];
// BOOL isMacth=[regextestmobile evaluateWithObject:cell3.infoDetailTextfeild.text];
//
//
// if (!isMacth) {
//
// [self.view makeToast:@"请正确输入小于11位电话号码"];
// return;
//
// }
if (cell3.infoDetailTextfeild.text.length ==0 || cell3.infoDetailTextfeild.text.length >11) {
[self.view makeToast:@"请正确输入正确的手机号或电话"];
return;
}
if (cell5.infoDetailTextfeild.text.length>20 ||cell5.infoDetailTextfeild.text.length == 0) {
[self.view makeToast:@"详情地址不能超过20个字"];
return;
}
if (celladd1.picImgView.image==nil) {
[self.view makeToast:@"请上传身份证正面图片"];
return;
}
if (celladd2.picImgView.image==nil) {
[self.view makeToast:@"请上传身份证反面图片"];
return;
}
if (celladd3.picImgView.image==nil) {
[self.view makeToast:@"请上传营业执照图片"];
return;
}
if (cell4.infoDetailTextfeild.text.length == 0) {
[self.view makeToast:@"请选择省市区"];
return;
}
[self.view makeToastActivity];
CertifyListFourthCell *cell =[self.view viewWithTag:CERTYVIEW_CELLTAGROW9];
cell.tiJiaoRenZheng.userInteractionEnabled=NO;
//cell.tiJiaoRenZheng.backgroundColor=[UIColor lightGrayColor];
UserModel*user=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
if (self.privence==nil) {
self.privence = @"";
}
if (self.city==nil) {
self.city = @"";
}
if (self.area ==nil) {
//有省份无地区
self.area =@"";
}
//服务器上传文件的字段和类型
// NSData*data=UIImageJPEGRepresentation(celladd1.picImgView.image,1);
NSData*imgdataFace=UIImagePNGRepresentation(celladd1.picImgView.image);
NSData*imgdataBack=UIImagePNGRepresentation(celladd2.picImgView.image);
NSData*imgdataZhiZhao=UIImagePNGRepresentation(celladd3.picImgView.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":cell1.infoDetailTextfeild.text,
@"shopsName":cell2.infoDetailTextfeild.text,
@"shopsPhone":cell3.infoDetailTextfeild.text,
@"shopsProvince":self.privence,
@"shopsCity":self.city,
@"shopsArea":self.area,
@"shopsAddress":cell5.infoDetailTextfeild.text,
@"file1":@"png",
@"file2":@"png",
@"file3":@"png",
@"weixinCode":@"",
@"shopLink":@""
};
}else{
paras= @{
@"userId":user.userId,
@"userName":cell1.infoDetailTextfeild.text,
@"shopsName":cell2.infoDetailTextfeild.text,
@"shopsPhone":cell3.infoDetailTextfeild.text,
@"shopsProvince":self.privence,
@"shopsCity":self.city,
@"shopsArea":self.area,
@"shopsAddress":cell5.infoDetailTextfeild.text,
@"file1":@"png",
@"file2":@"png",
@"file3":@"png",
@"weixinCode":@"",
@"shopLink":@""
};
url =IfishSaveShopsInfoV3;
}
[AFHttpTool saveShopsInfo:paras formatImgArr:imgDataArr requsetUrl:url success:^(id response) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSLog(@"result:%@",resultDic[@"result"]);
[self.view hideToastActivity];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
[self.view makeToast:@"提交成功"];
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
NSDictionary*shopsInfoDic= resultDic[@"data"];
CertificationShopModel *shopInfo=[[CertificationShopModel alloc] init];
shopInfo.picture1 = shopsInfoDic[@"picture1"];
shopInfo.picture2 = shopsInfoDic[@"picture2"];
shopInfo.picture3 = shopsInfoDic[@"picture3"];
shopInfo.picture4 = shopsInfoDic[@"picture4"];
shopInfo.reason = shopsInfoDic[@"reason"];
shopInfo.shopsAddress = shopsInfoDic[@"shopsAddress"];
shopInfo.shopsArea = shopsInfoDic[@"shopsArea"];
shopInfo.shopsCity = shopsInfoDic[@"shopsCity"];
shopInfo.shopsId = shopsInfoDic[@"shopsId"];
shopInfo.shopsName = shopsInfoDic[@"shopsName"];
shopInfo.shopsPhone = shopsInfoDic[@"shopsPhone"];
shopInfo.shopsProvince = shopsInfoDic[@"shopsProvince"];
shopInfo.status = shopsInfoDic[@"status"];
shopInfo.userId = shopsInfoDic[@"userId"];
shopInfo.userName = shopsInfoDic[@"userName"];
shopInfo.userImg = shopsInfoDic[@"userImg"];
shopInfo.wechat = shopsInfoDic[@"weixinCode"];
shopInfo.shoplink = shopsInfoDic[@"shopLink"];
[[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"];
ShopCertifyCheckViewController *cheackVc=[[ShopCertifyCheckViewController alloc] initWithNibName:@"ShopCertifyFailViewController" bundle:nil];
[self.navigationController pushViewController:cheackVc animated:YES];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
[self.view makeToast:@"提交失败错误码101"];
}else if ([resultDic[@"result"] isEqualToString:@"206"]){
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
[self.view makeToast:@"提交失败错误码206上传图片太大"];
}else if ([resultDic[@"result"] isEqualToString:@"211"]){
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
[self.view makeToast:@"提交失败错误码211用户ID不能存在"];
}
} failure:^(NSError *err) {
cell.tiJiaoRenZheng.userInteractionEnabled=YES;
[self.view makeToast:@"提交失败,请检查网络"];
NSLog(@"error:%@",err);
}];
}
@end