coachRecordVC.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. //
  2. // coachRecordVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/3/8.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. //带教记录
  9. #import "coachRecordVC.h"
  10. #import "AddRecordVC.h"
  11. #import "AppDelegate.h"
  12. #import "Tools.h"
  13. #import "DetailTJVC.h"
  14. #import "RecordCell.h"
  15. #import <MJRefresh.h>
  16. typedef NS_ENUM(NSInteger, MyGetDataType) {
  17. //正常请求数据
  18. MyGetDataTypeNomal=0,
  19. //下拉刷新请求数据
  20. MyGetDataTypeHeaderRefresh,
  21. //上拉加载更多请求数据
  22. MyGetDataTypeFooterRefresh
  23. };
  24. @interface coachRecordVC ()<UITableViewDelegate,UITableViewDataSource>
  25. {
  26. //记录页书
  27. NSInteger _currentPageNum;
  28. //正在加载的状态
  29. BOOL _IS_LOADING;
  30. //加载数据的类型
  31. MyGetDataType _getDataType;
  32. HolderView *holderV;
  33. UITextField *tfName;
  34. UITableView *mainTableView;
  35. NSMutableArray *models;//底部foottab数据源
  36. NSArray *xArray;
  37. NSMutableArray *teachTypes;
  38. NSString *searchString;
  39. }
  40. @end
  41. @implementation coachRecordVC
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. _currentPageNum = 0;
  45. _IS_LOADING = NO;
  46. _getDataType = MyGetDataTypeNomal;
  47. models = [NSMutableArray array];
  48. xArray = [NSArray array];
  49. teachTypes = [NSMutableArray array];
  50. float h,bd,w,x,y;
  51. x = bd = 10;
  52. w = (kSize.width - bd*4)/6.0;
  53. h = 50;
  54. y = kNavOffSet + bd;
  55. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w * 2, h)];
  56. label.text = _stuDic[@"STU_NAME"];
  57. label.textColor = titleColor;
  58. label.textAlignment = NSTextAlignmentCenter;
  59. [label setFont:[UIFont scaleSize:21]];
  60. [self.view addSubview:label];
  61. UILabel *telLabel = [[UILabel alloc] initWithFrame:CGRectMake(x + 2*w + 2*bd, y + 8, w * 4, h - 8)];
  62. //用富文本将电话号码
  63. NSString *telString = [NSString stringWithFormat:@"电话号码:%@",_stuDic[@"TSO_PHONE"]];
  64. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:telString];
  65. [aAttributedString addAttribute:NSForegroundColorAttributeName
  66. value:contentTextColor
  67. range:NSMakeRange(0, 5)];
  68. [aAttributedString addAttribute:NSForegroundColorAttributeName
  69. value:defGreen
  70. range:NSMakeRange(5, telString.length - 5)];
  71. telLabel.attributedText = aAttributedString;
  72. telLabel.textAlignment = NSTextAlignmentCenter;
  73. [telLabel setFont:[UIFont scaleSize:Font16]];
  74. [self.view addSubview:telLabel];
  75. //电话按钮
  76. UIButton *telBtn = [[UIButton alloc] initWithFrame:CGRectMake(x + 2*w + 2*bd, y, w * 4, h)];
  77. [telBtn target:self Tag:1];
  78. [self addV:telBtn];
  79. y += h + bd + 8;
  80. h -= 10;
  81. UIImageView *btnImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, y + 5, 30, 30)];
  82. btnImg.image = [UIImage imageNamed:@"xiuxue.png"];
  83. [self addV:btnImg];
  84. UIButton *btn;
  85. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, y, kSize.width/2.0, h)];
  86. [btn setTitle:@"添加日志" textColor:titleColor font:Font16 fotState:UIControlStateNormal];
  87. [btn borderColor:lineColor width:2 cornorRadios:0];
  88. [self addV:btn];
  89. [btn target:self Tag:2];
  90. btnImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 8, y + 5, 30, 30)];
  91. btnImg.image = [UIImage imageNamed:@"record.png"];
  92. [self addV:btnImg];
  93. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 - 2, y, kSize.width/2.0 + 2, h)];
  94. [btn setTitle:@"日志统计" textColor:titleColor font:Font16 fotState:UIControlStateNormal];
  95. [btn borderColor:lineColor width:2 cornorRadios:0];
  96. [self addV:btn];
  97. [btn target:self Tag:3];
  98. y += h + 2;
  99. mainTableView = [[UITableView alloc] initWithFrame:kFrame];
  100. mainTableView.y = y;
  101. mainTableView.height = kSize.height - mainTableView.y -SafeAreaBottomHeight;
  102. [mainTableView setDelegate:self];
  103. [mainTableView setDataSource:self];
  104. mainTableView.estimatedSectionFooterHeight = 0;
  105. [self addV:mainTableView];
  106. [mainTableView setTableFooterView:[UIView new]];
  107. holderV = [[HolderView alloc] initWithFrame:mainTableView.frame];
  108. [holderV freshBlock:^{
  109. [self getMyTeachLogs];
  110. }];
  111. [self addV:holderV];
  112. [holderV setHidden:YES];
  113. [self setRefreshAction];
  114. //休学记录==> 获取教学日志类型==〉日志记录
  115. [self getStuXXList];
  116. }
  117. -(void)btnClick:(UIButton *)sender
  118. {
  119. if (sender.tag == 1) {
  120. //拨打电话
  121. NSString* tel = _stuDic[@"TSO_PHONE"];
  122. if (tel && ![tel isEqualToString:@""]) {
  123. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",tel]]];
  124. }
  125. }
  126. if (sender.tag == 2) {
  127. if ([_stuDic[@"SUBJECT"] integerValue] == 1 || [_stuDic[@"SUBJECT"] integerValue] == 4) {
  128. ShowMsg(@"当前科目无需添加日志!");
  129. return;
  130. }
  131. AddRecordVC *vc = [[AddRecordVC alloc] init];
  132. vc.refreshTeachlogs = ^{
  133. [self headerRefresh];
  134. };
  135. vc.stuDic = _stuDic;
  136. vc.view.backgroundColor = backGroundColor;
  137. [vc configNavBar];
  138. [self.navigationController pushViewController:vc animated:YES];
  139. }
  140. if (sender.tag == 3) {
  141. DetailTJVC *TJVC = [[DetailTJVC alloc] init];
  142. [TJVC configNavBar];
  143. TJVC.view.backgroundColor = backGroundColor;
  144. [self.navigationController pushViewController:TJVC animated:YES];
  145. }
  146. }
  147. #pragma mark - 下拉刷新,上拉加载 -
  148. -(void)setRefreshAction{
  149. // 下拉刷新
  150. __weak typeof(self) weakSelf = self;
  151. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  152. [weakSelf headerRefresh];
  153. }];
  154. mainTableView.mj_header = mj_header;
  155. MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  156. [weakSelf footerRefresh];
  157. }];
  158. mainTableView.mj_footer = mj_footer;
  159. }
  160. #pragma mark - 数据加载更多和刷新 -
  161. -(void)headerRefresh{
  162. //设置获取数据的方式
  163. _getDataType=MyGetDataTypeHeaderRefresh;
  164. //加载数据
  165. [self getMyTeachLogs];
  166. [mainTableView.mj_header endRefreshing];
  167. }
  168. -(void)footerRefresh{
  169. //设置获取数据的方式
  170. _getDataType=MyGetDataTypeFooterRefresh;
  171. //加载数据
  172. [self getMyTeachLogs];
  173. [mainTableView.mj_footer endRefreshing];
  174. }
  175. #pragma mark 数据请求
  176. //请求休学信息
  177. - (void)getStuXXList
  178. {
  179. [LoadingView showHUD];
  180. if (![Util connectedToNetWork]) {
  181. showMsgUnconnect();
  182. return;
  183. }
  184. NSMutableArray *arr=[NSMutableArray array];
  185. [arr addPro:@"stuSfzhm" Value:_stuDic[@"STU_SFZHM"]];
  186. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  187. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  188. [arr addPro:@"isPage" Value:@"0"];
  189. [arr addPro:@"pageSize" Value:@"0"];
  190. [arr addPro:@"currentPage" Value:@"0"];
  191. NSString* method = @"stuXXList";
  192. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  193. RemoveHUD();
  194. [self getTeachTypes];
  195. if (!root) {
  196. return ;
  197. }
  198. if ([root[@"code"] isEqualToString:@"1"]) {
  199. return;
  200. }
  201. xArray = root[@"body"];
  202. }];
  203. }
  204. //请求类型 有关日志信息
  205. - (void)getTeachTypes
  206. {
  207. NSMutableArray *array = [NSMutableArray arrayWithObjects:@"车辆基础操作",@"直线控制离合",@"倒车入库左倒",@"倒车入库右倒",@"科目二全套训练",@"预约科目二考试",@"考试日期",@"路跑",@"变更车道",@"会车与超车",@"靠边停车和掉头",@"灯光使用",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"", nil];
  208. NSMutableArray *arr = [NSMutableArray array];
  209. [arr addPro:@"subject" Value:@""];
  210. [arr addPro:@"type" Value:@"1"];
  211. NSString* method = @"getTeachTypes";
  212. [LoadingView showHUD];
  213. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  214. RemoveHUD();
  215. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  216. NSString *filePath = [Tools getPathWithFileName:@"getTeachTypes.plist"];
  217. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  218. NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
  219. [teachTypes removeAllObjects];
  220. for (NSDictionary *dic in arr) {
  221. [teachTypes addObject:dic[@"TC_TEACH_TYPE"]];
  222. }
  223. }else{
  224. teachTypes = array;
  225. }
  226. [self headerRefresh];
  227. return;
  228. }
  229. NSString *filePath = [Tools getPathWithFileName:@"getTeachTypes.plist"];
  230. [root[@"body"] writeToFile:filePath atomically:YES];
  231. [teachTypes removeAllObjects];
  232. for (NSDictionary *dic in root[@"body"]) {
  233. [teachTypes addObject:dic[@"TC_TEACH_TYPE"]];
  234. }
  235. [self headerRefresh];
  236. }];
  237. }
  238. - (void)getMyTeachLogs
  239. {
  240. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  241. if (_IS_LOADING) {
  242. return;
  243. }
  244. [LoadingView showHUD];
  245. _IS_LOADING=YES;
  246. //获取第一页数据
  247. NSInteger needLoadPage;
  248. needLoadPage=_currentPageNum+1;
  249. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  250. needLoadPage=1;
  251. }
  252. NSString *queryValue = @"";
  253. if ([_stuDic isKindOfClass:[NSDictionary class]]) {
  254. if ([[_stuDic allKeys] count] != 0) {
  255. queryValue = _stuDic[@"TSO_ID"];
  256. }
  257. }
  258. NSMutableArray *arr=[NSMutableArray array];
  259. [arr addPro:@"queryValue" Value:queryValue];
  260. [arr addPro:@"isPage" Value:@"1"];
  261. [arr addPro:@"pageSize" Value:@"10"];
  262. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%ld",(long)needLoadPage]];
  263. NSString* method = @"getMyTeachLogs";
  264. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  265. RemoveHUD();
  266. //设置加载状态
  267. _IS_LOADING=NO;
  268. if (!root) {
  269. ShowMsg(@"数据请求失败,请重试");
  270. return;
  271. }
  272. if ([root[@"code"] integerValue] != 0) {
  273. ShowMsg(root[@"body"]);
  274. return;
  275. }
  276. //处理数据
  277. //如果获取到了数据,而且是下拉刷新,清空数组。
  278. if (_getDataType==MyGetDataTypeHeaderRefresh){
  279. [models removeAllObjects];
  280. }
  281. NSArray *bodyArray = root[@"body"];
  282. if (bodyArray && bodyArray.count > 0) {
  283. //追加数据
  284. [models addObjectsFromArray:bodyArray];
  285. //计数器+1
  286. _currentPageNum=needLoadPage;
  287. }
  288. if (xArray.count >0 || models.count >0) {
  289. [holderV setHidden:YES];
  290. }
  291. //刷新界面
  292. [mainTableView reloadData];
  293. //恢复初始状态。
  294. _getDataType=MyGetDataTypeNomal;
  295. }];
  296. }
  297. - (void)deleteTeachTypesWithRow:(NSInteger)row
  298. {
  299. if (![Util connectedToNetWork]) {
  300. showMsgUnconnect();
  301. return;
  302. }
  303. NSDictionary *dic = models[row];
  304. NSMutableArray *arr = [NSMutableArray array];
  305. [arr addPro:@"id" Value:dic[@"TL_ID"]];
  306. NSString* method = @"deleteMyTeachLog";
  307. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  308. RemoveHUD();
  309. //NSLog(@"日志删除---->%@----->%@",arr,root);
  310. if (!root) {
  311. return;
  312. }
  313. if ([root[@"code"] isEqualToString:@"1"]) {
  314. ShowMsg(root[@"body"]);
  315. }
  316. [models removeObjectAtIndex:row];
  317. [mainTableView reloadData];
  318. }];
  319. }
  320. #pragma mark - tableview delegate
  321. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  322. {
  323. if (xArray.count > 0 && models.count > 0) {
  324. return 2;
  325. }else{
  326. return 1;
  327. }
  328. }
  329. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  330. {
  331. UILabel *xLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  332. xLabel.backgroundColor = [UIColor colorWithWhite:.9 alpha:1];
  333. xLabel.text = @"休学记录";
  334. xLabel.font = [UIFont scaleSize:20];
  335. xLabel.textAlignment = NSTextAlignmentCenter;
  336. UILabel *rLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  337. rLabel.backgroundColor = [UIColor colorWithWhite:.9 alpha:1];
  338. rLabel.text = @"学员日志";
  339. rLabel.font = [UIFont scaleSize:20];
  340. rLabel.textAlignment = NSTextAlignmentCenter;
  341. if (xArray.count > 0 && models.count > 0) {
  342. if (section == 0) {
  343. return xLabel;
  344. }else{
  345. return rLabel;
  346. }
  347. }else if (xArray.count > 0){
  348. return xLabel;
  349. }else if (models.count > 0){
  350. return rLabel;
  351. }else{
  352. return [UILabel new];
  353. }
  354. }
  355. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  356. {
  357. return 40;
  358. }
  359. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  360. {
  361. return .1;
  362. }
  363. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  364. {
  365. if (xArray.count > 0 && models.count > 0) {
  366. if (section == 0) {
  367. return xArray.count;
  368. }else{
  369. return models.count;
  370. }
  371. }else if (xArray.count > 0){
  372. return xArray.count;
  373. }else if (models.count > 0){
  374. return models.count;
  375. }else{
  376. return 0;
  377. }
  378. }
  379. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  380. {
  381. RecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  382. if (cell == nil)
  383. {
  384. cell = [[RecordCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  385. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  386. }
  387. @try {
  388. if (xArray.count > 0 && models.count > 0) {
  389. if (indexPath.section == 0) {
  390. NSDictionary *dic = xArray[indexPath.row];
  391. cell.textLabel.adjustsFontSizeToFitWidth = YES;
  392. cell.textLabel.text = [NSString stringWithFormat:@"● 该学员于%@休学",dic[@"CRDATE"]];
  393. cell.detailTextLabel.text = @"";
  394. if ([dic[@"REASON"] length] > 0) {
  395. cell.detailTextLabel.text = [NSString stringWithFormat:@"休学原因: %@",dic[@"REASON"]];
  396. }
  397. if (cell.detailTextLabel.text.length > 0) {
  398. NSString *remarkString = cell.detailTextLabel.text;
  399. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
  400. [aAttributedString addAttribute:NSForegroundColorAttributeName
  401. value:[UIColor orangeColor]
  402. range:NSMakeRange(0, 5)];
  403. [aAttributedString addAttribute:NSForegroundColorAttributeName
  404. value:contentTextColor
  405. range:NSMakeRange(5, remarkString.length - 5)];
  406. cell.detailTextLabel.attributedText = aAttributedString;
  407. }
  408. cell.detailTextLabel.numberOfLines = 0;
  409. [cell.detailTextLabel setFont:[UIFont scaleSize:15]];
  410. CGFloat detailTextHight = [cell.detailTextLabel.text heightForWid:kSize.width - 20 Font:15];
  411. cell.detailTextLabel.height = detailTextHight + 10;
  412. cell.dateLabel.text = @"";
  413. }else{
  414. NSDictionary *dic = models[indexPath.row];
  415. NSString *teachStyle = teachTypes[[dic[@"TL_TEACH_ID"] integerValue] - 1];
  416. NSString *remarkS = [NSString stringWithFormat:@"%d、[%@]",(int)indexPath.row + 1,teachStyle];
  417. NSMutableAttributedString * aString = [[NSMutableAttributedString alloc] initWithString:remarkS];
  418. [aString addAttribute:NSForegroundColorAttributeName
  419. value:[UIColor orangeColor]
  420. range:NSMakeRange(2, 1)];
  421. [aString addAttribute:NSForegroundColorAttributeName
  422. value:[UIColor orangeColor]
  423. range:NSMakeRange(remarkS.length - 1, 1)];
  424. cell.textLabel.attributedText = aString;
  425. cell.textLabel.adjustsFontSizeToFitWidth = NO;
  426. //日期
  427. NSString *km = [dic[@"TL_SUBJECT"] isEqualToString:@"2"]?@"科二":@"科三";
  428. NSString *dateString = dic[@"TL_CRDATE"];
  429. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  430. [formatter setDateFormat:@"yyyy-MM-dd"];
  431. NSDate *cDate = [formatter dateFromString:dateString];
  432. [formatter setDateFormat:@"MM.dd.yyyy"];
  433. dateString = [formatter stringFromDate:cDate];
  434. cell.dateLabel.text = [NSString stringWithFormat:@"%@ %@",dateString,km];
  435. //如果没有 就不显示
  436. //cell.detailTextLabel.text = [NSString stringWithFormat:@"备注: 暂无备注"];
  437. cell.detailTextLabel.text = @"";
  438. if ([dic[@"TL_REMARK"] length] > 0) {
  439. cell.detailTextLabel.text = [NSString stringWithFormat:@"备注: %@",dic[@"TL_REMARK"]];
  440. }
  441. if (cell.detailTextLabel.text.length > 0) {
  442. NSString *remarkString = cell.detailTextLabel.text;
  443. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
  444. [aAttributedString addAttribute:NSForegroundColorAttributeName
  445. value:[UIColor orangeColor]
  446. range:NSMakeRange(0, 3)];
  447. [aAttributedString addAttribute:NSForegroundColorAttributeName
  448. value:contentTextColor
  449. range:NSMakeRange(3, remarkString.length - 3)];
  450. cell.detailTextLabel.attributedText = aAttributedString;
  451. }
  452. cell.detailTextLabel.numberOfLines = 0;
  453. [cell.detailTextLabel setFont:[UIFont scaleSize:15]];
  454. CGFloat detailTextHight = [cell.detailTextLabel.text heightForWid:kSize.width - 20 Font:15];
  455. cell.detailTextLabel.height = detailTextHight + 10;
  456. }
  457. }else if (xArray.count > 0){
  458. NSDictionary *dic = xArray[indexPath.row];
  459. //♦
  460. cell.textLabel.adjustsFontSizeToFitWidth = YES;
  461. cell.textLabel.text = [NSString stringWithFormat:@"● 该学员于%@被写入休学状态",dic[@"CRDATE"]];
  462. //cell.detailTextLabel.text = [NSString stringWithFormat:@"休学原因: 暂无"];
  463. cell.detailTextLabel.text = @"";
  464. if ([dic[@"REASON"] length] > 0) {
  465. cell.detailTextLabel.text = [NSString stringWithFormat:@"休学原因: %@",dic[@"REASON"]];
  466. }
  467. if (cell.detailTextLabel.text.length > 0) {
  468. NSString *remarkString = cell.detailTextLabel.text;
  469. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
  470. [aAttributedString addAttribute:NSForegroundColorAttributeName
  471. value:[UIColor orangeColor]
  472. range:NSMakeRange(0, 5)];
  473. [aAttributedString addAttribute:NSForegroundColorAttributeName
  474. value:contentTextColor
  475. range:NSMakeRange(5, remarkString.length - 5)];
  476. cell.detailTextLabel.attributedText = aAttributedString;
  477. }
  478. cell.detailTextLabel.numberOfLines = 0;
  479. [cell.detailTextLabel setFont:[UIFont scaleSize:15]];
  480. CGFloat detailTextHight = [cell.detailTextLabel.text heightForWid:kSize.width - 20 Font:15];
  481. cell.detailTextLabel.height = detailTextHight + 10;
  482. cell.dateLabel.text = @"";
  483. }
  484. else{
  485. NSDictionary *dic = models[indexPath.row];
  486. NSString *teachStyle = teachTypes[[dic[@"TL_TEACH_ID"] integerValue] - 1];
  487. NSString *remarkS = [NSString stringWithFormat:@"%d、[%@]",(int)indexPath.row + 1,teachStyle];
  488. NSMutableAttributedString * aString = [[NSMutableAttributedString alloc] initWithString:remarkS];
  489. [aString addAttribute:NSForegroundColorAttributeName
  490. value:[UIColor orangeColor]
  491. range:NSMakeRange(2, 1)];
  492. [aString addAttribute:NSForegroundColorAttributeName
  493. value:[UIColor orangeColor]
  494. range:NSMakeRange(remarkS.length - 1, 1)];
  495. cell.textLabel.attributedText = aString;
  496. cell.textLabel.adjustsFontSizeToFitWidth = NO;
  497. //日期
  498. NSString *km = [dic[@"TL_SUBJECT"] isEqualToString:@"2"]?@"科二":@"科三";
  499. NSString *dateString = dic[@"TL_CRDATE"];
  500. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  501. [formatter setDateFormat:@"yyyy-MM-dd"];
  502. NSDate *cDate = [formatter dateFromString:dateString];
  503. [formatter setDateFormat:@"MM.dd.yyyy"];
  504. dateString = [formatter stringFromDate:cDate];
  505. cell.dateLabel.text = [NSString stringWithFormat:@"%@ %@",dateString,km];
  506. //cell.detailTextLabel.text = [NSString stringWithFormat:@"备注: 暂无备注"];
  507. cell.detailTextLabel.text = @"";
  508. if ([dic[@"TL_REMARK"] length] > 0) {
  509. cell.detailTextLabel.text = [NSString stringWithFormat:@"备注: %@",dic[@"TL_REMARK"]];
  510. }
  511. if (cell.detailTextLabel.text.length > 0) {
  512. NSString *remarkString = cell.detailTextLabel.text;
  513. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
  514. [aAttributedString addAttribute:NSForegroundColorAttributeName
  515. value:[UIColor orangeColor]
  516. range:NSMakeRange(0, 3)];
  517. [aAttributedString addAttribute:NSForegroundColorAttributeName
  518. value:contentTextColor
  519. range:NSMakeRange(3, remarkString.length - 3)];
  520. cell.detailTextLabel.attributedText = aAttributedString;
  521. }
  522. cell.detailTextLabel.numberOfLines = 0;
  523. [cell.detailTextLabel setFont:[UIFont scaleSize:15]];
  524. CGFloat detailTextHight = [cell.detailTextLabel.text heightForWid:kSize.width - 20 Font:15];
  525. cell.detailTextLabel.height = detailTextHight + 10;
  526. }
  527. }
  528. @catch (NSException *exception) {
  529. }
  530. @finally {
  531. return cell;
  532. }
  533. }
  534. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  535. {
  536. if (xArray.count > 0 && indexPath.section == 0) {
  537. return 80.5;
  538. }
  539. NSDictionary *dic = models[indexPath.row];
  540. CGFloat height = [[NSString stringWithFormat:@"备注:%@",dic[@"TL_REMARK"]] heightForWid:kSize.width - 20 Font:15];
  541. return height + 70.5;
  542. }
  543. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  544. {
  545. if (xArray.count > 0 && models.count > 0) {
  546. if (indexPath.section == 0) {
  547. return;
  548. }else{
  549. AddRecordVC *vc = [[AddRecordVC alloc] init];
  550. vc.stuDic = _stuDic;
  551. vc.refreshTeachlogs = ^{
  552. [self headerRefresh];
  553. };
  554. vc.teachType = teachTypes;
  555. vc.recordDic = models[indexPath.row];
  556. vc.view.backgroundColor = backGroundColor;
  557. [vc configNavBar];
  558. [self.navigationController pushViewController:vc animated:YES];
  559. }
  560. }else if (xArray.count > 0){
  561. return;
  562. }else{
  563. AddRecordVC *vc = [[AddRecordVC alloc] init];
  564. vc.stuDic = _stuDic;
  565. vc.refreshTeachlogs = ^{
  566. [self headerRefresh];
  567. };
  568. vc.teachType = teachTypes;
  569. vc.recordDic = models[indexPath.row];
  570. vc.view.backgroundColor = backGroundColor;
  571. [vc configNavBar];
  572. [self.navigationController pushViewController:vc animated:YES];
  573. }
  574. }
  575. //表的编辑
  576. -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  577. {
  578. if (xArray.count > 0) {
  579. if (indexPath.section == 0) {
  580. return NO;
  581. }
  582. }
  583. return YES;
  584. }
  585. //记得默认是yes
  586. -(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
  587. {
  588. return YES;
  589. }
  590. -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  591. {
  592. return @"删除";
  593. }
  594. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  595. {
  596. [self deleteTeachTypesWithRow:indexPath.row];
  597. }
  598. - (void)didReceiveMemoryWarning {
  599. [super didReceiveMemoryWarning];
  600. // Dispose of any resources that can be recreated.
  601. }
  602. @end