WatchListViewController.m 56 KB

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