This commit is contained in:
lianxiang
2018-09-23 15:52:02 +08:00
parent 3508cab25e
commit 69522b22fc
13 changed files with 476 additions and 36 deletions
@@ -14,8 +14,12 @@
#import "SJPhotoPicker.h"
#import "GiGaNetManager.h"
#import "GiGaAPIResult.h"
#import "GiGaFeedBackKindView.h"
#import "GIGaUserFileHelper.h"
#import "GiGaServerConfig.h"
@interface GiGaFeedBackViewController ()
@property(nonatomic,strong) NSMutableArray *imagesUrl;
@end
@@ -24,7 +28,7 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self addNavTitile:@"意见反馈"];
_imagesUrl = [NSMutableArray new];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
@@ -107,6 +111,18 @@
return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
GiGaFeedBackKindView *piker = [GiGaFeedBackKindView showAt:self atRow:0];
piker.selectedItemBlock = ^(NSString *tile) {
GiGaFeedLeiIingViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.kidLabel.text = tile;
};
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
return 40;
@@ -151,10 +167,8 @@
#pragma mark 提交
-(void)tijiaoAction{
GIGaFeedPhontosViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:3]];
NSArray *names =cell.imageNames;
NSLog(@"names:%@",names);
GiGaFeedLeiIingViewCell *kindcell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
if ([kindcell.kidLabel.text isEqualToString:@"选择反馈类型"]) {
@@ -173,24 +187,145 @@
if (qqcell.QTextFiled.text.length == 0) {
qqcell.QTextFiled.text = @"";
}
NSDictionary *dic =nil;
NSString *qqcom = qqcell.QTextFiled.text;
if (!qqcom) {
dic = @{@"type":kindcell.kidLabel.text,@"content":contencell.contentFiled.text};
}else{
dic = @{@"type":kindcell.kidLabel.text,@"content":contencell.contentFiled.text,@"contact":qqcom
};
}
[self.imagesUrl removeAllObjects];
[self uploadImags:dic];
}
//先上传图片获取到 imageurls 再 提交内容信息
-(void)uploadImags:(NSDictionary *)params{
GIGaFeedPhontosViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:3]];
NSArray *names =cell.imageNames;
if (names.count <= 0) {
GIGA_ShowToast(@"请选择图片");
return;
}
NSLog(@"names:%@",names);
[self.view makeToastActivity:CSToastPositionCenter];
//.串行队列同步执行:任务都在当前线程执行(同步),并且顺序执行(串行)
dispatch_queue_t queue = dispatch_queue_create("serialQueue", DISPATCH_QUEUE_SERIAL);
[GiGaNetManager uploadImage:@"sys/sysdict/v1/maskproposaltype" imageNames:names parms:@{} responseBlock:^(NSDictionary *responseDict, NSDictionary *responseHeaderFields, NSError *error) {
for (NSUInteger i= 0; i < names.count; i ++) {
dispatch_sync(queue, ^{
NSLog(@"上船图片%ld **** %@",i,names[i]);
UIImage *image =[GIGaUserFileHelper getUserFeedbackImag:names[i]] ;
if (!image) {
GILog(@"获取图片:************%@ nil",names[i]);
return;
}
NSData*imageData=UIImageJPEGRepresentation(image,1.0f);
[self uploadImage:imageData name:names[i] info:params totalCount:names.count];
});
}
}
// 单张上传
-(void)uploadImage:(NSData *)imageData name:(NSString *)name info:(NSDictionary *)info totalCount:(NSInteger)count{
[self.view makeToastActivity:CSToastPositionCenter];
NSString *url = [NSString stringWithFormat:@"%@%@",[GiGaServerConfig getMainUrl],kUploadFeed];
[GiGaNetManager uploadImage:url imgData:imageData parms:@{@"file":@"file"} responseBlock:^(NSDictionary *responseDict, NSDictionary *responseHeaderFields, NSError *error) {
[self.view hideToastActivity];
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:responseDict];
if (result.success) {
NSString *url = responseDict[@"url"];
if (url) {
[self.imagesUrl addObject:url];
NSLog(@"上船图片%@成功",name);
NSLog(@"当前获取图片数组:%@",self.imagesUrl);
if (self.imagesUrl.count == count) {
[self uploadFeedinfo:info imgUrlList:self.imagesUrl];
}
}
}else if (result.code == 401){
GIGA_WIndowTost(@"登录超时,请重新登录");
[GiGaBaseAPiRequest userTokenTimeOutGologinFromVC:self];
}else{
GIGA_ShowToast(result.message);
}
}];
}
//body 传参数
-(void)uploadFeedinfo:(NSDictionary*)params imgUrlList:(NSArray *)urlArr{
NSMutableDictionary *finallyparam = [NSMutableDictionary dictionaryWithDictionary:params];
[finallyparam setObject:urlArr forKey:@"imgUrlList"];
NSLog(@"finallyparam%@",finallyparam);
[self.view makeToastActivity:CSToastPositionCenter];
NSString *url = [NSString stringWithFormat:@"%@%@",[GiGaServerConfig getMainUrl],kAPiUpLoadFeeeds];
[GiGaNetManager userbodyRequest:url params:finallyparam completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
[self.view hideToastActivity];
if (error) {
GILog(@"err:%@",error.localizedDescription);
}else{
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:responseDict];
GIGA_ShowToast(result.message);
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
if (result.success) {
GIGA_ShowToast(@"🙏感谢提出宝贵意见!🙏");
}else if (result.code == 401){
GIGA_WIndowTost(@"登录超时,请重新登录");
[GiGaBaseAPiRequest userTokenTimeOutGologinFromVC:self];
}else{
GIGA_ShowToast(result.message);
}
}
}];
}
//多张
-(void)mutipuleUpload{
// [GiGaNetManager uploadImage:kUploadFeed imageNames:names parms:@{@"file":@"file"} responseBlock:^(NSDictionary *responseDict, NSDictionary *responseHeaderFields, NSError *error) {
// [self.view hideToastActivity];
// if (error) {
// GILog(@"err:%@",error.localizedDescription);
// GIGA_ShowToast(@"error");
//
// }else{
// GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:responseDict];
// GIGA_ShowToast(result.message);
// if (result.success) {
//
// GIGA_ShowToast(result.message);
// [self uploadFeedinfo:params imgUrlList:@[]];
//
// }else if (result.code == 401){
// GIGA_WIndowTost(@"登录超时,请重新登录");
// [GiGaBaseAPiRequest userTokenTimeOutGologinFromVC:self];
//
// }else{
// GIGA_ShowToast(result.message);
// }
// }
// }];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
+15
View File
@@ -0,0 +1,15 @@
//
// GIGaFeedKind.h
// GIGA
//
// Created by lianxiang on 2018/9/23.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <JSONModel/JSONModel.h>
@interface GIGaFeedKind : JSONModel
@property (nonatomic,copy) NSString *feed_id;
@property (nonatomic,copy) NSString *remarks;
@end
+21
View File
@@ -0,0 +1,21 @@
//
// GIGaFeedKind.m
// GIGA
//
// Created by lianxiang on 2018/9/23.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GIGaFeedKind.h"
@implementation GIGaFeedKind
+(JSONKeyMapper *)keyMapper{
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"feed_id":@"id"}];
}
+ (BOOL)propertyIsOptional:(NSString *)propertyName{
return YES;
}
@end
@@ -0,0 +1,19 @@
//
// GiGaFeedBackKindView.h
// GIGA
//
// Created by lianxiang on 2018/9/23.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface GiGaFeedBackKindView : UIViewController
typedef void (^SelectedItemBlock)(NSString *tile);
+(GiGaFeedBackKindView *)showAt:(UIViewController *)vc atRow:(NSInteger)row;
@property(nonatomic,copy)NSString *showStr;
@property(nonatomic) NSInteger defultRow;
@property (nonatomic, copy) SelectedItemBlock selectedItemBlock;
@end
@@ -0,0 +1,207 @@
//
// GiGaFeedBackKindView.m
// GIGA
//
// Created by lianxiang on 2018/9/23.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GiGaFeedBackKindView.h"
#define PickerHeight 180
#define PickerToolBarHeight 44
#import "GiGaBaseAPiRequest.h"
#import "GIGaFeedKind.h"
@interface GiGaFeedBackKindView ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (nonatomic, strong) UIView *pickerContainerView;
@property (nonatomic, strong) UIPickerView *pickerView;
//picker控件数据源
@property(nonatomic,strong)NSMutableArray *pickerDataArr;
@end
@implementation GiGaFeedBackKindView
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
self.pickerDataArr = [NSMutableArray new];
[self initUI];
// Do any additional setup after loading the view.
}
-(void)requstData{
GiGaBaseAPiRequest *api = [GiGaBaseAPiRequest initWithRequestPath:kApiGetFeedList method:RequestPostMethod parms:@{}];
[api requstDataWithResult:^(GiGaAPIResult *result) {
if (result.success) {
GILog(@"反馈类型%@",result.dic);
NSArray *list =result.dic[@"list"];
if (!list) {
list= [NSArray new];
}
for (NSDictionary *feedDic in list) {
GIGaFeedKind *mode = [[GIGaFeedKind alloc] initWithDictionary:feedDic error:nil];;
[self.pickerDataArr addObject:mode];
}
[self.pickerView reloadAllComponents];
[self.pickerView selectRow:self.defultRow inComponent:0 animated:YES];
GIGaFeedKind *mode = self.pickerDataArr[self.defultRow];
if (mode) {
self.showStr =mode.remarks;
}
}else{
GIGA_ShowToast(result.message);
}
}];
}
-(void)initUI{
self.pickerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - (PickerHeight + PickerToolBarHeight), [UIScreen mainScreen].bounds.size.width, PickerHeight + PickerToolBarHeight)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, PickerToolBarHeight)];
toolBar.barTintColor = [UIColor whiteColor];
UIBarButtonItem *noSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
noSpace.width=10;
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];;
doneBtn.tintColor = GIGARGB(131, 10, 10, 1);
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)];
cancelBtn.tintColor = GIGARGB(131, 10, 10, 1);
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolBar setItems:[NSArray arrayWithObjects:noSpace,cancelBtn,flexSpace,doneBtn,noSpace, nil]];
UILabel *titleLabel = [UILabel new];
titleLabel.frame = CGRectMake(0, 0, 200, PickerToolBarHeight);
titleLabel.center = toolBar.center;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = GIGARGB(62, 62, 62, 1);
titleLabel.text = @"反馈类型";
titleLabel.font = GIGA_TEXTFONTBOLD(14);
[toolBar addSubview:titleLabel];
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, PickerToolBarHeight, [UIScreen mainScreen].bounds.size.width, PickerHeight)];
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
self.pickerView.backgroundColor = [UIColor whiteColor];
[self.pickerContainerView addSubview:toolBar];
[self.pickerContainerView addSubview:self.pickerView];
[self.view addSubview:self.pickerContainerView];
}
#pragma mark-- UIPickerViewDataSource
//列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
//每列个数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [self.pickerDataArr count];
}
#pragma mark-- UIPickerViewDelegate
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = (id)view;
if (!label)
{
label= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
GIGaFeedKind *mode = self.pickerDataArr[row];
label.text = mode.remarks;
}
return label;
}
//点击选择
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (self.selectedItemBlock) {
if (self.pickerDataArr.count > 0 ) {
GIGaFeedKind *mode = self.pickerDataArr[row];
self.showStr = mode.remarks;
self.selectedItemBlock(self.showStr);
}
}
}
-(void)done:(UIButton *)btn{
if (self.selectedItemBlock) {
if ([self.showStr isEqualToString:@"未知"]) {
[self hide];
return;
}
self.selectedItemBlock(self.showStr);
}
[self hide];
}
-(void)cancel:(UIButton*)btn{
[self hide];
}
-(void)hide{
[self dismissViewControllerAnimated:NO completion:^{
}];
}
+(GiGaFeedBackKindView *)showAt:(UIViewController *)vc atRow:(NSInteger)row
{
GiGaFeedBackKindView *piker = [[GiGaFeedBackKindView alloc] init];
if (!row) {
row = 0;
}
piker.defultRow = row;
[vc presentViewController:piker animated:YES completion:^{
}];
return piker;
}
-(instancetype)init{
if (self = [super init]) {
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.showStr = @"未知";
[self requstData];
}
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end