123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- //
- // EditPriceVC.m
- // LN_School
- //
- // Created by EchoShacolee on 2017/4/19.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "EditPriceVC.h"
- #import "applyCell.h"
- #import "TrainPriceDetail.h"
- @interface EditPriceVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
- {
- UITableView *_tableView;
- NSArray * _titles;
- NSArray *_dataArr;
- NSArray *_sheetsArray;
- NSString *_bustype;
-
- NSArray *_vehicletype;//车辆类型
- NSArray *_chargemode;//收费模式
- NSArray *_trainningtime;//培训时段
- NSArray *_paymode;//付费模式
- NSArray *_trainningmode;//培训模式
- NSArray * _subject;//培训部分
- }
- @end
- @implementation EditPriceVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self myInit];
- }
- -(void)myInit{
-
- if ([self.type isEqualToString:@"1"]) {
- self.navigationItem.title = @"新增培训价格";
- }else{
- self.navigationItem.title = @"修改培训价格";
- }
-
- self.view.backgroundColor = KBackGroundColor;
- [self goBackByNavigation];
-
- _vehicletype = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"];
- _chargemode = @[@"一次性收费",@"计时收费",@"分段式收费",@"其它"];
- _trainningtime = @[@"普通时段",@"高峰时段",@"节假日时段"];
- _paymode = @[@"先学后付",@"先付后学",@"其它"];
- _trainningmode = @[@"定时培训",@"预约培训",@"其它"];
- _subject = @[@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学"];
-
- _titles = @[@[@"培训车型",@"收费模式",@"培训时段",@"付费模式",@"培训模式",@"培训部份"],@[@"价格",@"班级名称"],@[@"服务内容"]];
-
-
- if ([self.type isEqualToString: @"1"]) {
- //新增
- //@[@"C1-小型汽车 >",@"收费模式 >",@"培训时段 >",@"付费模式 >",@"培训模式 >",@"培训部份 >"]]
- _dataArr = @[[NSMutableArray arrayWithArray:@[@[@"C1-小型汽车 >",@"C1"],@[@" >",@""],@[@" >",@""],@[@" >",@""],@[@" >",@""],@[@" >",@""]]],//车型后面的对应暂时没用到@"C1"
- [NSMutableArray arrayWithArray:@[@"请输入价格",@"请输入班级名称"]],
- [NSMutableArray arrayWithArray:@[@"请输入服务内容"]]
- ];
- }else{
- //修改
- //marr1
- NSString * tfStr = @">";
-
- NSMutableArray *marr1 = [NSMutableArray new];
-
- for (NSString * str in _vehicletype) {
- if([str rangeOfString:self.theDic[@"CSI_VEHICLETYPE"]].location !=NSNotFound)
- {
- tfStr = [NSString stringWithFormat:@"%@ >",str];
- }
- }
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_VEHICLETYPE"]]];
-
- //
- NSInteger index = [self.theDic[@"CSI_CHARGEMODE"] integerValue];
- if (index == 9) {
- tfStr = [NSString stringWithFormat:@"%@ >",[_chargemode lastObject]];
- }else{
- tfStr = [NSString stringWithFormat:@"%@ >",_chargemode[index]];
- }
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_CHARGEMODE"]]];
-
- //
- NSInteger index2 = [self.theDic[@"CSI_TRAINNINGTIME"] integerValue];
- tfStr = [NSString stringWithFormat:@"%@ >",_trainningtime[index2]];
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_TRAINNINGTIME"]]];
-
- //
- NSInteger index3 = [self.theDic[@"CSI_PAYMODE"] integerValue];
- if (index == 9) {
- tfStr = [NSString stringWithFormat:@"%@ >",[_paymode lastObject]];
- }else{
- tfStr = [NSString stringWithFormat:@"%@ >",_paymode[index3]];
- }
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_PAYMODE"]]];
-
- //
- NSInteger index4 = [self.theDic[@"CSI_TRAINNINGMODE"] integerValue];
- if (index == 9) {
- tfStr = [NSString stringWithFormat:@"%@ >",[_trainningmode lastObject]];
- }else{
- tfStr = [NSString stringWithFormat:@"%@ >",_trainningmode[index4]];
- }
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_TRAINNINGMODE"]]];
-
- //
- NSInteger index5 = [self.theDic[@"CSI_SUBJECT"] integerValue];
- tfStr = [NSString stringWithFormat:@"%@ >",_subject[index5]];
- [marr1 addObject:@[tfStr,self.theDic[@"CSI_SUBJECT"]]];
-
- _dataArr = @[marr1,
- [NSMutableArray arrayWithArray:@[[NSString stringWithFormat:@"%@",self.theDic[@"CSI_PRICE"]],[NSString stringWithFormat:@"%@",self.theDic[@"CSI_CLASSCURR"]]]],
- [NSMutableArray arrayWithArray:@[[NSString stringWithFormat:@"%@",self.theDic[@"CSI_SERVICE"]]]]
- ];
- }
-
-
- //
- _tableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
- _tableView.height -= kNavOffSet;
- _tableView.delegate =self;
- _tableView.dataSource = self;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- [self.view addSubview:_tableView];
-
- //
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
- btn.backgroundColor = RQMianColor;
- [btn borderCornorRadios:5];
- [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:1];
- [view addSubview:btn];
- _tableView.tableFooterView = view;
-
- }
- - (void)btnClick:(UIButton *)sender
- {
- if ([self.type isEqualToString:@"1"]) {
- [self editPriceWithMethod:@"addPrice"];
- }else{
- [self editPriceWithMethod:@"editPrice"];
- }
- }
- #pragma mark - tableview delegate
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return _titles.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_titles[section] count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
-
- NSArray *detailArray = _dataArr[indexPath.section];
-
- cell.detailField.delegate = self;
- cell.detailField.tag = indexPath.section * 10 + indexPath.row;
-
- if (indexPath.section == 0)
- {
- cell.detailField.userInteractionEnabled = NO;
- cell.detailField.textColor = RQMianColor;
- cell.detailField.text = detailArray[indexPath.row][0];
- }else {
- if (indexPath.section==1 && indexPath.row==0) {
- cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
- }
- cell.detailField.userInteractionEnabled = YES;
- NSArray *array = @[@"请输入价格",@"请输入班级名称",@"请输入服务内容"];
- if ([array containsObject:detailArray[indexPath.row]]) {
- cell.detailField.placeholder = detailArray[indexPath.row];
- }else {
- cell.detailField.textColor = KTitleColor;
- cell.detailField.text = detailArray[indexPath.row];
- }
- }
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [self.view endEditing:YES];
-
- if (indexPath.section == 0)
- {
- UIActionSheet *myActionSheet;
- if (indexPath.row == 0) {
-
- _sheetsArray = _vehicletype;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车", nil];
- }else if (indexPath.row == 1) {
-
- _sheetsArray = _chargemode;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil];
- }else if (indexPath.row == 2) {
-
- _sheetsArray = _trainningtime;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"普通时段",@"高峰时段",@"节假日时段", nil];
- }else if (indexPath.row == 3) {
-
- _sheetsArray = _paymode;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"先学后付",@"先付后学",@"其它", nil];
- }else if (indexPath.row == 4) {
-
- _sheetsArray = _trainningmode;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"定时培训",@"预约培训",@"其它", nil];
- }else if (indexPath.row == 5) {
-
- _sheetsArray = _subject;
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil];
- }
- myActionSheet.tag = indexPath.row;
- [myActionSheet showInView:self.view];
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 25;
- }
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
-
- [self.view endEditing:YES];
- }
- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == actionSheet.cancelButtonIndex) {
- return;
- }
-
- NSMutableArray *array = [_dataArr firstObject];
-
- NSString *detailString = _sheetsArray[buttonIndex];
-
- if (actionSheet.tag == 0) {
- [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[detailString substringToIndex:2]]];
- }else{
- [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[NSString stringWithFormat:@"%d",(int)buttonIndex+1]]];
- }
-
-
- NSIndexPath *indexpath = [NSIndexPath indexPathForRow:actionSheet.tag inSection:0];
- [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
- }
- #pragma mark textField
- -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- {
- NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
-
- //获取当前cell在tableview中的位置
- CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
-
- [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
-
- return YES;
- }
- -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
- {
-
- NSString *textString = textField.text;
-
- NSMutableArray *array = _dataArr[textField.tag/10];
- [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
-
- [_tableView reloadData];
- return YES;
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField endEditing:YES];
- return YES;
- }
- #pragma mark 网络请求
- -(void)editPriceWithMethod:(NSString *)method{
-
- //
- for (NSArray *arr in _dataArr[0]) {
- if ([arr[1] length] == 0) {
- ShowMsg(@"请填写完整信息");
- return;
- }
- }
-
- NSArray *array = @[@"请输入价格",@"请输入班级名称"];
- for (NSString *str in _dataArr[1]) {
- if (str.length == 0 || [array containsObject:str]) {
- ShowMsg(@"请填写完整信息");
- return;
- }
- }
-
-
- //
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- // NSString * str = _dataArr[0][0][0];
- // NSString * vehicletype = [str substringToIndex:str.length-3];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- if ([method isEqualToString:@"editPrice"]) {
- [dic setObject:self.theDic[@"CSI_ID"] forKey:@"id"];
- }
-
- [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
- [dic setObject:_dataArr[0][0][1] forKey:@"vehicletype"];
- [dic setObject:_dataArr[0][1][1] forKey:@"chargemode"];
- [dic setObject:_dataArr[0][2][1] forKey:@"trainningtime"];
- [dic setObject:_dataArr[0][3][1] forKey:@"paymode"];
- [dic setObject:_dataArr[0][4][1] forKey:@"trainningmode"];
- [dic setObject:_dataArr[0][5][1] forKey:@"subject"];
-
- [dic setObject:_dataArr[1][0] forKey:@"price"];
-
- [dic setObject:_dataArr[1][1] forKey:@"classcurr"];
-
- [dic setObject:_dataArr[2][0] forKey:@"service"];
-
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- NSLog(@"%@",root[@"msg"]);
- return;
- }
-
- if ([self.type isEqualToString:@"1"]) {
- ShowMsg(@"添加成功");
- }else{
- ShowMsg(@"修改成功");
- if (self.blcok) {
- self.blcok();
- }
- }
-
- [self.navigationController popViewControllerAnimated:YES];
-
- }];
-
- }
- #pragma mark - 限制输入字符
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- if (textField.tag == 10 && range.location >= 5) {
- return NO;
- }
- if (textField.tag == 11 && range.location >= 10) {
- return NO;
- }
- return YES;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|