TrainPriceList.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. //
  2. // TrainPriceList.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/19.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "TrainPriceList.h"
  9. #import "TrainPriceListCell.h"
  10. #import "TrainPriceDetail.h"
  11. #import "EditPriceVC.h"
  12. @interface TrainPriceList ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate>
  13. {
  14. NSArray * _dataArr;
  15. UITableView * _tableView;
  16. UISegmentedControl * _seg;
  17. //用于记录选中的cell
  18. NSMutableArray *_selectedIndexPathes;
  19. HolderView * holderV;
  20. //记录搜索条件
  21. NSString *_charegeModeStr;
  22. NSString *_trainningtimeStr;
  23. NSString *_trainningmodeStr;
  24. NSString *_subjectStr;
  25. }
  26. @end
  27. @implementation TrainPriceList
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.navigationItem.title = @"培训价格列表";
  31. self.view.backgroundColor = KBackGroundColor;
  32. _dataArr = [NSArray new];
  33. _selectedIndexPathes = [[NSMutableArray alloc] init];
  34. _charegeModeStr = @"";
  35. _trainningmodeStr = @"";
  36. _trainningtimeStr = @"";
  37. _subjectStr = @"";
  38. [self myInit];
  39. [self createBottomBarWithtoolTitles:@[@"新增",@"删除"]];
  40. }
  41. -(void)viewWillAppear:(BOOL)animated{
  42. [super viewWillAppear:animated];
  43. [self getData];
  44. }
  45. -(void)myInit{
  46. //
  47. [self goBackByNavigation];
  48. //
  49. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"全部价格" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtn)];
  50. [self.navigationItem.rightBarButtonItem setTintColor:RQMianColor];
  51. //
  52. UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 25)];
  53. [lab setText:@"设置搜索条件:" Font:Font14 TextColor:RQMianColor];
  54. [self.view addSubview:lab];
  55. _seg = [[UISegmentedControl alloc]initWithItems:@[@"收费模式",@"培训阶段",@"培训模式",@"培训部分"]];
  56. _seg.frame = CGRectMake(10, 25, kSize.width-20, 40);
  57. _seg.tintColor = RQMianColor;
  58. _seg.backgroundColor = [UIColor whiteColor];
  59. _seg.momentary = YES;
  60. [_seg addTarget:self action:@selector(segClick:) forControlEvents:UIControlEventValueChanged];
  61. [self.view addSubview:_seg];
  62. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-kNavOffSet-CGRectGetMaxY(_seg.frame)-JOb_DETAIL_BOTTOMBAR_HEIGHT-kSafeAreaBottomHeight) style:UITableViewStylePlain];
  63. _tableView.estimatedRowHeight = 100.0f;
  64. _tableView.tableFooterView = [UIView new];
  65. _tableView.dataSource = self;
  66. _tableView.delegate = self;
  67. [_tableView registerNib:[UINib nibWithNibName:@"TrainPriceListCell" bundle:nil] forCellReuseIdentifier:@"cellId"];
  68. [self.view addSubview:_tableView];
  69. holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  70. [holderV freshBlock:^{
  71. [self getData];
  72. }];
  73. [self.view addSubview:holderV];
  74. }
  75. -(void)rightBtn{
  76. _charegeModeStr = @"";
  77. _trainningmodeStr = @"";
  78. _trainningtimeStr = @"";
  79. _subjectStr = @"";
  80. [self getData];
  81. }
  82. -(void)segClick:(UISegmentedControl *)seg{
  83. switch (seg.selectedSegmentIndex) {
  84. case 0:
  85. {
  86. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择收费模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil];
  87. sheet.tag = 1;
  88. [sheet showInView:self.view];
  89. }
  90. break;
  91. case 1:
  92. {
  93. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训阶段" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"普通时段",@"高峰时段",@"节假日时段", nil];
  94. sheet.tag = 2;
  95. [sheet showInView:self.view];
  96. }
  97. break;
  98. case 2:
  99. {
  100. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"定时培训",@"预约培训",@"其它", nil];
  101. sheet.tag = 3;
  102. [sheet showInView:self.view];
  103. }
  104. break;
  105. case 3:
  106. {
  107. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训部分" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil];
  108. sheet.tag = 4;
  109. [sheet showInView:self.view];
  110. }
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. #pragma mark 创建BottomBarButton
  117. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  118. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  119. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  120. for (int i=0; i<toolTitles.count; i++) {
  121. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  122. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-kNavOffSet-kSafeAreaBottomHeight, widthBtn, HeightBth);
  123. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  124. button.backgroundColor = RQMianColor;
  125. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  126. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  127. button.tag = 10+i;
  128. [self.view addSubview:button];
  129. }
  130. }
  131. -(void)btnClick:(UIButton *)sender{
  132. switch (sender.tag) {
  133. case 11:
  134. {
  135. //删除培训价格
  136. if ([sender.currentTitle isEqualToString:@"删除"]) {
  137. [_tableView setEditing:YES animated:YES];
  138. [sender setTitle:@"确定删除" forState:UIControlStateNormal];
  139. } else {
  140. [_tableView setEditing:NO animated:YES];
  141. [sender setTitle:@"删除" forState:UIControlStateNormal];
  142. UIButton * btn = [self.view viewWithTag:100];
  143. [btn removeFromSuperview];
  144. }
  145. if (_tableView.isEditing) {
  146. //清空原有的记录
  147. [_selectedIndexPathes removeAllObjects];
  148. //添加全选 取消删除
  149. float widthBtn = (kSize.width-1)/2-20;
  150. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT-5;
  151. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  152. button.frame = CGRectMake(10+widthBtn+20, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT*2-kSafeAreaBottomHeight, widthBtn, HeightBth);
  153. [button setTitle:@"取消删除" forState:UIControlStateNormal];
  154. button.backgroundColor = [UIColor lightGrayColor];
  155. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  156. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  157. button.tag = 100;
  158. [self.view addSubview:button];
  159. //添加左侧item
  160. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"全选" style:UIBarButtonItemStylePlain target:self action:@selector(selectAll:)];
  161. self.navigationItem.leftBarButtonItem = leftItem;
  162. self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
  163. } else {
  164. //删除数据源中的数据
  165. [self delPrice];
  166. [self goBackByNavigation];
  167. }
  168. }
  169. break;
  170. case 10:
  171. {
  172. [self willEditPrice];//新增培训价格
  173. }
  174. break;
  175. case 100:
  176. {
  177. [_tableView setEditing:NO animated:YES];
  178. [_selectedIndexPathes removeAllObjects];
  179. [sender removeFromSuperview];
  180. [self goBackByNavigation];
  181. UIButton * btn = [self.view viewWithTag:11];
  182. [btn setTitle:@"删除" forState:UIControlStateNormal];
  183. }
  184. break;
  185. default:
  186. break;
  187. }
  188. }
  189. -(void)willEditPrice{
  190. EditPriceVC * vc = [[EditPriceVC alloc]init];
  191. vc.type = @"1";
  192. [self navPushHideTabbarToVC:vc];
  193. }
  194. #pragma mark action代理方法
  195. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
  196. switch (actionSheet.tag) {
  197. case 1:
  198. {
  199. //0,123,9
  200. if (buttonIndex > 4) {
  201. break;
  202. }
  203. if (buttonIndex == 4) {
  204. buttonIndex = 9;
  205. }
  206. _charegeModeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex];
  207. if (buttonIndex == 0) {
  208. _charegeModeStr = @"";
  209. }
  210. [self getData];
  211. }
  212. break;
  213. case 2:
  214. {
  215. if (buttonIndex > 3) {
  216. break;
  217. }
  218. //0,1,2,3
  219. _trainningtimeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex];
  220. if (buttonIndex == 0) {
  221. _trainningtimeStr = @"";
  222. }
  223. [self getData];
  224. }
  225. break;
  226. case 3:
  227. {
  228. //0,1,2,9
  229. if (buttonIndex > 3) {
  230. break;
  231. }
  232. if (buttonIndex == 3) {
  233. buttonIndex = 9;
  234. }
  235. _trainningmodeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex];
  236. if (buttonIndex == 0) {
  237. _trainningmodeStr = @"";
  238. }
  239. [self getData];
  240. }
  241. break;
  242. case 4:
  243. {
  244. //0,1-9
  245. if (buttonIndex > 9) {
  246. break;
  247. }
  248. _subjectStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex];
  249. if (buttonIndex == 0) {
  250. _subjectStr = @"";
  251. }
  252. [self getData];
  253. }
  254. break;
  255. default:
  256. break;
  257. }
  258. }
  259. #pragma mark tableview代理方法
  260. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  261. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  262. }
  263. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  264. //当取消选中cell时,从记录的数组中删除其indexPath
  265. [_selectedIndexPathes removeObject:indexPath];
  266. self.navigationItem.leftBarButtonItem.title = @"全选";
  267. }
  268. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  269. return _dataArr.count;
  270. }
  271. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  272. TrainPriceListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
  273. [cell upDataWithDic:_dataArr[indexPath.row]];
  274. return cell;
  275. }
  276. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  277. if (_tableView.editing) {
  278. //当选中cell时,记录其indexPath
  279. [_selectedIndexPathes addObject:indexPath];
  280. return;
  281. }
  282. TrainPriceDetail * vc = [[TrainPriceDetail alloc]init];
  283. vc.theId = _dataArr[indexPath.row][@"CSI_ID"];
  284. [self navPushHideTabbarToVC:vc];
  285. }
  286. //-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  287. // return 0.1f;
  288. //}
  289. - (void)didReceiveMemoryWarning {
  290. [super didReceiveMemoryWarning];
  291. // Dispose of any resources that can be recreated.
  292. }
  293. #pragma mark 删除全选择
  294. - (void)selectAll:(UIBarButtonItem *)item {
  295. //获取表格视图内容的尺寸
  296. CGSize size = _tableView.contentSize;
  297. CGRect rect = CGRectMake(0, 0, size.width, size.height);
  298. //获取指定区域的cell的indexPath
  299. NSArray *indexPathes = [_tableView indexPathsForRowsInRect:rect];
  300. if ([item.title isEqualToString:@"全选"]) {
  301. item.title = @"取消";
  302. for (NSIndexPath *indexPath in indexPathes) {
  303. //使用代码方式选中一行
  304. [_tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
  305. }
  306. //更新选中数组
  307. _selectedIndexPathes.array = indexPathes;
  308. } else {
  309. item.title = @"全选";
  310. for (NSIndexPath *indexPath in indexPathes) {
  311. //使用代码方式取消选中一行
  312. [_tableView deselectRowAtIndexPath:indexPath animated:YES];
  313. }
  314. //清空选中cell的记录数组
  315. [_selectedIndexPathes removeAllObjects];
  316. }
  317. }
  318. #pragma mark 数据请求
  319. -(void)getData{
  320. if (![NetManager connectedToNetWork]) {
  321. showMsgUnconnect();
  322. return;
  323. }
  324. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  325. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  326. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  327. [dic setObject:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  328. [dic setObject:defUser.userDict[@"qxbh"] forKey:@"qxbh"];
  329. [dic setObject:_charegeModeStr forKey:@"chargemode"];
  330. [dic setObject:_trainningtimeStr forKey:@"trainningtime"];
  331. [dic setObject:_trainningmodeStr forKey:@"trainningmode"];
  332. [dic setObject:_subjectStr forKey:@"subject"];
  333. NSString *method = @"prices";
  334. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  335. holderV.hidden = NO;
  336. if (!root) {
  337. ShowErrorMsg(@"请求失败!");
  338. return;
  339. }
  340. if ([root[@"code"] isEqualToString:@"1"]) {
  341. ShowErrorMsg(root[@"msg"]);
  342. return;
  343. }
  344. _dataArr = root[@"body"];
  345. if (_dataArr.count > 0) {
  346. holderV.hidden = YES;
  347. }
  348. [_tableView reloadData];
  349. }];
  350. }
  351. -(void)delPrice{
  352. if (_selectedIndexPathes.count == 0) {
  353. return;
  354. }
  355. NSMutableString *mStr = [NSMutableString new];
  356. for (int i=0; i<_selectedIndexPathes.count; i++) {
  357. NSIndexPath * indexPath = _selectedIndexPathes[i];
  358. [mStr appendFormat:@",%@",_dataArr[indexPath.row][@"CSI_ID"]];
  359. }
  360. NSString * idsStr = [mStr substringFromIndex:1];
  361. if (![NetManager connectedToNetWork]) {
  362. showMsgUnconnect();
  363. return;
  364. }
  365. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  366. [dic setObject:idsStr forKey:@"ids"];
  367. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  368. [NetManager requestAnythingWithURL:@"delPrice" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  369. if (!root) {
  370. ShowErrorMsg(@"请求失败!");
  371. return;
  372. }
  373. if ([root[@"code"] isEqualToString:@"1"]) {
  374. ShowErrorMsg(root[@"msg"]);
  375. return;
  376. }
  377. ShowMsg(@"删除成功!");
  378. [self getData];
  379. }];
  380. }
  381. /*
  382. #pragma mark - Navigation
  383. // In a storyboard-based application, you will often want to do a little preparation before navigation
  384. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  385. // Get the new view controller using [segue destinationViewController].
  386. // Pass the selected object to the new view controller.
  387. }
  388. */
  389. @end