WatchListViewController.m 49 KB

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