WatchListViewController.m 48 KB

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