OrderDetailViewController.m 136 KB

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