OrderDetailViewController.m 136 KB

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