RAOrderEditViewController+TableDataSource.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // RAOrderEditViewController+TableDataSource.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/4.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAOrderEditViewController+TableDataSource.h"
  9. #import "RAEditLabelCell.h"
  10. #import "RAEditInputModel.h"
  11. #import "RAEditMultInputModel.h"
  12. #import "RAEditLabelModel.h"
  13. #import "RAEditPhotoModel.h"
  14. #import "RAEditSignatureModel.h"
  15. #import "RAEditDateModel.h"
  16. #import "RAEditMultPhotoModel.h"
  17. #import "RAPhotoCell.h"
  18. #import "RAQRCodeScannerViewController.h"
  19. #import "RACameraViewController.h"
  20. #import "RAPhotoPreviewController.h"
  21. #import "SignatureViewController.h"
  22. #import "UIImage+RedAnt.h"
  23. #import "RADatePickerViewController.h"
  24. @implementation RAOrderEditViewController (TableDataSource)
  25. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  26. RAEditBaseModel *model = [self modelForIndexPath:indexPath];
  27. switch (model.type) {
  28. case RAEditTypeLabel: {
  29. RAEditLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditLabelCell" forIndexPath:indexPath];
  30. RAEditLabelModel *labelModel = (RAEditLabelModel *)model;
  31. cell.model = labelModel;
  32. return cell;
  33. }
  34. break;
  35. case RAEditTypeInput: {
  36. RAEditScanInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditScanInputCell" forIndexPath:indexPath];
  37. RAEditInputModel *inputModel = (RAEditInputModel *)model;
  38. cell.model = inputModel;
  39. cell.delegate = self;
  40. return cell;
  41. }
  42. break;
  43. case RAEditTypeMultInput: {
  44. RAEditMultInputCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditMultInputCell" forIndexPath:indexPath];
  45. RAEditMultInputModel *multInputModel = (RAEditMultInputModel *)model;
  46. cell.model = multInputModel;
  47. cell.delegate = self;
  48. return cell;
  49. }
  50. break;
  51. case RAEditTypePhoto: {
  52. RAEditPhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditPhotoCell" forIndexPath:indexPath];
  53. RAEditPhotoModel *photoModel = (RAEditPhotoModel *)model;
  54. cell.model = photoModel;
  55. cell.delegate = self;
  56. return cell;
  57. }
  58. break;
  59. case RAEditTypeSignature: {
  60. RAEditSignatureModel *signatureModel = (RAEditSignatureModel *)model;
  61. RAEditSignatureCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditSignatureCell" forIndexPath:indexPath];
  62. cell.model = signatureModel;
  63. cell.delegate = self;
  64. return cell;
  65. }
  66. break;
  67. case RAEditTypeDate: {
  68. RAEditDateModel *dateModel = (RAEditDateModel *)model;
  69. RAEditDateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RAEditDateCell" forIndexPath:indexPath];
  70. cell.model = dateModel;
  71. cell.delegate = self;
  72. return cell;
  73. }
  74. break;
  75. case RAEditTypeMultPhoto: {
  76. RAEditMultPhotoModel *multPhotoModel = (RAEditMultPhotoModel *)model;
  77. RAPhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:RAPhotoCell.reuseId forIndexPath:indexPath];
  78. cell.model = multPhotoModel.model;
  79. return cell;
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detaulCell"];
  86. return cell;
  87. }
  88. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  89. return [self itemCountForSection:section];
  90. }
  91. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  92. return [self editSectionCount];
  93. }
  94. #pragma mark - PhotoCell Delegate
  95. - (void)photoCellWillOpenCameraOrShowPhoto:(RAEditPhotoCell *)cell {
  96. if (cell.model.photo) {
  97. RAPhotoPreviewController *previewVC = [RAPhotoPreviewController viewControllerFromStoryboard];
  98. previewVC.image = cell.model.photo;
  99. previewVC.completion = ^{
  100. cell.model.photo = nil;
  101. };
  102. [self.navigationController pushViewController:previewVC animated:YES];
  103. } else {
  104. RACameraViewController *cameraVC = [RACameraViewController viewControllerFromStoryboard];
  105. cameraVC.completion = ^(UIImage *image) {
  106. cell.model.photo = [UIImage img_compress:image kbsize:1024];
  107. };
  108. cameraVC.fromVC = self;
  109. [self.navigationController pushViewController:cameraVC animated:YES];
  110. }
  111. }
  112. #pragma mark - Input Delegate
  113. - (void)scanInputCell:(RAEditScanInputCell *)cell clickScanButton:(UIButton *)sender {
  114. RAQRCodeScannerViewController *scanVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
  115. scanVC.completion = ^(NSString *value) {
  116. cell.model.value = value;
  117. };
  118. [self.navigationController pushViewController:scanVC animated:YES];
  119. }
  120. - (void)beginEditInputCell:(RAEditScanInputCell *)cell {
  121. self.editingIndexPath = [self indexPathForCell:cell];
  122. }
  123. - (void)endEditInputCell:(RAEditScanInputCell *)cell {
  124. self.editingIndexPath = nil;
  125. }
  126. #pragma mark - MultInput Delegate
  127. - (void)beginEditMultInputCell:(RAEditMultInputCell *)cell {
  128. self.editingIndexPath = [self indexPathForCell:cell];
  129. }
  130. - (void)endEditMultInputCell:(RAEditMultInputCell *)cell {
  131. self.editingIndexPath = nil;
  132. }
  133. #pragma mark - Signature Delegate
  134. - (void)signatureCell:(RAEditSignatureCell *)cell tapSignature:(RAEditSignatureModel *)model {
  135. if (model) {
  136. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature"
  137. bundle:[NSBundle mainBundle]]
  138. instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  139. vc.onReturnImg = ^(UIImage* img)
  140. {
  141. if(img!=nil) {
  142. model.signature = img;
  143. if (model.expand) {
  144. if ([model.expand isKindOfClass:[NSDictionary class]]) {
  145. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  146. [self expandIndexPath:indexPath withJsonItem:model.expand];
  147. } else if ([model.expand isKindOfClass:[RAEditBaseModel class]]) {
  148. if (((RAEditBaseModel *)model.expand).autofill) {
  149. [((RAEditBaseModel *)model.expand) updateDefaultValue];
  150. }
  151. }
  152. }
  153. }
  154. };
  155. [self.navigationController pushViewController:vc animated:NO];
  156. }
  157. }
  158. #pragma mark - DateCellDelegate
  159. - (void)dateCell:(RAEditDateCell *)cell didClickForModel:(RAEditDateModel *)model {
  160. if (model) {
  161. UIDatePickerMode mode = UIDatePickerModeDate;
  162. switch (model.mode) {
  163. case RAEditTypeModeTime: {
  164. mode = UIDatePickerModeTime;
  165. }
  166. break;
  167. case RAEditTypeModeDate: {
  168. mode = UIDatePickerModeDate;
  169. }
  170. break;
  171. case RAEditTypeModeDateAndTime: {
  172. mode = UIDatePickerModeDateAndTime;
  173. }
  174. break;
  175. default:
  176. break;
  177. }
  178. [RADatePickerViewController presentDatePicker:self title:model.title dateMode:mode withSetBlk:^(NSDate *date) {
  179. model.date = date;
  180. }];
  181. }
  182. }
  183. @end