WatchListViewController.m 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  300. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  301. NSMutableDictionary* return_json =result;
  302. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  303. if([[return_json valueForKey:@"result"] intValue]==2)
  304. {
  305. int result=[[return_json valueForKey:@"result"] intValue];
  306. if(result==2)
  307. {
  308. //successed.
  309. NSString* order_code = [return_json valueForKey:@"orderCode"];
  310. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  311. appDelegate.order_code = order_code;
  312. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  313. [self addtocart];
  314. }
  315. }
  316. else
  317. {
  318. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  319. }
  320. }];
  321. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  322. //
  323. // NSDictionary* return_json = [RANetwork new_Order];
  324. //
  325. // dispatch_async(dispatch_get_main_queue(), ^{
  326. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  327. //
  328. //
  329. // if([[return_json valueForKey:@"result"] intValue]==2)
  330. // {
  331. // int result=[[return_json valueForKey:@"result"] intValue];
  332. // if(result==2)
  333. // {
  334. // //successed.
  335. //
  336. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  337. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  338. // appDelegate.order_code = order_code;
  339. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  340. //
  341. // [self addtocart];
  342. //
  343. //
  344. // // [self ReloadData];
  345. //
  346. //
  347. // // if(self.shopCartBlock!=nil)
  348. // // {
  349. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  350. // //
  351. // //
  352. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  353. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  354. // // iv.image = img;
  355. // // // [self.contentView addSubview:iv];
  356. // // self.shopCartBlock(iv);
  357. // //
  358. // // }
  359. //
  360. // }
  361. // }
  362. // else
  363. // {
  364. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  365. // }
  366. //
  367. //
  368. //
  369. //
  370. // });
  371. // });
  372. }
  373. - (void)viewDidLoad
  374. {
  375. [super viewDidLoad];
  376. DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  377. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  378. ref.tag = 200 ;
  379. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  380. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  381. // ref.hidden = true;
  382. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  383. [self.itemListTable addSubview:ref];
  384. DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  385. // [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]];
  386. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  387. self.label_net_err.layer.borderWidth = 2.0;
  388. self.label_net_err.layer.cornerRadius=15;
  389. self.label_net_err.layer.masksToBounds=true;
  390. CGPoint center = self.mum.center;
  391. self.mum.frame = CGRectMake(0, 0, 100, 100);
  392. self.mum.center = center;
  393. // self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
  394. self.mum.layer.cornerRadius = 5.0f;
  395. self.mum.layer.masksToBounds = YES;
  396. self.sortIndex = 0;
  397. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  398. // tap.minimumPressDuration = 0.8; //定义按的时间
  399. [self.label_net_err addGestureRecognizer:tap];
  400. // [self reload_data];
  401. }
  402. -(void)manually_refresh
  403. {
  404. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  405. if(self.isrefreshing)
  406. {
  407. [reF endRefreshing];
  408. return;
  409. }
  410. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  411. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  412. // DebugLog(@"refresh!!!!!!!!");
  413. }
  414. - (IBAction)onSelectClick:(id)sender {
  415. // self.total=0;
  416. if([self.btnselect.title isEqualToString:@"Select all"])
  417. {
  418. int count =[[self.content_data valueForKey:@"count"] intValue];
  419. for(int i=0;i<count;i++)
  420. {
  421. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  422. [item_json setValue:@"1" forKey:@"check"];
  423. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  424. cell.img_checkmark.hidden=false;
  425. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  426. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  427. }
  428. [self.btnselect setTitle:@"Deselect all"];
  429. }
  430. else
  431. {
  432. int count =[[self.content_data valueForKey:@"count"] intValue];
  433. for(int i=0;i<count;i++)
  434. {
  435. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
  436. [item_json setValue:@"0" forKey:@"check"];
  437. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  438. cell.img_checkmark.hidden=true;
  439. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  440. }
  441. [self.btnselect setTitle:@"Select all"];
  442. // self.btnselect.titleLabel.text=@"Select all";
  443. }
  444. }
  445. - (IBAction)onDeleteClick:(id)sender {
  446. NSMutableArray* checked = [[NSMutableArray alloc] init];
  447. int count = [[self.content_data valueForKey:@"count"] intValue];
  448. for(int i=0;i<count;i++)
  449. {
  450. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  451. int check = [[item_json valueForKey:@"check"] intValue];
  452. if(check==1)
  453. {
  454. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  455. }
  456. }
  457. // disable for debug
  458. if(checked.count==0)
  459. return;
  460. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  461. NSString * string = [checked componentsJoinedByString:@","];
  462. [RANetwork request_remove_wishlist:string completionHandler:^(NSMutableDictionary *result) {
  463. NSMutableDictionary* cart_json = result;
  464. if([[cart_json valueForKey:@"result"] intValue]==2)
  465. {
  466. [self reload_data];
  467. [self.btnselect setTitle:@"Select all"];
  468. }
  469. else
  470. {
  471. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
  472. }
  473. }];
  474. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  475. //
  476. // NSDictionary* cart_json = [RANetwork watchlist_remove:string];
  477. //
  478. // dispatch_async(dispatch_get_main_queue(), ^{
  479. //
  480. //
  481. //
  482. // if([[cart_json valueForKey:@"result"] intValue]==2)
  483. // {
  484. // [self reload_data];
  485. //
  486. // [self.btnselect setTitle:@"Select all"];
  487. // }
  488. // else
  489. // {
  490. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Wish List" controller:self] ;
  491. // }
  492. //
  493. // });
  494. // });
  495. }
  496. -(void) viewWillAppear:(BOOL)animated
  497. {
  498. [super viewWillAppear:animated];
  499. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  500. #ifdef OFFLINE_MODE
  501. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  502. // 离线隐藏Email
  503. self.emailBtn.enabled = !appDelegate.offline_mode;
  504. // 离线隐藏Print
  505. self.printBtn.enabled = !appDelegate.offline_mode;
  506. #endif
  507. }
  508. -(void) operation_reload_data
  509. {
  510. if (self.dataOperationQueue.operationCount > 1) {
  511. return;
  512. }
  513. dispatch_async(dispatch_get_main_queue(), ^{
  514. if(self.isrefreshing)
  515. return;
  516. // [self.content_data removeAllObjects];
  517. // [self.itemListTable reloadData];
  518. self.isrefreshing=true;
  519. self.label_net_err.hidden=true;
  520. self.itemListTable.hidden=true;
  521. self.mum.center = self.view.center;
  522. self.mum.hidden = false;
  523. [self.mum startAnimating];
  524. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  525. [reF endRefreshing];
  526. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  527. [RANetwork request_wishlist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
  528. NSMutableDictionary* cart_json =result;
  529. [self.mum stopAnimating];
  530. self.isrefreshing=false;
  531. if (self.dataOperationQueue.operationCount > 1) {
  532. return ;
  533. }
  534. int result_code=[[cart_json valueForKey:@"result"] intValue];
  535. self.content_data = [cart_json mutableCopy];
  536. [self.itemListTable reloadData];
  537. self.print_url = [cart_json objectForKey:@"wishlist_print_url"];
  538. if(result_code==2||result_code==1||result_code==0)
  539. {
  540. self.itemListTable.hidden=false;
  541. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  542. appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue];
  543. }
  544. else
  545. if(result_code==RESULT_NET_ERROR)
  546. {
  547. self.label_net_err.hidden=false;
  548. self.itemListTable.hidden=true;
  549. }
  550. else
  551. {
  552. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Wish list" controller:self] ;
  553. }
  554. self.isrefreshing=false;
  555. }];
  556. return;
  557. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  558. //
  559. // NSDictionary* cart_json = [RANetwork request_WatchList:self.sortIndex];
  560. //
  561. // dispatch_async(dispatch_get_main_queue(), ^{
  562. //
  563. // [self.mum stopAnimating];
  564. // self.isrefreshing=false;
  565. // if (self.dataOperationQueue.operationCount > 1) {
  566. // return ;
  567. // }
  568. //
  569. // int result=[[cart_json valueForKey:@"result"] intValue];
  570. // self.content_data = [cart_json mutableCopy];
  571. // [self.itemListTable reloadData];
  572. // self.print_url = [cart_json objectForKey:@"wishlist_print_url"];
  573. //
  574. // if(result==2||result==1||result==0)
  575. // {
  576. // self.itemListTable.hidden=false;
  577. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  578. // appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue];
  579. // }
  580. // else
  581. // if(result==RESULT_NET_ERROR)
  582. // {
  583. // self.label_net_err.hidden=false;
  584. // self.itemListTable.hidden=true;
  585. // }
  586. // else
  587. // {
  588. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Wish list" controller:self] ;
  589. // }
  590. //
  591. // self.isrefreshing=false;
  592. //
  593. // });
  594. // });
  595. });
  596. }
  597. - (void)didReceiveMemoryWarning
  598. {
  599. [super didReceiveMemoryWarning];
  600. // Dispose of any resources that can be recreated.
  601. }
  602. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  603. //{
  604. //
  605. // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  606. //
  607. //
  608. //
  609. //// [self.itemListTable reloadData];
  610. // DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame));
  611. //
  612. //
  613. //}
  614. #pragma mark - Table view data source
  615. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  616. //{
  617. // return 0;
  618. //}
  619. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  620. //{
  621. // return 0;
  622. //}
  623. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  624. //{
  625. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  626. // return myView;
  627. //
  628. //}
  629. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  630. //{
  631. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  632. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  633. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  634. //// titleLabel.textColor=[UIColor whiteColor];
  635. //// titleLabel.backgroundColor = [UIColor clearColor];
  636. //// if(section==0)
  637. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  638. //// else
  639. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  640. //// [titleLabel sizeToFit];
  641. //// [myView addSubview:titleLabel];
  642. ////
  643. // return myView;
  644. //}
  645. //
  646. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  647. // if(section==0)
  648. // return nil;
  649. // else
  650. // return @"detail section";
  651. //}
  652. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  653. {
  654. return 33;
  655. }
  656. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  657. {
  658. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  659. if(value==nil)
  660. value=@"";
  661. unsigned long color = strtoul([value UTF8String],0,16);
  662. NSString *sectionTitle = @"Wish List";
  663. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)];
  664. // UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
  665. // sortButton.frame = CGRectMake(20, 5.5, (33 - 5.5 * 2), (33 - 5.5 * 2));
  666. // [sortButton setImage:[UIImage imageNamed:@"check_1_24"] forState:UIControlStateNormal];
  667. // [sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  668. // [myView addSubview:sortButton];
  669. [myView addSubview:self.sortButton];
  670. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5.5, tableView.bounds.size.width, 22)];
  671. titlelabel.textColor=UIColorFromRGB(color);
  672. titlelabel.textAlignment=NSTextAlignmentCenter;
  673. titlelabel.autoresizingMask=UIViewAutoresizingFlexibleWidth;
  674. titlelabel.text=sectionTitle;
  675. titlelabel.center = myView.center;
  676. myView.autoresizesSubviews=true;
  677. [myView addSubview:titlelabel];
  678. [myView addSubview:self.qtyLabel];
  679. return myView;
  680. }
  681. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  682. {
  683. return 1;
  684. }
  685. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  686. {
  687. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  688. int count =[[self.content_data valueForKey:@"count"] intValue];
  689. return count;
  690. }
  691. - (IBAction)imgbtnClicked:(UIButton *)sender {
  692. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  693. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  694. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  695. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  696. NSString* product_id = [item_json valueForKey:@"product_id"];
  697. NSString *name = [item_json objectForKey:@"description"];
  698. NSRange subRange = [name rangeOfString:@"\n"];
  699. name = [name substringToIndex:subRange.location];
  700. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  701. // dvc
  702. dvc.product_id=product_id;
  703. dvc.category_id=nil;
  704. dvc.ispush=true;
  705. dvc.model_name = name;
  706. [dvc reload];
  707. [self.navigationController pushViewController:dvc animated:true];
  708. }
  709. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  710. {
  711. // if(tableView==self.itemListTable)
  712. // {
  713. NSString *CellIdentifier = @"WatchListItemCell";
  714. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  715. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  716. // Button 设置了大小约束,Size就不会随内容变化
  717. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  718. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  719. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  720. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  721. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  722. NSString* img_url = [item_json valueForKey:@"img"];
  723. NSString* description = [item_json valueForKey:@"description"];
  724. // NSString* identifier = [item_json valueForKey:@"identifier"];
  725. // NSString* attribute = [item_json valueForKey:@"attribute"];
  726. // NSString* currency = [item_json valueForKey:@"currency"];
  727. // int count =[[item_json valueForKey:@"count"] intValue];
  728. NSString* price =[item_json valueForKey:@"tear_sheet_price"];
  729. // cell.labelAttribute.text = attribute;
  730. // cell.labelCurrency.text = currency;
  731. cell.labelDescription.text = description;
  732. // cell.labelIdentifier.text = identifier;
  733. cell.labelPrice.text = price;
  734. // cell.editCount.text =[NSString stringWithFormat:@"%d",count];
  735. // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  736. int check = [[item_json valueForKey:@"check"] intValue];
  737. if(check==1)
  738. cell.img_checkmark.hidden=false;
  739. else
  740. cell.img_checkmark.hidden=true;
  741. // UIImageView* iv =cell.btnImage.imageView;
  742. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  743. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  744. NSString* file_name=[img_url lastPathComponent];
  745. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  746. if(img_data!=nil)
  747. {
  748. UIImage * img =[UIImage imageWithData:img_data];
  749. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  750. [cell.btnImage setImage:img forState:UIControlStateNormal];
  751. }
  752. else
  753. {
  754. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  755. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  756. dispatch_async(dispatch_get_main_queue(), ^{
  757. if(downloadimg_data!=nil)
  758. {
  759. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  760. UIImage * img =[UIImage imageWithData:downloadimg_data];
  761. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  762. [cell.btnImage setImage:img forState:UIControlStateNormal];
  763. }
  764. else
  765. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  766. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  767. });
  768. });
  769. }
  770. cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
  771. int qty = [item_json[@"cart_count"] intValue];
  772. cell.qty_Label.text = [NSString stringWithFormat:@"QTY: %d",qty];
  773. return cell;
  774. }
  775. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  776. {
  777. ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  778. cell.selected = false;
  779. // self.dirty = true;
  780. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  781. int check = [[item_json valueForKey:@"check"] intValue];
  782. if(check==1)
  783. {
  784. [item_json setValue:@"0" forKey:@"check"];
  785. cell.img_checkmark.hidden=true;
  786. [self.btnselect setTitle: @"Select all"];
  787. }
  788. else
  789. {
  790. [item_json setValue:@"1" forKey:@"check"];
  791. cell.img_checkmark.hidden=false;
  792. }
  793. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  794. }
  795. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  796. return UITableViewCellEditingStyleDelete;
  797. }
  798. //#pragma mark - UIAlertViewDelegate
  799. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  800. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  801. //{
  802. //
  803. //
  804. //
  805. //}
  806. - (BOOL)isPureFloat:(NSString*)string{
  807. NSScanner* scan = [NSScanner scannerWithString:string];
  808. float val;
  809. return[scan scanFloat:&val] && [scan isAtEnd];
  810. }
  811. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  812. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  813. {
  814. // 添加一个删除按钮
  815. self.indexPath=indexPath;
  816. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  817. DebugLog(@"delete click");
  818. 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];
  819. alert.tag = ALERT_DEL;
  820. // alert.
  821. [alert show];
  822. }];
  823. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  824. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  825. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  826. return @[deleteRowAction];
  827. else
  828. return @[deleteRowAction];
  829. }
  830. - (void)tableView:(UITableView *)tableView
  831. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  832. }
  833. #pragma mark - UIAlertViewDelegate
  834. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  835. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  836. {
  837. UIApplication * app = [UIApplication sharedApplication];
  838. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  839. // if(alertView.tag==1234)
  840. // {
  841. //
  842. // // availability warring;
  843. //
  844. //
  845. // if(buttonIndex!=alertView.cancelButtonIndex)
  846. // {
  847. // if(appDelegate.order_code==nil)
  848. // {
  849. // [self neworder];
  850. // }
  851. // else
  852. // {
  853. // [self addtocart];
  854. // }
  855. // }
  856. // return;
  857. // }
  858. // int count=[self.quantity_text.text intValue];
  859. if(alertView.tag==ALERT_DEL)
  860. {
  861. if(buttonIndex!=alertView.cancelButtonIndex)
  862. {
  863. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  864. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  865. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
  866. [RANetwork request_remove_wishlist:ids completionHandler:^(NSMutableDictionary *result) {
  867. NSMutableDictionary* cart_json = result;
  868. if([[cart_json valueForKey:@"result"] intValue]==2)
  869. {
  870. [self reload_data];
  871. }
  872. else
  873. {
  874. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  875. }
  876. }];
  877. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  878. //
  879. // NSDictionary* cart_json = [RANetwork watchlist_remove:ids];
  880. //
  881. // dispatch_async(dispatch_get_main_queue(), ^{
  882. //
  883. //
  884. //
  885. // if([[cart_json valueForKey:@"result"] intValue]==2)
  886. // {
  887. // [self reload_data];
  888. // }
  889. // else
  890. // {
  891. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  892. // }
  893. //
  894. // });
  895. // });
  896. }
  897. return;
  898. }
  899. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  900. if(buttonIndex==alertView.cancelButtonIndex)
  901. {
  902. }
  903. else if(buttonIndex==1)
  904. {
  905. //open exist
  906. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  907. ovc.showNavibar = true;
  908. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  909. if(appDelegate.order_code==nil)
  910. {
  911. [self neworder];
  912. }
  913. else
  914. {
  915. [self addtocart];
  916. [main_vc checklogin:true];
  917. }
  918. };
  919. ovc.init_style = OL_OPEN;
  920. ovc.onCancel = ^(){
  921. [main_vc checklogin:true];
  922. };
  923. [self.navigationController pushViewController:ovc animated:true];
  924. }
  925. else
  926. {
  927. //create new;
  928. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  929. {
  930. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  931. cvc.showNavibar = true;
  932. cvc.contact_type = @"Sales_Order_Customer";
  933. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  934. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  935. appDelegate.customerInfo = value;
  936. if(appDelegate.order_code==nil)
  937. [self neworder];
  938. // [main_vc checklogin:true];
  939. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  940. //
  941. // if(self.returnValue)
  942. // self.returnValue(value);
  943. };
  944. cvc.onCancel = ^(){
  945. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  946. };
  947. cvc.onReset = ^(){
  948. [main_vc checklogin:true];
  949. };
  950. [self.navigationController pushViewController:cvc animated:true];
  951. }
  952. else
  953. {
  954. [self neworder];
  955. }
  956. }
  957. }
  958. #pragma mark - sort button
  959. - (void)wishlistSortButtonClicked:(UIButton *)sender {
  960. DebugLog(@"wish list sort button clicked");
  961. [self.view addSubview:self.sortItemController.view];
  962. }
  963. - (SortItemViewController *)sortItemController {
  964. if (!_sortItemController) {
  965. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(40, 40)];
  966. _sortItemController.sortIndex = self.sortIndex;
  967. _sortItemController.sortData = @[
  968. @{@"title":@"Last",@"icon":@"TX_18"},
  969. @{@"title":@"First",@"icon":@"TS_18"},
  970. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  971. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  972. @{@"title":@"Description",@"icon":@"DX_18"},
  973. ];
  974. __weak typeof(self) weakSelf = self;
  975. _sortItemController.sortBlock = ^(int sort){
  976. weakSelf.sortIndex = sort;
  977. [weakSelf reload_data];
  978. };
  979. }
  980. // _sortItemController.sortIndex = self.sortIndex;
  981. return _sortItemController;
  982. }
  983. - (SortButton *)sortButton {
  984. if (!_sortButton) {
  985. _sortButton = [SortButton sortButtonWithHeight:33];
  986. [_sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  987. }
  988. return _sortButton;
  989. }
  990. - (void)setSortIndex:(int)sortIndex {
  991. _sortIndex = sortIndex;
  992. NSString *selectedImageName = @"";
  993. switch (sortIndex) {
  994. case 0:{
  995. selectedImageName = @"TX_22";
  996. }
  997. break;
  998. case 1:{
  999. selectedImageName = @"TS_22";
  1000. }
  1001. break;
  1002. case 2:{
  1003. selectedImageName = @"IX_22";
  1004. }
  1005. break;
  1006. case 3:{
  1007. selectedImageName = @"IS_22";
  1008. }
  1009. break;
  1010. case 4:{
  1011. selectedImageName = @"DX_22";
  1012. }
  1013. break;
  1014. default:
  1015. break;
  1016. }
  1017. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  1018. }
  1019. - (UILabel *)qtyLabel {
  1020. if (!_qtyLabel) {
  1021. _qtyLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22)];
  1022. _qtyLabel.text = @"QTY";
  1023. _qtyLabel.textAlignment = NSTextAlignmentCenter;
  1024. _qtyLabel.autoresizingMask= UIViewAutoresizingFlexibleLeftMargin;
  1025. }
  1026. return _qtyLabel;
  1027. }
  1028. #pragma mark - rotation
  1029. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1030. self.sortItemController.view.frame = self.view.bounds;
  1031. }
  1032. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  1033. return YES;
  1034. }
  1035. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1036. self.sortItemController.view.frame = self.view.bounds;
  1037. self.qtyLabel.frame = CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22);
  1038. }
  1039. #pragma mark - Action
  1040. - (IBAction)printWishlistClick:(UIBarButtonItem *)sender {
  1041. if ([[self.content_data valueForKey:@"count"] intValue] < 1) {
  1042. [RAUtils message_alert:@"Please add wishlist first" title:@"Warning" controller:self];
  1043. return;
  1044. }
  1045. if (self.print_url.length == 0) {
  1046. [RAUtils message_alert:@"There is no resource to print" title:@"Warning" controller:self];
  1047. }
  1048. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  1049. ViewController.url = self.print_url;
  1050. ViewController.canSave = false;
  1051. ViewController.isLocalfile=NO;
  1052. NSString* subject;
  1053. subject =@"Wishlist Print";
  1054. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1055. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  1056. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  1057. if(customer_email.length>0)
  1058. {
  1059. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  1060. }
  1061. ViewController.mail_to = send_to;
  1062. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Wish_List %@.pdf",cur_time];
  1063. /*
  1064. #ifdef BUILD_HOMER
  1065. ViewController.filename = [NSString stringWithFormat:@"HOMER_Wish_List.pdf"];
  1066. #endif
  1067. #if defined(BUILD_NPD) || defined(BUILD_USAI)
  1068. ViewController.filename = [NSString stringWithFormat:@"NPD_Wish_List.pdf"];
  1069. #endif
  1070. */
  1071. ViewController.filename = [NSString stringWithFormat:@"%@_Wish_List.pdf",COMPANY_SHORT_NAME];
  1072. ViewController.mail_subject = subject;
  1073. ViewController.hidenavi = false;
  1074. [self.navigationController pushViewController:ViewController animated:YES];
  1075. }
  1076. - (IBAction)emailWishlistClick:(UIBarButtonItem *)sender {
  1077. if ([[self.content_data valueForKey:@"count"] intValue] < 1) {
  1078. [RAUtils message_alert:@"Please add wishlist first" title:@"Warning" controller:self];
  1079. return;
  1080. }
  1081. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  1082. emailAddrVC.textFiled.secureTextEntry = NO;
  1083. emailAddrVC.yesButtonTitle = @"send";
  1084. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  1085. __weak typeof(self) weakself = self;
  1086. emailAddrVC.textHandler = ^(NSString *text){
  1087. // 验证邮箱格式是否正确
  1088. // NSString *match = EMAIL_MATCHES;
  1089. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  1090. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  1091. BOOL isEmailAddr = YES;
  1092. if (isEmailAddr) {
  1093. // 验证是邮件地址,发送邮件
  1094. [weakVC dismissViewControllerAnimated:YES completion:^{
  1095. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1096. [RANetwork request_emailwishlist:text completionHandler:^(NSMutableDictionary *result) {
  1097. DebugLog(@"email wishlist result: %@",result);
  1098. [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  1099. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  1100. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  1101. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1102. }];
  1103. [errorAlertVC addAction:action];
  1104. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1105. }else {
  1106. [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
  1107. }
  1108. }];
  1109. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1110. //
  1111. // NSDictionary *result = [RANetwork quoteWishlist2EmailAddr:text];
  1112. // DebugLog(@"email wishlist result: %@",result);
  1113. // dispatch_async(dispatch_get_main_queue(), ^{
  1114. //
  1115. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  1116. //
  1117. // if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  1118. //
  1119. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  1120. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1121. //
  1122. // }];
  1123. //
  1124. // [errorAlertVC addAction:action];
  1125. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1126. //
  1127. // }else {
  1128. //
  1129. // [RAUtils message_alert:nil title:@"Email was sent successfully" controller:weakself];
  1130. //
  1131. // }
  1132. //
  1133. // });
  1134. //
  1135. // });
  1136. }];
  1137. } else {
  1138. // 非邮件地址,警告
  1139. [weakVC warning:@"Please enter right email address"];
  1140. }
  1141. };
  1142. [self presentViewController:emailAddrVC animated:YES completion:nil];
  1143. }
  1144. - (void)reRefreshView {
  1145. [self.itemListTable reloadData];
  1146. }
  1147. #pragma mark - RA_NOTIFICAITON
  1148. -(void) refresh_ui
  1149. {
  1150. [self.itemListTable reloadData];
  1151. }
  1152. -(void) reload_data {
  1153. __weak typeof(self) weakself = self;
  1154. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  1155. if (weakself) {
  1156. __strong typeof(weakself) strongself = weakself;
  1157. [strongself operation_reload_data];
  1158. }
  1159. }];
  1160. [self.dataOperationQueue addOperation:operation];
  1161. }
  1162. @end