123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- //
- // CheckCourseVC.m
- // LN_School
- //
- // Created by apple on 2017/4/12.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "CheckCourseVC.h"
- #import "CkeckCourceCell.h"
- @interface CheckCourseVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- UITableView *maintableView;
- UIButton *allSelectBtn, *moreSelectBtn;
- UIView *bottomBar;
- UIView *examerView;
- UITableView *examertableView;
-
- NSArray *dataArray;
- NSArray *examDataArray;
- NSString *examerID;
- NSMutableArray *sendIdArray;
- NSString *subjectString;
-
- HolderView * holderV;
- }
- @end
- @implementation CheckCourseVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"学时送审";
- self.view.backgroundColor = KBackGroundColor;
- if (_isNotification == NO)
- {
- //正常状态
- [self goBackByNavigation];
- }
- else
- {
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:RQMianColor];
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"选择阶段" style:UIBarButtonItemStyleDone target:self action:@selector(selectSubject)];
- self.navigationItem.rightBarButtonItem = item;
- [self.navigationItem.rightBarButtonItem setTintColor:RQMianColor];
-
-
- subjectString = @"1";
- dataArray = [NSArray array];
- sendIdArray = [NSMutableArray array];
-
- //tableView
- maintableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
- maintableView.height -= kNavOffSet;
- maintableView.delegate = self;
- maintableView.dataSource = self;
- maintableView.rowHeight = 100;
- maintableView.estimatedSectionFooterHeight = 0;
- [self.view addSubview:maintableView];
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
- view.backgroundColor = KBackGroundColor;
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)];
- [btn setImage:[UIImage imageNamed:@"pointMark"] withTitle:@"全选" textColor:KContentTextColor Font:Font17 forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@"pointMark_h"] withTitle:@"全选" textColor:RQMianColor Font:Font17 forState:UIControlStateSelected];
- [btn target:self Tag:1];
- [view addSubview:btn];
- allSelectBtn = btn;
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)];
- [btn setImage:[UIImage imageNamed:@"pointMark"] withTitle:@"多选" textColor:KContentTextColor Font:Font17 forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@"pointMark_h"] withTitle:@"多选" textColor:RQMianColor Font:Font17 forState:UIControlStateSelected];
- [btn target:self Tag:2];
- [view addSubview:btn];
- moreSelectBtn = btn;
-
- maintableView.tableHeaderView = view;
-
- [self setRefresh];
-
- //bottomBar
- bottomBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet - 50-kSafeAreaBottomHeight, kSize.width, 50)];
- bottomBar.backgroundColor = RQMianColor;
- [self.view addSubview:bottomBar];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0, 50)];
- [btn setTitle:@"批量考核" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:3];
- [bottomBar addSubview:btn];
- [btn addViewWithRect:CGRectMake(kSize.width/2.0, 0, 1, 50)];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 50)];
- [btn setTitle:@"批量送审" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:4];
- [bottomBar addSubview:btn];
-
- bottomBar.hidden = YES;
-
-
- [self trainTimes];
-
- holderV = [[HolderView alloc]initWithFrame:kFrame];
- [holderV freshBlock:^{
- [self trainTimes];
- }];
- [self.view addSubview:holderV];
- }
- -(void)setRefresh{
-
- __weak typeof(self) weakSelf = self;
- MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf trainTimes];
- }];
- maintableView.mj_header = mj_header;
- }
- -(void)dismissNavgation
- {
- [myDelegate initHomeVC];
- }
- - (void)setExamer {
-
- //懒加载 没有的时候就init一个
- if (!examerView) {
-
- examerView = [[UIView alloc] initWithFrame:kFrame];
- examerView.backgroundColor = windowBlockColor;
-
- examertableView = [[UITableView alloc] initWithFrame:CGRectMake(30, (kSize.height - kNavOffSet - 200)/2.0, kSize.width - 60, 200) style:UITableViewStylePlain];
- [examertableView borderCornorRadios:7];
- examertableView.backgroundColor = KBackGroundColor;
- examertableView.delegate = self;
- examertableView.dataSource = self;
- [examerView addSubview:examertableView];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width - 60, 50)];
- [label setText:@"请选择考核员" Font:Font18 TextColor:KSubTitleColor Alignment:NSTextAlignmentCenter];
- [label addSelfViewWithRect:CGRectMake(10, 48, kSize.width - 80, 2) Color:kLineColor];
- examertableView.tableHeaderView = label;
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, examertableView.y + examertableView.height, kSize.width - 60, 40)];
- view.backgroundColor = KBackGroundColor;
- [examerView addSubview:view];
- [view borderCornorRadios:7];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/2.0 - 30, 40)];
- [btn setTitle:@"取消" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:5];
- [view addSubview:btn];
- [btn addViewWithRect:CGRectMake(0, 0, kSize.width - 60, 1)];
- [btn addViewWithRect:CGRectMake(kSize.width/2.0 - 30, 0, 1, 40)];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 - 30, 0, kSize.width/2.0 - 30, 40)];
- [btn setTitle:@"确定" textColor:RQMianColor font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:6];
- [view addSubview:btn];
- }
-
- examerID = @"";
- [self.view addSubview:examerView];
-
- examDataArray = [NSArray array];
- [self getTrainExams];
- }
- #pragma mark Action
- - (void)selectSubject {
-
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"请选择培训阶段" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"第一阶段",@"第二阶段",@"第三阶段",@"第四阶段"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
- if (selectedOtherButtonIndex != NSNotFound) {
- subjectString = [NSString stringWithFormat:@"%ld",(long)selectedOtherButtonIndex + 1];
- [self trainTimes];
- }
- }];
- }
- - (void)btnClick:(UIButton *)sender {
-
- if (sender.tag == 1) {
- allSelectBtn.selected = !allSelectBtn.selected;
- if (allSelectBtn.selected == NO) {
- [sendIdArray removeAllObjects];
- }else {
- for (NSDictionary *dic in dataArray) {
- if (![sendIdArray containsObject:dic[@"ID"]]) {
- [sendIdArray addObject:dic[@"ID"]];
- }
- }
- moreSelectBtn.selected = YES;
-
- [self showBottomBar];
- }
-
- [maintableView reloadData];
- return;
- }
-
- if (sender.tag == 2) {
- moreSelectBtn.selected = !moreSelectBtn.selected;
-
- if (moreSelectBtn.selected == NO) {
- [sendIdArray removeAllObjects];
- allSelectBtn.selected = NO;
- [self hideBottomBar];
- }else {
- [self showBottomBar];
- }
-
- [maintableView reloadData];
- return;
- }
-
- if (sender.tag == 3) {
-
- if (sendIdArray.count < 1) {
- ShowMsg(@"请选择待考核学时");
- return;
- }
- [self setExamer];
- return;
- }
-
- if (sender.tag == 4) {
- [self trainSend];
- return;
- }
-
- if (sender.tag == 5) {
- //取消选择考核人
- examerID = @"";
- [examerView removeFromSuperview];
- return;
- }
-
- if (sender.tag == 6) {
- //选择考核人
- if (examerID.length < 1) {
- ShowMsg(@"请选择考核人");
- return;
- }
- [examerView removeFromSuperview];
- [self trainExamWithExamer:examerID];
- return;
- }
- }
- - (void) showBottomBar {
- if (bottomBar.isHidden) {
- bottomBar.hidden = NO;
- maintableView.height -= bottomBar.height;
- }
- maintableView.mj_header = nil;
- }
- - (void)hideBottomBar {
- if (!bottomBar.isHidden) {
- bottomBar.hidden = YES;
- maintableView.height += bottomBar.height;
- }
- [self setRefresh];
- }
- #pragma mark tableView
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (tableView == examertableView) {
- return examDataArray.count;
- }
- return dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (tableView == examertableView) {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"examCell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"examCell"];
- cell.backgroundColor = KBackGroundColor;
- [cell.textLabel setTextAlignment:NSTextAlignmentCenter];
- }
-
- NSDictionary *dic = examDataArray[indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"DQMC"],dic[@"EI_NAME"]];
-
- return cell;
- }
-
-
- CkeckCourceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil) {
- cell = [[CkeckCourceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- NSDictionary *dict = dataArray[indexPath.row];
- cell.dataDic = dict;
- [cell clickSendBtnWithBlock:^(NSString *cellString) {
- if (sendIdArray.count > 0) {
- [sendIdArray removeAllObjects];
- }
- [sendIdArray addObject:[[cellString componentsSeparatedByString:@"-"] lastObject]];
- NSString *cellType = [[cellString componentsSeparatedByString:@"-"] firstObject];
- if ([cellType isEqualToString:@"1"]) {
- //考核
- [self setExamer];
- }
- if ([cellType isEqualToString:@"2"]) {
- //送审
- [self trainSend];
- }
- }];
-
-
- if (moreSelectBtn.selected) {
- cell.isShowImg = YES;
- cell.checkBtn.userInteractionEnabled = NO;
- [cell.checkBtn setTitleColor:KContentTextColor forState:UIControlStateNormal];
- cell.checkBtn.layer.borderColor = KContentTextColor.CGColor;
- }else {
- cell.isShowImg = NO;
- cell.checkBtn.userInteractionEnabled = YES;
- [cell.checkBtn setTitleColor:RQMianColor forState:UIControlStateNormal];
- cell.checkBtn.layer.borderColor = RQMianColor.CGColor;
- }
-
- if (allSelectBtn.selected) {
- //全选
- cell.cellIsSelected = YES;
- }else {
-
- if (moreSelectBtn.selected) {
-
- if ([sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
- cell.cellIsSelected = YES;
- }else {
- cell.cellIsSelected = NO;
- }
- }else {
- cell.cellIsSelected = NO;
- }
- }
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
- if (tableView == examertableView) {
-
- NSDictionary *dic = examDataArray[indexPath.row];
- examerID = [dic[@"EI_ID"] stringValue];
- return;
- }
-
-
- if (!moreSelectBtn.selected) {
- return;
- }
-
- NSDictionary *dict = dataArray[indexPath.row];
-
- CkeckCourceCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- if (cell.cellIsSelected) {
- cell.cellIsSelected = NO;
- if ([sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
- [sendIdArray removeObject:[dict[@"STUDENT"] stringValue]];
- }
- if (allSelectBtn.selected) {
- allSelectBtn.selected = NO;
- }
- }else {
- cell.cellIsSelected = YES;
- if (![sendIdArray containsObject:[dict[@"STUDENT"] stringValue]]) {
- [sendIdArray addObject:[dict[@"STUDENT"] stringValue]];
- }
-
- if (sendIdArray.count == dataArray.count) {
- allSelectBtn.selected = YES;
- }
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 10;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [UIView new];
- }
- #pragma mark 数据请求
- //送审列表
- - (void)trainTimes {
-
- if (![NetManager connectedToNetWork]) {
- [maintableView.mj_header endRefreshing];
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
- [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
- [dic setObject:subjectString forKey:@"subject"];
- [dic setObject:@"0" forKey:@"isPage"];
- [dic setObject:@"" forKey:@"pageSize"];
- [dic setObject:@"" forKey:@"currentPage"];
-
- NSString *method = @"trainTimes";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- holderV.hidden = NO;
- [maintableView.mj_header endRefreshing];
-
- if (!root) {
- ShowMsg(@"获取数据错误");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- dataArray = root[@"body"];
-
- if (dataArray.count > 0) {
- holderV.hidden = YES;
- }
-
- [maintableView reloadData];
- }];
- }
- //考核员列表
- - (void)getTrainExams {
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
-
- NSString *method = @"getTrainExams";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsg(@"获取失败,请重试");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- examDataArray = root[@"body"];
- [examertableView reloadData];
- }];
- }
- //考核
- - (void)trainExamWithExamer:(NSString *)examerId {
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (sendIdArray.count < 1) {
- ShowMsg(@"请选择待考核学时");
- return;
- }
-
- NSString *ids = @"";
- for (NSString *str in sendIdArray) {
- for (NSDictionary *dict in dataArray) {
- if ([[dict[@"STUDENT"] stringValue] isEqualToString:str]) {
- if ([dict[@"EXAMERNAME"] length] < 1) {
- ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",str]];
- }
- break;
- }
- }
- }
-
- if (ids.length < 1) {
- ShowMsg(@"所选学时已考核");
- return;
- }
- ids = [ids substringToIndex:ids.length - 1];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:examerId forKey:@"examerId"];
- [dic setObject:ids forKey:@"stuIds"];
- [dic setObject:subjectString forKey:@"subject"];
-
- NSString *method = @"trainExam";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsg(@"考核学时失败,请重试");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- [sendIdArray removeAllObjects];
- allSelectBtn.selected = NO;
- moreSelectBtn.selected = NO;
-
- maintableView.height += bottomBar.height;
- bottomBar.hidden = YES;
- [self trainTimes];
- }];
- }
- //送审
- - (void)trainSend {
-
- if ([defUser.userDict[@"qz"] length] < 1) {
- ShowMsg(@"当前账户没有送审学时权限!");
- return;
- }
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (sendIdArray.count < 1) {
- ShowMsg(@"请选择待审核学时");
- return;
- }
-
- NSString *ids = @"";
- for (NSString *str in sendIdArray) {
- for (NSDictionary *dict in dataArray) {
- if ([[dict[@"STUDENT"] stringValue] isEqualToString:str]) {
- if ([dict[@"EXAMERNAME"] length] > 1) {
- ids = [ids stringByAppendingString:[NSString stringWithFormat:@"%@,",str]];
- }
- break;
- }
- }
- }
- if (ids.length < 1) {
- ShowMsg(@"所选学时已送审");
- return;
- }
- ids = [ids substringToIndex:ids.length - 1];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
- [dic setObject:ids forKey:@"stuIds"];
- [dic setObject:subjectString forKey:@"subject"];
-
- NSString *method = @"trainSend";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsg(@"审核学时失败,请重试");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- [sendIdArray removeAllObjects];
- allSelectBtn.selected = NO;
- moreSelectBtn.selected = NO;
-
- maintableView.height += bottomBar.height;
- bottomBar.hidden = YES;
- [self trainTimes];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|