OrderDetailViewController.m 135 KB

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