CartViewController.m 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493
  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 "RANetwork.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. #import "SortItemViewController.h"
  23. #import "SortButton.h"
  24. #import "NotificationNameCenter.h"
  25. #import "Singleton.h"
  26. #import "JKMessageBoxController.h"
  27. #import "RAPDFViewController.h"
  28. #ifdef BACKORDER_PROCESS
  29. #import "RAOrderEditorViewController.h"
  30. #endif
  31. #define ALERT_FREE 1024
  32. #define ALERT_DEL 1025
  33. #define ALERT_SET_FREE 1026
  34. #define ALERT_RESTORE_FREE 1027
  35. @interface CartViewController ()
  36. {
  37. CGRect cancelButtonFrame;
  38. }
  39. @property (nonatomic,strong) SortItemViewController *sortItemController;
  40. @property (nonatomic,assign) int sortIndex;
  41. @property (nonatomic,strong) SortButton *sortButton;
  42. @property (strong, nonatomic) IBOutlet UIButton *placeOrderButton;
  43. @property (strong, nonatomic) IBOutlet UIButton *cancelOrderButton;
  44. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  45. @property (strong, nonatomic) IBOutlet UIButton *emailButton;
  46. @property (strong, nonatomic) IBOutlet UIButton *printButton;
  47. @property (nonatomic,assign) BOOL currentOrderIsMerged;
  48. @property (nonatomic,strong) DefaultTableHeaderView *cartIndicatorBar;
  49. @property (nonatomic,assign) BOOL back_order_flag;
  50. @property (nonatomic,strong) NSDictionary *cart_json;
  51. @property (nonatomic,copy) NSString *print_url;
  52. @property (nonatomic,assign) BOOL available;///<所有Model均有库存,才能Place Order。
  53. @end
  54. @implementation CartViewController
  55. - (NSOperationQueue *)dataOperationQueue {
  56. if (!_dataOperationQueue) {
  57. _dataOperationQueue = [[NSOperationQueue alloc] init];
  58. _dataOperationQueue.maxConcurrentOperationCount = 1;
  59. }
  60. return _dataOperationQueue;
  61. }
  62. - (void)dealloc {
  63. [[NSNotificationCenter defaultCenter] removeObserver:self];
  64. }
  65. -(void) logout
  66. {
  67. [super logout];
  68. [self.content_arr removeAllObjects];
  69. self.cart_json = nil;
  70. }
  71. - (IBAction)OnEditSelectClick:(id)sender {
  72. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  73. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  74. if(count==0)
  75. {
  76. [RAUtils message_alert:@"No item in the cart" title:@"Cart" controller:self] ;
  77. return;
  78. }
  79. for(int i=0;i<count;i++)
  80. {
  81. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  82. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  83. }
  84. NSString * ids = [arr_ids componentsJoinedByString:@","];
  85. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  86. //block代码块取代了delegate
  87. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  88. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  89. //block代码块取代了delegate
  90. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  91. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
  92. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  93. NSDictionary* cart_json = [RANetwork cart_remove:ids];
  94. dispatch_async(dispatch_get_main_queue(), ^{
  95. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  96. if([[cart_json valueForKey:@"result"] intValue]==2)
  97. {
  98. [self end_edit];
  99. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  100. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  101. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  102. }
  103. else
  104. {
  105. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  106. }
  107. });
  108. });
  109. }];
  110. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  111. DebugLog(@"No");
  112. }];
  113. [alertControl addAction:actionOne];
  114. [alertControl addAction:alertthree];
  115. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  116. [self presentViewController:alertControl animated:YES completion:nil];
  117. DebugLog(@"%@",self.edit_select_arr);
  118. }];
  119. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  120. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Move Models To Wish List"];
  121. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  122. NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  123. dispatch_async(dispatch_get_main_queue(), ^{
  124. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  125. if([[cart_json valueForKey:@"result"] intValue]==2)
  126. {
  127. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  128. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  129. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  130. [self end_edit];
  131. }
  132. else
  133. {
  134. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  135. }
  136. });
  137. });
  138. }];
  139. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  140. DebugLog(@"No");
  141. }];
  142. [alertControl addAction:actionOne];
  143. [alertControl addAction:actionTwo];
  144. [alertControl addAction:alertthree];
  145. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  146. [self presentViewController:alertControl animated:YES completion:nil];
  147. DebugLog(@"%@",self.edit_select_arr);
  148. }
  149. - (IBAction)onEditAddWishClick:(id)sender {
  150. if(self.edit_select_arr.count==0)
  151. {
  152. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Move To Wish List" controller:self] ;
  153. return;
  154. }
  155. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  156. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  157. // //block代码块取代了delegate
  158. //
  159. //
  160. //
  161. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  162. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Move Models To Wish List"];
  163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  164. NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  165. dispatch_async(dispatch_get_main_queue(), ^{
  166. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  167. if([[cart_json valueForKey:@"result"] intValue]==2)
  168. {
  169. [self end_edit];
  170. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  171. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  172. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  173. }
  174. else
  175. {
  176. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  177. }
  178. });
  179. });
  180. // }];
  181. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  182. // DebugLog(@"No");
  183. // }];
  184. // [alertControl addAction:actionOne];
  185. //
  186. // [alertControl addAction:alertthree];
  187. //
  188. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  189. //
  190. //
  191. // [self presentViewController:alertControl animated:YES completion:nil];
  192. //
  193. // DebugLog(@"%@",self.edit_select_arr);
  194. }
  195. - (IBAction)onEditDelClick:(id)sender {
  196. if(self.edit_select_arr.count==0)
  197. {
  198. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Delete From Cart" controller:self] ;
  199. return;
  200. }
  201. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  202. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  203. //block代码块取代了delegate
  204. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  205. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
  206. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  207. NSDictionary* cart_json = [RANetwork cart_remove:ids];
  208. dispatch_async(dispatch_get_main_queue(), ^{
  209. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  210. if([[cart_json valueForKey:@"result"] intValue]==2)
  211. {
  212. [self end_edit];
  213. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  214. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  215. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  216. }
  217. else
  218. {
  219. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  220. }
  221. });
  222. });
  223. }];
  224. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  225. DebugLog(@"No");
  226. }];
  227. [alertControl addAction:actionOne];
  228. [alertControl addAction:alertthree];
  229. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  230. [self presentViewController:alertControl animated:YES completion:nil];
  231. DebugLog(@"%@",self.edit_select_arr);
  232. }
  233. - (IBAction)onEndEditClick:(id)sender {
  234. [self end_edit];
  235. }
  236. -(void)begin_edit
  237. {
  238. self.toolpanel.hidden = true;
  239. self.toolbar.hidden = false;
  240. // DebugLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  241. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  242. if ( UIInterfaceOrientationIsPortrait(orientation))
  243. self.cartItemView.frame = CGRectMake(0,40,768,840);
  244. else
  245. self.cartItemView.frame = CGRectMake(0,40,1024,584);
  246. [self.itemListTable setEditing:true animated:YES];
  247. [self.itemListTable reloadData];
  248. }
  249. -(void) end_edit
  250. {
  251. self.toolpanel.hidden=false;
  252. self.toolbar.hidden=true;
  253. // DebugLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  254. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  255. if ( UIInterfaceOrientationIsPortrait(orientation))
  256. self.cartItemView.frame = CGRectMake(0,40,768,760);
  257. else
  258. self.cartItemView.frame = CGRectMake(0,40,1024,508);
  259. [self.itemListTable setEditing:false animated:YES];
  260. [self.edit_select_arr removeAllObjects];
  261. [self.itemListTable reloadData];
  262. // [self reload_data];
  263. }
  264. - (IBAction)onEditClick:(id)sender {
  265. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  266. //
  267. // [appDelegate test_onDecodedDataResult:@"4400022"];
  268. //
  269. //
  270. // return;
  271. [self begin_edit];
  272. }
  273. -(void) reload_container_getdata:(bool) update_data
  274. {
  275. [super reload_container_getdata:update_data];
  276. if(update_data)
  277. [self reload_data];
  278. else
  279. {
  280. [self.itemListTable reloadData];
  281. [self refresh_total];
  282. }
  283. }
  284. -(void) showHidePrice
  285. {
  286. [self reload_container_getdata:false];
  287. // [self refresh_total];
  288. }
  289. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  290. {
  291. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  292. if (self) {
  293. // Custom initialization
  294. }
  295. return self;
  296. }
  297. - (IBAction)imgbtnClick:(UIButton *)sender {
  298. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  299. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  300. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  301. NSDictionary * item_json = nil;
  302. if (self.back_order_flag) {
  303. item_json = [self itemJsonAtIndexPath:indexPath];
  304. } else {
  305. item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  306. }
  307. NSString* product_id = [item_json valueForKey:@"product_id"];
  308. NSString *name = [item_json valueForKey:@"model"];
  309. int is_rate = [item_json[@"is_rate"] intValue];
  310. if(is_rate==1)
  311. return;
  312. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  313. // dvc
  314. dvc.product_id=product_id;
  315. dvc.category_id=nil;
  316. dvc.ispush=true;
  317. dvc.model_name = name;
  318. [dvc reload];
  319. [self.navigationController pushViewController:dvc animated:true];
  320. }
  321. -(void)viewWillLayoutSubviews
  322. {
  323. // if(self.showDetail==true)
  324. // {
  325. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  326. // int width=175;
  327. // // int height;
  328. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  329. // {
  330. // width = 370;
  331. // // height = 400;
  332. // }
  333. // else
  334. // {
  335. // // height = 300;
  336. // width = 175;
  337. // }
  338. //
  339. //
  340. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  341. //
  342. // self.collectionview.frame=frame;
  343. //
  344. //
  345. //
  346. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  347. // self.detailView.frame = framedetail;
  348. // }
  349. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  350. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  351. }
  352. - (void)viewWillAppear:(BOOL)animated
  353. {
  354. [super viewWillAppear:animated];
  355. // print 13 email 19 cancel 24 place order
  356. // Shop 权限检查
  357. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  358. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  359. if (![Singleton sharedInstance].permissions_edit_order) {
  360. CGRect frame0 = self.cancelOrderButton.frame;
  361. CGRect frame1 = self.placeOrderButton.frame;
  362. CGRect frame2 = self.emailButton.frame;
  363. CGRect frame3 = self.printButton.frame;
  364. CGFloat x = CGRectGetMaxX(frame1) - frame0.size.width;
  365. frame0.origin.x = x;
  366. self.cancelOrderButton.frame = frame0;
  367. x -= 19 + CGRectGetWidth(frame2);
  368. frame2.origin.x = x;
  369. self.emailButton.frame = frame2;
  370. x -= 13 + CGRectGetWidth(frame3);
  371. frame3.origin.x = x;
  372. self.printButton.frame = frame3;
  373. self.placeOrderButton.hidden = YES;
  374. } else {
  375. self.placeOrderButton.hidden = NO;
  376. CGSize size = cancelButtonFrame.size;
  377. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  378. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  379. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  380. CGRect frame2 = self.emailButton.frame;
  381. x -= 19 + CGRectGetWidth(frame2);
  382. frame2.origin.x = x;
  383. self.emailButton.frame = frame2;
  384. CGRect frame3 = self.printButton.frame;
  385. x -= 13 + CGRectGetWidth(frame3);
  386. frame3.origin.x = x;
  387. self.printButton.frame = frame3;
  388. }
  389. } else {
  390. // self.cancelOrderButton.frame = cancelButtonFrame;
  391. self.placeOrderButton.hidden = NO;
  392. CGSize size = cancelButtonFrame.size;
  393. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  394. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  395. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  396. CGRect frame2 = self.emailButton.frame;
  397. x -= 19 + CGRectGetWidth(frame2);
  398. frame2.origin.x = x;
  399. self.emailButton.frame = frame2;
  400. CGRect frame3 = self.printButton.frame;
  401. x -= 13 + CGRectGetWidth(frame3);
  402. frame3.origin.x = x;
  403. self.printButton.frame = frame3;
  404. }
  405. #ifdef OFFLINE_MODE
  406. // 离线隐藏Email
  407. self.emailButton.hidden = appDelegate.offline_mode;
  408. // 离线隐藏Print
  409. self.printButton.hidden = appDelegate.offline_mode;
  410. #endif
  411. // [self reload_data]; // 视图没及时刷新
  412. // UIApplication * app = [UIApplication sharedApplication];
  413. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  414. // if(appDelegate.bLogin==false)
  415. // {
  416. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  417. // // loginvc.delegate = self;
  418. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  419. //
  420. // loginvc.returnValue = ^(bool blogin){
  421. //
  422. //
  423. // UIApplication * app = [UIApplication sharedApplication];
  424. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  425. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  426. //
  427. // [main_vc checklogin:true];
  428. //
  429. //// [self reload_data];
  430. //
  431. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  432. //
  433. // };
  434. //
  435. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  436. //
  437. //
  438. //
  439. //
  440. //
  441. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  442. //
  443. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  444. // [self presentViewController:navi animated:YES completion:^{
  445. //
  446. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  447. //
  448. // DebugLog(@"CreateOrderViewController present.........");
  449. //
  450. // // self.btop = false;
  451. // // <#code#>
  452. // }];
  453. // }
  454. // else
  455. // {
  456. // [self reload_data];
  457. //// self.total = 0;
  458. // }
  459. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  460. }
  461. - (void)checkProductAvailable:(NSArray *)contents {
  462. if (contents == nil) {
  463. self.available = NO;
  464. return;
  465. }
  466. [contents enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  467. if ([obj isKindOfClass:[NSDictionary class]]) {
  468. NSDictionary *item_json = (NSDictionary *)obj;
  469. BOOL isAvailable = ![[item_json valueForKey:@"is_out_of_stock"] boolValue];
  470. self.available = self.available && isAvailable;
  471. }
  472. }];
  473. }
  474. - (void)clearContent {
  475. dispatch_async(dispatch_get_main_queue(), ^{
  476. self.freejson = nil;
  477. self.notes = nil;
  478. self.content_arr = nil;
  479. self.currentOrderIsMerged = nil;
  480. self.cart_json = nil;
  481. [Singleton sharedInstance].currentOrderIsMerged = NO;
  482. self.print_url = nil;
  483. [self checkProductAvailable:self.content_arr];
  484. [self refresh_total];
  485. [self.itemListTable reloadData];
  486. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  487. appDelegate.cart_count = 0;
  488. [appDelegate update_count_mark];
  489. });
  490. }
  491. -(void) operation_reload_data
  492. {
  493. if (self.dataOperationQueue.operationCount > 1) {
  494. return;
  495. }
  496. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  497. if (appDelegate.order_code == nil || appDelegate.order_code.length == 0) {
  498. [self clearContent];
  499. return;
  500. }
  501. __weak typeof(self) weakself = self;
  502. dispatch_async(dispatch_get_main_queue(), ^{
  503. if(weakself.isrefreshing)
  504. return;
  505. weakself.available = YES;
  506. weakself.itemListTable.hidden = true;
  507. weakself.label_net_err.hidden=true;
  508. weakself.isrefreshing=true;
  509. // [self.content_data removeAllObjects];
  510. // [self.itemListTable reloadData];
  511. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  512. //
  513. // [reF endRefreshing];
  514. //
  515. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  516. weakself.mum.center = weakself.view.center;
  517. weakself.mum.hidden = YES;
  518. // [self.mum startAnimating];
  519. DebugLog(@"reloading...");
  520. UIAlertView *loadingView = [RAUtils waiting_alert:@"Please Wait" title:@"Loading"];
  521. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  522. DebugLog(@"BEGIN LOAD CART");
  523. NSDictionary* cart_json = [RANetwork request_Cart:weakself.sortIndex];
  524. dispatch_async(dispatch_get_main_queue(), ^{
  525. //
  526. // [self.mum stopAnimating];
  527. [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  528. // self.content_data = [cart_json mutableCopy];
  529. #ifdef BACKORDER_PROCESS
  530. weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  531. #else
  532. weakself.back_order_flag = NO;
  533. #endif
  534. if (!weakself.back_order_flag) {
  535. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  536. weakself.notes = [cart_json valueForKey:@"general_note"];
  537. weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  538. weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  539. [Singleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  540. [weakself.itemListTable reloadData];
  541. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  542. [weakself checkProductAvailable:weakself.content_arr];
  543. [weakself refresh_total];
  544. } else {
  545. // v1.94
  546. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  547. weakself.notes = [cart_json valueForKey:@"general_note"];
  548. weakself.cart_json = cart_json;
  549. [weakself.itemListTable reloadData];
  550. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  551. [weakself checkProductAvailable:weakself.content_arr];
  552. }
  553. int result=[[cart_json valueForKey:@"result"] intValue];
  554. if (weakself.dataOperationQueue.operationCount > 1) {
  555. weakself.isrefreshing=false;
  556. return;
  557. }
  558. if(result==2||result==1||result==0)
  559. {
  560. [weakself.edit_select_arr removeAllObjects];
  561. weakself.itemListTable.hidden = false;
  562. // UIApplication * app = [UIApplication sharedApplication];
  563. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  564. // appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  565. weakself.itemListTable.hidden=false;
  566. if(weakself.onFinishLoad)
  567. weakself.onFinishLoad();
  568. }
  569. else
  570. if(result==RESULT_NET_ERROR)
  571. {
  572. weakself.label_net_err.hidden=false;
  573. weakself.itemListTable.hidden=true;
  574. }
  575. else
  576. {
  577. if(result!=1)
  578. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  579. }
  580. weakself.isrefreshing=false;
  581. DebugLog(@"FINISH LOAD CART");
  582. });
  583. });
  584. });
  585. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  586. }
  587. - (void) reload_data {
  588. __weak typeof(self) weakself = self;
  589. self.currentOrderIsMerged = NO;
  590. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  591. if (weakself) {
  592. __strong typeof(weakself) strongself = weakself;
  593. [strongself operation_reload_data];
  594. }
  595. }];
  596. [self.dataOperationQueue addOperation:operation];
  597. }
  598. -(void)manually_refresh
  599. {
  600. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  601. if(self.isrefreshing)
  602. {
  603. [reF endRefreshing];
  604. return;
  605. }
  606. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  607. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  608. // DebugLog(@"refresh!!!!!!!!");
  609. }
  610. -(void) ReloadData
  611. {
  612. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  613. [reF endRefreshing];
  614. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  615. [self reload_data];
  616. }
  617. - (void)viewDidLayoutSubviews {
  618. [super viewDidLayoutSubviews];
  619. [self layoutCartIndicatorBar];
  620. }
  621. - (DefaultTableHeaderView *)setupCartIndicatorBar {
  622. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  623. if(value==nil)
  624. value=@"";
  625. unsigned long color = strtoul([value UTF8String],0,16);
  626. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.itemListTable.bounds.size.width, 40)];
  627. // myView.backgroundColor = UIColorFromRGB(0x996633);
  628. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  629. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  630. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  631. myView.layer.shadowOffset = CGSizeMake(0, 0);
  632. myView.layer.shadowOpacity = 0.5;
  633. myView.layer.shadowRadius = 2.0;
  634. self.sortButton.tag = 5678 + 0;
  635. [myView addSubview:self.sortButton];
  636. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 9, 90, 22)];
  637. solabel.tag = 5678 + 1;
  638. solabel.textColor=UIColorFromRGB(color);
  639. solabel.backgroundColor = [UIColor clearColor];
  640. solabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  641. solabel.text=NSLocalizedString(@"Description", nil);
  642. [solabel sizeToFit];
  643. [myView addSubview:solabel];
  644. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  645. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  646. contactlabel.tag = 5678 + 2;
  647. contactlabel.textColor=UIColorFromRGB(color);
  648. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  649. contactlabel.backgroundColor = [UIColor clearColor];
  650. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  651. [contactlabel sizeToFit];
  652. [myView addSubview:contactlabel];
  653. x = self.itemListTable.bounds.size.width - (768 - 470);
  654. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  655. modellabel.tag = 5678 + 3;
  656. modellabel.textColor=UIColorFromRGB(color);
  657. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  658. modellabel.backgroundColor = [UIColor clearColor];
  659. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  660. [modellabel sizeToFit];
  661. [myView addSubview:modellabel];
  662. x = self.itemListTable.bounds.size.width - (768 - 640);
  663. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  664. pricelabel.tag = 5678 + 4;
  665. pricelabel.textColor=UIColorFromRGB(color);
  666. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  667. pricelabel.backgroundColor = [UIColor clearColor];
  668. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  669. [pricelabel sizeToFit];
  670. [myView addSubview:pricelabel];
  671. return myView;
  672. }
  673. - (void)layoutCartIndicatorBar {
  674. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  675. UILabel *solabel = [self.cartIndicatorBar viewWithTag:5678 + 1];
  676. [solabel sizeToFit];
  677. UILabel *contactlabel = [self.cartIndicatorBar viewWithTag:5678 + 2];
  678. contactlabel.frame = CGRectMake(x, 9, 90, 22);
  679. [contactlabel sizeToFit];
  680. x = self.itemListTable.bounds.size.width - (768 - 470);
  681. UILabel *modellabel = [self.cartIndicatorBar viewWithTag:5678 + 3];
  682. modellabel.frame = CGRectMake(x, 9, 90, 22);
  683. [modellabel sizeToFit];
  684. x = self.itemListTable.bounds.size.width - (768 - 640);
  685. UILabel *pricelabel = [self.cartIndicatorBar viewWithTag:5678 + 4];
  686. pricelabel.frame = CGRectMake(x, 9, 90, 22);
  687. [pricelabel sizeToFit];
  688. }
  689. - (void)viewDidLoad
  690. {
  691. [super viewDidLoad];
  692. self.edit_select_arr= [[NSMutableArray alloc] init];
  693. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  694. self.label_net_err.layer.borderWidth = 2.0;
  695. self.label_net_err.layer.cornerRadius=15;
  696. self.label_net_err.layer.masksToBounds=true;
  697. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(priceTypeChanged:) name:Change_Price_Type_Notification object:nil];
  698. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  699. // tap.minimumPressDuration = 0.8; //定义按的时间
  700. [self.label_net_err addGestureRecognizer:tap];
  701. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  702. ref.tag = 200 ;
  703. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  704. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  705. // ref.hidden = true;
  706. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  707. [self.itemListTable addSubview:ref];
  708. self.sortIndex = 0;
  709. self.currentOrderIsMerged = NO;
  710. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  711. self.toolpanel.layer.masksToBounds = false;
  712. //添加四个边阴影
  713. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  714. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  715. self.toolpanel.layer.shadowOpacity = 0.5;
  716. self.toolpanel.layer.shadowRadius = 2.0;
  717. cancelButtonFrame = self.cancelOrderButton.frame;
  718. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  719. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  720. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  721. // // self.detailTable.sectionHeaderHeight = 0.0001;
  722. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  723. // Do any additional setup after loading the view.
  724. self.cartIndicatorBar = [self setupCartIndicatorBar];
  725. [self.view addSubview:self.cartIndicatorBar];
  726. }
  727. //-(void)SelectOrder:(NSString *)orderid
  728. //{
  729. //// self.editOrderID.text=orderid;
  730. //// self.btnAddToOrder.enabled = true;
  731. //}
  732. - (void)didReceiveMemoryWarning
  733. {
  734. [super didReceiveMemoryWarning];
  735. // Dispose of any resources that can be recreated.
  736. }
  737. //- (IBAction)stepperAction:(UIStepper *)sender {
  738. //
  739. //
  740. //}
  741. - (IBAction)onContinueShoppingClick:(id)sender {
  742. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  743. [appDelegate switchToPreviousVC];
  744. }
  745. - (IBAction)onPlaceOrder:(UIButton *)sender {
  746. [self placeOrder];
  747. }
  748. -(void)placeOrder
  749. {
  750. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  751. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  752. if (![Singleton sharedInstance].permissions_edit_order) {
  753. return;
  754. }
  755. // if (!self.available) {
  756. //
  757. // [RAUtils message_alert:@"There are some products is not available" title:@"Warning" controller:self];
  758. // return;
  759. // }
  760. }
  761. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  762. bool have_free = false;
  763. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  764. if(count==0)
  765. {
  766. [RAUtils message_alert:@"Add some model first." title:@"Cart Is Empty." controller:self] ;
  767. return;
  768. }
  769. for(int i=0;i<count;i++)
  770. {
  771. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  772. // bool check = [[item_json valueForKey:@"check"] boolValue];
  773. NSString* product_id = [item_json valueForKey:@"product_id"];
  774. // if(check)
  775. // {
  776. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  777. //
  778. // }
  779. if(product_id.length==0)
  780. {
  781. [RAUtils message_alert:@"Some models in cart does not exist, you must remove them before place order." title:@"No Such Model" controller:self] ;
  782. return;
  783. }
  784. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  785. if(is_free)
  786. have_free=true;
  787. }
  788. // disable for debug
  789. // if(checked.count==0)
  790. // {
  791. // [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Place Order" controller:self] ;
  792. // return;
  793. // }
  794. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  795. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  796. /* FREE GIVE AWAY
  797. int free_count = [[self.freejson valueForKey:@"count"]intValue];
  798. for(int ic=free_count-1;ic>=0;ic--)
  799. {
  800. float compare_price = [[self.freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  801. if(self.total>=compare_price && !have_free&&appDelegate.can_set_cart_price)
  802. {
  803. 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];
  804. alert.tag = ALERT_FREE;
  805. [alert show];
  806. return;
  807. }
  808. }
  809. */
  810. #ifdef BACKORDER_PROCESS
  811. if (self.back_order_flag) {
  812. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  813. [params setObject:@(0) forKey:@"step"];
  814. RAOrderEditorViewController *orderEditorVC = [self.storyboard instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  815. orderEditorVC.disable_dropdown_refresh=true;
  816. orderEditorVC.url_type = URL_REMOTE;
  817. orderEditorVC.request_url=URL_CARTDELIVERY;
  818. orderEditorVC.params = params;
  819. orderEditorVC.delegate=self;
  820. [self.navigationController pushViewController:orderEditorVC animated:true];
  821. }
  822. else
  823. #endif
  824. {
  825. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  826. // NSString * string = [checked componentsJoinedByString:@","];
  827. // [params setValue:string forKey:@"cart2Checkbox"];
  828. CreateOrderViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
  829. orderinfoVC.disable_dropdown_refresh=true;
  830. orderinfoVC.url_type = URL_REMOTE;
  831. orderinfoVC.request_url=URL_CARTDELIVERY;
  832. orderinfoVC.params = params;
  833. orderinfoVC.delegate=self;
  834. //
  835. // if(checked.count==count)
  836. // {
  837. // orderinfoVC.have_tail = true
  838. // }
  839. [self.navigationController pushViewController:orderinfoVC animated:true];
  840. }
  841. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  842. //
  843. //
  844. //
  845. //
  846. //
  847. // navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  848. // [self presentViewController:navi animated:YES completion:^{
  849. //
  850. // DebugLog(@"CreateOrderViewController present.........");
  851. //
  852. // // self.btop = false;
  853. // // <#code#>
  854. // }];
  855. }
  856. //- (IBAction)onCommit:(UIButton *)sender {
  857. // ;
  858. //}
  859. //- (IBAction)CreateOrder:(id)sender {
  860. //}
  861. //- (IBAction)AddToOrder:(id)sender {
  862. //}
  863. //- (IBAction)ChooseOrder:(id)sender {
  864. //
  865. // OrderListViewController * orderlistVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  866. // // orderlistVC.delegate = self;
  867. // orderlistVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  868. // [self presentViewController:orderlistVC animated:YES completion:^{
  869. //
  870. // DebugLog(@"login.........");
  871. // // <#code#>
  872. // }];
  873. //}
  874. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  875. {
  876. //
  877. // CommonGridViewController * orderlistVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  878. // orderlistVC.delegate = self;
  879. // orderlistVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  880. // [self presentViewController:orderlistVC animated:YES completion:^{
  881. //
  882. // DebugLog(@"textFieldShouldBeginEditing.........");
  883. // // <#code#>
  884. // }];
  885. return NO;
  886. }
  887. - (IBAction)onDelete:(UIButton *)sender {
  888. return ;
  889. NSMutableArray* checked = [[NSMutableArray alloc] init];
  890. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  891. for(int i=0;i<count;i++)
  892. {
  893. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  894. bool check = [[item_json valueForKey:@"check"] boolValue];
  895. if(check)
  896. {
  897. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  898. }
  899. }
  900. // disable for debug
  901. if(checked.count==0)
  902. return;
  903. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  904. NSString * string = [checked componentsJoinedByString:@","];
  905. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  906. NSDictionary* cart_json = [RANetwork cart_remove:string];
  907. dispatch_async(dispatch_get_main_queue(), ^{
  908. if([[cart_json valueForKey:@"result"] intValue]==2)
  909. {
  910. [self reload_data];
  911. }
  912. else
  913. {
  914. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  915. }
  916. });
  917. });
  918. }
  919. -(void)refresh_total
  920. {
  921. self.total=0;
  922. self.total_carton=0;
  923. self.total_cuft=0;
  924. self.total_weight=0;
  925. self.total_QTY=0;
  926. self.total_item=0;
  927. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  928. for(int i=0;i<count;i++)
  929. {
  930. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  931. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  932. if(bcheck)
  933. {
  934. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  935. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  936. int count=[[item_json valueForKey:@"count"] intValue];
  937. double totalprice =count*unitprice * (1.0-discount/100.0);
  938. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  939. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  940. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  941. int item_count=1;
  942. int item_qty=1;
  943. NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  944. double dprice=0;
  945. if(bundle_item!=nil)
  946. {
  947. // int citem=0;
  948. int bcount=[[bundle_item valueForKey:@"count"] intValue];
  949. for(int bc=0;bc<bcount;bc++)
  950. {
  951. NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  952. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  953. // citem+= modulus;
  954. item_count+=1;
  955. item_qty+=modulus;
  956. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  957. dprice+= uprice*modulus*count;
  958. }
  959. }
  960. totalprice+= dprice;
  961. self.total+=totalprice;
  962. self.total_cuft+=cuft;
  963. self.total_carton+=carton;
  964. self.total_weight+=weight;
  965. self.total_item+=item_count;
  966. self.total_QTY+=(item_qty)*count;
  967. }
  968. }
  969. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  970. NSString* subtotal = [NSString stringWithFormat:@"$%.2f",self.total];
  971. NSString* subcuft = [NSString stringWithFormat:@"%.2f ft³",self.total_cuft];
  972. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  973. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  974. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  975. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  976. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  977. {
  978. }
  979. else
  980. {
  981. subtotal=nil;
  982. }
  983. self.labelTotal.text=subtotal;
  984. self.label_cuft.text=subcuft;
  985. self.label_carton.text=subcarton;
  986. self.label_weight.text=subweight;
  987. self.label_items.text = subitems;
  988. self.label_qty.text = subqty;
  989. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  990. }
  991. - (IBAction)onEditGeneralNotes:(id)sender {
  992. UIViewController* parentvc=self;
  993. CartGeneralNotesViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  994. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  995. vc.notes=self.notes;
  996. // vc.delegate = parentvc.self;
  997. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  998. vc.onSetValue = ^(NSString* notes){
  999. self.notes = notes;
  1000. [self refresh_total];
  1001. };
  1002. //
  1003. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1004. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1005. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1006. [parentvc presentViewController:navi animated:YES completion:^{
  1007. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1008. DebugLog(@"EditModelPriceViewController present.........");
  1009. // self.btop = false;
  1010. // <#code#>
  1011. }];
  1012. }
  1013. //- (IBAction)onSelectAll:(UIButton *)sender {
  1014. //
  1015. //
  1016. // NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  1017. //
  1018. //
  1019. //
  1020. //
  1021. //
  1022. //
  1023. // if([self.btnselect.titleLabel.text isEqualToString:@"Select all"])
  1024. // {
  1025. //
  1026. // long count = self.content_arr.count;// [[self.content_data valueForKey:@"count"] intValue];
  1027. // for(int i=0;i<count;i++)
  1028. // {
  1029. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1030. // if(![[item_json valueForKey:@"check"] boolValue])
  1031. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1032. //
  1033. // }
  1034. // [self.btnselect setTitle: @"Deselect all" forState: UIControlStateNormal];
  1035. // }
  1036. // else
  1037. // {
  1038. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1039. // for(int i=0;i<count;i++)
  1040. // {
  1041. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1042. // if([[item_json valueForKey:@"check"] boolValue])
  1043. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1044. //
  1045. // }
  1046. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  1047. // }
  1048. //
  1049. // NSString * ids = [arr_ids componentsJoinedByString:@","];
  1050. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1051. //
  1052. //
  1053. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  1054. //
  1055. // dispatch_async(dispatch_get_main_queue(), ^{
  1056. //
  1057. //
  1058. //
  1059. // if([[check_json valueForKey:@"result"] intValue]==2)
  1060. // {
  1061. //
  1062. // long count = self.content_arr.count;
  1063. // for(int i=0;i<count;i++)
  1064. // {
  1065. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];
  1066. // if([item_json[@"check"] boolValue])
  1067. // item_json[@"check"]= @"false";
  1068. // else
  1069. // item_json[@"check"]= @"true";
  1070. //
  1071. // self.content_arr[i] = item_json;
  1072. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  1073. // }
  1074. //
  1075. // [self reload_container_getdata:false];
  1076. //
  1077. // // [self reload_data];
  1078. // }
  1079. // else
  1080. // {
  1081. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  1082. // }
  1083. //
  1084. //
  1085. //
  1086. // });
  1087. // });
  1088. //
  1089. //
  1090. //
  1091. //
  1092. //
  1093. //
  1094. // // [self refresh_total];
  1095. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  1096. // // DebugLog(self.btnselect.titleLabel.text);
  1097. // // if(self.btnselect.titleLabel.text)
  1098. //}
  1099. //#pragma mark - MODEL cell delegate
  1100. //-(void) returnQTY:(int)qty
  1101. //{
  1102. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1103. //
  1104. // int count=[[item_json valueForKey:@"count"] intValue];
  1105. //
  1106. // if(count==qty)
  1107. // return;
  1108. // [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  1109. // double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  1110. // // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1111. // [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  1112. // self.content_arr[indexPath.row]= item_json;
  1113. // // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1114. // [self refresh_total];
  1115. // // self.total+=(unit_price*qty-sub_total);
  1116. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  1117. //
  1118. //
  1119. //}
  1120. - (IBAction)OnCancelOrderClicked:(id)sender {
  1121. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Cancel Order" message:@"Are you sure to cancel the order in cart ?" preferredStyle:UIAlertControllerStyleAlert];
  1122. //block代码块取代了delegate
  1123. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1124. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1125. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"];
  1126. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1127. NSDictionary* return_json = [RANetwork cancel_Order:nil order_code:appDelegate.order_code];
  1128. dispatch_async(dispatch_get_main_queue(), ^{
  1129. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1130. if([[return_json valueForKey:@"result"] intValue]==2)
  1131. {
  1132. //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1133. {
  1134. appDelegate.order_code= nil;
  1135. //appDelegate.user_type = 0;
  1136. appDelegate.customerInfo = nil;
  1137. appDelegate.contact_id = nil;
  1138. appDelegate.order_customer_id = nil;
  1139. [appDelegate SetSo:nil];
  1140. appDelegate.cart_count=0;
  1141. [appDelegate update_count_mark];
  1142. }
  1143. //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1144. //[self ReloadData];
  1145. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1146. // // appDelegate.order_code = nil;
  1147. //
  1148. // [appDelegate closeOrder];
  1149. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1150. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1151. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1152. // {
  1153. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1154. // }
  1155. }
  1156. else
  1157. {
  1158. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1159. }
  1160. });
  1161. });
  1162. }];
  1163. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1164. DebugLog(@"No");
  1165. }];
  1166. [alertControl addAction:actionOne];
  1167. [alertControl addAction:alertthree];
  1168. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1169. [self presentViewController:alertControl animated:YES completion:nil];
  1170. DebugLog(@"%@",self.edit_select_arr);
  1171. }
  1172. #pragma mark - commoneditor controller delegate
  1173. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1174. {
  1175. // [self reload_data];
  1176. if([value[@"commitorder_logout"] boolValue])
  1177. [self logout];
  1178. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1179. }
  1180. #pragma mark - Table view data source
  1181. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1182. {
  1183. NSDictionary * item_json = nil;
  1184. if (self.back_order_flag) {
  1185. item_json = [self itemJsonAtIndexPath:indexPath];
  1186. } else {
  1187. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1188. }
  1189. NSString* notes =[item_json valueForKey:@"note"];
  1190. if(notes.length>0)
  1191. {
  1192. return 146;
  1193. }
  1194. else
  1195. return 120;
  1196. }
  1197. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1198. //{
  1199. // return 0;
  1200. //}
  1201. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1202. //{
  1203. // return 0;
  1204. //}
  1205. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1206. //{
  1207. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1208. // return myView;
  1209. //
  1210. //}
  1211. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1212. //{
  1213. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1214. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1215. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1216. //// titleLabel.textColor=[UIColor whiteColor];
  1217. //// titleLabel.backgroundColor = [UIColor clearColor];
  1218. //// if(section==0)
  1219. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1220. //// else
  1221. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1222. //// [titleLabel sizeToFit];
  1223. //// [myView addSubview:titleLabel];
  1224. ////
  1225. // return myView;
  1226. //}
  1227. //
  1228. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1229. // if(section==0)
  1230. // return nil;
  1231. // else
  1232. // return @"detail section";
  1233. //}
  1234. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1235. {
  1236. if (self.back_order_flag) {
  1237. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  1238. } else {
  1239. return 1;
  1240. }
  1241. }
  1242. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1243. {
  1244. if (self.back_order_flag) {
  1245. return 50;
  1246. } else {
  1247. return 0;
  1248. }
  1249. }
  1250. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1251. {
  1252. if (self.back_order_flag) {
  1253. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  1254. // UILabel *title_lb = [header viewWithTag:8520];
  1255. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  1256. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  1257. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1258. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  1259. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1260. title_lb.font = [UIFont systemFontOfSize:25.0f];
  1261. [header addSubview:title_lb];
  1262. title_lb.text = [self titleForSection:section];
  1263. return header;
  1264. } else {
  1265. return nil;
  1266. }
  1267. }
  1268. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1269. {
  1270. if (self.back_order_flag) {
  1271. return [self itemCountInSection:section];
  1272. } else {
  1273. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1274. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1275. return count;
  1276. }
  1277. }
  1278. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1279. {
  1280. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1281. // if(tableView==self.itemListTable)
  1282. // {
  1283. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1284. NSString *CellIdentifier = @"CartItemCell";
  1285. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1286. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1287. if (self.back_order_flag) {
  1288. item_json = [self itemJsonAtIndexPath:indexPath];
  1289. } else {
  1290. item_json = self.content_arr[indexPath.row];
  1291. }
  1292. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1293. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  1294. if (cell.masterBtn != nil) {
  1295. if (master_json == nil) {
  1296. cell.masterBtn.hidden = YES;
  1297. } else{
  1298. cell.masterBtn.hidden = NO;
  1299. cell.master_items = master_json;
  1300. }
  1301. }
  1302. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1303. NSString* notes = [item_json valueForKey:@"note"];
  1304. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  1305. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  1306. cell.noprice = noprice;
  1307. cell.enable_longpress = true;
  1308. cell.bundle_item=combine_json;
  1309. NSString* img_url = [item_json valueForKey:@"img_url"];
  1310. NSString* description = [item_json valueForKey:@"description"];
  1311. // NSString* identifier = [item_json valueForKey:@"identifier"];
  1312. // NSString* attribute = [item_json valueForKey:@"attribute"];
  1313. // NSString* currency = [item_json valueForKey:@"currency"];
  1314. int count =[[item_json valueForKey:@"count"] intValue];
  1315. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  1316. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1317. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  1318. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  1319. NSString* product_id = [item_json valueForKey:@"product_id"];
  1320. // handle no such model
  1321. if(product_id.length==0)
  1322. cell.labelNoSuchModel.hidden=false;
  1323. else
  1324. cell.labelNoSuchModel.hidden=true;
  1325. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1326. if (!is_out_of_stock) {
  1327. cell.labelOutOfStock.hidden = YES;
  1328. } else {
  1329. cell.labelOutOfStock.hidden = NO;
  1330. }
  1331. // } else {
  1332. // cell.labelOutOfStock.hidden = YES;
  1333. // }
  1334. // discount = 5.0;
  1335. cell.discount = discount;
  1336. CGRect frame = cell.frame;
  1337. if(notes.length>0)
  1338. {
  1339. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  1340. frame.size.height = 146;
  1341. }
  1342. else
  1343. {
  1344. cell.labelNotes.text = nil;
  1345. frame.size.height = 120;
  1346. }
  1347. // cell.frame = frame;
  1348. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  1349. if(isfree)
  1350. {
  1351. cell.labelOldPrice.hidden = false;
  1352. cell.labelOldPrice.textColor = [UIColor redColor];
  1353. cell.labelOldPrice.text=@"Free";
  1354. cell.labelOldPrice.hideline = true;
  1355. cell.labelDiscount.hidden = true;
  1356. }
  1357. else
  1358. {
  1359. cell.labelOldPrice.textColor = [UIColor blackColor];
  1360. cell.labelOldPrice.hideline = false;
  1361. if(discount==0)
  1362. {
  1363. cell.labelOldPrice.hidden = true;
  1364. cell.labelDiscount.hidden = true;
  1365. }
  1366. else
  1367. {
  1368. cell.labelOldPrice.hidden = false;
  1369. cell.labelDiscount.hidden = false;
  1370. }
  1371. }
  1372. __weak typeof(self) weakSelf = self;
  1373. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  1374. {
  1375. NSMutableDictionary * item_json = nil;
  1376. if (weakSelf.back_order_flag) {
  1377. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  1378. } else {
  1379. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1380. }
  1381. // int count=[[item_json valueForKey:@"count"] intValue];
  1382. // if(count==qty)
  1383. // return;
  1384. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  1385. return ;
  1386. }
  1387. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  1388. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  1389. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  1390. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  1391. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  1392. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1393. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  1394. if (weakSelf.back_order_flag) {
  1395. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  1396. } else {
  1397. weakSelf.content_arr[indexPath.row]= item_json;
  1398. }
  1399. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1400. [weakSelf refresh_total];
  1401. };
  1402. // cell.delegate=self;
  1403. // cell.from=indexPath;
  1404. cell.unit_price = unitprice;
  1405. // cell.labelAttribute.text = attribute;
  1406. // cell.labelCurrency.text = currency;
  1407. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  1408. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  1409. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  1410. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1411. {
  1412. }
  1413. else
  1414. {
  1415. oldprice=nil;
  1416. newprice=nil;
  1417. newunitprice=nil;
  1418. }
  1419. cell.labelDiscount.text = discountstr;
  1420. cell.labelOldPrice.text = oldprice;
  1421. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  1422. cell.labelDescription.text = description;
  1423. // cell.labelIdentifier.text = identifier;
  1424. if(noprice&&unitprice==0.0)
  1425. {
  1426. cell.labelPrice.text = @"No Price";
  1427. cell.labelUnitPrice.text = @"No Price";
  1428. }
  1429. else
  1430. {
  1431. cell.labelPrice.text = newprice;
  1432. cell.labelUnitPrice.text = newunitprice;
  1433. }
  1434. bool check = [[item_json valueForKey:@"check"] boolValue];
  1435. if(check)
  1436. {
  1437. cell.img_checkmark.hidden=false;
  1438. // [item_json setValue:@"0" forKey:@"check"];
  1439. }
  1440. else
  1441. {
  1442. // [item_json setValue:@"1" forKey:@"check"];
  1443. cell.img_checkmark.hidden=true;
  1444. }
  1445. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  1446. cell.cart_id = cart_item_id;
  1447. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  1448. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  1449. else
  1450. [cell init_Stepper:1 max:9999 min:1 value:count];
  1451. [cell set_Count:count];
  1452. // Button 设置了大小约束,Size就不会随内容变化
  1453. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  1454. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  1455. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  1456. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  1457. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  1458. if (![cell.imageName isEqualToString:img_url]) {
  1459. cell.imageName = img_url;
  1460. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1461. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1462. NSString* file_name=[img_url lastPathComponent];
  1463. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1464. if(img_data!=nil)
  1465. {
  1466. UIImage * img =[UIImage imageWithData:img_data];
  1467. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1468. [cell.btnImage setImage:img forState:UIControlStateNormal];
  1469. }
  1470. else
  1471. {
  1472. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1473. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1474. dispatch_async(dispatch_get_main_queue(), ^{
  1475. if(downloadimg_data!=nil)
  1476. {
  1477. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1478. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1479. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1480. [cell.btnImage setImage:img forState:UIControlStateNormal];
  1481. }
  1482. else
  1483. {
  1484. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1485. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1486. }
  1487. });
  1488. });
  1489. }
  1490. }
  1491. cell.backgroundColor = [UIColor whiteColor];
  1492. if(self.itemListTable.editing)
  1493. {
  1494. cell.editCount.enabled = false;
  1495. cell.stepper.hidden=true;
  1496. }
  1497. else
  1498. {
  1499. cell.editCount.enabled=true;
  1500. cell.stepper.hidden=false;
  1501. }
  1502. return cell;
  1503. // }
  1504. // else
  1505. // {
  1506. // NSString *CellIdentifier = @"OrderInfoListItem";
  1507. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1508. // return cell;
  1509. // }
  1510. }
  1511. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  1512. {
  1513. if(!self.itemListTable.editing)
  1514. return;
  1515. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1516. NSMutableDictionary * item_json = nil;
  1517. if (self.back_order_flag) {
  1518. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1519. } else {
  1520. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1521. }
  1522. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1523. if ([self.edit_select_arr containsObject:cart_item_id])
  1524. {
  1525. [self.edit_select_arr removeObject:cart_item_id];
  1526. }
  1527. }
  1528. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1529. {
  1530. NSMutableDictionary * item_json = nil;
  1531. if (self.back_order_flag) {
  1532. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1533. } else {
  1534. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1535. }
  1536. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1537. if(self.itemListTable.editing)
  1538. {
  1539. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1540. if (![self.edit_select_arr containsObject:cart_item_id]) {
  1541. [self.edit_select_arr addObject:cart_item_id];
  1542. }
  1543. return;
  1544. }
  1545. // no checkmark support anymore for cart
  1546. return;
  1547. // ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  1548. //
  1549. //
  1550. // cell.selected = false;
  1551. // // self.dirty = true;
  1552. //
  1553. //
  1554. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1555. // if(check)
  1556. // {
  1557. // [item_json setValue:@"false" forKey:@"check"];
  1558. // cell.img_checkmark.hidden=true;
  1559. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  1560. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1561. // // self.total-=totalprice;
  1562. // }
  1563. // else
  1564. // {
  1565. // [item_json setValue:@"true" forKey:@"check"];
  1566. // cell.img_checkmark.hidden=false;
  1567. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1568. // // self.total+=totalprice;
  1569. // }
  1570. //
  1571. //
  1572. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1573. //
  1574. //
  1575. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1576. //
  1577. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  1578. //
  1579. // dispatch_async(dispatch_get_main_queue(), ^{
  1580. //
  1581. //
  1582. //
  1583. // if([[check_json valueForKey:@"result"] intValue]==2)
  1584. // {
  1585. //
  1586. //
  1587. // if([item_json[@"check"] boolValue]==false)
  1588. // item_json[@"check"]= @"false";
  1589. // else
  1590. // item_json[@"check"]= @"true";
  1591. //
  1592. // self.content_arr[indexPath.row] = item_json;
  1593. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1594. //
  1595. //
  1596. // [self reload_container_getdata:false];
  1597. //
  1598. //
  1599. // }
  1600. // else
  1601. // {
  1602. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  1603. // }
  1604. //
  1605. //
  1606. //
  1607. // });
  1608. // });
  1609. //
  1610. // //debug
  1611. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1612. //
  1613. // [self refresh_total];
  1614. //self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  1615. }
  1616. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1617. if(self.itemListTable.editing)
  1618. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  1619. else
  1620. return UITableViewCellEditingStyleDelete;
  1621. }
  1622. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1623. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1624. {
  1625. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1626. // 添加一个删除按钮
  1627. self.indexPath=indexPath;
  1628. NSMutableDictionary * item_json = nil;
  1629. if (self.back_order_flag) {
  1630. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1631. } else {
  1632. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1633. }
  1634. NSString* productID = [item_json valueForKey:@"product_id"];
  1635. BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  1636. __weak typeof(self) weakself = self;
  1637. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1638. DebugLog(@"delete click");
  1639. //[self.itemListTable setEditing:false animated:YES];
  1640. 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];
  1641. alert.tag = ALERT_DEL;
  1642. // alert.
  1643. [alert show];
  1644. }];
  1645. deleteRowAction.backgroundColor = [UIColor redColor];
  1646. UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  1647. {
  1648. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1649. dispatch_async(dispatch_get_global_queue(0,0), ^{
  1650. NSDictionary *dic = [RANetwork notifyModel:productID emailAddr:nil withScreen:ScreenCodeCart];
  1651. dispatch_async(dispatch_get_main_queue(), ^{
  1652. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1653. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  1654. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  1655. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1656. if ([dic valueForKey:@"err_msg"]) {
  1657. msg = [dic valueForKey:@"err_msg"];
  1658. }
  1659. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1660. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1661. }];
  1662. [errorAlertVC addAction:action];
  1663. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1664. } else if (result == RESULT_TRUE){
  1665. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1666. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  1667. [weakself showAddressBoxToEmailProduct:productID];
  1668. }
  1669. });
  1670. });
  1671. };
  1672. }];
  1673. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  1674. UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1675. DebugLog(@"Wishlist click");
  1676. NSMutableDictionary * item_json = nil;
  1677. if (self.back_order_flag) {
  1678. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1679. } else {
  1680. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1681. }
  1682. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  1683. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1684. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1685. // ModelItemCell* cell=[self.itemListTable cellForRowAtIndexPath:indexPath];
  1686. // [cell cancel_setQTY];
  1687. NSDictionary* return_json = [RANetwork move_cart2wish:cart_item_id ];
  1688. dispatch_async(dispatch_get_main_queue(), ^{
  1689. if([[return_json valueForKey:@"result"] intValue]==2)
  1690. {
  1691. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1692. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  1693. for(int i=0;i<self.content_arr.count;i++)
  1694. {
  1695. NSDictionary* obj_json = self.content_arr[i];
  1696. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  1697. if([_id isEqualToString:cart_item_id])
  1698. {
  1699. if (self.back_order_flag) {
  1700. [self updateItemJson:nil atIndexPath:indexPath];
  1701. } else {
  1702. [self.content_arr removeObjectAtIndex:i];
  1703. }
  1704. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  1705. appDelegate.cart_count--;
  1706. [appDelegate update_count_mark];
  1707. [self refresh_total];
  1708. }
  1709. }
  1710. [self.itemListTable reloadData];
  1711. }
  1712. else
  1713. {
  1714. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  1715. }
  1716. });
  1717. });
  1718. }];
  1719. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  1720. // 添加一个编辑按钮
  1721. UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1722. DebugLog(@"edit click");
  1723. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1724. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  1725. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  1726. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1727. [alert dismissViewControllerAnimated:YES completion:nil];
  1728. }];
  1729. [alert addAction:action];
  1730. if (weakself) {
  1731. __strong typeof(weakself) strongself = weakself;
  1732. [strongself presentViewController:alert animated:YES completion:nil];
  1733. }
  1734. return ;
  1735. }
  1736. if ([Singleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  1737. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  1738. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1739. [alert dismissViewControllerAnimated:YES completion:nil];
  1740. }];
  1741. [alert addAction:action];
  1742. if (weakself) {
  1743. __strong typeof(weakself) strongself = weakself;
  1744. [strongself presentViewController:alert animated:YES completion:nil];
  1745. }
  1746. return ;
  1747. }
  1748. }
  1749. UIViewController* parentvc=self;
  1750. EditModelPriceViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  1751. NSMutableDictionary * item_json = nil;
  1752. if (self.back_order_flag) {
  1753. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1754. } else {
  1755. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1756. }
  1757. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1758. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1759. vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1760. // vc.delegate = parentvc.self;
  1761. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1762. vc.onSetValue = ^(double price,double discount){
  1763. bool bmodify=false;
  1764. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  1765. bmodify=true;
  1766. NSString* notes = [item_json valueForKey:@"note"];
  1767. if(notes.length==0)
  1768. notes=@"";
  1769. if(bmodify)
  1770. {
  1771. if([notes isEqualToString:@""])
  1772. notes=@"PRICE MODIFIED";
  1773. NSRange range;
  1774. range = [notes rangeOfString:@"PRICE MODIFIED"];
  1775. if (range.location != NSNotFound) {
  1776. }else{
  1777. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  1778. }
  1779. }
  1780. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Update Price"];
  1781. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1782. NSDictionary* cart_json = nil;
  1783. cart_json = [RANetwork cart_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]] price:price discount:discount notes:notes];
  1784. dispatch_async(dispatch_get_main_queue(), ^{
  1785. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1786. if([[cart_json valueForKey:@"result"] intValue]==2)
  1787. {
  1788. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1789. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1790. [item_json setValue:notes forKey:@"note"];
  1791. if (self.back_order_flag) {
  1792. [self updateItemJson:item_json atIndexPath:indexPath];
  1793. } else {
  1794. self.content_arr[indexPath.row ] = item_json;
  1795. }
  1796. tableView.editing = false;
  1797. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1798. // [self refresh_total];
  1799. [weakself reload_data];
  1800. }
  1801. else
  1802. {
  1803. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1804. }
  1805. });
  1806. });
  1807. // [self reload_data];//[main_vc checklogin:true];
  1808. };
  1809. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1810. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1811. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1812. [parentvc presentViewController:navi animated:YES completion:^{
  1813. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1814. DebugLog(@"EditModelPriceViewController present.........");
  1815. // self.btop = false;
  1816. // <#code#>
  1817. }];
  1818. // [self.itemListTable setEditing:false animated:YES];
  1819. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1820. }];
  1821. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  1822. // // 添加一个更多按钮
  1823. //
  1824. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1825. //
  1826. // DebugLog(@点击了更多);
  1827. //
  1828. //
  1829. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1830. //
  1831. // }];
  1832. //
  1833. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  1834. //
  1835. // 将设置好的按钮放到数组中返回
  1836. // UITableViewRowAction *freeRowAction = nil;
  1837. //
  1838. //
  1839. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1840. //
  1841. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1842. //
  1843. // if(!isfree)
  1844. // {
  1845. //
  1846. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1847. //
  1848. // DebugLog(@"free click");
  1849. //
  1850. //
  1851. //
  1852. // 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];
  1853. // alert.tag = ALERT_SET_FREE;
  1854. // // alert.
  1855. // [alert show];
  1856. // }];
  1857. // }
  1858. // else
  1859. // {
  1860. //
  1861. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1862. //
  1863. // 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];
  1864. // alert.tag = ALERT_RESTORE_FREE;
  1865. // // alert.
  1866. // [alert show];
  1867. // }];
  1868. // }
  1869. //
  1870. //
  1871. //
  1872. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  1873. UITableViewRowAction *noteRowAction = nil;
  1874. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1875. noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1876. DebugLog(@"item note click");
  1877. UIViewController* parentvc=self;
  1878. ItemNotesViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  1879. NSMutableDictionary * item_json = nil;
  1880. if (self.back_order_flag) {
  1881. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1882. } else {
  1883. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1884. }
  1885. vc.onSaveNote=^(NSString* notes){
  1886. [item_json setValue:notes forKey:@"note"];
  1887. if (self.back_order_flag) {
  1888. [self updateItemJson:item_json atIndexPath:indexPath];
  1889. } else {
  1890. self.content_arr[indexPath.row ] = item_json;
  1891. }
  1892. tableView.editing = false;
  1893. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1894. };
  1895. vc.notes=[item_json valueForKey:@"note"];
  1896. vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1897. // vc.delegate = parentvc.self;
  1898. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1899. // vc.onSetValue = ^(){
  1900. // [self reload_data];//[main_vc checklogin:true];
  1901. // };
  1902. //
  1903. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1904. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1905. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1906. [parentvc presentViewController:navi animated:YES completion:^{
  1907. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1908. DebugLog(@"EditModelPriceViewController present.........");
  1909. // self.btop = false;
  1910. // <#code#>
  1911. }];
  1912. // [self.itemListTable setEditing:false animated:YES];
  1913. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1914. }];
  1915. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  1916. UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  1917. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  1918. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  1919. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Move To Back Order"];
  1920. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1921. NSDictionary* return_json = [RANetwork movetobackorder:cart_item_id];
  1922. dispatch_async(dispatch_get_main_queue(), ^{
  1923. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1924. if([[return_json valueForKey:@"result"] intValue]==2) {
  1925. [self reload_data];
  1926. } // if 2
  1927. else {
  1928. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  1929. }
  1930. }); // main
  1931. }); // global
  1932. }];
  1933. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  1934. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1935. {
  1936. NSMutableDictionary * item_json = nil;
  1937. if (self.back_order_flag) {
  1938. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1939. } else {
  1940. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1941. }
  1942. NSString* product_id = [item_json valueForKey:@"product_id"];
  1943. int is_rate = [item_json[@"is_rate"] intValue];
  1944. NSMutableArray* arr=[@[] mutableCopy];
  1945. BOOL condition = outOfStock;
  1946. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1947. #ifdef OFFLINE_MODE
  1948. condition = !appDelegate.offline_mode && outOfStock;
  1949. #endif
  1950. if (condition) {
  1951. [arr addObject:notifyMeAction];
  1952. }
  1953. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  1954. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  1955. if (self.back_order_flag && available) {
  1956. [arr addObject:move2BackAction];
  1957. }
  1958. #endif
  1959. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1960. #ifdef OFFLINE_MODE
  1961. condition = !appDelegate.offline_mode && outOfStock;
  1962. #endif
  1963. if (condition) {
  1964. [arr addObject:notifyMeAction];
  1965. }
  1966. #endif
  1967. if(product_id.length>0)
  1968. [arr addObject:noteRowAction];
  1969. [arr addObject:deleteRowAction];
  1970. if(product_id.length>0&& is_rate==0)
  1971. [arr addObject:addWatchAction];
  1972. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0)
  1973. {
  1974. [arr addObject:editRowAction];
  1975. // [arr addObject:freeRowAction];
  1976. }
  1977. return arr;
  1978. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  1979. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1980. if (appDelegate.customer_type == CustomerTypeStore) {
  1981. return @[notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  1982. } else {
  1983. // normal
  1984. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  1985. NSMutableArray *actionArray = [NSMutableArray array];
  1986. // move to backorder
  1987. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  1988. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  1989. if (self.back_order_flag && available) {
  1990. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  1991. [actionArray addObject:move2BackAction];
  1992. }
  1993. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  1994. // edit price
  1995. NSMutableDictionary * item_json = nil;
  1996. if (self.back_order_flag) {
  1997. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1998. } else {
  1999. item_json = [self.content_arr[indexPath.row] mutableCopy];
  2000. }
  2001. NSString* product_id = [item_json valueForKey:@"product_id"];
  2002. int is_rate = [item_json[@"is_rate"] intValue];
  2003. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  2004. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  2005. [actionArray addObject:editRowAction];
  2006. }
  2007. return actionArray;
  2008. }
  2009. }
  2010. else
  2011. return @[deleteRowAction,addWatchAction];
  2012. }
  2013. - (void)tableView:(UITableView *)tableView
  2014. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  2015. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2016. //
  2017. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2018. //
  2019. //
  2020. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2021. //
  2022. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  2023. //
  2024. // dispatch_async(dispatch_get_main_queue(), ^{
  2025. //
  2026. //
  2027. //
  2028. // if(cart_json!=nil)
  2029. // {
  2030. //
  2031. // [self reload_data];
  2032. // }
  2033. //
  2034. // });
  2035. // });
  2036. // sqlite3* db = [ApexMobileDB get_db];
  2037. // NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  2038. // [ApexMobileDB execSql:sql db:db];
  2039. // [iSalesDB close_db:db];
  2040. //
  2041. // [self.data.pagedata removeObjectAtIndex:indexPath.row];
  2042. //
  2043. // [tableView reloadData];
  2044. }
  2045. #pragma mark - UIAlertViewDelegate
  2046. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  2047. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  2048. {
  2049. if(alertView.tag==ALERT_DEL)
  2050. {
  2051. if(buttonIndex!=alertView.cancelButtonIndex)
  2052. {
  2053. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2054. NSMutableDictionary * item_json = nil;
  2055. if (self.back_order_flag) {
  2056. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2057. } else {
  2058. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2059. }
  2060. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2061. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2062. NSDictionary* cart_json = [RANetwork cart_remove:ids];
  2063. dispatch_async(dispatch_get_main_queue(), ^{
  2064. if([[cart_json valueForKey:@"result"] intValue]==2)
  2065. {
  2066. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2067. if (self.back_order_flag) {
  2068. NSInteger section_count = [self sectionCount];
  2069. for (int i = 0; i < section_count; i++) {
  2070. NSInteger item_count = [self itemCountInSection:i];
  2071. BOOL ready_break = NO;
  2072. for (int j = 0; j < item_count; j++) {
  2073. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2074. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  2075. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2076. if([_id isEqualToString:ids])
  2077. {
  2078. [self updateItemJson:nil atIndexPath:indexPath];
  2079. ready_break = YES;
  2080. break;
  2081. }
  2082. }
  2083. if (ready_break) {
  2084. break;
  2085. }
  2086. }
  2087. } else {
  2088. for(int i=0;i<self.content_arr.count;i++)
  2089. {
  2090. NSDictionary* obj_json = self.content_arr[i];
  2091. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2092. if([_id isEqualToString:ids])
  2093. {
  2094. [self.content_arr removeObjectAtIndex:i];
  2095. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2096. break;
  2097. // appDelegate.cart_count--;
  2098. // [appDelegate update_count_mark];
  2099. }
  2100. }
  2101. }
  2102. [self.itemListTable reloadData];
  2103. [self refresh_total];
  2104. // [self reload_data];
  2105. }
  2106. else
  2107. {
  2108. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  2109. }
  2110. });
  2111. });
  2112. }
  2113. }
  2114. else if(alertView.tag==ALERT_FREE)
  2115. {
  2116. if(buttonIndex==alertView.cancelButtonIndex)
  2117. {
  2118. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2119. // NSString * string = [checked componentsJoinedByString:@","];
  2120. // [params setValue:string forKey:@"cart2Checkbox"];
  2121. CreateOrderViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
  2122. orderinfoVC.disable_dropdown_refresh=true;
  2123. orderinfoVC.url_type = URL_REMOTE;
  2124. orderinfoVC.request_url=URL_CARTDELIVERY;
  2125. orderinfoVC.params = params;
  2126. orderinfoVC.delegate=self;
  2127. [self.navigationController pushViewController:orderinfoVC animated:true];
  2128. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  2129. //
  2130. //
  2131. //
  2132. //
  2133. //
  2134. // navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  2135. // [self presentViewController:navi animated:YES completion:^{
  2136. //
  2137. // DebugLog(@"CreateOrderViewController present.........");
  2138. //
  2139. // // self.btop = false;
  2140. // // <#code#>
  2141. // }];
  2142. }
  2143. }
  2144. else if(alertView.tag==ALERT_SET_FREE)
  2145. {
  2146. if(buttonIndex!=alertView.cancelButtonIndex)
  2147. {
  2148. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2149. NSMutableDictionary * item_json = nil;
  2150. if (self.back_order_flag) {
  2151. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2152. } else {
  2153. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  2154. }
  2155. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2156. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2157. NSDictionary* cart_json = [RANetwork cart_setFree:ids isfree:true];
  2158. dispatch_async(dispatch_get_main_queue(), ^{
  2159. if([[cart_json valueForKey:@"result"] intValue]==2)
  2160. {
  2161. [self reload_data];
  2162. }
  2163. else
  2164. {
  2165. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Set Free Model" controller:self] ;
  2166. }
  2167. });
  2168. });
  2169. }
  2170. }
  2171. else if(alertView.tag==ALERT_RESTORE_FREE)
  2172. {
  2173. if(buttonIndex!=alertView.cancelButtonIndex)
  2174. {
  2175. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2176. NSMutableDictionary * item_json = nil;
  2177. if (self.back_order_flag) {
  2178. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2179. } else {
  2180. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  2181. }
  2182. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2183. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2184. NSDictionary* cart_json = [RANetwork cart_setFree:ids isfree:false];
  2185. dispatch_async(dispatch_get_main_queue(), ^{
  2186. if([[cart_json valueForKey:@"result"] intValue]==2)
  2187. {
  2188. [self reload_data];
  2189. }
  2190. else
  2191. {
  2192. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Restore Model Price" controller:self] ;
  2193. }
  2194. });
  2195. });
  2196. }
  2197. }
  2198. }
  2199. #pragma mark - Support scanner
  2200. -(void) onDecodedData:(NSString*) value
  2201. {
  2202. int cqty=0;
  2203. if (self.back_order_flag) {
  2204. NSInteger section_count = [self sectionCount];
  2205. for (int i = 0; i < section_count; i++) {
  2206. NSInteger item_count = [self itemCountInSection:i];
  2207. for (int j = 0; j < item_count; j++) {
  2208. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2209. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  2210. if([item[@"model"] isEqualToString:value]) {
  2211. cqty=[item[@"count"] intValue];
  2212. }
  2213. }
  2214. }
  2215. } else {
  2216. for(int i=0;i<self.content_arr.count;i++)
  2217. {
  2218. NSDictionary* item= self.content_arr[i];
  2219. if([item[@"model"] isEqualToString:value])
  2220. cqty=[item[@"count"]intValue];
  2221. }
  2222. }
  2223. if(cqty>0)
  2224. {
  2225. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  2226. //block代码块取代了delegate
  2227. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2228. [self addtocart:value];
  2229. }];
  2230. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2231. DebugLog(@"No");
  2232. }];
  2233. [alertControl addAction:actionOne];
  2234. [alertControl addAction:alertthree];
  2235. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2236. [self presentViewController:alertControl animated:YES completion:nil];
  2237. }
  2238. else
  2239. [self addtocart:value];
  2240. }
  2241. -(void) addtocart:(NSString*) modelname
  2242. {
  2243. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2244. NSDictionary* return_json = [RANetwork add_toCart_byName: modelname withScreen:ScreenCodeCart];
  2245. dispatch_async(dispatch_get_main_queue(), ^{
  2246. if([[return_json valueForKey:@"result"] intValue]==2)
  2247. {
  2248. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  2249. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  2250. // bool isnew=false;
  2251. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2252. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  2253. if (self.back_order_flag) {
  2254. NSInteger section_count = [self sectionCount];
  2255. for (int i = 0; i < section_count; i++) {
  2256. NSInteger item_count = [self itemCountInSection:i];
  2257. BOOL ready_break = NO;
  2258. for (int j = 0; j < item_count; j++) {
  2259. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2260. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  2261. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2262. if([_id isEqualToString:item_id])
  2263. {
  2264. [self updateItemJson:nil atIndexPath:indexPath];
  2265. ready_break = YES;
  2266. break;
  2267. }
  2268. }
  2269. if (ready_break) {
  2270. break;
  2271. }
  2272. }
  2273. } else {
  2274. for(int i=0;i<self.content_arr.count;i++)
  2275. {
  2276. NSDictionary* obj_json = self.content_arr[i];
  2277. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2278. if([_id isEqualToString:item_id])
  2279. {
  2280. // self.content_arr[i] = newitem;
  2281. [self.content_arr removeObjectAtIndex:i];
  2282. break;
  2283. // [self.content_arr removeObjectAtIndex:i];
  2284. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2285. // appDelegate.cart_count--;
  2286. // [appDelegate update_count_mark];
  2287. }
  2288. }
  2289. }
  2290. #ifdef OFFLINE_MODE
  2291. if(appDelegate.offline_mode)
  2292. {
  2293. [self ReloadData];
  2294. }
  2295. else
  2296. #endif
  2297. {
  2298. if (self.back_order_flag) {
  2299. [self ReloadData];
  2300. } else {
  2301. [self.content_arr insertObject:newitem atIndex:0];
  2302. [self.itemListTable reloadData];
  2303. [self refresh_total];
  2304. }
  2305. }
  2306. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2307. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2308. }
  2309. else
  2310. {
  2311. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  2312. }
  2313. });
  2314. });
  2315. }
  2316. #pragma mark - sort button
  2317. - (void)cartSortButtonClicked:(UIButton *)sender {
  2318. DebugLog(@"cart sort button clicked");
  2319. [self.view addSubview:self.sortItemController.view];
  2320. }
  2321. - (SortItemViewController *)sortItemController {
  2322. if (!_sortItemController) {
  2323. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  2324. _sortItemController.sortIndex = self.sortIndex;
  2325. _sortItemController.sortData = @[
  2326. @{@"title":@"Last",@"icon":@"TX_18"},
  2327. @{@"title":@"First",@"icon":@"TS_18"},
  2328. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  2329. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  2330. @{@"title":@"Description",@"icon":@"DX_18"},
  2331. ];
  2332. __weak typeof(self) weakSelf = self;
  2333. _sortItemController.sortBlock = ^(int sort){
  2334. weakSelf.sortIndex = sort;
  2335. [weakSelf reload_data];
  2336. };
  2337. }
  2338. // _sortItemController.sortIndex = self.sortIndex;
  2339. return _sortItemController;
  2340. }
  2341. - (SortButton *)sortButton {
  2342. if (!_sortButton) {
  2343. _sortButton = [SortButton sortButtonWithHeight:40];
  2344. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  2345. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  2346. }
  2347. return _sortButton;
  2348. }
  2349. - (void)setSortIndex:(int)sortIndex {
  2350. _sortIndex = sortIndex;
  2351. NSString *selectedImageName = @"";
  2352. switch (sortIndex) {
  2353. case 0:{
  2354. selectedImageName = @"TX_22";
  2355. }
  2356. break;
  2357. case 1:{
  2358. selectedImageName = @"TS_22";
  2359. }
  2360. break;
  2361. case 2:{
  2362. selectedImageName = @"IX_22";
  2363. }
  2364. break;
  2365. case 3:{
  2366. selectedImageName = @"IS_22";
  2367. }
  2368. break;
  2369. case 4:{
  2370. selectedImageName = @"DX_22";
  2371. }
  2372. break;
  2373. default:
  2374. break;
  2375. }
  2376. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  2377. }
  2378. #pragma mark - rotation
  2379. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  2380. self.sortItemController.view.frame = self.view.bounds;
  2381. }
  2382. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  2383. return YES;
  2384. }
  2385. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  2386. self.sortItemController.view.frame = self.view.bounds;
  2387. }
  2388. #pragma mark - notification action
  2389. - (void)priceTypeChanged:(id)notification {
  2390. [self reload_data];
  2391. }
  2392. #pragma mark - button action
  2393. - (IBAction)emailButtonClick:(UIButton *)sender {
  2394. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  2395. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  2396. emailAddrVC.textFiled.secureTextEntry = NO;
  2397. emailAddrVC.yesButtonTitle = @"send";
  2398. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  2399. __weak typeof(self) weakself = self;
  2400. emailAddrVC.textHandler = ^(NSString *text){
  2401. // 验证邮箱格式是否正确
  2402. // NSString *match = EMAIL_MATCHES;
  2403. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  2404. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  2405. BOOL isEmailAddr = YES;
  2406. if (isEmailAddr) {
  2407. // 验证是邮件地址,发送邮件
  2408. [weakVC dismissViewControllerAnimated:YES completion:^{
  2409. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  2410. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  2411. NSDictionary *result = [RANetwork quoteOrder:appDelegate.order_code emailAddr:text];
  2412. DebugLog(@"email cart result: %@",result);
  2413. dispatch_async(dispatch_get_main_queue(), ^{
  2414. [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  2415. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  2416. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  2417. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2418. }];
  2419. [errorAlertVC addAction:action];
  2420. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2421. }else {
  2422. [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  2423. }
  2424. });
  2425. });
  2426. }];
  2427. } else {
  2428. // 非邮件地址,警告
  2429. [weakVC warning:@"Please enter right email address"];
  2430. }
  2431. };
  2432. [self presentViewController:emailAddrVC animated:YES completion:nil];
  2433. }
  2434. - (IBAction)printCartButtonClick:(UIButton *)sender {
  2435. RAPDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  2436. ViewController.url = self.print_url;
  2437. ViewController.canSave = false;
  2438. ViewController.isLocalfile=NO;
  2439. NSString* subject;
  2440. subject =@"Cart Print";
  2441. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2442. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  2443. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  2444. if(customer_email.length>0)
  2445. {
  2446. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  2447. }
  2448. ViewController.mail_to = send_to;
  2449. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  2450. ViewController.mail_subject = subject;
  2451. ViewController.hidenavi = false;
  2452. [self.navigationController pushViewController:ViewController animated:YES];
  2453. }
  2454. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  2455. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  2456. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  2457. emailAddrVC.textFiled.secureTextEntry = NO;
  2458. emailAddrVC.yesButtonTitle = @"send";
  2459. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  2460. __weak typeof(self) weakself = self;
  2461. emailAddrVC.textHandler = ^(NSString *text){
  2462. // 验证邮箱格式是否正确
  2463. // NSString *match = EMAIL_MATCHES;
  2464. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  2465. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  2466. BOOL isEmailAddr = YES;
  2467. if (isEmailAddr) {
  2468. // 验证是邮件地址,发送邮件
  2469. [weakVC dismissViewControllerAnimated:YES completion:^{
  2470. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  2471. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  2472. NSDictionary *result = [RANetwork notifyModel:productID emailAddr:text withScreen:ScreenCodeCart];
  2473. dispatch_async(dispatch_get_main_queue(), ^{
  2474. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2475. int resultStatus = [[result objectForKey:@"result"] intValue];
  2476. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  2477. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2478. if ([result valueForKey:@"err_msg"]) {
  2479. msg = [result valueForKey:@"err_msg"];
  2480. }
  2481. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2482. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2483. }];
  2484. [errorAlertVC addAction:action];
  2485. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2486. }else if(resultStatus == RESULT_TRUE){
  2487. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  2488. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  2489. [weakself showAddressBoxToEmailProduct:productID];
  2490. }
  2491. });
  2492. });
  2493. }];
  2494. } else {
  2495. // 非邮件地址,警告
  2496. [weakVC warning:@"Please enter right email address"];
  2497. }
  2498. };
  2499. [self presentViewController:emailAddrVC animated:YES completion:nil];
  2500. }
  2501. #pragma mark - Back Order
  2502. - (void) setCart_json:(NSDictionary *)cart_json {
  2503. _cart_json = cart_json;
  2504. [self fillContentArray];
  2505. }
  2506. - (void)fillContentArray {
  2507. NSMutableArray *arr = [NSMutableArray array];
  2508. for (int i = 0; i < [self sectionCount]; i++) {
  2509. NSInteger item_count = [self itemCountInSection:i];
  2510. for (int j = 0; j < item_count; j++) {
  2511. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  2512. [arr addObject:item];
  2513. }
  2514. }
  2515. self.content_arr = arr;
  2516. [self refresh_total];
  2517. }
  2518. - (NSInteger)sectionCount {
  2519. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  2520. }
  2521. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  2522. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  2523. }
  2524. - (NSInteger)itemCountInSection:(NSInteger)section {
  2525. NSDictionary *section_json = [self jsonAtSection:section];
  2526. return [[section_json objectForKey:@"count"] integerValue];
  2527. }
  2528. - (NSString *)titleForSection:(NSInteger)section {
  2529. NSDictionary *section_json = [self jsonAtSection:section];
  2530. return [section_json objectForKey:@"title"];
  2531. }
  2532. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  2533. NSDictionary *section = [self jsonAtSection:indexPath.section];
  2534. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2535. }
  2536. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  2537. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  2538. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  2539. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  2540. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  2541. if (new_item_json) {
  2542. // 更新Item
  2543. [new_section_json setObject:new_item_json forKey:item_key];
  2544. } else {
  2545. // 删除Item
  2546. NSInteger item_count = [self itemCountInSection:indexPath.section];
  2547. for (NSInteger i = 0; i < item_count; i++) {
  2548. if (i >= indexPath.row) {
  2549. if (i < item_count - 1) {
  2550. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  2551. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  2552. item_key = [NSString stringWithFormat:@"item_%ld",i];
  2553. [new_section_json setObject:followed_item_json forKey:item_key];
  2554. } else {
  2555. item_key = [NSString stringWithFormat:@"item_%ld",i];
  2556. [new_section_json removeObjectForKey:item_key];
  2557. }
  2558. }
  2559. }
  2560. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  2561. }
  2562. [new_cart_json setObject:new_section_json forKey:section_key];
  2563. self.cart_json = [new_cart_json copy];
  2564. }
  2565. - (void)reRefreshView {
  2566. [self.itemListTable reloadData];
  2567. }
  2568. @end