OrderDetailViewController.m 139 KB

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