123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #import "SuggestVC.h"
- @interface SuggestVC ()<UITextViewDelegate,UIAlertViewDelegate>
- {
- UITextView* titleTV,*contentTV;
-
- UIButton* placeHolder;
-
- UIButton* placeHolderCon;
-
- UIButton* placeHolderCon2;
-
- UIBarButtonItem *item;
-
-
- NSString *coachNum;
-
- NSArray *coachsArray;
- }
- @end
- @implementation SuggestVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- coachNum = @"";
-
- [self myInit];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.navigationController.navigationBarHidden = NO;
- }
- #pragma mark -
- /**这里把背景设置灰色更简单。
- */
- -(void)myInit
- {
- [self configNavigationBar];
- [self.view setBackgroundColor:backGroundColor];
-
- //textview的奇怪bug。不能是第一个subview 会滑动的都有这种情况 tableview scroll 等
- UIView *vi = [[UIView alloc] init];
- [self.view addSubview:vi];
-
- CGFloat x, y, w, h, bd;
- bd = 20;
- x = bd;
- w = kSize.width - x*2;
- y = bd + kNavOffSet;
- h = 40;
- UITextView* tv;
- tv= [[UITextView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [tv setBackgroundColor:[UIColor whiteColor]];
- tv.layer.borderColor = contentTextColor.CGColor;
- [tv setFont:[UIFont scaleSize:20]];
- tv.layer.borderWidth = 1;
- [self.view addSubview:tv];
- //[tv setDelegate:self];
- titleTV = tv;
-
- UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, h)];
- [btn addTarget:self action:@selector(hideBtn) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:@"请输入标题" textColor:contentTextColor font:20 fotState:UIControlStateNormal];
- [self.view addSubview:btn];
- [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- placeHolder = btn;
-
- y += h + bd ;
- h = 100;
- tv= [[UITextView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [tv setBackgroundColor:[UIColor whiteColor]];
- tv.layer.borderColor = contentTextColor.CGColor;
- [tv setFont:[UIFont scaleSize:20]];
- tv.layer.borderWidth = 1;
- [self.view addSubview:tv];
- [tv setDelegate:self];
- contentTV = tv;
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, 40)];
- [btn addTarget:self action:@selector(hideBtnCon) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:@"请输入内容" textColor:contentTextColor font:20 fotState:UIControlStateNormal];
- [self.view addSubview:btn];
- [btn setUserInteractionEnabled:NO];
- [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- placeHolderCon = btn;
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, h)];
- [btn addTarget:self action:@selector(hideBtnCon) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:btn];
- [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- placeHolderCon2 = btn;
- }
- -(void)setType:(int)type
- {
- _type = type;
- NSArray* arr = @[@"",@"向驾校建议",@"向教练建议",@"向系统建议",];
- [self setTitle:arr[type]];
-
- //layout
- CGFloat x , y,w ,h ,bd;
- bd = 20;
- x = bd;
- w = kSize.width - x*2;
-
- y = bd*3 + 40+100 + kNavOffSet;
- h = 60;
- UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(x , y, w, h)];
- [btn setTitle:@"提交建议" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(uploadSuggest) forControlEvents:UIControlEventTouchUpInside];
- [btn setBackgroundColor:defGreen];
- btn.layer.cornerRadius = 10;
- [self.view addSubview:btn];
-
- if (_type == 2) {
- [self getMyCoachInfos];
-
- item = [[UIBarButtonItem alloc] initWithTitle:@"教练选择" style:UIBarButtonItemStyleDone target:self action:@selector(clickToChooseCoach)];
- [item setTintColor:defGreen];
- [self.navigationItem setRightBarButtonItem:item];
- }
- }
- -(void)clickToChooseCoach
- {
- if (coachsArray.count == 0) {
- ShowMsg(@"查询不到您的教练");
- return;
- }else if (coachsArray.count == 1){
- coachNum = [[coachsArray firstObject] objectForKey:@"SFZHM"];
- [item setTitle:[[coachsArray firstObject] objectForKey:@"NAME"]];
- }else
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请选择教练" message:nil delegate:self cancelButtonTitle:[[coachsArray firstObject] objectForKey:@"NAME"] otherButtonTitles:[coachsArray[1] objectForKey:@"NAME"], nil];
- [alert show];
- }
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 0) {
- coachNum = [[coachsArray firstObject] objectForKey:@"SFZHM"];
- [item setTitle:[[coachsArray firstObject] objectForKey:@"NAME"]];
- }else{
- coachNum = [coachsArray[1] objectForKey:@"SFZHM"];
- [item setTitle:[coachsArray[1] objectForKey:@"NAME"]];
- }
- }
- -(void)hideBtn
- {
- [placeHolder setHidden:YES];
- [titleTV becomeFirstResponder];
- }
- -(void)hideBtnCon
- {
- [placeHolderCon setHidden:YES];
- [placeHolderCon2 setHidden:YES];
- [contentTV becomeFirstResponder];
- }
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- [titleTV resignFirstResponder];
- [contentTV resignFirstResponder];
- }
- -(void)uploadSuggest
- {
- NSString* title = titleTV.text;
- NSString* content = contentTV.text;
-
- if (title.length > 100) {
- ShowMsg(@"标题不能超出100字");
- return;
- }
- if (content.length > 500) {
- ShowMsg(@"内容不能超出500字");
- return;
- }
- if (title.length < 1 || content.length < 1) {
- ShowMsg(@"标题或内容不能为空");
- return;
- }
-
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- //danson--fromUser参数 原本是myDelegate.identifyNum
-
- NSMutableArray* array = [NSMutableArray array];
- [array property:title forKey:@"title"];
- [array property:content forKey:@"content"];
- [array property:@"2" forKey:@"source"];
- [array property:defUser.userTel forKey:@"tel"];
- NSString* str = [NSString stringWithFormat:@"%d",self.type];
- NSString *userString = @"";
- if (self.type == 1) {
- userString = defUser.userSchoolId;
- }
- if (self.type == 2) {
- userString = coachNum;
- if ([userString isEqualToString:@""]) {
- ShowMsg(@"请点击右上角进行教练选择");
- return;
- }
- }
- [array property:str forKey:@"type"];
- [array property:userString forKey:@"user"];
- [array property:defUser.userDict[@"id"] forKey:@"fromUser"];
- [array property:defUser.userName forKey:@"fromUserName"];
-
- NSString* method = @"uploadSuggestInfo";
-
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:array data:nil completion:^(NSDictionary * dict) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!dict) {
- ShowMsgFailed();
- return;
- }else if([dict[@"code"] isEqualToString:@"1"]){
- ShowMsg(dict[@"body"]);
- return;
- }
-
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"操作成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- }];
- }
- #pragma mark 异步获取教练信息
- -(void)getMyCoachInfos
- {
- if (![Util connectedToNetWork]) {
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- if ([defUser.userDict[@"outId"] isEqualToString:@""]) {
- return;
- }
- [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
- NSString* method = @"getMyCoachInfos";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
-
- if (!root) {
- [LoadingView showMsg:@"暂未找到您的教练"];
- return;
- }
- NSString* code = root[@"code"];
- if (code.intValue >0)
- {
- [LoadingView showMsg:root[@"body"]];
- return;
- }
- NSArray* body = root[@"body"];
- if (body.count < 1) {
- [LoadingView showMsg:@"查询不到您的教练"];
- return;
- }
- coachsArray = body;
-
- //NSLog(@"%@",coachsArray);
- }];
-
- }
- @end
|