OrderDetailViewController.m 140 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578
  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 != nil ? 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 != nil ? 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. // 这里有问题,npd 里order 提交后,product id 为空,暂时屏蔽掉
  1026. return;
  1027. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1028. NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1029. // if(indexPath.section!=1)
  1030. // return ;
  1031. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1032. NSDictionary * item_json = self.content_data[[NSString stringWithFormat:@"section_%ld",(long)indexPath.section]][@"data"][[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1033. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1034. NSString* product_id = [item_json valueForKey:@"product_id"];
  1035. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1036. // dvc
  1037. dvc.product_id=product_id;
  1038. dvc.category_id=nil;
  1039. dvc.ispush=true;
  1040. [dvc reload];
  1041. [self.navigationController pushViewController:dvc animated:true];
  1042. }
  1043. /*
  1044. #pragma mark - Navigation
  1045. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1046. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1047. // Get the new view controller using [segue destinationViewController].
  1048. // Pass the selected object to the new view controller.
  1049. }
  1050. */
  1051. #pragma mark - Table view data source
  1052. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1053. {
  1054. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1055. // if([item_json objectForKey:@"combine"] == nil)
  1056. // {
  1057. // return 120;
  1058. // }
  1059. // else
  1060. // return 150;
  1061. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1062. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1063. NSDictionary *data = [section_item objectForKey:@"data"];
  1064. NSString *type = [section_item objectForKey:@"type"];
  1065. if ([type isEqualToString:@"order_info"]) {
  1066. float height= self.web_info_height;
  1067. if(height==0)
  1068. height=DEF_TABLE_HEIGHT;
  1069. return height;
  1070. } else if ([type isEqualToString:@"sign_url"]) {
  1071. return 148;
  1072. } else if ([type isEqualToString:@"more_order_info"]) {
  1073. float height= self.web_moreinfo_height;
  1074. if(height==0)
  1075. height=DEF_TABLE_HEIGHT;
  1076. return height;
  1077. } else if ([type isEqualToString:@"sub_order"]) {
  1078. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1079. NSString *item_type = [item objectForKey:@"type"];
  1080. if ([item_type isEqualToString:@"pick_info"]) {
  1081. return 218;
  1082. } else {
  1083. NSString* notes =[item valueForKey:@"note"];
  1084. if(notes.length>0)
  1085. {
  1086. return 190;
  1087. }
  1088. else
  1089. return 162;
  1090. }
  1091. } else if ([type isEqualToString:@"price_info"]) {
  1092. return 44;
  1093. }
  1094. #endif
  1095. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1096. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1097. NSDictionary *data = [section_item objectForKey:@"data"];
  1098. NSString *type = [section_item objectForKey:@"type"];
  1099. if ([type isEqualToString:@"order_info"]) {
  1100. float height= self.web_info_height;
  1101. if(height==0)
  1102. height=DEF_TABLE_HEIGHT;
  1103. return height;
  1104. } else if ([type isEqualToString:@"sign_url"]) {
  1105. return 148;
  1106. } else if ([type isEqualToString:@"more_order_info"]) {
  1107. float height= self.web_moreinfo_height;
  1108. if(height==0)
  1109. height=DEF_TABLE_HEIGHT;
  1110. return height;
  1111. } else if ([type isEqualToString:@"sub_order"]) {
  1112. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1113. NSString *item_type = [item objectForKey:@"type"];
  1114. if ([item_type isEqualToString:@"pick_info"]) {
  1115. return 218;
  1116. } else {
  1117. NSString* notes =[item valueForKey:@"note"];
  1118. if(notes.length>0)
  1119. {
  1120. return 190;
  1121. }
  1122. else
  1123. return 162;
  1124. }
  1125. } else if ([type isEqualToString:@"price_info"]) {
  1126. return 44;
  1127. }
  1128. #endif
  1129. #ifdef BUILD_HMLG
  1130. switch (indexPath.section) {
  1131. case 0:
  1132. {
  1133. if(indexPath.row==0)
  1134. {
  1135. float height= self.web_info_height;
  1136. if(height==0)
  1137. height=DEF_TABLE_HEIGHT;
  1138. return height;
  1139. }
  1140. else
  1141. return 148;
  1142. }
  1143. break;
  1144. case 1:
  1145. {
  1146. float height= self.web_moreinfo_height;
  1147. if(height==0)
  1148. height=DEF_TABLE_HEIGHT;
  1149. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  1150. //wait(1000);
  1151. return height;
  1152. }
  1153. break;
  1154. case 2:
  1155. {
  1156. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1157. NSString* notes =[item_json valueForKey:@"note"];
  1158. if(notes.length>0)
  1159. {
  1160. return 190;
  1161. }
  1162. else
  1163. return 162;
  1164. }
  1165. case 3:
  1166. return 44;
  1167. default:
  1168. break;
  1169. }
  1170. #endif
  1171. return 44;
  1172. }
  1173. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1174. //{
  1175. // return 0;
  1176. //}
  1177. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1178. //{
  1179. // return 0;
  1180. //}
  1181. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1182. //{
  1183. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1184. // return myView;
  1185. //
  1186. //}
  1187. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1188. //{
  1189. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1190. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1191. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1192. //// titleLabel.textColor=[UIColor whiteColor];
  1193. //// titleLabel.backgroundColor = [UIColor clearColor];
  1194. //// if(section==0)
  1195. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1196. //// else
  1197. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1198. //// [titleLabel sizeToFit];
  1199. //// [myView addSubview:titleLabel];
  1200. ////
  1201. // return myView;
  1202. //}
  1203. //
  1204. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1205. {
  1206. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1207. if(value==nil)
  1208. value=@"";
  1209. unsigned long color = strtoul([value UTF8String],0,16);
  1210. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1211. // myView.backgroundColor = UIColorFromRGB(0x996633);;
  1212. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1213. // myView.layer.masksToBounds = false;
  1214. //添加四个边阴影
  1215. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1216. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1217. myView.layer.shadowOpacity = 0.5;
  1218. myView.layer.shadowRadius = 2.0;
  1219. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1220. NSString*labeltitle = nil;
  1221. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1222. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1223. NSString *title = [section_item objectForKey:@"title"];
  1224. labeltitle = title;
  1225. if ([title isEqualToString:@"More Info"]) {
  1226. NSString* btntitle=nil ;
  1227. if(self.showMore)
  1228. {
  1229. btntitle=@"Hide";
  1230. }
  1231. else{
  1232. btntitle=@"Show";
  1233. }
  1234. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1235. btn.tag=section;
  1236. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1237. [btn setTitle:btntitle forState:UIControlStateNormal];
  1238. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1239. [myView addSubview:btn];
  1240. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1241. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1242. NSString *normalTitle = @"Show";
  1243. NSString *selectedTitle = @"Hide";
  1244. if (item_switch == YES) {
  1245. normalTitle = @"Hide";
  1246. selectedTitle = @"Show";
  1247. }
  1248. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1249. btn.tag=section;
  1250. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1251. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1252. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1253. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1254. [myView addSubview:btn];
  1255. }
  1256. #endif
  1257. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1258. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1259. NSString *title = [section_item objectForKey:@"title"];
  1260. labeltitle = title;
  1261. if ([title isEqualToString:@"More Info"]) {
  1262. NSString* btntitle=nil ;
  1263. if(self.showMore)
  1264. {
  1265. btntitle=@"Hide";
  1266. }
  1267. else{
  1268. btntitle=@"Show";
  1269. }
  1270. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1271. btn.tag=section;
  1272. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1273. [btn setTitle:btntitle forState:UIControlStateNormal];
  1274. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1275. [myView addSubview:btn];
  1276. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1277. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1278. NSString *normalTitle = @"Show";
  1279. NSString *selectedTitle = @"Hide";
  1280. if (item_switch == YES) {
  1281. normalTitle = @"Hide";
  1282. selectedTitle = @"Show";
  1283. }
  1284. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1285. btn.tag=section;
  1286. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1287. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1288. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1289. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1290. [myView addSubview:btn];
  1291. }
  1292. #endif
  1293. #ifdef BUILD_HMLG
  1294. switch (section) {
  1295. case 0:
  1296. labeltitle= @"Order Info";
  1297. break;
  1298. case 1:
  1299. {
  1300. labeltitle= @"More Info";
  1301. NSString* btntitle=nil ;
  1302. if(self.showMore)
  1303. {
  1304. btntitle=@"Hide";
  1305. // [section setValue:@"false" forKey:@"hide"];
  1306. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  1307. }
  1308. else{
  1309. btntitle=@"Show";
  1310. }
  1311. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1312. btn.tag=section;
  1313. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1314. [btn setTitle:btntitle forState:UIControlStateNormal];
  1315. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1316. [myView addSubview:btn];
  1317. }
  1318. break;
  1319. case 2:{
  1320. labeltitle= @"Models";
  1321. NSString* btntitle=nil ;
  1322. if(self.showModels)
  1323. {
  1324. btntitle=@"Hide";
  1325. }
  1326. else{
  1327. btntitle=@"Show";
  1328. }
  1329. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1330. btn.tag=section;
  1331. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1332. [btn setTitle:btntitle forState:UIControlStateNormal];
  1333. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1334. [myView addSubview:btn];
  1335. }
  1336. break;
  1337. case 3:
  1338. labeltitle= @"Price Info";
  1339. default:
  1340. break;
  1341. }
  1342. #endif
  1343. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  1344. titlelabel.textColor=UIColorFromRGB(color);;
  1345. titlelabel.backgroundColor = [UIColor clearColor];
  1346. titlelabel.text=NSLocalizedString(labeltitle, nil);
  1347. [titlelabel sizeToFit];
  1348. titlelabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  1349. [myView addSubview:titlelabel];
  1350. //
  1351. return myView;
  1352. }
  1353. #pragma mark - hide section button clicked
  1354. - (void)HideSction:(UIButton *)sender {
  1355. /*
  1356. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
  1357. bool hide = [[section valueForKey:@"hide"]boolValue];
  1358. if(hide)
  1359. {
  1360. [section setValue:@"false" forKey:@"hide"];
  1361. [sender setTitle:@"Show" forState:UIControlStateNormal];
  1362. }
  1363. else{
  1364. [section setValue:@"true" forKey:@"hide"];
  1365. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1366. }
  1367. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
  1368. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1369. */
  1370. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1371. NSUInteger section = sender.tag;
  1372. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1373. NSString *title = [section_item objectForKey:@"title"];
  1374. if ([title isEqualToString:@"More Info"]) {
  1375. self.showMore = !self.showMore;
  1376. NSRange range = NSMakeRange(section, 1);
  1377. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1378. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1379. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1380. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1381. if (item_switch == YES) {
  1382. [section_item setObject:@(NO) forKey:@"switch"];
  1383. } else {
  1384. [section_item setObject:@(YES) forKey:@"switch"];
  1385. }
  1386. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1387. sender.selected = !sender.selected;
  1388. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1389. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1390. }
  1391. #endif
  1392. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1393. NSUInteger section = sender.tag;
  1394. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1395. NSString *title = [section_item objectForKey:@"title"];
  1396. if ([title isEqualToString:@"More Info"]) {
  1397. self.showMore = !self.showMore;
  1398. NSRange range = NSMakeRange(section, 1);
  1399. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1400. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1401. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1402. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1403. if (item_switch == YES) {
  1404. [section_item setObject:@(NO) forKey:@"switch"];
  1405. } else {
  1406. [section_item setObject:@(YES) forKey:@"switch"];
  1407. }
  1408. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1409. sender.selected = !sender.selected;
  1410. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1411. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1412. }
  1413. #endif
  1414. #ifdef BUILD_HMLG
  1415. switch (sender.tag) {
  1416. case 0:{
  1417. }
  1418. break;
  1419. case 1:{
  1420. self.showMore=!self.showMore;
  1421. NSRange range = NSMakeRange(1, 1);
  1422. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1423. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1424. }
  1425. break;
  1426. case 2:{
  1427. self.showModels = !self.showModels;
  1428. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:2];
  1429. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1430. }
  1431. break;
  1432. default:
  1433. break;
  1434. }
  1435. #endif
  1436. }
  1437. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1438. switch (section) {
  1439. case 0:
  1440. return @"Order Info";
  1441. break;
  1442. case 1:
  1443. return @"More Info";
  1444. break;
  1445. case 2:
  1446. return @"Models";
  1447. case 3:
  1448. return @"Price Info";
  1449. default:
  1450. break;
  1451. }
  1452. return nil;
  1453. }
  1454. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1455. {
  1456. if(self.content_data==nil)
  1457. return 0;
  1458. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1459. return [[self.content_data objectForKey:@"count"] integerValue];
  1460. #endif
  1461. //#ifdef BUILD_USAI
  1462. // return [[self.content_data objectForKey:@"count"] integerValue];
  1463. //#endif
  1464. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1465. return [[self.content_data objectForKey:@"count"] integerValue];
  1466. #endif
  1467. #ifdef BUILD_HMLG
  1468. return 4;
  1469. #endif
  1470. }
  1471. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1472. {
  1473. return 33;
  1474. }
  1475. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1476. {
  1477. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1478. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1479. NSDictionary *data = [section_item objectForKey:@"data"];
  1480. NSString *section_type = [section_item objectForKey:@"type"];
  1481. if ([section_type isEqualToString:@"sub_order"]) {
  1482. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1483. if (item_switch == YES) {
  1484. return [[data objectForKey:@"count"] integerValue];
  1485. } else {
  1486. return 0;
  1487. }
  1488. } else if ([section_type isEqualToString:@"order_info"]){
  1489. if (self.showModels) {
  1490. return 1;
  1491. } else {
  1492. return 0;
  1493. }
  1494. } else if ([section_type isEqualToString:@"sign_url"]){
  1495. return 1;
  1496. } else if ([section_type isEqualToString:@"more_order_info"]){
  1497. if(self.showMore)
  1498. return 1;
  1499. else
  1500. return 0;
  1501. }else if ([section_type isEqualToString:@"price_info"]){
  1502. return [[data objectForKey:@"count"] integerValue];
  1503. }
  1504. return 0;
  1505. #endif
  1506. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1507. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1508. NSDictionary *data = [section_item objectForKey:@"data"];
  1509. NSString *section_type = [section_item objectForKey:@"type"];
  1510. if ([section_type isEqualToString:@"sub_order"]) {
  1511. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1512. if (item_switch == YES) {
  1513. return [[data objectForKey:@"count"] integerValue];
  1514. } else {
  1515. return 0;
  1516. }
  1517. } else if ([section_type isEqualToString:@"order_info"]){
  1518. if (self.showModels) {
  1519. return 1;
  1520. } else {
  1521. return 0;
  1522. }
  1523. } else if ([section_type isEqualToString:@"sign_url"]){
  1524. return 1;
  1525. } else if ([section_type isEqualToString:@"more_order_info"]){
  1526. if(self.showMore)
  1527. return 1;
  1528. else
  1529. return 0;
  1530. }else if ([section_type isEqualToString:@"price_info"]){
  1531. return [[data objectForKey:@"count"] integerValue];
  1532. }
  1533. return 0;
  1534. #endif
  1535. #ifdef BUILD_HMLG
  1536. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1537. if(section==0)
  1538. return 2;
  1539. if(section==1)
  1540. {
  1541. if(self.showMore)
  1542. return 1;
  1543. else
  1544. return 0;
  1545. }
  1546. if(section==2)
  1547. {
  1548. if (self.showModels) {
  1549. int count =[[self.content_data valueForKey:@"model_count"] intValue];
  1550. return count;
  1551. } else {
  1552. return 0;
  1553. }
  1554. }
  1555. if(section==3) {
  1556. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1557. return 6;
  1558. #endif
  1559. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1560. return 6;
  1561. #endif
  1562. #ifdef BUILD_HMLG
  1563. return 4;
  1564. #endif
  1565. }
  1566. #endif
  1567. return 0;
  1568. }
  1569. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1570. {
  1571. UIApplication * app = [UIApplication sharedApplication];
  1572. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1573. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  1574. /**
  1575. * ver1.90
  1576. */
  1577. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1578. NSString *type = [section objectForKey:@"type"];
  1579. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  1580. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1581. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1582. cell.webview.tag = indexPath.section;
  1583. cell.webview.delegate = self;
  1584. // cell.webView.scrollView.contentSize.height = 0;
  1585. cell.webview.scrollView.bounces=NO;
  1586. cell.webview.scrollView.directionalLockEnabled = true;
  1587. CGSize size= cell.webview.scrollView.contentSize;
  1588. size.height=10;
  1589. cell.webview.scrollView.contentSize=size;
  1590. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1591. cell.backgroundColor = [UIColor whiteColor];
  1592. cell.webview.userInteractionEnabled = YES;
  1593. return cell;
  1594. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  1595. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  1596. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1597. NSString* img_url = [section valueForKey:@"data"];
  1598. cell.sign_img.userInteractionEnabled = NO;
  1599. __block BOOL hasTapGesture = NO;
  1600. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1601. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  1602. hasTapGesture = YES;
  1603. *stop = YES;
  1604. }
  1605. }];
  1606. if (!hasTapGesture) {
  1607. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  1608. [cell.sign_img addGestureRecognizer:signatureTap];
  1609. }
  1610. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1611. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1612. if(status_code==1) {
  1613. BOOL condition = offline_edit;
  1614. #ifdef OFFLINE_MODE
  1615. condition = condition || appDelegate.offline_mode==false;
  1616. #else
  1617. condition = YES;
  1618. #endif
  1619. if (condition)
  1620. {
  1621. cell.sign_img.userInteractionEnabled = YES;
  1622. }
  1623. }
  1624. else if(status_code==0) {
  1625. BOOL condition = offline_edit;
  1626. #ifdef OFFLINE_MODE
  1627. condition = condition || appDelegate.offline_mode==false;
  1628. #else
  1629. condition = YES;
  1630. #endif
  1631. if (condition)
  1632. {
  1633. cell.sign_img.userInteractionEnabled = YES;
  1634. }
  1635. }
  1636. NSString* file_name=[img_url lastPathComponent];
  1637. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1638. if(img_data!=nil)
  1639. {
  1640. UIImage * img =[UIImage imageWithData:img_data];
  1641. cell.sign_img.image=img ;
  1642. }
  1643. else
  1644. {
  1645. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1646. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1647. dispatch_async(dispatch_get_main_queue(), ^{
  1648. if(downloadimg_data!=nil)
  1649. {
  1650. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1651. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1652. cell.sign_img.image=img ;
  1653. }
  1654. else {
  1655. if (cell.sign_img.userInteractionEnabled) {
  1656. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  1657. } else {
  1658. cell.sign_img.image = nil;
  1659. }
  1660. }
  1661. });
  1662. });
  1663. }
  1664. cell.backgroundColor = [UIColor whiteColor];
  1665. return cell;
  1666. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  1667. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1668. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1669. cell.webview.tag = indexPath.section;
  1670. cell.webview.delegate = self;
  1671. // cell.webView.scrollView.contentSize.height = 0;
  1672. cell.webview.scrollView.bounces=NO;
  1673. cell.webview.scrollView.directionalLockEnabled = true;
  1674. CGSize size= cell.webview.scrollView.contentSize;
  1675. size.height=10;
  1676. cell.webview.scrollView.contentSize=size;
  1677. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1678. cell.backgroundColor = [UIColor whiteColor];
  1679. return cell;
  1680. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  1681. NSDictionary *data = [section objectForKey:@"data"];
  1682. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1683. NSString *item_type = [item objectForKey:@"type"];
  1684. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  1685. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  1686. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1687. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  1688. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  1689. NSString *track_number = [item objectForKey:@"tracking_number"];
  1690. NSString *status = [item objectForKey:@"status"];
  1691. cell.track_number_lb.text = track_number;
  1692. cell.status_lb.text = status;
  1693. cell.carrier_lb.text = carrier;
  1694. cell.url_lb.text = web_url;
  1695. return cell;
  1696. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  1697. NSString *CellIdentifier = @"OrderDetailModelCell";
  1698. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1699. NSDictionary * item_json = item;
  1700. // int count = [[item_json valueForKey:@"count"] intValue];
  1701. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1702. cell.bundle_item=combine_json;
  1703. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  1704. if (cell.masterBtn != nil) {
  1705. if (master_json == nil) {
  1706. cell.masterBtn.hidden = YES;
  1707. } else{
  1708. cell.masterBtn.hidden = NO;
  1709. cell.master_items = master_json;
  1710. }
  1711. }
  1712. double dprice=0.0;
  1713. if(cell.bundle_item!=nil)
  1714. {
  1715. int citem=0;
  1716. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  1717. for(int bc=0;bc<bcount;bc++)
  1718. {
  1719. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1720. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1721. citem+= modulus;
  1722. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1723. dprice+= uprice*modulus;
  1724. }
  1725. if(citem==1)
  1726. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1727. else
  1728. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1729. cell.buttonBundle.hidden = NO;
  1730. }
  1731. else
  1732. {
  1733. cell.buttonBundle.hidden = YES;
  1734. }
  1735. NSString* img_url = [item_json valueForKey:@"img"];
  1736. NSString* description = [item_json valueForKey:@"Item Number"];
  1737. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  1738. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  1739. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  1740. NSString* qty = [item_json valueForKey:@"QTY"];
  1741. NSString* status = [item_json valueForKey:@"order_item_status"];
  1742. NSString* notes = [item_json valueForKey:@"note"];
  1743. if(notes.length>0)
  1744. {
  1745. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  1746. }
  1747. else
  1748. cell.noteLabel.text = nil;
  1749. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1750. {
  1751. }
  1752. else
  1753. {
  1754. unitprice=nil;
  1755. origin_price=nil;
  1756. subtotal=nil;
  1757. }
  1758. float duprice = [unitprice floatValue];
  1759. float dsubtotal = (duprice+dprice)*[qty intValue];
  1760. cell.descriptionLabel.text=description;
  1761. if(dprice>0)
  1762. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  1763. else
  1764. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  1765. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  1766. cell.qtyLabel.text = qty;
  1767. cell.statusLabel.text = status;
  1768. cell.labelOldPrice.text = origin_price;
  1769. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  1770. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  1771. cell.labelDiscount.text = discountstr;
  1772. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1773. if(isfree)
  1774. {
  1775. cell.labelOldPrice.hidden = false;
  1776. cell.labelOldPrice.textColor = [UIColor redColor];
  1777. cell.labelOldPrice.text=@"Free";
  1778. cell.labelOldPrice.hideline = true;
  1779. cell.labelDiscount.hidden = true;
  1780. }
  1781. else
  1782. {
  1783. cell.labelOldPrice.textColor = [UIColor blackColor];
  1784. cell.labelOldPrice.hideline = false;
  1785. if(discount==0)
  1786. {
  1787. cell.labelOldPrice.hidden = true;
  1788. cell.labelDiscount.hidden = true;
  1789. }
  1790. else
  1791. {
  1792. cell.labelOldPrice.hidden = false;
  1793. cell.labelDiscount.hidden = false;
  1794. }
  1795. }
  1796. // Button 设置了大小约束,Size就不会随内容变化
  1797. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  1798. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  1799. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  1800. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  1801. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  1802. if (![cell.imageName isEqualToString:img_url]) {
  1803. cell.imageName = img_url;
  1804. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1805. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1806. NSString* file_name=[img_url lastPathComponent];
  1807. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1808. if(img_data!=nil)
  1809. {
  1810. UIImage * img =[UIImage imageWithData:img_data];
  1811. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1812. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  1813. }
  1814. else
  1815. {
  1816. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1817. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1818. dispatch_async(dispatch_get_main_queue(), ^{
  1819. if(downloadimg_data!=nil)
  1820. {
  1821. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1822. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1823. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1824. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  1825. }
  1826. else
  1827. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1828. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1829. });
  1830. });
  1831. }
  1832. }
  1833. cell.backgroundColor = [UIColor whiteColor];
  1834. return cell;
  1835. }
  1836. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  1837. NSString *CellIdentifier = @"OrderDetailPriceCell";
  1838. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1839. NSDictionary *data = [section objectForKey:@"data"];
  1840. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1841. NSString *title = [item objectForKey:@"title"];
  1842. NSString *value = [item objectForKey:@"value"];
  1843. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  1844. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1845. {
  1846. }
  1847. else
  1848. {
  1849. value=nil;
  1850. }
  1851. }
  1852. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  1853. cell.priceLabel.text = value;
  1854. cell.backgroundColor = [UIColor whiteColor];
  1855. return cell;
  1856. }
  1857. #endif
  1858. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1859. /**
  1860. * ver1.90
  1861. */
  1862. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1863. NSString *type = [section objectForKey:@"type"];
  1864. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  1865. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1866. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1867. cell.webview.tag = indexPath.section;
  1868. cell.webview.delegate = self;
  1869. // cell.webView.scrollView.contentSize.height = 0;
  1870. cell.webview.scrollView.bounces=NO;
  1871. cell.webview.scrollView.directionalLockEnabled = true;
  1872. CGSize size= cell.webview.scrollView.contentSize;
  1873. size.height=10;
  1874. cell.webview.scrollView.contentSize=size;
  1875. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1876. cell.backgroundColor = [UIColor whiteColor];
  1877. return cell;
  1878. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  1879. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  1880. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1881. NSString* img_url = [section valueForKey:@"data"];
  1882. cell.sign_img.userInteractionEnabled = NO;
  1883. __block BOOL hasTapGesture = NO;
  1884. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1885. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  1886. hasTapGesture = YES;
  1887. *stop = YES;
  1888. }
  1889. }];
  1890. if (!hasTapGesture) {
  1891. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  1892. [cell.sign_img addGestureRecognizer:signatureTap];
  1893. }
  1894. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1895. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1896. if(status_code==1) {
  1897. BOOL condition = offline_edit;
  1898. #ifdef OFFLINE_MODE
  1899. condition = condition || appDelegate.offline_mode==false;
  1900. #else
  1901. condition = YES;
  1902. #endif
  1903. if (condition)
  1904. {
  1905. cell.sign_img.userInteractionEnabled = YES;
  1906. }
  1907. }
  1908. else if(status_code==0) {
  1909. BOOL condition = offline_edit;
  1910. #ifdef OFFLINE_MODE
  1911. condition = condition || appDelegate.offline_mode==false;
  1912. #else
  1913. condition = YES;
  1914. #endif
  1915. if (condition)
  1916. {
  1917. cell.sign_img.userInteractionEnabled = YES;
  1918. }
  1919. }
  1920. NSString* file_name=[img_url lastPathComponent];
  1921. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1922. if(img_data!=nil)
  1923. {
  1924. UIImage * img =[UIImage imageWithData:img_data];
  1925. cell.sign_img.image=img ;
  1926. }
  1927. else
  1928. {
  1929. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1930. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1931. dispatch_async(dispatch_get_main_queue(), ^{
  1932. if(downloadimg_data!=nil)
  1933. {
  1934. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1935. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1936. cell.sign_img.image=img ;
  1937. }
  1938. else {
  1939. if (cell.sign_img.userInteractionEnabled) {
  1940. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  1941. } else {
  1942. cell.sign_img.image = nil;
  1943. }
  1944. }
  1945. });
  1946. });
  1947. }
  1948. cell.backgroundColor = [UIColor whiteColor];
  1949. return cell;
  1950. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  1951. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1952. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1953. cell.webview.tag = indexPath.section;
  1954. cell.webview.delegate = self;
  1955. // cell.webView.scrollView.contentSize.height = 0;
  1956. cell.webview.scrollView.bounces=NO;
  1957. cell.webview.scrollView.directionalLockEnabled = true;
  1958. CGSize size= cell.webview.scrollView.contentSize;
  1959. size.height=10;
  1960. cell.webview.scrollView.contentSize=size;
  1961. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1962. cell.backgroundColor = [UIColor whiteColor];
  1963. return cell;
  1964. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  1965. NSDictionary *data = [section objectForKey:@"data"];
  1966. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1967. NSString *item_type = [item objectForKey:@"type"];
  1968. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  1969. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  1970. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1971. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  1972. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  1973. NSString *track_number = [item objectForKey:@"tracking_number"];
  1974. NSString *status = [item objectForKey:@"status"];
  1975. cell.track_number_lb.text = track_number;
  1976. cell.status_lb.text = status;
  1977. cell.carrier_lb.text = carrier;
  1978. cell.url_lb.text = web_url;
  1979. return cell;
  1980. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  1981. NSString *CellIdentifier = @"OrderDetailModelCell";
  1982. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1983. NSDictionary * item_json = item;
  1984. // int count = [[item_json valueForKey:@"count"] intValue];
  1985. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1986. cell.bundle_item=combine_json;
  1987. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  1988. if (cell.masterBtn != nil) {
  1989. if (master_json == nil) {
  1990. cell.masterBtn.hidden = YES;
  1991. } else{
  1992. cell.masterBtn.hidden = NO;
  1993. cell.master_items = master_json;
  1994. }
  1995. }
  1996. double dprice=0.0;
  1997. if(cell.bundle_item!=nil)
  1998. {
  1999. int citem=0;
  2000. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2001. for(int bc=0;bc<bcount;bc++)
  2002. {
  2003. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2004. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2005. citem+= modulus;
  2006. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2007. dprice+= uprice*modulus;
  2008. }
  2009. if(citem==1)
  2010. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2011. else
  2012. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2013. cell.buttonBundle.hidden = NO;
  2014. }
  2015. else
  2016. {
  2017. cell.buttonBundle.hidden = YES;
  2018. }
  2019. NSString* img_url = [item_json valueForKey:@"img"];
  2020. NSString* description = [item_json valueForKey:@"Item Number"];
  2021. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2022. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2023. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2024. NSString* qty = [item_json valueForKey:@"QTY"];
  2025. NSString* status = [item_json valueForKey:@"order_item_status"];
  2026. NSString* notes = [item_json valueForKey:@"note"];
  2027. if(notes.length>0)
  2028. {
  2029. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2030. }
  2031. else
  2032. cell.noteLabel.text = nil;
  2033. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2034. {
  2035. }
  2036. else
  2037. {
  2038. unitprice=nil;
  2039. origin_price=nil;
  2040. subtotal=nil;
  2041. }
  2042. float duprice = [unitprice floatValue];
  2043. float dsubtotal = (duprice+dprice)*[qty intValue];
  2044. cell.descriptionLabel.text=description;
  2045. if(dprice>0)
  2046. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2047. else
  2048. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2049. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2050. cell.qtyLabel.text = qty;
  2051. cell.statusLabel.text = status;
  2052. cell.labelOldPrice.text = origin_price;
  2053. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2054. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2055. cell.labelDiscount.text = discountstr;
  2056. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2057. if(isfree)
  2058. {
  2059. cell.labelOldPrice.hidden = false;
  2060. cell.labelOldPrice.textColor = [UIColor redColor];
  2061. cell.labelOldPrice.text=@"Free";
  2062. cell.labelOldPrice.hideline = true;
  2063. cell.labelDiscount.hidden = true;
  2064. }
  2065. else
  2066. {
  2067. cell.labelOldPrice.textColor = [UIColor blackColor];
  2068. cell.labelOldPrice.hideline = false;
  2069. if(discount==0)
  2070. {
  2071. cell.labelOldPrice.hidden = true;
  2072. cell.labelDiscount.hidden = true;
  2073. }
  2074. else
  2075. {
  2076. cell.labelOldPrice.hidden = false;
  2077. cell.labelDiscount.hidden = false;
  2078. }
  2079. }
  2080. // Button 设置了大小约束,Size就不会随内容变化
  2081. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2082. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2083. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2084. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2085. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2086. if (![cell.imageName isEqualToString:img_url]) {
  2087. cell.imageName = img_url;
  2088. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2089. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2090. NSString* file_name=[img_url lastPathComponent];
  2091. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2092. if(img_data!=nil)
  2093. {
  2094. UIImage * img =[UIImage imageWithData:img_data];
  2095. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2096. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2097. }
  2098. else
  2099. {
  2100. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2101. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2102. dispatch_async(dispatch_get_main_queue(), ^{
  2103. if(downloadimg_data!=nil)
  2104. {
  2105. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2106. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2107. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2108. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2109. }
  2110. else
  2111. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2112. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2113. });
  2114. });
  2115. }
  2116. }
  2117. cell.backgroundColor = [UIColor whiteColor];
  2118. return cell;
  2119. }
  2120. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  2121. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2122. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2123. NSDictionary *data = [section objectForKey:@"data"];
  2124. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2125. NSString *title = [item objectForKey:@"title"];
  2126. NSString *value = [item objectForKey:@"value"];
  2127. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  2128. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2129. {
  2130. }
  2131. else
  2132. {
  2133. value=nil;
  2134. }
  2135. }
  2136. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  2137. cell.priceLabel.text = value;
  2138. cell.backgroundColor = [UIColor whiteColor];
  2139. return cell;
  2140. }
  2141. #endif
  2142. #ifdef BUILD_HMLG
  2143. switch(indexPath.section)
  2144. {
  2145. case 0:
  2146. {
  2147. if(indexPath.row==0)
  2148. {
  2149. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2150. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2151. cell.webview.tag = indexPath.section;
  2152. cell.webview.delegate = self;
  2153. // cell.webView.scrollView.contentSize.height = 0;
  2154. cell.webview.scrollView.bounces=NO;
  2155. cell.webview.scrollView.directionalLockEnabled = true;
  2156. CGSize size= cell.webview.scrollView.contentSize;
  2157. size.height=10;
  2158. cell.webview.scrollView.contentSize=size;
  2159. [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  2160. cell.backgroundColor = [UIColor whiteColor];
  2161. return cell;
  2162. }
  2163. else
  2164. {
  2165. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2166. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2167. NSString* img_url = [self.content_data valueForKey:@"sign_url"];
  2168. cell.sign_img.userInteractionEnabled = NO;
  2169. __block BOOL hasTapGesture = NO;
  2170. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2171. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2172. hasTapGesture = YES;
  2173. *stop = YES;
  2174. }
  2175. }];
  2176. if (!hasTapGesture) {
  2177. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2178. [cell.sign_img addGestureRecognizer:signatureTap];
  2179. }
  2180. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2181. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2182. if(status_code==1) {
  2183. BOOL condition = offline_edit;
  2184. #ifdef OFFLINE_MODE
  2185. condition = condition || appDelegate.offline_mode==false;
  2186. #else
  2187. condition = YES;
  2188. #endif
  2189. if (condition)
  2190. {
  2191. cell.sign_img.userInteractionEnabled = YES;
  2192. }
  2193. }
  2194. else if(status_code==0) {
  2195. BOOL condition = offline_edit;
  2196. #ifdef OFFLINE_MODE
  2197. condition = condition || appDelegate.offline_mode==false;
  2198. #else
  2199. condition = YES;
  2200. #endif
  2201. if (condition)
  2202. {
  2203. cell.sign_img.userInteractionEnabled = YES;
  2204. }
  2205. }
  2206. NSString* file_name=[img_url lastPathComponent];
  2207. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2208. if(img_data!=nil)
  2209. {
  2210. UIImage * img =[UIImage imageWithData:img_data];
  2211. cell.sign_img.image=img ;
  2212. }
  2213. else
  2214. {
  2215. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2216. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2217. dispatch_async(dispatch_get_main_queue(), ^{
  2218. if(downloadimg_data!=nil)
  2219. {
  2220. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2221. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2222. cell.sign_img.image=img ;
  2223. }
  2224. else {
  2225. if (cell.sign_img.userInteractionEnabled) {
  2226. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2227. } else {
  2228. cell.sign_img.image = nil;
  2229. }
  2230. }
  2231. });
  2232. });
  2233. }
  2234. cell.backgroundColor = [UIColor whiteColor];
  2235. return cell;
  2236. }
  2237. }
  2238. break;
  2239. case 1:
  2240. {
  2241. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2242. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2243. cell.webview.tag = indexPath.section;
  2244. cell.webview.delegate = self;
  2245. // cell.webView.scrollView.contentSize.height = 0;
  2246. cell.webview.scrollView.bounces=NO;
  2247. cell.webview.scrollView.directionalLockEnabled = true;
  2248. CGSize size= cell.webview.scrollView.contentSize;
  2249. size.height=10;
  2250. cell.webview.scrollView.contentSize=size;
  2251. [cell.webview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  2252. cell.backgroundColor = [UIColor whiteColor];
  2253. return cell;
  2254. // NSString *CellIdentifier = @"OrderDetailInfoCell";
  2255. // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2256. //
  2257. // cell.infoLabel.text =[self.content_data valueForKey:@"more_order_info"];
  2258. //
  2259. //
  2260. //
  2261. //// float width = tableView.frame.size.width;
  2262. //// width-=CELL_MARGIN*2;
  2263. //// CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  2264. ////
  2265. //// NSString* key =[self.content_data valueForKey:@"order_info"];
  2266. ////
  2267. ////
  2268. ////
  2269. //// CGRect frame;
  2270. //// frame.size = constraintkey;
  2271. //// frame.origin.x=0;
  2272. //// frame.origin.y=0;
  2273. ////
  2274. //// RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  2275. ////
  2276. //// [rtlabel setText: key];
  2277. //// CGSize optimumSize = [rtlabel optimumSize];
  2278. ////
  2279. //// float height = optimumSize.height;
  2280. //// height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  2281. ////
  2282. ////
  2283. //// frame.origin.x=LABEL_MARGIN;
  2284. //// frame.size=CGSizeMake(width, height);
  2285. ////
  2286. //// cell.infoLabel.frame = frame;
  2287. //
  2288. //
  2289. //
  2290. //
  2291. // cell.backgroundColor = [UIColor whiteColor];
  2292. // return cell;
  2293. }
  2294. break;
  2295. case 2:
  2296. {
  2297. NSString *CellIdentifier = @"OrderDetailModelCell";
  2298. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2299. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2300. int count = [[item_json valueForKey:@"count"] intValue];
  2301. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2302. cell.bundle_item=combine_json;
  2303. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2304. if (cell.masterBtn != nil) {
  2305. if (master_json == nil) {
  2306. cell.masterBtn.hidden = YES;
  2307. } else{
  2308. cell.masterBtn.hidden = NO;
  2309. cell.master_items = master_json;
  2310. }
  2311. }
  2312. double dprice=0.0;
  2313. if(cell.bundle_item!=nil)
  2314. {
  2315. int citem=0;
  2316. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2317. for(int bc=0;bc<bcount;bc++)
  2318. {
  2319. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2320. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2321. citem+= modulus;
  2322. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2323. dprice+= uprice*modulus;
  2324. }
  2325. if(citem==1)
  2326. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2327. else
  2328. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2329. cell.buttonBundle.hidden = NO;
  2330. }
  2331. else
  2332. {
  2333. cell.buttonBundle.hidden = YES;
  2334. }
  2335. NSString* img_url = [item_json valueForKey:@"img"];
  2336. NSString* description = [item_json valueForKey:@"Item Number"];
  2337. // NSString* description = [item_json valueForKey:@"Item Number"];
  2338. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2339. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2340. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2341. NSString* qty = [item_json valueForKey:@"QTY"];
  2342. NSString* status = [item_json valueForKey:@"order_item_status"];
  2343. NSString* notes = [item_json valueForKey:@"note"];
  2344. if(notes.length>0)
  2345. {
  2346. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2347. }
  2348. else
  2349. cell.noteLabel.text = nil;
  2350. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2351. {
  2352. }
  2353. else
  2354. {
  2355. unitprice=nil;
  2356. origin_price=nil;
  2357. subtotal=nil;
  2358. }
  2359. float duprice = [unitprice floatValue];
  2360. float dsubtotal = (duprice+dprice)*[qty intValue];
  2361. cell.descriptionLabel.text=description;
  2362. if(dprice>0)
  2363. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2364. else
  2365. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2366. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2367. cell.qtyLabel.text = qty;
  2368. cell.statusLabel.text = status;
  2369. cell.labelOldPrice.text = origin_price;
  2370. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2371. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2372. cell.labelDiscount.text = discountstr;
  2373. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2374. if(isfree)
  2375. {
  2376. cell.labelOldPrice.hidden = false;
  2377. cell.labelOldPrice.textColor = [UIColor redColor];
  2378. cell.labelOldPrice.text=@"Free";
  2379. cell.labelOldPrice.hideline = true;
  2380. cell.labelDiscount.hidden = true;
  2381. }
  2382. else
  2383. {
  2384. cell.labelOldPrice.textColor = [UIColor blackColor];
  2385. cell.labelOldPrice.hideline = false;
  2386. if(discount==0)
  2387. {
  2388. cell.labelOldPrice.hidden = true;
  2389. cell.labelDiscount.hidden = true;
  2390. }
  2391. else
  2392. {
  2393. cell.labelOldPrice.hidden = false;
  2394. cell.labelDiscount.hidden = false;
  2395. }
  2396. }
  2397. // Button 设置了大小约束,Size就不会随内容变化
  2398. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2399. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2400. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2401. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2402. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2403. if (![cell.imageName isEqualToString:img_url]) {
  2404. cell.imageName = img_url;
  2405. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2406. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2407. NSString* file_name=[img_url lastPathComponent];
  2408. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2409. if(img_data!=nil)
  2410. {
  2411. UIImage * img =[UIImage imageWithData:img_data];
  2412. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2413. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2414. }
  2415. else
  2416. {
  2417. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2418. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2419. dispatch_async(dispatch_get_main_queue(), ^{
  2420. if(downloadimg_data!=nil)
  2421. {
  2422. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2423. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2424. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2425. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2426. }
  2427. else
  2428. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2429. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2430. });
  2431. });
  2432. }
  2433. }
  2434. cell.backgroundColor = [UIColor whiteColor];
  2435. return cell;
  2436. }
  2437. break;
  2438. case 3:
  2439. {
  2440. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2441. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2442. switch (indexPath.row) {
  2443. case 0:
  2444. {
  2445. cell.chargeLabel.text =@"Sub-Total:";
  2446. NSString* price=[self.content_data valueForKey:@"Sub-Total"];
  2447. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2448. {
  2449. }
  2450. else
  2451. {
  2452. price=nil;
  2453. }
  2454. cell.priceLabel.text =price;
  2455. break;
  2456. }
  2457. case 1:
  2458. cell.chargeLabel.text = @"Shipping:";
  2459. cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
  2460. break;
  2461. case 2: {
  2462. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  2463. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2464. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2465. #endif
  2466. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2467. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2468. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2469. #endif
  2470. #ifdef BUILD_HMLG
  2471. cell.chargeLabel.text = @"Tax:";
  2472. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  2473. cell.priceLabel.text = tax;
  2474. #endif
  2475. }
  2476. break;
  2477. case 3: {
  2478. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  2479. cell.chargeLabel.text = @"Handling Fee:";
  2480. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2481. #endif
  2482. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2483. cell.chargeLabel.text = @"Handling Fee:";
  2484. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2485. #endif
  2486. #ifdef BUILD_HMLG
  2487. NSString* price=[self.content_data valueForKey:@"Total"];
  2488. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2489. {
  2490. }
  2491. else
  2492. {
  2493. price=nil;
  2494. }
  2495. cell.chargeLabel.text = @"Total:";
  2496. cell.priceLabel.text =price;
  2497. #endif
  2498. }
  2499. break;
  2500. case 4: {
  2501. cell.chargeLabel.text = @"Tax:";
  2502. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  2503. cell.priceLabel.text = tax;
  2504. }
  2505. break;
  2506. case 5:
  2507. {
  2508. NSString* price=[self.content_data valueForKey:@"Total"];
  2509. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2510. {
  2511. }
  2512. else
  2513. {
  2514. price=nil;
  2515. }
  2516. cell.chargeLabel.text = @"Total:";
  2517. cell.priceLabel.text =price;
  2518. break;
  2519. }
  2520. default:
  2521. break;
  2522. }
  2523. cell.backgroundColor = [UIColor whiteColor];
  2524. return cell;
  2525. }
  2526. }
  2527. #endif
  2528. return nil;
  2529. // if(tableView==self.itemListTable)
  2530. // {
  2531. // NSString *CellIdentifier = @"CartItemCell";
  2532. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2533. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2534. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2535. //
  2536. // cell.bundle_item=combine_json;
  2537. // NSString* img_url = [item_json valueForKey:@"img_url"];
  2538. // NSString* description = [item_json valueForKey:@"description"];
  2539. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  2540. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  2541. // NSString* currency = [item_json valueForKey:@"currency"];
  2542. // int count =[[item_json valueForKey:@"count"] intValue];
  2543. //
  2544. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2545. //
  2546. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2547. //
  2548. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2549. // cell.unit_price = unitprice;
  2550. // // cell.labelAttribute.text = attribute;
  2551. // // cell.labelCurrency.text = currency;
  2552. // cell.labelDescription.text = description;
  2553. // // cell.labelIdentifier.text = identifier;
  2554. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  2555. //
  2556. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  2557. //
  2558. //
  2559. //
  2560. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2561. // cell.cart_id = cart_item_id;
  2562. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2563. //
  2564. //
  2565. //
  2566. // [cell set_Count:count];
  2567. //
  2568. // NSString* file_name=[img_url lastPathComponent];
  2569. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2570. // if(img_data!=nil)
  2571. // {
  2572. //
  2573. // UIImage * img =[UIImage imageWithData:img_data];
  2574. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2575. // }
  2576. // else
  2577. // {
  2578. //
  2579. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2580. //
  2581. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2582. //
  2583. // dispatch_async(dispatch_get_main_queue(), ^{
  2584. //
  2585. //
  2586. //
  2587. // if(downloadimg_data!=nil)
  2588. // {
  2589. // [iSalesDB cache_img:downloadimg_data :file_name ];
  2590. //
  2591. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  2592. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2593. // }
  2594. //
  2595. // });
  2596. // });
  2597. //
  2598. //
  2599. // }
  2600. // return cell;
  2601. // }
  2602. // else
  2603. // {
  2604. // NSString *CellIdentifier = @"OrderInfoListItem";
  2605. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2606. // return cell;
  2607. // }
  2608. }
  2609. #pragma mark - UIAlertViewDelegate
  2610. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  2611. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  2612. {
  2613. if(buttonIndex!=alertView.cancelButtonIndex)
  2614. {
  2615. [self copyOrder];
  2616. }
  2617. }
  2618. - (void)copyOrder {
  2619. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Copy Order"];
  2620. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2621. NSDictionary* order_json = [RANetwork copy_Order:self.order_code];
  2622. dispatch_async(dispatch_get_main_queue(), ^{
  2623. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2624. if([[order_json valueForKey:@"result"] intValue]==2)
  2625. {
  2626. // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  2627. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2628. // if([appDelegate.order_code isEqualToString: self.order_code])
  2629. // {
  2630. // [appDelegate closeOrder];
  2631. //// appDelegate.order_code= nil;
  2632. // [appDelegate SetSo:nil];
  2633. //
  2634. //
  2635. // }
  2636. 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];
  2637. [alert show];
  2638. #ifdef RA_NOTIFICATION
  2639. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2640. #else
  2641. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2642. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2643. #endif
  2644. [self.navigationController popViewControllerAnimated:false];
  2645. }
  2646. else
  2647. {
  2648. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  2649. }
  2650. });
  2651. });
  2652. }
  2653. #pragma mark - web view delegate
  2654. //- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  2655. //{
  2656. // if(navigationType != UIWebViewNavigationTypeLinkClicked)
  2657. // return true;
  2658. // // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  2659. //
  2660. // NSString* str = request.URL.absoluteString;
  2661. // if([str isEqualToString:@"about:blank"])
  2662. // return true;
  2663. // WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  2664. // ViewController.url = str;
  2665. // // ViewController. = self.function_name;
  2666. // // ViewController.behavior =BEHAVIOR_SEARCH;
  2667. //
  2668. // [self.navigationController pushViewController:ViewController animated:YES];
  2669. // DebugLog(@"shouldStartLoadWithRequest");
  2670. // return false;
  2671. //}
  2672. - (void)webViewDidFinishLoad:(UIWebView *)webView
  2673. {
  2674. DebugLog(@"webViewDidFinishLoad @@@@@@@@@@@@@@@@@ entry");
  2675. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  2676. NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
  2677. if(indexPath==nil)
  2678. {//for ios7
  2679. cell = (UITableViewCell *) webView.superview.superview.superview;
  2680. indexPath = [self.detailTable indexPathForCell:cell];
  2681. }
  2682. if(indexPath==nil)
  2683. return;
  2684. float height= 0;
  2685. if(indexPath.section==0)
  2686. height=self.web_info_height;
  2687. else
  2688. height = self.web_moreinfo_height;
  2689. // if(height>0)
  2690. // return;
  2691. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  2692. // CGSize size= webView.scrollView.contentSize;
  2693. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  2694. CGRect frame = webView.frame;
  2695. NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  2696. //
  2697. if(height==[fitHeight floatValue])
  2698. return;
  2699. frame.size.height = [fitHeight floatValue];
  2700. //webView.frame = frame;
  2701. // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  2702. if(indexPath.section==0)
  2703. self.web_info_height=frame.size.height;
  2704. else
  2705. self.web_moreinfo_height = frame.size.height;
  2706. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  2707. DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
  2708. dispatch_async(dispatch_get_main_queue(), ^{
  2709. // UI更新代码
  2710. // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  2711. [self.detailTable reloadData];
  2712. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2713. });
  2714. // [self.table beginUpdates];
  2715. // [self.table endUpdates];
  2716. // [self.webviewoprationQueue addOperationWithBlock:^{
  2717. // }];
  2718. // [self.table endUpdates];
  2719. // }
  2720. }
  2721. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
  2722. if (navigationType != UIWebViewNavigationTypeLinkClicked ) {
  2723. return YES;
  2724. }
  2725. if ([[UIApplication sharedApplication] canOpenURL:request.URL]) {
  2726. [[UIApplication sharedApplication] openURL:request.URL];
  2727. }
  2728. return NO;
  2729. }
  2730. - (void)reRefreshView {
  2731. [self.detailTable reloadData];
  2732. }
  2733. #pragma mark - RA_NOTIFICAITON
  2734. -(void) refresh_ui
  2735. {
  2736. [self.detailTable reloadData];
  2737. }
  2738. -(void) reload_data
  2739. {
  2740. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  2741. [reF endRefreshing];
  2742. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  2743. [self loaddata];
  2744. }
  2745. -(void) refresh_price
  2746. {
  2747. [self refresh_ui];
  2748. }
  2749. @end