OrderDetailViewController.m 158 KB

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