CartViewController.m 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824
  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. [self updateSurchargeForCartSection];
  803. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  804. // [self refresh_total];
  805. // [self refresh_ui];
  806. }
  807. //-(void)SelectOrder:(NSString *)orderid
  808. //{
  809. //// self.editOrderID.text=orderid;
  810. //// self.btnAddToOrder.enabled = true;
  811. //}
  812. - (void)didReceiveMemoryWarning
  813. {
  814. [super didReceiveMemoryWarning];
  815. // Dispose of any resources that can be recreated.
  816. }
  817. //- (IBAction)stepperAction:(UIStepper *)sender {
  818. //
  819. //
  820. //}
  821. - (IBAction)onContinueShoppingClick:(id)sender {
  822. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  823. [appDelegate switchToPreviousVC];
  824. }
  825. - (IBAction)onOrderDiscount:(id)sender {
  826. }
  827. - (IBAction)onPlaceOrder:(UIButton *)sender {
  828. #ifndef SCANNER_ORDER
  829. if (![self isOrderAvailable]) {
  830. return;
  831. }
  832. #endif
  833. [self placeOrder];
  834. }
  835. -(void) scanPlaceOrder
  836. {
  837. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  838. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  839. // NSString * string = [checked componentsJoinedByString:@","];
  840. // [params setValue:string forKey:@"cart2Checkbox"];
  841. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  842. // NSError *error=nil;
  843. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  844. //
  845. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  846. // NSString *documents = [paths objectAtIndex:0];
  847. NSString *orderdir = [OLDataProvider getScanPath];
  848. NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  849. int section_count = [dict[@"section_count"] intValue];
  850. for(int i=0;i<section_count;i++)
  851. {
  852. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  853. NSString* title = section[@"title"];
  854. if([title isEqualToString:@"Model Information"])
  855. {
  856. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  857. int cart_count = [cart_section[@"count"] intValue];
  858. for(int j=0;j<cart_count;j++)
  859. {
  860. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  861. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  862. cart_item[@"control"]=@"model";
  863. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  864. }
  865. section[@"count"] = @(cart_count);
  866. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  867. }
  868. else
  869. if([title isEqualToString:@"Customer"])
  870. {
  871. int scount = [section[@"count"] intValue];
  872. for(int j=0;j<scount;j++)
  873. {
  874. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  875. NSString * name = item[@"name"];
  876. if([name isEqualToString:@"business_card"])
  877. {
  878. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  879. for(int l=0;l<arr.count;l++)
  880. {
  881. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  882. }
  883. }
  884. else
  885. {
  886. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  887. item[@"value"]=appDelegate.customerInfo[name];
  888. }
  889. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  890. }
  891. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  892. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  893. }
  894. else
  895. if([title isEqualToString:@"Remarks Content"])
  896. {
  897. int scount = [section[@"count"] intValue];
  898. for(int j=0;j<scount;j++)
  899. {
  900. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  901. NSString * name = item[@"name"];
  902. if([name isEqualToString:@"comments"])
  903. {
  904. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  905. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  906. }
  907. }
  908. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  909. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  910. }
  911. else if([title isEqualToString:@"Order Total"])
  912. {
  913. int scount = [section[@"count"] intValue];
  914. for(int j=0;j<scount;j++)
  915. {
  916. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  917. NSString * name = item[@"name"];
  918. if([name isEqualToString:@"totalPrice"])
  919. {
  920. item[@"value"] = [RAConvertor currencyNumber:self.total+self.surcharge];//[NSString stringWithFormat:@"%.2f",self.total+self.surcharge];
  921. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  922. }
  923. else if([name isEqualToString:@"subtotalPrice"])
  924. {
  925. item[@"value"] = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"%.2f",self.total];
  926. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  927. }
  928. else if([name isEqualToString:@"surcharge"])
  929. {
  930. item[@"value"] = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"%.2f",self.surcharge];
  931. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  932. }
  933. }
  934. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  935. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  936. }
  937. }
  938. // NSString *path = NSTemporaryDirectory();
  939. //
  940. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  941. // NSString *filePath = [path stringByAppendingPathComponent:file];
  942. //
  943. //
  944. //
  945. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  946. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  947. orderinfoVC.disable_dropdown_refresh=true;
  948. orderinfoVC.url_type = URL_FILE;
  949. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  950. orderinfoVC.params = params;
  951. orderinfoVC.title=@"";
  952. orderinfoVC.delegate=self;
  953. //
  954. // if(checked.count==count)
  955. // {
  956. // orderinfoVC.have_tail = true
  957. // }
  958. [self.navigationController pushViewController:orderinfoVC animated:true];
  959. return;
  960. }
  961. - (IBAction)onBulkDiscount:(id)sender {
  962. #ifdef SCANNER_ORDER
  963. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  964. vc.bulk = true;
  965. vc.discount=0;
  966. // vc.price = 0;
  967. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  968. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  969. // vc.delegate = parentvc.self;
  970. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  971. vc.onSetValue = ^(double price,double discount){
  972. bool bmodify=false;
  973. if(discount>0)
  974. bmodify=true;
  975. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  976. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  977. [RANetwork request_scan_bulkdiscount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  978. NSDictionary* cart_json = result;
  979. // [waitalert dismissViewControllerAnimated:YES completion:^{
  980. [pop hide];
  981. if([[cart_json valueForKey:@"result"] intValue]==2)
  982. {
  983. [self reload_data];
  984. #ifdef RA_NOTIFICATION
  985. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  986. #else
  987. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  988. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  989. #endif
  990. }
  991. else
  992. {
  993. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  994. }
  995. // }];
  996. }];
  997. // }];
  998. };
  999. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1000. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1001. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1002. [self presentViewController:navi animated:YES completion:^{
  1003. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1004. DebugLog(@"EditModelPriceViewController present.........");
  1005. // self.btop = false;
  1006. // <#code#>
  1007. }];
  1008. #endif
  1009. }
  1010. - (IBAction)onChangePrice:(id)sender {
  1011. #ifdef SCANNER_ORDER
  1012. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1013. if(RASingleton.sharedInstance.scan_cart ==nil)
  1014. {
  1015. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1016. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1017. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1018. }
  1019. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1020. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change Price Type" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1021. UIAlertAction *action1 = [UIAlertAction actionWithTitle:price_group[@"price_0"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1022. self.btnBulkDiscount.hidden = true;
  1023. // self.btnPrice.titleLabel.text = @"FOB CTNR";
  1024. [self.btnPrice setTitle: price_group[@"price_0"][@"display"] forState:UIControlStateNormal];
  1025. RASingleton.sharedInstance.price_type=0;
  1026. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1027. int count = [section[@"count"] intValue];
  1028. for(int i=0;i<count;i++)
  1029. {
  1030. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1031. item[@"price"]=item[ price_group[@"price_0"][@"name"]];
  1032. item[@"unit_price"]= item[price_group[@"price_0"][@"name"]];
  1033. item[@"erp_unit_price"]= item[price_group[@"price_0"][@"name"]];
  1034. item[@"discount"]=@(0);
  1035. item[@"note"]=@"";
  1036. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1037. }
  1038. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1039. RASingleton.sharedInstance.scan_cart[@"price_type"] = @0;
  1040. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1041. [self updateSurchargeForCartSection];
  1042. [self.cartIndicatorBar removeFromSuperview];
  1043. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1044. [self.view addSubview:self.cartIndicatorBar];
  1045. [self reload_data];
  1046. }];
  1047. UIAlertAction *action2 = [UIAlertAction actionWithTitle:price_group[@"price_1"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1048. self.btnBulkDiscount.hidden = false;
  1049. [self.btnPrice setTitle: price_group[@"price_1"][@"display"] forState:UIControlStateNormal];
  1050. RASingleton.sharedInstance.price_type=1;
  1051. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1052. int count = [section[@"count"] intValue];
  1053. for(int i=0;i<count;i++)
  1054. {
  1055. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1056. NSString * unit_price;
  1057. if(item [@"net_price"])
  1058. unit_price=item[price_group[@"price_3"][@"name"]];
  1059. else if(item [@"special_price"])
  1060. {
  1061. unit_price= item[price_group[@"price_2"][@"name"]];
  1062. }
  1063. else
  1064. {
  1065. unit_price= item[price_group[@"price_1"][@"name"]];
  1066. }
  1067. if([unit_price isEqualToString:@"N/A"])
  1068. unit_price = @"0";
  1069. else
  1070. {
  1071. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  1072. }
  1073. item[@"unit_price"] = unit_price;
  1074. item[@"erp_unit_price"] = unit_price;
  1075. item[@"price"]= unit_price;//item[@"price1"];
  1076. // item[@"unit_price"]= item[@"price1"];
  1077. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1078. }
  1079. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  1080. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1081. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1082. [self updateSurchargeForCartSection];
  1083. [self.cartIndicatorBar removeFromSuperview];
  1084. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1085. [self.view addSubview:self.cartIndicatorBar];
  1086. [self reload_data];
  1087. }];
  1088. //%25 逻辑应HMLG要求去掉
  1089. /*
  1090. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1091. // self.btnPrice.titleLabel.text = @"%25";
  1092. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1093. RASingleton.sharedInstance.price_type=2;
  1094. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1095. int count = [section[@"count"] intValue];
  1096. for(int i=0;i<count;i++)
  1097. {
  1098. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1099. item[@"price"]= item[price_group[@"price_2"][@"name"]];
  1100. item[@"unit_price"]= item[price_group[@"price_2"][@"name"]];
  1101. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1102. }
  1103. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1104. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1105. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1106. [self.cartIndicatorBar removeFromSuperview];
  1107. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1108. [self.view addSubview:self.cartIndicatorBar];
  1109. [self reload_data];
  1110. }];
  1111. */
  1112. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1113. }];
  1114. [alertControl addAction:action1];
  1115. [alertControl addAction:action2];
  1116. // [alertControl addAction:action3];
  1117. // [alertControl addAction:alertthree];
  1118. [alertControl addAction:alertCancel];
  1119. [self presentViewController:alertControl animated:YES completion:nil];
  1120. #endif
  1121. }
  1122. -(void) newoloorder
  1123. {
  1124. NSString *orderdir =[OLDataProvider getScanPath];
  1125. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1126. appDelegate.can_set_cart_price = true;
  1127. appDelegate.can_see_price = true;
  1128. {
  1129. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1130. {
  1131. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1132. //block代码块取代了delegate
  1133. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1134. NSMutableDictionary* dict = nil;
  1135. // NSMutableDictionary* dict = nil;
  1136. NSString* ordertemplate = nil;
  1137. if([RADataProvider getSiteHasERP])
  1138. ordertemplate =@"e_order.json";
  1139. else
  1140. ordertemplate =@"e_order_noerp.json";
  1141. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1142. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1143. [RAUtils dicttofile:orderPath dict:dict];
  1144. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1145. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1146. [self scanPlaceOrder];
  1147. }];
  1148. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1149. NSMutableDictionary* dict = nil;
  1150. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1151. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1152. [RAUtils dicttofile:orderPath dict:dict];
  1153. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1154. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1155. [self scanPlaceOrder];
  1156. }];
  1157. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1158. appDelegate.order_code = nil;
  1159. DebugLog(@"No");
  1160. }];
  1161. [alertControl addAction:actionOne];
  1162. [alertControl addAction:alert2];
  1163. [alertControl addAction:alertthree];
  1164. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1165. [self presentViewController:alertControl animated:YES completion:nil];
  1166. DebugLog(@"%@",self.edit_select_arr);
  1167. }
  1168. else
  1169. {
  1170. NSMutableDictionary* dict = nil;
  1171. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1172. {
  1173. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1174. }
  1175. else
  1176. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1177. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1178. [RAUtils dicttofile:orderPath dict:dict];
  1179. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1180. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1181. [self scanPlaceOrder];
  1182. }
  1183. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1184. }
  1185. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1186. // mainvc.btnScan.enabled = true;
  1187. // [appDelegate updateScanButton:true];
  1188. }
  1189. -(void) newoloorder1
  1190. {
  1191. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1192. appDelegate.can_set_cart_price = true;
  1193. appDelegate.can_see_price = true;
  1194. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1195. // NSString *documents = [paths objectAtIndex:0];
  1196. {
  1197. NSString *orderdir =[OLDataProvider getScanPath];
  1198. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1199. {
  1200. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1201. //block代码块取代了delegate
  1202. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1203. NSMutableDictionary* dict = nil;
  1204. NSString* ordertemplate = nil;
  1205. if([RADataProvider getSiteHasERP])
  1206. ordertemplate =@"e_order.json";
  1207. else
  1208. ordertemplate =@"e_order_noerp.json";
  1209. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1210. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1211. [RAUtils dicttofile:orderPath dict:dict];
  1212. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1213. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1214. [self scanPlaceOrder];
  1215. }];
  1216. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1217. NSMutableDictionary* dict = nil;
  1218. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1219. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1220. [RAUtils dicttofile:orderPath dict:dict];
  1221. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1222. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1223. [self scanPlaceOrder];
  1224. }];
  1225. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1226. appDelegate.order_code = nil;
  1227. DebugLog(@"No");
  1228. }];
  1229. [alertControl addAction:actionOne];
  1230. [alertControl addAction:alert2];
  1231. [alertControl addAction:alertthree];
  1232. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1233. [self presentViewController:alertControl animated:YES completion:nil];
  1234. DebugLog(@"%@",self.edit_select_arr);
  1235. }
  1236. else
  1237. {
  1238. NSMutableDictionary* dict = nil;
  1239. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1240. {
  1241. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1242. }
  1243. else
  1244. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1245. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1246. [RAUtils dicttofile:orderPath dict:dict];
  1247. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1248. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1249. [self scanPlaceOrder];
  1250. }
  1251. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1252. }
  1253. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1254. // mainvc.btnScan.enabled = true;
  1255. // [appDelegate updateScanButton:true];
  1256. }
  1257. -(void)newScanOrder1
  1258. {
  1259. //
  1260. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1261. //
  1262. //
  1263. // if(appDelegate.order_code.length>0)
  1264. // {
  1265. //// 当前订单先关闭
  1266. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1267. // appDelegate.order_code = nil;
  1268. // appDelegate.customerInfo = nil;
  1269. // RASingleton.sharedInstance.scan_cart = nil;
  1270. // appDelegate.contact_id = nil;
  1271. //// [appDelegate updateScanButton:false];
  1272. //
  1273. // [appDelegate update_count_mark];
  1274. // [appDelegate closeOrder];
  1275. //
  1276. // }
  1277. //
  1278. //
  1279. {
  1280. [self newoloorder1];
  1281. }
  1282. }
  1283. -(void)newScanOrder
  1284. {
  1285. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1286. {
  1287. [self newoloorder];
  1288. }
  1289. }
  1290. -(void)placeOrder
  1291. {
  1292. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1293. #ifndef SCANNER_ORDER
  1294. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1295. if (![RASingleton sharedInstance].permissions_edit_order) {
  1296. return;
  1297. }
  1298. }
  1299. #endif
  1300. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1301. bool have_free = false;
  1302. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1303. if(count==0)
  1304. {
  1305. [RAUtils message_box:@"Cart Is Empty." message:@"Add some model first." completion:nil] ;
  1306. return;
  1307. }
  1308. for(int i=0;i<count;i++)
  1309. {
  1310. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1311. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1312. NSString* product_id = [item_json valueForKey:@"product_id"];
  1313. // if(check)
  1314. // {
  1315. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1316. //
  1317. // }
  1318. if(product_id.length==0)
  1319. {
  1320. [RAUtils message_box:@"No Such Model" message:@"Some models in cart does not exist, you must remove them before place order." completion:nil] ;
  1321. return;
  1322. }
  1323. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1324. if(is_free)
  1325. have_free=true;
  1326. }
  1327. #ifdef SCANNER_ORDER
  1328. if(appDelegate.bLogin==false)
  1329. {
  1330. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1331. // loginvc.delegate = self;
  1332. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1333. loginvc.returnValue = ^(bool blogin){
  1334. if(blogin)
  1335. {
  1336. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1337. if(appDelegate.order_code.length==0)
  1338. {
  1339. [self newScanOrder];
  1340. }
  1341. }
  1342. };
  1343. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1344. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1345. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1346. [self presentViewController:navi animated:YES completion:^{
  1347. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1348. DebugLog(@"LoginViewController present.........");
  1349. // self.btop = false;
  1350. // <#code#>
  1351. }];
  1352. return;
  1353. }
  1354. else
  1355. {
  1356. NSString *orderdir =[OLDataProvider getScanPath];
  1357. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1358. if(appDelegate.order_code.length==0 )
  1359. {
  1360. [self newScanOrder];
  1361. }
  1362. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1363. {
  1364. [self newScanOrder1];
  1365. }
  1366. else
  1367. {
  1368. [self scanPlaceOrder];
  1369. //place order
  1370. }
  1371. return;
  1372. }
  1373. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1374. // {
  1375. //
  1376. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1377. // // NSString * string = [checked componentsJoinedByString:@","];
  1378. // // [params setValue:string forKey:@"cart2Checkbox"];
  1379. //
  1380. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1381. //// NSError *error=nil;
  1382. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1383. ////
  1384. //
  1385. //
  1386. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1387. // NSString *documents = [paths objectAtIndex:0];
  1388. //
  1389. //
  1390. //
  1391. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1392. //
  1393. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1394. //
  1395. // int section_count = [dict[@"section_count"] intValue];
  1396. //
  1397. // for(int i=0;i<section_count;i++)
  1398. // {
  1399. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1400. // NSString* title = section[@"title"];
  1401. // if([title isEqualToString:@"Model Information"])
  1402. // {
  1403. //
  1404. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1405. // int cart_count = [cart_section[@"count"] intValue];
  1406. // for(int j=0;j<cart_count;j++)
  1407. // {
  1408. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1409. // cart_item[@"control"]=@"model";
  1410. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1411. //
  1412. // }
  1413. // section[@"count"] = @(cart_count);
  1414. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1415. // }
  1416. // else
  1417. // if([title isEqualToString:@"Customer"])
  1418. // {
  1419. //
  1420. // int scount = [section[@"count"] intValue];
  1421. // for(int j=0;j<scount;j++)
  1422. // {
  1423. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1424. // NSString * name = item[@"name"];
  1425. //
  1426. // if([name isEqualToString:@"business_card"])
  1427. // {
  1428. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1429. // for(int l=0;l<arr.count;l++)
  1430. // {
  1431. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1432. // }
  1433. // }
  1434. // else
  1435. // item[@"value"]=appDelegate.customerInfo[name];
  1436. //
  1437. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1438. // }
  1439. //
  1440. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1441. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1442. //
  1443. //
  1444. // }
  1445. // else
  1446. // if([title isEqualToString:@"Remarks Content"])
  1447. // {
  1448. //
  1449. // int scount = [section[@"count"] intValue];
  1450. // for(int j=0;j<scount;j++)
  1451. // {
  1452. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1453. // NSString * name = item[@"name"];
  1454. //
  1455. //
  1456. // if([name isEqualToString:@"comments"])
  1457. // {
  1458. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1459. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1460. // }
  1461. //
  1462. //
  1463. // }
  1464. //
  1465. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1466. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1467. //
  1468. //
  1469. // }
  1470. // else if([title isEqualToString:@"Order Total"])
  1471. // {
  1472. //
  1473. // int scount = [section[@"count"] intValue];
  1474. // for(int j=0;j<scount;j++)
  1475. // {
  1476. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1477. // NSString * name = item[@"name"];
  1478. //
  1479. //
  1480. // if([name isEqualToString:@"totalPrice"])
  1481. // {
  1482. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  1483. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1484. // }
  1485. //
  1486. //
  1487. // }
  1488. //
  1489. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1490. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1491. //
  1492. //
  1493. //
  1494. // }
  1495. //
  1496. //
  1497. //
  1498. //
  1499. // }
  1500. //
  1501. //// NSString *path = NSTemporaryDirectory();
  1502. ////
  1503. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1504. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  1505. ////
  1506. ////
  1507. ////
  1508. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1509. //
  1510. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1511. //
  1512. //
  1513. //
  1514. // orderinfoVC.disable_dropdown_refresh=true;
  1515. // orderinfoVC.url_type = URL_FILE;
  1516. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1517. //
  1518. // orderinfoVC.params = params;
  1519. // orderinfoVC.title=@"";
  1520. // orderinfoVC.delegate=self;
  1521. // //
  1522. // // if(checked.count==count)
  1523. // // {
  1524. // // orderinfoVC.have_tail = true
  1525. // // }
  1526. //
  1527. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1528. //
  1529. // return;
  1530. // }
  1531. #endif
  1532. //#ifdef BACKORDER_PROCESS
  1533. // if (self.back_order_flag) {
  1534. //
  1535. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1536. // [params setObject:@(0) forKey:@"step"];
  1537. //
  1538. //
  1539. // RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  1540. //
  1541. //
  1542. // //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1543. //
  1544. // orderEditorVC.disable_dropdown_refresh=true;
  1545. // orderEditorVC.url_type = URL_REMOTE;
  1546. // orderEditorVC.request_url=URL_CARTDELIVERY;
  1547. // orderEditorVC.params = params;
  1548. // orderEditorVC.delegate=self;
  1549. // orderEditorVC.title=@"";
  1550. // [self.navigationController pushViewController:orderEditorVC animated:true];
  1551. //
  1552. // }
  1553. // else
  1554. //#endif
  1555. // {
  1556. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1557. // // NSString * string = [checked componentsJoinedByString:@","];
  1558. // // [params setValue:string forKey:@"cart2Checkbox"];
  1559. //
  1560. //
  1561. //
  1562. //
  1563. //
  1564. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1565. //
  1566. // orderinfoVC.disable_dropdown_refresh=true;
  1567. // orderinfoVC.url_type = URL_REMOTE;
  1568. // orderinfoVC.request_url=URL_CARTDELIVERY;
  1569. //
  1570. // orderinfoVC.params = params;
  1571. // orderinfoVC.title=@"";
  1572. // orderinfoVC.delegate=self;
  1573. // //
  1574. // // if(checked.count==count)
  1575. // // {
  1576. // // orderinfoVC.have_tail = true
  1577. // // }
  1578. //
  1579. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1580. // }
  1581. }
  1582. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  1583. {
  1584. return NO;
  1585. }
  1586. - (IBAction)onScanDiscount:(UIButton*)sender {
  1587. #ifdef SCANNER_ORDER
  1588. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1589. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  1590. UIViewController* parentvc=self;
  1591. // EditModelPriceViewController
  1592. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1593. NSMutableDictionary * item_json = nil;
  1594. if (self.back_order_flag) {
  1595. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  1596. } else {
  1597. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1598. }
  1599. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1600. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1601. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1602. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1603. // vc.delegate = parentvc.self;
  1604. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1605. vc.onSetValue = ^(double price,double discount){
  1606. bool bmodify=false;
  1607. if(discount>0)
  1608. bmodify=true;
  1609. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1610. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  1611. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1612. NSDictionary* cart_json = result;
  1613. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1614. [pop hide];
  1615. if([[cart_json valueForKey:@"result"] intValue]==2)
  1616. {
  1617. [self reload_data];
  1618. #ifdef RA_NOTIFICATION
  1619. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1620. #else
  1621. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1622. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1623. #endif
  1624. }
  1625. else
  1626. {
  1627. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  1628. }
  1629. // }];
  1630. }];
  1631. // }];
  1632. };
  1633. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1634. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1635. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1636. [parentvc presentViewController:navi animated:YES completion:^{
  1637. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1638. DebugLog(@"EditModelPriceViewController present.........");
  1639. // self.btop = false;
  1640. // <#code#>
  1641. }];
  1642. #endif
  1643. }
  1644. /**
  1645. 切换价格组或价格类型后,重新计算购物车每个 item 的 unit_surcharge。
  1646. price_type 和 price_group 从 RASingleton / AppDelegate 实时读取。
  1647. */
  1648. - (void)updateSurchargeForCartSection {
  1649. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1650. NSDictionary *price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1651. NSMutableDictionary *section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1652. int count = [section[@"count"] intValue];
  1653. for (int i = 0; i < count; i++) {
  1654. NSMutableDictionary *item = [section[[NSString stringWithFormat:@"item_%d", i]] mutableCopy];
  1655. // 与 onAddToCart / setScan_val 保持相同的 key 选取逻辑
  1656. NSString *unit_price_key;
  1657. if (RASingleton.sharedInstance.price_type == 0)
  1658. unit_price_key = price_group[@"price_0"][@"name"];
  1659. else if ([item[@"special_price"] boolValue])
  1660. unit_price_key = price_group[@"price_2"][@"name"];
  1661. else if ([item[@"net_price"] boolValue])
  1662. unit_price_key = price_group[@"price_3"][@"name"];
  1663. else
  1664. unit_price_key = price_group[@"price_1"][@"name"];
  1665. NSString *surcharge_key = [unit_price_key stringByAppendingString:@"_surcharge"];
  1666. id unit_surcharge_val = item[surcharge_key];
  1667. double surcharge_d = 0;
  1668. if (unit_surcharge_val != nil && unit_surcharge_val != [NSNull null]) {
  1669. if ([unit_surcharge_val isKindOfClass:[NSNumber class]])
  1670. surcharge_d = [unit_surcharge_val doubleValue];
  1671. else if ([unit_surcharge_val isKindOfClass:[NSString class]] &&
  1672. ![(NSString *)unit_surcharge_val isEqualToString:@"N/A"])
  1673. surcharge_d = [(NSString *)unit_surcharge_val doubleValue];
  1674. }
  1675. item[@"unit_surcharge"] = [NSString stringWithFormat:@"%.2f", surcharge_d];
  1676. section[[NSString stringWithFormat:@"item_%d", i]] = item;
  1677. }
  1678. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1679. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1680. }
  1681. -(void)refresh_total
  1682. {
  1683. self.total=0;
  1684. self.total_carton=0;
  1685. self.total_cuft=0;
  1686. self.total_weight=0;
  1687. self.total_QTY=0;
  1688. self.total_item=0;
  1689. self.surcharge=0;
  1690. #ifdef SCANNER_ORDER
  1691. NSString* pricename;
  1692. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  1693. NSString* servername = [addressDic objectForKey:@"show_name"];
  1694. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  1695. NSString * shortname = arrsn[0];
  1696. if(shortname.length==0)
  1697. shortname = servername;
  1698. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1699. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1700. switch(RASingleton.sharedInstance.price_type )
  1701. {
  1702. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  1703. break;;
  1704. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  1705. break;;
  1706. // case 2: pricename = @"25%";
  1707. // break;
  1708. }
  1709. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  1710. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  1711. [self.cartIndicatorBar removeFromSuperview];
  1712. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1713. [self.view addSubview:self.cartIndicatorBar];
  1714. #endif
  1715. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1716. for(int i=0;i<count;i++)
  1717. {
  1718. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1719. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  1720. if(bcheck)
  1721. {
  1722. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  1723. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  1724. int count=[[item_json valueForKey:@"count"] intValue];
  1725. double totalprice =count*unitprice*(1-discount/100.0);
  1726. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  1727. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  1728. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  1729. int item_count=1;
  1730. int item_qty=1;
  1731. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  1732. // surcharge = unit_surcharge * qty,同样应用折扣
  1733. double msurcharge = [[item_json valueForKey:@"unit_surcharge"] doubleValue] * count * (1 - discount / 100.0);
  1734. // double dprice=0;
  1735. // if(bundle_item!=nil)
  1736. // {
  1737. // // int citem=0;
  1738. //
  1739. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  1740. // for(int bc=0;bc<bcount;bc++)
  1741. // {
  1742. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1743. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1744. // // citem+= modulus;
  1745. // item_count+=1;
  1746. // item_qty+=modulus;
  1747. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1748. // dprice+= uprice*modulus*count;
  1749. //
  1750. // }
  1751. // }
  1752. // totalprice+= dprice;
  1753. self.surcharge+=msurcharge;
  1754. self.total+=totalprice;
  1755. self.total_cuft+=cuft;
  1756. self.total_carton+=carton;
  1757. self.total_weight+=weight;
  1758. self.total_item+=item_count;
  1759. self.total_QTY+=(item_qty)*count;
  1760. }
  1761. }
  1762. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  1763. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  1764. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  1765. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  1766. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  1767. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  1768. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  1769. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  1770. #ifndef SCANNER_ORDER
  1771. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1772. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1773. {
  1774. }
  1775. else
  1776. {
  1777. subtotal=nil;
  1778. }
  1779. #else
  1780. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1781. [OLDataProvider updateScanOrder:appDelegate.order_code];
  1782. #endif
  1783. self.labelTotalSurcharge.text = surcharge;
  1784. self.labelTotalPrice.text = totalprice;
  1785. self.labelTotal.text=subtotal;
  1786. self.labelScanSubtotal.hidden = NO;
  1787. self.labelScanSubtotal.text = subtotal;
  1788. self.label_cuft.text=subcuft;
  1789. self.label_carton.text=subcarton;
  1790. self.label_weight.text=subweight;
  1791. self.label_items.text = subitems;
  1792. self.label_qty.text = subqty;
  1793. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  1794. }
  1795. - (IBAction)onEditGeneralNotes:(id)sender {
  1796. #ifndef SCANNER_ORDER
  1797. if (![self isOrderAvailable]) {
  1798. return;
  1799. }
  1800. #endif
  1801. UIViewController* parentvc=self;
  1802. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  1803. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1804. vc.notes=self.notes;
  1805. // vc.delegate = parentvc.self;
  1806. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1807. vc.onSetValue = ^(NSString* notes){
  1808. self.notes = notes;
  1809. [self refresh_total];
  1810. };
  1811. //
  1812. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1813. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1814. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1815. [parentvc presentViewController:navi animated:YES completion:^{
  1816. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1817. DebugLog(@"general notes editor present.........");
  1818. // self.btop = false;
  1819. // <#code#>
  1820. }];
  1821. }
  1822. - (IBAction)OnCancelOrderClicked:(id)sender {
  1823. }
  1824. #pragma mark - Private
  1825. - (BOOL)isOrderAvailable {
  1826. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1827. if (appDelegate.order_code.length == 0) {
  1828. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  1829. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1830. }];
  1831. [alertVC addAction:okAction];
  1832. [self presentViewController:alertVC animated:YES completion:nil];
  1833. return NO;
  1834. }
  1835. return YES;
  1836. }
  1837. #pragma mark - commoneditor controller delegate
  1838. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1839. {
  1840. // [self reload_data];
  1841. if([value[@"commitorder_logout"] boolValue])
  1842. [self logout];
  1843. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1844. }
  1845. #pragma mark - Table view data source
  1846. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1847. {
  1848. NSDictionary * item_json = nil;
  1849. if (self.back_order_flag) {
  1850. item_json = [self itemJsonAtIndexPath:indexPath];
  1851. } else {
  1852. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1853. }
  1854. NSString* notes =[item_json valueForKey:@"note"];
  1855. if(notes.length>0)
  1856. {
  1857. return 146;
  1858. }
  1859. else
  1860. return 120;
  1861. }
  1862. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1863. //{
  1864. // return 0;
  1865. //}
  1866. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1867. //{
  1868. // return 0;
  1869. //}
  1870. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1871. //{
  1872. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1873. // return myView;
  1874. //
  1875. //}
  1876. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1877. //{
  1878. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1879. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1880. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1881. //// titleLabel.textColor=[UIColor whiteColor];
  1882. //// titleLabel.backgroundColor = [UIColor clearColor];
  1883. //// if(section==0)
  1884. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1885. //// else
  1886. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1887. //// [titleLabel sizeToFit];
  1888. //// [myView addSubview:titleLabel];
  1889. ////
  1890. // return myView;
  1891. //}
  1892. //
  1893. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1894. // if(section==0)
  1895. // return nil;
  1896. // else
  1897. // return @"detail section";
  1898. //}
  1899. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1900. {
  1901. if (self.back_order_flag) {
  1902. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  1903. } else {
  1904. return 1;
  1905. }
  1906. }
  1907. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1908. {
  1909. #ifdef SCANNER_ORDER
  1910. return 0;
  1911. #else
  1912. if (self.back_order_flag) {
  1913. return 50;
  1914. } else {
  1915. return 0;
  1916. }
  1917. #endif
  1918. }
  1919. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1920. {
  1921. #ifdef SCANNER_ORDER
  1922. return nil;
  1923. #else
  1924. if (self.back_order_flag) {
  1925. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  1926. // UILabel *title_lb = [header viewWithTag:8520];
  1927. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  1928. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  1929. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1930. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  1931. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1932. title_lb.font = [UIFont systemFontOfSize:25.0f];
  1933. title_lb.textColor = [UIColor whiteColor];
  1934. [header addSubview:title_lb];
  1935. title_lb.text = [self titleForSection:section];
  1936. return header;
  1937. } else {
  1938. return nil;
  1939. }
  1940. #endif
  1941. }
  1942. #ifdef SCANNER_ORDER
  1943. - (IBAction)onScanChangeCustomerType:(id)sender {
  1944. return;
  1945. // NSString *orderdir =[OLDataProvider getScanPath];
  1946. //
  1947. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1948. // //block代码块取代了delegate
  1949. //
  1950. //
  1951. //
  1952. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1953. //
  1954. // NSMutableDictionary* dict = nil;
  1955. // NSString* ordertemplate = nil;
  1956. // if([RADataProvider getSiteHasERP])
  1957. // ordertemplate =@"e_order.json";
  1958. // else
  1959. // ordertemplate =@"e_order_noerp.json";
  1960. //
  1961. // dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1962. //
  1963. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1964. //
  1965. //
  1966. //
  1967. // [RAUtils dicttofile:orderPath dict:dict];
  1968. //
  1969. //
  1970. //
  1971. //
  1972. ////
  1973. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1974. ////
  1975. ////
  1976. ////
  1977. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1978. ////
  1979. //// [self scanPlaceOrder];
  1980. ////
  1981. // }];
  1982. //
  1983. // UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1984. // NSMutableDictionary* dict = nil;
  1985. // dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1986. //
  1987. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1988. //
  1989. //
  1990. //
  1991. // [RAUtils dicttofile:orderPath dict:dict];
  1992. //
  1993. //
  1994. //
  1995. ////
  1996. ////
  1997. //// NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1998. ////
  1999. ////
  2000. ////
  2001. //// [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2002. //// [self scanPlaceOrder];
  2003. // }];
  2004. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2005. // DebugLog(@"No");
  2006. // }];
  2007. // [alertControl addAction:actionOne];
  2008. // [alertControl addAction:alert2];
  2009. // [alertControl addAction:alertthree];
  2010. //
  2011. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2012. //
  2013. //
  2014. // [self presentViewController:alertControl animated:YES completion:nil];
  2015. //
  2016. // DebugLog(@"%@",self.edit_select_arr);
  2017. }
  2018. #endif
  2019. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2020. {
  2021. if (self.back_order_flag) {
  2022. return [self itemCountInSection:section];
  2023. } else {
  2024. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2025. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2026. return count;
  2027. }
  2028. }
  2029. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2030. {
  2031. // if(tableView==self.itemListTable)
  2032. // {
  2033. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2034. NSString *CellIdentifier;
  2035. #ifdef SCANNER_ORDER
  2036. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2037. CellIdentifier = @"ScanCartItemCell";
  2038. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2039. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2040. item_json = [self itemJsonAtIndexPath:indexPath];
  2041. NSString* notes = [item_json valueForKey:@"note"];
  2042. if(notes.length>0)
  2043. {
  2044. cell.labelNotes.text = notes;
  2045. }
  2046. else
  2047. {
  2048. cell.labelNotes.text = nil;
  2049. }
  2050. NSString* description =[item_json valueForKey:@"description"];
  2051. NSString* model =[item_json valueForKey:@"model"];
  2052. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2053. int count =[[item_json valueForKey:@"count"] intValue];
  2054. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2055. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2056. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2057. cell.discount = discount;
  2058. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2059. {
  2060. cell.btnScanDiscount.hidden = true;
  2061. }
  2062. else
  2063. {
  2064. switch(RASingleton.sharedInstance.price_type)
  2065. {
  2066. case 0: cell.btnScanDiscount.hidden = true;
  2067. break;;
  2068. case 1:
  2069. {
  2070. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2071. cell.btnScanDiscount.hidden = false;
  2072. else
  2073. cell.btnScanDiscount.hidden = true;
  2074. }
  2075. break;;
  2076. // case 2: pricename = @"25%";
  2077. // break;
  2078. }
  2079. }
  2080. // NSString* product_id = [item_json valueForKey:@"product_id"];
  2081. //
  2082. //
  2083. //
  2084. //
  2085. // CGRect frame = cell.frame;
  2086. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of: %d", stockUom];
  2087. __weak typeof(self) weakSelf = self;
  2088. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2089. {
  2090. int result = [[ext objectForKey:@"result"] intValue];
  2091. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2092. if (result == 2 && refresh) {
  2093. [self ReloadData];
  2094. return;
  2095. }
  2096. NSMutableDictionary * item_json = nil;
  2097. if (weakSelf.back_order_flag) {
  2098. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2099. } else {
  2100. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2101. }
  2102. // int count=[[item_json valueForKey:@"count"] intValue];
  2103. // if(count==qty)
  2104. // return;
  2105. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2106. return ;
  2107. }
  2108. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2109. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2110. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2111. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2112. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2113. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2114. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2115. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2116. if (weakSelf.back_order_flag) {
  2117. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2118. } else {
  2119. weakSelf.content_arr[indexPath.row]= item_json;
  2120. }
  2121. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2122. [weakSelf refresh_total];
  2123. #ifdef RA_NOTIFICATION
  2124. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2125. #else
  2126. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2127. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2128. #endif
  2129. };
  2130. // cell.delegate=self;
  2131. // cell.from=indexPath;
  2132. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2133. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2134. {
  2135. cell.labelUnitPrice.textColor= [UIColor redColor];
  2136. if([item_json[@"special_price"] boolValue]||discount>0)
  2137. {
  2138. cell.labelOldPrice.hidden = false;
  2139. // if([item_json[@"special_price"] boolValue])
  2140. // {
  2141. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[price_group[@"price_1"][@"name"]] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2142. // }
  2143. // else
  2144. // {
  2145. // }
  2146. }
  2147. else
  2148. cell.labelOldPrice.hidden = true;
  2149. }
  2150. else
  2151. {
  2152. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2153. cell.labelOldPrice.hidden = true;
  2154. }
  2155. // if(discount>0)
  2156. // {
  2157. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2158. // cell.labelOldPrice.hidden = false;
  2159. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2160. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2161. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2162. // frame.size.height = 120;
  2163. // }
  2164. // else
  2165. // {
  2166. //
  2167. //
  2168. // cell.labelOldPrice.hidden = true;
  2169. // cell.labelNotes.text = nil;
  2170. // frame.size.height = 94;
  2171. // }
  2172. cell.unit_price = unitprice;
  2173. // cell.labelAttribute.text = attribute;
  2174. // cell.labelCurrency.text = currency;
  2175. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2176. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2177. cell.labelModel.text = model;
  2178. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2179. // if(noprice&&unitprice==0.0)
  2180. // {
  2181. // cell.labelPrice.text = @"No Price";
  2182. //
  2183. // cell.labelUnitPrice.text = @"No Price";
  2184. // }
  2185. // else
  2186. {
  2187. cell.labelSubtotal.text = subtotal;
  2188. cell.labelUnitPrice.text = newunitprice;
  2189. }
  2190. // bool check = [[item_json valueForKey:@"check"] boolValue];
  2191. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2192. cell.cart_id = cart_item_id;
  2193. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2194. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2195. // else
  2196. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2197. [cell set_Count:count];
  2198. // Button 设置了大小约束,Size就不会随内容变化
  2199. cell.backgroundColor = [UIColor whiteColor];
  2200. return cell;
  2201. #else
  2202. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2203. CellIdentifier = @"CartItemCell";
  2204. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2205. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2206. if (self.back_order_flag) {
  2207. item_json = [self itemJsonAtIndexPath:indexPath];
  2208. } else {
  2209. item_json = self.content_arr[indexPath.row];
  2210. }
  2211. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2212. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2213. if (cell.masterBtn != nil) {
  2214. if (master_json == nil) {
  2215. cell.masterBtn.hidden = YES;
  2216. } else{
  2217. cell.masterBtn.hidden = NO;
  2218. cell.master_items = master_json;
  2219. }
  2220. }
  2221. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2222. NSString* notes = [item_json valueForKey:@"note"];
  2223. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2224. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  2225. cell.noprice = noprice;
  2226. cell.enable_longpress = true;
  2227. cell.bundle_item=combine_json;
  2228. NSString* img_url = [item_json valueForKey:@"img_url"];
  2229. NSString* description = [item_json valueForKey:@"description"];
  2230. // NSString* identifier = [item_json valueForKey:@"identifier"];
  2231. // NSString* attribute = [item_json valueForKey:@"attribute"];
  2232. // NSString* currency = [item_json valueForKey:@"currency"];
  2233. int count =[[item_json valueForKey:@"count"] intValue];
  2234. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2235. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2236. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2237. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2238. NSString* product_id = [item_json valueForKey:@"product_id"];
  2239. // handle no such model
  2240. if(product_id.length==0)
  2241. cell.labelNoSuchModel.hidden=false;
  2242. else
  2243. cell.labelNoSuchModel.hidden=true;
  2244. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2245. if (!is_out_of_stock) {
  2246. cell.labelOutOfStock.hidden = YES;
  2247. } else {
  2248. cell.labelOutOfStock.hidden = NO;
  2249. }
  2250. // } else {
  2251. // cell.labelOutOfStock.hidden = YES;
  2252. // }
  2253. // discount = 5.0;
  2254. cell.discount = discount;
  2255. CGRect frame = cell.frame;
  2256. if(notes.length>0)
  2257. {
  2258. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2259. frame.size.height = 146;
  2260. }
  2261. else
  2262. {
  2263. cell.labelNotes.text = nil;
  2264. frame.size.height = 120;
  2265. }
  2266. // cell.frame = frame;
  2267. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2268. if(isfree)
  2269. {
  2270. cell.labelOldPrice.hidden = false;
  2271. cell.labelOldPrice.textColor = [UIColor redColor];
  2272. cell.labelOldPrice.text=@"Free";
  2273. cell.labelOldPrice.hideline = true;
  2274. cell.labelDiscount.hidden = true;
  2275. }
  2276. else
  2277. {
  2278. cell.labelOldPrice.textColor = [UIColor blackColor];
  2279. cell.labelOldPrice.hideline = false;
  2280. if(discount==0)
  2281. {
  2282. cell.labelOldPrice.hidden = true;
  2283. cell.labelDiscount.hidden = true;
  2284. }
  2285. else
  2286. {
  2287. cell.labelOldPrice.hidden = false;
  2288. cell.labelDiscount.hidden = false;
  2289. }
  2290. }
  2291. __weak typeof(self) weakSelf = self;
  2292. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2293. {
  2294. int result = [[ext objectForKey:@"result"] intValue];
  2295. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2296. if (result == 2 && refresh) {
  2297. [self ReloadData];
  2298. return;
  2299. }
  2300. NSMutableDictionary * item_json = nil;
  2301. if (weakSelf.back_order_flag) {
  2302. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2303. } else {
  2304. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2305. }
  2306. // int count=[[item_json valueForKey:@"count"] intValue];
  2307. // if(count==qty)
  2308. // return;
  2309. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2310. return ;
  2311. }
  2312. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2313. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  2314. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2315. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2316. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2317. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2318. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2319. if (weakSelf.back_order_flag) {
  2320. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2321. } else {
  2322. weakSelf.content_arr[indexPath.row]= item_json;
  2323. }
  2324. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2325. [weakSelf refresh_total];
  2326. #ifdef RA_NOTIFICATION
  2327. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2328. #else
  2329. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2330. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2331. #endif
  2332. };
  2333. // cell.delegate=self;
  2334. // cell.from=indexPath;
  2335. cell.unit_price = unitprice;
  2336. // cell.labelAttribute.text = attribute;
  2337. // cell.labelCurrency.text = currency;
  2338. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  2339. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  2340. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  2341. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2342. {
  2343. }
  2344. else
  2345. {
  2346. oldprice=nil;
  2347. newprice=nil;
  2348. newunitprice=nil;
  2349. }
  2350. cell.labelDiscount.text = discountstr;
  2351. cell.labelOldPrice.text = oldprice;
  2352. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of: %d", stockUom];
  2353. cell.labelDescription.text = description;
  2354. // cell.labelIdentifier.text = identifier;
  2355. if(noprice&&unitprice==0.0)
  2356. {
  2357. cell.labelPrice.text = @"No Price";
  2358. cell.labelUnitPrice.text = @"No Price";
  2359. }
  2360. else
  2361. {
  2362. cell.labelPrice.text = newprice;
  2363. cell.labelUnitPrice.text = newunitprice;
  2364. }
  2365. bool check = [[item_json valueForKey:@"check"] boolValue];
  2366. if(check)
  2367. {
  2368. cell.img_checkmark.hidden=false;
  2369. // [item_json setValue:@"0" forKey:@"check"];
  2370. }
  2371. else
  2372. {
  2373. // [item_json setValue:@"1" forKey:@"check"];
  2374. cell.img_checkmark.hidden=true;
  2375. }
  2376. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2377. cell.cart_id = cart_item_id;
  2378. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2379. {
  2380. #ifdef IGNORE_SOLD_IN_QTY
  2381. [cell init_Stepper:1 max:9999 min:1 value:count];
  2382. #else
  2383. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2384. #endif
  2385. }
  2386. // else
  2387. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2388. [cell set_Count:count];
  2389. // Button 设置了大小约束,Size就不会随内容变化
  2390. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  2391. #if __IPHONE_OS_VERSION_MIN_REQUIRED <150000
  2392. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2393. #endif
  2394. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2395. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2396. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2397. if (![cell.imageName isEqualToString:img_url]) {
  2398. cell.imageName = img_url;
  2399. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2400. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2401. NSString* file_name=[img_url lastPathComponent];
  2402. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2403. if(img_data!=nil)
  2404. {
  2405. UIImage * img =[UIImage imageWithData:img_data];
  2406. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2407. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2408. }
  2409. else
  2410. {
  2411. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2412. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2413. dispatch_async(dispatch_get_main_queue(), ^{
  2414. if(downloadimg_data!=nil)
  2415. {
  2416. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2417. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2418. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2419. [cell.btnImage setImage:img forState:UIControlStateNormal];
  2420. }
  2421. else
  2422. {
  2423. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2424. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2425. }
  2426. });
  2427. });
  2428. }
  2429. }
  2430. cell.backgroundColor = [UIColor whiteColor];
  2431. if(self.itemListTable.editing)
  2432. {
  2433. cell.editCount.enabled = false;
  2434. cell.stepper.hidden=true;
  2435. }
  2436. else
  2437. {
  2438. cell.editCount.enabled=true;
  2439. cell.stepper.hidden=false;
  2440. }
  2441. return cell;
  2442. // }
  2443. // else
  2444. // {
  2445. // NSString *CellIdentifier = @"OrderInfoListItem";
  2446. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2447. // return cell;
  2448. // }
  2449. #endif
  2450. }
  2451. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  2452. {
  2453. if(!self.itemListTable.editing)
  2454. return;
  2455. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2456. NSMutableDictionary * item_json = nil;
  2457. if (self.back_order_flag) {
  2458. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2459. } else {
  2460. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2461. }
  2462. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2463. if ([self.edit_select_arr containsObject:cart_item_id])
  2464. {
  2465. [self.edit_select_arr removeObject:cart_item_id];
  2466. }
  2467. }
  2468. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2469. {
  2470. #ifdef SCANNER_ORDER
  2471. return;
  2472. #endif
  2473. NSMutableDictionary * item_json = nil;
  2474. if (self.back_order_flag) {
  2475. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2476. } else {
  2477. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2478. }
  2479. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2480. if(self.itemListTable.editing)
  2481. {
  2482. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2483. if (![self.edit_select_arr containsObject:cart_item_id]) {
  2484. [self.edit_select_arr addObject:cart_item_id];
  2485. }
  2486. return;
  2487. }
  2488. // no checkmark support anymore for cart
  2489. return;
  2490. }
  2491. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  2492. if(self.itemListTable.editing)
  2493. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  2494. else
  2495. return UITableViewCellEditingStyleDelete;
  2496. }
  2497. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  2498. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  2499. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  2500. {
  2501. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2502. // 添加一个删除按钮
  2503. self.indexPath=indexPath;
  2504. NSMutableDictionary * item_json = nil;
  2505. if (self.back_order_flag) {
  2506. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2507. } else {
  2508. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2509. }
  2510. NSString* productID = [item_json valueForKey:@"product_id"];
  2511. // BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  2512. __weak typeof(self) weakself = self;
  2513. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2514. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@" Delete " handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2515. DebugLog(@"delete click");
  2516. //[self.itemListTable setEditing:false animated:YES];
  2517. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  2518. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2519. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2520. NSMutableDictionary * item_json = nil;
  2521. if (self.back_order_flag) {
  2522. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  2523. } else {
  2524. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2525. }
  2526. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  2527. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  2528. PopWaitAlert* pop = [RAUtils waiting_pop:@"Remove Model" completion:nil];
  2529. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  2530. NSMutableDictionary* cart_json = result;
  2531. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2532. [pop hide];
  2533. if([[cart_json valueForKey:@"result"] intValue]==2)
  2534. {
  2535. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2536. if (self.back_order_flag) {
  2537. NSInteger section_count = [self sectionCount];
  2538. for (int i = 0; i < section_count; i++) {
  2539. NSInteger item_count = [self itemCountInSection:i];
  2540. BOOL ready_break = NO;
  2541. for (int j = 0; j < item_count; j++) {
  2542. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2543. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  2544. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2545. if([_id isEqualToString:ids])
  2546. {
  2547. [self updateItemJson:nil atIndexPath:indexPath];
  2548. ready_break = YES;
  2549. break;
  2550. }
  2551. }
  2552. if (ready_break) {
  2553. break;
  2554. }
  2555. }
  2556. } else {
  2557. for(int i=0;i<self.content_arr.count;i++)
  2558. {
  2559. NSDictionary* obj_json = self.content_arr[i];
  2560. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2561. if([_id isEqualToString:ids])
  2562. {
  2563. [self.content_arr removeObjectAtIndex:i];
  2564. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2565. break;
  2566. // appDelegate.cart_count--;
  2567. // [appDelegate update_count_mark];
  2568. }
  2569. }
  2570. }
  2571. #ifdef SCANNER_ORDER
  2572. self.cart_json = cart_json;
  2573. #endif
  2574. [self.itemListTable reloadData];
  2575. [self refresh_total];
  2576. #ifdef RA_NOTIFICATION
  2577. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2578. #else
  2579. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2580. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2581. #endif
  2582. // [self reload_data];
  2583. }
  2584. else
  2585. {
  2586. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2587. }
  2588. // }];
  2589. }];
  2590. // }];
  2591. }];
  2592. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2593. }];
  2594. [alertController addAction:action_2];
  2595. [alertController addAction:action_3];
  2596. [self presentViewController:alertController animated:YES completion:nil];
  2597. // 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];
  2598. // alert.tag = ALERT_DEL;
  2599. // // alert.
  2600. // [alert show];
  2601. }];
  2602. deleteRowAction.backgroundColor = [UIColor redColor];
  2603. UIContextualAction* notifyMeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Notify Me" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2604. {
  2605. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2606. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2607. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2608. NSMutableDictionary *dic = result;
  2609. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2610. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2611. [pop hide];
  2612. int result_code = [[dic valueForKey:@"result"] intValue];
  2613. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2614. {
  2615. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2616. if ([dic valueForKey:@"err_msg"]) {
  2617. msg = [dic valueForKey:@"err_msg"];
  2618. }
  2619. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2620. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2621. }];
  2622. [errorAlertVC addAction:action];
  2623. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2624. } else if (result_code == RESULT_TRUE){
  2625. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2626. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2627. [weakself showAddressBoxToEmailProduct:productID];
  2628. }
  2629. // }];
  2630. }];
  2631. // }];
  2632. };
  2633. }];
  2634. // UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2635. //
  2636. // {
  2637. //
  2638. //// __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2639. // PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  2640. // [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  2641. // NSMutableDictionary *dic = result;
  2642. //
  2643. //
  2644. // // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2645. //// [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2646. // [pop hide];
  2647. // int result_code = [[dic valueForKey:@"result"] intValue];
  2648. //
  2649. // if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  2650. // {
  2651. //
  2652. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2653. //
  2654. // if ([dic valueForKey:@"err_msg"]) {
  2655. // msg = [dic valueForKey:@"err_msg"];
  2656. // }
  2657. //
  2658. //
  2659. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2660. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2661. //
  2662. // }];
  2663. //
  2664. // [errorAlertVC addAction:action];
  2665. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2666. //
  2667. // } else if (result_code == RESULT_TRUE){
  2668. //
  2669. // [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  2670. //
  2671. // } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  2672. //
  2673. // [weakself showAddressBoxToEmailProduct:productID];
  2674. //
  2675. // }
  2676. //// }];
  2677. //
  2678. //
  2679. //
  2680. // }];
  2681. //
  2682. //// }];
  2683. //
  2684. // };
  2685. //
  2686. //
  2687. // }];
  2688. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  2689. // UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2690. UIContextualAction* addWatchAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Move To Wish List" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2691. DebugLog(@"Wishlist click");
  2692. NSMutableDictionary * item_json = nil;
  2693. if (self.back_order_flag) {
  2694. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2695. } else {
  2696. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2697. }
  2698. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2699. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2700. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2701. NSDictionary* return_json = result;
  2702. if([[return_json valueForKey:@"result"] intValue]==2)
  2703. {
  2704. #ifdef RA_NOTIFICATION
  2705. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2706. #else
  2707. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2708. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  2709. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2710. #endif
  2711. for(int i=0;i<self.content_arr.count;i++)
  2712. {
  2713. NSDictionary* obj_json = self.content_arr[i];
  2714. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  2715. if([_id isEqualToString:cart_item_id])
  2716. {
  2717. if (self.back_order_flag) {
  2718. [self updateItemJson:nil atIndexPath:indexPath];
  2719. } else {
  2720. [self.content_arr removeObjectAtIndex:i];
  2721. }
  2722. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  2723. appDelegate.cart_count--;
  2724. [appDelegate update_count_mark];
  2725. [self refresh_total];
  2726. }
  2727. }
  2728. [self.itemListTable reloadData];
  2729. }
  2730. else
  2731. {
  2732. [RAUtils message_box:@"Move To Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2733. }
  2734. }];
  2735. }];
  2736. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  2737. // 添加一个编辑按钮
  2738. // UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
  2739. UIContextualAction* editRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Edit Price" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2740. DebugLog(@"edit click");
  2741. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2742. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  2743. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  2744. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2745. [alert dismissViewControllerAnimated:YES completion:nil];
  2746. }];
  2747. [alert addAction:action];
  2748. if (weakself) {
  2749. __strong typeof(weakself) strongself = weakself;
  2750. [strongself presentViewController:alert animated:YES completion:nil];
  2751. }
  2752. return ;
  2753. }
  2754. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  2755. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  2756. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2757. [alert dismissViewControllerAnimated:YES completion:nil];
  2758. }];
  2759. [alert addAction:action];
  2760. if (weakself) {
  2761. __strong typeof(weakself) strongself = weakself;
  2762. [strongself presentViewController:alert animated:YES completion:nil];
  2763. }
  2764. return ;
  2765. }
  2766. }
  2767. UIViewController* parentvc=self;
  2768. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  2769. NSMutableDictionary * item_json = nil;
  2770. if (self.back_order_flag) {
  2771. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2772. } else {
  2773. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2774. }
  2775. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2776. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2777. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2778. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2779. // vc.delegate = parentvc.self;
  2780. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2781. vc.onSetValue = ^(double price,double discount){
  2782. bool bmodify=false;
  2783. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  2784. bmodify=true;
  2785. NSString* notes = [item_json valueForKey:@"note"];
  2786. if(notes.length==0)
  2787. notes=@"";
  2788. if(bmodify)
  2789. {
  2790. if([notes isEqualToString:@""])
  2791. notes=@"PRICE MODIFIED";
  2792. NSRange range;
  2793. range = [notes rangeOfString:@"PRICE MODIFIED"];
  2794. if (range.location != NSNotFound) {
  2795. }else{
  2796. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2797. }
  2798. }
  2799. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2800. PopWaitAlert* pop = [RAUtils waiting_pop:@"Update Price" completion:nil];
  2801. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  2802. NSDictionary* cart_json = result;
  2803. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2804. [pop hide];
  2805. if([[cart_json valueForKey:@"result"] intValue]==2)
  2806. {
  2807. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2808. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2809. [item_json setValue:notes forKey:@"note"];
  2810. if (self.back_order_flag) {
  2811. [self updateItemJson:item_json atIndexPath:indexPath];
  2812. } else {
  2813. self.content_arr[indexPath.row ] = item_json;
  2814. }
  2815. tableView.editing = false;
  2816. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2817. // [self refresh_total];
  2818. [weakself reload_data];
  2819. #ifdef RA_NOTIFICATION
  2820. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2821. #else
  2822. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2823. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2824. #endif
  2825. }
  2826. else
  2827. {
  2828. [RAUtils message_box:@"Update Price" message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
  2829. }
  2830. // }];
  2831. }];
  2832. // }];
  2833. // [self reload_data];//[main_vc checklogin:true];
  2834. };
  2835. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2836. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2837. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2838. [parentvc presentViewController:navi animated:YES completion:^{
  2839. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2840. DebugLog(@"EditModelPriceViewController present.........");
  2841. // self.btop = false;
  2842. // <#code#>
  2843. }];
  2844. // [self.itemListTable setEditing:false animated:YES];
  2845. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2846. }];
  2847. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  2848. // // 添加一个更多按钮
  2849. //
  2850. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2851. //
  2852. // DebugLog(@点击了更多);
  2853. //
  2854. //
  2855. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2856. //
  2857. // }];
  2858. //
  2859. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  2860. //
  2861. // 将设置好的按钮放到数组中返回
  2862. // UITableViewRowAction *freeRowAction = nil;
  2863. //
  2864. //
  2865. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2866. //
  2867. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2868. //
  2869. // if(!isfree)
  2870. // {
  2871. //
  2872. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2873. //
  2874. // DebugLog(@"free click");
  2875. //
  2876. //
  2877. //
  2878. // 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];
  2879. // alert.tag = ALERT_SET_FREE;
  2880. // // alert.
  2881. // [alert show];
  2882. // }];
  2883. // }
  2884. // else
  2885. // {
  2886. //
  2887. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2888. //
  2889. // 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];
  2890. // alert.tag = ALERT_RESTORE_FREE;
  2891. // // alert.
  2892. // [alert show];
  2893. // }];
  2894. // }
  2895. //
  2896. //
  2897. //
  2898. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  2899. // UITableViewRowAction *noteRowAction = nil;
  2900. //
  2901. //
  2902. // // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2903. //
  2904. //
  2905. //
  2906. //
  2907. // noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  2908. UIContextualAction* noteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Edit note" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2909. DebugLog(@"item note click");
  2910. UIViewController* parentvc=self;
  2911. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  2912. NSMutableDictionary * item_json = nil;
  2913. if (self.back_order_flag) {
  2914. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2915. } else {
  2916. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2917. }
  2918. vc.onSaveNote=^(NSString* notes){
  2919. [item_json setValue:notes forKey:@"note"];
  2920. if (self.back_order_flag) {
  2921. [self updateItemJson:item_json atIndexPath:indexPath];
  2922. } else {
  2923. self.content_arr[indexPath.row ] = item_json;
  2924. }
  2925. tableView.editing = false;
  2926. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2927. };
  2928. vc.notes=[item_json valueForKey:@"note"];
  2929. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2930. // vc.delegate = parentvc.self;
  2931. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2932. // vc.onSetValue = ^(){
  2933. // [self reload_data];//[main_vc checklogin:true];
  2934. // };
  2935. //
  2936. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2937. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2938. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2939. [parentvc presentViewController:navi animated:YES completion:^{
  2940. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2941. DebugLog(@"EditModelPriceViewController present.........");
  2942. // self.btop = false;
  2943. // <#code#>
  2944. }];
  2945. // [self.itemListTable setEditing:false animated:YES];
  2946. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2947. }];
  2948. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  2949. // UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  2950. UIContextualAction* move2BackAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Move to Back Order" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  2951. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  2952. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  2953. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  2954. PopWaitAlert* pop = [RAUtils waiting_pop:@"Move To Back Order" completion:nil];
  2955. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  2956. NSMutableDictionary* return_json =result ;
  2957. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2958. [pop hide];
  2959. if([[return_json valueForKey:@"result"] intValue]==2) {
  2960. [self reload_data];
  2961. } // if 2
  2962. else {
  2963. [RAUtils message_box:@"Move To Back Order" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  2964. }
  2965. // }];
  2966. }];
  2967. // }];
  2968. }];
  2969. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  2970. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  2971. {
  2972. NSMutableDictionary * item_json = nil;
  2973. if (self.back_order_flag) {
  2974. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2975. } else {
  2976. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2977. }
  2978. NSString* product_id = [item_json valueForKey:@"product_id"];
  2979. NSMutableArray* arr=[@[] mutableCopy];
  2980. if(product_id.length>0)
  2981. [arr addObject:noteRowAction];
  2982. [arr addObject:deleteRowAction];
  2983. // return arr;
  2984. return [UISwipeActionsConfiguration configurationWithActions:arr];
  2985. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  2986. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2987. if (appDelegate.customer_type == CustomerTypeStore) {
  2988. // return @[deleteRowAction];
  2989. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  2990. } else {
  2991. // normal
  2992. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  2993. NSMutableArray *actionArray = [NSMutableArray array];
  2994. // move to backorder
  2995. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  2996. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  2997. if (self.back_order_flag && available) {
  2998. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  2999. [actionArray addObject:move2BackAction];
  3000. }
  3001. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  3002. // edit price
  3003. NSMutableDictionary * item_json = nil;
  3004. if (self.back_order_flag) {
  3005. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3006. } else {
  3007. item_json = [self.content_arr[indexPath.row] mutableCopy];
  3008. }
  3009. NSString* product_id = [item_json valueForKey:@"product_id"];
  3010. int is_rate = [item_json[@"is_rate"] intValue];
  3011. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  3012. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  3013. [actionArray addObject:editRowAction];
  3014. }
  3015. // return actionArray;
  3016. return [UISwipeActionsConfiguration configurationWithActions:actionArray];
  3017. }
  3018. }
  3019. else
  3020. // return @[deleteRowAction];
  3021. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  3022. }
  3023. - (void)tableView:(UITableView *)tableView
  3024. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  3025. }
  3026. #pragma mark - Support scanner
  3027. -(void) onDecodedData:(NSString*) value
  3028. {
  3029. int cqty=0;
  3030. if (self.back_order_flag) {
  3031. NSInteger section_count = [self sectionCount];
  3032. for (int i = 0; i < section_count; i++) {
  3033. NSInteger item_count = [self itemCountInSection:i];
  3034. for (int j = 0; j < item_count; j++) {
  3035. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3036. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  3037. if([item[@"model"] isEqualToString:value]) {
  3038. cqty=[item[@"count"] intValue];
  3039. }
  3040. }
  3041. }
  3042. } else {
  3043. for(int i=0;i<self.content_arr.count;i++)
  3044. {
  3045. NSDictionary* item= self.content_arr[i];
  3046. if([item[@"model"] isEqualToString:value])
  3047. cqty=[item[@"count"]intValue];
  3048. }
  3049. }
  3050. if(cqty>0)
  3051. {
  3052. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  3053. //block代码块取代了delegate
  3054. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  3055. [self addtocart:value];
  3056. }];
  3057. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3058. DebugLog(@"No");
  3059. }];
  3060. [alertControl addAction:actionOne];
  3061. [alertControl addAction:alertthree];
  3062. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  3063. [self presentViewController:alertControl animated:YES completion:nil];
  3064. }
  3065. else
  3066. [self addtocart:value];
  3067. }
  3068. -(void) addtocart:(NSString*) modelname
  3069. {
  3070. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3071. NSDictionary* return_json =result;
  3072. if([[return_json valueForKey:@"result"] intValue]==2)
  3073. {
  3074. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  3075. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  3076. // bool isnew=false;
  3077. //
  3078. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3079. if (self.back_order_flag) {
  3080. NSInteger section_count = [self sectionCount];
  3081. for (int i = 0; i < section_count; i++) {
  3082. NSInteger item_count = [self itemCountInSection:i];
  3083. BOOL ready_break = NO;
  3084. for (int j = 0; j < item_count; j++) {
  3085. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3086. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3087. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3088. if([_id isEqualToString:item_id])
  3089. {
  3090. [self updateItemJson:nil atIndexPath:indexPath];
  3091. ready_break = YES;
  3092. break;
  3093. }
  3094. }
  3095. if (ready_break) {
  3096. break;
  3097. }
  3098. }
  3099. } else {
  3100. for(int i=0;i<self.content_arr.count;i++)
  3101. {
  3102. NSDictionary* obj_json = self.content_arr[i];
  3103. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3104. if([_id isEqualToString:item_id])
  3105. {
  3106. // self.content_arr[i] = newitem;
  3107. [self.content_arr removeObjectAtIndex:i];
  3108. break;
  3109. // [self.content_arr removeObjectAtIndex:i];
  3110. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3111. // appDelegate.cart_count--;
  3112. // [appDelegate update_count_mark];
  3113. }
  3114. }
  3115. }
  3116. AppDelegate *appDelegate =nil;
  3117. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3118. #ifdef OFFLINE_MODE
  3119. if(appDelegate.offline_mode)
  3120. {
  3121. [self ReloadData];
  3122. }
  3123. else
  3124. #endif
  3125. {
  3126. if (self.back_order_flag) {
  3127. [self ReloadData];
  3128. } else {
  3129. [self.content_arr insertObject:newitem atIndex:0];
  3130. [self.itemListTable reloadData];
  3131. [self refresh_total];
  3132. }
  3133. }
  3134. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3135. #ifdef RA_NOTIFICATION
  3136. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3137. #else
  3138. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  3139. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3140. #endif
  3141. }
  3142. else
  3143. {
  3144. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  3145. }
  3146. }];
  3147. }
  3148. #pragma mark - sort button
  3149. - (void)cartSortButtonClicked:(UIButton *)sender {
  3150. DebugLog(@"cart sort button clicked");
  3151. [self.view addSubview:self.sortItemController.view];
  3152. }
  3153. - (SortItemViewController *)sortItemController {
  3154. if (!_sortItemController) {
  3155. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  3156. _sortItemController.sortIndex = self.sortIndex;
  3157. _sortItemController.sortData = @[
  3158. @{@"title":@"Last",@"icon":@"TX_18"},
  3159. @{@"title":@"First",@"icon":@"TS_18"},
  3160. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  3161. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  3162. @{@"title":@"Description",@"icon":@"DX_18"},
  3163. ];
  3164. __weak typeof(self) weakSelf = self;
  3165. _sortItemController.sortBlock = ^(int sort){
  3166. weakSelf.sortIndex = sort;
  3167. [weakSelf reload_data];
  3168. };
  3169. }
  3170. // _sortItemController.sortIndex = self.sortIndex;
  3171. return _sortItemController;
  3172. }
  3173. - (SortButton *)sortButton {
  3174. if (!_sortButton) {
  3175. _sortButton = [SortButton sortButtonWithHeight:40];
  3176. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  3177. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  3178. }
  3179. return _sortButton;
  3180. }
  3181. - (void)setSortIndex:(int)sortIndex {
  3182. _sortIndex = sortIndex;
  3183. NSString *selectedImageName = @"";
  3184. switch (sortIndex) {
  3185. case 0:{
  3186. selectedImageName = @"TX_22";
  3187. }
  3188. break;
  3189. case 1:{
  3190. selectedImageName = @"TS_22";
  3191. }
  3192. break;
  3193. case 2:{
  3194. selectedImageName = @"IX_22";
  3195. }
  3196. break;
  3197. case 3:{
  3198. selectedImageName = @"IS_22";
  3199. }
  3200. break;
  3201. case 4:{
  3202. selectedImageName = @"DX_22";
  3203. }
  3204. break;
  3205. default:
  3206. break;
  3207. }
  3208. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  3209. }
  3210. #pragma mark - rotation
  3211. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3212. //
  3213. // self.sortItemController.view.frame = self.view.bounds;
  3214. //}
  3215. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  3216. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  3217. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3218. // what ever you want to prepare
  3219. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  3220. // self.sortItemController.view.frame = self.view.bounds;
  3221. self.sortItemController.view.frame = self.view.bounds;
  3222. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3223. // [self.itemListTable reloadData];
  3224. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3225. [self layoutCartIndicatorBar];
  3226. }];
  3227. }
  3228. -(BOOL) shouldAutorotate
  3229. {
  3230. return YES;
  3231. }
  3232. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  3233. // return YES;
  3234. //}
  3235. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  3236. // self.sortItemController.view.frame = self.view.bounds;
  3237. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  3238. //
  3239. //// [self.itemListTable reloadData];
  3240. //
  3241. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  3242. // [self layoutCartIndicatorBar];
  3243. //}
  3244. #pragma mark - notification action
  3245. - (void)priceTypeChanged:(id)notification {
  3246. [self reload_data];
  3247. #ifdef RA_NOTIFICATION
  3248. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3249. #else
  3250. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3251. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3252. #endif
  3253. }
  3254. #pragma mark - button action
  3255. - (IBAction)emailButtonClick:(UIButton *)sender {
  3256. if (![self isOrderAvailable]) {
  3257. return;
  3258. }
  3259. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3260. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  3261. emailAddrVC.textFiled.secureTextEntry = NO;
  3262. emailAddrVC.yesButtonTitle = @"send";
  3263. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3264. __weak typeof(self) weakself = self;
  3265. emailAddrVC.textHandler = ^(NSString *text){
  3266. // 验证邮箱格式是否正确
  3267. // NSString *match = EMAIL_MATCHES;
  3268. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3269. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3270. BOOL isEmailAddr = YES;
  3271. if (isEmailAddr) {
  3272. // 验证是邮件地址,发送邮件
  3273. [weakVC dismissViewControllerAnimated:YES completion:^{
  3274. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3275. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3276. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  3277. DebugLog(@"email cart result: %@",result);
  3278. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3279. [pop hide];
  3280. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  3281. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  3282. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  3283. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3284. }];
  3285. [errorAlertVC addAction:action];
  3286. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3287. }else {
  3288. [RAUtils message_box:@"Message" message:@"Send Email Success" completion:nil];
  3289. }
  3290. // }];
  3291. }];
  3292. // }];
  3293. }];
  3294. } else {
  3295. // 非邮件地址,警告
  3296. [weakVC warning:@"Please enter right email address"];
  3297. }
  3298. };
  3299. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3300. }
  3301. - (IBAction)printCartButtonClick:(UIButton *)sender {
  3302. if (![self isOrderAvailable]) {
  3303. return;
  3304. }
  3305. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  3306. ViewController.url = self.print_url;
  3307. ViewController.canSave = false;
  3308. ViewController.isLocalfile=NO;
  3309. NSString* subject;
  3310. subject =@"Cart Print";
  3311. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3312. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  3313. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  3314. if(customer_email.length>0)
  3315. {
  3316. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  3317. }
  3318. ViewController.mail_to = send_to;
  3319. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  3320. ViewController.mail_subject = subject;
  3321. ViewController.hidenavi = false;
  3322. [self.navigationController pushViewController:ViewController animated:YES];
  3323. }
  3324. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  3325. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  3326. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  3327. emailAddrVC.textFiled.secureTextEntry = NO;
  3328. emailAddrVC.yesButtonTitle = @"send";
  3329. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  3330. __weak typeof(self) weakself = self;
  3331. emailAddrVC.textHandler = ^(NSString *text){
  3332. // 验证邮箱格式是否正确
  3333. // NSString *match = EMAIL_MATCHES;
  3334. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  3335. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  3336. BOOL isEmailAddr = YES;
  3337. if (isEmailAddr) {
  3338. // 验证是邮件地址,发送邮件
  3339. [weakVC dismissViewControllerAnimated:YES completion:^{
  3340. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3341. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  3342. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3343. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3344. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3345. [pop hide];
  3346. int resultStatus = [[result objectForKey:@"result"] intValue];
  3347. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  3348. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3349. if ([result valueForKey:@"err_msg"]) {
  3350. msg = [result valueForKey:@"err_msg"];
  3351. }
  3352. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3353. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3354. }];
  3355. [errorAlertVC addAction:action];
  3356. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3357. }else if(resultStatus == RESULT_TRUE){
  3358. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  3359. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  3360. [weakself showAddressBoxToEmailProduct:productID];
  3361. }
  3362. // }];
  3363. }];
  3364. // }];
  3365. }];
  3366. } else {
  3367. // 非邮件地址,警告
  3368. [weakVC warning:@"Please enter right email address"];
  3369. }
  3370. };
  3371. [self presentViewController:emailAddrVC animated:YES completion:nil];
  3372. }
  3373. #pragma mark - Back Order
  3374. - (void) setCart_json:(NSDictionary *)cart_json {
  3375. _cart_json = cart_json;
  3376. [self fillContentArray];
  3377. }
  3378. - (void)fillContentArray {
  3379. NSMutableArray *arr = [NSMutableArray array];
  3380. for (int i = 0; i < [self sectionCount]; i++) {
  3381. NSInteger item_count = [self itemCountInSection:i];
  3382. for (int j = 0; j < item_count; j++) {
  3383. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  3384. [arr addObject:item];
  3385. }
  3386. }
  3387. self.content_arr = arr;
  3388. [self refresh_total];
  3389. }
  3390. - (NSInteger)sectionCount {
  3391. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  3392. }
  3393. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  3394. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  3395. }
  3396. - (NSInteger)itemCountInSection:(NSInteger)section {
  3397. NSDictionary *section_json = [self jsonAtSection:section];
  3398. return [[section_json objectForKey:@"count"] integerValue];
  3399. }
  3400. - (NSString *)titleForSection:(NSInteger)section {
  3401. NSDictionary *section_json = [self jsonAtSection:section];
  3402. return [section_json objectForKey:@"title"];
  3403. }
  3404. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  3405. NSDictionary *section = [self jsonAtSection:indexPath.section];
  3406. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  3407. }
  3408. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  3409. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  3410. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  3411. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  3412. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  3413. if (new_item_json) {
  3414. // 更新Item
  3415. [new_section_json setObject:new_item_json forKey:item_key];
  3416. } else {
  3417. // 删除Item
  3418. NSInteger item_count = [self itemCountInSection:indexPath.section];
  3419. for (NSInteger i = 0; i < item_count; i++) {
  3420. if (i >= indexPath.row) {
  3421. if (i < item_count - 1) {
  3422. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  3423. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  3424. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3425. [new_section_json setObject:followed_item_json forKey:item_key];
  3426. } else {
  3427. item_key = [NSString stringWithFormat:@"item_%ld",i];
  3428. [new_section_json removeObjectForKey:item_key];
  3429. }
  3430. }
  3431. }
  3432. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  3433. }
  3434. [new_cart_json setObject:new_section_json forKey:section_key];
  3435. self.cart_json = [new_cart_json copy];
  3436. }
  3437. - (void)reRefreshView {
  3438. [self.itemListTable reloadData];
  3439. }
  3440. #pragma mark - RA_NOTIFICAITON
  3441. -(void) refresh_ui
  3442. {
  3443. [self.itemListTable reloadData];
  3444. [self refresh_total];
  3445. }
  3446. -(void) refresh_price
  3447. {
  3448. [self refresh_ui];
  3449. }
  3450. - (void) reload_data {
  3451. __weak typeof(self) weakself = self;
  3452. self.currentOrderIsMerged = NO;
  3453. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  3454. if (weakself) {
  3455. __strong typeof(weakself) strongself = weakself;
  3456. [strongself operation_reload_data];
  3457. }
  3458. }];
  3459. [self.dataOperationQueue addOperation:operation];
  3460. }
  3461. @end