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