WatchListViewController.m 48 KB

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