RAOrderEditViewController+TableDataSource.m 8.7 KB

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