CartViewController.m 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778
  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 "RASingleton.h"
  26. #import "JKMessageBoxController.h"
  27. #import "RAPDFViewController.h"
  28. #ifdef SCANNER_ORDER
  29. #import "ScanCartItemCell.h"
  30. #import "ScanDiscountViewController.h"
  31. #else
  32. #endif
  33. #ifdef BUILD_CONTRAST
  34. #import "OrderDiscountViewController.h"
  35. #endif
  36. #ifdef BACKORDER_PROCESS
  37. #import "RAOrderEditorViewController.h"
  38. #endif
  39. #import "CustomerEditViewController.h"
  40. //#define ALERT_FREE 1024
  41. //#define ALERT_DEL 1025
  42. //#define ALERT_SET_FREE 1026
  43. //#define ALERT_RESTORE_FREE 1027
  44. @interface CartViewController ()
  45. {
  46. CGRect cancelButtonFrame;
  47. }
  48. @property (nonatomic,strong) SortItemViewController *sortItemController;
  49. @property (nonatomic,assign) int sortIndex;
  50. @property (nonatomic,strong) SortButton *sortButton;
  51. @property (strong, nonatomic) IBOutlet UIButton *placeOrderButton;
  52. @property (strong, nonatomic) IBOutlet UIButton *cancelOrderButton;
  53. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  54. @property (strong, nonatomic) IBOutlet UIButton *emailButton;
  55. @property (strong, nonatomic) IBOutlet UIButton *printButton;
  56. @property (weak, nonatomic) IBOutlet UIButton *editButton;
  57. @property (weak, nonatomic) IBOutlet UIButton *continueButton;
  58. @property (weak, nonatomic) IBOutlet UILabel *labelTotalcuft;
  59. @property (weak, nonatomic) IBOutlet UILabel *labelTotalWeight;
  60. @property (weak, nonatomic) IBOutlet UILabel *labelTotalCarton;
  61. @property (weak, nonatomic) IBOutlet UILabel *valuecuft;
  62. @property (weak, nonatomic) IBOutlet UILabel *valueweight;
  63. @property (weak, nonatomic) IBOutlet UILabel *valuecarton;
  64. @property (nonatomic,assign) BOOL currentOrderIsMerged;
  65. @property (nonatomic,strong) DefaultTableHeaderView *cartIndicatorBar;
  66. @property (nonatomic,assign) BOOL back_order_flag;
  67. @property (nonatomic,strong) NSDictionary *cart_json;
  68. @property (nonatomic,copy) NSString *print_url;
  69. @property (nonatomic,assign) BOOL available;///<所有Model均有库存,才能Place Order。
  70. @end
  71. @implementation CartViewController
  72. - (NSOperationQueue *)dataOperationQueue {
  73. if (!_dataOperationQueue) {
  74. _dataOperationQueue = [[NSOperationQueue alloc] init];
  75. _dataOperationQueue.maxConcurrentOperationCount = 1;
  76. }
  77. return _dataOperationQueue;
  78. }
  79. - (void)dealloc {
  80. #ifndef RA_NOTIFICATION
  81. [[NSNotificationCenter defaultCenter] removeObserver:self];
  82. #endif
  83. }
  84. -(void) logout
  85. {
  86. [super logout];
  87. [self.content_arr removeAllObjects];
  88. [self refresh_ui];
  89. self.cart_json = nil;
  90. }
  91. - (IBAction)OnEditSelectClick:(id)sender {
  92. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  93. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  94. if(count==0)
  95. {
  96. [RAUtils message_box:@"Cart" message:@"No item in the cart" completion:nil] ;
  97. return;
  98. }
  99. for(int i=0;i<count;i++)
  100. {
  101. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  102. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  103. }
  104. NSString * ids = [arr_ids componentsJoinedByString:@","];
  105. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  106. //block代码块取代了delegate
  107. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  108. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  109. //block代码块取代了delegate
  110. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  111. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  112. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Models From Cart" completion:nil];
  113. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  114. NSMutableDictionary* cart_json =result;
  115. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  116. // [waitalert dismissViewControllerAnimated:YES completion:^{
  117. [pop hide];
  118. if([[cart_json valueForKey:@"result"] intValue]==2)
  119. {
  120. [self end_edit];
  121. #ifdef RA_NOTIFICATION
  122. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  123. #else
  124. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  125. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  126. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  127. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  128. #endif
  129. }
  130. else
  131. {
  132. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  133. }
  134. // }];
  135. }];
  136. // }];
  137. }];
  138. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  139. DebugLog(@"No");
  140. }];
  141. [alertControl addAction:actionOne];
  142. [alertControl addAction:alertthree];
  143. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  144. [self presentViewController:alertControl animated:YES completion:nil];
  145. DebugLog(@"%@",self.edit_select_arr);
  146. }];
  147. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  148. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  149. PopWaitAlert* pop = [RAUtils waiting_pop:@"Move Models To Wish List" completion:nil];
  150. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  151. NSDictionary* cart_json =result;
  152. // [waitalert dismissViewControllerAnimated:YES completion:^{
  153. [pop hide];
  154. if([[cart_json valueForKey:@"result"] intValue]==2)
  155. {
  156. #ifdef RA_NOTIFICATION
  157. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  158. #else
  159. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  160. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  161. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  162. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  163. #endif
  164. [self end_edit];
  165. }
  166. else
  167. {
  168. [RAUtils message_box:@"Move Models To Wish List" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  169. }
  170. // }];
  171. }];
  172. // }];
  173. }];
  174. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  175. DebugLog(@"No");
  176. }];
  177. [alertControl addAction:actionOne];
  178. [alertControl addAction:actionTwo];
  179. [alertControl addAction:alertthree];
  180. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  181. [self presentViewController:alertControl animated:YES completion:nil];
  182. DebugLog(@"%@",self.edit_select_arr);
  183. }
  184. - (IBAction)onEditAddWishClick:(id)sender {
  185. if(self.edit_select_arr.count==0)
  186. {
  187. [RAUtils message_box:@"Cannot Move To Wish List" message:@"You must select at least one model." completion:nil] ;
  188. return;
  189. }
  190. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  191. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  192. // //block代码块取代了delegate
  193. //
  194. //
  195. //
  196. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  197. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  198. PopWaitAlert* pop = [RAUtils waiting_pop:@"Move Models To Wish List" completion:nil];
  199. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  200. NSDictionary* cart_json = result;
  201. // [waitalert dismissViewControllerAnimated:YES completion:^{
  202. [pop hide];
  203. if([[cart_json valueForKey:@"result"] intValue]==2)
  204. {
  205. [self end_edit];
  206. #ifdef RA_NOTIFICATION
  207. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  208. #else
  209. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  210. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  211. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  212. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  213. #endif
  214. }
  215. else
  216. {
  217. [RAUtils message_box:@"Move To Wish List" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  218. }
  219. // }];
  220. }];
  221. // }];
  222. }
  223. - (IBAction)onEditDelClick:(id)sender {
  224. if(self.edit_select_arr.count==0)
  225. {
  226. [RAUtils message_box:@"Cannot Delete From Cart" message:@"You must select at least one model." completion:nil] ;
  227. return;
  228. }
  229. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  230. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  231. //block代码块取代了delegate
  232. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  233. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  234. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Models From Cart" completion:nil];
  235. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  236. NSMutableDictionary* cart_json =result;
  237. // [waitalert dismissViewControllerAnimated:YES completion:^{
  238. [pop hide];
  239. if([[cart_json valueForKey:@"result"] intValue]==2)
  240. {
  241. [self end_edit];
  242. #ifdef RA_NOTIFICATION
  243. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  244. #else
  245. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  246. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  247. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  248. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  249. #endif
  250. }
  251. else
  252. {
  253. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  254. }
  255. // }];
  256. }];
  257. // }];
  258. }];
  259. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  260. DebugLog(@"No");
  261. }];
  262. [alertControl addAction:actionOne];
  263. [alertControl addAction:alertthree];
  264. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  265. [self presentViewController:alertControl animated:YES completion:nil];
  266. DebugLog(@"%@",self.edit_select_arr);
  267. }
  268. - (IBAction)onEndEditClick:(id)sender {
  269. [self end_edit];
  270. }
  271. -(void)begin_edit
  272. {
  273. self.toolpanel.hidden = true;
  274. self.toolbar.hidden = false;
  275. // DebugLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  276. // NSArray *scenes=[[[UIApplication sharedApplication] connectedScenes] allObjects];
  277. // NSArray *windows=[[scenes objectAtIndex:0] windows];
  278. //
  279. // UIWindow* w=windows[0];
  280. UIInterfaceOrientation orientation = [RAUtils query_orientation:self];
  281. // if (@available(iOS 13, *)) {
  282. // orientation= [RAUtils query_orientation:self];
  283. // }
  284. // else
  285. // orientation=[[UIApplication sharedApplication] statusBarOrientation];
  286. if ( UIInterfaceOrientationIsPortrait(orientation))
  287. self.cartItemView.frame = CGRectMake(0,40,768,840);
  288. else
  289. self.cartItemView.frame = CGRectMake(0,40,1024,584);
  290. [self.itemListTable setEditing:true animated:YES];
  291. [self.itemListTable reloadData];
  292. }
  293. -(void) end_edit
  294. {
  295. self.toolpanel.hidden=false;
  296. self.toolbar.hidden=true;
  297. // DebugLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  298. UIInterfaceOrientation orientation= [RAUtils query_orientation:self];// = [[UIApplication sharedApplication]statusBarOrientation];
  299. if ( UIInterfaceOrientationIsPortrait(orientation))
  300. self.cartItemView.frame = CGRectMake(0,40,768,760);
  301. else
  302. self.cartItemView.frame = CGRectMake(0,40,1024,508);
  303. [self.itemListTable setEditing:false animated:YES];
  304. [self.edit_select_arr removeAllObjects];
  305. [self.itemListTable reloadData];
  306. // [self reload_data];
  307. }
  308. - (IBAction)onEditClick:(id)sender {
  309. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  310. //
  311. // [appDelegate test_onDecodedDataResult:@"4400022"];
  312. //
  313. //
  314. // return;
  315. [self begin_edit];
  316. }
  317. #ifndef RA_NOTIFICATION
  318. -(void) reload_container_getdata:(bool) update_data
  319. {
  320. [super reload_container_getdata:update_data];
  321. if(update_data)
  322. [self reload_data];
  323. else
  324. {
  325. [self.itemListTable reloadData];
  326. [self refresh_total];
  327. }
  328. }
  329. #endif
  330. -(void) showHidePrice
  331. {
  332. #ifndef RA_NOTIFICATION
  333. [self reload_container_getdata:false];
  334. #endif
  335. // [self refresh_total];
  336. }
  337. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  338. {
  339. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  340. if (self) {
  341. // Custom initialization
  342. }
  343. return self;
  344. }
  345. - (IBAction)imgbtnClick:(UIButton *)sender {
  346. #ifdef SCANNER_ORDER
  347. return;
  348. #endif
  349. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  350. //
  351. // NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  352. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  353. // NSDictionary * item_json = nil;
  354. // if (self.back_order_flag) {
  355. // item_json = [self itemJsonAtIndexPath:indexPath];
  356. // } else {
  357. // item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  358. // }
  359. //
  360. // NSString* product_id = [item_json valueForKey:@"product_id"];
  361. // NSString *name = [item_json valueForKey:@"model"];
  362. //
  363. // int is_rate = [item_json[@"is_rate"] intValue];
  364. // if(is_rate==1)
  365. // return;
  366. //
  367. // DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  368. // // dvc
  369. //
  370. // dvc.product_id=product_id;
  371. // dvc.category_id=nil;
  372. // dvc.ispush=true;
  373. // dvc.model_name = name;
  374. //
  375. // [dvc reload];
  376. // [self.navigationController pushViewController:dvc animated:true];
  377. }
  378. -(void)viewWillLayoutSubviews
  379. {
  380. // if(self.showDetail==true)
  381. // {
  382. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  383. // int width=175;
  384. // // int height;
  385. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  386. // {
  387. // width = 370;
  388. // // height = 400;
  389. // }
  390. // else
  391. // {
  392. // // height = 300;
  393. // width = 175;
  394. // }
  395. //
  396. //
  397. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  398. //
  399. // self.collectionview.frame=frame;
  400. //
  401. //
  402. //
  403. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  404. // self.detailView.frame = framedetail;
  405. // }
  406. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  407. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  408. }
  409. - (void)viewWillAppear:(BOOL)animated
  410. {
  411. [super viewWillAppear:animated];
  412. // print 13 email 19 cancel 24 place order
  413. // Shop 权限检查
  414. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  415. if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  416. if (![RASingleton sharedInstance].permissions_edit_order) {
  417. CGRect frame0 = self.cancelOrderButton.frame;
  418. CGRect frame1 = self.placeOrderButton.frame;
  419. CGRect frame2 = self.emailButton.frame;
  420. CGRect frame3 = self.printButton.frame;
  421. CGFloat x = CGRectGetMaxX(frame1) - frame0.size.width;
  422. frame0.origin.x = x;
  423. self.cancelOrderButton.frame = frame0;
  424. x -= 20 + CGRectGetWidth(frame2);
  425. frame2.origin.x = x;
  426. self.emailButton.frame = frame2;
  427. x -= 20 + CGRectGetWidth(frame3);
  428. frame3.origin.x = x;
  429. self.printButton.frame = frame3;
  430. self.placeOrderButton.hidden = YES;
  431. } else {
  432. self.placeOrderButton.hidden = NO;
  433. CGSize size = cancelButtonFrame.size;
  434. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  435. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  436. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  437. CGRect frame2 = self.emailButton.frame;
  438. x -= 20 + CGRectGetWidth(frame2);
  439. frame2.origin.x = x;
  440. self.emailButton.frame = frame2;
  441. CGRect frame3 = self.printButton.frame;
  442. x -= 20 + CGRectGetWidth(frame3);
  443. frame3.origin.x = x;
  444. self.printButton.frame = frame3;
  445. }
  446. } else {
  447. // self.cancelOrderButton.frame = cancelButtonFrame;
  448. self.placeOrderButton.hidden = NO;
  449. CGSize size = cancelButtonFrame.size;
  450. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  451. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  452. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  453. CGRect frame2 = self.emailButton.frame;
  454. x -= 20 + CGRectGetWidth(frame2);
  455. frame2.origin.x = x;
  456. self.emailButton.frame = frame2;
  457. CGRect frame3 = self.printButton.frame;
  458. x -= 20 + CGRectGetWidth(frame3);
  459. frame3.origin.x = x;
  460. self.printButton.frame = frame3;
  461. }
  462. #ifdef OFFLINE_MODE
  463. // 离线隐藏Email
  464. self.emailButton.hidden = appDelegate.offline_mode;
  465. // 离线隐藏Print
  466. self.printButton.hidden = appDelegate.offline_mode;
  467. #endif
  468. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  469. #ifdef SCANNER_ORDER
  470. if(appDelegate.user_type == USER_ROLE_EMPLOYEE)
  471. {
  472. self.btnBulkDiscount.hidden = false;
  473. }
  474. else
  475. self.btnBulkDiscount.hidden = true;
  476. #endif
  477. }
  478. - (void)checkProductAvailable:(NSArray *)contents {
  479. if (contents == nil) {
  480. self.available = NO;
  481. return;
  482. }
  483. [contents enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  484. if ([obj isKindOfClass:[NSDictionary class]]) {
  485. NSDictionary *item_json = (NSDictionary *)obj;
  486. BOOL isAvailable = ![[item_json valueForKey:@"is_out_of_stock"] boolValue];
  487. self.available = self.available && isAvailable;
  488. }
  489. }];
  490. }
  491. - (void)clearContent {
  492. dispatch_async(dispatch_get_main_queue(), ^{
  493. self.freejson = nil;
  494. self.notes = nil;
  495. self.content_arr = nil;
  496. self.currentOrderIsMerged = nil;
  497. self.cart_json = nil;
  498. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  499. self.print_url = nil;
  500. [self checkProductAvailable:self.content_arr];
  501. [self refresh_total];
  502. [self.itemListTable reloadData];
  503. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  504. appDelegate.cart_count = 0;
  505. [appDelegate update_count_mark];
  506. });
  507. }
  508. -(void) operation_reload_data
  509. {
  510. if (self.dataOperationQueue.operationCount > 1) {
  511. return;
  512. }
  513. __block AppDelegate *appDelegate = nil;
  514. dispatch_sync(dispatch_get_main_queue(), ^{
  515. //some UI methods ej
  516. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  517. });
  518. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  519. #ifndef SCANNER_ORDER
  520. //扫码订单允许后建订单
  521. if (appDelegate.order_code == nil || appDelegate.order_code.length == 0) {
  522. [self clearContent];
  523. return;
  524. }
  525. #endif
  526. __weak typeof(self) weakself = self;
  527. dispatch_async(dispatch_get_main_queue(), ^{
  528. if(weakself.isrefreshing)
  529. return;
  530. weakself.available = YES;
  531. weakself.itemListTable.hidden = true;
  532. weakself.label_net_err.hidden=true;
  533. weakself.isrefreshing=true;
  534. // [self.content_data removeAllObjects];
  535. // [self.itemListTable reloadData];
  536. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  537. //
  538. // [reF endRefreshing];
  539. //
  540. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  541. weakself.mum.center = weakself.view.center;
  542. weakself.mum.hidden = YES;
  543. // [self.mum startAnimating];
  544. DebugLog(@"reloading...");
  545. // __block UIAlertController *loadingView = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  546. PopWaitAlert* pop = [RAUtils waiting_pop:@"Loading" completion:nil];
  547. [RANetwork request_cart:weakself.sortIndex completionHandler:^(NSMutableDictionary *result) {
  548. DebugLog(@"BEGIN LOAD CART");
  549. NSDictionary* cart_json = result;
  550. //
  551. // [self.mum stopAnimating];
  552. // [loadingView dismissViewControllerAnimated:YES completion:^{
  553. [pop hide];
  554. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  555. // self.content_data = [cart_json mutableCopy];
  556. #ifdef BACKORDER_PROCESS
  557. weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  558. #else
  559. weakself.back_order_flag = NO;
  560. #endif
  561. if (!weakself.back_order_flag) {
  562. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  563. weakself.notes = [cart_json valueForKey:@"general_note"];
  564. weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  565. weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  566. [RASingleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  567. [weakself.itemListTable reloadData];
  568. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  569. [weakself checkProductAvailable:weakself.content_arr];
  570. [weakself refresh_total];
  571. } else {
  572. // v1.94
  573. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  574. weakself.notes = [cart_json valueForKey:@"general_note"];
  575. weakself.cart_json = cart_json;
  576. [weakself.itemListTable reloadData];
  577. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  578. [weakself checkProductAvailable:weakself.content_arr];
  579. }
  580. int result_code=[[cart_json valueForKey:@"result"] intValue];
  581. if (weakself.dataOperationQueue.operationCount > 1) {
  582. weakself.isrefreshing=false;
  583. return;
  584. }
  585. if(result_code==2||result_code==1||result_code==0)
  586. {
  587. [weakself.edit_select_arr removeAllObjects];
  588. weakself.itemListTable.hidden = false;
  589. // UIApplication * app = [UIApplication sharedApplication];
  590. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  591. // appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  592. weakself.itemListTable.hidden=false;
  593. if(weakself.onFinishLoad)
  594. weakself.onFinishLoad();
  595. }
  596. else
  597. if(result_code==RESULT_NET_ERROR)
  598. {
  599. weakself.label_net_err.hidden=false;
  600. weakself.itemListTable.hidden=true;
  601. }
  602. else
  603. {
  604. if(result_code!=1)
  605. [RAUtils message_box:@"Loading Cart" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  606. }
  607. weakself.isrefreshing=false;
  608. DebugLog(@"FINISH LOAD CART");
  609. // }];
  610. }];
  611. // }];
  612. });
  613. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  614. }
  615. -(void)manually_refresh
  616. {
  617. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  618. if(self.isrefreshing)
  619. {
  620. [reF endRefreshing];
  621. return;
  622. }
  623. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  624. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  625. // DebugLog(@"refresh!!!!!!!!");
  626. }
  627. -(void) ReloadData
  628. {
  629. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  630. [reF endRefreshing];
  631. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  632. [self reload_data];
  633. }
  634. - (void)viewDidLayoutSubviews {
  635. [super viewDidLayoutSubviews];
  636. [self layoutCartIndicatorBar];
  637. }
  638. - (DefaultTableHeaderView *)setupCartIndicatorBar {
  639. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  640. if(value==nil)
  641. value=@"";
  642. unsigned long color = strtoul([value UTF8String],0,16);
  643. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
  644. // myView.backgroundColor = UIColorFromRGB(0x996633);
  645. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  646. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  647. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  648. myView.layer.shadowOffset = CGSizeMake(0, 0);
  649. myView.layer.shadowOpacity = 0.5;
  650. myView.layer.shadowRadius = 2.0;
  651. #ifndef SCANNER_ORDER
  652. self.sortButton.tag = 5678 + 0;
  653. [myView addSubview:self.sortButton];
  654. #endif
  655. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 9, 90, 22)];
  656. solabel.tag = 5678 + 1;
  657. solabel.textColor=UIColorFromRGB(color);
  658. solabel.backgroundColor = [UIColor clearColor];
  659. solabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  660. solabel.text=NSLocalizedString(@"Description", nil);
  661. [solabel sizeToFit];
  662. [myView addSubview:solabel];
  663. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  664. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  665. contactlabel.tag = 5678 + 2;
  666. contactlabel.textColor=UIColorFromRGB(color);
  667. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  668. contactlabel.backgroundColor = [UIColor clearColor];
  669. #ifdef SCANNER_ORDER
  670. NSString* pricename;
  671. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  672. NSString* servername = [addressDic objectForKey:@"show_name"];
  673. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  674. NSString * shortname = arrsn[0];
  675. if(shortname.length==0)
  676. shortname = servername;
  677. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  678. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  679. // self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
  680. // self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
  681. switch(RASingleton.sharedInstance.price_type)
  682. {
  683. case 0:
  684. // pricename =[NSString stringWithFormat:@"%@_DDP",shortname];
  685. pricename = price_group[@"price_0"][@"display"];
  686. break;;
  687. case 1:
  688. // pricename = [NSString stringWithFormat:@"%@_WHSE",shortname];;
  689. pricename=price_group[@"price_1"][@"display"];//@"WHSE";
  690. break;;
  691. // case 2: pricename = @"25%";
  692. // break;
  693. }
  694. contactlabel.text=pricename;
  695. // contactlabel.frame= CGRectMake(x-100, 9, 90, 22);
  696. // contactlabel.tran
  697. #else
  698. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  699. #endif
  700. [contactlabel sizeToFit];
  701. [myView addSubview:contactlabel];
  702. x = self.itemListTable.bounds.size.width - (768 - 470);
  703. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  704. modellabel.tag = 5678 + 3;
  705. modellabel.textColor=UIColorFromRGB(color);
  706. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  707. modellabel.backgroundColor = [UIColor clearColor];
  708. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  709. [modellabel sizeToFit];
  710. [myView addSubview:modellabel];
  711. x = self.itemListTable.bounds.size.width - (768 - 640);
  712. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  713. pricelabel.tag = 5678 + 4;
  714. pricelabel.textColor=UIColorFromRGB(color);
  715. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  716. pricelabel.backgroundColor = [UIColor clearColor];
  717. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  718. [pricelabel sizeToFit];
  719. [myView addSubview:pricelabel];
  720. return myView;
  721. }
  722. - (void)layoutCartIndicatorBar {
  723. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  724. UILabel *solabel = [self.cartIndicatorBar viewWithTag:5678 + 1];
  725. [solabel sizeToFit];
  726. UILabel *contactlabel = [self.cartIndicatorBar viewWithTag:5678 + 2];
  727. contactlabel.frame = CGRectMake(x, 9, 90, 22);
  728. [contactlabel sizeToFit];
  729. x = self.itemListTable.bounds.size.width - (768 - 470);
  730. UILabel *modellabel = [self.cartIndicatorBar viewWithTag:5678 + 3];
  731. modellabel.frame = CGRectMake(x, 9, 90, 22);
  732. [modellabel sizeToFit];
  733. x = self.itemListTable.bounds.size.width - (768 - 640);
  734. UILabel *pricelabel = [self.cartIndicatorBar viewWithTag:5678 + 4];
  735. pricelabel.frame = CGRectMake(x, 9, 90, 22);
  736. [pricelabel sizeToFit];
  737. }
  738. - (void)viewDidLoad
  739. {
  740. [super viewDidLoad];
  741. #ifdef BUILD_CONTRAST
  742. self.btnOrderDiscount.hidden=false;
  743. #endif
  744. #ifdef SCANNER_ORDER
  745. self.printButton.hidden = true;
  746. self.emailButton.hidden = true;
  747. self.editButton.hidden = true;
  748. self.continueButton.hidden = true;
  749. self.labelTotalcuft.hidden = false;
  750. self.labelTotalWeight.hidden = true;
  751. self.labelTotalCarton.hidden = true;
  752. self.valuecuft.hidden = false;
  753. self.valueweight.hidden = true;
  754. self.valuecarton.hidden = true;
  755. #endif
  756. #ifdef RA_NOTIFICATION
  757. self.support_scanner = true;
  758. #endif
  759. self.edit_select_arr= [[NSMutableArray alloc] init];
  760. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  761. self.label_net_err.layer.borderWidth = 2.0;
  762. self.label_net_err.layer.cornerRadius=15;
  763. self.label_net_err.layer.masksToBounds=true;
  764. #ifdef SCANNER_ORDER
  765. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cartrefresh:) name:@"RA_NOTIFICATION_CART_REFRESH" object:nil];
  766. #endif
  767. #ifndef RA_NOTIFICATION
  768. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(priceTypeChanged:) name:Change_Price_Type_Notification object:nil];
  769. #endif
  770. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  771. // tap.minimumPressDuration = 0.8; //定义按的时间
  772. [self.label_net_err addGestureRecognizer:tap];
  773. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  774. ref.tag = 200 ;
  775. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  776. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  777. // ref.hidden = true;
  778. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  779. [self.itemListTable addSubview:ref];
  780. self.sortIndex = 0;
  781. self.currentOrderIsMerged = NO;
  782. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  783. self.toolpanel.layer.masksToBounds = false;
  784. //添加四个边阴影
  785. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  786. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  787. self.toolpanel.layer.shadowOpacity = 0.5;
  788. self.toolpanel.layer.shadowRadius = 2.0;
  789. cancelButtonFrame = self.cancelOrderButton.frame;
  790. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  791. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  792. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  793. // // self.detailTable.sectionHeaderHeight = 0.0001;
  794. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  795. // Do any additional setup after loading the view.
  796. self.cartIndicatorBar = [self setupCartIndicatorBar];
  797. [self.view addSubview:self.cartIndicatorBar];
  798. }
  799. -(void) cartrefresh: (NSNotification *)notification
  800. {
  801. [OLDataProvider scanRefreshCart];
  802. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  803. // [self refresh_total];
  804. // [self refresh_ui];
  805. }
  806. //-(void)SelectOrder:(NSString *)orderid
  807. //{
  808. //// self.editOrderID.text=orderid;
  809. //// self.btnAddToOrder.enabled = true;
  810. //}
  811. - (void)didReceiveMemoryWarning
  812. {
  813. [super didReceiveMemoryWarning];
  814. // Dispose of any resources that can be recreated.
  815. }
  816. //- (IBAction)stepperAction:(UIStepper *)sender {
  817. //
  818. //
  819. //}
  820. - (IBAction)onContinueShoppingClick:(id)sender {
  821. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  822. [appDelegate switchToPreviousVC];
  823. }
  824. - (IBAction)onOrderDiscount:(id)sender {
  825. }
  826. - (IBAction)onPlaceOrder:(UIButton *)sender {
  827. #ifndef SCANNER_ORDER
  828. if (![self isOrderAvailable]) {
  829. return;
  830. }
  831. #endif
  832. [self placeOrder];
  833. }
  834. -(void) scanPlaceOrder
  835. {
  836. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  837. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  838. // NSString * string = [checked componentsJoinedByString:@","];
  839. // [params setValue:string forKey:@"cart2Checkbox"];
  840. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  841. // NSError *error=nil;
  842. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  843. //
  844. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  845. // NSString *documents = [paths objectAtIndex:0];
  846. NSString *orderdir = [OLDataProvider getScanPath];
  847. NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  848. int section_count = [dict[@"section_count"] intValue];
  849. for(int i=0;i<section_count;i++)
  850. {
  851. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  852. NSString* title = section[@"title"];
  853. if([title isEqualToString:@"Model Information"])
  854. {
  855. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  856. int cart_count = [cart_section[@"count"] intValue];
  857. for(int j=0;j<cart_count;j++)
  858. {
  859. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  860. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  861. cart_item[@"control"]=@"model";
  862. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  863. }
  864. section[@"count"] = @(cart_count);
  865. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  866. }
  867. else
  868. if([title isEqualToString:@"Customer"])
  869. {
  870. int scount = [section[@"count"] intValue];
  871. for(int j=0;j<scount;j++)
  872. {
  873. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  874. NSString * name = item[@"name"];
  875. if([name isEqualToString:@"business_card"])
  876. {
  877. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  878. for(int l=0;l<arr.count;l++)
  879. {
  880. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  881. }
  882. }
  883. else
  884. {
  885. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  886. item[@"value"]=appDelegate.customerInfo[name];
  887. }
  888. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  889. }
  890. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  891. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  892. }
  893. else
  894. if([title isEqualToString:@"Remarks Content"])
  895. {
  896. int scount = [section[@"count"] intValue];
  897. for(int j=0;j<scount;j++)
  898. {
  899. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  900. NSString * name = item[@"name"];
  901. if([name isEqualToString:@"comments"])
  902. {
  903. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  904. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  905. }
  906. }
  907. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  908. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  909. }
  910. else if([title isEqualToString:@"Order Total"])
  911. {
  912. int scount = [section[@"count"] intValue];
  913. for(int j=0;j<scount;j++)
  914. {
  915. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  916. NSString * name = item[@"name"];
  917. if([name isEqualToString:@"totalPrice"])
  918. {
  919. item[@"value"] = [RAConvertor currencyNumber:self.total+self.surcharge];//[NSString stringWithFormat:@"%.2f",self.total+self.surcharge];
  920. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  921. }
  922. else if([name isEqualToString:@"subtotalPrice"])
  923. {
  924. item[@"value"] = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"%.2f",self.total];
  925. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  926. }
  927. else if([name isEqualToString:@"surcharge"])
  928. {
  929. item[@"value"] = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"%.2f",self.surcharge];
  930. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  931. }
  932. }
  933. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  934. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  935. }
  936. }
  937. // NSString *path = NSTemporaryDirectory();
  938. //
  939. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  940. // NSString *filePath = [path stringByAppendingPathComponent:file];
  941. //
  942. //
  943. //
  944. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  945. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  946. orderinfoVC.disable_dropdown_refresh=true;
  947. orderinfoVC.url_type = URL_FILE;
  948. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  949. orderinfoVC.params = params;
  950. orderinfoVC.title=@"";
  951. orderinfoVC.delegate=self;
  952. //
  953. // if(checked.count==count)
  954. // {
  955. // orderinfoVC.have_tail = true
  956. // }
  957. [self.navigationController pushViewController:orderinfoVC animated:true];
  958. return;
  959. }
  960. - (IBAction)onBulkDiscount:(id)sender {
  961. #ifdef SCANNER_ORDER
  962. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  963. vc.bulk = true;
  964. vc.discount=0;
  965. // vc.price = 0;
  966. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  967. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  968. // vc.delegate = parentvc.self;
  969. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  970. vc.onSetValue = ^(double price,double discount){
  971. bool bmodify=false;
  972. if(discount>0)
  973. bmodify=true;
  974. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  975. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  976. [RANetwork request_scan_bulkdiscount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  977. NSDictionary* cart_json = result;
  978. // [waitalert dismissViewControllerAnimated:YES completion:^{
  979. [pop hide];
  980. if([[cart_json valueForKey:@"result"] intValue]==2)
  981. {
  982. [self reload_data];
  983. #ifdef RA_NOTIFICATION
  984. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  985. #else
  986. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  987. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  988. #endif
  989. }
  990. else
  991. {
  992. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  993. }
  994. // }];
  995. }];
  996. // }];
  997. };
  998. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  999. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1000. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1001. [self presentViewController:navi animated:YES completion:^{
  1002. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1003. DebugLog(@"EditModelPriceViewController present.........");
  1004. // self.btop = false;
  1005. // <#code#>
  1006. }];
  1007. #endif
  1008. }
  1009. - (IBAction)onChangePrice:(id)sender {
  1010. #ifdef SCANNER_ORDER
  1011. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1012. if(RASingleton.sharedInstance.scan_cart ==nil)
  1013. {
  1014. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1015. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1016. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1017. }
  1018. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1019. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change Price Type" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1020. UIAlertAction *action1 = [UIAlertAction actionWithTitle:price_group[@"price_0"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1021. self.btnBulkDiscount.hidden = true;
  1022. // self.btnPrice.titleLabel.text = @"FOB CTNR";
  1023. [self.btnPrice setTitle: price_group[@"price_0"][@"display"] forState:UIControlStateNormal];
  1024. RASingleton.sharedInstance.price_type=0;
  1025. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1026. int count = [section[@"count"] intValue];
  1027. for(int i=0;i<count;i++)
  1028. {
  1029. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1030. item[@"price"]=item[ price_group[@"price_0"][@"name"]];
  1031. item[@"unit_price"]= item[price_group[@"price_0"][@"name"]];
  1032. item[@"erp_unit_price"]= item[price_group[@"price_0"][@"name"]];
  1033. item[@"discount"]=@(0);
  1034. item[@"note"]=@"";
  1035. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1036. }
  1037. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1038. RASingleton.sharedInstance.scan_cart[@"price_type"] = @0;
  1039. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1040. [self.cartIndicatorBar removeFromSuperview];
  1041. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1042. [self.view addSubview:self.cartIndicatorBar];
  1043. [self reload_data];
  1044. }];
  1045. UIAlertAction *action2 = [UIAlertAction actionWithTitle:price_group[@"price_1"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1046. self.btnBulkDiscount.hidden = false;
  1047. [self.btnPrice setTitle: price_group[@"price_1"][@"display"] forState:UIControlStateNormal];
  1048. RASingleton.sharedInstance.price_type=1;
  1049. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1050. int count = [section[@"count"] intValue];
  1051. for(int i=0;i<count;i++)
  1052. {
  1053. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1054. NSString * unit_price;
  1055. if(item [@"net_price"])
  1056. unit_price=item[price_group[@"price_3"][@"name"]];
  1057. else if(item [@"special_price"])
  1058. {
  1059. unit_price= item[price_group[@"price_2"][@"name"]];
  1060. }
  1061. else
  1062. {
  1063. unit_price= item[price_group[@"price_1"][@"name"]];
  1064. }
  1065. if([unit_price isEqualToString:@"N/A"])
  1066. unit_price = @"0";
  1067. else
  1068. {
  1069. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  1070. }
  1071. item[@"unit_price"] = unit_price;
  1072. item[@"erp_unit_price"] = unit_price;
  1073. item[@"price"]= unit_price;//item[@"price1"];
  1074. // item[@"unit_price"]= item[@"price1"];
  1075. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1076. }
  1077. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  1078. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1079. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1080. [self.cartIndicatorBar removeFromSuperview];
  1081. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1082. [self.view addSubview:self.cartIndicatorBar];
  1083. [self reload_data];
  1084. }];
  1085. //%25 逻辑应HMLG要求去掉
  1086. /*
  1087. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1088. // self.btnPrice.titleLabel.text = @"%25";
  1089. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1090. RASingleton.sharedInstance.price_type=2;
  1091. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1092. int count = [section[@"count"] intValue];
  1093. for(int i=0;i<count;i++)
  1094. {
  1095. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1096. item[@"price"]= item[price_group[@"price_2"][@"name"]];
  1097. item[@"unit_price"]= item[price_group[@"price_2"][@"name"]];
  1098. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1099. }
  1100. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1101. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1102. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1103. [self.cartIndicatorBar removeFromSuperview];
  1104. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1105. [self.view addSubview:self.cartIndicatorBar];
  1106. [self reload_data];
  1107. }];
  1108. */
  1109. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1110. }];
  1111. [alertControl addAction:action1];
  1112. [alertControl addAction:action2];
  1113. // [alertControl addAction:action3];
  1114. // [alertControl addAction:alertthree];
  1115. [alertControl addAction:alertCancel];
  1116. [self presentViewController:alertControl animated:YES completion:nil];
  1117. #endif
  1118. }
  1119. -(void) newoloorder
  1120. {
  1121. NSString *orderdir =[OLDataProvider getScanPath];
  1122. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1123. appDelegate.can_set_cart_price = true;
  1124. appDelegate.can_see_price = true;
  1125. {
  1126. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1127. {
  1128. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1129. //block代码块取代了delegate
  1130. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1131. NSMutableDictionary* dict = nil;
  1132. // NSMutableDictionary* dict = nil;
  1133. NSString* ordertemplate = nil;
  1134. if([RADataProvider getSiteHasERP])
  1135. ordertemplate =@"e_order.json";
  1136. else
  1137. ordertemplate =@"e_order_noerp.json";
  1138. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1139. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1140. [RAUtils dicttofile:orderPath dict:dict];
  1141. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1142. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1143. [self scanPlaceOrder];
  1144. }];
  1145. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1146. NSMutableDictionary* dict = nil;
  1147. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1148. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1149. [RAUtils dicttofile:orderPath dict:dict];
  1150. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1151. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1152. [self scanPlaceOrder];
  1153. }];
  1154. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1155. appDelegate.order_code = nil;
  1156. DebugLog(@"No");
  1157. }];
  1158. [alertControl addAction:actionOne];
  1159. [alertControl addAction:alert2];
  1160. [alertControl addAction:alertthree];
  1161. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1162. [self presentViewController:alertControl animated:YES completion:nil];
  1163. DebugLog(@"%@",self.edit_select_arr);
  1164. }
  1165. else
  1166. {
  1167. NSMutableDictionary* dict = nil;
  1168. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1169. {
  1170. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1171. }
  1172. else
  1173. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1174. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1175. [RAUtils dicttofile:orderPath dict:dict];
  1176. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1177. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1178. [self scanPlaceOrder];
  1179. }
  1180. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1181. }
  1182. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1183. // mainvc.btnScan.enabled = true;
  1184. // [appDelegate updateScanButton:true];
  1185. }
  1186. -(void) newoloorder1
  1187. {
  1188. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1189. appDelegate.can_set_cart_price = true;
  1190. appDelegate.can_see_price = true;
  1191. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1192. // NSString *documents = [paths objectAtIndex:0];
  1193. {
  1194. NSString *orderdir =[OLDataProvider getScanPath];
  1195. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1196. {
  1197. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1198. //block代码块取代了delegate
  1199. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1200. NSMutableDictionary* dict = nil;
  1201. NSString* ordertemplate = nil;
  1202. if([RADataProvider getSiteHasERP])
  1203. ordertemplate =@"e_order.json";
  1204. else
  1205. ordertemplate =@"e_order_noerp.json";
  1206. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1207. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1208. [RAUtils dicttofile:orderPath dict:dict];
  1209. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1210. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1211. [self scanPlaceOrder];
  1212. }];
  1213. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1214. NSMutableDictionary* dict = nil;
  1215. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1216. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1217. [RAUtils dicttofile:orderPath dict:dict];
  1218. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1219. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1220. [self scanPlaceOrder];
  1221. }];
  1222. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1223. appDelegate.order_code = nil;
  1224. DebugLog(@"No");
  1225. }];
  1226. [alertControl addAction:actionOne];
  1227. [alertControl addAction:alert2];
  1228. [alertControl addAction:alertthree];
  1229. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1230. [self presentViewController:alertControl animated:YES completion:nil];
  1231. DebugLog(@"%@",self.edit_select_arr);
  1232. }
  1233. else
  1234. {
  1235. NSMutableDictionary* dict = nil;
  1236. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1237. {
  1238. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1239. }
  1240. else
  1241. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1242. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1243. [RAUtils dicttofile:orderPath dict:dict];
  1244. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1245. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1246. [self scanPlaceOrder];
  1247. }
  1248. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1249. }
  1250. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1251. // mainvc.btnScan.enabled = true;
  1252. // [appDelegate updateScanButton:true];
  1253. }
  1254. -(void)newScanOrder1
  1255. {
  1256. //
  1257. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1258. //
  1259. //
  1260. // if(appDelegate.order_code.length>0)
  1261. // {
  1262. //// 当前订单先关闭
  1263. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1264. // appDelegate.order_code = nil;
  1265. // appDelegate.customerInfo = nil;
  1266. // RASingleton.sharedInstance.scan_cart = nil;
  1267. // appDelegate.contact_id = nil;
  1268. //// [appDelegate updateScanButton:false];
  1269. //
  1270. // [appDelegate update_count_mark];
  1271. // [appDelegate closeOrder];
  1272. //
  1273. // }
  1274. //
  1275. //
  1276. {
  1277. [self newoloorder1];
  1278. }
  1279. }
  1280. -(void)newScanOrder
  1281. {
  1282. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1283. {
  1284. [self newoloorder];
  1285. }
  1286. }
  1287. -(void)placeOrder
  1288. {
  1289. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1290. #ifndef SCANNER_ORDER
  1291. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1292. if (![RASingleton sharedInstance].permissions_edit_order) {
  1293. return;
  1294. }
  1295. }
  1296. #endif
  1297. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1298. bool have_free = false;
  1299. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1300. if(count==0)
  1301. {
  1302. [RAUtils message_box:@"Cart Is Empty." message:@"Add some model first." completion:nil] ;
  1303. return;
  1304. }
  1305. for(int i=0;i<count;i++)
  1306. {
  1307. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1308. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1309. NSString* product_id = [item_json valueForKey:@"product_id"];
  1310. // if(check)
  1311. // {
  1312. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1313. //
  1314. // }
  1315. if(product_id.length==0)
  1316. {
  1317. [RAUtils message_box:@"No Such Model" message:@"Some models in cart does not exist, you must remove them before place order." completion:nil] ;
  1318. return;
  1319. }
  1320. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1321. if(is_free)
  1322. have_free=true;
  1323. }
  1324. #ifdef SCANNER_ORDER
  1325. if(appDelegate.bLogin==false)
  1326. {
  1327. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1328. // loginvc.delegate = self;
  1329. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1330. loginvc.returnValue = ^(bool blogin){
  1331. if(blogin)
  1332. {
  1333. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1334. if(appDelegate.order_code.length==0)
  1335. {
  1336. [self newScanOrder];
  1337. }
  1338. }
  1339. };
  1340. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1341. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1342. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1343. [self presentViewController:navi animated:YES completion:^{
  1344. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1345. DebugLog(@"LoginViewController present.........");
  1346. // self.btop = false;
  1347. // <#code#>
  1348. }];
  1349. return;
  1350. }
  1351. else
  1352. {
  1353. NSString *orderdir =[OLDataProvider getScanPath];
  1354. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1355. if(appDelegate.order_code.length==0 )
  1356. {
  1357. [self newScanOrder];
  1358. }
  1359. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1360. {
  1361. [self newScanOrder1];
  1362. }
  1363. else
  1364. {
  1365. [self scanPlaceOrder];
  1366. //place order
  1367. }
  1368. return;
  1369. }
  1370. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1371. // {
  1372. //
  1373. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1374. // // NSString * string = [checked componentsJoinedByString:@","];
  1375. // // [params setValue:string forKey:@"cart2Checkbox"];
  1376. //
  1377. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1378. //// NSError *error=nil;
  1379. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1380. ////
  1381. //
  1382. //
  1383. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1384. // NSString *documents = [paths objectAtIndex:0];
  1385. //
  1386. //
  1387. //
  1388. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1389. //
  1390. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1391. //
  1392. // int section_count = [dict[@"section_count"] intValue];
  1393. //
  1394. // for(int i=0;i<section_count;i++)
  1395. // {
  1396. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1397. // NSString* title = section[@"title"];
  1398. // if([title isEqualToString:@"Model Information"])
  1399. // {
  1400. //
  1401. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1402. // int cart_count = [cart_section[@"count"] intValue];
  1403. // for(int j=0;j<cart_count;j++)
  1404. // {
  1405. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1406. // cart_item[@"control"]=@"model";
  1407. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1408. //
  1409. // }
  1410. // section[@"count"] = @(cart_count);
  1411. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1412. // }
  1413. // else
  1414. // if([title isEqualToString:@"Customer"])
  1415. // {
  1416. //
  1417. // int scount = [section[@"count"] intValue];
  1418. // for(int j=0;j<scount;j++)
  1419. // {
  1420. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1421. // NSString * name = item[@"name"];
  1422. //
  1423. // if([name isEqualToString:@"business_card"])
  1424. // {
  1425. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1426. // for(int l=0;l<arr.count;l++)
  1427. // {
  1428. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1429. // }
  1430. // }
  1431. // else
  1432. // item[@"value"]=appDelegate.customerInfo[name];
  1433. //
  1434. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1435. // }
  1436. //
  1437. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1438. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1439. //
  1440. //
  1441. // }
  1442. // else
  1443. // if([title isEqualToString:@"Remarks Content"])
  1444. // {
  1445. //
  1446. // int scount = [section[@"count"] intValue];
  1447. // for(int j=0;j<scount;j++)
  1448. // {
  1449. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1450. // NSString * name = item[@"name"];
  1451. //
  1452. //
  1453. // if([name isEqualToString:@"comments"])
  1454. // {
  1455. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1456. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1457. // }
  1458. //
  1459. //
  1460. // }
  1461. //
  1462. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1463. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1464. //
  1465. //
  1466. // }
  1467. // else if([title isEqualToString:@"Order Total"])
  1468. // {
  1469. //
  1470. // int scount = [section[@"count"] intValue];
  1471. // for(int j=0;j<scount;j++)
  1472. // {
  1473. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1474. // NSString * name = item[@"name"];
  1475. //
  1476. //
  1477. // if([name isEqualToString:@"totalPrice"])
  1478. // {
  1479. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  1480. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1481. // }
  1482. //
  1483. //
  1484. // }
  1485. //
  1486. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1487. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1488. //
  1489. //
  1490. //
  1491. // }
  1492. //
  1493. //
  1494. //
  1495. //
  1496. // }
  1497. //
  1498. //// NSString *path = NSTemporaryDirectory();
  1499. ////
  1500. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1501. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  1502. ////
  1503. ////
  1504. ////
  1505. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1506. //
  1507. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1508. //
  1509. //
  1510. //
  1511. // orderinfoVC.disable_dropdown_refresh=true;
  1512. // orderinfoVC.url_type = URL_FILE;
  1513. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1514. //
  1515. // orderinfoVC.params = params;
  1516. // orderinfoVC.title=@"";
  1517. // orderinfoVC.delegate=self;
  1518. // //
  1519. // // if(checked.count==count)
  1520. // // {
  1521. // // orderinfoVC.have_tail = true
  1522. // // }
  1523. //
  1524. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1525. //
  1526. // return;
  1527. // }
  1528. #endif
  1529. //#ifdef BACKORDER_PROCESS
  1530. // if (self.back_order_flag) {
  1531. //
  1532. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1533. // [params setObject:@(0) forKey:@"step"];
  1534. //
  1535. //
  1536. // RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  1537. //
  1538. //
  1539. // //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1540. //
  1541. // orderEditorVC.disable_dropdown_refresh=true;
  1542. // orderEditorVC.url_type = URL_REMOTE;
  1543. // orderEditorVC.request_url=URL_CARTDELIVERY;
  1544. // orderEditorVC.params = params;
  1545. // orderEditorVC.delegate=self;
  1546. // orderEditorVC.title=@"";
  1547. // [self.navigationController pushViewController:orderEditorVC animated:true];
  1548. //
  1549. // }
  1550. // else
  1551. //#endif
  1552. // {
  1553. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1554. // // NSString * string = [checked componentsJoinedByString:@","];
  1555. // // [params setValue:string forKey:@"cart2Checkbox"];
  1556. //
  1557. //
  1558. //
  1559. //
  1560. //
  1561. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1562. //
  1563. // orderinfoVC.disable_dropdown_refresh=true;
  1564. // orderinfoVC.url_type = URL_REMOTE;
  1565. // orderinfoVC.request_url=URL_CARTDELIVERY;
  1566. //
  1567. // orderinfoVC.params = params;
  1568. // orderinfoVC.title=@"";
  1569. // orderinfoVC.delegate=self;
  1570. // //
  1571. // // if(checked.count==count)
  1572. // // {
  1573. // // orderinfoVC.have_tail = true
  1574. // // }
  1575. //
  1576. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1577. // }
  1578. }
  1579. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  1580. {
  1581. return NO;
  1582. }
  1583. - (IBAction)onScanDiscount:(UIButton*)sender {
  1584. #ifdef SCANNER_ORDER
  1585. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1586. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  1587. UIViewController* parentvc=self;
  1588. // EditModelPriceViewController
  1589. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1590. NSMutableDictionary * item_json = nil;
  1591. if (self.back_order_flag) {
  1592. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1593. } else {
  1594. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1595. }
  1596. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1597. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1598. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1599. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1600. // vc.delegate = parentvc.self;
  1601. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1602. vc.onSetValue = ^(double price,double discount){
  1603. bool bmodify=false;
  1604. if(discount>0)
  1605. bmodify=true;
  1606. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1607. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  1608. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1609. NSDictionary* cart_json = result;
  1610. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1611. [pop hide];
  1612. if([[cart_json valueForKey:@"result"] intValue]==2)
  1613. {
  1614. [self reload_data];
  1615. #ifdef RA_NOTIFICATION
  1616. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1617. #else
  1618. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1619. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1620. #endif
  1621. }
  1622. else
  1623. {
  1624. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  1625. }
  1626. // }];
  1627. }];
  1628. // }];
  1629. };
  1630. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1631. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1632. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1633. [parentvc presentViewController:navi animated:YES completion:^{
  1634. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1635. DebugLog(@"EditModelPriceViewController present.........");
  1636. // self.btop = false;
  1637. // <#code#>
  1638. }];
  1639. #endif
  1640. }
  1641. -(void)refresh_total
  1642. {
  1643. self.total=0;
  1644. self.total_carton=0;
  1645. self.total_cuft=0;
  1646. self.total_weight=0;
  1647. self.total_QTY=0;
  1648. self.total_item=0;
  1649. self.surcharge=0;
  1650. #ifdef SCANNER_ORDER
  1651. NSString* pricename;
  1652. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  1653. NSString* servername = [addressDic objectForKey:@"show_name"];
  1654. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  1655. NSString * shortname = arrsn[0];
  1656. if(shortname.length==0)
  1657. shortname = servername;
  1658. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1659. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1660. switch(RASingleton.sharedInstance.price_type )
  1661. {
  1662. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  1663. break;;
  1664. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  1665. break;;
  1666. // case 2: pricename = @"25%";
  1667. // break;
  1668. }
  1669. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  1670. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  1671. [self.cartIndicatorBar removeFromSuperview];
  1672. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1673. [self.view addSubview:self.cartIndicatorBar];
  1674. #endif
  1675. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1676. for(int i=0;i<count;i++)
  1677. {
  1678. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1679. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  1680. if(bcheck)
  1681. {
  1682. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  1683. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  1684. int count=[[item_json valueForKey:@"count"] intValue];
  1685. double totalprice =count*unitprice*(1-discount/100.0);
  1686. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  1687. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  1688. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  1689. int item_count=1;
  1690. int item_qty=1;
  1691. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  1692. // surcharge = unit_surcharge * qty
  1693. double msurcharge = [[item_json valueForKey:@"unit_surcharge"] doubleValue] * count;
  1694. // double dprice=0;
  1695. // if(bundle_item!=nil)
  1696. // {
  1697. // // int citem=0;
  1698. //
  1699. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  1700. // for(int bc=0;bc<bcount;bc++)
  1701. // {
  1702. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1703. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1704. // // citem+= modulus;
  1705. // item_count+=1;
  1706. // item_qty+=modulus;
  1707. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1708. // dprice+= uprice*modulus*count;
  1709. //
  1710. // }
  1711. // }
  1712. // totalprice+= dprice;
  1713. self.surcharge+=msurcharge;
  1714. self.total+=totalprice;
  1715. self.total_cuft+=cuft;
  1716. self.total_carton+=carton;
  1717. self.total_weight+=weight;
  1718. self.total_item+=item_count;
  1719. self.total_QTY+=(item_qty)*count;
  1720. }
  1721. }
  1722. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  1723. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  1724. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  1725. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  1726. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  1727. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  1728. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  1729. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  1730. #ifndef SCANNER_ORDER
  1731. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1732. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1733. {
  1734. }
  1735. else
  1736. {
  1737. subtotal=nil;
  1738. }
  1739. #else
  1740. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1741. [OLDataProvider updateScanOrder:appDelegate.order_code];
  1742. #endif
  1743. self.labelTotalSurcharge.text = surcharge;
  1744. self.labelTotalPrice.text = totalprice;
  1745. self.labelTotal.text=subtotal;
  1746. self.labelScanSubtotal.text = subtotal;
  1747. self.label_cuft.text=subcuft;
  1748. self.label_carton.text=subcarton;
  1749. self.label_weight.text=subweight;
  1750. self.label_items.text = subitems;
  1751. self.label_qty.text = subqty;
  1752. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  1753. }
  1754. - (IBAction)onEditGeneralNotes:(id)sender {
  1755. #ifndef SCANNER_ORDER
  1756. if (![self isOrderAvailable]) {
  1757. return;
  1758. }
  1759. #endif
  1760. UIViewController* parentvc=self;
  1761. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  1762. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1763. vc.notes=self.notes;
  1764. // vc.delegate = parentvc.self;
  1765. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1766. vc.onSetValue = ^(NSString* notes){
  1767. self.notes = notes;
  1768. [self refresh_total];
  1769. };
  1770. //
  1771. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1772. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1773. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1774. [parentvc presentViewController:navi animated:YES completion:^{
  1775. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1776. DebugLog(@"general notes editor present.........");
  1777. // self.btop = false;
  1778. // <#code#>
  1779. }];
  1780. }
  1781. - (IBAction)OnCancelOrderClicked:(id)sender {
  1782. }
  1783. #pragma mark - Private
  1784. - (BOOL)isOrderAvailable {
  1785. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1786. if (appDelegate.order_code.length == 0) {
  1787. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  1788. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1789. }];
  1790. [alertVC addAction:okAction];
  1791. [self presentViewController:alertVC animated:YES completion:nil];
  1792. return NO;
  1793. }
  1794. return YES;
  1795. }
  1796. #pragma mark - commoneditor controller delegate
  1797. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1798. {
  1799. // [self reload_data];
  1800. if([value[@"commitorder_logout"] boolValue])
  1801. [self logout];
  1802. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1803. }
  1804. #pragma mark - Table view data source
  1805. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1806. {
  1807. NSDictionary * item_json = nil;
  1808. if (self.back_order_flag) {
  1809. item_json = [self itemJsonAtIndexPath:indexPath];
  1810. } else {
  1811. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1812. }
  1813. NSString* notes =[item_json valueForKey:@"note"];
  1814. if(notes.length>0)
  1815. {
  1816. return 146;
  1817. }
  1818. else
  1819. return 120;
  1820. }
  1821. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1822. //{
  1823. // return 0;
  1824. //}
  1825. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1826. //{
  1827. // return 0;
  1828. //}
  1829. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1830. //{
  1831. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1832. // return myView;
  1833. //
  1834. //}
  1835. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1836. //{
  1837. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1838. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1839. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1840. //// titleLabel.textColor=[UIColor whiteColor];
  1841. //// titleLabel.backgroundColor = [UIColor clearColor];
  1842. //// if(section==0)
  1843. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1844. //// else
  1845. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1846. //// [titleLabel sizeToFit];
  1847. //// [myView addSubview:titleLabel];
  1848. ////
  1849. // return myView;
  1850. //}
  1851. //
  1852. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1853. // if(section==0)
  1854. // return nil;
  1855. // else
  1856. // return @"detail section";
  1857. //}
  1858. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1859. {
  1860. if (self.back_order_flag) {
  1861. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  1862. } else {
  1863. return 1;
  1864. }
  1865. }
  1866. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1867. {
  1868. #ifdef SCANNER_ORDER
  1869. return 0;
  1870. #else
  1871. if (self.back_order_flag) {
  1872. return 50;
  1873. } else {
  1874. return 0;
  1875. }
  1876. #endif
  1877. }
  1878. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1879. {
  1880. #ifdef SCANNER_ORDER
  1881. return nil;
  1882. #else
  1883. if (self.back_order_flag) {
  1884. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  1885. // UILabel *title_lb = [header viewWithTag:8520];
  1886. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  1887. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  1888. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1889. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  1890. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1891. title_lb.font = [UIFont systemFontOfSize:25.0f];
  1892. title_lb.textColor = [UIColor whiteColor];
  1893. [header addSubview:title_lb];
  1894. title_lb.text = [self titleForSection:section];
  1895. return header;
  1896. } else {
  1897. return nil;
  1898. }
  1899. #endif
  1900. }
  1901. #ifdef SCANNER_ORDER
  1902. - (IBAction)onScanChangeCustomerType:(id)sender {
  1903. return;
  1904. // NSString *orderdir =[OLDataProvider getScanPath];
  1905. //
  1906. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1907. // //block代码块取代了delegate
  1908. //
  1909. //
  1910. //
  1911. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1912. //
  1913. // NSMutableDictionary* dict = nil;
  1914. // NSString* ordertemplate = nil;
  1915. // if([RADataProvider getSiteHasERP])
  1916. // ordertemplate =@"e_order.json";
  1917. // else
  1918. // ordertemplate =@"e_order_noerp.json";
  1919. //
  1920. // dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1921. //
  1922. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1923. //
  1924. //
  1925. //
  1926. // [RAUtils dicttofile:orderPath dict:dict];
  1927. //
  1928. //
  1929. //
  1930. //
  1931. ////
  1932. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1933. ////
  1934. ////
  1935. ////
  1936. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1937. ////
  1938. //// [self scanPlaceOrder];
  1939. ////
  1940. // }];
  1941. //
  1942. // UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1943. // NSMutableDictionary* dict = nil;
  1944. // dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1945. //
  1946. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1947. //
  1948. //
  1949. //
  1950. // [RAUtils dicttofile:orderPath dict:dict];
  1951. //
  1952. //
  1953. //
  1954. ////
  1955. ////
  1956. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1957. ////
  1958. ////
  1959. ////
  1960. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1961. //// [self scanPlaceOrder];
  1962. // }];
  1963. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1964. // DebugLog(@"No");
  1965. // }];
  1966. // [alertControl addAction:actionOne];
  1967. // [alertControl addAction:alert2];
  1968. // [alertControl addAction:alertthree];
  1969. //
  1970. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1971. //
  1972. //
  1973. // [self presentViewController:alertControl animated:YES completion:nil];
  1974. //
  1975. // DebugLog(@"%@",self.edit_select_arr);
  1976. }
  1977. #endif
  1978. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1979. {
  1980. if (self.back_order_flag) {
  1981. return [self itemCountInSection:section];
  1982. } else {
  1983. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1984. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1985. return count;
  1986. }
  1987. }
  1988. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1989. {
  1990. // if(tableView==self.itemListTable)
  1991. // {
  1992. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1993. NSString *CellIdentifier;
  1994. #ifdef SCANNER_ORDER
  1995. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1996. CellIdentifier = @"ScanCartItemCell";
  1997. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1998. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1999. item_json = [self itemJsonAtIndexPath:indexPath];
  2000. NSString* notes = [item_json valueForKey:@"note"];
  2001. if(notes.length>0)
  2002. {
  2003. cell.labelNotes.text = notes;
  2004. }
  2005. else
  2006. {
  2007. cell.labelNotes.text = nil;
  2008. }
  2009. NSString* description =[item_json valueForKey:@"description"];
  2010. NSString* model =[item_json valueForKey:@"model"];
  2011. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2012. int count =[[item_json valueForKey:@"count"] intValue];
  2013. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2014. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2015. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2016. cell.discount = discount;
  2017. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2018. {
  2019. cell.btnScanDiscount.hidden = true;
  2020. }
  2021. else
  2022. {
  2023. switch(RASingleton.sharedInstance.price_type)
  2024. {
  2025. case 0: cell.btnScanDiscount.hidden = true;
  2026. break;;
  2027. case 1:
  2028. {
  2029. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2030. cell.btnScanDiscount.hidden = false;
  2031. else
  2032. cell.btnScanDiscount.hidden = true;
  2033. }
  2034. break;;
  2035. // case 2: pricename = @"25%";
  2036. // break;
  2037. }
  2038. }
  2039. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2040. //
  2041. //
  2042. //
  2043. //
  2044. // CGRect frame = cell.frame;
  2045. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of: %d", stockUom];
  2046. __weak typeof(self) weakSelf = self;
  2047. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2048. {
  2049. int result = [[ext objectForKey:@"result"] intValue];
  2050. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2051. if (result == 2 && refresh) {
  2052. [self ReloadData];
  2053. return;
  2054. }
  2055. NSMutableDictionary * item_json = nil;
  2056. if (weakSelf.back_order_flag) {
  2057. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2058. } else {
  2059. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2060. }
  2061. // int count=[[item_json valueForKey:@"count"] intValue];
  2062. // if(count==qty)
  2063. // return;
  2064. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2065. return ;
  2066. }
  2067. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2068. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2069. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2070. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2071. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2072. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2073. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2074. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2075. if (weakSelf.back_order_flag) {
  2076. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2077. } else {
  2078. weakSelf.content_arr[indexPath.row]= item_json;
  2079. }
  2080. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2081. [weakSelf refresh_total];
  2082. #ifdef RA_NOTIFICATION
  2083. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2084. #else
  2085. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2086. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2087. #endif
  2088. };
  2089. // cell.delegate=self;
  2090. // cell.from=indexPath;
  2091. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2092. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2093. {
  2094. cell.labelUnitPrice.textColor= [UIColor redColor];
  2095. if([item_json[@"special_price"] boolValue]||discount>0)
  2096. {
  2097. cell.labelOldPrice.hidden = false;
  2098. // if([item_json[@"special_price"] boolValue])
  2099. // {
  2100. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[price_group[@"price_1"][@"name"]] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2101. // }
  2102. // else
  2103. // {
  2104. // }
  2105. }
  2106. else
  2107. cell.labelOldPrice.hidden = true;
  2108. }
  2109. else
  2110. {
  2111. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2112. cell.labelOldPrice.hidden = true;
  2113. }
  2114. // if(discount>0)
  2115. // {
  2116. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2117. // cell.labelOldPrice.hidden = false;
  2118. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2119. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2120. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2121. // frame.size.height = 120;
  2122. // }
  2123. // else
  2124. // {
  2125. //
  2126. //
  2127. // cell.labelOldPrice.hidden = true;
  2128. // cell.labelNotes.text = nil;
  2129. // frame.size.height = 94;
  2130. // }
  2131. cell.unit_price = unitprice;
  2132. // cell.labelAttribute.text = attribute;
  2133. // cell.labelCurrency.text = currency;
  2134. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2135. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2136. cell.labelModel.text = model;
  2137. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2138. // if(noprice&&unitprice==0.0)
  2139. // {
  2140. // cell.labelPrice.text = @"No Price";
  2141. //
  2142. // cell.labelUnitPrice.text = @"No Price";
  2143. // }
  2144. // else
  2145. {
  2146. cell.labelSubtotal.text = subtotal;
  2147. cell.labelUnitPrice.text = newunitprice;
  2148. }
  2149. // bool check = [[item_json valueForKey:@"check"] boolValue];
  2150. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2151. cell.cart_id = cart_item_id;
  2152. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2153. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2154. // else
  2155. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2156. [cell set_Count:count];
  2157. // Button 设置了大小约束,Size就不会随内容变化
  2158. cell.backgroundColor = [UIColor whiteColor];
  2159. return cell;
  2160. #else
  2161. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2162. CellIdentifier = @"CartItemCell";
  2163. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2164. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2165. if (self.back_order_flag) {
  2166. item_json = [self itemJsonAtIndexPath:indexPath];
  2167. } else {
  2168. item_json = self.content_arr[indexPath.row];
  2169. }
  2170. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2171. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2172. if (cell.masterBtn != nil) {
  2173. if (master_json == nil) {
  2174. cell.masterBtn.hidden = YES;
  2175. } else{
  2176. cell.masterBtn.hidden = NO;
  2177. cell.master_items = master_json;
  2178. }
  2179. }
  2180. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2181. NSString* notes = [item_json valueForKey:@"note"];
  2182. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2183. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  2184. cell.noprice = noprice;
  2185. cell.enable_longpress = true;
  2186. cell.bundle_item=combine_json;
  2187. NSString* img_url = [item_json valueForKey:@"img_url"];
  2188. NSString* description = [item_json valueForKey:@"description"];
  2189. // NSString* identifier = [item_json valueForKey:@"identifier"];
  2190. // NSString* attribute = [item_json valueForKey:@"attribute"];
  2191. // NSString* currency = [item_json valueForKey:@"currency"];
  2192. int count =[[item_json valueForKey:@"count"] intValue];
  2193. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2194. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2195. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2196. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2197. NSString* product_id = [item_json valueForKey:@"product_id"];
  2198. // handle no such model
  2199. if(product_id.length==0)
  2200. cell.labelNoSuchModel.hidden=false;
  2201. else
  2202. cell.labelNoSuchModel.hidden=true;
  2203. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2204. if (!is_out_of_stock) {
  2205. cell.labelOutOfStock.hidden = YES;
  2206. } else {
  2207. cell.labelOutOfStock.hidden = NO;
  2208. }
  2209. // } else {
  2210. // cell.labelOutOfStock.hidden = YES;
  2211. // }
  2212. // discount = 5.0;
  2213. cell.discount = discount;
  2214. CGRect frame = cell.frame;
  2215. if(notes.length>0)
  2216. {
  2217. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2218. frame.size.height = 146;
  2219. }
  2220. else
  2221. {
  2222. cell.labelNotes.text = nil;
  2223. frame.size.height = 120;
  2224. }
  2225. // cell.frame = frame;
  2226. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2227. if(isfree)
  2228. {
  2229. cell.labelOldPrice.hidden = false;
  2230. cell.labelOldPrice.textColor = [UIColor redColor];
  2231. cell.labelOldPrice.text=@"Free";
  2232. cell.labelOldPrice.hideline = true;
  2233. cell.labelDiscount.hidden = true;
  2234. }
  2235. else
  2236. {
  2237. cell.labelOldPrice.textColor = [UIColor blackColor];
  2238. cell.labelOldPrice.hideline = false;
  2239. if(discount==0)
  2240. {
  2241. cell.labelOldPrice.hidden = true;
  2242. cell.labelDiscount.hidden = true;
  2243. }
  2244. else
  2245. {
  2246. cell.labelOldPrice.hidden = false;
  2247. cell.labelDiscount.hidden = false;
  2248. }
  2249. }
  2250. __weak typeof(self) weakSelf = self;
  2251. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2252. {
  2253. int result = [[ext objectForKey:@"result"] intValue];
  2254. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2255. if (result == 2 && refresh) {
  2256. [self ReloadData];
  2257. return;
  2258. }
  2259. NSMutableDictionary * item_json = nil;
  2260. if (weakSelf.back_order_flag) {
  2261. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2262. } else {
  2263. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2264. }
  2265. // int count=[[item_json valueForKey:@"count"] intValue];
  2266. // if(count==qty)
  2267. // return;
  2268. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2269. return ;
  2270. }
  2271. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2272. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  2273. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2274. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2275. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2276. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2277. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2278. if (weakSelf.back_order_flag) {
  2279. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2280. } else {
  2281. weakSelf.content_arr[indexPath.row]= item_json;
  2282. }
  2283. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2284. [weakSelf refresh_total];
  2285. #ifdef RA_NOTIFICATION
  2286. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2287. #else
  2288. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2289. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2290. #endif
  2291. };
  2292. // cell.delegate=self;
  2293. // cell.from=indexPath;
  2294. cell.unit_price = unitprice;
  2295. // cell.labelAttribute.text = attribute;
  2296. // cell.labelCurrency.text = currency;
  2297. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  2298. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  2299. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  2300. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2301. {
  2302. }
  2303. else
  2304. {
  2305. oldprice=nil;
  2306. newprice=nil;
  2307. newunitprice=nil;
  2308. }
  2309. cell.labelDiscount.text = discountstr;
  2310. cell.labelOldPrice.text = oldprice;
  2311. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of: %d", stockUom];
  2312. cell.labelDescription.text = description;
  2313. // cell.labelIdentifier.text = identifier;
  2314. if(noprice&&unitprice==0.0)
  2315. {
  2316. cell.labelPrice.text = @"No Price";
  2317. cell.labelUnitPrice.text = @"No Price";
  2318. }
  2319. else
  2320. {
  2321. cell.labelPrice.text = newprice;
  2322. cell.labelUnitPrice.text = newunitprice;
  2323. }
  2324. bool check = [[item_json valueForKey:@"check"] boolValue];
  2325. if(check)
  2326. {
  2327. cell.img_checkmark.hidden=false;
  2328. // [item_json setValue:@"0" forKey:@"check"];
  2329. }
  2330. else
  2331. {
  2332. // [item_json setValue:@"1" forKey:@"check"];
  2333. cell.img_checkmark.hidden=true;
  2334. }
  2335. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2336. cell.cart_id = cart_item_id;
  2337. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2338. {
  2339. #ifdef IGNORE_SOLD_IN_QTY
  2340. [cell init_Stepper:1 max:9999 min:1 value:count];
  2341. #else
  2342. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2343. #endif
  2344. }
  2345. // else
  2346. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2347. [cell set_Count:count];
  2348. // Button 设置了大小约束,Size就不会随内容变化
  2349. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  2350. #if __IPHONE_OS_VERSION_MIN_REQUIRED <150000
  2351. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2352. #endif
  2353. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2354. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2355. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2356. if (![cell.imageName isEqualToString:img_url]) {
  2357. cell.imageName = img_url;
  2358. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2359. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2360. NSString* file_name=[img_url lastPathComponent];
  2361. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2362. if(img_data!=nil)
  2363. {
  2364. UIImage * img =[UIImage imageWithData:img_data];
  2365. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2366. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2367. }
  2368. else
  2369. {
  2370. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2371. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2372. dispatch_async(dispatch_get_main_queue(), ^{
  2373. if(downloadimg_data!=nil)
  2374. {
  2375. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2376. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2377. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2378. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2379. }
  2380. else
  2381. {
  2382. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2383. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2384. }
  2385. });
  2386. });
  2387. }
  2388. }
  2389. cell.backgroundColor = [UIColor whiteColor];
  2390. if(self.itemListTable.editing)
  2391. {
  2392. cell.editCount.enabled = false;
  2393. cell.stepper.hidden=true;
  2394. }
  2395. else
  2396. {
  2397. cell.editCount.enabled=true;
  2398. cell.stepper.hidden=false;
  2399. }
  2400. return cell;
  2401. // }
  2402. // else
  2403. // {
  2404. // NSString *CellIdentifier = @"OrderInfoListItem";
  2405. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2406. // return cell;
  2407. // }
  2408. #endif
  2409. }
  2410. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  2411. {
  2412. if(!self.itemListTable.editing)
  2413. return;
  2414. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2415. NSMutableDictionary * item_json = nil;
  2416. if (self.back_order_flag) {
  2417. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2418. } else {
  2419. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2420. }
  2421. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2422. if ([self.edit_select_arr containsObject:cart_item_id])
  2423. {
  2424. [self.edit_select_arr removeObject:cart_item_id];
  2425. }
  2426. }
  2427. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2428. {
  2429. #ifdef SCANNER_ORDER
  2430. return;
  2431. #endif
  2432. NSMutableDictionary * item_json = nil;
  2433. if (self.back_order_flag) {
  2434. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2435. } else {
  2436. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2437. }
  2438. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2439. if(self.itemListTable.editing)
  2440. {
  2441. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2442. if (![self.edit_select_arr containsObject:cart_item_id]) {
  2443. [self.edit_select_arr addObject:cart_item_id];
  2444. }
  2445. return;
  2446. }
  2447. // no checkmark support anymore for cart
  2448. return;
  2449. }
  2450. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  2451. if(self.itemListTable.editing)
  2452. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  2453. else
  2454. return UITableViewCellEditingStyleDelete;
  2455. }
  2456. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  2457. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  2458. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  2459. {
  2460. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2461. // 添加一个删除按钮
  2462. self.indexPath=indexPath;
  2463. NSMutableDictionary * item_json = nil;
  2464. if (self.back_order_flag) {
  2465. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2466. } else {
  2467. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2468. }
  2469. NSString* productID = [item_json valueForKey:@"product_id"];
  2470. // BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2471. __weak typeof(self) weakself = self;
  2472. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2473. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@" Delete " handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2474. DebugLog(@"delete click");
  2475. //[self.itemListTable setEditing:false animated:YES];
  2476. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  2477. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2478. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2479. NSMutableDictionary * item_json = nil;
  2480. if (self.back_order_flag) {
  2481. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2482. } else {
  2483. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2484. }
  2485. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  2486. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  2487. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Model" completion:nil];
  2488. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  2489. NSMutableDictionary* cart_json = result;
  2490. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2491. [pop hide];
  2492. if([[cart_json valueForKey:@"result"] intValue]==2)
  2493. {
  2494. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2495. if (self.back_order_flag) {
  2496. NSInteger section_count = [self sectionCount];
  2497. for (int i = 0; i < section_count; i++) {
  2498. NSInteger item_count = [self itemCountInSection:i];
  2499. BOOL ready_break = NO;
  2500. for (int j = 0; j < item_count; j++) {
  2501. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2502. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  2503. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2504. if([_id isEqualToString:ids])
  2505. {
  2506. [self updateItemJson:nil atIndexPath:indexPath];
  2507. ready_break = YES;
  2508. break;
  2509. }
  2510. }
  2511. if (ready_break) {
  2512. break;
  2513. }
  2514. }
  2515. } else {
  2516. for(int i=0;i<self.content_arr.count;i++)
  2517. {
  2518. NSDictionary* obj_json = self.content_arr[i];
  2519. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2520. if([_id isEqualToString:ids])
  2521. {
  2522. [self.content_arr removeObjectAtIndex:i];
  2523. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2524. break;
  2525. // appDelegate.cart_count--;
  2526. // [appDelegate update_count_mark];
  2527. }
  2528. }
  2529. }
  2530. #ifdef SCANNER_ORDER
  2531. self.cart_json = cart_json;
  2532. #endif
  2533. [self.itemListTable reloadData];
  2534. [self refresh_total];
  2535. #ifdef RA_NOTIFICATION
  2536. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2537. #else
  2538. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2539. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2540. #endif
  2541. // [self reload_data];
  2542. }
  2543. else
  2544. {
  2545. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2546. }
  2547. // }];
  2548. }];
  2549. // }];
  2550. }];
  2551. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2552. }];
  2553. [alertController addAction:action_2];
  2554. [alertController addAction:action_3];
  2555. [self presentViewController:alertController animated:YES completion:nil];
  2556. // 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];
  2557. // alert.tag = ALERT_DEL;
  2558. // // alert.
  2559. // [alert show];
  2560. }];
  2561. deleteRowAction.backgroundColor = [UIColor redColor];
  2562. UIContextualAction* notifyMeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Notify Me" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2563. {
  2564. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2565. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2566. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2567. NSMutableDictionary *dic = result;
  2568. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2569. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2570. [pop hide];
  2571. int result_code = [[dic valueForKey:@"result"] intValue];
  2572. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2573. {
  2574. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2575. if ([dic valueForKey:@"err_msg"]) {
  2576. msg = [dic valueForKey:@"err_msg"];
  2577. }
  2578. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2579. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2580. }];
  2581. [errorAlertVC addAction:action];
  2582. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2583. } else if (result_code == RESULT_TRUE){
  2584. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2585. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2586. [weakself showAddressBoxToEmailProduct:productID];
  2587. }
  2588. // }];
  2589. }];
  2590. // }];
  2591. };
  2592. }];
  2593. // UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2594. //
  2595. // {
  2596. //
  2597. //// __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2598. // PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2599. // [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2600. // NSMutableDictionary *dic = result;
  2601. //
  2602. //
  2603. // // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2604. //// [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2605. // [pop hide];
  2606. // int result_code = [[dic valueForKey:@"result"] intValue];
  2607. //
  2608. // if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2609. // {
  2610. //
  2611. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2612. //
  2613. // if ([dic valueForKey:@"err_msg"]) {
  2614. // msg = [dic valueForKey:@"err_msg"];
  2615. // }
  2616. //
  2617. //
  2618. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2619. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2620. //
  2621. // }];
  2622. //
  2623. // [errorAlertVC addAction:action];
  2624. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2625. //
  2626. // } else if (result_code == RESULT_TRUE){
  2627. //
  2628. // [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2629. //
  2630. // } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2631. //
  2632. // [weakself showAddressBoxToEmailProduct:productID];
  2633. //
  2634. // }
  2635. //// }];
  2636. //
  2637. //
  2638. //
  2639. // }];
  2640. //
  2641. //// }];
  2642. //
  2643. // };
  2644. //
  2645. //
  2646. // }];
  2647. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  2648. // UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2649. UIContextualAction* addWatchAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Move To Wish List" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2650. DebugLog(@"Wishlist click");
  2651. NSMutableDictionary * item_json = nil;
  2652. if (self.back_order_flag) {
  2653. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2654. } else {
  2655. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2656. }
  2657. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2658. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2659. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2660. NSDictionary* return_json = result;
  2661. if([[return_json valueForKey:@"result"] intValue]==2)
  2662. {
  2663. #ifdef RA_NOTIFICATION
  2664. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2665. #else
  2666. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2667. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  2668. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2669. #endif
  2670. for(int i=0;i<self.content_arr.count;i++)
  2671. {
  2672. NSDictionary* obj_json = self.content_arr[i];
  2673. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2674. if([_id isEqualToString:cart_item_id])
  2675. {
  2676. if (self.back_order_flag) {
  2677. [self updateItemJson:nil atIndexPath:indexPath];
  2678. } else {
  2679. [self.content_arr removeObjectAtIndex:i];
  2680. }
  2681. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2682. appDelegate.cart_count--;
  2683. [appDelegate update_count_mark];
  2684. [self refresh_total];
  2685. }
  2686. }
  2687. [self.itemListTable reloadData];
  2688. }
  2689. else
  2690. {
  2691. [RAUtils message_box:@"Move To Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2692. }
  2693. }];
  2694. }];
  2695. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  2696. // 添加一个编辑按钮
  2697. // UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2698. UIContextualAction* editRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Edit Price" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2699. DebugLog(@"edit click");
  2700. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2701. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  2702. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  2703. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2704. [alert dismissViewControllerAnimated:YES completion:nil];
  2705. }];
  2706. [alert addAction:action];
  2707. if (weakself) {
  2708. __strong typeof(weakself) strongself = weakself;
  2709. [strongself presentViewController:alert animated:YES completion:nil];
  2710. }
  2711. return ;
  2712. }
  2713. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  2714. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  2715. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2716. [alert dismissViewControllerAnimated:YES completion:nil];
  2717. }];
  2718. [alert addAction:action];
  2719. if (weakself) {
  2720. __strong typeof(weakself) strongself = weakself;
  2721. [strongself presentViewController:alert animated:YES completion:nil];
  2722. }
  2723. return ;
  2724. }
  2725. }
  2726. UIViewController* parentvc=self;
  2727. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  2728. NSMutableDictionary * item_json = nil;
  2729. if (self.back_order_flag) {
  2730. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2731. } else {
  2732. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2733. }
  2734. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2735. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2736. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2737. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2738. // vc.delegate = parentvc.self;
  2739. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2740. vc.onSetValue = ^(double price,double discount){
  2741. bool bmodify=false;
  2742. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  2743. bmodify=true;
  2744. NSString* notes = [item_json valueForKey:@"note"];
  2745. if(notes.length==0)
  2746. notes=@"";
  2747. if(bmodify)
  2748. {
  2749. if([notes isEqualToString:@""])
  2750. notes=@"PRICE MODIFIED";
  2751. NSRange range;
  2752. range = [notes rangeOfString:@"PRICE MODIFIED"];
  2753. if (range.location != NSNotFound) {
  2754. }else{
  2755. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2756. }
  2757. }
  2758. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2759. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  2760. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  2761. NSDictionary* cart_json = result;
  2762. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2763. [pop hide];
  2764. if([[cart_json valueForKey:@"result"] intValue]==2)
  2765. {
  2766. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2767. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2768. [item_json setValue:notes forKey:@"note"];
  2769. if (self.back_order_flag) {
  2770. [self updateItemJson:item_json atIndexPath:indexPath];
  2771. } else {
  2772. self.content_arr[indexPath.row ] = item_json;
  2773. }
  2774. tableView.editing = false;
  2775. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2776. // [self refresh_total];
  2777. [weakself reload_data];
  2778. #ifdef RA_NOTIFICATION
  2779. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2780. #else
  2781. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2782. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2783. #endif
  2784. }
  2785. else
  2786. {
  2787. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2788. }
  2789. // }];
  2790. }];
  2791. // }];
  2792. // [self reload_data];//[main_vc checklogin:true];
  2793. };
  2794. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2795. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2796. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2797. [parentvc presentViewController:navi animated:YES completion:^{
  2798. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2799. DebugLog(@"EditModelPriceViewController present.........");
  2800. // self.btop = false;
  2801. // <#code#>
  2802. }];
  2803. // [self.itemListTable setEditing:false animated:YES];
  2804. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2805. }];
  2806. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  2807. // // 添加一个更多按钮
  2808. //
  2809. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2810. //
  2811. // DebugLog(@点击了更多);
  2812. //
  2813. //
  2814. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2815. //
  2816. // }];
  2817. //
  2818. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  2819. //
  2820. // 将设置好的按钮放到数组中返回
  2821. // UITableViewRowAction *freeRowAction = nil;
  2822. //
  2823. //
  2824. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2825. //
  2826. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2827. //
  2828. // if(!isfree)
  2829. // {
  2830. //
  2831. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2832. //
  2833. // DebugLog(@"free click");
  2834. //
  2835. //
  2836. //
  2837. // 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];
  2838. // alert.tag = ALERT_SET_FREE;
  2839. // // alert.
  2840. // [alert show];
  2841. // }];
  2842. // }
  2843. // else
  2844. // {
  2845. //
  2846. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2847. //
  2848. // 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];
  2849. // alert.tag = ALERT_RESTORE_FREE;
  2850. // // alert.
  2851. // [alert show];
  2852. // }];
  2853. // }
  2854. //
  2855. //
  2856. //
  2857. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  2858. // UITableViewRowAction *noteRowAction = nil;
  2859. //
  2860. //
  2861. // // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2862. //
  2863. //
  2864. //
  2865. //
  2866. // noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2867. UIContextualAction* noteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Edit note" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2868. DebugLog(@"item note click");
  2869. UIViewController* parentvc=self;
  2870. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  2871. NSMutableDictionary * item_json = nil;
  2872. if (self.back_order_flag) {
  2873. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2874. } else {
  2875. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2876. }
  2877. vc.onSaveNote=^(NSString* notes){
  2878. [item_json setValue:notes forKey:@"note"];
  2879. if (self.back_order_flag) {
  2880. [self updateItemJson:item_json atIndexPath:indexPath];
  2881. } else {
  2882. self.content_arr[indexPath.row ] = item_json;
  2883. }
  2884. tableView.editing = false;
  2885. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2886. };
  2887. vc.notes=[item_json valueForKey:@"note"];
  2888. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2889. // vc.delegate = parentvc.self;
  2890. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2891. // vc.onSetValue = ^(){
  2892. // [self reload_data];//[main_vc checklogin:true];
  2893. // };
  2894. //
  2895. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2896. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2897. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2898. [parentvc presentViewController:navi animated:YES completion:^{
  2899. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2900. DebugLog(@"EditModelPriceViewController present.........");
  2901. // self.btop = false;
  2902. // <#code#>
  2903. }];
  2904. // [self.itemListTable setEditing:false animated:YES];
  2905. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2906. }];
  2907. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  2908. // UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2909. UIContextualAction* move2BackAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Move to Back Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2910. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  2911. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2912. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  2913. PopWaitAlert* pop = [RAUtils waiting_pop:@"Move To Back Order" completion:nil];
  2914. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2915. NSMutableDictionary* return_json =result ;
  2916. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2917. [pop hide];
  2918. if([[return_json valueForKey:@"result"] intValue]==2) {
  2919. [self reload_data];
  2920. } // if 2
  2921. else {
  2922. [RAUtils message_box:@"Move To Back Order" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2923. }
  2924. // }];
  2925. }];
  2926. // }];
  2927. }];
  2928. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  2929. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2930. {
  2931. NSMutableDictionary * item_json = nil;
  2932. if (self.back_order_flag) {
  2933. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2934. } else {
  2935. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2936. }
  2937. NSString* product_id = [item_json valueForKey:@"product_id"];
  2938. NSMutableArray* arr=[@[] mutableCopy];
  2939. if(product_id.length>0)
  2940. [arr addObject:noteRowAction];
  2941. [arr addObject:deleteRowAction];
  2942. // return arr;
  2943. return [UISwipeActionsConfiguration configurationWithActions:arr];
  2944. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  2945. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2946. if (appDelegate.customer_type == CustomerTypeStore) {
  2947. // return @[deleteRowAction];
  2948. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  2949. } else {
  2950. // normal
  2951. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  2952. NSMutableArray *actionArray = [NSMutableArray array];
  2953. // move to backorder
  2954. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  2955. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  2956. if (self.back_order_flag && available) {
  2957. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  2958. [actionArray addObject:move2BackAction];
  2959. }
  2960. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  2961. // edit price
  2962. NSMutableDictionary * item_json = nil;
  2963. if (self.back_order_flag) {
  2964. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2965. } else {
  2966. item_json = [self.content_arr[indexPath.row] mutableCopy];
  2967. }
  2968. NSString* product_id = [item_json valueForKey:@"product_id"];
  2969. int is_rate = [item_json[@"is_rate"] intValue];
  2970. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  2971. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  2972. [actionArray addObject:editRowAction];
  2973. }
  2974. // return actionArray;
  2975. return [UISwipeActionsConfiguration configurationWithActions:actionArray];
  2976. }
  2977. }
  2978. else
  2979. // return @[deleteRowAction];
  2980. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  2981. }
  2982. - (void)tableView:(UITableView *)tableView
  2983. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  2984. }
  2985. #pragma mark - Support scanner
  2986. -(void) onDecodedData:(NSString*) value
  2987. {
  2988. int cqty=0;
  2989. if (self.back_order_flag) {
  2990. NSInteger section_count = [self sectionCount];
  2991. for (int i = 0; i < section_count; i++) {
  2992. NSInteger item_count = [self itemCountInSection:i];
  2993. for (int j = 0; j < item_count; j++) {
  2994. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2995. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  2996. if([item[@"model"] isEqualToString:value]) {
  2997. cqty=[item[@"count"] intValue];
  2998. }
  2999. }
  3000. }
  3001. } else {
  3002. for(int i=0;i<self.content_arr.count;i++)
  3003. {
  3004. NSDictionary* item= self.content_arr[i];
  3005. if([item[@"model"] isEqualToString:value])
  3006. cqty=[item[@"count"]intValue];
  3007. }
  3008. }
  3009. if(cqty>0)
  3010. {
  3011. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  3012. //block代码块取代了delegate
  3013. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  3014. [self addtocart:value];
  3015. }];
  3016. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3017. DebugLog(@"No");
  3018. }];
  3019. [alertControl addAction:actionOne];
  3020. [alertControl addAction:alertthree];
  3021. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  3022. [self presentViewController:alertControl animated:YES completion:nil];
  3023. }
  3024. else
  3025. [self addtocart:value];
  3026. }
  3027. -(void) addtocart:(NSString*) modelname
  3028. {
  3029. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3030. NSDictionary* return_json =result;
  3031. if([[return_json valueForKey:@"result"] intValue]==2)
  3032. {
  3033. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  3034. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  3035. // bool isnew=false;
  3036. //
  3037. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3038. if (self.back_order_flag) {
  3039. NSInteger section_count = [self sectionCount];
  3040. for (int i = 0; i < section_count; i++) {
  3041. NSInteger item_count = [self itemCountInSection:i];
  3042. BOOL ready_break = NO;
  3043. for (int j = 0; j < item_count; j++) {
  3044. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3045. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3046. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3047. if([_id isEqualToString:item_id])
  3048. {
  3049. [self updateItemJson:nil atIndexPath:indexPath];
  3050. ready_break = YES;
  3051. break;
  3052. }
  3053. }
  3054. if (ready_break) {
  3055. break;
  3056. }
  3057. }
  3058. } else {
  3059. for(int i=0;i<self.content_arr.count;i++)
  3060. {
  3061. NSDictionary* obj_json = self.content_arr[i];
  3062. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3063. if([_id isEqualToString:item_id])
  3064. {
  3065. // self.content_arr[i] = newitem;
  3066. [self.content_arr removeObjectAtIndex:i];
  3067. break;
  3068. // [self.content_arr removeObjectAtIndex:i];
  3069. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3070. // appDelegate.cart_count--;
  3071. // [appDelegate update_count_mark];
  3072. }
  3073. }
  3074. }
  3075. AppDelegate *appDelegate =nil;
  3076. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3077. #ifdef OFFLINE_MODE
  3078. if(appDelegate.offline_mode)
  3079. {
  3080. [self ReloadData];
  3081. }
  3082. else
  3083. #endif
  3084. {
  3085. if (self.back_order_flag) {
  3086. [self ReloadData];
  3087. } else {
  3088. [self.content_arr insertObject:newitem atIndex:0];
  3089. [self.itemListTable reloadData];
  3090. [self refresh_total];
  3091. }
  3092. }
  3093. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3094. #ifdef RA_NOTIFICATION
  3095. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3096. #else
  3097. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  3098. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3099. #endif
  3100. }
  3101. else
  3102. {
  3103. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  3104. }
  3105. }];
  3106. }
  3107. #pragma mark - sort button
  3108. - (void)cartSortButtonClicked:(UIButton *)sender {
  3109. DebugLog(@"cart sort button clicked");
  3110. [self.view addSubview:self.sortItemController.view];
  3111. }
  3112. - (SortItemViewController *)sortItemController {
  3113. if (!_sortItemController) {
  3114. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  3115. _sortItemController.sortIndex = self.sortIndex;
  3116. _sortItemController.sortData = @[
  3117. @{@"title":@"Last",@"icon":@"TX_18"},
  3118. @{@"title":@"First",@"icon":@"TS_18"},
  3119. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  3120. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  3121. @{@"title":@"Description",@"icon":@"DX_18"},
  3122. ];
  3123. __weak typeof(self) weakSelf = self;
  3124. _sortItemController.sortBlock = ^(int sort){
  3125. weakSelf.sortIndex = sort;
  3126. [weakSelf reload_data];
  3127. };
  3128. }
  3129. // _sortItemController.sortIndex = self.sortIndex;
  3130. return _sortItemController;
  3131. }
  3132. - (SortButton *)sortButton {
  3133. if (!_sortButton) {
  3134. _sortButton = [SortButton sortButtonWithHeight:40];
  3135. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  3136. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  3137. }
  3138. return _sortButton;
  3139. }
  3140. - (void)setSortIndex:(int)sortIndex {
  3141. _sortIndex = sortIndex;
  3142. NSString *selectedImageName = @"";
  3143. switch (sortIndex) {
  3144. case 0:{
  3145. selectedImageName = @"TX_22";
  3146. }
  3147. break;
  3148. case 1:{
  3149. selectedImageName = @"TS_22";
  3150. }
  3151. break;
  3152. case 2:{
  3153. selectedImageName = @"IX_22";
  3154. }
  3155. break;
  3156. case 3:{
  3157. selectedImageName = @"IS_22";
  3158. }
  3159. break;
  3160. case 4:{
  3161. selectedImageName = @"DX_22";
  3162. }
  3163. break;
  3164. default:
  3165. break;
  3166. }
  3167. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  3168. }
  3169. #pragma mark - rotation
  3170. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3171. //
  3172. // self.sortItemController.view.frame = self.view.bounds;
  3173. //}
  3174. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  3175. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  3176. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3177. // what ever you want to prepare
  3178. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3179. // self.sortItemController.view.frame = self.view.bounds;
  3180. self.sortItemController.view.frame = self.view.bounds;
  3181. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3182. // [self.itemListTable reloadData];
  3183. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3184. [self layoutCartIndicatorBar];
  3185. }];
  3186. }
  3187. -(BOOL) shouldAutorotate
  3188. {
  3189. return YES;
  3190. }
  3191. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  3192. // return YES;
  3193. //}
  3194. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3195. // self.sortItemController.view.frame = self.view.bounds;
  3196. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3197. //
  3198. //// [self.itemListTable reloadData];
  3199. //
  3200. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3201. // [self layoutCartIndicatorBar];
  3202. //}
  3203. #pragma mark - notification action
  3204. - (void)priceTypeChanged:(id)notification {
  3205. [self reload_data];
  3206. #ifdef RA_NOTIFICATION
  3207. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3208. #else
  3209. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3210. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3211. #endif
  3212. }
  3213. #pragma mark - button action
  3214. - (IBAction)emailButtonClick:(UIButton *)sender {
  3215. if (![self isOrderAvailable]) {
  3216. return;
  3217. }
  3218. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3219. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  3220. emailAddrVC.textFiled.secureTextEntry = NO;
  3221. emailAddrVC.yesButtonTitle = @"send";
  3222. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3223. __weak typeof(self) weakself = self;
  3224. emailAddrVC.textHandler = ^(NSString *text){
  3225. // 验证邮箱格式是否正确
  3226. // NSString *match = EMAIL_MATCHES;
  3227. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3228. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3229. BOOL isEmailAddr = YES;
  3230. if (isEmailAddr) {
  3231. // 验证是邮件地址,发送邮件
  3232. [weakVC dismissViewControllerAnimated:YES completion:^{
  3233. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3234. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3235. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  3236. DebugLog(@"email cart result: %@",result);
  3237. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3238. [pop hide];
  3239. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  3240. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  3241. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  3242. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3243. }];
  3244. [errorAlertVC addAction:action];
  3245. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3246. }else {
  3247. [RAUtils message_box:@"Message" message:@"Send Email Success" completion:nil];
  3248. }
  3249. // }];
  3250. }];
  3251. // }];
  3252. }];
  3253. } else {
  3254. // 非邮件地址,警告
  3255. [weakVC warning:@"Please enter right email address"];
  3256. }
  3257. };
  3258. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3259. }
  3260. - (IBAction)printCartButtonClick:(UIButton *)sender {
  3261. if (![self isOrderAvailable]) {
  3262. return;
  3263. }
  3264. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  3265. ViewController.url = self.print_url;
  3266. ViewController.canSave = false;
  3267. ViewController.isLocalfile=NO;
  3268. NSString* subject;
  3269. subject =@"Cart Print";
  3270. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3271. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  3272. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  3273. if(customer_email.length>0)
  3274. {
  3275. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  3276. }
  3277. ViewController.mail_to = send_to;
  3278. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  3279. ViewController.mail_subject = subject;
  3280. ViewController.hidenavi = false;
  3281. [self.navigationController pushViewController:ViewController animated:YES];
  3282. }
  3283. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  3284. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3285. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  3286. emailAddrVC.textFiled.secureTextEntry = NO;
  3287. emailAddrVC.yesButtonTitle = @"send";
  3288. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3289. __weak typeof(self) weakself = self;
  3290. emailAddrVC.textHandler = ^(NSString *text){
  3291. // 验证邮箱格式是否正确
  3292. // NSString *match = EMAIL_MATCHES;
  3293. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3294. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3295. BOOL isEmailAddr = YES;
  3296. if (isEmailAddr) {
  3297. // 验证是邮件地址,发送邮件
  3298. [weakVC dismissViewControllerAnimated:YES completion:^{
  3299. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3300. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3301. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3302. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3303. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3304. [pop hide];
  3305. int resultStatus = [[result objectForKey:@"result"] intValue];
  3306. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  3307. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3308. if ([result valueForKey:@"err_msg"]) {
  3309. msg = [result valueForKey:@"err_msg"];
  3310. }
  3311. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3312. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3313. }];
  3314. [errorAlertVC addAction:action];
  3315. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3316. }else if(resultStatus == RESULT_TRUE){
  3317. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  3318. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  3319. [weakself showAddressBoxToEmailProduct:productID];
  3320. }
  3321. // }];
  3322. }];
  3323. // }];
  3324. }];
  3325. } else {
  3326. // 非邮件地址,警告
  3327. [weakVC warning:@"Please enter right email address"];
  3328. }
  3329. };
  3330. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3331. }
  3332. #pragma mark - Back Order
  3333. - (void) setCart_json:(NSDictionary *)cart_json {
  3334. _cart_json = cart_json;
  3335. [self fillContentArray];
  3336. }
  3337. - (void)fillContentArray {
  3338. NSMutableArray *arr = [NSMutableArray array];
  3339. for (int i = 0; i < [self sectionCount]; i++) {
  3340. NSInteger item_count = [self itemCountInSection:i];
  3341. for (int j = 0; j < item_count; j++) {
  3342. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  3343. [arr addObject:item];
  3344. }
  3345. }
  3346. self.content_arr = arr;
  3347. [self refresh_total];
  3348. }
  3349. - (NSInteger)sectionCount {
  3350. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  3351. }
  3352. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  3353. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  3354. }
  3355. - (NSInteger)itemCountInSection:(NSInteger)section {
  3356. NSDictionary *section_json = [self jsonAtSection:section];
  3357. return [[section_json objectForKey:@"count"] integerValue];
  3358. }
  3359. - (NSString *)titleForSection:(NSInteger)section {
  3360. NSDictionary *section_json = [self jsonAtSection:section];
  3361. return [section_json objectForKey:@"title"];
  3362. }
  3363. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  3364. NSDictionary *section = [self jsonAtSection:indexPath.section];
  3365. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  3366. }
  3367. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  3368. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  3369. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  3370. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  3371. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  3372. if (new_item_json) {
  3373. // 更新Item
  3374. [new_section_json setObject:new_item_json forKey:item_key];
  3375. } else {
  3376. // 删除Item
  3377. NSInteger item_count = [self itemCountInSection:indexPath.section];
  3378. for (NSInteger i = 0; i < item_count; i++) {
  3379. if (i >= indexPath.row) {
  3380. if (i < item_count - 1) {
  3381. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  3382. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  3383. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3384. [new_section_json setObject:followed_item_json forKey:item_key];
  3385. } else {
  3386. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3387. [new_section_json removeObjectForKey:item_key];
  3388. }
  3389. }
  3390. }
  3391. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  3392. }
  3393. [new_cart_json setObject:new_section_json forKey:section_key];
  3394. self.cart_json = [new_cart_json copy];
  3395. }
  3396. - (void)reRefreshView {
  3397. [self.itemListTable reloadData];
  3398. }
  3399. #pragma mark - RA_NOTIFICAITON
  3400. -(void) refresh_ui
  3401. {
  3402. [self.itemListTable reloadData];
  3403. [self refresh_total];
  3404. }
  3405. -(void) refresh_price
  3406. {
  3407. [self refresh_ui];
  3408. }
  3409. - (void) reload_data {
  3410. __weak typeof(self) weakself = self;
  3411. self.currentOrderIsMerged = NO;
  3412. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  3413. if (weakself) {
  3414. __strong typeof(weakself) strongself = weakself;
  3415. [strongself operation_reload_data];
  3416. }
  3417. }];
  3418. [self.dataOperationQueue addOperation:operation];
  3419. }
  3420. @end