ModelModeViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // ModelModeViewController.m
  3. // RA Image
  4. //
  5. // Created by Jack on 2017/5/2.
  6. // Copyright © 2017年 USAI. All rights reserved.
  7. //
  8. #import "ModelModeViewController.h"
  9. #import "JLKeyboardListener.h"
  10. #import <AVFoundation/AVFoundation.h>
  11. #import <AssetsLibrary/AssetsLibrary.h>
  12. #import "ManufacturerListController.h"
  13. #import "UploadViewController.h"
  14. @interface ModelModeViewController ()<UITextViewDelegate>
  15. @property (strong, nonatomic) IBOutlet UITextView *noteTextView;
  16. @property (strong, nonatomic) IBOutlet UILabel *barcodeLabel;
  17. @property (strong, nonatomic) IBOutlet UIButton *imgBtn;
  18. @property (strong, nonatomic) IBOutlet UIButton *manufactureBtn;
  19. @property (strong, nonatomic) IBOutlet UIButton *scanBtn;
  20. @property (strong, nonatomic) IBOutlet UIButton *cameraBtn;
  21. @property (strong, nonatomic) IBOutlet UIButton *uploadBtn;
  22. @property (strong, nonatomic) IBOutlet UIButton *typeBtn;
  23. @property (strong, nonatomic) IBOutlet UILabel *photoCountLabel;
  24. @property (nonatomic,copy) NSString *manufacturer;
  25. @end
  26. @implementation ModelModeViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. self.noteTextView.layer.borderColor = [UIColor blackColor].CGColor;
  31. self.noteTextView.layer.borderWidth = 1.0f;
  32. [self registListenKeyboard];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. - (void)clear {
  39. self.barcode = nil;
  40. self.manufacturer = nil;
  41. self.noteTextView.text = @"Note:";
  42. [self.imgBtn setBackgroundImage:nil forState:UIControlStateNormal];
  43. [self clearPhotos];
  44. }
  45. #pragma mark - Button Action
  46. - (IBAction)imgBtnClick:(UIButton *)sender {
  47. [self showPhotoList];
  48. }
  49. - (IBAction)manufactureBtnClick:(UIButton *)sender {
  50. ManufacturerListController *manuVC = (ManufacturerListController *)[self viewControllerInStoryboard:@"Mode" withId:@"ManufacturerListController"];
  51. __weak typeof(self) weakself = self;
  52. manuVC.returnValue = ^(NSString *value) {
  53. if (weakself) {
  54. __strong typeof(weakself) strongself = weakself;
  55. strongself.manufacturer = value;
  56. }
  57. };
  58. manuVC.manufacturerList = self.manufacturerList;
  59. [self.navigationController pushViewController:manuVC animated:YES];
  60. }
  61. - (IBAction)scanBtnClick:(UIButton *)sender {
  62. [self showScanner];
  63. }
  64. - (IBAction)cameraBtnClick:(id)sender {
  65. [self clickCameraButton];
  66. }
  67. - (IBAction)uploadBtnClick:(id)sender {
  68. if(self.barcode.length ==0)
  69. {
  70. [RAUtils message_alert:@"Barcode cann't be blank" title:@"Warning" controller:self];
  71. return;
  72. }
  73. if(self.photos.count ==0)
  74. {
  75. [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
  76. return;
  77. }
  78. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  79. //prepare upload
  80. NSMutableArray* tasks = [NSMutableArray new];
  81. for(NSMutableDictionary* photo in self.photos)
  82. {
  83. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  84. task[@"path"]=self.name;
  85. task[@"file"]=photo[@"file"];
  86. task[@"url"]=Appdelegate.address;
  87. NSString *md5 = [photo objectForKey:@"md5"];
  88. NSString *manufacturer = self.manufacturer;
  89. NSString *note = self.noteTextView.text;
  90. if (!manufacturer.length) {
  91. manufacturer = @"";
  92. }
  93. if (!note.length) {
  94. note = @"";
  95. }
  96. NSDictionary* params = @{
  97. @"user" : Appdelegate.user,
  98. @"password" : Appdelegate.password,
  99. @"mode":self.name,
  100. @"barcode":self.barcode,
  101. @"manufacturer":manufacturer,
  102. @"note":note,
  103. @"_operate":@"upload",
  104. @"platform":@"ios",
  105. @"md5":md5
  106. };
  107. task[@"params"]=params;
  108. [tasks addObject:task];
  109. }
  110. // // add upload tasks;
  111. [Appdelegate.uploadManager addTasks:tasks];
  112. [self clear];
  113. // UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
  114. // [self.navigationController pushViewController:upVC animated:YES];
  115. }
  116. - (IBAction)typeBtnClick:(UIButton *)sender {
  117. [self showBarcodeInput];
  118. }
  119. #pragma mark - Setter
  120. - (void)setManufacturer:(NSString *)manufacturer {
  121. _manufacturer = manufacturer;
  122. NSString *title = @"Manufacturer";
  123. if (manufacturer.length) {
  124. title = manufacturer;
  125. }
  126. [self.manufactureBtn setTitle:title forState:UIControlStateNormal];
  127. }
  128. #pragma mark - Super Method
  129. - (void)receiveImage:(UIImage *)img {
  130. if (img) {
  131. [self.imgBtn setBackgroundImage:img forState:UIControlStateNormal];
  132. }
  133. }
  134. - (void)setBarcode:(NSString *)barcode {
  135. [super setBarcode:barcode];
  136. if (!barcode) {
  137. barcode = @"";
  138. }
  139. self.barcodeLabel.text = [NSString stringWithFormat:@"%@:%@",self.barcodeTitle,barcode];
  140. }
  141. - (void)setPhotoCount:(NSUInteger)photoCount {
  142. [super setPhotoCount:photoCount];
  143. NSString *str = nil;
  144. if (photoCount > 0) {
  145. str = [NSString stringWithFormat:@"%lu Photos",photoCount];
  146. } else {
  147. str = @"No Photos";
  148. }
  149. self.photoCountLabel.text = str;
  150. }
  151. #pragma mark - TextView Delegate
  152. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  153. self.currentFirstResponder = textView;
  154. return YES;
  155. }
  156. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  157. self.currentFirstResponder = nil;
  158. return YES;
  159. }
  160. @end