WatchListViewController.m 54 KB

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