OrderDetailViewController.m 174 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130
  1. //
  2. // OrderDetailViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/28/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderDetailViewController.h"
  9. #import "OrderDetailInfoCell.h"
  10. #import "OrderDetailHtmlCell.h"
  11. #import "OrderDetailModelCell.h"
  12. #import "OrderDetailPriceCell.h"
  13. #import "OrderDetailSignatureCell.h"
  14. #import "RANetwork.h"
  15. #import "RTLabel.h"
  16. #import "DetailViewController.h"
  17. #import "RAPDFViewController.h"
  18. #import "SignatureViewController.h"
  19. #import "MainViewController.h"
  20. #import "DefaultAppearance.h"
  21. #import "DefaultTableHeaderView.h"
  22. #import "OLDataProvider.h"
  23. #import "OrderDetailPickInfoCell.h"
  24. #define DEF_CELL_HEIGHT 44
  25. #define DEF_TABLE_HEIGHT 44
  26. #define LINE_WIDTH 0
  27. #define CELL_MARGIN 0
  28. #define LABEL_MARGIN 15
  29. @interface OrderDetailViewController ()
  30. @property (nonatomic,assign) BOOL showModels;
  31. @end
  32. @implementation OrderDetailViewController
  33. - (void)saleOrderWithPath:(NSString *)path {
  34. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  35. ViewController.url = path;
  36. ViewController.canSave = false;
  37. ViewController.isLocalfile=YES;
  38. NSString* subject;
  39. subject =[NSString stringWithFormat:@"Sales Order %@",self.order_code];
  40. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  41. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  42. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  43. if(customer_email.length>0)
  44. {
  45. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  46. }
  47. ViewController.mail_to = send_to;
  48. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",self.order_code];
  49. ViewController.mail_subject = subject;
  50. ViewController.hidenavi = false;
  51. [self.navigationController pushViewController:ViewController animated:YES];
  52. }
  53. #ifndef RA_NOTIFICATION
  54. -(void) reload_container_getdata:(bool) update_data
  55. {
  56. [super reload_container_getdata:update_data];
  57. if(update_data)
  58. [self reload_data];
  59. else
  60. {
  61. [self.detailTable reloadData];
  62. }
  63. }
  64. #endif
  65. - (void)onBackClick:(UIButton *)sender {
  66. [self.navigationController popViewControllerAnimated:FALSE];
  67. }
  68. -(void)manually_refresh
  69. {
  70. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  71. if(self.isrefreshing)
  72. {
  73. [reF endRefreshing];
  74. return;
  75. }
  76. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  77. if ([self respondsToSelector:@selector(reload_data)])
  78. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  79. // DebugLog(@"refresh!!!!!!!!");
  80. }
  81. - (void)viewDidLoad {
  82. [super viewDidLoad];
  83. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  84. self.label_net_err.layer.borderWidth = 2.0;
  85. self.label_net_err.layer.cornerRadius=15;
  86. self.label_net_err.layer.masksToBounds=true;
  87. self.showModels = YES;
  88. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  89. // tap.minimumPressDuration = 0.8; //定义按的时间
  90. [self.label_net_err addGestureRecognizer:tap];
  91. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  92. ref.tag = 200 ;
  93. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  94. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  95. // ref.hidden = true;
  96. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  97. [self.detailTable addSubview:ref];
  98. NSMutableArray * items = [[NSMutableArray alloc]init];
  99. self.navigationItem.title=@"View Order Detail";
  100. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  101. style:UIBarButtonItemStylePlain
  102. target:self
  103. action:@selector( onBackClick:)];
  104. // closeButton.tintColor = UIColorFromRGB(0x996633);
  105. self.navigationItem.leftBarButtonItem = closeButton;
  106. self.btnOpen = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  107. style:UIBarButtonItemStylePlain
  108. target:self
  109. action:@selector(onOpenOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
  110. // self.btnOpen.tintColor = UIColorFromRGB(0x996633);
  111. self.btnSign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"signature"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  112. style:UIBarButtonItemStylePlain
  113. target:self
  114. action:@selector(onSignOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
  115. // self.btnSign.tintColor = UIColorFromRGB(0x996633);
  116. #if defined(BUILD_NPD) || defined(BUILD_USAI)|| defined (BUILD_CONTRAST)
  117. self.btnCopy =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"order_copy"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  118. style:UIBarButtonItemStylePlain
  119. target:self
  120. action:@selector(onCopyOrderClick:)];
  121. #else
  122. self.btnCopy =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"copy"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  123. style:UIBarButtonItemStylePlain
  124. target:self
  125. action:@selector(onCopyOrderClick:)];// [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Commit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCommitOrderClick:)];
  126. // self.btnCopy.tintColor = UIColorFromRGB(0x996633);
  127. #endif
  128. // self.btnSend = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Email", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSendMailClick:)];
  129. self.btnRelease = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"unlock"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  130. style:UIBarButtonItemStylePlain
  131. target:self
  132. action:@selector(onReleaseOrderClick:)];
  133. // self.btnRelease.tintColor = UIColorFromRGB(0x996633);
  134. self.btnPDF = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"mail"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  135. style:UIBarButtonItemStylePlain
  136. target:self
  137. action:@selector(onDownloadOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  138. // self.btnPDF.tintColor = UIColorFromRGB(0x996633);
  139. // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  140. // item1.title = @"item1";
  141. //// item1.image = [UIImage imageNamed:@"rect_setting"];
  142. // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  143. //// item2.image = [UIImage imageNamed:@"rect_about"];
  144. // item2.title = @"item2";
  145. // UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  146. // fixedItem.width = 0.0f;
  147. AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
  148. [items addObject:self.btnOpen];
  149. // [items addObject:fixedItem];
  150. // [items addObject:self.btnCommit];
  151. // [items addObject:fixedItem];
  152. if (appDelegate.user_type != USER_ROLE_CUSTOMER) {
  153. [items addObject:self.btnRelease];
  154. }
  155. // [items addObject:fixedItem];
  156. [items addObject:self.btnPDF];
  157. // [items addObject:fixedItem];
  158. [items addObject:self.btnSign];
  159. // [items addObject:fixedItem];
  160. if ((appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer) || appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  161. [items addObject:self.btnCopy];
  162. }
  163. // [items addObject:item2];
  164. self.navigationItem.rightBarButtonItems=items;
  165. self.btnOpen.enabled =false;
  166. self.btnSign.enabled = false;
  167. self.btnCopy.enabled =false;
  168. self.btnPDF.enabled =false;
  169. self.btnRelease.enabled =false;
  170. // if(self.isTempOrder)
  171. // {
  172. //
  173. //
  174. // self.btnOpen.enabled =true;
  175. //
  176. //
  177. // self.btnCommit.enabled =true;
  178. // }
  179. // else
  180. // {
  181. //
  182. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  183. //
  184. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  185. // self.btnOpen.enabled =false;
  186. // self.btnCommit.enabled =false;
  187. // }
  188. // Do any additional setup after loading the view.
  189. // [self loaddata];
  190. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  191. }
  192. //
  193. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  194. //// self.web_info_height = 0;
  195. ////
  196. //// [self.detailTable.indexPathsForVisibleRows enumerateObjectsUsingBlock:^(NSIndexPath * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  197. ////
  198. //// if (obj.section == 0 && obj.section == 0) {
  199. //// [self.detailTable reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  200. //// }
  201. ////
  202. //// }];
  203. //
  204. //
  205. //}
  206. - (IBAction)onReleaseOrderClick:(id)sender {
  207. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  208. //block代码块取代了delegate
  209. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  210. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  211. [RANetwork request_release_order:self.order_code withScreen:ScreenCodeOrderInfo completionHandler:^(NSMutableDictionary *result) {
  212. NSDictionary* order_json =result;
  213. [waitalert dismissViewControllerAnimated:YES completion:^{
  214. if([[order_json valueForKey:@"result"] intValue]==2)
  215. {
  216. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  217. // appDelegate.order_code = nil;
  218. [appDelegate closeOrder];
  219. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  220. //
  221. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  222. // if(self.selectOrder)
  223. // self.selectOrder();
  224. [self.navigationController popToRootViewControllerAnimated:false];
  225. }
  226. else
  227. {
  228. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  229. }
  230. }];
  231. }];
  232. }];
  233. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  234. //
  235. // NSDictionary* order_json = [RANetwork release_Order:self.order_code withScreen:ScreenCodeOrderInfo];
  236. //
  237. // dispatch_async(dispatch_get_main_queue(), ^{
  238. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  239. // if([[order_json valueForKey:@"result"] intValue]==2)
  240. // {
  241. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  242. // // appDelegate.order_code = nil;
  243. // [appDelegate closeOrder];
  244. //
  245. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  246. // //
  247. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  248. // // if(self.selectOrder)
  249. // // self.selectOrder();
  250. // [self.navigationController popToRootViewControllerAnimated:false];
  251. //
  252. // }
  253. // else
  254. // {
  255. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  256. // }
  257. //
  258. //
  259. //
  260. // });
  261. // });
  262. }];
  263. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  264. DebugLog(@"Cancel");
  265. }];
  266. [alertControl addAction:actionOne];
  267. [alertControl addAction:alertthree];
  268. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  269. [self presentViewController:alertControl animated:YES completion:nil];
  270. // get customer info
  271. }
  272. - (void)onDownloadOrderClick:(id)sender {
  273. //
  274. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  275. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  276. ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  277. NSString* so = [self.content_data valueForKey:@"so#"];
  278. if(so==nil)
  279. so =@"";
  280. NSString* company = [self.content_data[@"customerInfo"] valueForKey:@"customer_name"];
  281. if(company==nil)
  282. company =@"";
  283. ViewController.save_name =so;
  284. ViewController.hidenavi = false;
  285. if(company==nil)
  286. company=@"";
  287. NSString* customer_email= [self.content_data[@"customerInfo"] valueForKey:@"customer_email"];
  288. // NSMutableArray* arr_subject = [[NSMutableArray alloc]init];
  289. // if(company.length>0)
  290. // [arr_subject addObject:company];
  291. // if(so.length>0)
  292. // [arr_subject addObject:so];
  293. if(company.length==0)
  294. company=@"";
  295. if(so.length==0)
  296. so=@"";
  297. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  298. if(customer_email.length>0)
  299. {
  300. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  301. // customer_email compo
  302. // [send_to addObject:customer_email];
  303. }
  304. ViewController.mail_to = send_to;
  305. NSString* subject = nil;
  306. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  307. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,COMPANY_NAME];
  308. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  309. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  310. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  311. }
  312. #endif
  313. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  314. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,COMPANY_NAME];
  315. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  316. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  317. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  318. }
  319. #endif
  320. #ifdef BUILD_HMLG
  321. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from Homelegance.",company,so];
  322. #endif
  323. ViewController.mail_subject = subject;
  324. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  325. NSString *alertTitle = @"View Sales Order:";
  326. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30)) {
  327. alertTitle = @"View Store Order";
  328. }
  329. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];
  330. //block代码块取代了delegate
  331. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Thumbnails" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  332. #ifdef OFFLINE_MODE
  333. if(appDelegate.offline_mode)
  334. {
  335. __weak typeof(self) weakself = self;
  336. NSMutableDictionary* params = [@{
  337. @"thumb" : @"1",
  338. @"order_code" : self.order_code != nil ? self.order_code : @"",
  339. @"user":appDelegate.user
  340. } mutableCopy];
  341. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  342. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  343. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  344. NSString *path = dic[@"pdf_path"];
  345. [weakself saleOrderWithPath:path];
  346. // ViewController.url = path;
  347. // ViewController.isLocalfile = YES;
  348. //
  349. // [self.navigationController pushViewController:ViewController animated:YES];
  350. } else {
  351. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  352. }
  353. }
  354. else
  355. #endif
  356. {
  357. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  358. url= [url stringByAppendingString:@"&has_item_pic=true"];
  359. DebugLog(@"pdf url:%@",url);
  360. ViewController.url = url;
  361. [self.navigationController pushViewController:ViewController animated:YES];
  362. }
  363. }];
  364. NSString* alertthreetitle=@"Without Thumbnails";
  365. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))
  366. {
  367. alertthreetitle=@"Print Quotation";
  368. }
  369. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:alertthreetitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  370. #ifdef OFFLINE_MODE
  371. if(appDelegate.offline_mode)
  372. {
  373. __weak typeof(self) weakself = self;
  374. NSMutableDictionary* params = [@{
  375. @"thumb" : @"0",
  376. @"order_code" : self.order_code != nil ? self.order_code : @"",
  377. @"user":appDelegate.user
  378. } mutableCopy];
  379. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  380. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  381. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  382. NSString *path = dic[@"pdf_path"];
  383. [weakself saleOrderWithPath:path];
  384. // ViewController.url = path;
  385. // ViewController.isLocalfile = YES;
  386. //
  387. // [self.navigationController pushViewController:ViewController animated:YES];
  388. } else {
  389. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  390. }
  391. }
  392. else
  393. #endif
  394. {
  395. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  396. DebugLog(@"pdf url:%@",url);
  397. ViewController.url = url;
  398. [self.navigationController pushViewController:ViewController animated:YES];
  399. }
  400. }];
  401. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
  402. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))//[status isEqualToString:@"Saved Order"])
  403. {
  404. [alertControl addAction:alertthree];
  405. [alertControl addAction:alertCancel];
  406. }
  407. else
  408. {
  409. [alertControl addAction:actionOne];
  410. [alertControl addAction:alertthree];
  411. [alertControl addAction:alertCancel];
  412. }
  413. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  414. [self presentViewController:alertControl animated:YES completion:nil];
  415. // get customer info
  416. //
  417. }
  418. - (void)onCopyOrderClick:(id)sender {
  419. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  420. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.order_code) {
  421. __weak typeof(self) weakself = self;
  422. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You must release current order,are you sure to release the order then copy a new order?" preferredStyle:UIAlertControllerStyleAlert];
  423. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  424. }];
  425. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  426. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  427. [RANetwork request_release_order:appDelegate.order_code withScreen:ScreenCodeOrderInfo completionHandler:^(NSMutableDictionary *result) {
  428. NSDictionary* order_json = result;
  429. [waitalert dismissViewControllerAnimated:YES completion:^{
  430. if([[order_json valueForKey:@"result"] intValue]==2)
  431. {
  432. [appDelegate closeOrder];
  433. [weakself copyOrder];
  434. } else {
  435. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
  436. }
  437. }];
  438. }];
  439. }];
  440. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  441. //
  442. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeOrderInfo];
  443. //
  444. // dispatch_async(dispatch_get_main_queue(), ^{
  445. //
  446. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  447. // if([[order_json valueForKey:@"result"] intValue]==2)
  448. // {
  449. // [appDelegate closeOrder];
  450. //
  451. // [weakself copyOrder];
  452. //
  453. // } else {
  454. //
  455. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
  456. // }
  457. // });
  458. //
  459. // });
  460. }];
  461. [alertVC addAction:cancelAction];
  462. [alertVC addAction:yesAction];
  463. [self presentViewController:alertVC animated:YES completion:nil];
  464. } else {
  465. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Copy confirm" message:@"Are you sure to copy order?" preferredStyle:UIAlertControllerStyleAlert];
  466. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  467. [self copyOrder];
  468. }];
  469. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  470. }];
  471. [alertController addAction:action_2];
  472. [alertController addAction:action_3];
  473. [self presentViewController:alertController animated:YES completion:nil];
  474. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Copy confirm", nil) message:NSLocalizedString(@"Are you sure to copy order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  475. // [alert show];
  476. }
  477. }
  478. //- (void)onCommitOrderClick:(id)sender {
  479. // // get customer info
  480. //
  481. // int model_count = [[self.content_data valueForKey:@"model_count"] intValue];
  482. // if(model_count==0)
  483. // {
  484. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error." message:@"Can not submit an order without models." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  485. ////
  486. //// [alert show];
  487. //
  488. //
  489. // [RAUtils alert_view:@"Cannot submit an order without models" title:@""];
  490. // }
  491. //
  492. // else
  493. // {
  494. //
  495. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit confirm", nil) message:NSLocalizedString(@"Are you sure to submit order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  496. // [alert show];
  497. //
  498. // }
  499. //
  500. //
  501. //}
  502. -(void) upload_img :(UIImage*) img
  503. {
  504. #ifdef OFFLINE_MODE
  505. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  506. if(appDelegate.offline_mode)
  507. {
  508. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImageJPEGRepresentation(img,1.0f)];;
  509. // 再将NSData转为字符串
  510. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  511. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  512. DebugLog(@"data string: %@",jsonStr);
  513. NSError *error=nil;
  514. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  515. if([[json valueForKey:@"result"] intValue]==2)
  516. {
  517. NSString* img_url_down = json[@"img_url_aname"];
  518. NSString* img_url_up = json[@"img_url"];
  519. {
  520. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature" completion:^{
  521. [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  522. NSDictionary* order_json = result;
  523. [waitalert dismissViewControllerAnimated:YES completion:^{
  524. if([[order_json valueForKey:@"result"] intValue]==2)
  525. {
  526. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  527. // appDelegate.order_code = self.order_code;
  528. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  529. //
  530. //
  531. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  532. //
  533. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  534. // [self.navigationController popViewControllerAnimated:false];
  535. //
  536. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  537. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  538. // if(self.selectOrder)
  539. // self.selectOrder(self.content_data);
  540. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  541. int count = [[self.content_data objectForKey:@"count"] intValue];
  542. for (int i = 0; i < count; i++) {
  543. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  544. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  545. NSString *type = [section objectForKey:@"type"];
  546. if ([type isEqualToString:@"sign_url"]) {
  547. [section setObject:img_url_down forKey:@"data"];
  548. [self.content_data setObject:section forKey:key];
  549. break;
  550. }
  551. }
  552. #endif
  553. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  554. int count = [[self.content_data objectForKey:@"count"] intValue];
  555. for (int i = 0; i < count; i++) {
  556. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  557. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  558. NSString *type = [section objectForKey:@"type"];
  559. if ([type isEqualToString:@"sign_url"]) {
  560. [section setObject:img_url_down forKey:@"data"];
  561. [self.content_data setObject:section forKey:key];
  562. break;
  563. }
  564. }
  565. #endif
  566. #ifdef BUILD_HMLG
  567. [self.content_data setValue:img_url_down forKey:@"sign_url"];
  568. #endif
  569. //self.btnSign.enabled = false;
  570. [self.detailTable reloadData];
  571. [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  572. }
  573. else
  574. {
  575. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  576. }
  577. }];
  578. }];
  579. }];
  580. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  581. //
  582. // NSDictionary* order_json = [RANetwork sign_Order:self.order_code path:img_url_up];
  583. //
  584. // dispatch_async(dispatch_get_main_queue(), ^{
  585. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  586. // if([[order_json valueForKey:@"result"] intValue]==2)
  587. // {
  588. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  589. // // appDelegate.order_code = self.order_code;
  590. // // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  591. // //
  592. // //
  593. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  594. // //
  595. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  596. // // [self.navigationController popViewControllerAnimated:false];
  597. // //
  598. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  599. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  600. // // if(self.selectOrder)
  601. // // self.selectOrder(self.content_data);
  602. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  603. // int count = [[self.content_data objectForKey:@"count"] intValue];
  604. // for (int i = 0; i < count; i++) {
  605. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  606. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  607. // NSString *type = [section objectForKey:@"type"];
  608. // if ([type isEqualToString:@"sign_url"]) {
  609. // [section setObject:img_url_down forKey:@"data"];
  610. // [self.content_data setObject:section forKey:key];
  611. // break;
  612. // }
  613. // }
  614. //#endif
  615. //
  616. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  617. // int count = [[self.content_data objectForKey:@"count"] intValue];
  618. // for (int i = 0; i < count; i++) {
  619. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  620. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  621. // NSString *type = [section objectForKey:@"type"];
  622. // if ([type isEqualToString:@"sign_url"]) {
  623. // [section setObject:img_url_down forKey:@"data"];
  624. // [self.content_data setObject:section forKey:key];
  625. // break;
  626. // }
  627. // }
  628. //#endif
  629. //
  630. //
  631. //#ifdef BUILD_HMLG
  632. //
  633. // [self.content_data setValue:img_url_down forKey:@"sign_url"];
  634. //#endif
  635. // //self.btnSign.enabled = false;
  636. // [self.detailTable reloadData];
  637. //
  638. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  639. //
  640. //
  641. // }
  642. // else
  643. // {
  644. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  645. // }
  646. //
  647. //
  648. //
  649. // });
  650. // });
  651. }
  652. }
  653. else
  654. {
  655. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  656. }
  657. }
  658. else
  659. #endif
  660. {
  661. NSData *imageData = UIImagePNGRepresentation(img);
  662. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  663. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  664. if(appDelegate.user!=nil)
  665. [params setValue:appDelegate.user forKey:@"user"];
  666. if(appDelegate.password!=nil)
  667. [params setValue:appDelegate.password forKey:@"password"];
  668. __weak typeof(self) weakSelf = self;
  669. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature" completion:^{
  670. [RANetwork request_fastupload:params filename:@"test.jpg" data:imageData url:URL_UPLOAD_IMG completionHandler:^(NSMutableDictionary *result) {
  671. NSMutableDictionary *json=result;
  672. if([[json valueForKey:@"result"] intValue]==2)
  673. {
  674. NSString* img_url_down = json[@"img_url_aname"];
  675. NSString* img_url_up = json[@"img_url"];
  676. {
  677. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  678. [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  679. NSDictionary* order_json =result;
  680. [waitalert dismissViewControllerAnimated:YES completion:^{
  681. if([[order_json valueForKey:@"result"] intValue]==2)
  682. {
  683. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  684. int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  685. for (int i = 0; i < count; i++) {
  686. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  687. NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  688. NSString *type = [section objectForKey:@"type"];
  689. if ([type isEqualToString:@"sign_url"]) {
  690. [section setObject:img_url_down forKey:@"data"];
  691. [weakSelf.content_data setObject:section forKey:key];
  692. break;
  693. }
  694. }
  695. #endif
  696. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  697. int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  698. for (int i = 0; i < count; i++) {
  699. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  700. NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  701. NSString *type = [section objectForKey:@"type"];
  702. if ([type isEqualToString:@"sign_url"]) {
  703. [section setObject:img_url_down forKey:@"data"];
  704. [weakSelf.content_data setObject:section forKey:key];
  705. break;
  706. }
  707. }
  708. #endif
  709. #ifdef BUILD_HMLG
  710. [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  711. #endif
  712. //self.btnSign.enabled = false;
  713. [weakSelf.detailTable reloadData];
  714. [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  715. }
  716. else
  717. {
  718. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  719. }
  720. }];
  721. }];
  722. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  723. //
  724. // NSDictionary* order_json = [RANetwork sign_Order:weakSelf.order_code path:img_url_up];
  725. //
  726. // dispatch_async(dispatch_get_main_queue(), ^{
  727. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  728. // if([[order_json valueForKey:@"result"] intValue]==2)
  729. // {
  730. //
  731. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  732. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  733. // for (int i = 0; i < count; i++) {
  734. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  735. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  736. // NSString *type = [section objectForKey:@"type"];
  737. // if ([type isEqualToString:@"sign_url"]) {
  738. // [section setObject:img_url_down forKey:@"data"];
  739. // [weakSelf.content_data setObject:section forKey:key];
  740. // break;
  741. // }
  742. // }
  743. //#endif
  744. //
  745. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  746. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  747. // for (int i = 0; i < count; i++) {
  748. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  749. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  750. // NSString *type = [section objectForKey:@"type"];
  751. // if ([type isEqualToString:@"sign_url"]) {
  752. // [section setObject:img_url_down forKey:@"data"];
  753. // [weakSelf.content_data setObject:section forKey:key];
  754. // break;
  755. // }
  756. // }
  757. //#endif
  758. //
  759. //#ifdef BUILD_HMLG
  760. // [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  761. //#endif
  762. // //self.btnSign.enabled = false;
  763. // [weakSelf.detailTable reloadData];
  764. //
  765. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  766. //
  767. //
  768. // }
  769. // else
  770. // {
  771. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  772. // }
  773. //
  774. //
  775. //
  776. // });
  777. // });
  778. }
  779. }
  780. else
  781. {
  782. dispatch_async(dispatch_get_main_queue(), ^{
  783. [waitalert dismissViewControllerAnimated:YES completion:^{
  784. NSString *msg = [json valueForKey:@"err_msg"];
  785. if (msg.length == 0) {
  786. msg = [json objectForKey:@"msg"];
  787. }
  788. [RAUtils message_alert:msg title:@"Upload Image" controller:weakSelf] ;
  789. }];
  790. });
  791. }
  792. }];
  793. }];
  794. // [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
  795. //
  796. // if([[json valueForKey:@"result"] intValue]==2)
  797. // {
  798. // NSString* img_url_down = json[@"img_url_aname"];
  799. // NSString* img_url_up = json[@"img_url"];
  800. // {
  801. //// UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  802. // [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  803. // NSDictionary* order_json =result;
  804. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  805. // if([[order_json valueForKey:@"result"] intValue]==2)
  806. // {
  807. //
  808. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  809. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  810. // for (int i = 0; i < count; i++) {
  811. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  812. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  813. // NSString *type = [section objectForKey:@"type"];
  814. // if ([type isEqualToString:@"sign_url"]) {
  815. // [section setObject:img_url_down forKey:@"data"];
  816. // [weakSelf.content_data setObject:section forKey:key];
  817. // break;
  818. // }
  819. // }
  820. //#endif
  821. //
  822. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  823. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  824. // for (int i = 0; i < count; i++) {
  825. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  826. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  827. // NSString *type = [section objectForKey:@"type"];
  828. // if ([type isEqualToString:@"sign_url"]) {
  829. // [section setObject:img_url_down forKey:@"data"];
  830. // [weakSelf.content_data setObject:section forKey:key];
  831. // break;
  832. // }
  833. // }
  834. //#endif
  835. //
  836. //#ifdef BUILD_HMLG
  837. // [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  838. //#endif
  839. // //self.btnSign.enabled = false;
  840. // [weakSelf.detailTable reloadData];
  841. //
  842. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  843. //
  844. //
  845. // }
  846. // else
  847. // {
  848. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  849. // }
  850. //
  851. //
  852. //
  853. // }];
  854. //
  855. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  856. ////
  857. //// NSDictionary* order_json = [RANetwork sign_Order:weakSelf.order_code path:img_url_up];
  858. ////
  859. //// dispatch_async(dispatch_get_main_queue(), ^{
  860. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  861. //// if([[order_json valueForKey:@"result"] intValue]==2)
  862. //// {
  863. ////
  864. ////#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  865. //// int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  866. //// for (int i = 0; i < count; i++) {
  867. //// NSString *key = [NSString stringWithFormat:@"section_%d",i];
  868. //// NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  869. //// NSString *type = [section objectForKey:@"type"];
  870. //// if ([type isEqualToString:@"sign_url"]) {
  871. //// [section setObject:img_url_down forKey:@"data"];
  872. //// [weakSelf.content_data setObject:section forKey:key];
  873. //// break;
  874. //// }
  875. //// }
  876. ////#endif
  877. ////
  878. ////#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  879. //// int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  880. //// for (int i = 0; i < count; i++) {
  881. //// NSString *key = [NSString stringWithFormat:@"section_%d",i];
  882. //// NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  883. //// NSString *type = [section objectForKey:@"type"];
  884. //// if ([type isEqualToString:@"sign_url"]) {
  885. //// [section setObject:img_url_down forKey:@"data"];
  886. //// [weakSelf.content_data setObject:section forKey:key];
  887. //// break;
  888. //// }
  889. //// }
  890. ////#endif
  891. ////
  892. ////#ifdef BUILD_HMLG
  893. //// [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  894. ////#endif
  895. //// //self.btnSign.enabled = false;
  896. //// [weakSelf.detailTable reloadData];
  897. ////
  898. //// [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  899. ////
  900. ////
  901. //// }
  902. //// else
  903. //// {
  904. //// [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  905. //// }
  906. ////
  907. ////
  908. ////
  909. //// });
  910. //// });
  911. // }
  912. //
  913. //
  914. // }
  915. // else
  916. // {
  917. // dispatch_async(dispatch_get_main_queue(), ^{
  918. //
  919. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  920. // NSString *msg = [json valueForKey:@"err_msg"];
  921. // if (msg.length == 0) {
  922. // msg = [json objectForKey:@"msg"];
  923. // }
  924. //
  925. // [RAUtils message_alert:msg title:@"Upload Image" controller:weakSelf] ;
  926. // });
  927. // }
  928. //
  929. // } Progress:nil DecryptHandler:nil];
  930. // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
  931. // DebugLog(URL_UPLOAD_IMG);
  932. //
  933. // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  934. // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
  935. // } error:nil];
  936. //
  937. //
  938. // // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  939. // // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
  940. // // } error:nil];
  941. // //
  942. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  943. //
  944. //
  945. //
  946. // //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  947. //
  948. //
  949. //
  950. // //
  951. // NSProgress *progress = nil;
  952. //
  953. // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
  954. //
  955. // // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
  956. //
  957. //
  958. //
  959. //
  960. // if (error) {
  961. //
  962. // NSString* err_msg = [error localizedDescription];
  963. // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
  964. //
  965. //
  966. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  967. //
  968. // DebugLog(@"data string: %@",str);
  969. //
  970. // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
  971. //
  972. // } else {
  973. // DebugLog(@"response ");
  974. //
  975. //
  976. //
  977. // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
  978. //
  979. // // 再将NSData转为字符串
  980. // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  981. //
  982. // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  983. //
  984. // DebugLog(@"data string: %@",jsonStr);
  985. //
  986. // NSDictionary* json = responseObject;
  987. //
  988. // if([[json valueForKey:@"result"] intValue]==2)
  989. // {
  990. // NSString* img_url_down = json[@"img_url_aname"];
  991. // NSString* img_url_up = json[@"img_url"];
  992. //
  993. // {
  994. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  995. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  996. //
  997. // NSDictionary* order_json = [iSalesNetwork sign_Order:self.order_code path:img_url_up];
  998. //
  999. // dispatch_async(dispatch_get_main_queue(), ^{
  1000. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1001. // if([[order_json valueForKey:@"result"] intValue]==2)
  1002. // {
  1003. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1004. // // appDelegate.order_code = self.order_code;
  1005. // // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1006. // //
  1007. // //
  1008. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1009. // //
  1010. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1011. // // [self.navigationController popViewControllerAnimated:false];
  1012. // //
  1013. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1014. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1015. // // if(self.selectOrder)
  1016. // // self.selectOrder(self.content_data);
  1017. //
  1018. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  1019. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1020. // for (int i = 0; i < count; i++) {
  1021. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1022. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1023. // NSString *type = [section objectForKey:@"type"];
  1024. // if ([type isEqualToString:@"sign_url"]) {
  1025. // [section setObject:img_url_down forKey:@"data"];
  1026. // [self.content_data setObject:section forKey:key];
  1027. // break;
  1028. // }
  1029. // }
  1030. //#endif
  1031. //
  1032. //#ifdef BUILD_HOMER
  1033. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1034. // for (int i = 0; i < count; i++) {
  1035. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1036. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1037. // NSString *type = [section objectForKey:@"type"];
  1038. // if ([type isEqualToString:@"sign_url"]) {
  1039. // [section setObject:img_url_down forKey:@"data"];
  1040. // [self.content_data setObject:section forKey:key];
  1041. // break;
  1042. // }
  1043. // }
  1044. //#endif
  1045. //#ifdef BUILD_GATIT
  1046. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1047. // for (int i = 0; i < count; i++) {
  1048. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1049. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1050. // NSString *type = [section objectForKey:@"type"];
  1051. // if ([type isEqualToString:@"sign_url"]) {
  1052. // [section setObject:img_url_down forKey:@"data"];
  1053. // [self.content_data setObject:section forKey:key];
  1054. // break;
  1055. // }
  1056. // }
  1057. //#endif
  1058. //
  1059. //#ifdef BUILD_HMLG
  1060. // [self.content_data setValue:img_url_down forKey:@"sign_url"];
  1061. //#endif
  1062. // //self.btnSign.enabled = false;
  1063. // [self.detailTable reloadData];
  1064. //
  1065. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  1066. //
  1067. //
  1068. // }
  1069. // else
  1070. // {
  1071. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  1072. // }
  1073. //
  1074. //
  1075. //
  1076. // });
  1077. // });
  1078. // }
  1079. //
  1080. //
  1081. // }
  1082. // else
  1083. // {
  1084. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  1085. // }
  1086. //
  1087. //
  1088. //
  1089. //
  1090. //
  1091. //
  1092. // }
  1093. // // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1094. // }];
  1095. //
  1096. // [uploadTask resume];
  1097. }
  1098. }
  1099. - (IBAction)onSignOrderClick:(id)sender {
  1100. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1101. if (appDelegate.order_code.length > 0 && [self.order_code isEqualToString:appDelegate.order_code]) {
  1102. [self showSignaturePanel];
  1103. } else {
  1104. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"you need open the order first" preferredStyle:UIAlertControllerStyleAlert];
  1105. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1106. }];
  1107. [alertVC addAction:cancelAction];
  1108. __weak typeof(self) weakSelf = self;
  1109. UIAlertAction *openAction = [UIAlertAction actionWithTitle:@"Open" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1110. [self opentOrder:^{
  1111. [weakSelf showSignaturePanel];
  1112. }];
  1113. }];
  1114. [alertVC addAction:openAction];
  1115. [self presentViewController:alertVC animated:YES completion:nil];
  1116. }
  1117. }
  1118. - (void)showSignaturePanel {
  1119. __block UIImage* signimg=nil;
  1120. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:nil] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  1121. vc.onReturnImg = ^(UIImage* img)
  1122. {
  1123. signimg = img;
  1124. if(signimg!=nil)
  1125. [self upload_img:signimg];
  1126. };
  1127. [self.navigationController pushViewController:vc animated:NO];
  1128. }
  1129. - (void)opentOrder:(void(^)(void))completionBlk {
  1130. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Open Order" completion:^{
  1131. [RANetwork request_open_order:self.order_code completionHandler:^(NSMutableDictionary *result) {
  1132. NSDictionary* order_json = result;
  1133. [waitalert dismissViewControllerAnimated:YES completion:^{
  1134. if([[order_json valueForKey:@"result"] intValue]==2)
  1135. {
  1136. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1137. appDelegate.order_code = self.order_code;
  1138. appDelegate.order_status = self.order_status;
  1139. [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1140. appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1141. appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1142. // [self.navigationController popViewControllerAnimated:false];
  1143. #ifdef RA_NOTIFICATION
  1144. [ActiveViewController Notify:@"CartViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1145. #else
  1146. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1147. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1148. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1149. #endif
  1150. if (completionBlk) {
  1151. completionBlk();
  1152. }
  1153. // if(self.selectOrder)
  1154. // self.selectOrder(self.content_data);
  1155. }
  1156. else
  1157. {
  1158. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  1159. }
  1160. }];
  1161. }];
  1162. }];
  1163. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1164. //
  1165. // NSDictionary* order_json = [RANetwork open_Order:self.order_code];
  1166. //
  1167. // dispatch_async(dispatch_get_main_queue(), ^{
  1168. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1169. // if([[order_json valueForKey:@"result"] intValue]==2)
  1170. // {
  1171. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1172. // appDelegate.order_code = self.order_code;
  1173. // appDelegate.order_status = self.order_status;
  1174. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1175. //
  1176. //
  1177. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1178. //
  1179. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1180. //
  1181. //// [self.navigationController popViewControllerAnimated:false];
  1182. //
  1183. //#ifdef RA_NOTIFICATION
  1184. // [ActiveViewController Notify:@"CartViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1185. //#else
  1186. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1187. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1188. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1189. //#endif
  1190. //
  1191. // if (completionBlk) {
  1192. // completionBlk();
  1193. // }
  1194. //
  1195. //// if(self.selectOrder)
  1196. //// self.selectOrder(self.content_data);
  1197. // }
  1198. // else
  1199. // {
  1200. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  1201. // }
  1202. //
  1203. //
  1204. //
  1205. // });
  1206. // });
  1207. }
  1208. - (IBAction)onOpenOrderClick:(id)sender {
  1209. // get customer info
  1210. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to open order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1211. //block代码块取代了delegate
  1212. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1213. [self opentOrder:^{
  1214. [self.navigationController popViewControllerAnimated:false];
  1215. if(self.selectOrder)
  1216. self.selectOrder(self.content_data);
  1217. }];
  1218. }];
  1219. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1220. DebugLog(@"Cancel");
  1221. }];
  1222. [alertControl addAction:actionOne];
  1223. [alertControl addAction:alertthree];
  1224. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1225. [self presentViewController:alertControl animated:YES completion:nil];
  1226. }
  1227. - (void)didReceiveMemoryWarning {
  1228. [super didReceiveMemoryWarning];
  1229. // Dispose of any resources that can be recreated.
  1230. }
  1231. -(void) loaddata
  1232. {
  1233. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading"];
  1234. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  1235. // dispatch_async(dispatch_get_main_queue(), ^{
  1236. if(self.isrefreshing)
  1237. return;
  1238. self.detailTable.hidden = true;
  1239. self.label_net_err.hidden=true;
  1240. self.isrefreshing=true;
  1241. self.mum.center = self.view.center;
  1242. self.mum.hidden = false;
  1243. [self.mum startAnimating];
  1244. DebugLog(@"reloading...");
  1245. self.web_info_height=0;
  1246. self.web_moreinfo_height=0;
  1247. // self.content_data = nil;
  1248. self.btnOpen.enabled =false;
  1249. self.btnSign.enabled = false;
  1250. self.btnCopy.enabled =false;
  1251. self.btnPDF.enabled =false;
  1252. self.btnRelease.enabled =false;
  1253. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1254. [params setValue:self.orderid forKey:@"orderId"];
  1255. if (self.erpSerialNo) {
  1256. [params setValue:self.erpSerialNo forKey:@"erp_order_serial_no"];
  1257. }
  1258. [RANetwork request_orderdetail:params completionHandler:^(NSMutableDictionary *result) {
  1259. NSDictionary* order_json = result;
  1260. [waitalert dismissViewControllerAnimated:YES completion:^{
  1261. [self.mum stopAnimating];
  1262. if([[order_json valueForKey:@"result"] intValue]==2)
  1263. {
  1264. self.detailTable.hidden = false;
  1265. self.content_data = [order_json mutableCopy];
  1266. }
  1267. else {
  1268. self.content_data = nil;
  1269. if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1270. {
  1271. self.label_net_err.hidden=false;
  1272. self.detailTable.hidden=true;
  1273. }
  1274. else
  1275. {
  1276. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  1277. }
  1278. }
  1279. bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
  1280. if(web_order)
  1281. self.btnCopy.enabled = false;
  1282. else
  1283. self.btnCopy.enabled = true;
  1284. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1285. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1286. int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  1287. if(model_count>0)/*&& ! appDelegate.offline_mode*/
  1288. {
  1289. if(appDelegate.user_type== USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1290. self.btnPDF.enabled =true;
  1291. else
  1292. {
  1293. // || appDelegate.user_type==USER_ROLE_CUSTOMER
  1294. if(self.is_shoporder)
  1295. {
  1296. if(status_code==1||status_code==30)
  1297. self.btnPDF.enabled =true;
  1298. }
  1299. else
  1300. {
  1301. if(status_code==2)
  1302. self.btnPDF.enabled =true;
  1303. }
  1304. }
  1305. }
  1306. // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1307. // NSString* status = [self.content_data valueForKey:@"order_status"];
  1308. NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  1309. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1310. if(status_code==1)//[status isEqualToString:@"Saved Order"])
  1311. {
  1312. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1313. //
  1314. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1315. BOOL condition = offline_edit;
  1316. #ifdef OFFLINE_MODE
  1317. condition = condition || appDelegate.offline_mode==false;
  1318. #else
  1319. condition = YES;
  1320. #endif
  1321. if(condition)
  1322. {
  1323. self.btnOpen.enabled =true;
  1324. self.btnSign.enabled = true;
  1325. }
  1326. // if([lock_user isEqualToString:appDelegate.user])
  1327. // {
  1328. // self.btnCommit.enabled =true;
  1329. // }
  1330. // else
  1331. // self.btnCommit.enabled =false;
  1332. }
  1333. else
  1334. if(status_code==0)//[status isEqualToString:@"Quote Saved"])
  1335. {
  1336. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1337. //
  1338. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1339. BOOL condition = offline_edit;
  1340. #ifdef OFFLINE_MODE
  1341. condition = condition || appDelegate.offline_mode==false;
  1342. #else
  1343. condition = YES;
  1344. #endif
  1345. if (condition)
  1346. {
  1347. self.btnOpen.enabled =true;
  1348. self.btnSign.enabled = true;
  1349. }
  1350. // self.btnCommit.enabled =false;
  1351. }
  1352. BOOL lock_condition_1 = [lock_user isEqualToString:appDelegate.user];
  1353. BOOL lock_condition_2 = false;
  1354. #ifdef OFFLINE_MODE
  1355. lock_condition_1 = !appDelegate.offline_mode && lock_condition_1;
  1356. lock_condition_2 = appDelegate.offline_mode && [self.order_code isEqualToString:appDelegate.order_code];
  1357. #endif
  1358. if((lock_condition_1 || lock_condition_2)&& (status_code==1||status_code==0))
  1359. {
  1360. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1361. self.btnRelease.enabled =true;
  1362. }
  1363. else
  1364. {
  1365. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1366. self.btnRelease.enabled =false;
  1367. }
  1368. [self.detailTable reloadData];
  1369. self.isrefreshing=false;
  1370. if (self.order_code == nil) {
  1371. self.btnCopy.enabled = false;
  1372. } else {
  1373. self.btnCopy.enabled = true;
  1374. }
  1375. }];
  1376. }];
  1377. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1378. //
  1379. //
  1380. // NSDictionary* order_json = [RANetwork request_OrderDetail:params];
  1381. //
  1382. // dispatch_async(dispatch_get_main_queue(), ^{
  1383. //
  1384. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1385. // [self.mum stopAnimating];
  1386. // if([[order_json valueForKey:@"result"] intValue]==2)
  1387. // {
  1388. // self.detailTable.hidden = false;
  1389. // self.content_data = [order_json mutableCopy];
  1390. //
  1391. //
  1392. // }
  1393. // else {
  1394. // self.content_data = nil;
  1395. // if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1396. // {
  1397. // self.label_net_err.hidden=false;
  1398. // self.detailTable.hidden=true;
  1399. // }
  1400. // else
  1401. // {
  1402. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  1403. // }
  1404. // }
  1405. //
  1406. // bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
  1407. // if(web_order)
  1408. // self.btnCopy.enabled = false;
  1409. // else
  1410. // self.btnCopy.enabled = true;
  1411. // int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1412. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1413. // int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  1414. // if(model_count>0)/*&& ! appDelegate.offline_mode*/
  1415. // {
  1416. // if(appDelegate.user_type== USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1417. // self.btnPDF.enabled =true;
  1418. // else
  1419. // {
  1420. // // || appDelegate.user_type==USER_ROLE_CUSTOMER
  1421. // if(self.is_shoporder)
  1422. // {
  1423. // if(status_code==1||status_code==30)
  1424. // self.btnPDF.enabled =true;
  1425. //
  1426. // }
  1427. // else
  1428. // {
  1429. // if(status_code==2)
  1430. // self.btnPDF.enabled =true;
  1431. // }
  1432. // }
  1433. // }
  1434. // // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1435. //
  1436. //// NSString* status = [self.content_data valueForKey:@"order_status"];
  1437. //
  1438. // NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  1439. //
  1440. // bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1441. // if(status_code==1)//[status isEqualToString:@"Saved Order"])
  1442. // {
  1443. // // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1444. // //
  1445. // // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1446. //
  1447. // BOOL condition = offline_edit;
  1448. //#ifdef OFFLINE_MODE
  1449. // condition = condition || appDelegate.offline_mode==false;
  1450. //#else
  1451. // condition = YES;
  1452. //#endif
  1453. // if(condition)
  1454. // {
  1455. // self.btnOpen.enabled =true;
  1456. //
  1457. // self.btnSign.enabled = true;
  1458. // }
  1459. // // if([lock_user isEqualToString:appDelegate.user])
  1460. // // {
  1461. // // self.btnCommit.enabled =true;
  1462. // // }
  1463. // // else
  1464. // // self.btnCommit.enabled =false;
  1465. // }
  1466. // else
  1467. // if(status_code==0)//[status isEqualToString:@"Quote Saved"])
  1468. // {
  1469. // // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1470. // //
  1471. // // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1472. //
  1473. // BOOL condition = offline_edit;
  1474. //#ifdef OFFLINE_MODE
  1475. // condition = condition || appDelegate.offline_mode==false;
  1476. //#else
  1477. // condition = YES;
  1478. //#endif
  1479. // if (condition)
  1480. // {
  1481. // self.btnOpen.enabled =true;
  1482. //
  1483. // self.btnSign.enabled = true;
  1484. // }
  1485. // // self.btnCommit.enabled =false;
  1486. // }
  1487. // BOOL lock_condition_1 = [lock_user isEqualToString:appDelegate.user];
  1488. // BOOL lock_condition_2 = false;
  1489. //#ifdef OFFLINE_MODE
  1490. // lock_condition_1 = !appDelegate.offline_mode && lock_condition_1;
  1491. // lock_condition_2 = appDelegate.offline_mode && [self.order_code isEqualToString:appDelegate.order_code];
  1492. //#endif
  1493. //
  1494. // if((lock_condition_1 || lock_condition_2)&& (status_code==1||status_code==0))
  1495. // {
  1496. // // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1497. //
  1498. //
  1499. // self.btnRelease.enabled =true;
  1500. // }
  1501. // else
  1502. // {
  1503. //
  1504. //
  1505. // // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1506. // self.btnRelease.enabled =false;
  1507. // }
  1508. //
  1509. // [self.detailTable reloadData];
  1510. // self.isrefreshing=false;
  1511. //
  1512. // if (self.order_code == nil) {
  1513. // self.btnCopy.enabled = false;
  1514. // } else {
  1515. // self.btnCopy.enabled = true;
  1516. // }
  1517. //
  1518. // });
  1519. //
  1520. // });
  1521. // });
  1522. }];
  1523. }
  1524. - (void)viewWillAppear:(BOOL)animated
  1525. {
  1526. [super viewWillAppear:animated];
  1527. // if(appDelegate.can_submit_order)
  1528. // {
  1529. //
  1530. //
  1531. // [self.btnCommit setImage:[UIImage imageNamed:@"commit"]];
  1532. // self.btnCommit.enabled = true;
  1533. // }
  1534. // else
  1535. // {
  1536. // [self.btnCommit setImage:nil];
  1537. // self.btnCommit.enabled = false;
  1538. // }
  1539. //
  1540. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1541. }
  1542. - (IBAction)imgbtnClicked:(UIButton*)sender {
  1543. // 这里有问题,npd 里order 提交后,product id 为空,暂时屏蔽掉
  1544. return;
  1545. // 以下为屏蔽前的代码
  1546. //
  1547. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1548. //
  1549. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1550. //
  1551. //// if(indexPath.section!=1)
  1552. //// return ;
  1553. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1554. // NSDictionary * item_json = self.content_data[[NSString stringWithFormat:@"section_%ld",(long)indexPath.section]][@"data"][[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1555. //// NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1556. //
  1557. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1558. //
  1559. // DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1560. // // dvc
  1561. //
  1562. // dvc.product_id=product_id;
  1563. // dvc.category_id=nil;
  1564. // dvc.ispush=true;
  1565. // [dvc reload];
  1566. // [self.navigationController pushViewController:dvc animated:true];
  1567. }
  1568. /*
  1569. #pragma mark - Navigation
  1570. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1571. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1572. // Get the new view controller using [segue destinationViewController].
  1573. // Pass the selected object to the new view controller.
  1574. }
  1575. */
  1576. #pragma mark - Table view data source
  1577. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1578. {
  1579. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1580. // if([item_json objectForKey:@"combine"] == nil)
  1581. // {
  1582. // return 120;
  1583. // }
  1584. // else
  1585. // return 150;
  1586. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1587. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1588. NSDictionary *data = [section_item objectForKey:@"data"];
  1589. NSString *type = [section_item objectForKey:@"type"];
  1590. if ([type isEqualToString:@"order_info"]) {
  1591. float height= self.web_info_height;
  1592. if(height==0)
  1593. height=DEF_TABLE_HEIGHT;
  1594. return height;
  1595. } else if ([type isEqualToString:@"sign_url"]) {
  1596. return 148;
  1597. } else if ([type isEqualToString:@"more_order_info"]) {
  1598. float height= self.web_moreinfo_height;
  1599. if(height==0)
  1600. height=DEF_TABLE_HEIGHT;
  1601. return height;
  1602. } else if ([type isEqualToString:@"sub_order"]) {
  1603. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1604. NSString *item_type = [item objectForKey:@"type"];
  1605. if ([item_type isEqualToString:@"pick_info"]) {
  1606. return 218;
  1607. } else {
  1608. NSString* notes =[item valueForKey:@"note"];
  1609. if(notes.length>0)
  1610. {
  1611. return 190;
  1612. }
  1613. else
  1614. return 162;
  1615. }
  1616. } else if ([type isEqualToString:@"price_info"]) {
  1617. return 44;
  1618. }
  1619. #endif
  1620. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1621. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1622. NSDictionary *data = [section_item objectForKey:@"data"];
  1623. NSString *type = [section_item objectForKey:@"type"];
  1624. if ([type isEqualToString:@"order_info"]) {
  1625. float height= self.web_info_height;
  1626. if(height==0)
  1627. height=DEF_TABLE_HEIGHT;
  1628. return height;
  1629. } else if ([type isEqualToString:@"sign_url"]) {
  1630. return 148;
  1631. } else if ([type isEqualToString:@"more_order_info"]) {
  1632. float height= self.web_moreinfo_height;
  1633. if(height==0)
  1634. height=DEF_TABLE_HEIGHT;
  1635. return height;
  1636. } else if ([type isEqualToString:@"sub_order"]) {
  1637. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1638. NSString *item_type = [item objectForKey:@"type"];
  1639. if ([item_type isEqualToString:@"pick_info"]) {
  1640. return 218;
  1641. } else {
  1642. NSString* notes =[item valueForKey:@"note"];
  1643. if(notes.length>0)
  1644. {
  1645. return 190;
  1646. }
  1647. else
  1648. return 162;
  1649. }
  1650. } else if ([type isEqualToString:@"price_info"]) {
  1651. return 44;
  1652. }
  1653. #endif
  1654. #ifdef BUILD_HMLG
  1655. switch (indexPath.section) {
  1656. case 0:
  1657. {
  1658. if(indexPath.row==0)
  1659. {
  1660. float height= self.web_info_height;
  1661. if(height==0)
  1662. height=DEF_TABLE_HEIGHT;
  1663. return height;
  1664. }
  1665. else
  1666. return 148;
  1667. }
  1668. break;
  1669. case 1:
  1670. {
  1671. float height= self.web_moreinfo_height;
  1672. if(height==0)
  1673. height=DEF_TABLE_HEIGHT;
  1674. return height;
  1675. }
  1676. break;
  1677. case 2:
  1678. {
  1679. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1680. NSString* notes =[item_json valueForKey:@"note"];
  1681. if(notes.length>0)
  1682. {
  1683. return 190;
  1684. }
  1685. else
  1686. return 162;
  1687. }
  1688. case 3:
  1689. return 44;
  1690. default:
  1691. break;
  1692. }
  1693. #endif
  1694. return 44;
  1695. }
  1696. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1697. //{
  1698. // return 0;
  1699. //}
  1700. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1701. //{
  1702. // return 0;
  1703. //}
  1704. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1705. //{
  1706. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1707. // return myView;
  1708. //
  1709. //}
  1710. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1711. //{
  1712. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1713. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1714. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1715. //// titleLabel.textColor=[UIColor whiteColor];
  1716. //// titleLabel.backgroundColor = [UIColor clearColor];
  1717. //// if(section==0)
  1718. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1719. //// else
  1720. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1721. //// [titleLabel sizeToFit];
  1722. //// [myView addSubview:titleLabel];
  1723. ////
  1724. // return myView;
  1725. //}
  1726. //
  1727. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1728. {
  1729. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1730. if(value==nil)
  1731. value=@"";
  1732. unsigned long color = strtoul([value UTF8String],0,16);
  1733. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1734. // myView.backgroundColor = UIColorFromRGB(0x996633);;
  1735. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1736. // myView.layer.masksToBounds = false;
  1737. //添加四个边阴影
  1738. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1739. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1740. myView.layer.shadowOpacity = 0.5;
  1741. myView.layer.shadowRadius = 2.0;
  1742. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1743. NSString*labeltitle = nil;
  1744. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1745. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1746. NSString *title = [section_item objectForKey:@"title"];
  1747. labeltitle = title;
  1748. if ([title isEqualToString:@"More Info"]) {
  1749. NSString* btntitle=nil ;
  1750. if(self.showMore)
  1751. {
  1752. btntitle=@"Hide";
  1753. }
  1754. else{
  1755. btntitle=@"Show";
  1756. }
  1757. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1758. btn.tag=section;
  1759. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1760. [btn setTitle:btntitle forState:UIControlStateNormal];
  1761. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1762. [myView addSubview:btn];
  1763. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1764. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1765. NSString *normalTitle = @"Show";
  1766. NSString *selectedTitle = @"Hide";
  1767. if (item_switch == YES) {
  1768. normalTitle = @"Hide";
  1769. selectedTitle = @"Show";
  1770. }
  1771. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1772. btn.tag=section;
  1773. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1774. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1775. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1776. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1777. [myView addSubview:btn];
  1778. }
  1779. #endif
  1780. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1781. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1782. NSString *title = [section_item objectForKey:@"title"];
  1783. labeltitle = title;
  1784. if ([title isEqualToString:@"More Info"]) {
  1785. NSString* btntitle=nil ;
  1786. if(self.showMore)
  1787. {
  1788. btntitle=@"Hide";
  1789. }
  1790. else{
  1791. btntitle=@"Show";
  1792. }
  1793. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1794. btn.tag=section;
  1795. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1796. [btn setTitle:btntitle forState:UIControlStateNormal];
  1797. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1798. [myView addSubview:btn];
  1799. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1800. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1801. NSString *normalTitle = @"Show";
  1802. NSString *selectedTitle = @"Hide";
  1803. if (item_switch == YES) {
  1804. normalTitle = @"Hide";
  1805. selectedTitle = @"Show";
  1806. }
  1807. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1808. btn.tag=section;
  1809. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1810. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1811. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1812. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1813. [myView addSubview:btn];
  1814. }
  1815. #endif
  1816. #ifdef BUILD_HMLG
  1817. switch (section) {
  1818. case 0:
  1819. labeltitle= @"Order Info";
  1820. break;
  1821. case 1:
  1822. {
  1823. labeltitle= @"More Info";
  1824. NSString* btntitle=nil ;
  1825. if(self.showMore)
  1826. {
  1827. btntitle=@"Hide";
  1828. // [section setValue:@"false" forKey:@"hide"];
  1829. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  1830. }
  1831. else{
  1832. btntitle=@"Show";
  1833. }
  1834. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1835. btn.tag=section;
  1836. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1837. [btn setTitle:btntitle forState:UIControlStateNormal];
  1838. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1839. [myView addSubview:btn];
  1840. }
  1841. break;
  1842. case 2:{
  1843. labeltitle= @"Models";
  1844. NSString* btntitle=nil ;
  1845. if(self.showModels)
  1846. {
  1847. btntitle=@"Hide";
  1848. }
  1849. else{
  1850. btntitle=@"Show";
  1851. }
  1852. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1853. btn.tag=section;
  1854. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1855. [btn setTitle:btntitle forState:UIControlStateNormal];
  1856. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1857. [myView addSubview:btn];
  1858. }
  1859. break;
  1860. case 3:
  1861. labeltitle= @"Price Info";
  1862. default:
  1863. break;
  1864. }
  1865. #endif
  1866. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  1867. titlelabel.textColor=UIColorFromRGB(color);;
  1868. titlelabel.backgroundColor = [UIColor clearColor];
  1869. titlelabel.text=NSLocalizedString(labeltitle, nil);
  1870. [titlelabel sizeToFit];
  1871. titlelabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  1872. [myView addSubview:titlelabel];
  1873. //
  1874. return myView;
  1875. }
  1876. #pragma mark - hide section button clicked
  1877. - (void)HideSction:(UIButton *)sender {
  1878. /*
  1879. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
  1880. bool hide = [[section valueForKey:@"hide"]boolValue];
  1881. if(hide)
  1882. {
  1883. [section setValue:@"false" forKey:@"hide"];
  1884. [sender setTitle:@"Show" forState:UIControlStateNormal];
  1885. }
  1886. else{
  1887. [section setValue:@"true" forKey:@"hide"];
  1888. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1889. }
  1890. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
  1891. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1892. */
  1893. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1894. NSUInteger section = sender.tag;
  1895. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1896. NSString *title = [section_item objectForKey:@"title"];
  1897. if ([title isEqualToString:@"More Info"]) {
  1898. self.showMore = !self.showMore;
  1899. NSRange range = NSMakeRange(section, 1);
  1900. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1901. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1902. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1903. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1904. if (item_switch == YES) {
  1905. [section_item setObject:@(NO) forKey:@"switch"];
  1906. } else {
  1907. [section_item setObject:@(YES) forKey:@"switch"];
  1908. }
  1909. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1910. sender.selected = !sender.selected;
  1911. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1912. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1913. }
  1914. #endif
  1915. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1916. NSUInteger section = sender.tag;
  1917. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1918. NSString *title = [section_item objectForKey:@"title"];
  1919. if ([title isEqualToString:@"More Info"]) {
  1920. self.showMore = !self.showMore;
  1921. NSRange range = NSMakeRange(section, 1);
  1922. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1923. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1924. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1925. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1926. if (item_switch == YES) {
  1927. [section_item setObject:@(NO) forKey:@"switch"];
  1928. } else {
  1929. [section_item setObject:@(YES) forKey:@"switch"];
  1930. }
  1931. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1932. sender.selected = !sender.selected;
  1933. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1934. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1935. }
  1936. #endif
  1937. #ifdef BUILD_HMLG
  1938. switch (sender.tag) {
  1939. case 0:{
  1940. }
  1941. break;
  1942. case 1:{
  1943. self.showMore=!self.showMore;
  1944. NSRange range = NSMakeRange(1, 1);
  1945. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1946. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1947. }
  1948. break;
  1949. case 2:{
  1950. self.showModels = !self.showModels;
  1951. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:2];
  1952. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1953. }
  1954. break;
  1955. default:
  1956. break;
  1957. }
  1958. #endif
  1959. }
  1960. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1961. switch (section) {
  1962. case 0:
  1963. return @"Order Info";
  1964. break;
  1965. case 1:
  1966. return @"More Info";
  1967. break;
  1968. case 2:
  1969. return @"Models";
  1970. case 3:
  1971. return @"Price Info";
  1972. default:
  1973. break;
  1974. }
  1975. return nil;
  1976. }
  1977. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1978. {
  1979. if(self.content_data==nil)
  1980. return 0;
  1981. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1982. return [[self.content_data objectForKey:@"count"] integerValue];
  1983. #endif
  1984. //#ifdef BUILD_USAI
  1985. // return [[self.content_data objectForKey:@"count"] integerValue];
  1986. //#endif
  1987. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1988. return [[self.content_data objectForKey:@"count"] integerValue];
  1989. #endif
  1990. #ifdef BUILD_HMLG
  1991. return 4;
  1992. #endif
  1993. return 4;
  1994. }
  1995. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1996. {
  1997. return 33;
  1998. }
  1999. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2000. {
  2001. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2002. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  2003. NSDictionary *data = [section_item objectForKey:@"data"];
  2004. NSString *section_type = [section_item objectForKey:@"type"];
  2005. if ([section_type isEqualToString:@"sub_order"]) {
  2006. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  2007. if (item_switch == YES) {
  2008. return [[data objectForKey:@"count"] integerValue];
  2009. } else {
  2010. return 0;
  2011. }
  2012. } else if ([section_type isEqualToString:@"order_info"]){
  2013. if (self.showModels) {
  2014. return 1;
  2015. } else {
  2016. return 0;
  2017. }
  2018. } else if ([section_type isEqualToString:@"sign_url"]){
  2019. return 1;
  2020. } else if ([section_type isEqualToString:@"more_order_info"]){
  2021. if(self.showMore)
  2022. return 1;
  2023. else
  2024. return 0;
  2025. }else if ([section_type isEqualToString:@"price_info"]){
  2026. return [[data objectForKey:@"count"] integerValue];
  2027. }
  2028. return 0;
  2029. #endif
  2030. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2031. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  2032. NSDictionary *data = [section_item objectForKey:@"data"];
  2033. NSString *section_type = [section_item objectForKey:@"type"];
  2034. if ([section_type isEqualToString:@"sub_order"]) {
  2035. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  2036. if (item_switch == YES) {
  2037. return [[data objectForKey:@"count"] integerValue];
  2038. } else {
  2039. return 0;
  2040. }
  2041. } else if ([section_type isEqualToString:@"order_info"]){
  2042. if (self.showModels) {
  2043. return 1;
  2044. } else {
  2045. return 0;
  2046. }
  2047. } else if ([section_type isEqualToString:@"sign_url"]){
  2048. return 1;
  2049. } else if ([section_type isEqualToString:@"more_order_info"]){
  2050. if(self.showMore)
  2051. return 1;
  2052. else
  2053. return 0;
  2054. }else if ([section_type isEqualToString:@"price_info"]){
  2055. return [[data objectForKey:@"count"] integerValue];
  2056. }
  2057. return 0;
  2058. #endif
  2059. #ifdef BUILD_HMLG
  2060. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2061. if(section==0)
  2062. return 2;
  2063. if(section==1)
  2064. {
  2065. if(self.showMore)
  2066. return 1;
  2067. else
  2068. return 0;
  2069. }
  2070. if(section==2)
  2071. {
  2072. if (self.showModels) {
  2073. int count =[[self.content_data valueForKey:@"model_count"] intValue];
  2074. return count;
  2075. } else {
  2076. return 0;
  2077. }
  2078. }
  2079. if(section==3) {
  2080. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2081. return 6;
  2082. #endif
  2083. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2084. return 6;
  2085. #endif
  2086. #ifdef BUILD_HMLG
  2087. return 4;
  2088. #endif
  2089. }
  2090. #endif
  2091. return 0;
  2092. }
  2093. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2094. {
  2095. UIApplication * app = [UIApplication sharedApplication];
  2096. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2097. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2098. /**
  2099. * ver1.90
  2100. */
  2101. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  2102. NSString *type = [section objectForKey:@"type"];
  2103. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  2104. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2105. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2106. cell.html = nil;
  2107. cell.wkwebview.tag = indexPath.section;
  2108. cell.wkwebview.navigationDelegate = self;
  2109. cell.wkwebview.scrollView.bounces=NO;
  2110. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2111. CGSize size= cell.wkwebview.scrollView.contentSize;
  2112. size.height=10;
  2113. cell.wkwebview.scrollView.contentSize=size;
  2114. cell.backgroundColor = [UIColor whiteColor];
  2115. cell.wkwebview.userInteractionEnabled = YES;
  2116. cell.html =[section valueForKey:@"data"];
  2117. NSLog(@"wkwebview loadHTMLString 0");
  2118. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2119. NSLog(@"wkwebview loadHTMLString 1");
  2120. return cell;
  2121. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  2122. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2123. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2124. NSString* img_url = [section valueForKey:@"data"];
  2125. cell.sign_img.userInteractionEnabled = NO;
  2126. __block BOOL hasTapGesture = NO;
  2127. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2128. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2129. hasTapGesture = YES;
  2130. *stop = YES;
  2131. }
  2132. }];
  2133. if (!hasTapGesture) {
  2134. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2135. [cell.sign_img addGestureRecognizer:signatureTap];
  2136. }
  2137. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2138. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2139. if(status_code==1) {
  2140. BOOL condition = offline_edit;
  2141. #ifdef OFFLINE_MODE
  2142. condition = condition || appDelegate.offline_mode==false;
  2143. #else
  2144. condition = YES;
  2145. #endif
  2146. if (condition)
  2147. {
  2148. cell.sign_img.userInteractionEnabled = YES;
  2149. }
  2150. }
  2151. else if(status_code==0) {
  2152. BOOL condition = offline_edit;
  2153. #ifdef OFFLINE_MODE
  2154. condition = condition || appDelegate.offline_mode==false;
  2155. #else
  2156. condition = YES;
  2157. #endif
  2158. if (condition)
  2159. {
  2160. cell.sign_img.userInteractionEnabled = YES;
  2161. }
  2162. }
  2163. NSString* file_name=[img_url lastPathComponent];
  2164. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2165. if(img_data!=nil)
  2166. {
  2167. UIImage * img =[UIImage imageWithData:img_data];
  2168. cell.sign_img.image=img ;
  2169. }
  2170. else
  2171. {
  2172. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2173. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2174. dispatch_async(dispatch_get_main_queue(), ^{
  2175. if(downloadimg_data!=nil)
  2176. {
  2177. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2178. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2179. cell.sign_img.image=img ;
  2180. }
  2181. else {
  2182. if (cell.sign_img.userInteractionEnabled) {
  2183. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2184. } else {
  2185. cell.sign_img.image = nil;
  2186. }
  2187. }
  2188. });
  2189. });
  2190. }
  2191. cell.backgroundColor = [UIColor whiteColor];
  2192. return cell;
  2193. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  2194. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2195. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2196. cell.wkwebview.tag = indexPath.section;
  2197. cell.wkwebview.navigationDelegate = self;
  2198. cell.wkwebview.scrollView.bounces=NO;
  2199. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2200. CGSize size= cell.wkwebview.scrollView.contentSize;
  2201. size.height=10;
  2202. cell.wkwebview.scrollView.contentSize=size;
  2203. NSLog(@"wkwebview loadHTMLString 3");
  2204. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2205. NSLog(@"wkwebview loadHTMLString 4");
  2206. cell.backgroundColor = [UIColor whiteColor];
  2207. return cell;
  2208. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  2209. NSDictionary *data = [section objectForKey:@"data"];
  2210. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2211. NSString *item_type = [item objectForKey:@"type"];
  2212. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  2213. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  2214. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2215. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  2216. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  2217. NSString *track_number = [item objectForKey:@"tracking_number"];
  2218. NSString *status = [item objectForKey:@"status"];
  2219. cell.track_number_lb.text = track_number;
  2220. cell.status_lb.text = status;
  2221. cell.carrier_lb.text = carrier;
  2222. cell.url_lb.text = web_url;
  2223. return cell;
  2224. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  2225. NSString *CellIdentifier = @"OrderDetailModelCell";
  2226. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2227. NSDictionary * item_json = item;
  2228. // int count = [[item_json valueForKey:@"count"] intValue];
  2229. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2230. cell.bundle_item=combine_json;
  2231. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2232. if (cell.masterBtn != nil) {
  2233. if (master_json == nil) {
  2234. cell.masterBtn.hidden = YES;
  2235. } else{
  2236. cell.masterBtn.hidden = NO;
  2237. cell.master_items = master_json;
  2238. }
  2239. }
  2240. double dprice=0.0;
  2241. if(cell.bundle_item!=nil)
  2242. {
  2243. int citem=0;
  2244. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2245. for(int bc=0;bc<bcount;bc++)
  2246. {
  2247. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2248. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2249. citem+= modulus;
  2250. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2251. dprice+= uprice*modulus;
  2252. }
  2253. if(citem==1)
  2254. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2255. else
  2256. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2257. cell.buttonBundle.hidden = NO;
  2258. }
  2259. else
  2260. {
  2261. cell.buttonBundle.hidden = YES;
  2262. }
  2263. NSString* img_url = [item_json valueForKey:@"img"];
  2264. NSString* description = [item_json valueForKey:@"Item Number"];
  2265. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2266. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2267. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2268. NSString* qty = [item_json valueForKey:@"QTY"];
  2269. NSString* status = [item_json valueForKey:@"order_item_status"];
  2270. NSString* notes = [item_json valueForKey:@"note"];
  2271. if(notes.length>0)
  2272. {
  2273. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2274. }
  2275. else
  2276. cell.noteLabel.text = nil;
  2277. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2278. {
  2279. }
  2280. else
  2281. {
  2282. unitprice=nil;
  2283. origin_price=nil;
  2284. subtotal=nil;
  2285. }
  2286. float duprice = [unitprice floatValue];
  2287. float dsubtotal = (duprice+dprice)*[qty intValue];
  2288. cell.descriptionLabel.text=description;
  2289. if(dprice>0)
  2290. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2291. else
  2292. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2293. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2294. cell.qtyLabel.text = qty;
  2295. cell.statusLabel.text = status;
  2296. cell.labelOldPrice.text = origin_price;
  2297. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2298. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2299. cell.labelDiscount.text = discountstr;
  2300. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2301. if(isfree)
  2302. {
  2303. cell.labelOldPrice.hidden = false;
  2304. cell.labelOldPrice.textColor = [UIColor redColor];
  2305. cell.labelOldPrice.text=@"Free";
  2306. cell.labelOldPrice.hideline = true;
  2307. cell.labelDiscount.hidden = true;
  2308. }
  2309. else
  2310. {
  2311. cell.labelOldPrice.textColor = [UIColor blackColor];
  2312. cell.labelOldPrice.hideline = false;
  2313. if(discount==0)
  2314. {
  2315. cell.labelOldPrice.hidden = true;
  2316. cell.labelDiscount.hidden = true;
  2317. }
  2318. else
  2319. {
  2320. cell.labelOldPrice.hidden = false;
  2321. cell.labelDiscount.hidden = false;
  2322. }
  2323. }
  2324. // Button 设置了大小约束,Size就不会随内容变化
  2325. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2326. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2327. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2328. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2329. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2330. if (![cell.imageName isEqualToString:img_url]) {
  2331. cell.imageName = img_url;
  2332. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2333. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2334. NSString* file_name=[img_url lastPathComponent];
  2335. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2336. if(img_data!=nil)
  2337. {
  2338. UIImage * img =[UIImage imageWithData:img_data];
  2339. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2340. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2341. }
  2342. else
  2343. {
  2344. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2345. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2346. dispatch_async(dispatch_get_main_queue(), ^{
  2347. if(downloadimg_data!=nil)
  2348. {
  2349. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2350. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2351. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2352. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2353. }
  2354. else
  2355. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2356. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2357. });
  2358. });
  2359. }
  2360. }
  2361. cell.backgroundColor = [UIColor whiteColor];
  2362. return cell;
  2363. }
  2364. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  2365. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2366. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2367. NSDictionary *data = [section objectForKey:@"data"];
  2368. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2369. NSString *title = [item objectForKey:@"title"];
  2370. NSString *value = [item objectForKey:@"value"];
  2371. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  2372. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2373. {
  2374. }
  2375. else
  2376. {
  2377. value=nil;
  2378. }
  2379. }
  2380. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  2381. cell.priceLabel.text = value;
  2382. cell.backgroundColor = [UIColor whiteColor];
  2383. return cell;
  2384. }
  2385. #endif
  2386. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2387. /**
  2388. * ver1.90
  2389. */
  2390. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  2391. NSString *type = [section objectForKey:@"type"];
  2392. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  2393. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2394. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2395. cell.html = nil;
  2396. cell.wkwebview.tag = indexPath.section;
  2397. cell.wkwebview.navigationDelegate = self;
  2398. cell.wkwebview.scrollView.bounces=NO;
  2399. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2400. CGSize size= cell.wkwebview.scrollView.contentSize;
  2401. size.height=10;
  2402. cell.wkwebview.scrollView.contentSize=size;
  2403. cell.backgroundColor = [UIColor whiteColor];
  2404. cell.wkwebview.userInteractionEnabled = YES;
  2405. cell.html =[section valueForKey:@"data"];
  2406. NSLog(@"wkwebview loadHTMLString 0");
  2407. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2408. NSLog(@"wkwebview loadHTMLString 1");
  2409. return cell;
  2410. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  2411. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2412. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2413. NSString* img_url = [section valueForKey:@"data"];
  2414. cell.sign_img.userInteractionEnabled = NO;
  2415. __block BOOL hasTapGesture = NO;
  2416. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2417. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2418. hasTapGesture = YES;
  2419. *stop = YES;
  2420. }
  2421. }];
  2422. if (!hasTapGesture) {
  2423. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2424. [cell.sign_img addGestureRecognizer:signatureTap];
  2425. }
  2426. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2427. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2428. if(status_code==1) {
  2429. BOOL condition = offline_edit;
  2430. #ifdef OFFLINE_MODE
  2431. condition = condition || appDelegate.offline_mode==false;
  2432. #else
  2433. condition = YES;
  2434. #endif
  2435. if (condition)
  2436. {
  2437. cell.sign_img.userInteractionEnabled = YES;
  2438. }
  2439. }
  2440. else if(status_code==0) {
  2441. BOOL condition = offline_edit;
  2442. #ifdef OFFLINE_MODE
  2443. condition = condition || appDelegate.offline_mode==false;
  2444. #else
  2445. condition = YES;
  2446. #endif
  2447. if (condition)
  2448. {
  2449. cell.sign_img.userInteractionEnabled = YES;
  2450. }
  2451. }
  2452. NSString* file_name=[img_url lastPathComponent];
  2453. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2454. if(img_data!=nil)
  2455. {
  2456. UIImage * img =[UIImage imageWithData:img_data];
  2457. cell.sign_img.image=img ;
  2458. }
  2459. else
  2460. {
  2461. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2462. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2463. dispatch_async(dispatch_get_main_queue(), ^{
  2464. if(downloadimg_data!=nil)
  2465. {
  2466. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2467. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2468. cell.sign_img.image=img ;
  2469. }
  2470. else {
  2471. if (cell.sign_img.userInteractionEnabled) {
  2472. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2473. } else {
  2474. cell.sign_img.image = nil;
  2475. }
  2476. }
  2477. });
  2478. });
  2479. }
  2480. cell.backgroundColor = [UIColor whiteColor];
  2481. return cell;
  2482. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  2483. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2484. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2485. cell.wkwebview.tag = indexPath.section;
  2486. cell.wkwebview.navigationDelegate = self;
  2487. cell.wkwebview.scrollView.bounces=NO;
  2488. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2489. CGSize size= cell.wkwebview.scrollView.contentSize;
  2490. size.height=10;
  2491. cell.wkwebview.scrollView.contentSize=size;
  2492. NSLog(@"wkwebview loadHTMLString 3");
  2493. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2494. NSLog(@"wkwebview loadHTMLString 4");
  2495. cell.backgroundColor = [UIColor whiteColor];
  2496. return cell;
  2497. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  2498. NSDictionary *data = [section objectForKey:@"data"];
  2499. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2500. NSString *item_type = [item objectForKey:@"type"];
  2501. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  2502. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  2503. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2504. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  2505. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  2506. NSString *track_number = [item objectForKey:@"tracking_number"];
  2507. NSString *status = [item objectForKey:@"status"];
  2508. cell.track_number_lb.text = track_number;
  2509. cell.status_lb.text = status;
  2510. cell.carrier_lb.text = carrier;
  2511. cell.url_lb.text = web_url;
  2512. return cell;
  2513. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  2514. NSString *CellIdentifier = @"OrderDetailModelCell";
  2515. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2516. NSDictionary * item_json = item;
  2517. // int count = [[item_json valueForKey:@"count"] intValue];
  2518. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2519. cell.bundle_item=combine_json;
  2520. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2521. if (cell.masterBtn != nil) {
  2522. if (master_json == nil) {
  2523. cell.masterBtn.hidden = YES;
  2524. } else{
  2525. cell.masterBtn.hidden = NO;
  2526. cell.master_items = master_json;
  2527. }
  2528. }
  2529. double dprice=0.0;
  2530. if(cell.bundle_item!=nil)
  2531. {
  2532. int citem=0;
  2533. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2534. for(int bc=0;bc<bcount;bc++)
  2535. {
  2536. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2537. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2538. citem+= modulus;
  2539. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2540. dprice+= uprice*modulus;
  2541. }
  2542. if(citem==1)
  2543. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2544. else
  2545. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2546. cell.buttonBundle.hidden = NO;
  2547. }
  2548. else
  2549. {
  2550. cell.buttonBundle.hidden = YES;
  2551. }
  2552. NSString* img_url = [item_json valueForKey:@"img"];
  2553. NSString* description = [item_json valueForKey:@"Item Number"];
  2554. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2555. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2556. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2557. NSString* qty = [item_json valueForKey:@"QTY"];
  2558. NSString* status = [item_json valueForKey:@"order_item_status"];
  2559. NSString* notes = [item_json valueForKey:@"note"];
  2560. if(notes.length>0)
  2561. {
  2562. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2563. }
  2564. else
  2565. cell.noteLabel.text = nil;
  2566. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2567. {
  2568. }
  2569. else
  2570. {
  2571. unitprice=nil;
  2572. origin_price=nil;
  2573. subtotal=nil;
  2574. }
  2575. float duprice = [unitprice floatValue];
  2576. float dsubtotal = (duprice+dprice)*[qty intValue];
  2577. cell.descriptionLabel.text=description;
  2578. if(dprice>0)
  2579. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2580. else
  2581. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2582. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2583. cell.qtyLabel.text = qty;
  2584. cell.statusLabel.text = status;
  2585. cell.labelOldPrice.text = origin_price;
  2586. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2587. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2588. cell.labelDiscount.text = discountstr;
  2589. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2590. if(isfree)
  2591. {
  2592. cell.labelOldPrice.hidden = false;
  2593. cell.labelOldPrice.textColor = [UIColor redColor];
  2594. cell.labelOldPrice.text=@"Free";
  2595. cell.labelOldPrice.hideline = true;
  2596. cell.labelDiscount.hidden = true;
  2597. }
  2598. else
  2599. {
  2600. cell.labelOldPrice.textColor = [UIColor blackColor];
  2601. cell.labelOldPrice.hideline = false;
  2602. if(discount==0)
  2603. {
  2604. cell.labelOldPrice.hidden = true;
  2605. cell.labelDiscount.hidden = true;
  2606. }
  2607. else
  2608. {
  2609. cell.labelOldPrice.hidden = false;
  2610. cell.labelDiscount.hidden = false;
  2611. }
  2612. }
  2613. // Button 设置了大小约束,Size就不会随内容变化
  2614. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2615. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2616. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2617. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2618. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2619. if (![cell.imageName isEqualToString:img_url]) {
  2620. cell.imageName = img_url;
  2621. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2622. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2623. NSString* file_name=[img_url lastPathComponent];
  2624. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2625. if(img_data!=nil)
  2626. {
  2627. UIImage * img =[UIImage imageWithData:img_data];
  2628. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2629. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2630. }
  2631. else
  2632. {
  2633. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2634. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2635. dispatch_async(dispatch_get_main_queue(), ^{
  2636. if(downloadimg_data!=nil)
  2637. {
  2638. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2639. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2640. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2641. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2642. }
  2643. else
  2644. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2645. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2646. });
  2647. });
  2648. }
  2649. }
  2650. cell.backgroundColor = [UIColor whiteColor];
  2651. return cell;
  2652. }
  2653. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  2654. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2655. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2656. NSDictionary *data = [section objectForKey:@"data"];
  2657. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2658. NSString *title = [item objectForKey:@"title"];
  2659. NSString *value = [item objectForKey:@"value"];
  2660. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  2661. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2662. {
  2663. }
  2664. else
  2665. {
  2666. value=nil;
  2667. }
  2668. }
  2669. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  2670. cell.priceLabel.text = value;
  2671. cell.backgroundColor = [UIColor whiteColor];
  2672. return cell;
  2673. }
  2674. #endif
  2675. #ifdef BUILD_HMLG
  2676. switch(indexPath.section)
  2677. {
  2678. case 0:
  2679. {
  2680. if(indexPath.row==0)
  2681. {
  2682. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2683. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2684. cell.html = nil;
  2685. cell.wkwebview.tag = indexPath.section;
  2686. cell.wkwebview.navigationDelegate = self;
  2687. cell.wkwebview.scrollView.bounces=NO;
  2688. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2689. CGSize size= cell.wkwebview.scrollView.contentSize;
  2690. size.height=10;
  2691. cell.wkwebview.scrollView.contentSize=size;
  2692. cell.backgroundColor = [UIColor whiteColor];
  2693. cell.wkwebview.userInteractionEnabled = YES;
  2694. cell.html =[self.content_data valueForKey:@"order_info"];
  2695. [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  2696. // [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  2697. // cell.backgroundColor = [UIColor whiteColor];
  2698. return cell;
  2699. }
  2700. else
  2701. {
  2702. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2703. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2704. NSString* img_url = [self.content_data valueForKey:@"sign_url"];
  2705. cell.sign_img.userInteractionEnabled = NO;
  2706. __block BOOL hasTapGesture = NO;
  2707. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2708. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2709. hasTapGesture = YES;
  2710. *stop = YES;
  2711. }
  2712. }];
  2713. if (!hasTapGesture) {
  2714. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2715. [cell.sign_img addGestureRecognizer:signatureTap];
  2716. }
  2717. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2718. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2719. if(status_code==1) {
  2720. BOOL condition = offline_edit;
  2721. #ifdef OFFLINE_MODE
  2722. condition = condition || appDelegate.offline_mode==false;
  2723. #else
  2724. condition = YES;
  2725. #endif
  2726. if (condition)
  2727. {
  2728. cell.sign_img.userInteractionEnabled = YES;
  2729. }
  2730. }
  2731. else if(status_code==0) {
  2732. BOOL condition = offline_edit;
  2733. #ifdef OFFLINE_MODE
  2734. condition = condition || appDelegate.offline_mode==false;
  2735. #else
  2736. condition = YES;
  2737. #endif
  2738. if (condition)
  2739. {
  2740. cell.sign_img.userInteractionEnabled = YES;
  2741. }
  2742. }
  2743. NSString* file_name=[img_url lastPathComponent];
  2744. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2745. if(img_data!=nil)
  2746. {
  2747. UIImage * img =[UIImage imageWithData:img_data];
  2748. cell.sign_img.image=img ;
  2749. }
  2750. else
  2751. {
  2752. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2753. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2754. dispatch_async(dispatch_get_main_queue(), ^{
  2755. if(downloadimg_data!=nil)
  2756. {
  2757. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2758. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2759. cell.sign_img.image=img ;
  2760. }
  2761. else {
  2762. if (cell.sign_img.userInteractionEnabled) {
  2763. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2764. } else {
  2765. cell.sign_img.image = nil;
  2766. }
  2767. }
  2768. });
  2769. });
  2770. }
  2771. cell.backgroundColor = [UIColor whiteColor];
  2772. return cell;
  2773. }
  2774. }
  2775. break;
  2776. case 1:
  2777. {
  2778. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2779. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2780. cell.wkwebview.tag = indexPath.section;
  2781. cell.wkwebview.navigationDelegate = self;
  2782. cell.wkwebview.scrollView.bounces=NO;
  2783. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2784. CGSize size= cell.wkwebview.scrollView.contentSize;
  2785. size.height=10;
  2786. cell.wkwebview.scrollView.contentSize=size;
  2787. NSLog(@"wkwebview loadHTMLString 3");
  2788. [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  2789. NSLog(@"wkwebview loadHTMLString 4");
  2790. cell.backgroundColor = [UIColor whiteColor];
  2791. return cell;
  2792. \
  2793. return cell;
  2794. }
  2795. break;
  2796. case 2:
  2797. {
  2798. NSString *CellIdentifier = @"OrderDetailModelCell";
  2799. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2800. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2801. int count = [[item_json valueForKey:@"count"] intValue];
  2802. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2803. cell.bundle_item=combine_json;
  2804. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2805. if (cell.masterBtn != nil) {
  2806. if (master_json == nil) {
  2807. cell.masterBtn.hidden = YES;
  2808. } else{
  2809. cell.masterBtn.hidden = NO;
  2810. cell.master_items = master_json;
  2811. }
  2812. }
  2813. double dprice=0.0;
  2814. if(cell.bundle_item!=nil)
  2815. {
  2816. int citem=0;
  2817. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2818. for(int bc=0;bc<bcount;bc++)
  2819. {
  2820. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2821. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2822. citem+= modulus;
  2823. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2824. dprice+= uprice*modulus;
  2825. }
  2826. if(citem==1)
  2827. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2828. else
  2829. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2830. cell.buttonBundle.hidden = NO;
  2831. }
  2832. else
  2833. {
  2834. cell.buttonBundle.hidden = YES;
  2835. }
  2836. NSString* img_url = [item_json valueForKey:@"img"];
  2837. NSString* description = [item_json valueForKey:@"Item Number"];
  2838. // NSString* description = [item_json valueForKey:@"Item Number"];
  2839. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2840. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2841. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2842. NSString* qty = [item_json valueForKey:@"QTY"];
  2843. NSString* status = [item_json valueForKey:@"order_item_status"];
  2844. NSString* notes = [item_json valueForKey:@"note"];
  2845. if(notes.length>0)
  2846. {
  2847. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2848. }
  2849. else
  2850. cell.noteLabel.text = nil;
  2851. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2852. {
  2853. }
  2854. else
  2855. {
  2856. unitprice=nil;
  2857. origin_price=nil;
  2858. subtotal=nil;
  2859. }
  2860. float duprice = [unitprice floatValue];
  2861. float dsubtotal = (duprice+dprice)*[qty intValue];
  2862. cell.descriptionLabel.text=description;
  2863. if(dprice>0)
  2864. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2865. else
  2866. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2867. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2868. cell.qtyLabel.text = qty;
  2869. cell.statusLabel.text = status;
  2870. cell.labelOldPrice.text = origin_price;
  2871. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2872. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2873. cell.labelDiscount.text = discountstr;
  2874. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2875. if(isfree)
  2876. {
  2877. cell.labelOldPrice.hidden = false;
  2878. cell.labelOldPrice.textColor = [UIColor redColor];
  2879. cell.labelOldPrice.text=@"Free";
  2880. cell.labelOldPrice.hideline = true;
  2881. cell.labelDiscount.hidden = true;
  2882. }
  2883. else
  2884. {
  2885. cell.labelOldPrice.textColor = [UIColor blackColor];
  2886. cell.labelOldPrice.hideline = false;
  2887. if(discount==0)
  2888. {
  2889. cell.labelOldPrice.hidden = true;
  2890. cell.labelDiscount.hidden = true;
  2891. }
  2892. else
  2893. {
  2894. cell.labelOldPrice.hidden = false;
  2895. cell.labelDiscount.hidden = false;
  2896. }
  2897. }
  2898. // Button 设置了大小约束,Size就不会随内容变化
  2899. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2900. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2901. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2902. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2903. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2904. if (![cell.imageName isEqualToString:img_url]) {
  2905. cell.imageName = img_url;
  2906. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2907. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2908. NSString* file_name=[img_url lastPathComponent];
  2909. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2910. if(img_data!=nil)
  2911. {
  2912. UIImage * img =[UIImage imageWithData:img_data];
  2913. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2914. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2915. }
  2916. else
  2917. {
  2918. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2919. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2920. dispatch_async(dispatch_get_main_queue(), ^{
  2921. if(downloadimg_data!=nil)
  2922. {
  2923. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2924. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2925. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2926. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2927. }
  2928. else
  2929. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2930. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2931. });
  2932. });
  2933. }
  2934. }
  2935. cell.backgroundColor = [UIColor whiteColor];
  2936. return cell;
  2937. }
  2938. break;
  2939. case 3:
  2940. {
  2941. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2942. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2943. switch (indexPath.row) {
  2944. case 0:
  2945. {
  2946. cell.chargeLabel.text =@"Sub-Total:";
  2947. NSString* price=[self.content_data valueForKey:@"Sub-Total"];
  2948. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2949. {
  2950. }
  2951. else
  2952. {
  2953. price=nil;
  2954. }
  2955. cell.priceLabel.text =price;
  2956. break;
  2957. }
  2958. case 1:
  2959. cell.chargeLabel.text = @"Shipping:";
  2960. cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
  2961. break;
  2962. case 2: {
  2963. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2964. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2965. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2966. #endif
  2967. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2968. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2969. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2970. #endif
  2971. #ifdef BUILD_HMLG
  2972. cell.chargeLabel.text = @"Tax:";
  2973. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  2974. cell.priceLabel.text = tax;
  2975. #endif
  2976. }
  2977. break;
  2978. case 3: {
  2979. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2980. cell.chargeLabel.text = @"Handling Fee:";
  2981. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2982. #endif
  2983. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2984. cell.chargeLabel.text = @"Handling Fee:";
  2985. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2986. #endif
  2987. #ifdef BUILD_HMLG
  2988. NSString* price=[self.content_data valueForKey:@"Total"];
  2989. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2990. {
  2991. }
  2992. else
  2993. {
  2994. price=nil;
  2995. }
  2996. cell.chargeLabel.text = @"Total:";
  2997. cell.priceLabel.text =price;
  2998. #endif
  2999. }
  3000. break;
  3001. case 4: {
  3002. cell.chargeLabel.text = @"Tax:";
  3003. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  3004. cell.priceLabel.text = tax;
  3005. }
  3006. break;
  3007. case 5:
  3008. {
  3009. NSString* price=[self.content_data valueForKey:@"Total"];
  3010. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3011. {
  3012. }
  3013. else
  3014. {
  3015. price=nil;
  3016. }
  3017. cell.chargeLabel.text = @"Total:";
  3018. cell.priceLabel.text =price;
  3019. break;
  3020. }
  3021. default:
  3022. break;
  3023. }
  3024. cell.backgroundColor = [UIColor whiteColor];
  3025. return cell;
  3026. }
  3027. }
  3028. #endif
  3029. return nil;
  3030. // if(tableView==self.itemListTable)
  3031. // {
  3032. // NSString *CellIdentifier = @"CartItemCell";
  3033. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3034. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3035. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3036. //
  3037. // cell.bundle_item=combine_json;
  3038. // NSString* img_url = [item_json valueForKey:@"img_url"];
  3039. // NSString* description = [item_json valueForKey:@"description"];
  3040. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  3041. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  3042. // NSString* currency = [item_json valueForKey:@"currency"];
  3043. // int count =[[item_json valueForKey:@"count"] intValue];
  3044. //
  3045. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3046. //
  3047. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3048. //
  3049. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3050. // cell.unit_price = unitprice;
  3051. // // cell.labelAttribute.text = attribute;
  3052. // // cell.labelCurrency.text = currency;
  3053. // cell.labelDescription.text = description;
  3054. // // cell.labelIdentifier.text = identifier;
  3055. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  3056. //
  3057. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  3058. //
  3059. //
  3060. //
  3061. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3062. // cell.cart_id = cart_item_id;
  3063. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3064. //
  3065. //
  3066. //
  3067. // [cell set_Count:count];
  3068. //
  3069. // NSString* file_name=[img_url lastPathComponent];
  3070. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3071. // if(img_data!=nil)
  3072. // {
  3073. //
  3074. // UIImage * img =[UIImage imageWithData:img_data];
  3075. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3076. // }
  3077. // else
  3078. // {
  3079. //
  3080. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3081. //
  3082. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3083. //
  3084. // dispatch_async(dispatch_get_main_queue(), ^{
  3085. //
  3086. //
  3087. //
  3088. // if(downloadimg_data!=nil)
  3089. // {
  3090. // [iSalesDB cache_img:downloadimg_data :file_name ];
  3091. //
  3092. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  3093. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3094. // }
  3095. //
  3096. // });
  3097. // });
  3098. //
  3099. //
  3100. // }
  3101. // return cell;
  3102. // }
  3103. // else
  3104. // {
  3105. // NSString *CellIdentifier = @"OrderInfoListItem";
  3106. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3107. // return cell;
  3108. // }
  3109. }
  3110. //#pragma mark - UIAlertViewDelegate
  3111. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  3112. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  3113. //{
  3114. //
  3115. // if(buttonIndex!=alertView.cancelButtonIndex)
  3116. // {
  3117. // [self copyOrder];
  3118. // }
  3119. //}
  3120. - (void)copyOrder {
  3121. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Copy Order" completion:^{
  3122. [RANetwork request_copy_order:self.order_code completionHandler:^(NSMutableDictionary *result) {
  3123. NSDictionary* order_json = result;
  3124. [waitalert dismissViewControllerAnimated:YES completion:^{
  3125. if([[order_json valueForKey:@"result"] intValue]==2)
  3126. {
  3127. // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  3128. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3129. // if([appDelegate.order_code isEqualToString: self.order_code])
  3130. // {
  3131. // [appDelegate closeOrder];
  3132. //// appDelegate.order_code= nil;
  3133. // [appDelegate SetSo:nil];
  3134. //
  3135. //
  3136. // }
  3137. [RAUtils message_alert:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] title:@"Copy successful." controller:self];
  3138. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Copy successful." message:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3139. //
  3140. // [alert show];
  3141. //
  3142. #ifdef RA_NOTIFICATION
  3143. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3144. #else
  3145. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3146. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3147. #endif
  3148. [self.navigationController popViewControllerAnimated:false];
  3149. }
  3150. else
  3151. {
  3152. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  3153. }
  3154. }];
  3155. }];
  3156. }];
  3157. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3158. //
  3159. // NSDictionary* order_json = [RANetwork copy_Order:self.order_code];
  3160. //
  3161. // dispatch_async(dispatch_get_main_queue(), ^{
  3162. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3163. // if([[order_json valueForKey:@"result"] intValue]==2)
  3164. // {
  3165. // // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  3166. //
  3167. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3168. // // if([appDelegate.order_code isEqualToString: self.order_code])
  3169. // // {
  3170. // // [appDelegate closeOrder];
  3171. // //// appDelegate.order_code= nil;
  3172. // // [appDelegate SetSo:nil];
  3173. // //
  3174. // //
  3175. // // }
  3176. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Copy successful." message:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3177. //
  3178. // [alert show];
  3179. //
  3180. //
  3181. //
  3182. //#ifdef RA_NOTIFICATION
  3183. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3184. //#else
  3185. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3186. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3187. //#endif
  3188. //
  3189. // [self.navigationController popViewControllerAnimated:false];
  3190. //
  3191. // }
  3192. // else
  3193. // {
  3194. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  3195. // }
  3196. //
  3197. //
  3198. //
  3199. // });
  3200. // });
  3201. }
  3202. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
  3203. {
  3204. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  3205. NSLog(@"%@",message.name);
  3206. NSLog(@"body:%@",message.body);
  3207. }
  3208. #pragma mark - WKNavigationDelegate
  3209. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
  3210. {
  3211. NSLog(@"wkwebview didFinishNavigation");
  3212. // [webView evaluateJavaScript:@"document.documentElement.outerHTML.toString()" completionHandler:^(id _Nullable html ,NSError * _Nullable error) {
  3213. //
  3214. // NSLog(html);
  3215. // }];
  3216. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  3217. NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
  3218. if(indexPath==nil)
  3219. {//for ios7
  3220. cell = (UITableViewCell *) webView.superview.superview.superview;
  3221. indexPath = [self.detailTable indexPathForCell:cell];
  3222. }
  3223. if(indexPath==nil)
  3224. return;
  3225. float height= 0;
  3226. if(indexPath.section==0)
  3227. height=self.web_info_height;
  3228. else
  3229. height = self.web_moreinfo_height;
  3230. if(height>0)
  3231. return;
  3232. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  3233. // CGSize size= webView.scrollView.contentSize;
  3234. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  3235. [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight,NSError * _Nullable error) {
  3236. NSLog(@"wkwebview evaluateJavaScript");
  3237. CGRect frame = webView.frame;
  3238. if(height==[fitHeight floatValue])
  3239. {
  3240. NSLog(@"wkwebview return no need reload table");
  3241. return;
  3242. }
  3243. frame.size.height = [fitHeight floatValue];
  3244. //webView.frame = frame;
  3245. // DebugLog(@"wkwebviewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  3246. if(indexPath.section==0)
  3247. self.web_info_height=frame.size.height;
  3248. else
  3249. self.web_moreinfo_height = frame.size.height;
  3250. NSLog(@"wkwebview need call table reload");
  3251. dispatch_async(dispatch_get_main_queue(), ^{
  3252. NSLog(@"reload tableview!!! %f",frame.size.height);
  3253. // UI更新代码
  3254. // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  3255. // [self.detailTable reloadData];
  3256. [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
  3257. // [self performSelector:@selector(rtable) withObject:nil afterDelay:1];
  3258. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  3259. });
  3260. }];
  3261. }
  3262. #pragma mark - web view delegate
  3263. - (void)reRefreshView {
  3264. [self.detailTable reloadData];
  3265. }
  3266. #pragma mark - RA_NOTIFICAITON
  3267. -(void) refresh_ui
  3268. {
  3269. [self.detailTable reloadData];
  3270. }
  3271. -(void) reload_data
  3272. {
  3273. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  3274. [reF endRefreshing];
  3275. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  3276. [self loaddata];
  3277. }
  3278. -(void) refresh_price
  3279. {
  3280. [self refresh_ui];
  3281. }
  3282. @end