ImitateOrderCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. //
  2. // ImitateOrderCell.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2017/5/15.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "ImitateOrderCell.h"
  9. @implementation ImitateOrderCell
  10. {
  11. UIView *backView;
  12. UITextView *reasonTV;
  13. }
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. // Initialization code
  17. }
  18. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  19. [super setSelected:selected animated:animated];
  20. // Configure the view for the selected state
  21. }
  22. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  23. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  24. if (self) {
  25. self.backgroundColor = backGroundColor;
  26. NSMutableArray *labelArray = [NSMutableArray arrayWithCapacity:7];
  27. for (int i = 0; i < 8; i ++) {
  28. UILabel *label = [UILabel new];
  29. [label setTextAlignment:NSTextAlignmentLeft];
  30. label.font = [UIFont scaleSize:NormalFont];
  31. label.textColor = contentTextColor;
  32. [self.contentView addSubview:label];
  33. [labelArray addObject:label];
  34. }
  35. orderNumLab = labelArray[0];
  36. lineLab = labelArray[1];
  37. yuyueDateLab = labelArray[2];
  38. moniTimeLab = labelArray[3];
  39. trainLineLab = labelArray[4];
  40. deviceLableLab = labelArray[5];
  41. allPriceLab = labelArray[6];
  42. lineLab.backgroundColor = RQlineColor;
  43. orderNumLab.textAlignment = NSTextAlignmentRight;
  44. allPriceLab.textAlignment = NSTextAlignmentRight;
  45. moniTimeLab.textAlignment = NSTextAlignmentRight;
  46. NSArray *titleName = @[@"支付",@"取消订单"];
  47. NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3];
  48. for (int i = 0; i < titleName.count; i++) {
  49. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  50. [btn setTitle:titleName[i] forState:UIControlStateNormal];
  51. [btn.titleLabel setFont:[UIFont systemFontOfSize:13]];
  52. [btn setTitleColor:RQ_MAIN_COLOR forState:UIControlStateNormal];
  53. [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
  54. [btn target:self tag:i + 1];
  55. [self.contentView addSubview:btn];
  56. [btns addObject:btn];
  57. }
  58. payBtn = btns[0];
  59. cancleOrderBtn = btns[1];
  60. }
  61. return self;
  62. }
  63. +(ImitateOrderCell *)cellForTabelView:(UITableView*)tableView block:(MyBlockType)block
  64. {
  65. ImitateOrderCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ImitateOrderCell"];
  66. if (!cell) {
  67. cell = [[ImitateOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImitateOrderCell"];
  68. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  69. cell.backgroundColor = backGroundColor;
  70. }
  71. cell.block = block;
  72. return cell;
  73. }
  74. -(void)layoutSubviews
  75. {
  76. [super layoutSubviews];
  77. CGFloat wid = self.width;
  78. CGFloat x,y,w,h,bd;
  79. x = y = 0;
  80. bd = 5;
  81. w = wid - 20;
  82. h = 29;
  83. orderNumLab.frame = setDIYFrame;
  84. x = 0;
  85. y += h;
  86. w = wid;
  87. h = 1.0;
  88. lineLab.frame = setDIYFrame;
  89. x = 20;
  90. y += h + bd;
  91. w = wid - 40;
  92. h = 20;
  93. yuyueDateLab.frame = setDIYFrame;
  94. moniTimeLab.frame = setDIYFrame;
  95. y += h + bd;
  96. trainLineLab.frame = setDIYFrame;//训练点
  97. allPriceLab.frame = setDIYFrame;//价格
  98. y += h + bd;
  99. deviceLableLab.frame = setDIYFrame;//设备号
  100. y += 5;
  101. h = 25;
  102. w = 60;
  103. x = wid - 190 - 20;
  104. //订单状态 1 待支付 2 有效单 3 已完成 4 已取消 5 退款单
  105. switch (self.type) {
  106. case 1:
  107. {
  108. payBtn.hidden = NO;
  109. cancleOrderBtn.hidden = NO;
  110. //刷新
  111. x += 65;
  112. payBtn.frame = setDIYFrame;
  113. x += 65;
  114. cancleOrderBtn.frame = setDIYFrame;
  115. }
  116. break;
  117. case 2:
  118. {
  119. payBtn.hidden = YES;
  120. cancleOrderBtn.hidden = NO;
  121. //刷新
  122. x += 65;
  123. payBtn.frame = setDIYFrame;
  124. x += 65;
  125. cancleOrderBtn.frame = setDIYFrame;
  126. }
  127. break;
  128. case 3:
  129. {
  130. payBtn.hidden = YES;
  131. cancleOrderBtn.hidden = YES;
  132. //刷新
  133. x += 65;
  134. payBtn.frame = setDIYFrame;
  135. x += 65;
  136. cancleOrderBtn.frame = setDIYFrame;
  137. }
  138. break;
  139. case 4:
  140. {
  141. payBtn.hidden = YES;
  142. cancleOrderBtn.hidden = YES;
  143. //刷新
  144. x += 65;
  145. payBtn.frame = setDIYFrame;
  146. x += 65;
  147. cancleOrderBtn.frame = setDIYFrame;
  148. }
  149. break;
  150. case 5:
  151. {
  152. payBtn.hidden = YES;
  153. cancleOrderBtn.hidden = YES;
  154. //刷新
  155. x += 65;
  156. payBtn.frame = setDIYFrame;
  157. x += 65;
  158. cancleOrderBtn.frame = setDIYFrame;
  159. }
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. -(void)setDataDic:(NSDictionary *)dataDic
  166. {
  167. _dataDic = dataDic;
  168. /*
  169. UILabel * orderNumLab;
  170. UILabel * yuyueDateLab;
  171. UILabel * moniTimeLab;
  172. UILabel * trainLineLab;
  173. UILabel * deviceLableLab;
  174. UILabel * allPriceLab;
  175. UILabel * lineLab;
  176. */
  177. orderNumLab.text = [NSString stringWithFormat:@"订单号:%@",dataDic[@"ORDERNO"]];
  178. yuyueDateLab.text = [NSString stringWithFormat:@"预约日期:%@",dataDic[@"PXRQ"]];
  179. moniTimeLab.text = [NSString stringWithFormat:@"培训时间:%@",dataDic[@"PXTIME"]];
  180. trainLineLab.text = [NSString stringWithFormat:@"训练点: %@",dataDic[@"XLDMC"]];
  181. deviceLableLab.text = [NSString stringWithFormat:@"设备号: %@",dataDic[@"CODE"]];
  182. NSString * price = dataDic[@"MONEY"];
  183. if ([price length] < 1) {
  184. price = @"0";
  185. }
  186. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:@"价格:免费"];
  187. if (price.floatValue > 0.0) {
  188. abs = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"价格:%@元",price]];
  189. }
  190. [abs beginEditing];
  191. //字体大小
  192. [abs addAttribute:NSFontAttributeName
  193. value:[UIFont scaleSize:17]
  194. range:NSMakeRange(3, abs.length-3)];
  195. [abs addAttribute:NSFontAttributeName
  196. value:[UIFont scaleSize:15]
  197. range:NSMakeRange(0, 3)];
  198. //字体颜色
  199. [abs addAttribute:NSForegroundColorAttributeName
  200. value:[UIColor redColor]
  201. range:NSMakeRange(3, abs.length-3)];
  202. [abs addAttribute:NSForegroundColorAttributeName
  203. value:contentTextColor
  204. range:NSMakeRange(0,3)];
  205. allPriceLab.attributedText = abs;
  206. }
  207. -(void)btnClick:(UIButton *)btn{
  208. switch (btn.tag) {
  209. case 1:
  210. {
  211. //支付
  212. }
  213. break;
  214. case 2:
  215. {
  216. backView = [[UIView alloc] initWithFrame:kFrame];
  217. backView.backgroundColor = windowBlockColor;
  218. [myDelegate.window addSubview:backView];
  219. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeybored)];
  220. [backView addGestureRecognizer:tap];
  221. CGFloat w = kSize.width - 40;
  222. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, kSize.height/2.0 - 100, w, 160)];
  223. view.backgroundColor = backGroundColor;
  224. [view borderColor:RQlineColor width:1 cornorRadius:5];
  225. [backView addSubview:view];
  226. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w, 30)];
  227. [label setText:@"请输入取消原因" Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  228. [view addSubview:label];
  229. reasonTV = [[UITextView alloc] initWithFrame:CGRectMake(20, 30, w - 40, 80)];
  230. [reasonTV borderColor:RQlineColor width:1 cornorRadius:5];
  231. [view addSubview:reasonTV];
  232. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(30, 120, 80, 30)];
  233. [btn setTitle:@"取消" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
  234. [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
  235. [btn target:self tag:3];
  236. [view addSubview:btn];
  237. btn = [[UIButton alloc] initWithFrame:CGRectMake(w - 110, 120, 80, 30)];
  238. [btn setTitle:@"确认" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
  239. [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
  240. [btn target:self tag:4];
  241. [view addSubview:btn];
  242. }
  243. break;
  244. case 3:
  245. {
  246. [backView removeFromSuperview];
  247. }
  248. break;
  249. case 4:
  250. {
  251. if (reasonTV.text.length < 1) {
  252. ShowMsg(@"请输入取消订单原因");
  253. return;
  254. }
  255. [backView removeFromSuperview];
  256. //取消订单
  257. [self deteleReserveMn];
  258. }
  259. break;
  260. default:
  261. break;
  262. }
  263. }
  264. -(void)deteleReserveMn{
  265. [LoadingView showHUD];
  266. if (![Util connectedToNetWork]) {
  267. showMsgUnconnect();
  268. return;
  269. }
  270. NSMutableArray *arr=[NSMutableArray array];
  271. [arr addPro:@"reserveId" Value:_dataDic[@"ID"]];
  272. [arr addPro:@"reason" Value:reasonTV.text];
  273. NSString* method = @"deteleReserveMn";
  274. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  275. RemoveHUD();
  276. if (!root) {
  277. return;
  278. }
  279. if ([root[@"code"] intValue] == 1) {
  280. ShowMsg(root[@"body"]);
  281. return;
  282. }
  283. if (_block) {
  284. _block([NSString stringWithFormat:@"%@",_dataDic[@"ID"]]);
  285. }
  286. }];
  287. }
  288. - (void)closeKeybored {
  289. [reasonTV resignFirstResponder];
  290. }
  291. @end