WatchListViewController.m 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. //
  2. // WatchListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-8-1.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "WatchListViewController.h"
  9. #import "RANetwork.h"
  10. #import "ModelItemCell.h"
  11. #import "DetailViewController.h"
  12. #import "LoginViewController.h"
  13. #import "MainViewController.h"
  14. #import "TearSheetParamViewController.h"
  15. #import "EditModelPriceViewController.h"
  16. #import "ContactListViewController.h"
  17. #import "DefaultTableHeaderView.h"
  18. #import "DefaultAppearance.h"
  19. #import "SortItemViewController.h"
  20. #import "SortButton.h"
  21. #import "UIColor+JK_HEX.h"
  22. #import "CartUtils.h"
  23. #import "RAPDFViewController.h"
  24. #import "JKMessageBoxController.h"
  25. #define ALERT_DEL 1025
  26. //#import "PDFViewController.h"
  27. @interface WatchListViewController ()
  28. @property (strong, nonatomic) IBOutlet UIBarButtonItem *emailBtn;
  29. @property (strong, nonatomic) IBOutlet UIBarButtonItem *printBtn;
  30. @property (nonatomic,strong) SortItemViewController *sortItemController;
  31. @property (nonatomic,assign) int sortIndex;
  32. @property (nonatomic,strong) SortButton *sortButton;
  33. @property (nonatomic,strong) UILabel *qtyLabel;
  34. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  35. @property (nonatomic,copy) NSString *print_url;
  36. @end
  37. @implementation WatchListViewController
  38. - (NSOperationQueue *)dataOperationQueue {
  39. if (!_dataOperationQueue) {
  40. _dataOperationQueue = [[NSOperationQueue alloc] init];
  41. _dataOperationQueue.maxConcurrentOperationCount = 1;
  42. }
  43. return _dataOperationQueue;
  44. }
  45. -(void) logout
  46. {
  47. self.content_data = nil;
  48. [self refresh_ui];
  49. }
  50. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  51. {
  52. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  53. if (self) {
  54. // Custom initialization
  55. }
  56. return self;
  57. }
  58. #ifndef RA_NOTIFICATION
  59. -(void) reload_container_getdata:(bool) update_data
  60. {
  61. [super reload_container_getdata:update_data];
  62. if(update_data)
  63. [self reload_data];
  64. else
  65. [self.itemListTable reloadData];
  66. }
  67. #endif
  68. - (IBAction)onAddtoCart:(id)sender {
  69. [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
  70. return;
  71. //
  72. // UIApplication * app = [UIApplication sharedApplication];
  73. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  74. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  75. // if(appDelegate.bLogin==false)
  76. // {
  77. //
  78. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  79. // // loginvc.delegate = self;
  80. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  81. //
  82. // loginvc.returnValue = ^(bool blogin){
  83. //
  84. //
  85. // // UIApplication * app = [UIApplication sharedApplication];
  86. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  87. //
  88. //
  89. //
  90. //
  91. // if(blogin)
  92. // {
  93. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
  94. // {
  95. //
  96. // [main_vc checklogin:false];
  97. // if(appDelegate.can_create_order)
  98. // { NSString* msg =@"";
  99. // if(appDelegate.contact_id.length>0)
  100. // {
  101. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  102. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  103. //
  104. // }
  105. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  106. //
  107. //
  108. //
  109. // // alert.
  110. // [alert show];
  111. // }
  112. // else
  113. // {
  114. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  115. //
  116. // // alert.
  117. // [alert show];
  118. // }
  119. // }
  120. //// else
  121. //// {
  122. //// [main_vc checklogin:true];
  123. //// }
  124. // }
  125. //
  126. // // self.offset = 0;
  127. // // [self.content_data removeAllObjects];
  128. // // [self loadpage];
  129. // //
  130. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  131. //
  132. // };
  133. //
  134. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  135. //
  136. //
  137. //
  138. //
  139. //
  140. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  141. //
  142. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  143. // [self presentViewController:navi animated:YES completion:^{
  144. //
  145. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  146. //
  147. // DebugLog(@"LoginViewController present.........");
  148. //
  149. // // self.btop = false;
  150. // // <#code#>
  151. // }];
  152. // }
  153. // else
  154. // {
  155. // //if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  156. // if(appDelegate.order_code==nil)
  157. // {
  158. // [main_vc checklogin:false];
  159. // if(appDelegate.can_create_order)
  160. // {
  161. // NSString* msg =@"";
  162. // if(appDelegate.contact_id.length>0)
  163. // {
  164. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  165. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  166. //
  167. // }
  168. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  169. //
  170. // // alert.
  171. // [alert show];
  172. // }
  173. // else
  174. // {
  175. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  176. //
  177. // // alert.
  178. // [alert show];
  179. // }
  180. // }
  181. // else
  182. // {
  183. //
  184. // if(appDelegate.order_code==nil)
  185. // [ self neworder];
  186. // else
  187. // [self addtocart];
  188. //
  189. //
  190. //
  191. // }
  192. // }
  193. //
  194. }
  195. -(void) addtocart
  196. {
  197. NSMutableArray* checked = [[NSMutableArray alloc] init];
  198. NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
  199. int count = [[self.content_data valueForKey:@"count"] intValue];
  200. for(int i=0;i<count;i++)
  201. {
  202. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  203. bool check = [[item_json valueForKey:@"check"] boolValue];
  204. if(check)
  205. {
  206. /*
  207. if ([[item_json valueForKey:@"available"] isEqualToString:@"In Production"] || [[item_json valueForKey:@"available"] integerValue] == 0) {
  208. [RAUtils message_alert:@"There ars some products is not available" title:@"Warning" controller:self];
  209. return;
  210. }
  211. */
  212. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
  213. [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  214. }
  215. }
  216. if(checked.count==0)
  217. {
  218. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
  219. return;
  220. }
  221. NSString * ids = [checked_iid componentsJoinedByString:@","];
  222. self.btnAddtoCart.enabled = false;
  223. [RANetwork request_move_wish2cart:ids completionHandler:^(NSMutableDictionary *result) {
  224. NSDictionary* return_json = result;
  225. self.btnAddtoCart.enabled = true;
  226. if([[return_json valueForKey:@"result"] intValue]==2)
  227. {
  228. #ifdef RA_NOTIFICATION
  229. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  230. #else
  231. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  232. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  233. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  234. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  235. #endif
  236. [RAUtils message_alert:nil title:@" Multiple items moved to Cart" controller:self] ;
  237. }
  238. else
  239. {
  240. [self reload_data];
  241. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Cart" controller:self] ;
  242. }
  243. }];
  244. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  245. //
  246. // NSDictionary* return_json = [RANetwork move_wish2cart:ids];
  247. //
  248. // dispatch_async(dispatch_get_main_queue(), ^{
  249. //
  250. // self.btnAddtoCart.enabled = true;
  251. //
  252. // if([[return_json valueForKey:@"result"] intValue]==2)
  253. // {
  254. //// int result=[[return_json valueForKey:@"result"] intValue];re
  255. //// if(result==2)
  256. //// {
  257. // //successed.
  258. //
  259. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  260. //
  261. //// appDelegate.order_code = order_code;
  262. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  263. //// appDelegate.order_code = order_code;
  264. //
  265. //
  266. //
  267. //
  268. //
  269. //#ifdef RA_NOTIFICATION
  270. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  271. //#else
  272. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  273. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  274. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  275. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  276. //#endif
  277. // [RAUtils message_alert:nil title:@" Multiple items moved to Cart" controller:self] ;
  278. //
  279. //// [self end_select];
  280. //
  281. //
  282. //
  283. //// }
  284. // }
  285. // else
  286. // {
  287. // [self reload_data];
  288. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Cart" controller:self] ;
  289. // }
  290. //
  291. //
  292. //
  293. //
  294. // });
  295. // });
  296. }
  297. -(void) neworder
  298. {
  299. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order"];
  300. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  301. NSMutableDictionary* return_json =result;
  302. [waitalert dismissViewControllerAnimated:YES completion:nil];
  303. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  304. if([[return_json valueForKey:@"result"] intValue]==2)
  305. {
  306. int result=[[return_json valueForKey:@"result"] intValue];
  307. if(result==2)
  308. {
  309. //successed.
  310. NSString* order_code = [return_json valueForKey:@"orderCode"];
  311. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  312. appDelegate.order_code = order_code;
  313. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  314. [self addtocart];
  315. }
  316. }
  317. else
  318. {
  319. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  320. }
  321. }];
  322. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  323. //
  324. // NSDictionary* return_json = [RANetwork new_Order];
  325. //
  326. // dispatch_async(dispatch_get_main_queue(), ^{
  327. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  328. //
  329. //
  330. // if([[return_json valueForKey:@"result"] intValue]==2)
  331. // {
  332. // int result=[[return_json valueForKey:@"result"] intValue];
  333. // if(result==2)
  334. // {
  335. // //successed.
  336. //
  337. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  338. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  339. // appDelegate.order_code = order_code;
  340. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  341. //
  342. // [self addtocart];
  343. //
  344. //
  345. // // [self ReloadData];
  346. //
  347. //
  348. // // if(self.shopCartBlock!=nil)
  349. // // {
  350. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  351. // //
  352. // //
  353. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  354. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  355. // // iv.image = img;
  356. // // // [self.contentView addSubview:iv];
  357. // // self.shopCartBlock(iv);
  358. // //
  359. // // }
  360. //
  361. // }
  362. // }
  363. // else
  364. // {
  365. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  366. // }
  367. //
  368. //
  369. //
  370. //
  371. // });
  372. // });
  373. }
  374. - (void)viewDidLoad
  375. {
  376. [super viewDidLoad];
  377. DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  378. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  379. ref.tag = 200 ;
  380. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  381. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  382. // ref.hidden = true;
  383. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  384. [self.itemListTable addSubview:ref];
  385. DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  386. // [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]];
  387. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  388. self.label_net_err.layer.borderWidth = 2.0;
  389. self.label_net_err.layer.cornerRadius=15;
  390. self.label_net_err.layer.masksToBounds=true;
  391. CGPoint center = self.mum.center;
  392. self.mum.frame = CGRectMake(0, 0, 100, 100);
  393. self.mum.center = center;
  394. // self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
  395. self.mum.layer.cornerRadius = 5.0f;
  396. self.mum.layer.masksToBounds = YES;
  397. self.sortIndex = 0;
  398. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  399. // tap.minimumPressDuration = 0.8; //定义按的时间
  400. [self.label_net_err addGestureRecognizer:tap];
  401. // [self reload_data];
  402. }
  403. -(void)manually_refresh
  404. {
  405. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  406. if(self.isrefreshing)
  407. {
  408. [reF endRefreshing];
  409. return;
  410. }
  411. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  412. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  413. // DebugLog(@"refresh!!!!!!!!");
  414. }
  415. - (IBAction)onSelectClick:(id)sender {
  416. // self.total=0;
  417. if([self.btnselect.title isEqualToString:@"Select all"])
  418. {
  419. int count =[[self.content_data valueForKey:@"count"] intValue];
  420. for(int i=0;i<count;i++)
  421. {
  422. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  423. [item_json setValue:@"1" forKey:@"check"];
  424. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  425. cell.img_checkmark.hidden=false;
  426. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  427. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  428. }
  429. [self.btnselect setTitle:@"Deselect all"];
  430. }
  431. else
  432. {
  433. int count =[[self.content_data valueForKey:@"count"] intValue];
  434. for(int i=0;i<count;i++)
  435. {
  436. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
  437. [item_json setValue:@"0" forKey:@"check"];
  438. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  439. cell.img_checkmark.hidden=true;
  440. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  441. }
  442. [self.btnselect setTitle:@"Select all"];
  443. // self.btnselect.titleLabel.text=@"Select all";
  444. }
  445. }
  446. - (IBAction)onDeleteClick:(id)sender {
  447. NSMutableArray* checked = [[NSMutableArray alloc] init];
  448. int count = [[self.content_data valueForKey:@"count"] intValue];
  449. for(int i=0;i<count;i++)
  450. {
  451. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  452. int check = [[item_json valueForKey:@"check"] intValue];
  453. if(check==1)
  454. {
  455. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  456. }
  457. }
  458. // disable for debug
  459. if(checked.count==0)
  460. return;
  461. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  462. NSString * string = [checked componentsJoinedByString:@","];
  463. [RANetwork request_remove_wishlist:string completionHandler:^(NSMutableDictionary *result) {
  464. NSMutableDictionary* cart_json = result;
  465. if([[cart_json valueForKey:@"result"] intValue]==2)
  466. {
  467. [self reload_data];
  468. [self.btnselect setTitle:@"Select all"];
  469. }
  470. else
  471. {
  472. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
  473. }
  474. }];
  475. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  476. //
  477. // NSDictionary* cart_json = [RANetwork watchlist_remove:string];
  478. //
  479. // dispatch_async(dispatch_get_main_queue(), ^{
  480. //
  481. //
  482. //
  483. // if([[cart_json valueForKey:@"result"] intValue]==2)
  484. // {
  485. // [self reload_data];
  486. //
  487. // [self.btnselect setTitle:@"Select all"];
  488. // }
  489. // else
  490. // {
  491. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
  492. // }
  493. //
  494. // });
  495. // });
  496. }
  497. -(void) viewWillAppear:(BOOL)animated
  498. {
  499. [super viewWillAppear:animated];
  500. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  501. #ifdef OFFLINE_MODE
  502. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  503. // 离线隐藏Email
  504. self.emailBtn.enabled = !appDelegate.offline_mode;
  505. // 离线隐藏Print
  506. self.printBtn.enabled = !appDelegate.offline_mode;
  507. #endif
  508. }
  509. -(void) operation_reload_data
  510. {
  511. if (self.dataOperationQueue.operationCount > 1) {
  512. return;
  513. }
  514. dispatch_async(dispatch_get_main_queue(), ^{
  515. if(self.isrefreshing)
  516. return;
  517. // [self.content_data removeAllObjects];
  518. // [self.itemListTable reloadData];
  519. self.isrefreshing=true;
  520. self.label_net_err.hidden=true;
  521. self.itemListTable.hidden=true;
  522. self.mum.center = self.view.center;
  523. self.mum.hidden = false;
  524. [self.mum startAnimating];
  525. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  526. [reF endRefreshing];
  527. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  528. [RANetwork request_wishlist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
  529. NSMutableDictionary* cart_json =result;
  530. [self.mum stopAnimating];
  531. self.isrefreshing=false;
  532. if (self.dataOperationQueue.operationCount > 1) {
  533. return ;
  534. }
  535. int result_code=[[cart_json valueForKey:@"result"] intValue];
  536. self.content_data = [cart_json mutableCopy];
  537. [self.itemListTable reloadData];
  538. self.print_url = [cart_json objectForKey:@"wishlist_print_url"];
  539. if(result_code==2||result_code==1||result_code==0)
  540. {
  541. self.itemListTable.hidden=false;
  542. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  543. appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue];
  544. }
  545. else
  546. if(result_code==RESULT_NET_ERROR)
  547. {
  548. self.label_net_err.hidden=false;
  549. self.itemListTable.hidden=true;
  550. }
  551. else
  552. {
  553. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Wish list" controller:self] ;
  554. }
  555. self.isrefreshing=false;
  556. }];
  557. return;
  558. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  559. //
  560. // NSDictionary* cart_json = [RANetwork request_WatchList:self.sortIndex];
  561. //
  562. // dispatch_async(dispatch_get_main_queue(), ^{
  563. //
  564. // [self.mum stopAnimating];
  565. // self.isrefreshing=false;
  566. // if (self.dataOperationQueue.operationCount > 1) {
  567. // return ;
  568. // }
  569. //
  570. // int result=[[cart_json valueForKey:@"result"] intValue];
  571. // self.content_data = [cart_json mutableCopy];
  572. // [self.itemListTable reloadData];
  573. // self.print_url = [cart_json objectForKey:@"wishlist_print_url"];
  574. //
  575. // if(result==2||result==1||result==0)
  576. // {
  577. // self.itemListTable.hidden=false;
  578. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  579. // appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue];
  580. // }
  581. // else
  582. // if(result==RESULT_NET_ERROR)
  583. // {
  584. // self.label_net_err.hidden=false;
  585. // self.itemListTable.hidden=true;
  586. // }
  587. // else
  588. // {
  589. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Wish list" controller:self] ;
  590. // }
  591. //
  592. // self.isrefreshing=false;
  593. //
  594. // });
  595. // });
  596. });
  597. }
  598. - (void)didReceiveMemoryWarning
  599. {
  600. [super didReceiveMemoryWarning];
  601. // Dispose of any resources that can be recreated.
  602. }
  603. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  604. //{
  605. //
  606. // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  607. //
  608. //
  609. //
  610. //// [self.itemListTable reloadData];
  611. // DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  612. //
  613. //
  614. //}
  615. #pragma mark - Table view data source
  616. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  617. //{
  618. // return 0;
  619. //}
  620. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  621. //{
  622. // return 0;
  623. //}
  624. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  625. //{
  626. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  627. // return myView;
  628. //
  629. //}
  630. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  631. //{
  632. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  633. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  634. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  635. //// titleLabel.textColor=[UIColor whiteColor];
  636. //// titleLabel.backgroundColor = [UIColor clearColor];
  637. //// if(section==0)
  638. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  639. //// else
  640. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  641. //// [titleLabel sizeToFit];
  642. //// [myView addSubview:titleLabel];
  643. ////
  644. // return myView;
  645. //}
  646. //
  647. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  648. // if(section==0)
  649. // return nil;
  650. // else
  651. // return @"detail section";
  652. //}
  653. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  654. {
  655. return 33;
  656. }
  657. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  658. {
  659. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  660. if(value==nil)
  661. value=@"";
  662. unsigned long color = strtoul([value UTF8String],0,16);
  663. NSString *sectionTitle = @"Wish List";
  664. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)];
  665. // UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
  666. // sortButton.frame = CGRectMake(20, 5.5, (33 - 5.5 * 2), (33 - 5.5 * 2));
  667. // [sortButton setImage:[UIImage imageNamed:@"check_1_24"] forState:UIControlStateNormal];
  668. // [sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  669. // [myView addSubview:sortButton];
  670. [myView addSubview:self.sortButton];
  671. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5.5, tableView.bounds.size.width, 22)];
  672. titlelabel.textColor=UIColorFromRGB(color);
  673. titlelabel.textAlignment=NSTextAlignmentCenter;
  674. titlelabel.autoresizingMask=UIViewAutoresizingFlexibleWidth;
  675. titlelabel.text=sectionTitle;
  676. titlelabel.center = myView.center;
  677. myView.autoresizesSubviews=true;
  678. [myView addSubview:titlelabel];
  679. [myView addSubview:self.qtyLabel];
  680. return myView;
  681. }
  682. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  683. {
  684. return 1;
  685. }
  686. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  687. {
  688. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  689. int count =[[self.content_data valueForKey:@"count"] intValue];
  690. return count;
  691. }
  692. - (IBAction)imgbtnClicked:(UIButton *)sender {
  693. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  694. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  695. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  696. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  697. NSString* product_id = [item_json valueForKey:@"product_id"];
  698. NSString *name = [item_json objectForKey:@"description"];
  699. NSRange subRange = [name rangeOfString:@"\n"];
  700. name = [name substringToIndex:subRange.location];
  701. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  702. // dvc
  703. dvc.product_id=product_id;
  704. dvc.category_id=nil;
  705. dvc.ispush=true;
  706. dvc.model_name = name;
  707. [dvc reload];
  708. [self.navigationController pushViewController:dvc animated:true];
  709. }
  710. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  711. {
  712. // if(tableView==self.itemListTable)
  713. // {
  714. NSString *CellIdentifier = @"WatchListItemCell";
  715. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  716. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  717. // Button 设置了大小约束,Size就不会随内容变化
  718. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  719. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  720. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  721. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  722. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  723. NSString* img_url = [item_json valueForKey:@"img"];
  724. NSString* description = [item_json valueForKey:@"description"];
  725. // NSString* identifier = [item_json valueForKey:@"identifier"];
  726. // NSString* attribute = [item_json valueForKey:@"attribute"];
  727. // NSString* currency = [item_json valueForKey:@"currency"];
  728. // int count =[[item_json valueForKey:@"count"] intValue];
  729. NSString* price =[item_json valueForKey:@"tear_sheet_price"];
  730. // cell.labelAttribute.text = attribute;
  731. // cell.labelCurrency.text = currency;
  732. cell.labelDescription.text = description;
  733. // cell.labelIdentifier.text = identifier;
  734. cell.labelPrice.text = price;
  735. // cell.editCount.text =[NSString stringWithFormat:@"%d",count];
  736. // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  737. int check = [[item_json valueForKey:@"check"] intValue];
  738. if(check==1)
  739. cell.img_checkmark.hidden=false;
  740. else
  741. cell.img_checkmark.hidden=true;
  742. // UIImageView* iv =cell.btnImage.imageView;
  743. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  744. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  745. NSString* file_name=[img_url lastPathComponent];
  746. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  747. if(img_data!=nil)
  748. {
  749. UIImage * img =[UIImage imageWithData:img_data];
  750. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  751. [cell.btnImage setImage:img forState:UIControlStateNormal];
  752. }
  753. else
  754. {
  755. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  756. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  757. dispatch_async(dispatch_get_main_queue(), ^{
  758. if(downloadimg_data!=nil)
  759. {
  760. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  761. UIImage * img =[UIImage imageWithData:downloadimg_data];
  762. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  763. [cell.btnImage setImage:img forState:UIControlStateNormal];
  764. }
  765. else
  766. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  767. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  768. });
  769. });
  770. }
  771. cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
  772. int qty = [item_json[@"cart_count"] intValue];
  773. cell.qty_Label.text = [NSString stringWithFormat:@"QTY: %d",qty];
  774. return cell;
  775. }
  776. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  777. {
  778. ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  779. cell.selected = false;
  780. // self.dirty = true;
  781. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  782. int check = [[item_json valueForKey:@"check"] intValue];
  783. if(check==1)
  784. {
  785. [item_json setValue:@"0" forKey:@"check"];
  786. cell.img_checkmark.hidden=true;
  787. [self.btnselect setTitle: @"Select all"];
  788. }
  789. else
  790. {
  791. [item_json setValue:@"1" forKey:@"check"];
  792. cell.img_checkmark.hidden=false;
  793. }
  794. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  795. }
  796. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  797. return UITableViewCellEditingStyleDelete;
  798. }
  799. //#pragma mark - UIAlertViewDelegate
  800. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  801. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  802. //{
  803. //
  804. //
  805. //
  806. //}
  807. - (BOOL)isPureFloat:(NSString*)string{
  808. NSScanner* scan = [NSScanner scannerWithString:string];
  809. float val;
  810. return[scan scanFloat:&val] && [scan isAtEnd];
  811. }
  812. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  813. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  814. {
  815. // 添加一个删除按钮
  816. self.indexPath=indexPath;
  817. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  818. DebugLog(@"delete click");
  819. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from wishlist?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  820. alert.tag = ALERT_DEL;
  821. // alert.
  822. [alert show];
  823. }];
  824. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  825. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  826. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  827. return @[deleteRowAction];
  828. else
  829. return @[deleteRowAction];
  830. }
  831. - (void)tableView:(UITableView *)tableView
  832. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  833. }
  834. #pragma mark - UIAlertViewDelegate
  835. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  836. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  837. {
  838. UIApplication * app = [UIApplication sharedApplication];
  839. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  840. // if(alertView.tag==1234)
  841. // {
  842. //
  843. // // availability warring;
  844. //
  845. //
  846. // if(buttonIndex!=alertView.cancelButtonIndex)
  847. // {
  848. // if(appDelegate.order_code==nil)
  849. // {
  850. // [self neworder];
  851. // }
  852. // else
  853. // {
  854. // [self addtocart];
  855. // }
  856. // }
  857. // return;
  858. // }
  859. // int count=[self.quantity_text.text intValue];
  860. if(alertView.tag==ALERT_DEL)
  861. {
  862. if(buttonIndex!=alertView.cancelButtonIndex)
  863. {
  864. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  865. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  866. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
  867. [RANetwork request_remove_wishlist:ids completionHandler:^(NSMutableDictionary *result) {
  868. NSMutableDictionary* cart_json = result;
  869. if([[cart_json valueForKey:@"result"] intValue]==2)
  870. {
  871. [self reload_data];
  872. }
  873. else
  874. {
  875. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  876. }
  877. }];
  878. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  879. //
  880. // NSDictionary* cart_json = [RANetwork watchlist_remove:ids];
  881. //
  882. // dispatch_async(dispatch_get_main_queue(), ^{
  883. //
  884. //
  885. //
  886. // if([[cart_json valueForKey:@"result"] intValue]==2)
  887. // {
  888. // [self reload_data];
  889. // }
  890. // else
  891. // {
  892. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  893. // }
  894. //
  895. // });
  896. // });
  897. }
  898. return;
  899. }
  900. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  901. if(buttonIndex==alertView.cancelButtonIndex)
  902. {
  903. }
  904. else if(buttonIndex==1)
  905. {
  906. //open exist
  907. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  908. ovc.showNavibar = true;
  909. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  910. if(appDelegate.order_code==nil)
  911. {
  912. [self neworder];
  913. }
  914. else
  915. {
  916. [self addtocart];
  917. [main_vc checklogin:true];
  918. }
  919. };
  920. ovc.init_style = OL_OPEN;
  921. ovc.onCancel = ^(){
  922. [main_vc checklogin:true];
  923. };
  924. [self.navigationController pushViewController:ovc animated:true];
  925. }
  926. else
  927. {
  928. //create new;
  929. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  930. {
  931. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  932. cvc.showNavibar = true;
  933. cvc.contact_type = @"Sales_Order_Customer";
  934. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  935. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  936. appDelegate.customerInfo = value;
  937. if(appDelegate.order_code==nil)
  938. [self neworder];
  939. // [main_vc checklogin:true];
  940. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  941. //
  942. // if(self.returnValue)
  943. // self.returnValue(value);
  944. };
  945. cvc.onCancel = ^(){
  946. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  947. };
  948. cvc.onReset = ^(){
  949. [main_vc checklogin:true];
  950. };
  951. [self.navigationController pushViewController:cvc animated:true];
  952. }
  953. else
  954. {
  955. [self neworder];
  956. }
  957. }
  958. }
  959. #pragma mark - sort button
  960. - (void)wishlistSortButtonClicked:(UIButton *)sender {
  961. DebugLog(@"wish list sort button clicked");
  962. [self.view addSubview:self.sortItemController.view];
  963. }
  964. - (SortItemViewController *)sortItemController {
  965. if (!_sortItemController) {
  966. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(40, 40)];
  967. _sortItemController.sortIndex = self.sortIndex;
  968. _sortItemController.sortData = @[
  969. @{@"title":@"Last",@"icon":@"TX_18"},
  970. @{@"title":@"First",@"icon":@"TS_18"},
  971. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  972. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  973. @{@"title":@"Description",@"icon":@"DX_18"},
  974. ];
  975. __weak typeof(self) weakSelf = self;
  976. _sortItemController.sortBlock = ^(int sort){
  977. weakSelf.sortIndex = sort;
  978. [weakSelf reload_data];
  979. };
  980. }
  981. // _sortItemController.sortIndex = self.sortIndex;
  982. return _sortItemController;
  983. }
  984. - (SortButton *)sortButton {
  985. if (!_sortButton) {
  986. _sortButton = [SortButton sortButtonWithHeight:33];
  987. [_sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  988. }
  989. return _sortButton;
  990. }
  991. - (void)setSortIndex:(int)sortIndex {
  992. _sortIndex = sortIndex;
  993. NSString *selectedImageName = @"";
  994. switch (sortIndex) {
  995. case 0:{
  996. selectedImageName = @"TX_22";
  997. }
  998. break;
  999. case 1:{
  1000. selectedImageName = @"TS_22";
  1001. }
  1002. break;
  1003. case 2:{
  1004. selectedImageName = @"IX_22";
  1005. }
  1006. break;
  1007. case 3:{
  1008. selectedImageName = @"IS_22";
  1009. }
  1010. break;
  1011. case 4:{
  1012. selectedImageName = @"DX_22";
  1013. }
  1014. break;
  1015. default:
  1016. break;
  1017. }
  1018. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  1019. }
  1020. - (UILabel *)qtyLabel {
  1021. if (!_qtyLabel) {
  1022. _qtyLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22)];
  1023. _qtyLabel.text = @"QTY";
  1024. _qtyLabel.textAlignment = NSTextAlignmentCenter;
  1025. _qtyLabel.autoresizingMask= UIViewAutoresizingFlexibleLeftMargin;
  1026. }
  1027. return _qtyLabel;
  1028. }
  1029. #pragma mark - rotation
  1030. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1031. self.sortItemController.view.frame = self.view.bounds;
  1032. }
  1033. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  1034. return YES;
  1035. }
  1036. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1037. self.sortItemController.view.frame = self.view.bounds;
  1038. self.qtyLabel.frame = CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22);
  1039. }
  1040. #pragma mark - Action
  1041. - (IBAction)printWishlistClick:(UIBarButtonItem *)sender {
  1042. if ([[self.content_data valueForKey:@"count"] intValue] < 1) {
  1043. [RAUtils message_alert:@"Please add wishlist first" title:@"Warning" controller:self];
  1044. return;
  1045. }
  1046. if (self.print_url.length == 0) {
  1047. [RAUtils message_alert:@"There is no resource to print" title:@"Warning" controller:self];
  1048. }
  1049. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  1050. ViewController.url = self.print_url;
  1051. ViewController.canSave = false;
  1052. ViewController.isLocalfile=NO;
  1053. NSString* subject;
  1054. subject =@"Wishlist Print";
  1055. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1056. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  1057. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  1058. if(customer_email.length>0)
  1059. {
  1060. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  1061. }
  1062. ViewController.mail_to = send_to;
  1063. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Wish_List %@.pdf",cur_time];
  1064. /*
  1065. #ifdef BUILD_HOMER
  1066. ViewController.filename = [NSString stringWithFormat:@"HOMER_Wish_List.pdf"];
  1067. #endif
  1068. #if defined(BUILD_NPD) || defined(BUILD_USAI)
  1069. ViewController.filename = [NSString stringWithFormat:@"NPD_Wish_List.pdf"];
  1070. #endif
  1071. */
  1072. ViewController.filename = [NSString stringWithFormat:@"%@_Wish_List.pdf",COMPANY_SHORT_NAME];
  1073. ViewController.mail_subject = subject;
  1074. ViewController.hidenavi = false;
  1075. [self.navigationController pushViewController:ViewController animated:YES];
  1076. }
  1077. - (IBAction)emailWishlistClick:(UIBarButtonItem *)sender {
  1078. if ([[self.content_data valueForKey:@"count"] intValue] < 1) {
  1079. [RAUtils message_alert:@"Please add wishlist first" title:@"Warning" controller:self];
  1080. return;
  1081. }
  1082. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  1083. emailAddrVC.textFiled.secureTextEntry = NO;
  1084. emailAddrVC.yesButtonTitle = @"send";
  1085. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  1086. __weak typeof(self) weakself = self;
  1087. emailAddrVC.textHandler = ^(NSString *text){
  1088. // 验证邮箱格式是否正确
  1089. // NSString *match = EMAIL_MATCHES;
  1090. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  1091. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  1092. BOOL isEmailAddr = YES;
  1093. if (isEmailAddr) {
  1094. // 验证是邮件地址,发送邮件
  1095. [weakVC dismissViewControllerAnimated:YES completion:^{
  1096. UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email"];
  1097. [RANetwork request_emailwishlist:text completionHandler:^(NSMutableDictionary *result) {
  1098. DebugLog(@"email wishlist result: %@",result);
  1099. [waitting_alert dismissViewControllerAnimated:YES completion:nil];
  1100. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  1101. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  1102. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  1103. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1104. }];
  1105. [errorAlertVC addAction:action];
  1106. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1107. }else {
  1108. [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
  1109. }
  1110. }];
  1111. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1112. //
  1113. // NSDictionary *result = [RANetwork quoteWishlist2EmailAddr:text];
  1114. // DebugLog(@"email wishlist result: %@",result);
  1115. // dispatch_async(dispatch_get_main_queue(), ^{
  1116. //
  1117. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  1118. //
  1119. // if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  1120. //
  1121. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  1122. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1123. //
  1124. // }];
  1125. //
  1126. // [errorAlertVC addAction:action];
  1127. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1128. //
  1129. // }else {
  1130. //
  1131. // [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
  1132. //
  1133. // }
  1134. //
  1135. // });
  1136. //
  1137. // });
  1138. }];
  1139. } else {
  1140. // 非邮件地址,警告
  1141. [weakVC warning:@"Please enter right email address"];
  1142. }
  1143. };
  1144. [self presentViewController:emailAddrVC animated:YES completion:nil];
  1145. }
  1146. - (void)reRefreshView {
  1147. [self.itemListTable reloadData];
  1148. }
  1149. #pragma mark - RA_NOTIFICAITON
  1150. -(void) refresh_ui
  1151. {
  1152. [self.itemListTable reloadData];
  1153. }
  1154. -(void) reload_data {
  1155. __weak typeof(self) weakself = self;
  1156. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  1157. if (weakself) {
  1158. __strong typeof(weakself) strongself = weakself;
  1159. [strongself operation_reload_data];
  1160. }
  1161. }];
  1162. [self.dataOperationQueue addOperation:operation];
  1163. }
  1164. @end