OrderDetailViewController.m 157 KB

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