| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // ModelModeViewController.m
- // RA Image
- //
- // Created by Jack on 2017/5/2.
- // Copyright © 2017年 USAI. All rights reserved.
- //
- #import "ModelModeViewController.h"
- #import "JLKeyboardListener.h"
- #import <AVFoundation/AVFoundation.h>
- #import <AssetsLibrary/AssetsLibrary.h>
- #import "ManufacturerListController.h"
- #import "UploadViewController.h"
- @interface ModelModeViewController ()<UITextViewDelegate>
- @property (strong, nonatomic) IBOutlet UITextView *noteTextView;
- @property (strong, nonatomic) IBOutlet UILabel *barcodeLabel;
- @property (strong, nonatomic) IBOutlet UIButton *imgBtn;
- @property (strong, nonatomic) IBOutlet UIButton *manufactureBtn;
- @property (strong, nonatomic) IBOutlet UIButton *scanBtn;
- @property (strong, nonatomic) IBOutlet UIButton *cameraBtn;
- @property (strong, nonatomic) IBOutlet UIButton *uploadBtn;
- @property (strong, nonatomic) IBOutlet UIButton *typeBtn;
- @property (strong, nonatomic) IBOutlet UILabel *photoCountLabel;
- @property (nonatomic,copy) NSString *manufacturer;
- @end
- @implementation ModelModeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.noteTextView.layer.borderColor = [UIColor blackColor].CGColor;
- self.noteTextView.layer.borderWidth = 1.0f;
- [self registListenKeyboard];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)clear {
- self.barcode = nil;
- self.manufacturer = nil;
- self.noteTextView.text = @"Note:";
- [self.imgBtn setBackgroundImage:nil forState:UIControlStateNormal];
- [self clearPhotos];
- }
- #pragma mark - Button Action
- - (IBAction)imgBtnClick:(UIButton *)sender {
- [self showPhotoList];
- }
- - (IBAction)manufactureBtnClick:(UIButton *)sender {
- ManufacturerListController *manuVC = (ManufacturerListController *)[self viewControllerInStoryboard:@"Mode" withId:@"ManufacturerListController"];
- __weak typeof(self) weakself = self;
- manuVC.returnValue = ^(NSString *value) {
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- strongself.manufacturer = value;
- }
- };
- manuVC.manufacturerList = self.manufacturerList;
- [self.navigationController pushViewController:manuVC animated:YES];
- }
- - (IBAction)scanBtnClick:(UIButton *)sender {
- [self showScanner];
- }
- - (IBAction)cameraBtnClick:(id)sender {
- [self clickCameraButton];
- }
- - (IBAction)uploadBtnClick:(id)sender {
- if(self.barcode.length ==0)
- {
- [RAUtils message_alert:@"Barcode cann't be blank" title:@"Warning" controller:self];
- return;
- }
- if(self.photos.count ==0)
- {
- [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
- return;
- }
- AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
-
-
-
- //prepare upload
- NSMutableArray* tasks = [NSMutableArray new];
-
- for(NSMutableDictionary* photo in self.photos)
- {
-
- NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
-
-
- task[@"path"]=self.name;
- task[@"file"]=photo[@"file"];
-
- task[@"url"]=Appdelegate.address;
- NSString *md5 = [photo objectForKey:@"md5"];
- NSString *manufacturer = self.manufacturer;
- NSString *note = self.noteTextView.text;
- if (!manufacturer.length) {
- manufacturer = @"";
- }
- if (!note.length) {
- note = @"";
- }
-
- NSDictionary* params = @{
- @"user" : Appdelegate.user,
- @"password" : Appdelegate.password,
- @"mode":self.name,
- @"barcode":self.barcode,
- @"manufacturer":manufacturer,
- @"note":note,
- @"_operate":@"upload",
- @"platform":@"ios",
- @"md5":md5
- };
- task[@"params"]=params;
- [tasks addObject:task];
-
- }
-
-
- // // add upload tasks;
- [Appdelegate.uploadManager addTasks:tasks];
-
- [self clear];
-
- // UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
- // [self.navigationController pushViewController:upVC animated:YES];
- }
- - (IBAction)typeBtnClick:(UIButton *)sender {
- [self showBarcodeInput];
- }
- #pragma mark - Setter
- - (void)setManufacturer:(NSString *)manufacturer {
- _manufacturer = manufacturer;
- NSString *title = @"Manufacturer";
- if (manufacturer.length) {
- title = manufacturer;
- }
- [self.manufactureBtn setTitle:title forState:UIControlStateNormal];
- }
- #pragma mark - Super Method
- - (void)receiveImage:(UIImage *)img {
- if (img) {
- [self.imgBtn setBackgroundImage:img forState:UIControlStateNormal];
- }
- }
- - (void)setBarcode:(NSString *)barcode {
- [super setBarcode:barcode];
- if (!barcode) {
- barcode = @"";
- }
- self.barcodeLabel.text = [NSString stringWithFormat:@"%@:%@",self.barcodeTitle,barcode];
- }
- - (void)setPhotoCount:(NSUInteger)photoCount {
- [super setPhotoCount:photoCount];
- NSString *str = nil;
- if (photoCount > 0) {
- str = [NSString stringWithFormat:@"%lu Photos",photoCount];
- } else {
- str = @"No Photos";
- }
- self.photoCountLabel.text = str;
- }
- #pragma mark - TextView Delegate
- - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
- self.currentFirstResponder = textView;
- return YES;
- }
- - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
- self.currentFirstResponder = nil;
- return YES;
- }
- @end
|