WatchListViewController.m 50 KB

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