EditPriceVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. //
  2. // EditPriceVC.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/19.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "EditPriceVC.h"
  9. #import "applyCell.h"
  10. #import "TrainPriceDetail.h"
  11. @interface EditPriceVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
  12. {
  13. UITableView *_tableView;
  14. NSArray * _titles;
  15. NSArray *_dataArr;
  16. NSArray *_sheetsArray;
  17. NSString *_bustype;
  18. NSArray *_vehicletype;//车辆类型
  19. NSArray *_chargemode;//收费模式
  20. NSArray *_trainningtime;//培训时段
  21. NSArray *_paymode;//付费模式
  22. NSArray *_trainningmode;//培训模式
  23. NSArray * _subject;//培训部分
  24. }
  25. @end
  26. @implementation EditPriceVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [self myInit];
  30. }
  31. -(void)myInit{
  32. if ([self.type isEqualToString:@"1"]) {
  33. self.navigationItem.title = @"新增培训价格";
  34. }else{
  35. self.navigationItem.title = @"修改培训价格";
  36. }
  37. self.view.backgroundColor = KBackGroundColor;
  38. [self goBackByNavigation];
  39. _vehicletype = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"];
  40. _chargemode = @[@"一次性收费",@"计时收费",@"分段式收费",@"其它"];
  41. _trainningtime = @[@"普通时段",@"高峰时段",@"节假日时段"];
  42. _paymode = @[@"先学后付",@"先付后学",@"其它"];
  43. _trainningmode = @[@"定时培训",@"预约培训",@"其它"];
  44. _subject = @[@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学"];
  45. _titles = @[@[@"培训车型",@"收费模式",@"培训时段",@"付费模式",@"培训模式",@"培训部份"],@[@"价格",@"班级名称"],@[@"服务内容"]];
  46. if ([self.type isEqualToString: @"1"]) {
  47. //新增
  48. //@[@"C1-小型汽车 >",@"收费模式 >",@"培训时段 >",@"付费模式 >",@"培训模式 >",@"培训部份 >"]]
  49. _dataArr = @[[NSMutableArray arrayWithArray:@[@[@"C1-小型汽车 >",@"C1"],@[@" >",@""],@[@" >",@""],@[@" >",@""],@[@" >",@""],@[@" >",@""]]],//车型后面的对应暂时没用到@"C1"
  50. [NSMutableArray arrayWithArray:@[@"请输入价格",@"请输入班级名称"]],
  51. [NSMutableArray arrayWithArray:@[@"请输入服务内容"]]
  52. ];
  53. }else{
  54. //修改
  55. //marr1
  56. NSString * tfStr = @">";
  57. NSMutableArray *marr1 = [NSMutableArray new];
  58. for (NSString * str in _vehicletype) {
  59. if([str rangeOfString:self.theDic[@"CSI_VEHICLETYPE"]].location !=NSNotFound)
  60. {
  61. tfStr = [NSString stringWithFormat:@"%@ >",str];
  62. }
  63. }
  64. [marr1 addObject:@[tfStr,self.theDic[@"CSI_VEHICLETYPE"]]];
  65. //
  66. NSInteger index = [self.theDic[@"CSI_CHARGEMODE"] integerValue];
  67. if (index == 9) {
  68. tfStr = [NSString stringWithFormat:@"%@ >",[_chargemode lastObject]];
  69. }else{
  70. tfStr = [NSString stringWithFormat:@"%@ >",_chargemode[index]];
  71. }
  72. [marr1 addObject:@[tfStr,self.theDic[@"CSI_CHARGEMODE"]]];
  73. //
  74. NSInteger index2 = [self.theDic[@"CSI_TRAINNINGTIME"] integerValue];
  75. tfStr = [NSString stringWithFormat:@"%@ >",_trainningtime[index2]];
  76. [marr1 addObject:@[tfStr,self.theDic[@"CSI_TRAINNINGTIME"]]];
  77. //
  78. NSInteger index3 = [self.theDic[@"CSI_PAYMODE"] integerValue];
  79. if (index == 9) {
  80. tfStr = [NSString stringWithFormat:@"%@ >",[_paymode lastObject]];
  81. }else{
  82. tfStr = [NSString stringWithFormat:@"%@ >",_paymode[index3]];
  83. }
  84. [marr1 addObject:@[tfStr,self.theDic[@"CSI_PAYMODE"]]];
  85. //
  86. NSInteger index4 = [self.theDic[@"CSI_TRAINNINGMODE"] integerValue];
  87. if (index == 9) {
  88. tfStr = [NSString stringWithFormat:@"%@ >",[_trainningmode lastObject]];
  89. }else{
  90. tfStr = [NSString stringWithFormat:@"%@ >",_trainningmode[index4]];
  91. }
  92. [marr1 addObject:@[tfStr,self.theDic[@"CSI_TRAINNINGMODE"]]];
  93. //
  94. NSInteger index5 = [self.theDic[@"CSI_SUBJECT"] integerValue];
  95. tfStr = [NSString stringWithFormat:@"%@ >",_subject[index5]];
  96. [marr1 addObject:@[tfStr,self.theDic[@"CSI_SUBJECT"]]];
  97. _dataArr = @[marr1,
  98. [NSMutableArray arrayWithArray:@[[NSString stringWithFormat:@"%@",self.theDic[@"CSI_PRICE"]],[NSString stringWithFormat:@"%@",self.theDic[@"CSI_CLASSCURR"]]]],
  99. [NSMutableArray arrayWithArray:@[[NSString stringWithFormat:@"%@",self.theDic[@"CSI_SERVICE"]]]]
  100. ];
  101. }
  102. //
  103. _tableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
  104. _tableView.height -= kNavOffSet;
  105. _tableView.delegate =self;
  106. _tableView.dataSource = self;
  107. _tableView.estimatedSectionHeaderHeight = 0;
  108. _tableView.estimatedSectionFooterHeight = 0;
  109. [self.view addSubview:_tableView];
  110. //
  111. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
  112. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
  113. btn.backgroundColor = defGreen;
  114. [btn borderCornorRadios:5];
  115. [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  116. [btn target:self Tag:1];
  117. [view addSubview:btn];
  118. _tableView.tableFooterView = view;
  119. }
  120. - (void)btnClick:(UIButton *)sender
  121. {
  122. if ([self.type isEqualToString:@"1"]) {
  123. [self editPriceWithMethod:@"addPrice"];
  124. }else{
  125. [self editPriceWithMethod:@"editPrice"];
  126. }
  127. }
  128. #pragma mark - tableview delegate
  129. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  130. {
  131. return _titles.count;
  132. }
  133. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  134. {
  135. return [_titles[section] count];
  136. }
  137. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  138. {
  139. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  140. if (cell == nil)
  141. {
  142. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  143. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  144. }
  145. [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
  146. NSArray *detailArray = _dataArr[indexPath.section];
  147. cell.detailField.delegate = self;
  148. cell.detailField.tag = indexPath.section * 10 + indexPath.row;
  149. if (indexPath.section == 0)
  150. {
  151. cell.detailField.userInteractionEnabled = NO;
  152. cell.detailField.textColor = defGreen;
  153. cell.detailField.text = detailArray[indexPath.row][0];
  154. }else {
  155. cell.detailField.userInteractionEnabled = YES;
  156. NSArray *array = @[@"请输入价格",@"请输入班级名称",@"请输入服务内容"];
  157. if ([array containsObject:detailArray[indexPath.row]]) {
  158. cell.detailField.placeholder = detailArray[indexPath.row];
  159. }else {
  160. cell.detailField.textColor = KTitleColor;
  161. cell.detailField.text = detailArray[indexPath.row];
  162. }
  163. }
  164. return cell;
  165. }
  166. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  167. {
  168. [self.view endEditing:YES];
  169. if (indexPath.section == 0)
  170. {
  171. UIActionSheet *myActionSheet;
  172. if (indexPath.row == 0) {
  173. _sheetsArray = _vehicletype;
  174. 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];
  175. }else if (indexPath.row == 1) {
  176. _sheetsArray = _chargemode;
  177. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil];
  178. }else if (indexPath.row == 2) {
  179. _sheetsArray = _trainningtime;
  180. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"普通时段",@"高峰时段",@"节假日时段", nil];
  181. }else if (indexPath.row == 3) {
  182. _sheetsArray = _paymode;
  183. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"先学后付",@"先付后学",@"其它", nil];
  184. }else if (indexPath.row == 4) {
  185. _sheetsArray = _trainningmode;
  186. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"定时培训",@"预约培训",@"其它", nil];
  187. }else if (indexPath.row == 5) {
  188. _sheetsArray = _subject;
  189. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil];
  190. }
  191. myActionSheet.tag = indexPath.row;
  192. [myActionSheet showInView:self.view];
  193. }
  194. }
  195. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  196. {
  197. return .1;
  198. }
  199. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  200. {
  201. return 25;
  202. }
  203. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  204. [self.view endEditing:YES];
  205. }
  206. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  207. {
  208. if (buttonIndex == actionSheet.cancelButtonIndex) {
  209. return;
  210. }
  211. NSMutableArray *array = [_dataArr firstObject];
  212. NSString *detailString = _sheetsArray[buttonIndex];
  213. if (actionSheet.tag == 0) {
  214. [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[detailString substringToIndex:2]]];
  215. }else{
  216. [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[NSString stringWithFormat:@"%d",(int)buttonIndex+1]]];
  217. }
  218. NSIndexPath *indexpath = [NSIndexPath indexPathForRow:actionSheet.tag inSection:0];
  219. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
  220. }
  221. #pragma mark textField
  222. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  223. {
  224. NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
  225. //获取当前cell在tableview中的位置
  226. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  227. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  228. return YES;
  229. }
  230. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  231. {
  232. NSString *textString = textField.text;
  233. NSMutableArray *array = _dataArr[textField.tag/10];
  234. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  235. [_tableView reloadData];
  236. return YES;
  237. }
  238. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  239. {
  240. [textField endEditing:YES];
  241. return YES;
  242. }
  243. #pragma mark 网络请求
  244. -(void)editPriceWithMethod:(NSString *)method{
  245. //
  246. for (NSArray *arr in _dataArr[0]) {
  247. if ([arr[1] length] == 0) {
  248. ShowMsg(@"请填写完整信息");
  249. return;
  250. }
  251. }
  252. NSArray *array = @[@"请输入价格",@"请输入班级名称"];
  253. for (NSString *str in _dataArr[1]) {
  254. if (str.length == 0 || [array containsObject:str]) {
  255. ShowMsg(@"请填写完整信息");
  256. return;
  257. }
  258. }
  259. //
  260. if (![NetManager connectedToNetWork]) {
  261. showMsgUnconnect();
  262. return;
  263. }
  264. // NSString * str = _dataArr[0][0][0];
  265. // NSString * vehicletype = [str substringToIndex:str.length-3];
  266. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  267. if ([method isEqualToString:@"editPrice"]) {
  268. [dic setObject:self.theDic[@"CSI_ID"] forKey:@"id"];
  269. }
  270. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  271. [dic setObject:_dataArr[0][0][1] forKey:@"vehicletype"];
  272. [dic setObject:_dataArr[0][1][1] forKey:@"chargemode"];
  273. [dic setObject:_dataArr[0][2][1] forKey:@"trainningtime"];
  274. [dic setObject:_dataArr[0][3][1] forKey:@"paymode"];
  275. [dic setObject:_dataArr[0][4][1] forKey:@"trainningmode"];
  276. [dic setObject:_dataArr[0][5][1] forKey:@"subject"];
  277. [dic setObject:_dataArr[1][0] forKey:@"price"];
  278. [dic setObject:_dataArr[1][1] forKey:@"classcurr"];
  279. [dic setObject:_dataArr[2][0] forKey:@"service"];
  280. [MBProgressHUD showLoadToView:self.view];
  281. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  282. [MBProgressHUD hideHUDForView:self.view];
  283. if (!root) {
  284. ShowErrorMsg(@"请求失败!");
  285. return;
  286. }
  287. if ([root[@"code"] isEqualToString:@"1"]) {
  288. ShowErrorMsg(root[@"msg"]);
  289. NSLog(@"%@",root[@"msg"]);
  290. return;
  291. }
  292. if ([self.type isEqualToString:@"1"]) {
  293. ShowMsg(@"添加成功");
  294. }else{
  295. ShowMsg(@"修改成功");
  296. if (self.blcok) {
  297. self.blcok();
  298. }
  299. }
  300. [self.navigationController popViewControllerAnimated:YES];
  301. }];
  302. }
  303. - (void)didReceiveMemoryWarning {
  304. [super didReceiveMemoryWarning];
  305. // Dispose of any resources that can be recreated.
  306. }
  307. /*
  308. #pragma mark - Navigation
  309. // In a storyboard-based application, you will often want to do a little preparation before navigation
  310. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  311. // Get the new view controller using [segue destinationViewController].
  312. // Pass the selected object to the new view controller.
  313. }
  314. */
  315. @end