EquipmentDetailVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. //
  2. // EquipmentDetailVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/5/10.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "EquipmentDetailVC.h"
  9. #import "DateView.h"
  10. @interface EquipmentDetailVC ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. UILabel *priceLabel;
  13. UITableView *mainTableView;
  14. UILabel *noReserveLabel;
  15. UIButton *beginBtn, *endBtn;
  16. UIButton *discountBtn;
  17. NSArray *dataArray;
  18. NSString *beginTime, *endTime;
  19. CGFloat price;
  20. BOOL isUseDisCount;
  21. }
  22. @end
  23. @implementation EquipmentDetailVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.title = [NSString stringWithFormat:@" 模拟设备%@",_devDic[@"CODE"]];
  27. self.view.backgroundColor = backGroundColor;
  28. [self configNavigationBar];
  29. isUseDisCount = NO;
  30. beginTime = endTime = @"";
  31. dataArray = [NSArray array];
  32. CGFloat x,y,w,h,bd;
  33. x = y = bd = 10;
  34. w = kSize.width - 2*x;
  35. h = 40;
  36. UILabel *label = [[UILabel alloc] setxywh];
  37. label.backgroundColor = backGroundColor;
  38. [label borderColor:RQlineColor width:1 cornorRadius:5];
  39. [label setText:[NSString stringWithFormat:@" 训练点:%@",_imiAppoint] Font:Font17 TextColor:kTitleColor];
  40. [self.view addSubview:label];
  41. y += h + bd;
  42. h = 90;
  43. label = [[UILabel alloc] setxywh];
  44. label.backgroundColor = backGroundColor;
  45. [label borderColor:RQlineColor width:1 cornorRadius:5];
  46. label.numberOfLines = 3;
  47. [label setText:@" 培训日期:\n 开放时间:\n 培训价格:" Font:Font17 TextColor:kTitleColor];
  48. [self.view addSubview:label];
  49. priceLabel = label;
  50. y += h + bd;
  51. h = 30;
  52. label = [[UILabel alloc] setxywh];
  53. [label setText:@" 已约时段:" Font:Font17 TextColor:kTitleColor];
  54. [self.view addSubview:label];
  55. y += h + bd/2.0;
  56. h = kSize.height - y - kNavOffSet - 200;
  57. mainTableView = [[UITableView alloc] initWithFrame:setDIYFrame style:UITableViewStylePlain];
  58. mainTableView.backgroundColor = backGroundColor;
  59. [mainTableView borderColor:RQlineColor width:1 cornorRadius:5];
  60. mainTableView.delegate = self;
  61. mainTableView.dataSource = self;
  62. [self.view addSubview:mainTableView];
  63. [mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  64. //如果有预约就隐藏
  65. label = [[UILabel alloc] setxywh];
  66. label.x += 10;
  67. label.y += 10;
  68. label.width -= 20;
  69. label.height = 50;
  70. label.numberOfLines = 0;
  71. [label setText:@"恭喜您,该设备还没有任何预约!" Font:FontTitle TextColor:[UIColor orangeColor]];
  72. [self.view addSubview:label];
  73. noReserveLabel = label;
  74. //200 的尺寸 需要 选择时间 是否优惠 预约按钮 20+30 + 20+60+20 + 50
  75. NSString *labelString = @" 选择时段:";
  76. w = [labelString sizeForFont:Font17].width;
  77. y += h + 2*bd;
  78. h = 30;
  79. label = [[UILabel alloc] setxywh];
  80. [label setText:labelString Font:Font17 TextColor:kTitleColor];
  81. [self.view addSubview:label];
  82. x += w + bd;
  83. w = (kSize.width - x - bd - 30)/2.0;
  84. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  85. btn.frame = setDIYFrame;
  86. [btn setTitle:@"开始时间" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
  87. [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
  88. [btn target:self tag:1];
  89. [self.view addSubview:btn];
  90. beginBtn = btn;
  91. x += w + 30;
  92. btn = [UIButton buttonWithType:UIButtonTypeSystem];
  93. btn.frame = setDIYFrame;
  94. [btn setTitle:@"结束时间" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
  95. [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
  96. [btn target:self tag:2];
  97. [self.view addSubview:btn];
  98. endBtn = btn;
  99. x -= 25;
  100. w = 2 * bd;
  101. label = [[UILabel alloc] setxywh];
  102. [label setText:@"--" Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  103. [self.view addSubview:label];
  104. //优惠
  105. x = bd;
  106. y += h + 2*bd;
  107. w = kSize.width - 2*x;
  108. h = 40;
  109. btn = [[UIButton alloc] setxywh];
  110. btn.titleLabel.numberOfLines = 0;
  111. [btn setTitle:@"暂无可用优惠券" textColor:contentTextColor Font:Font17 fotState:UIControlStateNormal];
  112. [btn borderColor:contentTextColor width:1 cornorRadius:5];
  113. [btn target:self tag:3];
  114. [self.view addSubview:btn];
  115. btn.userInteractionEnabled = NO;
  116. discountBtn = btn;
  117. //预约按钮
  118. x = 0;
  119. w += 2*bd;
  120. y += 60 + 2*bd;
  121. h = 50;
  122. btn = [[UIButton alloc] setxywh];
  123. btn.backgroundColor = backGroundColor;
  124. [btn setTitle:@"我要预约" textColor:RQ_MAIN_COLOR Font:FontTitle fotState:UIControlStateNormal];
  125. [btn target:self tag:4];
  126. [self.view addSubview:btn];
  127. [self getReserveMnByDevId];
  128. }
  129. - (void)btnClick:(UIButton *)sender {
  130. if (sender.tag == 1) {
  131. DateView *dateV = [[DateView alloc] init];
  132. [dateV setStyle:3];
  133. [dateV showWithComplete:^(NSString * result) {
  134. beginTime = result;
  135. [beginBtn setTitle:beginTime forState:UIControlStateNormal];
  136. }];
  137. }
  138. if (sender.tag == 2) {
  139. DateView *dateV = [[DateView alloc] init];
  140. [dateV setStyle:3];
  141. [dateV showWithComplete:^(NSString * result) {
  142. endTime = result;
  143. [endBtn setTitle:endTime forState:UIControlStateNormal];
  144. }];
  145. }
  146. if (sender.tag == 3) {
  147. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否使用优惠券?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  148. UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"不使用" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  149. isUseDisCount = NO;
  150. [discountBtn setTitle:@"您有免费半小时优惠券,点击使用" forState:UIControlStateNormal];
  151. }];
  152. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"使用" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  153. isUseDisCount = YES;
  154. [discountBtn setTitle:@"已选择使用免费半小时优惠券,请选择时长为半小时的时间段" forState:UIControlStateNormal];
  155. }];
  156. [alert addAction:noAction];
  157. [alert addAction:yesAction];
  158. [self presentViewController:alert animated:NO completion:nil];
  159. }
  160. if (sender.tag == 4) {
  161. if (![self isValueTime]) {
  162. return;
  163. }
  164. if (isUseDisCount) {
  165. if (![self isHalfOfHour]) {
  166. return;
  167. }
  168. }
  169. [self uploadReserveMn];
  170. }
  171. }
  172. - (BOOL)isValueTime {
  173. if (beginTime.length < 1) {
  174. ShowMsg(@"请选择开始时间");
  175. return NO;
  176. }
  177. if (endTime.length < 1) {
  178. ShowMsg(@"请选择结束时间");
  179. return NO;
  180. }
  181. if ([beginTime isEqualToString:endTime]) {
  182. ShowMsg(@"开始时间不能等于结束时间");
  183. return NO;
  184. }
  185. NSString *beginHou = [[beginTime componentsSeparatedByString:@":"] firstObject];
  186. NSString *beginMin = [[beginTime componentsSeparatedByString:@":"] lastObject];
  187. NSString *endHou = [[endTime componentsSeparatedByString:@":"] firstObject];
  188. NSString *endMin = [[endTime componentsSeparatedByString:@":"] lastObject];
  189. if (beginHou.integerValue > endHou.integerValue) {
  190. ShowMsg(@"开始时间不能大于结束时间");
  191. return NO;
  192. }
  193. if (beginHou.integerValue == endHou.integerValue) {
  194. if (beginMin.integerValue > endMin.integerValue) {
  195. ShowMsg(@"开始时间不能大于结束时间");
  196. return NO;
  197. }
  198. }
  199. return YES;
  200. }
  201. - (BOOL)isHalfOfHour {
  202. NSString *beginHou = [[beginTime componentsSeparatedByString:@":"] firstObject];
  203. NSString *beginMin = [[beginTime componentsSeparatedByString:@":"] lastObject];
  204. NSString *endHou = [[endTime componentsSeparatedByString:@":"] firstObject];
  205. NSString *endMin = [[endTime componentsSeparatedByString:@":"] lastObject];
  206. if (endHou.integerValue - beginHou.integerValue > 1) {
  207. return NO;
  208. }
  209. if (![beginHou isEqualToString:endHou] && [beginMin isEqualToString:endMin]) {
  210. return NO;
  211. }
  212. return YES;
  213. }
  214. #pragma mark tableView
  215. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  216. return dataArray.count;
  217. }
  218. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  219. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  220. if (cell == nil) {
  221. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  222. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  223. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  224. }
  225. NSDictionary *dic = dataArray[indexPath.row];
  226. cell.textLabel.text = [NSString stringWithFormat:@"%@--%@ %@",dic[@"startTime"],dic[@"endTime"],dic[@"userName"]];
  227. return cell;
  228. }
  229. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  230. return [UIView new];
  231. }
  232. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  233. return .1;
  234. }
  235. #pragma mark 数据请求
  236. - (void)getReserveMnByDevId {
  237. [LoadingView showHUD];
  238. if (![Util connectedToNetWork]) {
  239. showMsgUnconnect();
  240. return;
  241. }
  242. NSMutableArray *arr=[NSMutableArray array];
  243. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  244. [arr addPro:@"devId" Value:_devDic[@"ID"]];
  245. [arr addPro:@"quotaId" Value:_quotaId];
  246. NSString* method = @"getReserveMnByDevId";
  247. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  248. RemoveHUD();
  249. // NSLog(@"getReserveMnByDevId--><>%@",root);
  250. if (!root) {
  251. return;
  252. }
  253. if ([root[@"code"] intValue] == 1) {
  254. ShowMsg(root[@"body"]);
  255. return;
  256. }
  257. price = [[root[@"body"] objectForKey:@"price"] floatValue];
  258. if ([[root[@"body"] objectForKey:@"price"] floatValue] > 0.0) {
  259. priceLabel.text = [NSString stringWithFormat:@" 培训日期:%@\n 开放时间:%@-%@\n 培训价格:%@元",[root[@"body"] objectForKey:@"PXRQ"],[root[@"body"] objectForKey:@"STARTTIME"],[root[@"body"] objectForKey:@"ENDTIME"],[root[@"body"] objectForKey:@"price"]];
  260. [self getDiscountHalfHour];
  261. }else {
  262. priceLabel.text = [NSString stringWithFormat:@" 培训日期:%@\n\n 开放时间:%@-%@",[root[@"body"] objectForKey:@"PXRQ"],[root[@"body"] objectForKey:@"STARTTIME"],[root[@"body"] objectForKey:@"ENDTIME"]];
  263. }
  264. dataArray = [root[@"body"] objectForKey:@"rmlist"];
  265. if (dataArray.count > 0) {
  266. noReserveLabel.hidden = YES;
  267. }else {
  268. noReserveLabel.hidden = NO;
  269. }
  270. [mainTableView reloadData];
  271. }];
  272. }
  273. - (void)getDiscountHalfHour {
  274. if (![Util connectedToNetWork]) {
  275. showMsgUnconnect();
  276. return;
  277. }
  278. NSMutableArray *arr=[NSMutableArray array];
  279. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  280. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  281. NSString* method = @"getDiscountHalfHour";
  282. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  283. if (!root) {
  284. return;
  285. }
  286. if ([root[@"code"] intValue] == 1) {
  287. ShowMsg(root[@"body"]);
  288. return;
  289. }
  290. if ([root[@"body"] integerValue] == 1) {
  291. discountBtn.userInteractionEnabled = YES;
  292. discountBtn.height = 50;
  293. [discountBtn setTitle:@"您有免费半小时优惠券,点击使用" textColor:[UIColor orangeColor] Font:Font17 fotState:UIControlStateNormal];
  294. discountBtn.layer.borderColor = [UIColor orangeColor].CGColor;
  295. }
  296. }];
  297. }
  298. - (void)uploadReserveMn {
  299. [LoadingView showHUD];
  300. if (![Util connectedToNetWork]) {
  301. showMsgUnconnect();
  302. return;
  303. }
  304. NSString *isPay = @"2";
  305. if (price > 0.00) {
  306. if (isUseDisCount) {
  307. isPay = @"1";
  308. }else{
  309. isPay = @"0";
  310. }
  311. }
  312. NSMutableArray *arr=[NSMutableArray array];
  313. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  314. [arr addPro:@"deviceId" Value:_devDic[@"ID"]];
  315. [arr addPro:@"quotaId" Value:_quotaId];
  316. [arr addPro:@"isPay" Value:isPay];
  317. [arr addPro:@"startTime" Value:beginTime];
  318. [arr addPro:@"endTime" Value:endTime];
  319. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  320. NSString* method = @"uploadReserveMn";
  321. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  322. RemoveHUD();
  323. if (!root) {
  324. return;
  325. }
  326. if ([root[@"code"] intValue] == 1) {
  327. ShowMsg(root[@"body"]);
  328. return;
  329. }
  330. [self getReserveMnByDevId];
  331. }];
  332. }
  333. - (void)didReceiveMemoryWarning {
  334. [super didReceiveMemoryWarning];
  335. // Dispose of any resources that can be recreated.
  336. }
  337. @end