SuggestVC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #import "SuggestVC.h"
  2. @interface SuggestVC ()<UITextViewDelegate,UIAlertViewDelegate>
  3. {
  4. UITextView* titleTV,*contentTV;
  5. UIButton* placeHolder;
  6. UIButton* placeHolderCon;
  7. UIButton* placeHolderCon2;
  8. UIBarButtonItem *item;
  9. NSString *coachNum;
  10. NSArray *coachsArray;
  11. }
  12. @end
  13. @implementation SuggestVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. coachNum = @"";
  17. [self myInit];
  18. }
  19. - (void)didReceiveMemoryWarning {
  20. [super didReceiveMemoryWarning];
  21. }
  22. -(void)viewWillAppear:(BOOL)animated
  23. {
  24. [super viewWillAppear:animated];
  25. self.navigationController.navigationBarHidden = NO;
  26. }
  27. #pragma mark -
  28. /**这里把背景设置灰色更简单。
  29. */
  30. -(void)myInit
  31. {
  32. [self configNavigationBar];
  33. [self.view setBackgroundColor:backGroundColor];
  34. //textview的奇怪bug。不能是第一个subview 会滑动的都有这种情况 tableview scroll 等
  35. UIView *vi = [[UIView alloc] init];
  36. [self.view addSubview:vi];
  37. CGFloat x, y, w, h, bd;
  38. bd = 20;
  39. x = bd;
  40. w = kSize.width - x*2;
  41. y = bd + kNavOffSet;
  42. h = 40;
  43. UITextView* tv;
  44. tv= [[UITextView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  45. [tv setBackgroundColor:[UIColor whiteColor]];
  46. tv.layer.borderColor = contentTextColor.CGColor;
  47. [tv setFont:[UIFont scaleSize:20]];
  48. tv.layer.borderWidth = 1;
  49. [self.view addSubview:tv];
  50. //[tv setDelegate:self];
  51. titleTV = tv;
  52. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, h)];
  53. [btn addTarget:self action:@selector(hideBtn) forControlEvents:UIControlEventTouchUpInside];
  54. [btn setTitle:@"请输入标题" textColor:contentTextColor font:20 fotState:UIControlStateNormal];
  55. [self.view addSubview:btn];
  56. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  57. placeHolder = btn;
  58. y += h + bd ;
  59. h = 100;
  60. tv= [[UITextView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  61. [tv setBackgroundColor:[UIColor whiteColor]];
  62. tv.layer.borderColor = contentTextColor.CGColor;
  63. [tv setFont:[UIFont scaleSize:20]];
  64. tv.layer.borderWidth = 1;
  65. [self.view addSubview:tv];
  66. [tv setDelegate:self];
  67. contentTV = tv;
  68. btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, 40)];
  69. [btn addTarget:self action:@selector(hideBtnCon) forControlEvents:UIControlEventTouchUpInside];
  70. [btn setTitle:@"请输入内容" textColor:contentTextColor font:20 fotState:UIControlStateNormal];
  71. [self.view addSubview:btn];
  72. [btn setUserInteractionEnabled:NO];
  73. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  74. placeHolderCon = btn;
  75. btn = [[UIButton alloc] initWithFrame:CGRectMake(x + 15, y, w, h)];
  76. [btn addTarget:self action:@selector(hideBtnCon) forControlEvents:UIControlEventTouchUpInside];
  77. [self.view addSubview:btn];
  78. [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  79. placeHolderCon2 = btn;
  80. }
  81. -(void)setType:(int)type
  82. {
  83. _type = type;
  84. NSArray* arr = @[@"",@"向驾校建议",@"向教练建议",@"向系统建议",];
  85. [self setTitle:arr[type]];
  86. //layout
  87. CGFloat x , y,w ,h ,bd;
  88. bd = 20;
  89. x = bd;
  90. w = kSize.width - x*2;
  91. y = bd*3 + 40+100 + kNavOffSet;
  92. h = 60;
  93. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(x , y, w, h)];
  94. [btn setTitle:@"提交建议" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal];
  95. [btn addTarget:self action:@selector(uploadSuggest) forControlEvents:UIControlEventTouchUpInside];
  96. [btn setBackgroundColor:defGreen];
  97. btn.layer.cornerRadius = 10;
  98. [self.view addSubview:btn];
  99. if (_type == 2) {
  100. [self getMyCoachInfos];
  101. item = [[UIBarButtonItem alloc] initWithTitle:@"教练选择" style:UIBarButtonItemStyleDone target:self action:@selector(clickToChooseCoach)];
  102. [item setTintColor:defGreen];
  103. [self.navigationItem setRightBarButtonItem:item];
  104. }
  105. }
  106. -(void)clickToChooseCoach
  107. {
  108. if (coachsArray.count == 0) {
  109. ShowMsg(@"查询不到您的教练");
  110. return;
  111. }else if (coachsArray.count == 1){
  112. coachNum = [[coachsArray firstObject] objectForKey:@"SFZHM"];
  113. [item setTitle:[[coachsArray firstObject] objectForKey:@"NAME"]];
  114. }else
  115. {
  116. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请选择教练" message:nil delegate:self cancelButtonTitle:[[coachsArray firstObject] objectForKey:@"NAME"] otherButtonTitles:[coachsArray[1] objectForKey:@"NAME"], nil];
  117. [alert show];
  118. }
  119. }
  120. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  121. {
  122. if (buttonIndex == 0) {
  123. coachNum = [[coachsArray firstObject] objectForKey:@"SFZHM"];
  124. [item setTitle:[[coachsArray firstObject] objectForKey:@"NAME"]];
  125. }else{
  126. coachNum = [coachsArray[1] objectForKey:@"SFZHM"];
  127. [item setTitle:[coachsArray[1] objectForKey:@"NAME"]];
  128. }
  129. }
  130. -(void)hideBtn
  131. {
  132. [placeHolder setHidden:YES];
  133. [titleTV becomeFirstResponder];
  134. }
  135. -(void)hideBtnCon
  136. {
  137. [placeHolderCon setHidden:YES];
  138. [placeHolderCon2 setHidden:YES];
  139. [contentTV becomeFirstResponder];
  140. }
  141. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  142. {
  143. [titleTV resignFirstResponder];
  144. [contentTV resignFirstResponder];
  145. }
  146. -(void)uploadSuggest
  147. {
  148. NSString* title = titleTV.text;
  149. NSString* content = contentTV.text;
  150. if (title.length > 100) {
  151. ShowMsg(@"标题不能超出100字");
  152. return;
  153. }
  154. if (content.length > 500) {
  155. ShowMsg(@"内容不能超出500字");
  156. return;
  157. }
  158. if (title.length < 1 || content.length < 1) {
  159. ShowMsg(@"标题或内容不能为空");
  160. return;
  161. }
  162. if (![Util connectedToNetWork]) {
  163. showMsgUnconnect();
  164. return;
  165. }
  166. //danson--fromUser参数 原本是myDelegate.identifyNum
  167. NSMutableArray* array = [NSMutableArray array];
  168. [array property:title forKey:@"title"];
  169. [array property:content forKey:@"content"];
  170. [array property:@"2" forKey:@"source"];
  171. [array property:defUser.userTel forKey:@"tel"];
  172. NSString* str = [NSString stringWithFormat:@"%d",self.type];
  173. NSString *userString = @"";
  174. if (self.type == 1) {
  175. userString = defUser.userSchoolId;
  176. }
  177. if (self.type == 2) {
  178. userString = coachNum;
  179. if ([userString isEqualToString:@""]) {
  180. ShowMsg(@"请点击右上角进行教练选择");
  181. return;
  182. }
  183. }
  184. [array property:str forKey:@"type"];
  185. [array property:userString forKey:@"user"];
  186. [array property:defUser.userDict[@"id"] forKey:@"fromUser"];
  187. [array property:defUser.userName forKey:@"fromUserName"];
  188. NSString* method = @"uploadSuggestInfo";
  189. [MBProgressHUD showLoadToView:self.view];
  190. [jiaPeiManager requestAnythingWithURL:method array:array data:nil completion:^(NSDictionary * dict) {
  191. [MBProgressHUD hideHUDForView:self.view];
  192. if (!dict) {
  193. ShowMsgFailed();
  194. return;
  195. }else if([dict[@"code"] isEqualToString:@"1"]){
  196. ShowMsg(dict[@"body"]);
  197. return;
  198. }
  199. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"操作成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  200. [alert show];
  201. [self.navigationController dismissViewControllerAnimated:NO completion:nil];
  202. }];
  203. }
  204. #pragma mark 异步获取教练信息
  205. -(void)getMyCoachInfos
  206. {
  207. if (![Util connectedToNetWork]) {
  208. return;
  209. }
  210. NSMutableArray *arr=[NSMutableArray array];
  211. if ([defUser.userDict[@"outId"] isEqualToString:@""]) {
  212. return;
  213. }
  214. [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]];
  215. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  216. NSString* method = @"getMyCoachInfos";
  217. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  218. if (!root) {
  219. [LoadingView showMsg:@"暂未找到您的教练"];
  220. return;
  221. }
  222. NSString* code = root[@"code"];
  223. if (code.intValue >0)
  224. {
  225. [LoadingView showMsg:root[@"body"]];
  226. return;
  227. }
  228. NSArray* body = root[@"body"];
  229. if (body.count < 1) {
  230. [LoadingView showMsg:@"查询不到您的教练"];
  231. return;
  232. }
  233. coachsArray = body;
  234. //NSLog(@"%@",coachsArray);
  235. }];
  236. }
  237. @end