CartViewController.m 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  1. //
  2. // CartViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-6.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAUtils.h"
  9. #import "CartViewController.h"
  10. #import "ModelItemCell.h"
  11. #import "iSalesNetwork.h"
  12. //#import "CommonGridViewController.h"
  13. #import "CreateOrderViewController.h"
  14. #import "DetailViewController.h"
  15. #import "EditModelPriceViewController.h"
  16. #import "MainViewController.h"
  17. #import "LoginViewController.h"
  18. #import "ItemNotesViewController.h"
  19. #import "CartGeneralNotesViewController.h"
  20. #import "DefaultAppearance.h"
  21. #import "DefaultTableHeaderView.h"
  22. #define ALERT_FREE 1024
  23. #define ALERT_DEL 1025
  24. #define ALERT_SET_FREE 1026
  25. #define ALERT_RESTORE_FREE 1027
  26. @interface CartViewController ()
  27. @end
  28. @implementation CartViewController
  29. -(void) logout
  30. {
  31. [self.content_arr removeAllObjects];
  32. }
  33. - (IBAction)OnEditSelectClick:(id)sender {
  34. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  35. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  36. if(count==0)
  37. {
  38. [RAUtils message_alert:@"No item in the cart" title:@"Cart" controller:self] ;
  39. return;
  40. }
  41. for(int i=0;i<count;i++)
  42. {
  43. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  44. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  45. }
  46. NSString * ids = [arr_ids componentsJoinedByString:@","];
  47. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  48. //block代码块取代了delegate
  49. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  50. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  51. //block代码块取代了delegate
  52. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  53. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
  54. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  55. NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  56. dispatch_async(dispatch_get_main_queue(), ^{
  57. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  58. if([[cart_json valueForKey:@"result"] intValue]==2)
  59. {
  60. [self end_edit];
  61. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  62. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  63. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  64. }
  65. else
  66. {
  67. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  68. }
  69. });
  70. });
  71. }];
  72. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  73. NSLog(@"No");
  74. }];
  75. [alertControl addAction:actionOne];
  76. [alertControl addAction:alertthree];
  77. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  78. [self presentViewController:alertControl animated:YES completion:nil];
  79. NSLog(@"%@",self.edit_select_arr);
  80. }];
  81. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  82. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Move Models To Wish List"];
  83. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  84. NSDictionary* cart_json = [iSalesNetwork move_cart2wish:ids];
  85. dispatch_async(dispatch_get_main_queue(), ^{
  86. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  87. if([[cart_json valueForKey:@"result"] intValue]==2)
  88. {
  89. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  90. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  91. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  92. [self end_edit];
  93. }
  94. else
  95. {
  96. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  97. }
  98. });
  99. });
  100. }];
  101. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  102. NSLog(@"No");
  103. }];
  104. [alertControl addAction:actionOne];
  105. [alertControl addAction:actionTwo];
  106. [alertControl addAction:alertthree];
  107. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  108. [self presentViewController:alertControl animated:YES completion:nil];
  109. NSLog(@"%@",self.edit_select_arr);
  110. }
  111. - (IBAction)onEditAddWishClick:(id)sender {
  112. if(self.edit_select_arr.count==0)
  113. {
  114. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Move To Wish List" controller:self] ;
  115. return;
  116. }
  117. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  118. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  119. // //block代码块取代了delegate
  120. //
  121. //
  122. //
  123. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  124. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Move Models To Wish List"];
  125. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  126. NSDictionary* cart_json = [iSalesNetwork move_cart2wish:ids];
  127. dispatch_async(dispatch_get_main_queue(), ^{
  128. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  129. if([[cart_json valueForKey:@"result"] intValue]==2)
  130. {
  131. [self end_edit];
  132. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  133. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  134. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  135. }
  136. else
  137. {
  138. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  139. }
  140. });
  141. });
  142. // }];
  143. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  144. // NSLog(@"No");
  145. // }];
  146. // [alertControl addAction:actionOne];
  147. //
  148. // [alertControl addAction:alertthree];
  149. //
  150. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  151. //
  152. //
  153. // [self presentViewController:alertControl animated:YES completion:nil];
  154. //
  155. // NSLog(@"%@",self.edit_select_arr);
  156. }
  157. - (IBAction)onEditDelClick:(id)sender {
  158. if(self.edit_select_arr.count==0)
  159. {
  160. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Delete From Cart" controller:self] ;
  161. return;
  162. }
  163. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  164. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  165. //block代码块取代了delegate
  166. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  167. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
  168. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  169. NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  170. dispatch_async(dispatch_get_main_queue(), ^{
  171. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  172. if([[cart_json valueForKey:@"result"] intValue]==2)
  173. {
  174. [self end_edit];
  175. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  176. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  177. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  178. }
  179. else
  180. {
  181. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  182. }
  183. });
  184. });
  185. }];
  186. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  187. NSLog(@"No");
  188. }];
  189. [alertControl addAction:actionOne];
  190. [alertControl addAction:alertthree];
  191. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  192. [self presentViewController:alertControl animated:YES completion:nil];
  193. NSLog(@"%@",self.edit_select_arr);
  194. }
  195. - (IBAction)onEndEditClick:(id)sender {
  196. [self end_edit];
  197. }
  198. -(void)begin_edit
  199. {
  200. self.toolpanel.hidden = true;
  201. self.toolbar.hidden = false;
  202. // NSLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  203. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  204. if ( UIInterfaceOrientationIsPortrait(orientation))
  205. self.cartItemView.frame = CGRectMake(0,0,768,880);
  206. else
  207. self.cartItemView.frame = CGRectMake(0,0,1024,624);
  208. [self.itemListTable setEditing:true animated:YES];
  209. [self.itemListTable reloadData];
  210. }
  211. -(void) end_edit
  212. {
  213. self.toolpanel.hidden=false;
  214. self.toolbar.hidden=true;
  215. // NSLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  216. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  217. if ( UIInterfaceOrientationIsPortrait(orientation))
  218. self.cartItemView.frame = CGRectMake(0,0,768,824);
  219. else
  220. self.cartItemView.frame = CGRectMake(0,0,1024,568);
  221. [self.itemListTable setEditing:false animated:YES];
  222. [self.edit_select_arr removeAllObjects];
  223. [self.itemListTable reloadData];
  224. // [self reload_data];
  225. }
  226. - (IBAction)onEditClick:(id)sender {
  227. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  228. //
  229. // [appDelegate test_onDecodedDataResult:@"4400022"];
  230. //
  231. //
  232. // return;
  233. //
  234. [self begin_edit];
  235. }
  236. -(void) reload_container_getdata:(bool) update_data
  237. {
  238. [super reload_container_getdata:update_data];
  239. if(update_data)
  240. [self reload_data];
  241. else
  242. {
  243. [self.itemListTable reloadData];
  244. [self refresh_total];
  245. }
  246. }
  247. -(void) showHidePrice
  248. {
  249. [self reload_container_getdata:false];
  250. // [self refresh_total];
  251. }
  252. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  253. {
  254. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  255. if (self) {
  256. // Custom initialization
  257. }
  258. return self;
  259. }
  260. - (IBAction)imgbtnClick:(UIButton *)sender {
  261. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  262. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  263. // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  264. NSDictionary * item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  265. NSString* product_id = [item_json valueForKey:@"product_id"];
  266. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  267. // dvc
  268. dvc.product_id=product_id;
  269. dvc.category_id=nil;
  270. dvc.ispush=true;
  271. [dvc reload];
  272. [self.navigationController pushViewController:dvc animated:true];
  273. }
  274. -(void)viewWillLayoutSubviews
  275. {
  276. // if(self.showDetail==true)
  277. // {
  278. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  279. // int width=175;
  280. // // int height;
  281. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  282. // {
  283. // width = 370;
  284. // // height = 400;
  285. // }
  286. // else
  287. // {
  288. // // height = 300;
  289. // width = 175;
  290. // }
  291. //
  292. //
  293. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  294. //
  295. // self.collectionview.frame=frame;
  296. //
  297. //
  298. //
  299. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  300. // self.detailView.frame = framedetail;
  301. // }
  302. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  303. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  304. }
  305. - (void)viewWillAppear:(BOOL)animated
  306. {
  307. [super viewWillAppear:animated];
  308. // UIApplication * app = [UIApplication sharedApplication];
  309. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  310. // if(appDelegate.bLogin==false)
  311. // {
  312. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  313. // // loginvc.delegate = self;
  314. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  315. //
  316. // loginvc.returnValue = ^(bool blogin){
  317. //
  318. //
  319. // UIApplication * app = [UIApplication sharedApplication];
  320. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  321. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  322. //
  323. // [main_vc checklogin:true];
  324. //
  325. //// [self reload_data];
  326. //
  327. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  328. //
  329. // };
  330. //
  331. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  332. //
  333. //
  334. //
  335. //
  336. //
  337. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  338. //
  339. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  340. // [self presentViewController:navi animated:YES completion:^{
  341. //
  342. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  343. //
  344. // NSLog(@"CreateOrderViewController present.........");
  345. //
  346. // // self.btop = false;
  347. // // <#code#>
  348. // }];
  349. // }
  350. // else
  351. // {
  352. // [self reload_data];
  353. //// self.total = 0;
  354. // }
  355. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  356. }
  357. -(void) reload_data
  358. {
  359. dispatch_async(dispatch_get_main_queue(), ^{
  360. if(self.isrefreshing)
  361. return;
  362. self.itemListTable.hidden = true;
  363. self.label_net_err.hidden=true;
  364. self.isrefreshing=true;
  365. // [self.content_data removeAllObjects];
  366. // [self.itemListTable reloadData];
  367. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  368. //
  369. // [reF endRefreshing];
  370. //
  371. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  372. self.mum.center = self.view.center;
  373. self.mum.hidden = false;
  374. [self.mum startAnimating];
  375. NSLog(@"reloading...");
  376. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  377. NSLog(@"BEGIN LOAD CART");
  378. NSDictionary* cart_json = [iSalesNetwork request_Cart];
  379. dispatch_async(dispatch_get_main_queue(), ^{
  380. //
  381. [self.mum stopAnimating];
  382. // self.content_data = [cart_json mutableCopy];
  383. self.freejson = [cart_json objectForKey:@"freeGiveaway"];
  384. self.notes = [cart_json valueForKey:@"general_note"];
  385. self.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  386. [self.itemListTable reloadData];
  387. [self refresh_total];
  388. int result=[[cart_json valueForKey:@"result"] intValue];
  389. if(result==2||result==1||result==0)
  390. {
  391. self.itemListTable.hidden = false;
  392. UIApplication * app = [UIApplication sharedApplication];
  393. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  394. appDelegate.cart_count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  395. self.itemListTable.hidden=false;
  396. if(self.onFinishLoad)
  397. self.onFinishLoad();
  398. }
  399. else
  400. if(result==RESULT_NET_ERROR)
  401. {
  402. self.label_net_err.hidden=false;
  403. self.itemListTable.hidden=true;
  404. }
  405. else
  406. {
  407. if(result!=1)
  408. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:self] ;
  409. }
  410. self.isrefreshing=false;
  411. NSLog(@"FINISH LOAD CART");
  412. });
  413. });
  414. });
  415. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  416. }
  417. -(void)manually_refresh
  418. {
  419. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  420. if(self.isrefreshing)
  421. {
  422. [reF endRefreshing];
  423. return;
  424. }
  425. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  426. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  427. // DebugLog(@"refresh!!!!!!!!");
  428. }
  429. -(void) ReloadData
  430. {
  431. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  432. [reF endRefreshing];
  433. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  434. [self reload_data];
  435. }
  436. - (void)viewDidLoad
  437. {
  438. [super viewDidLoad];
  439. self.edit_select_arr= [[NSMutableArray alloc] init];
  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. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  445. // tap.minimumPressDuration = 0.8; //定义按的时间
  446. [self.label_net_err addGestureRecognizer:tap];
  447. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  448. ref.tag = 200 ;
  449. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  450. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  451. // ref.hidden = true;
  452. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  453. [self.itemListTable addSubview:ref];
  454. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  455. self.toolpanel.layer.masksToBounds = false;
  456. //添加四个边阴影
  457. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  458. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  459. self.toolpanel.layer.shadowOpacity = 0.5;
  460. self.toolpanel.layer.shadowRadius = 2.0;
  461. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  462. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  463. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  464. // // self.detailTable.sectionHeaderHeight = 0.0001;
  465. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  466. // Do any additional setup after loading the view.
  467. }
  468. //-(void)SelectOrder:(NSString *)orderid
  469. //{
  470. //// self.editOrderID.text=orderid;
  471. //// self.btnAddToOrder.enabled = true;
  472. //}
  473. - (void)didReceiveMemoryWarning
  474. {
  475. [super didReceiveMemoryWarning];
  476. // Dispose of any resources that can be recreated.
  477. }
  478. //- (IBAction)stepperAction:(UIStepper *)sender {
  479. //
  480. //
  481. //}
  482. - (IBAction)onContinueShoppingClick:(id)sender {
  483. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  484. [appDelegate switchToPreviousVC];
  485. }
  486. - (IBAction)onPlaceOrder:(UIButton *)sender {
  487. [self placeOrder];
  488. }
  489. -(void)placeOrder
  490. {
  491. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  492. bool have_free = false;
  493. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  494. if(count==0)
  495. {
  496. [RAUtils message_alert:@"Add some model first." title:@"Cart Is Empty." controller:self] ;
  497. return;
  498. }
  499. for(int i=0;i<count;i++)
  500. {
  501. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  502. // bool check = [[item_json valueForKey:@"check"] boolValue];
  503. NSString* product_id = [item_json valueForKey:@"product_id"];
  504. // if(check)
  505. // {
  506. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  507. //
  508. // }
  509. if(product_id.length==0)
  510. {
  511. [RAUtils message_alert:@"Some models in cart does not exist, you must remove them before place order." title:@"No Such Model" controller:self] ;
  512. return;
  513. }
  514. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  515. if(is_free)
  516. have_free=true;
  517. }
  518. // disable for debug
  519. // if(checked.count==0)
  520. // {
  521. // [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Place Order" controller:self] ;
  522. // return;
  523. // }
  524. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  525. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  526. /* FREE GIVE AWAY
  527. int free_count = [[self.freejson valueForKey:@"count"]intValue];
  528. for(int ic=free_count-1;ic>=0;ic--)
  529. {
  530. float compare_price = [[self.freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  531. if(self.total>=compare_price && !have_free&&appDelegate.can_set_cart_price)
  532. {
  533. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away available.", nil) message:[NSString stringWithFormat:@"Order total price more than %.2f, do you want to add free give away item before place order?", compare_price] delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  534. alert.tag = ALERT_FREE;
  535. [alert show];
  536. return;
  537. }
  538. }
  539. */
  540. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  541. // NSString * string = [checked componentsJoinedByString:@","];
  542. // [params setValue:string forKey:@"cart2Checkbox"];
  543. CreateOrderViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
  544. orderinfoVC.disable_dropdown_refresh=true;
  545. orderinfoVC.url_type = URL_REMOTE;
  546. orderinfoVC.request_url=URL_CARTDELIVERY;
  547. orderinfoVC.params = params;
  548. orderinfoVC.delegate=self;
  549. //
  550. // if(checked.count==count)
  551. // {
  552. // orderinfoVC.have_tail = true
  553. // }
  554. [self.navigationController pushViewController:orderinfoVC animated:true];
  555. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  556. //
  557. //
  558. //
  559. //
  560. //
  561. // navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  562. // [self presentViewController:navi animated:YES completion:^{
  563. //
  564. // NSLog(@"CreateOrderViewController present.........");
  565. //
  566. // // self.btop = false;
  567. // // <#code#>
  568. // }];
  569. }
  570. //- (IBAction)onCommit:(UIButton *)sender {
  571. // ;
  572. //}
  573. //- (IBAction)CreateOrder:(id)sender {
  574. //}
  575. //- (IBAction)AddToOrder:(id)sender {
  576. //}
  577. //- (IBAction)ChooseOrder:(id)sender {
  578. //
  579. // OrderListViewController * orderlistVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  580. // // orderlistVC.delegate = self;
  581. // orderlistVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  582. // [self presentViewController:orderlistVC animated:YES completion:^{
  583. //
  584. // NSLog(@"login.........");
  585. // // <#code#>
  586. // }];
  587. //}
  588. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  589. {
  590. //
  591. // CommonGridViewController * orderlistVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  592. // orderlistVC.delegate = self;
  593. // orderlistVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  594. // [self presentViewController:orderlistVC animated:YES completion:^{
  595. //
  596. // NSLog(@"textFieldShouldBeginEditing.........");
  597. // // <#code#>
  598. // }];
  599. return NO;
  600. }
  601. - (IBAction)onDelete:(UIButton *)sender {
  602. return ;
  603. NSMutableArray* checked = [[NSMutableArray alloc] init];
  604. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  605. for(int i=0;i<count;i++)
  606. {
  607. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  608. bool check = [[item_json valueForKey:@"check"] boolValue];
  609. if(check)
  610. {
  611. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  612. }
  613. }
  614. // disable for debug
  615. if(checked.count==0)
  616. return;
  617. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  618. NSString * string = [checked componentsJoinedByString:@","];
  619. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  620. NSDictionary* cart_json = [iSalesNetwork cart_remove:string];
  621. dispatch_async(dispatch_get_main_queue(), ^{
  622. if([[cart_json valueForKey:@"result"] intValue]==2)
  623. {
  624. [self reload_data];
  625. }
  626. else
  627. {
  628. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  629. }
  630. });
  631. });
  632. }
  633. -(void)refresh_total
  634. {
  635. self.total=0;
  636. self.total_carton=0;
  637. self.total_cuft=0;
  638. self.total_weight=0;
  639. self.total_QTY=0;
  640. self.total_item=0;
  641. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  642. for(int i=0;i<count;i++)
  643. {
  644. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  645. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  646. if(bcheck)
  647. {
  648. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  649. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  650. int count=[[item_json valueForKey:@"count"] intValue];
  651. double totalprice =count*unitprice * (1.0-discount/100.0);
  652. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  653. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  654. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  655. int item_count=1;
  656. int item_qty=1;
  657. NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  658. double dprice=0;
  659. if(bundle_item!=nil)
  660. {
  661. // int citem=0;
  662. int bcount=[[bundle_item valueForKey:@"count"] intValue];
  663. for(int bc=0;bc<bcount;bc++)
  664. {
  665. NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  666. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  667. // citem+= modulus;
  668. item_count+=1;
  669. item_qty+=modulus;
  670. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  671. dprice+= uprice*modulus*count;
  672. }
  673. }
  674. totalprice+= dprice;
  675. self.total+=totalprice;
  676. self.total_cuft+=cuft;
  677. self.total_carton+=carton;
  678. self.total_weight+=weight;
  679. self.total_item+=item_count;
  680. self.total_QTY+=(item_qty)*count;
  681. }
  682. }
  683. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  684. NSString* subtotal = [NSString stringWithFormat:@"$%.2f",self.total];
  685. NSString* subcuft = [NSString stringWithFormat:@"%.2f ft³",self.total_cuft];
  686. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  687. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  688. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  689. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  690. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  691. {
  692. }
  693. else
  694. {
  695. subtotal=nil;
  696. }
  697. self.labelTotal.text=subtotal;
  698. self.label_cuft.text=subcuft;
  699. self.label_carton.text=subcarton;
  700. self.label_weight.text=subweight;
  701. self.label_items.text = subitems;
  702. self.label_qty.text = subqty;
  703. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  704. }
  705. - (IBAction)onEditGeneralNotes:(id)sender {
  706. UIViewController* parentvc=self;
  707. CartGeneralNotesViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  708. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  709. vc.notes=self.notes;
  710. // vc.delegate = parentvc.self;
  711. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  712. vc.onSetValue = ^(NSString* notes){
  713. self.notes = notes;
  714. [self refresh_total];
  715. };
  716. //
  717. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  718. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  719. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  720. [parentvc presentViewController:navi animated:YES completion:^{
  721. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  722. NSLog(@"EditModelPriceViewController present.........");
  723. // self.btop = false;
  724. // <#code#>
  725. }];
  726. }
  727. //- (IBAction)onSelectAll:(UIButton *)sender {
  728. //
  729. //
  730. // NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  731. //
  732. //
  733. //
  734. //
  735. //
  736. //
  737. // if([self.btnselect.titleLabel.text isEqualToString:@"Select all"])
  738. // {
  739. //
  740. // long count = self.content_arr.count;// [[self.content_data valueForKey:@"count"] intValue];
  741. // for(int i=0;i<count;i++)
  742. // {
  743. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  744. // if(![[item_json valueForKey:@"check"] boolValue])
  745. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  746. //
  747. // }
  748. // [self.btnselect setTitle: @"Deselect all" forState: UIControlStateNormal];
  749. // }
  750. // else
  751. // {
  752. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  753. // for(int i=0;i<count;i++)
  754. // {
  755. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  756. // if([[item_json valueForKey:@"check"] boolValue])
  757. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  758. //
  759. // }
  760. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  761. // }
  762. //
  763. // NSString * ids = [arr_ids componentsJoinedByString:@","];
  764. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  765. //
  766. //
  767. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  768. //
  769. // dispatch_async(dispatch_get_main_queue(), ^{
  770. //
  771. //
  772. //
  773. // if([[check_json valueForKey:@"result"] intValue]==2)
  774. // {
  775. //
  776. // long count = self.content_arr.count;
  777. // for(int i=0;i<count;i++)
  778. // {
  779. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];
  780. // if([item_json[@"check"] boolValue])
  781. // item_json[@"check"]= @"false";
  782. // else
  783. // item_json[@"check"]= @"true";
  784. //
  785. // self.content_arr[i] = item_json;
  786. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  787. // }
  788. //
  789. // [self reload_container_getdata:false];
  790. //
  791. // // [self reload_data];
  792. // }
  793. // else
  794. // {
  795. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  796. // }
  797. //
  798. //
  799. //
  800. // });
  801. // });
  802. //
  803. //
  804. //
  805. //
  806. //
  807. //
  808. // // [self refresh_total];
  809. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  810. // // NSLog(self.btnselect.titleLabel.text);
  811. // // if(self.btnselect.titleLabel.text)
  812. //}
  813. //#pragma mark - MODEL cell delegate
  814. //-(void) returnQTY:(int)qty
  815. //{
  816. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  817. //
  818. // int count=[[item_json valueForKey:@"count"] intValue];
  819. //
  820. // if(count==qty)
  821. // return;
  822. // [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  823. // double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  824. // // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  825. // [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  826. // self.content_arr[indexPath.row]= item_json;
  827. // // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  828. // [self refresh_total];
  829. // // self.total+=(unit_price*qty-sub_total);
  830. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  831. //
  832. //
  833. //}
  834. - (IBAction)OnCancelOrderClicked:(id)sender {
  835. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Cancel Order?" message:@"Canceled order cannot be edit anymore." preferredStyle:UIAlertControllerStyleAlert];
  836. //block代码块取代了delegate
  837. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  838. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  839. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"];
  840. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  841. NSDictionary* return_json = [iSalesNetwork cancel_Order:nil order_code:appDelegate.order_code];
  842. dispatch_async(dispatch_get_main_queue(), ^{
  843. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  844. if([[return_json valueForKey:@"result"] intValue]==2)
  845. {
  846. //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  847. {
  848. appDelegate.order_code= nil;
  849. appDelegate.user_type = 0;
  850. appDelegate.customerInfo = nil;
  851. appDelegate.contact_id = nil;
  852. appDelegate.order_customer_id = nil;
  853. [appDelegate SetSo:nil];
  854. appDelegate.cart_count=0;
  855. [appDelegate update_count_mark];
  856. }
  857. //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  858. //[self ReloadData];
  859. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  860. // // appDelegate.order_code = nil;
  861. //
  862. // [appDelegate closeOrder];
  863. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  864. [((MainViewController*)appDelegate.main_vc) switchToHome];
  865. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  866. // {
  867. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  868. // }
  869. }
  870. else
  871. {
  872. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  873. }
  874. });
  875. });
  876. }];
  877. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  878. NSLog(@"No");
  879. }];
  880. [alertControl addAction:actionOne];
  881. [alertControl addAction:alertthree];
  882. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  883. [self presentViewController:alertControl animated:YES completion:nil];
  884. NSLog(@"%@",self.edit_select_arr);
  885. }
  886. #pragma mark - commoneditor controller delegate
  887. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  888. {
  889. // [self reload_data];
  890. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  891. }
  892. #pragma mark - Table view data source
  893. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  894. {
  895. NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  896. NSString* notes =[item_json valueForKey:@"note"];
  897. if(notes.length>0)
  898. {
  899. return 146;
  900. }
  901. else
  902. return 120;
  903. }
  904. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  905. //{
  906. // return 0;
  907. //}
  908. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  909. //{
  910. // return 0;
  911. //}
  912. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  913. //{
  914. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  915. // return myView;
  916. //
  917. //}
  918. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  919. //{
  920. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  921. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  922. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  923. //// titleLabel.textColor=[UIColor whiteColor];
  924. //// titleLabel.backgroundColor = [UIColor clearColor];
  925. //// if(section==0)
  926. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  927. //// else
  928. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  929. //// [titleLabel sizeToFit];
  930. //// [myView addSubview:titleLabel];
  931. ////
  932. // return myView;
  933. //}
  934. //
  935. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  936. // if(section==0)
  937. // return nil;
  938. // else
  939. // return @"detail section";
  940. //}
  941. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  942. {
  943. return 1;
  944. }
  945. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  946. {
  947. return 40;
  948. }
  949. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  950. {
  951. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  952. if(value==nil)
  953. value=@"";
  954. unsigned long color = strtoul([value UTF8String],0,16);
  955. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  956. // myView.backgroundColor = UIColorFromRGB(0x996633);
  957. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  958. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  959. myView.layer.shadowOffset = CGSizeMake(0, 0);
  960. myView.layer.shadowOpacity = 0.5;
  961. myView.layer.shadowRadius = 2.0;
  962. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 5.5, 90, 22)];
  963. solabel.textColor=UIColorFromRGB(color);
  964. solabel.backgroundColor = [UIColor clearColor];
  965. solabel.text=NSLocalizedString(@"Description", nil);
  966. [solabel sizeToFit];
  967. [myView addSubview:solabel];
  968. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(320, 5.5, 90, 22)];
  969. contactlabel.textColor=UIColorFromRGB(color);
  970. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  971. contactlabel.backgroundColor = [UIColor clearColor];
  972. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  973. [contactlabel sizeToFit];
  974. [myView addSubview:contactlabel];
  975. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(470, 5.5, 90, 22)];
  976. modellabel.textColor=UIColorFromRGB(color);
  977. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  978. modellabel.backgroundColor = [UIColor clearColor];
  979. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  980. [modellabel sizeToFit];
  981. [myView addSubview:modellabel];
  982. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(640, 5.5, 90, 22)];
  983. pricelabel.textColor=UIColorFromRGB(color);
  984. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  985. pricelabel.backgroundColor = [UIColor clearColor];
  986. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  987. [pricelabel sizeToFit];
  988. [myView addSubview:pricelabel];
  989. //
  990. return myView;
  991. }
  992. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  993. {
  994. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  995. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  996. return count;
  997. }
  998. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  999. {
  1000. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1001. // if(tableView==self.itemListTable)
  1002. // {
  1003. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1004. NSString *CellIdentifier = @"CartItemCell";
  1005. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1006. NSDictionary * item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1007. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1008. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1009. NSString* notes = [item_json valueForKey:@"note"];
  1010. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  1011. cell.noprice = noprice;
  1012. cell.enable_longpress = true;
  1013. cell.bundle_item=combine_json;
  1014. NSString* img_url = [item_json valueForKey:@"img_url"];
  1015. NSString* description = [item_json valueForKey:@"description"];
  1016. // NSString* identifier = [item_json valueForKey:@"identifier"];
  1017. // NSString* attribute = [item_json valueForKey:@"attribute"];
  1018. // NSString* currency = [item_json valueForKey:@"currency"];
  1019. int count =[[item_json valueForKey:@"count"] intValue];
  1020. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  1021. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1022. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  1023. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  1024. NSString* product_id = [item_json valueForKey:@"product_id"];
  1025. // handle no such model
  1026. if(product_id.length==0)
  1027. cell.labelNoSuchModel.hidden=false;
  1028. else
  1029. cell.labelNoSuchModel.hidden=true;
  1030. // discount = 5.0;
  1031. cell.discount = discount;
  1032. CGRect frame = cell.frame;
  1033. if(notes.length>0)
  1034. {
  1035. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  1036. frame.size.height = 146;
  1037. }
  1038. else
  1039. {
  1040. cell.labelNotes.text = nil;
  1041. frame.size.height = 120;
  1042. }
  1043. // cell.frame = frame;
  1044. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  1045. if(isfree)
  1046. {
  1047. cell.labelOldPrice.hidden = false;
  1048. cell.labelOldPrice.textColor = [UIColor redColor];
  1049. cell.labelOldPrice.text=@"Free";
  1050. cell.labelOldPrice.hideline = true;
  1051. cell.labelDiscount.hidden = true;
  1052. }
  1053. else
  1054. {
  1055. cell.labelOldPrice.textColor = [UIColor blackColor];
  1056. cell.labelOldPrice.hideline = false;
  1057. if(discount==0)
  1058. {
  1059. cell.labelOldPrice.hidden = true;
  1060. cell.labelDiscount.hidden = true;
  1061. }
  1062. else
  1063. {
  1064. cell.labelOldPrice.hidden = false;
  1065. cell.labelDiscount.hidden = false;
  1066. }
  1067. }
  1068. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  1069. {
  1070. NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1071. // int count=[[item_json valueForKey:@"count"] intValue];
  1072. // if(count==qty)
  1073. // return;
  1074. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  1075. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  1076. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  1077. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  1078. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  1079. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1080. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  1081. self.content_arr[indexPath.row]= item_json;
  1082. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1083. [self refresh_total];
  1084. };
  1085. // cell.delegate=self;
  1086. // cell.from=indexPath;
  1087. cell.unit_price = unitprice;
  1088. // cell.labelAttribute.text = attribute;
  1089. // cell.labelCurrency.text = currency;
  1090. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  1091. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  1092. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  1093. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1094. {
  1095. }
  1096. else
  1097. {
  1098. oldprice=nil;
  1099. newprice=nil;
  1100. newunitprice=nil;
  1101. }
  1102. cell.labelDiscount.text = discountstr;
  1103. cell.labelOldPrice.text = oldprice;
  1104. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  1105. cell.labelDescription.text = description;
  1106. // cell.labelIdentifier.text = identifier;
  1107. if(noprice&&unitprice==0.0)
  1108. {
  1109. cell.labelPrice.text = @"No Price";
  1110. cell.labelUnitPrice.text = @"No Price";
  1111. }
  1112. else
  1113. {
  1114. cell.labelPrice.text = newprice;
  1115. cell.labelUnitPrice.text = newunitprice;
  1116. }
  1117. bool check = [[item_json valueForKey:@"check"] boolValue];
  1118. if(check)
  1119. {
  1120. cell.img_checkmark.hidden=false;
  1121. // [item_json setValue:@"0" forKey:@"check"];
  1122. }
  1123. else
  1124. {
  1125. // [item_json setValue:@"1" forKey:@"check"];
  1126. cell.img_checkmark.hidden=true;
  1127. }
  1128. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  1129. cell.cart_id = cart_item_id;
  1130. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  1131. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  1132. else
  1133. [cell init_Stepper:1 max:9999 min:1 value:count];
  1134. [cell set_Count:count];
  1135. [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1136. NSString* file_name=[img_url lastPathComponent];
  1137. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1138. if(img_data!=nil)
  1139. {
  1140. UIImage * img =[UIImage imageWithData:img_data];
  1141. [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1142. }
  1143. else
  1144. {
  1145. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1146. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1147. dispatch_async(dispatch_get_main_queue(), ^{
  1148. if(downloadimg_data!=nil)
  1149. {
  1150. [iSalesDB cache_img:downloadimg_data :file_name ];
  1151. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1152. [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1153. }
  1154. else
  1155. {
  1156. [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1157. }
  1158. });
  1159. });
  1160. }
  1161. cell.backgroundColor = [UIColor whiteColor];
  1162. if(self.itemListTable.editing)
  1163. {
  1164. cell.editCount.enabled = false;
  1165. cell.stepper.hidden=true;
  1166. }
  1167. else
  1168. {
  1169. cell.editCount.enabled=true;
  1170. cell.stepper.hidden=false;
  1171. }
  1172. return cell;
  1173. // }
  1174. // else
  1175. // {
  1176. // NSString *CellIdentifier = @"OrderInfoListItem";
  1177. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1178. // return cell;
  1179. // }
  1180. }
  1181. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  1182. {
  1183. if(!self.itemListTable.editing)
  1184. return;
  1185. NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1186. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1187. if ([self.edit_select_arr containsObject:cart_item_id])
  1188. {
  1189. [self.edit_select_arr removeObject:cart_item_id];
  1190. }
  1191. }
  1192. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1193. {
  1194. NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1195. if(self.itemListTable.editing)
  1196. {
  1197. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1198. if (![self.edit_select_arr containsObject:cart_item_id]) {
  1199. [self.edit_select_arr addObject:cart_item_id];
  1200. }
  1201. return;
  1202. }
  1203. // no checkmark support anymore for cart
  1204. return;
  1205. ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  1206. cell.selected = false;
  1207. // self.dirty = true;
  1208. bool check = [[item_json valueForKey:@"check"] boolValue];
  1209. if(check)
  1210. {
  1211. [item_json setValue:@"false" forKey:@"check"];
  1212. cell.img_checkmark.hidden=true;
  1213. [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  1214. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1215. // self.total-=totalprice;
  1216. }
  1217. else
  1218. {
  1219. [item_json setValue:@"true" forKey:@"check"];
  1220. cell.img_checkmark.hidden=false;
  1221. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1222. // self.total+=totalprice;
  1223. }
  1224. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1225. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1226. NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  1227. dispatch_async(dispatch_get_main_queue(), ^{
  1228. if([[check_json valueForKey:@"result"] intValue]==2)
  1229. {
  1230. if([item_json[@"check"] boolValue]==false)
  1231. item_json[@"check"]= @"false";
  1232. else
  1233. item_json[@"check"]= @"true";
  1234. self.content_arr[indexPath.row] = item_json;
  1235. //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1236. [self reload_container_getdata:false];
  1237. }
  1238. else
  1239. {
  1240. [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  1241. }
  1242. });
  1243. });
  1244. //debug
  1245. //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1246. [self refresh_total];
  1247. //self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  1248. }
  1249. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1250. if(self.itemListTable.editing)
  1251. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  1252. else
  1253. return UITableViewCellEditingStyleDelete;
  1254. }
  1255. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1256. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1257. {
  1258. // 添加一个删除按钮
  1259. self.indexPath=indexPath;
  1260. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1261. NSLog(@"delete click");
  1262. //[self.itemListTable setEditing:false animated:YES];
  1263. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from cart?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1264. alert.tag = ALERT_DEL;
  1265. // alert.
  1266. [alert show];
  1267. }];
  1268. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1269. UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1270. NSLog(@"Wishlist click");
  1271. NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1272. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  1273. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1274. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1275. NSDictionary* return_json = [iSalesNetwork move_cart2wish:cart_item_id ];
  1276. dispatch_async(dispatch_get_main_queue(), ^{
  1277. if([[return_json valueForKey:@"result"] intValue]==2)
  1278. {
  1279. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1280. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  1281. for(int i=0;i<self.content_arr.count;i++)
  1282. {
  1283. NSDictionary* obj_json = self.content_arr[i];
  1284. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  1285. if([_id isEqualToString:cart_item_id])
  1286. {
  1287. [self.content_arr removeObjectAtIndex:i];
  1288. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  1289. appDelegate.cart_count--;
  1290. [appDelegate update_count_mark];
  1291. [self refresh_total];
  1292. }
  1293. }
  1294. // if(self.WatchlistBlock!=nil)
  1295. // {
  1296. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1297. //
  1298. //
  1299. // CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  1300. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1301. // iv.image = img;
  1302. // // [self.contentView addSubview:iv];
  1303. // self.WatchlistBlock(iv);
  1304. //
  1305. // }
  1306. }
  1307. else
  1308. {
  1309. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  1310. }
  1311. });
  1312. });
  1313. }];
  1314. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  1315. // 添加一个编辑按钮
  1316. UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1317. NSLog(@"edit click");
  1318. UIViewController* parentvc=self;
  1319. EditModelPriceViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  1320. NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1321. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1322. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1323. vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1324. // vc.delegate = parentvc.self;
  1325. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1326. vc.onSetValue = ^(double price,double discount){
  1327. bool bmodify=false;
  1328. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  1329. bmodify=true;
  1330. NSString* notes = [item_json valueForKey:@"note"];
  1331. if(notes.length==0)
  1332. notes=@"";
  1333. if(bmodify)
  1334. {
  1335. if([notes isEqualToString:@""])
  1336. notes=@"PRICE MODIFIED";
  1337. NSRange range;
  1338. range = [notes rangeOfString:@"PRICE MODIFIED"];
  1339. if (range.location != NSNotFound) {
  1340. }else{
  1341. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  1342. }
  1343. }
  1344. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Update Price"];
  1345. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1346. NSDictionary* cart_json = nil;
  1347. cart_json = [iSalesNetwork cart_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]] price:price discount:discount notes:notes];
  1348. dispatch_async(dispatch_get_main_queue(), ^{
  1349. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1350. if([[cart_json valueForKey:@"result"] intValue]==2)
  1351. {
  1352. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1353. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1354. [item_json setValue:notes forKey:@"note"];
  1355. self.content_arr[indexPath.row ] = item_json;
  1356. tableView.editing = false;
  1357. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1358. }
  1359. else
  1360. {
  1361. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1362. }
  1363. });
  1364. });
  1365. // [self reload_data];//[main_vc checklogin:true];
  1366. };
  1367. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1368. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1369. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1370. [parentvc presentViewController:navi animated:YES completion:^{
  1371. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1372. NSLog(@"EditModelPriceViewController present.........");
  1373. // self.btop = false;
  1374. // <#code#>
  1375. }];
  1376. // [self.itemListTable setEditing:false animated:YES];
  1377. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1378. }];
  1379. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  1380. // // 添加一个更多按钮
  1381. //
  1382. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1383. //
  1384. // NSLog(@点击了更多);
  1385. //
  1386. //
  1387. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1388. //
  1389. // }];
  1390. //
  1391. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  1392. //
  1393. // 将设置好的按钮放到数组中返回
  1394. // UITableViewRowAction *freeRowAction = nil;
  1395. //
  1396. //
  1397. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1398. //
  1399. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1400. //
  1401. // if(!isfree)
  1402. // {
  1403. //
  1404. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1405. //
  1406. // NSLog(@"free click");
  1407. //
  1408. //
  1409. //
  1410. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away confirm", nil) message:NSLocalizedString(@"Are you sure make this model free?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1411. // alert.tag = ALERT_SET_FREE;
  1412. // // alert.
  1413. // [alert show];
  1414. // }];
  1415. // }
  1416. // else
  1417. // {
  1418. //
  1419. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1420. //
  1421. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Restore free model confirm", nil) message:NSLocalizedString(@"Are you sure restore free model?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1422. // alert.tag = ALERT_RESTORE_FREE;
  1423. // // alert.
  1424. // [alert show];
  1425. // }];
  1426. // }
  1427. //
  1428. //
  1429. //
  1430. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  1431. UITableViewRowAction *noteRowAction = nil;
  1432. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1433. noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1434. NSLog(@"item note click");
  1435. UIViewController* parentvc=self;
  1436. ItemNotesViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  1437. NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1438. vc.onSaveNote=^(NSString* notes){
  1439. [item_json setValue:notes forKey:@"note"];
  1440. self.content_arr[indexPath.row ] = item_json;
  1441. tableView.editing = false;
  1442. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1443. };
  1444. vc.notes=[item_json valueForKey:@"note"];
  1445. vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1446. // vc.delegate = parentvc.self;
  1447. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1448. // vc.onSetValue = ^(){
  1449. // [self reload_data];//[main_vc checklogin:true];
  1450. // };
  1451. //
  1452. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1453. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1454. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1455. [parentvc presentViewController:navi animated:YES completion:^{
  1456. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1457. NSLog(@"EditModelPriceViewController present.........");
  1458. // self.btop = false;
  1459. // <#code#>
  1460. }];
  1461. // [self.itemListTable setEditing:false animated:YES];
  1462. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1463. }];
  1464. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  1465. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1466. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1467. {
  1468. NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]
  1469. NSString* product_id = [item_json valueForKey:@"product_id"];
  1470. NSMutableArray* arr=[@[] mutableCopy];
  1471. if(product_id.length>0)
  1472. [arr addObject:noteRowAction];
  1473. [arr addObject:deleteRowAction];
  1474. if(product_id.length>0)
  1475. [arr addObject:addWatchAction];
  1476. if(appDelegate.can_set_cart_price && product_id.length>0)
  1477. {
  1478. [arr addObject:editRowAction];
  1479. // [arr addObject:freeRowAction];
  1480. }
  1481. return arr;
  1482. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  1483. }
  1484. else
  1485. return @[deleteRowAction,addWatchAction];
  1486. }
  1487. - (void)tableView:(UITableView *)tableView
  1488. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  1489. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1490. //
  1491. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1492. //
  1493. //
  1494. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1495. //
  1496. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  1497. //
  1498. // dispatch_async(dispatch_get_main_queue(), ^{
  1499. //
  1500. //
  1501. //
  1502. // if(cart_json!=nil)
  1503. // {
  1504. //
  1505. // [self reload_data];
  1506. // }
  1507. //
  1508. // });
  1509. // });
  1510. // sqlite3* db = [ApexMobileDB get_db];
  1511. // NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  1512. // [ApexMobileDB execSql:sql db:db];
  1513. // sqlite3_close(db);
  1514. //
  1515. // [self.data.pagedata removeObjectAtIndex:indexPath.row];
  1516. //
  1517. // [tableView reloadData];
  1518. }
  1519. #pragma mark - UIAlertViewDelegate
  1520. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1521. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1522. {
  1523. if(alertView.tag==ALERT_DEL)
  1524. {
  1525. if(buttonIndex!=alertView.cancelButtonIndex)
  1526. {
  1527. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1528. NSMutableDictionary * item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  1529. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1530. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1531. NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  1532. dispatch_async(dispatch_get_main_queue(), ^{
  1533. if([[cart_json valueForKey:@"result"] intValue]==2)
  1534. {
  1535. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1536. for(int i=0;i<self.content_arr.count;i++)
  1537. {
  1538. NSDictionary* obj_json = self.content_arr[i];
  1539. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  1540. if([_id isEqualToString:ids])
  1541. {
  1542. [self.content_arr removeObjectAtIndex:i];
  1543. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  1544. break;
  1545. // appDelegate.cart_count--;
  1546. // [appDelegate update_count_mark];
  1547. }
  1548. }
  1549. [self.itemListTable reloadData];
  1550. [self refresh_total];
  1551. // [self reload_data];
  1552. }
  1553. else
  1554. {
  1555. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  1556. }
  1557. });
  1558. });
  1559. }
  1560. }
  1561. else if(alertView.tag==ALERT_FREE)
  1562. {
  1563. if(buttonIndex==alertView.cancelButtonIndex)
  1564. {
  1565. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1566. // NSString * string = [checked componentsJoinedByString:@","];
  1567. // [params setValue:string forKey:@"cart2Checkbox"];
  1568. CreateOrderViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
  1569. orderinfoVC.disable_dropdown_refresh=true;
  1570. orderinfoVC.url_type = URL_REMOTE;
  1571. orderinfoVC.request_url=URL_CARTDELIVERY;
  1572. orderinfoVC.params = params;
  1573. orderinfoVC.delegate=self;
  1574. [self.navigationController pushViewController:orderinfoVC animated:true];
  1575. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  1576. //
  1577. //
  1578. //
  1579. //
  1580. //
  1581. // navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  1582. // [self presentViewController:navi animated:YES completion:^{
  1583. //
  1584. // NSLog(@"CreateOrderViewController present.........");
  1585. //
  1586. // // self.btop = false;
  1587. // // <#code#>
  1588. // }];
  1589. }
  1590. }
  1591. else if(alertView.tag==ALERT_SET_FREE)
  1592. {
  1593. if(buttonIndex!=alertView.cancelButtonIndex)
  1594. {
  1595. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1596. NSMutableDictionary * item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  1597. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1598. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1599. NSDictionary* cart_json = [iSalesNetwork cart_setFree:ids isfree:true];
  1600. dispatch_async(dispatch_get_main_queue(), ^{
  1601. if([[cart_json valueForKey:@"result"] intValue]==2)
  1602. {
  1603. [self reload_data];
  1604. }
  1605. else
  1606. {
  1607. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Set Free Model" controller:self] ;
  1608. }
  1609. });
  1610. });
  1611. }
  1612. }
  1613. else if(alertView.tag==ALERT_RESTORE_FREE)
  1614. {
  1615. if(buttonIndex!=alertView.cancelButtonIndex)
  1616. {
  1617. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1618. NSMutableDictionary * item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  1619. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1620. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1621. NSDictionary* cart_json = [iSalesNetwork cart_setFree:ids isfree:false];
  1622. dispatch_async(dispatch_get_main_queue(), ^{
  1623. if([[cart_json valueForKey:@"result"] intValue]==2)
  1624. {
  1625. [self reload_data];
  1626. }
  1627. else
  1628. {
  1629. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Restore Model Price" controller:self] ;
  1630. }
  1631. });
  1632. });
  1633. }
  1634. }
  1635. }
  1636. #pragma mark - Support scanner
  1637. -(void) onDecodedData:(NSString*) value
  1638. {
  1639. // return;
  1640. [self addtocart:value];
  1641. }
  1642. //-(void) neworder
  1643. //{
  1644. //
  1645. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  1646. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1647. //
  1648. // NSDictionary* return_json = [iSalesNetwork new_Order];
  1649. //
  1650. // dispatch_async(dispatch_get_main_queue(), ^{
  1651. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1652. //
  1653. //
  1654. // if([[return_json valueForKey:@"result"] intValue]==2)
  1655. // {
  1656. // int result=[[return_json valueForKey:@"result"] intValue];
  1657. // if(result==2)
  1658. // {
  1659. // //successed.
  1660. //
  1661. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  1662. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1663. // appDelegate.order_code = order_code;
  1664. //
  1665. //
  1666. // [self addtocart];
  1667. //
  1668. //
  1669. // // [self ReloadData];
  1670. //
  1671. //
  1672. // // if(self.shopCartBlock!=nil)
  1673. // // {
  1674. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1675. // //
  1676. // //
  1677. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1678. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1679. // // iv.image = img;
  1680. // // // [self.contentView addSubview:iv];
  1681. // // self.shopCartBlock(iv);
  1682. // //
  1683. // // }
  1684. //
  1685. // }
  1686. // }
  1687. // else
  1688. // {
  1689. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1690. // }
  1691. //
  1692. //
  1693. //
  1694. //
  1695. // });
  1696. // });
  1697. //}
  1698. -(void) addtocart:(NSString*) modelname
  1699. {
  1700. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1701. NSDictionary* return_json = [iSalesNetwork add_toCart_byName: modelname];
  1702. dispatch_async(dispatch_get_main_queue(), ^{
  1703. if([[return_json valueForKey:@"result"] intValue]==2)
  1704. {
  1705. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  1706. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  1707. // bool isnew=false;
  1708. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1709. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  1710. for(int i=0;i<self.content_arr.count;i++)
  1711. {
  1712. NSDictionary* obj_json = self.content_arr[i];
  1713. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  1714. if([_id isEqualToString:item_id])
  1715. {
  1716. // self.content_arr[i] = newitem;
  1717. [self.content_arr removeObjectAtIndex:i];
  1718. break;
  1719. // [self.content_arr removeObjectAtIndex:i];
  1720. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  1721. // appDelegate.cart_count--;
  1722. // [appDelegate update_count_mark];
  1723. }
  1724. }
  1725. [self.content_arr insertObject:newitem atIndex:0];
  1726. [self.itemListTable reloadData];
  1727. [self refresh_total];
  1728. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1729. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1730. }
  1731. else
  1732. {
  1733. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  1734. }
  1735. });
  1736. });
  1737. }
  1738. @end