OrderDetailViewController.m 137 KB

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