EditPriceVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 = RQMianColor;
  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 = RQMianColor;
  153. cell.detailField.text = detailArray[indexPath.row][0];
  154. }else {
  155. if (indexPath.section==1 && indexPath.row==0) {
  156. cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
  157. }
  158. cell.detailField.userInteractionEnabled = YES;
  159. NSArray *array = @[@"请输入价格",@"请输入班级名称",@"请输入服务内容"];
  160. if ([array containsObject:detailArray[indexPath.row]]) {
  161. cell.detailField.placeholder = detailArray[indexPath.row];
  162. }else {
  163. cell.detailField.textColor = KTitleColor;
  164. cell.detailField.text = detailArray[indexPath.row];
  165. }
  166. }
  167. return cell;
  168. }
  169. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  170. {
  171. [self.view endEditing:YES];
  172. if (indexPath.section == 0)
  173. {
  174. UIActionSheet *myActionSheet;
  175. if (indexPath.row == 0) {
  176. _sheetsArray = _vehicletype;
  177. 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];
  178. }else if (indexPath.row == 1) {
  179. _sheetsArray = _chargemode;
  180. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil];
  181. }else if (indexPath.row == 2) {
  182. _sheetsArray = _trainningtime;
  183. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"普通时段",@"高峰时段",@"节假日时段", nil];
  184. }else if (indexPath.row == 3) {
  185. _sheetsArray = _paymode;
  186. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"先学后付",@"先付后学",@"其它", nil];
  187. }else if (indexPath.row == 4) {
  188. _sheetsArray = _trainningmode;
  189. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"定时培训",@"预约培训",@"其它", nil];
  190. }else if (indexPath.row == 5) {
  191. _sheetsArray = _subject;
  192. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil];
  193. }
  194. myActionSheet.tag = indexPath.row;
  195. [myActionSheet showInView:self.view];
  196. }
  197. }
  198. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  199. {
  200. return .1;
  201. }
  202. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  203. {
  204. return 25;
  205. }
  206. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  207. [self.view endEditing:YES];
  208. }
  209. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  210. {
  211. if (buttonIndex == actionSheet.cancelButtonIndex) {
  212. return;
  213. }
  214. NSMutableArray *array = [_dataArr firstObject];
  215. NSString *detailString = _sheetsArray[buttonIndex];
  216. if (actionSheet.tag == 0) {
  217. [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[detailString substringToIndex:2]]];
  218. }else{
  219. [array replaceObjectAtIndex:actionSheet.tag withObject:@[[NSString stringWithFormat:@"%@ >",detailString],[NSString stringWithFormat:@"%d",(int)buttonIndex+1]]];
  220. }
  221. NSIndexPath *indexpath = [NSIndexPath indexPathForRow:actionSheet.tag inSection:0];
  222. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
  223. }
  224. #pragma mark textField
  225. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  226. {
  227. NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
  228. //获取当前cell在tableview中的位置
  229. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  230. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  231. return YES;
  232. }
  233. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  234. {
  235. NSString *textString = textField.text;
  236. NSMutableArray *array = _dataArr[textField.tag/10];
  237. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  238. [_tableView reloadData];
  239. return YES;
  240. }
  241. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  242. {
  243. [textField endEditing:YES];
  244. return YES;
  245. }
  246. #pragma mark 网络请求
  247. -(void)editPriceWithMethod:(NSString *)method{
  248. //
  249. for (NSArray *arr in _dataArr[0]) {
  250. if ([arr[1] length] == 0) {
  251. ShowMsg(@"请填写完整信息");
  252. return;
  253. }
  254. }
  255. NSArray *array = @[@"请输入价格",@"请输入班级名称"];
  256. for (NSString *str in _dataArr[1]) {
  257. if (str.length == 0 || [array containsObject:str]) {
  258. ShowMsg(@"请填写完整信息");
  259. return;
  260. }
  261. }
  262. //
  263. if (![NetManager connectedToNetWork]) {
  264. showMsgUnconnect();
  265. return;
  266. }
  267. // NSString * str = _dataArr[0][0][0];
  268. // NSString * vehicletype = [str substringToIndex:str.length-3];
  269. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  270. if ([method isEqualToString:@"editPrice"]) {
  271. [dic setObject:self.theDic[@"CSI_ID"] forKey:@"id"];
  272. }
  273. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  274. [dic setObject:_dataArr[0][0][1] forKey:@"vehicletype"];
  275. [dic setObject:_dataArr[0][1][1] forKey:@"chargemode"];
  276. [dic setObject:_dataArr[0][2][1] forKey:@"trainningtime"];
  277. [dic setObject:_dataArr[0][3][1] forKey:@"paymode"];
  278. [dic setObject:_dataArr[0][4][1] forKey:@"trainningmode"];
  279. [dic setObject:_dataArr[0][5][1] forKey:@"subject"];
  280. [dic setObject:_dataArr[1][0] forKey:@"price"];
  281. [dic setObject:_dataArr[1][1] forKey:@"classcurr"];
  282. [dic setObject:_dataArr[2][0] forKey:@"service"];
  283. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  284. if (!root) {
  285. ShowErrorMsg(@"请求失败!");
  286. return;
  287. }
  288. if ([root[@"code"] isEqualToString:@"1"]) {
  289. ShowErrorMsg(root[@"msg"]);
  290. NSLog(@"%@",root[@"msg"]);
  291. return;
  292. }
  293. if ([self.type isEqualToString:@"1"]) {
  294. ShowMsg(@"添加成功");
  295. }else{
  296. ShowMsg(@"修改成功");
  297. if (self.blcok) {
  298. self.blcok();
  299. }
  300. }
  301. [self.navigationController popViewControllerAnimated:YES];
  302. }];
  303. }
  304. #pragma mark - 限制输入字符
  305. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  306. if (textField.tag == 10 && range.location >= 5) {
  307. return NO;
  308. }
  309. if (textField.tag == 11 && range.location >= 10) {
  310. return NO;
  311. }
  312. return YES;
  313. }
  314. - (void)didReceiveMemoryWarning {
  315. [super didReceiveMemoryWarning];
  316. // Dispose of any resources that can be recreated.
  317. }
  318. /*
  319. #pragma mark - Navigation
  320. // In a storyboard-based application, you will often want to do a little preparation before navigation
  321. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  322. // Get the new view controller using [segue destinationViewController].
  323. // Pass the selected object to the new view controller.
  324. }
  325. */
  326. @end