972 lines
30 KiB
Objective-C
972 lines
30 KiB
Objective-C
//
|
||
// ShopEditViewController.m
|
||
// Ifish
|
||
//
|
||
// Created by imac on 16/8/24.
|
||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||
//
|
||
|
||
#import "ShopEditViewController.h"
|
||
#import "CertifyListViewFirstCell.h"
|
||
#import "CertifyListSecondCell.h"
|
||
#import "shopEditViewImgCell.h"
|
||
#define CELLMODYF_LOACTON 4440440
|
||
#define CLLSHENGSHIQU_LOACTON 2220220
|
||
#define CLLDETALADDRESS 3330330
|
||
#define CELLPHONE 1110110
|
||
|
||
#define CELLADDIMG 5550550
|
||
#define CELLTIJIAOBTN 6660660
|
||
#import "ChinaPlckerView.h"
|
||
#import "CertifyListFourthCell.h"
|
||
#import <BaiduMapAPI_Location/BMKLocationService.h>
|
||
#import <BaiduMapAPI_Search/BMKSearchComponent.h>
|
||
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
|
||
#import "UIImageView+WebCache.h"
|
||
#import "ShopCertificationHtmlController.h"
|
||
@interface ShopEditViewController ()<UITableViewDelegate,
|
||
UITableViewDataSource,
|
||
UITextFieldDelegate,
|
||
UIImagePickerControllerDelegate,
|
||
UIActionSheetDelegate,
|
||
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) NSString *address;
|
||
@property(nonatomic)BMKLocationService*locService;
|
||
@property(nonatomic,strong) NSString *privence;
|
||
@property(nonatomic,strong) NSString *city;
|
||
@property(nonatomic,strong) NSString *area;
|
||
@property(nonatomic,strong)UIActionSheet*photosheet;
|
||
@property(nonatomic)BOOL isUpdate;
|
||
|
||
@end
|
||
|
||
@implementation ShopEditViewController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
// Do any additional setup after loading the view.
|
||
_isUpdate = NO;
|
||
self.title = @"修改资料";
|
||
[self creatTab];
|
||
self.titles = @[@"电话:",@"地址:",@""];
|
||
self.placeHolders = @[@"联系电话",@"省、市、区",@"请填写和营业执照一致的详情地址"];
|
||
self.privence = self.shopInfo.shopsProvince;
|
||
self.city = self.shopInfo.shopsCity;
|
||
self.area = self.shopInfo.shopsArea;
|
||
|
||
[self getLocation];
|
||
|
||
}
|
||
#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:CELLMODYF_LOACTON];
|
||
|
||
if (cell) {
|
||
|
||
cell.loactionLabel.text= self.address;
|
||
|
||
}
|
||
|
||
static dispatch_once_t disOnce;
|
||
dispatch_once(&disOnce, ^ {
|
||
|
||
[self.tableView reloadData];
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
|
||
|
||
|
||
}
|
||
|
||
|
||
-(void)goBackAction{
|
||
|
||
|
||
//IOS 8
|
||
if (_isUpdate) {
|
||
|
||
[self.navigationController popViewControllerAnimated:YES];
|
||
return;
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
// Dispose of any resources that can be recreated.
|
||
}
|
||
|
||
-(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_BACKGROUD_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:[shopEditViewImgCell class]]) {
|
||
|
||
return YES;
|
||
}
|
||
|
||
return NO;
|
||
|
||
|
||
}
|
||
|
||
-(void)tabViewGestrue{
|
||
|
||
[self hiddenKeybord];
|
||
}
|
||
|
||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||
|
||
return 6;
|
||
|
||
}
|
||
|
||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||
|
||
|
||
return 1;
|
||
}
|
||
|
||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
if (indexPath.row <= 2) {
|
||
|
||
CertifyListViewFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListViewFirstCell"];
|
||
if (!cell) {
|
||
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListViewFirstCell" owner:self options:nil]lastObject];
|
||
|
||
}
|
||
|
||
cell.infoDetailTextfeild.placeholder = self.placeHolders[indexPath.row];
|
||
if (indexPath.row ==0) {
|
||
cell.infoDetailTextfeild.text = self.shopInfo.shopsPhone;
|
||
}else if (indexPath.row ==1){
|
||
cell.infoDetailTextfeild.text = [NSString stringWithFormat:@"%@%@%@",self.privence,self.city,self.area];
|
||
|
||
}else if (indexPath.row ==2){
|
||
|
||
cell.infoDetailTextfeild.text = self.shopInfo.shopsAddress;
|
||
|
||
}
|
||
|
||
|
||
cell.titleCatelabel.text = self.titles[indexPath.row];
|
||
|
||
cell.tag = (indexPath.row + 1)*1110110;
|
||
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 == 0) {
|
||
|
||
cell.infoDetailTextfeild.keyboardType= UIKeyboardTypeNumberPad;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
return cell;
|
||
|
||
|
||
}else if (indexPath.row == 3){
|
||
|
||
|
||
|
||
CertifyListSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListSecondCell"];
|
||
if (!cell) {
|
||
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListSecondCell" owner:self options:nil]lastObject];
|
||
|
||
}
|
||
|
||
|
||
cell.dingWeiBtn.layer.masksToBounds = YES;
|
||
cell.dingWeiBtn.layer.cornerRadius = 5;
|
||
[cell.dingWeiBtn addTarget:self action:@selector(useLocationArea) forControlEvents:UIControlEventTouchUpInside];
|
||
cell.tag= CELLMODYF_LOACTON;
|
||
|
||
if (self.address) {
|
||
cell.loactionLabel.text = self.address;
|
||
|
||
}
|
||
|
||
|
||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
||
return cell;
|
||
|
||
|
||
}else if (indexPath.row == 4){
|
||
|
||
shopEditViewImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"shopEditViewImgCell"];
|
||
if (!cell) {
|
||
cell = [[[NSBundle mainBundle]loadNibNamed:@"shopEditViewImgCell" owner:self options:nil]lastObject];
|
||
|
||
}
|
||
cell.tag = CELLADDIMG ;
|
||
cell.zhaoPaiImg.userInteractionEnabled = YES;
|
||
|
||
if (![self.shopInfo.picture4 isEqualToString:@""]) {
|
||
cell.addImgBtn.hidden = YES;
|
||
cell.shangchuanLabel.hidden = YES;
|
||
|
||
//获取系统当前的时间戳
|
||
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||
NSTimeInterval time=[dat timeIntervalSince1970]*1000;
|
||
NSString *timeString = [NSString stringWithFormat:@"%.0f",time];
|
||
|
||
NSString * imgUrl = [NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.shopInfo.userId,self.shopInfo.picture4,timeString];
|
||
|
||
[cell.zhaoPaiImg sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
|
||
|
||
}else{
|
||
cell.addImgBtn.hidden = NO;
|
||
cell.shangchuanLabel.hidden = NO;
|
||
}
|
||
|
||
|
||
//获取系统当前的时间戳
|
||
|
||
// NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||
// NSTimeInterval time=[dat timeIntervalSince1970]*1000;
|
||
// NSString *timeString = [NSString stringWithFormat:@"%.0f",time];
|
||
//
|
||
// NSString * imgUrl = [NSString stringWithFormat:@"%@/shops/%@/%@?time=%@",JIEKOUPORTHTTP,self.shopInfo.userId,self.shopInfo.picture4,timeString];
|
||
//
|
||
// [cell.zhaoPaiImg sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
|
||
//
|
||
// if (cell.zhaoPaiImg.image) {
|
||
// cell.addImgBtn.hidden = YES;
|
||
// cell.shangchuanLabel.hidden = YES;
|
||
//
|
||
// }else{
|
||
//
|
||
// cell.addImgBtn.hidden = NO;
|
||
// cell.shangchuanLabel.hidden = NO;
|
||
// }
|
||
|
||
|
||
[cell.addImgBtn addTarget:self action:@selector(addImgAction:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
|
||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
return cell;
|
||
|
||
|
||
}else if (indexPath.row == 5){
|
||
|
||
|
||
CertifyListFourthCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CertifyListFourthCell"];
|
||
if (!cell) {
|
||
cell = [[[NSBundle mainBundle]loadNibNamed:@"CertifyListFourthCell" owner:self options:nil]lastObject];
|
||
|
||
}
|
||
|
||
cell.tag = CELLTIJIAOBTN;
|
||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
||
cell.xieYiBtn.hidden = YES;
|
||
|
||
[cell.tiJiaoRenZheng addTarget:self action:@selector(tiJiaoRenZheng:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
[cell.tiJiaoRenZheng setTitle:@"确认修改" forState:UIControlStateNormal];
|
||
cell.xieYiButton.hidden = YES;
|
||
|
||
|
||
return cell;
|
||
|
||
}
|
||
|
||
return nil;
|
||
|
||
}
|
||
|
||
|
||
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
|
||
|
||
CGFloat rowH = kScreenSize.width * 2/3;
|
||
|
||
if (indexPath.row <=2){
|
||
|
||
return 60;
|
||
|
||
|
||
}else if (indexPath.row == 3){
|
||
|
||
|
||
return 70;
|
||
|
||
|
||
}else if (indexPath.row == 4){
|
||
|
||
return rowH;
|
||
|
||
|
||
}else if (indexPath.row == 5){
|
||
|
||
return 100;
|
||
|
||
|
||
}
|
||
|
||
return 0;
|
||
|
||
}
|
||
|
||
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
CertifyListViewFirstCell *cell =[self.view viewWithTag:CELLPHONE];
|
||
[cell.infoDetailTextfeild resignFirstResponder];
|
||
|
||
|
||
if (indexPath.row == 4) {
|
||
|
||
[self picImgHandler];
|
||
}
|
||
}
|
||
|
||
|
||
#pragma mark - textField 代理
|
||
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
|
||
{
|
||
|
||
CertifyListViewFirstCell *cell =[self.view viewWithTag:CLLSHENGSHIQU_LOACTON];
|
||
|
||
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;
|
||
|
||
|
||
[self.tableView reloadData];
|
||
|
||
}
|
||
|
||
|
||
#pragma mark - 使用定位地址
|
||
|
||
|
||
-(void)useLocationArea{
|
||
|
||
|
||
CertifyListViewFirstCell *cell =[self.view viewWithTag:CLLDETALADDRESS];
|
||
|
||
CertifyListSecondCell *lactioncell = [self.view viewWithTag:CELLMODYF_LOACTON];
|
||
self.shopInfo.shopsAddress= lactioncell.loactionLabel.text;
|
||
cell.infoDetailTextfeild.text = lactioncell.loactionLabel.text;
|
||
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - 招牌选择按钮
|
||
|
||
-(void)addImgAction:(UIButton *)btn{
|
||
|
||
[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];
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
#pragma mark--UIActionSheetDelegate IOS7
|
||
|
||
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||
|
||
if (actionSheet==self.photosheet) {
|
||
if (buttonIndex==actionSheet.cancelButtonIndex) {
|
||
return;
|
||
}
|
||
NSUInteger sourceType=0;
|
||
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
|
||
|
||
|
||
switch (buttonIndex) {
|
||
case 0:
|
||
{
|
||
sourceType=UIImagePickerControllerSourceTypeCamera;
|
||
|
||
|
||
}
|
||
|
||
break;
|
||
case 1:
|
||
{
|
||
sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
|
||
|
||
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
}else{
|
||
|
||
if (buttonIndex==1) {
|
||
sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
|
||
}
|
||
}
|
||
// 转跳页面
|
||
UIImagePickerController*imgPic=[[UIImagePickerController alloc]init];
|
||
imgPic.delegate=self;
|
||
imgPic.allowsEditing=YES;
|
||
imgPic.sourceType=sourceType;
|
||
[self presentViewController:imgPic 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 不缩放保存
|
||
|
||
shopEditViewImgCell *cell = [self.view viewWithTag:CELLADDIMG];
|
||
cell.zhaoPaiImg.image = smallImage;
|
||
cell.addImgBtn.hidden= YES;
|
||
cell.shangchuanLabel.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:CLLDETALADDRESS];
|
||
[cell1.infoDetailTextfeild resignFirstResponder];
|
||
CertifyListViewFirstCell *cell2 =[self.view viewWithTag:CELLPHONE];
|
||
[cell2.infoDetailTextfeild resignFirstResponder];
|
||
|
||
|
||
}
|
||
|
||
#pragma mark- 协议
|
||
|
||
-(void)xieYiBtnClick:(UIButton*)btn{
|
||
|
||
btn.selected =! btn.selected;
|
||
CertifyListFourthCell *cell =[self.view viewWithTag:CELLTIJIAOBTN];
|
||
|
||
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:CELLPHONE];
|
||
|
||
CertifyListViewFirstCell *cell2 =[self.view viewWithTag:CLLSHENGSHIQU_LOACTON];
|
||
|
||
CertifyListViewFirstCell *cell3 =[self.view viewWithTag:CLLDETALADDRESS];
|
||
|
||
|
||
|
||
shopEditViewImgCell *celladd = [self.view viewWithTag:CELLADDIMG];
|
||
|
||
|
||
|
||
if (cell1.infoDetailTextfeild.text.length ==0 || cell1.infoDetailTextfeild.text.length >11) {
|
||
|
||
[self.view makeToast:@"请正确输入正确的手机号或电话"];
|
||
|
||
return;
|
||
|
||
|
||
}
|
||
|
||
|
||
if (cell3.infoDetailTextfeild.text.length>20 ||cell3.infoDetailTextfeild.text.length == 0) {
|
||
|
||
[self.view makeToast:@"详情地址不能超过20个字"];
|
||
|
||
return;
|
||
|
||
}
|
||
|
||
|
||
|
||
if (cell2.infoDetailTextfeild.text.length == 0) {
|
||
[self.view makeToast:@"请选择省市区"];
|
||
return;
|
||
|
||
}
|
||
|
||
[self.view makeToastActivity];
|
||
|
||
|
||
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager manager];
|
||
manager.requestSerializer = [AFJSONRequestSerializer serializer];
|
||
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||
|
||
if (self.privence==nil) {
|
||
|
||
self.privence = @"无";
|
||
}
|
||
|
||
if (self.city==nil) {
|
||
self.city = @"无";
|
||
|
||
}
|
||
|
||
if (self.area ==nil) {
|
||
//有省份无地区
|
||
self.area =@"无";
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/* NSString *url = IfishUpdateBaseShopsInfo;
|
||
|
||
NSDictionary *paras = @{
|
||
@"shopsId":self.shopInfo.shopsId,
|
||
@"shopsPhone":cell1.infoDetailTextfeild.text,
|
||
@"shopsProvince":self.privence,
|
||
@"shopsCity":self.city,
|
||
@"shopsArea":self.area,
|
||
@"shopsAddress":cell3.infoDetailTextfeild.text,
|
||
@"file4":@"png"
|
||
};
|
||
|
||
|
||
[manager POST:url parameters:paras constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
||
|
||
|
||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||
|
||
formatter.dateFormat = @"yyyyMMddHHmmss";
|
||
|
||
NSString *str = [formatter stringFromDate:[NSDate date]];
|
||
|
||
NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
|
||
|
||
NSString *name = [NSString stringWithFormat:@"file%d",4];
|
||
|
||
|
||
NSData* imgdata=UIImagePNGRepresentation(celladd.zhaoPaiImg.image);
|
||
|
||
|
||
if (celladd.zhaoPaiImg.image) {
|
||
[formData appendPartWithFileData:imgdata name:name fileName:fileName mimeType:@"image/png"];
|
||
}
|
||
|
||
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||
|
||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||
NSLog(@"result:%@",resultDic[@"result"]);
|
||
[self.view hideToastActivity];
|
||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self.view makeToast:@"提交成功"];
|
||
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"];
|
||
|
||
[[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"];
|
||
|
||
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||
|
||
[self.view makeToast:@"提交失败错误码101"];
|
||
}
|
||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||
|
||
[self.view makeToast:@"提交失败,请检查网络"];
|
||
|
||
}];*/
|
||
|
||
|
||
|
||
UIImage* imgdata=celladd.zhaoPaiImg.image;
|
||
NSString *url = IfishUpdateBaseShopsInfo;
|
||
|
||
NSDictionary *paras = @{
|
||
@"shopsId":self.shopInfo.shopsId,
|
||
@"shopsPhone":cell1.infoDetailTextfeild.text,
|
||
@"shopsProvince":self.privence,
|
||
@"shopsCity":self.city,
|
||
@"shopsArea":self.area,
|
||
@"shopsAddress":cell3.infoDetailTextfeild.text,
|
||
@"file4":@"png",
|
||
@"":@"",
|
||
@"":@""
|
||
};
|
||
|
||
[AFHttpTool updateBaseShopsInfo:paras formatImg:imgdata requsetUrl:url success:^(id response) {
|
||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
||
NSLog(@"result:%@",resultDic[@"result"]);
|
||
[self.view hideToastActivity];
|
||
_isUpdate = YES;
|
||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self.view makeToast:@"提交成功"];
|
||
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"];
|
||
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||
|
||
[self.view makeToast:@"提交失败错误码101"];
|
||
}
|
||
|
||
|
||
} failure:^(NSError *err) {
|
||
[self.view makeToast:@"提交失败,请检查网络"];
|
||
}];
|
||
}
|
||
|
||
@end
|