WatchListViewController.m 50 KB

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