AddRecordVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //
  2. // AddRecordVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/3/10.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "AddRecordVC.h"
  9. #import "DateView.h"
  10. #import "PickTimeV.h"
  11. #import "AppDelegate.h"
  12. @interface AddRecordVC ()<UITextViewDelegate>
  13. {
  14. UIButton *styleBtn,*dateBtn,*addBtn;
  15. UITextView *markTV;
  16. UILabel *placeHolderLabel;
  17. DateView *dateV;
  18. PickTimeV *pickV;
  19. NSString *dateString;
  20. NSString *recordStyle;
  21. }
  22. @end
  23. @implementation AddRecordVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.title = @"日志添加";
  27. float bd,x,y,w,h;
  28. x = bd = 10;
  29. y = kNavOffSet + 10;
  30. w = kSize.width - 20;
  31. h = 50;
  32. UIView *bgView;
  33. UILabel *label;
  34. UIButton *button;
  35. bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
  36. [bgView boardWid:2 Color:lineColor];
  37. [bgView corner:5];
  38. [self addV:bgView];
  39. label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y , w - bd, h)];
  40. [label setText:[NSString stringWithFormat:@"学员姓名: %@",_stuDic[@"STU_NAME"]] Font:18 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  41. [self addV:label];
  42. if ([_stuDic[@"SUBJECT"] integerValue] == 2 || [_stuDic[@"SUBJECT"] integerValue] == 3) {
  43. y += h + bd;
  44. bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
  45. [bgView boardWid:2 Color:lineColor];
  46. [bgView corner:5];
  47. [self addV:bgView];
  48. label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y , w - bd, h)];
  49. [label setText:[NSString stringWithFormat:@"日志类型:"] Font:18 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  50. [self addV:label];
  51. button = [[UIButton alloc] initWithFrame:CGRectMake(x, y , w, h)];
  52. [button setTitle:@"请选择日志类型" textColor:defGreen font:17 fotState:UIControlStateNormal];
  53. [button target:self Tag:1];
  54. [self addV:button];
  55. styleBtn = button;
  56. }
  57. y += h + bd;
  58. bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
  59. [bgView boardWid:2 Color:lineColor];
  60. [bgView corner:5];
  61. [self addV:bgView];
  62. label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y , w - bd, h)];
  63. [label setText:[NSString stringWithFormat:@"添加时间:"] Font:18 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  64. [self addV:label];
  65. //默认是当天时间
  66. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  67. [formatter setDateFormat:@"yyyy-MM-dd"];
  68. dateString = [formatter stringFromDate:[NSDate date]];
  69. button = [[UIButton alloc] initWithFrame:CGRectMake(x, y , w, h)];
  70. [button setTitle:dateString textColor:defGreen font:17 fotState:UIControlStateNormal];
  71. [button target:self Tag:2];
  72. [self addV:button];
  73. dateBtn = button;
  74. y += h + bd;
  75. h = 180;
  76. if (kSize.height < 500.0) {
  77. h = 140;
  78. }
  79. bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
  80. [bgView boardWid:2 Color:lineColor];
  81. [bgView corner:5];
  82. [self addV:bgView];
  83. markTV = [[UITextView alloc] initWithFrame:CGRectMake(x + bd, y + 5, w - 2*bd, h - 10)];
  84. markTV.delegate = self;
  85. markTV.backgroundColor = backGroundColor;
  86. markTV.textColor = contentTextColor;
  87. [markTV setFont:[UIFont scaleSize:17]];
  88. markTV.returnKeyType = UIReturnKeyDone;
  89. [self addV:markTV];
  90. label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y + 5, w - 2*bd, 30)];
  91. label.text = @"备注:请输入备注信息(60字以内)";
  92. label.textColor = contentTextColor;
  93. [label setFont:[UIFont scaleSize:17]];
  94. [label setTextAlignment:NSTextAlignmentLeft];
  95. [self addV:label];
  96. placeHolderLabel = label;
  97. y += h + 25;
  98. if (kSize.height > 600.0) {
  99. y += 100;
  100. }
  101. h = 50;
  102. button = [[UIButton alloc] initWithFrame:CGRectMake(x + 2*bd, y, w - 4*bd, h)];
  103. [button setTitle:@"确认添加" textColor:[UIColor whiteColor] font:20 fotState:UIControlStateNormal];
  104. button.backgroundColor = defGreen;
  105. [button.layer setMasksToBounds:YES];
  106. [button.layer setCornerRadius:10];
  107. [button target:self Tag:3];
  108. [self addV:button];
  109. addBtn = button;
  110. //修改日志
  111. if (_recordDic) {
  112. // NSLog(@"修改的日志---->%@",_recordDic);
  113. self.title = @"日志修改";
  114. recordStyle = _recordDic[@"TL_TEACH_ID"];
  115. if (_teachType.count > [recordStyle integerValue] - 1) {
  116. [styleBtn setTitle:_teachType[[recordStyle integerValue] - 1] forState:UIControlStateNormal];
  117. }
  118. [dateBtn setTitle:_recordDic[@"TL_CRDATE"] forState:UIControlStateNormal];
  119. [dateBtn setUserInteractionEnabled:NO];
  120. markTV.text = _recordDic[@"TL_REMARK"];
  121. if (markTV.text && markTV.text.length > 0) {
  122. [placeHolderLabel setHidden:YES];
  123. }
  124. [addBtn setTitle:@"确认修改" forState:UIControlStateNormal];
  125. addBtn.tag = 4;
  126. }
  127. }
  128. -(void)btnClick:(UIButton *)sender
  129. {
  130. [self.view endEditing:YES];
  131. if (sender.tag == 1) {
  132. //选择日志类型
  133. pickV = [[PickTimeV alloc] init];
  134. if ([_stuDic objectForKey:@"SUBJECT"]) {
  135. pickV.KM = _stuDic[@"SUBJECT"];
  136. }
  137. [pickV setWhichVC:@"AddRecordVC"];
  138. [pickV complete:^(NSDictionary* obj) {
  139. [styleBtn setTitle:obj[@"TC_TEACH_TYPE"] forState:UIControlStateNormal];
  140. recordStyle = obj[@"TC_ID"];
  141. }];
  142. [pickV show];
  143. }
  144. if (sender.tag == 2) {
  145. //选择日志时间
  146. dateV = [[DateView alloc] init];
  147. [dateV setStyle:0];
  148. [dateV showWithComplete:^(NSString * result) {
  149. //NSLog(@"%@",result); eg:2016-03-11
  150. dateString = result;
  151. [dateBtn setTitle:dateString forState:UIControlStateNormal];
  152. }];
  153. }
  154. if (sender.tag == 3) {
  155. //确认添加
  156. if (!recordStyle || recordStyle.length == 0) {
  157. if ([_stuDic[@"SUBJECT"] integerValue] == 2 || [_stuDic[@"SUBJECT"] integerValue] == 3) {
  158. ShowMsg(@"请选择日志类型");
  159. return;
  160. }
  161. }
  162. if (markTV.text.length > 60) {
  163. ShowMsg(@"备注已超过60字符");
  164. return;
  165. }
  166. [self uploadTeachLogs];
  167. }
  168. if (sender.tag == 4) {
  169. //确认修改
  170. if (markTV.text.length > 60) {
  171. ShowMsg(@"备注已超过60字符");
  172. return;
  173. }
  174. [self modifyTeachLogs];
  175. }
  176. }
  177. #pragma mark 添加日志
  178. - (void)uploadTeachLogs
  179. {
  180. [LoadingView showHUD];
  181. if (![Util connectedToNetWork]) {
  182. showMsgUnconnect();
  183. return;
  184. }
  185. NSMutableArray *arr=[NSMutableArray array];
  186. [arr addPro:@"name" Value:_stuDic[@"STU_NAME"]];
  187. [arr addPro:@"userOutId" Value:_stuDic[@"TSO_ID"]];
  188. [arr addPro:@"coaSfzhm" Value:defUser.userDict[@"idcard"]];
  189. [arr addPro:@"crDate" Value:dateString];
  190. [arr addPro:@"teachId" Value:recordStyle];
  191. [arr addPro:@"subject" Value:_stuDic[@"SUBJECT"]];
  192. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  193. [arr addPro:@"remark" Value:markTV.text];
  194. NSString* method = @"uploadTeachLogs";
  195. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  196. RemoveHUD();
  197. //NSLog(@"添加日志---->%@----->%@",arr,root);
  198. if (!root) {
  199. ShowMsg(@"上传失败!");
  200. return ;
  201. }
  202. if ([root[@"code"] isEqualToString:@"1"]) {
  203. ShowMsg(root[@"body"]);
  204. return;
  205. }
  206. ShowMsg(@"上传成功!");
  207. if (self.refreshTeachlogs) {
  208. self.refreshTeachlogs();
  209. }
  210. [self.navigationController popViewControllerAnimated:YES];
  211. }];
  212. }
  213. #pragma mark 修改日志
  214. - (void)modifyTeachLogs
  215. {
  216. [LoadingView showHUD];
  217. if (![Util connectedToNetWork]) {
  218. showMsgUnconnect();
  219. return;
  220. }
  221. NSMutableArray *arr=[NSMutableArray array];
  222. [arr addPro:@"id" Value:_recordDic[@"TL_ID"]];
  223. [arr addPro:@"teachId" Value:recordStyle];
  224. [arr addPro:@"subject" Value:_stuDic[@"SUBJECT"]];
  225. [arr addPro:@"remark" Value:markTV.text];
  226. NSString* method = @"modifyMyTeachLog";
  227. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  228. RemoveHUD();
  229. //NSLog(@"修改日志---->%@----->%@",arr,root);
  230. if (!root) {
  231. ShowMsg(@"修改失败!");
  232. return ;
  233. }
  234. if ([root[@"code"] isEqualToString:@"1"]) {
  235. ShowMsg(root[@"body"]);
  236. return;
  237. }
  238. ShowMsg(@"修改成功!");
  239. if (self.refreshTeachlogs) {
  240. self.refreshTeachlogs();
  241. }
  242. [self.navigationController popViewControllerAnimated:YES];
  243. }];
  244. }
  245. #pragma mark tv代理
  246. -(void)textViewDidBeginEditing:(UITextView *)textView
  247. {
  248. [placeHolderLabel setTextColor:[UIColor colorWithWhite:.3 alpha:.5]];
  249. }
  250. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  251. {
  252. NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text];
  253. [changedString replaceCharactersInRange:range withString:text];
  254. if (changedString.length > 0) {
  255. [placeHolderLabel setHidden:YES];
  256. }else{
  257. [placeHolderLabel setHidden:NO];
  258. }
  259. if ([@"\n" isEqualToString:text] == YES) {
  260. //如果是换行键 就隐藏键盘
  261. [self.view endEditing:YES];
  262. return NO;
  263. }
  264. return YES;
  265. }
  266. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  267. {
  268. [self.view endEditing:YES];
  269. }
  270. - (void)didReceiveMemoryWarning {
  271. [super didReceiveMemoryWarning];
  272. // Dispose of any resources that can be recreated.
  273. }
  274. /*
  275. #pragma mark - Navigation
  276. // In a storyboard-based application, you will often want to do a little preparation before navigation
  277. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  278. // Get the new view controller using [segue destinationViewController].
  279. // Pass the selected object to the new view controller.
  280. }
  281. */
  282. @end