OrderDetailViewController.m 138 KB

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