OrderDetailViewController.m 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336
  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 = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] 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)|| defined (BUILD_CONTRAST)
  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. //
  194. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  195. //// self.web_info_height = 0;
  196. ////
  197. //// [self.detailTable.indexPathsForVisibleRows enumerateObjectsUsingBlock:^(NSIndexPath * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  198. ////
  199. //// if (obj.section == 0 && obj.section == 0) {
  200. //// [self.detailTable reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  201. //// }
  202. ////
  203. //// }];
  204. //
  205. //
  206. //}
  207. - (IBAction)onReleaseOrderClick:(id)sender {
  208. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  209. //block代码块取代了delegate
  210. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  211. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  212. [RANetwork request_release_order:self.order_code withScreen:ScreenCodeOrderInfo completionHandler:^(NSMutableDictionary *result) {
  213. NSDictionary* order_json =result;
  214. [waitalert dismissViewControllerAnimated:YES completion:^{
  215. if([[order_json valueForKey:@"result"] intValue]==2)
  216. {
  217. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  218. // appDelegate.order_code = nil;
  219. [appDelegate closeOrder];
  220. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  221. //
  222. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  223. // if(self.selectOrder)
  224. // self.selectOrder();
  225. [self.navigationController popToRootViewControllerAnimated:false];
  226. }
  227. else
  228. {
  229. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  230. }
  231. }];
  232. }];
  233. }];
  234. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  235. //
  236. // NSDictionary* order_json = [RANetwork release_Order:self.order_code withScreen:ScreenCodeOrderInfo];
  237. //
  238. // dispatch_async(dispatch_get_main_queue(), ^{
  239. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  240. // if([[order_json valueForKey:@"result"] intValue]==2)
  241. // {
  242. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  243. // // appDelegate.order_code = nil;
  244. // [appDelegate closeOrder];
  245. //
  246. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  247. // //
  248. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  249. // // if(self.selectOrder)
  250. // // self.selectOrder();
  251. // [self.navigationController popToRootViewControllerAnimated:false];
  252. //
  253. // }
  254. // else
  255. // {
  256. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  257. // }
  258. //
  259. //
  260. //
  261. // });
  262. // });
  263. }];
  264. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  265. DebugLog(@"Cancel");
  266. }];
  267. [alertControl addAction:actionOne];
  268. [alertControl addAction:alertthree];
  269. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  270. [self presentViewController:alertControl animated:YES completion:nil];
  271. // get customer info
  272. }
  273. - (void)onDownloadOrderClick:(id)sender {
  274. //
  275. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  276. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  277. ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  278. NSString* so = [self.content_data valueForKey:@"so#"];
  279. if(so==nil)
  280. so =@"";
  281. NSString* company = [self.content_data[@"customerInfo"] valueForKey:@"customer_name"];
  282. if(company==nil)
  283. company =@"";
  284. ViewController.save_name =so;
  285. ViewController.hidenavi = false;
  286. if(company==nil)
  287. company=@"";
  288. NSString* customer_email= [self.content_data[@"customerInfo"] valueForKey:@"customer_email"];
  289. // NSMutableArray* arr_subject = [[NSMutableArray alloc]init];
  290. // if(company.length>0)
  291. // [arr_subject addObject:company];
  292. // if(so.length>0)
  293. // [arr_subject addObject:so];
  294. if(company.length==0)
  295. company=@"";
  296. if(so.length==0)
  297. so=@"";
  298. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  299. if(customer_email.length>0)
  300. {
  301. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  302. // customer_email compo
  303. // [send_to addObject:customer_email];
  304. }
  305. ViewController.mail_to = send_to;
  306. NSString* subject = nil;
  307. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  308. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,COMPANY_NAME];
  309. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  310. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  311. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  312. }
  313. #endif
  314. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  315. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,COMPANY_NAME];
  316. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  317. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  318. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  319. }
  320. #endif
  321. #ifdef BUILD_HMLG
  322. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from Homelegance.",company,so];
  323. #endif
  324. ViewController.mail_subject = subject;
  325. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  326. NSString *alertTitle = @"View Sales Order:";
  327. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30)) {
  328. alertTitle = @"View Store Order";
  329. }
  330. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];
  331. //block代码块取代了delegate
  332. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Thumbnails" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  333. #ifdef OFFLINE_MODE
  334. if(appDelegate.offline_mode)
  335. {
  336. __weak typeof(self) weakself = self;
  337. NSMutableDictionary* params = [@{
  338. @"thumb" : @"1",
  339. @"order_code" : self.order_code != nil ? self.order_code : @"",
  340. @"user":appDelegate.user
  341. } mutableCopy];
  342. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  343. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  344. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  345. NSString *path = dic[@"pdf_path"];
  346. [weakself saleOrderWithPath:path];
  347. // ViewController.url = path;
  348. // ViewController.isLocalfile = YES;
  349. //
  350. // [self.navigationController pushViewController:ViewController animated:YES];
  351. } else {
  352. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  353. }
  354. }
  355. else
  356. #endif
  357. {
  358. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  359. url= [url stringByAppendingString:@"&has_item_pic=true"];
  360. DebugLog(@"pdf url:%@",url);
  361. ViewController.url = url;
  362. [self.navigationController pushViewController:ViewController animated:YES];
  363. }
  364. }];
  365. NSString* alertthreetitle=@"Without Thumbnails";
  366. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))
  367. {
  368. alertthreetitle=@"Print Quotation";
  369. }
  370. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:alertthreetitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  371. #ifdef OFFLINE_MODE
  372. if(appDelegate.offline_mode)
  373. {
  374. __weak typeof(self) weakself = self;
  375. NSMutableDictionary* params = [@{
  376. @"thumb" : @"0",
  377. @"order_code" : self.order_code != nil ? self.order_code : @"",
  378. @"user":appDelegate.user
  379. } mutableCopy];
  380. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  381. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  382. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  383. NSString *path = dic[@"pdf_path"];
  384. [weakself saleOrderWithPath:path];
  385. // ViewController.url = path;
  386. // ViewController.isLocalfile = YES;
  387. //
  388. // [self.navigationController pushViewController:ViewController animated:YES];
  389. } else {
  390. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  391. }
  392. }
  393. else
  394. #endif
  395. {
  396. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  397. DebugLog(@"pdf url:%@",url);
  398. ViewController.url = url;
  399. [self.navigationController pushViewController:ViewController animated:YES];
  400. }
  401. }];
  402. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
  403. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))//[status isEqualToString:@"Saved Order"])
  404. {
  405. [alertControl addAction:alertthree];
  406. [alertControl addAction:alertCancel];
  407. }
  408. else
  409. {
  410. [alertControl addAction:actionOne];
  411. [alertControl addAction:alertthree];
  412. [alertControl addAction:alertCancel];
  413. }
  414. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  415. [self presentViewController:alertControl animated:YES completion:nil];
  416. // get customer info
  417. //
  418. }
  419. - (void)onCopyOrderClick:(id)sender {
  420. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  421. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.order_code) {
  422. __weak typeof(self) weakself = self;
  423. 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];
  424. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  425. }];
  426. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  427. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  428. [RANetwork request_release_order:appDelegate.order_code withScreen:ScreenCodeOrderInfo completionHandler:^(NSMutableDictionary *result) {
  429. NSDictionary* order_json = result;
  430. [waitalert dismissViewControllerAnimated:YES completion:^{
  431. if([[order_json valueForKey:@"result"] intValue]==2)
  432. {
  433. [appDelegate closeOrder];
  434. [weakself copyOrder];
  435. } else {
  436. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
  437. }
  438. }];
  439. }];
  440. }];
  441. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  442. //
  443. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeOrderInfo];
  444. //
  445. // dispatch_async(dispatch_get_main_queue(), ^{
  446. //
  447. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  448. // if([[order_json valueForKey:@"result"] intValue]==2)
  449. // {
  450. // [appDelegate closeOrder];
  451. //
  452. // [weakself copyOrder];
  453. //
  454. // } else {
  455. //
  456. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
  457. // }
  458. // });
  459. //
  460. // });
  461. }];
  462. [alertVC addAction:cancelAction];
  463. [alertVC addAction:yesAction];
  464. [self presentViewController:alertVC animated:YES completion:nil];
  465. } else {
  466. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Copy confirm" message:@"Are you sure to copy order?" preferredStyle:UIAlertControllerStyleAlert];
  467. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  468. [self copyOrder];
  469. }];
  470. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  471. }];
  472. [alertController addAction:action_2];
  473. [alertController addAction:action_3];
  474. [self presentViewController:alertController animated:YES completion:nil];
  475. // 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];
  476. // [alert show];
  477. }
  478. }
  479. //- (void)onCommitOrderClick:(id)sender {
  480. // // get customer info
  481. //
  482. // int model_count = [[self.content_data valueForKey:@"model_count"] intValue];
  483. // if(model_count==0)
  484. // {
  485. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error." message:@"Can not submit an order without models." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  486. ////
  487. //// [alert show];
  488. //
  489. //
  490. // [RAUtils alert_view:@"Cannot submit an order without models" title:@""];
  491. // }
  492. //
  493. // else
  494. // {
  495. //
  496. // 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];
  497. // [alert show];
  498. //
  499. // }
  500. //
  501. //
  502. //}
  503. -(void) upload_img :(UIImage*) img
  504. {
  505. #ifdef OFFLINE_MODE
  506. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  507. if(appDelegate.offline_mode)
  508. {
  509. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)];;
  510. // 再将NSData转为字符串
  511. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  512. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  513. DebugLog(@"data string: %@",jsonStr);
  514. NSError *error=nil;
  515. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  516. if([[json valueForKey:@"result"] intValue]==2)
  517. {
  518. NSString* img_url_down = json[@"img_url_aname"];
  519. NSString* img_url_up = json[@"img_url"];
  520. {
  521. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature" completion:^{
  522. [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  523. NSDictionary* order_json = result;
  524. [waitalert dismissViewControllerAnimated:YES completion:^{
  525. if([[order_json valueForKey:@"result"] intValue]==2)
  526. {
  527. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  528. // appDelegate.order_code = self.order_code;
  529. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  530. //
  531. //
  532. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  533. //
  534. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  535. // [self.navigationController popViewControllerAnimated:false];
  536. //
  537. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  538. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  539. // if(self.selectOrder)
  540. // self.selectOrder(self.content_data);
  541. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  542. int count = [[self.content_data objectForKey:@"count"] intValue];
  543. for (int i = 0; i < count; i++) {
  544. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  545. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  546. NSString *type = [section objectForKey:@"type"];
  547. if ([type isEqualToString:@"sign_url"]) {
  548. [section setObject:img_url_down forKey:@"data"];
  549. [self.content_data setObject:section forKey:key];
  550. break;
  551. }
  552. }
  553. #endif
  554. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  555. int count = [[self.content_data objectForKey:@"count"] intValue];
  556. for (int i = 0; i < count; i++) {
  557. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  558. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  559. NSString *type = [section objectForKey:@"type"];
  560. if ([type isEqualToString:@"sign_url"]) {
  561. [section setObject:img_url_down forKey:@"data"];
  562. [self.content_data setObject:section forKey:key];
  563. break;
  564. }
  565. }
  566. #endif
  567. #ifdef BUILD_HMLG
  568. [self.content_data setValue:img_url_down forKey:@"sign_url"];
  569. #endif
  570. //self.btnSign.enabled = false;
  571. [self.detailTable reloadData];
  572. [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  573. }
  574. else
  575. {
  576. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  577. }
  578. }];
  579. }];
  580. }];
  581. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  582. //
  583. // NSDictionary* order_json = [RANetwork sign_Order:self.order_code path:img_url_up];
  584. //
  585. // dispatch_async(dispatch_get_main_queue(), ^{
  586. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  587. // if([[order_json valueForKey:@"result"] intValue]==2)
  588. // {
  589. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  590. // // appDelegate.order_code = self.order_code;
  591. // // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  592. // //
  593. // //
  594. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  595. // //
  596. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  597. // // [self.navigationController popViewControllerAnimated:false];
  598. // //
  599. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  600. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  601. // // if(self.selectOrder)
  602. // // self.selectOrder(self.content_data);
  603. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  604. // int count = [[self.content_data objectForKey:@"count"] intValue];
  605. // for (int i = 0; i < count; i++) {
  606. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  607. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  608. // NSString *type = [section objectForKey:@"type"];
  609. // if ([type isEqualToString:@"sign_url"]) {
  610. // [section setObject:img_url_down forKey:@"data"];
  611. // [self.content_data setObject:section forKey:key];
  612. // break;
  613. // }
  614. // }
  615. //#endif
  616. //
  617. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  618. // int count = [[self.content_data objectForKey:@"count"] intValue];
  619. // for (int i = 0; i < count; i++) {
  620. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  621. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  622. // NSString *type = [section objectForKey:@"type"];
  623. // if ([type isEqualToString:@"sign_url"]) {
  624. // [section setObject:img_url_down forKey:@"data"];
  625. // [self.content_data setObject:section forKey:key];
  626. // break;
  627. // }
  628. // }
  629. //#endif
  630. //
  631. //
  632. //#ifdef BUILD_HMLG
  633. //
  634. // [self.content_data setValue:img_url_down forKey:@"sign_url"];
  635. //#endif
  636. // //self.btnSign.enabled = false;
  637. // [self.detailTable reloadData];
  638. //
  639. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  640. //
  641. //
  642. // }
  643. // else
  644. // {
  645. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  646. // }
  647. //
  648. //
  649. //
  650. // });
  651. // });
  652. }
  653. }
  654. else
  655. {
  656. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  657. }
  658. }
  659. else
  660. #endif
  661. {
  662. NSData *imageData = UIImagePNGRepresentation(img);
  663. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  664. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  665. if(appDelegate.user!=nil)
  666. [params setValue:appDelegate.user forKey:@"user"];
  667. if(appDelegate.password!=nil)
  668. [params setValue:appDelegate.password forKey:@"password"];
  669. __weak typeof(self) weakSelf = self;
  670. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature" completion:^{
  671. [RANetwork request_fastupload:params filename:@"test.jpg" data:imageData url:URL_UPLOAD_IMG completionHandler:^(NSMutableDictionary *result) {
  672. NSMutableDictionary *json=result;
  673. if([[json valueForKey:@"result"] intValue]==2)
  674. {
  675. NSString* img_url_down = json[@"img_url_aname"];
  676. NSString* img_url_up = json[@"img_url"];
  677. {
  678. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  679. [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  680. NSDictionary* order_json =result;
  681. [waitalert dismissViewControllerAnimated:YES completion:^{
  682. if([[order_json valueForKey:@"result"] intValue]==2)
  683. {
  684. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  685. int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  686. for (int i = 0; i < count; i++) {
  687. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  688. NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  689. NSString *type = [section objectForKey:@"type"];
  690. if ([type isEqualToString:@"sign_url"]) {
  691. [section setObject:img_url_down forKey:@"data"];
  692. [weakSelf.content_data setObject:section forKey:key];
  693. break;
  694. }
  695. }
  696. #endif
  697. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  698. int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  699. for (int i = 0; i < count; i++) {
  700. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  701. NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  702. NSString *type = [section objectForKey:@"type"];
  703. if ([type isEqualToString:@"sign_url"]) {
  704. [section setObject:img_url_down forKey:@"data"];
  705. [weakSelf.content_data setObject:section forKey:key];
  706. break;
  707. }
  708. }
  709. #endif
  710. #ifdef BUILD_HMLG
  711. [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  712. #endif
  713. //self.btnSign.enabled = false;
  714. [weakSelf.detailTable reloadData];
  715. [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  716. }
  717. else
  718. {
  719. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  720. }
  721. }];
  722. }];
  723. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  724. //
  725. // NSDictionary* order_json = [RANetwork sign_Order:weakSelf.order_code path:img_url_up];
  726. //
  727. // dispatch_async(dispatch_get_main_queue(), ^{
  728. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  729. // if([[order_json valueForKey:@"result"] intValue]==2)
  730. // {
  731. //
  732. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  733. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  734. // for (int i = 0; i < count; i++) {
  735. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  736. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  737. // NSString *type = [section objectForKey:@"type"];
  738. // if ([type isEqualToString:@"sign_url"]) {
  739. // [section setObject:img_url_down forKey:@"data"];
  740. // [weakSelf.content_data setObject:section forKey:key];
  741. // break;
  742. // }
  743. // }
  744. //#endif
  745. //
  746. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  747. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  748. // for (int i = 0; i < count; i++) {
  749. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  750. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  751. // NSString *type = [section objectForKey:@"type"];
  752. // if ([type isEqualToString:@"sign_url"]) {
  753. // [section setObject:img_url_down forKey:@"data"];
  754. // [weakSelf.content_data setObject:section forKey:key];
  755. // break;
  756. // }
  757. // }
  758. //#endif
  759. //
  760. //#ifdef BUILD_HMLG
  761. // [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  762. //#endif
  763. // //self.btnSign.enabled = false;
  764. // [weakSelf.detailTable reloadData];
  765. //
  766. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  767. //
  768. //
  769. // }
  770. // else
  771. // {
  772. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  773. // }
  774. //
  775. //
  776. //
  777. // });
  778. // });
  779. }
  780. }
  781. else
  782. {
  783. dispatch_async(dispatch_get_main_queue(), ^{
  784. [waitalert dismissViewControllerAnimated:YES completion:^{
  785. NSString *msg = [json valueForKey:@"err_msg"];
  786. if (msg.length == 0) {
  787. msg = [json objectForKey:@"msg"];
  788. }
  789. [RAUtils message_alert:msg title:@"Upload Image" controller:weakSelf] ;
  790. }];
  791. });
  792. }
  793. }];
  794. }];
  795. // [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
  796. //
  797. // if([[json valueForKey:@"result"] intValue]==2)
  798. // {
  799. // NSString* img_url_down = json[@"img_url_aname"];
  800. // NSString* img_url_up = json[@"img_url"];
  801. // {
  802. //// UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  803. // [RANetwork request_update_order_signature:self.order_code path:img_url_up completionHandler:^(NSMutableDictionary *result) {
  804. // NSDictionary* order_json =result;
  805. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  806. // if([[order_json valueForKey:@"result"] intValue]==2)
  807. // {
  808. //
  809. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  810. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  811. // for (int i = 0; i < count; i++) {
  812. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  813. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  814. // NSString *type = [section objectForKey:@"type"];
  815. // if ([type isEqualToString:@"sign_url"]) {
  816. // [section setObject:img_url_down forKey:@"data"];
  817. // [weakSelf.content_data setObject:section forKey:key];
  818. // break;
  819. // }
  820. // }
  821. //#endif
  822. //
  823. //#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  824. // int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  825. // for (int i = 0; i < count; i++) {
  826. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  827. // NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  828. // NSString *type = [section objectForKey:@"type"];
  829. // if ([type isEqualToString:@"sign_url"]) {
  830. // [section setObject:img_url_down forKey:@"data"];
  831. // [weakSelf.content_data setObject:section forKey:key];
  832. // break;
  833. // }
  834. // }
  835. //#endif
  836. //
  837. //#ifdef BUILD_HMLG
  838. // [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  839. //#endif
  840. // //self.btnSign.enabled = false;
  841. // [weakSelf.detailTable reloadData];
  842. //
  843. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  844. //
  845. //
  846. // }
  847. // else
  848. // {
  849. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  850. // }
  851. //
  852. //
  853. //
  854. // }];
  855. //
  856. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  857. ////
  858. //// NSDictionary* order_json = [RANetwork sign_Order:weakSelf.order_code path:img_url_up];
  859. ////
  860. //// dispatch_async(dispatch_get_main_queue(), ^{
  861. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  862. //// if([[order_json valueForKey:@"result"] intValue]==2)
  863. //// {
  864. ////
  865. ////#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  866. //// int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  867. //// for (int i = 0; i < count; i++) {
  868. //// NSString *key = [NSString stringWithFormat:@"section_%d",i];
  869. //// NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  870. //// NSString *type = [section objectForKey:@"type"];
  871. //// if ([type isEqualToString:@"sign_url"]) {
  872. //// [section setObject:img_url_down forKey:@"data"];
  873. //// [weakSelf.content_data setObject:section forKey:key];
  874. //// break;
  875. //// }
  876. //// }
  877. ////#endif
  878. ////
  879. ////#if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  880. //// int count = [[weakSelf.content_data objectForKey:@"count"] intValue];
  881. //// for (int i = 0; i < count; i++) {
  882. //// NSString *key = [NSString stringWithFormat:@"section_%d",i];
  883. //// NSMutableDictionary *section = [[weakSelf.content_data objectForKey:key] mutableCopy];
  884. //// NSString *type = [section objectForKey:@"type"];
  885. //// if ([type isEqualToString:@"sign_url"]) {
  886. //// [section setObject:img_url_down forKey:@"data"];
  887. //// [weakSelf.content_data setObject:section forKey:key];
  888. //// break;
  889. //// }
  890. //// }
  891. ////#endif
  892. ////
  893. ////#ifdef BUILD_HMLG
  894. //// [weakSelf.content_data setValue:img_url_down forKey:@"sign_url"];
  895. ////#endif
  896. //// //self.btnSign.enabled = false;
  897. //// [weakSelf.detailTable reloadData];
  898. ////
  899. //// [RAUtils message_alert:@"Successful." title:@"Signature" controller:weakSelf];
  900. ////
  901. ////
  902. //// }
  903. //// else
  904. //// {
  905. //// [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:weakSelf] ;
  906. //// }
  907. ////
  908. ////
  909. ////
  910. //// });
  911. //// });
  912. // }
  913. //
  914. //
  915. // }
  916. // else
  917. // {
  918. // dispatch_async(dispatch_get_main_queue(), ^{
  919. //
  920. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  921. // NSString *msg = [json valueForKey:@"err_msg"];
  922. // if (msg.length == 0) {
  923. // msg = [json objectForKey:@"msg"];
  924. // }
  925. //
  926. // [RAUtils message_alert:msg title:@"Upload Image" controller:weakSelf] ;
  927. // });
  928. // }
  929. //
  930. // } Progress:nil DecryptHandler:nil];
  931. // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
  932. // DebugLog(URL_UPLOAD_IMG);
  933. //
  934. // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  935. // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
  936. // } error:nil];
  937. //
  938. //
  939. // // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  940. // // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
  941. // // } error:nil];
  942. // //
  943. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  944. //
  945. //
  946. //
  947. // //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  948. //
  949. //
  950. //
  951. // //
  952. // NSProgress *progress = nil;
  953. //
  954. // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
  955. //
  956. // // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
  957. //
  958. //
  959. //
  960. //
  961. // if (error) {
  962. //
  963. // NSString* err_msg = [error localizedDescription];
  964. // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
  965. //
  966. //
  967. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  968. //
  969. // DebugLog(@"data string: %@",str);
  970. //
  971. // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
  972. //
  973. // } else {
  974. // DebugLog(@"response ");
  975. //
  976. //
  977. //
  978. // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
  979. //
  980. // // 再将NSData转为字符串
  981. // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  982. //
  983. // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  984. //
  985. // DebugLog(@"data string: %@",jsonStr);
  986. //
  987. // NSDictionary* json = responseObject;
  988. //
  989. // if([[json valueForKey:@"result"] intValue]==2)
  990. // {
  991. // NSString* img_url_down = json[@"img_url_aname"];
  992. // NSString* img_url_up = json[@"img_url"];
  993. //
  994. // {
  995. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Signature"];
  996. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  997. //
  998. // NSDictionary* order_json = [iSalesNetwork sign_Order:self.order_code path:img_url_up];
  999. //
  1000. // dispatch_async(dispatch_get_main_queue(), ^{
  1001. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1002. // if([[order_json valueForKey:@"result"] intValue]==2)
  1003. // {
  1004. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1005. // // appDelegate.order_code = self.order_code;
  1006. // // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1007. // //
  1008. // //
  1009. // // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1010. // //
  1011. // // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1012. // // [self.navigationController popViewControllerAnimated:false];
  1013. // //
  1014. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1015. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1016. // // if(self.selectOrder)
  1017. // // self.selectOrder(self.content_data);
  1018. //
  1019. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  1020. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1021. // for (int i = 0; i < count; i++) {
  1022. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1023. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1024. // NSString *type = [section objectForKey:@"type"];
  1025. // if ([type isEqualToString:@"sign_url"]) {
  1026. // [section setObject:img_url_down forKey:@"data"];
  1027. // [self.content_data setObject:section forKey:key];
  1028. // break;
  1029. // }
  1030. // }
  1031. //#endif
  1032. //
  1033. //#ifdef BUILD_HOMER
  1034. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1035. // for (int i = 0; i < count; i++) {
  1036. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1037. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1038. // NSString *type = [section objectForKey:@"type"];
  1039. // if ([type isEqualToString:@"sign_url"]) {
  1040. // [section setObject:img_url_down forKey:@"data"];
  1041. // [self.content_data setObject:section forKey:key];
  1042. // break;
  1043. // }
  1044. // }
  1045. //#endif
  1046. //#ifdef BUILD_GATIT
  1047. // int count = [[self.content_data objectForKey:@"count"] intValue];
  1048. // for (int i = 0; i < count; i++) {
  1049. // NSString *key = [NSString stringWithFormat:@"section_%d",i];
  1050. // NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  1051. // NSString *type = [section objectForKey:@"type"];
  1052. // if ([type isEqualToString:@"sign_url"]) {
  1053. // [section setObject:img_url_down forKey:@"data"];
  1054. // [self.content_data setObject:section forKey:key];
  1055. // break;
  1056. // }
  1057. // }
  1058. //#endif
  1059. //
  1060. //#ifdef BUILD_HMLG
  1061. // [self.content_data setValue:img_url_down forKey:@"sign_url"];
  1062. //#endif
  1063. // //self.btnSign.enabled = false;
  1064. // [self.detailTable reloadData];
  1065. //
  1066. // [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  1067. //
  1068. //
  1069. // }
  1070. // else
  1071. // {
  1072. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  1073. // }
  1074. //
  1075. //
  1076. //
  1077. // });
  1078. // });
  1079. // }
  1080. //
  1081. //
  1082. // }
  1083. // else
  1084. // {
  1085. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  1086. // }
  1087. //
  1088. //
  1089. //
  1090. //
  1091. //
  1092. //
  1093. // }
  1094. // // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1095. // }];
  1096. //
  1097. // [uploadTask resume];
  1098. }
  1099. }
  1100. - (IBAction)onSignOrderClick:(id)sender {
  1101. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1102. if (appDelegate.order_code.length > 0 && [self.order_code isEqualToString:appDelegate.order_code]) {
  1103. [self showSignaturePanel];
  1104. } else {
  1105. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"you need open the order first" preferredStyle:UIAlertControllerStyleAlert];
  1106. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1107. }];
  1108. [alertVC addAction:cancelAction];
  1109. __weak typeof(self) weakSelf = self;
  1110. UIAlertAction *openAction = [UIAlertAction actionWithTitle:@"Open" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1111. [self opentOrder:^{
  1112. [weakSelf showSignaturePanel];
  1113. }];
  1114. }];
  1115. [alertVC addAction:openAction];
  1116. [self presentViewController:alertVC animated:YES completion:nil];
  1117. }
  1118. }
  1119. - (void)showSignaturePanel {
  1120. __block UIImage* signimg=nil;
  1121. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:nil] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  1122. vc.onReturnImg = ^(UIImage* img)
  1123. {
  1124. signimg = img;
  1125. if(signimg!=nil)
  1126. [self upload_img:signimg];
  1127. };
  1128. [self.navigationController pushViewController:vc animated:NO];
  1129. }
  1130. - (void)opentOrder:(void(^)(void))completionBlk {
  1131. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Open Order" completion:^{
  1132. [RANetwork request_open_order:self.order_code completionHandler:^(NSMutableDictionary *result) {
  1133. NSDictionary* order_json = result;
  1134. [waitalert dismissViewControllerAnimated:YES completion:^{
  1135. if([[order_json valueForKey:@"result"] intValue]==2)
  1136. {
  1137. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1138. appDelegate.order_code = self.order_code;
  1139. appDelegate.order_status = self.order_status;
  1140. [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1141. appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1142. appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1143. // [self.navigationController popViewControllerAnimated:false];
  1144. #ifdef RA_NOTIFICATION
  1145. [ActiveViewController Notify:@"CartViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1146. #else
  1147. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1148. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1149. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1150. #endif
  1151. if (completionBlk) {
  1152. completionBlk();
  1153. }
  1154. // if(self.selectOrder)
  1155. // self.selectOrder(self.content_data);
  1156. }
  1157. else
  1158. {
  1159. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  1160. }
  1161. }];
  1162. }];
  1163. }];
  1164. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1165. //
  1166. // NSDictionary* order_json = [RANetwork open_Order:self.order_code];
  1167. //
  1168. // dispatch_async(dispatch_get_main_queue(), ^{
  1169. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1170. // if([[order_json valueForKey:@"result"] intValue]==2)
  1171. // {
  1172. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1173. // appDelegate.order_code = self.order_code;
  1174. // appDelegate.order_status = self.order_status;
  1175. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  1176. //
  1177. //
  1178. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  1179. //
  1180. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  1181. //
  1182. //// [self.navigationController popViewControllerAnimated:false];
  1183. //
  1184. //#ifdef RA_NOTIFICATION
  1185. // [ActiveViewController Notify:@"CartViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1186. //#else
  1187. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1188. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1189. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  1190. //#endif
  1191. //
  1192. // if (completionBlk) {
  1193. // completionBlk();
  1194. // }
  1195. //
  1196. //// if(self.selectOrder)
  1197. //// self.selectOrder(self.content_data);
  1198. // }
  1199. // else
  1200. // {
  1201. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  1202. // }
  1203. //
  1204. //
  1205. //
  1206. // });
  1207. // });
  1208. }
  1209. - (IBAction)onOpenOrderClick:(id)sender {
  1210. // get customer info
  1211. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to open order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1212. //block代码块取代了delegate
  1213. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1214. [self opentOrder:^{
  1215. [self.navigationController popViewControllerAnimated:false];
  1216. if(self.selectOrder)
  1217. self.selectOrder(self.content_data);
  1218. }];
  1219. }];
  1220. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1221. DebugLog(@"Cancel");
  1222. }];
  1223. [alertControl addAction:actionOne];
  1224. [alertControl addAction:alertthree];
  1225. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1226. [self presentViewController:alertControl animated:YES completion:nil];
  1227. }
  1228. - (void)didReceiveMemoryWarning {
  1229. [super didReceiveMemoryWarning];
  1230. // Dispose of any resources that can be recreated.
  1231. }
  1232. -(void) loaddata
  1233. {
  1234. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading"];
  1235. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  1236. // dispatch_async(dispatch_get_main_queue(), ^{
  1237. if(self.isrefreshing)
  1238. return;
  1239. self.detailTable.hidden = true;
  1240. self.label_net_err.hidden=true;
  1241. self.isrefreshing=true;
  1242. self.mum.center = self.view.center;
  1243. self.mum.hidden = false;
  1244. [self.mum startAnimating];
  1245. DebugLog(@"reloading...");
  1246. self.web_info_height=0;
  1247. self.web_moreinfo_height=0;
  1248. // self.content_data = nil;
  1249. self.btnOpen.enabled =false;
  1250. self.btnSign.enabled = false;
  1251. self.btnCopy.enabled =false;
  1252. self.btnPDF.enabled =false;
  1253. self.btnRelease.enabled =false;
  1254. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  1255. [params setValue:self.orderid forKey:@"orderId"];
  1256. if (self.erpSerialNo) {
  1257. [params setValue:self.erpSerialNo forKey:@"erp_order_serial_no"];
  1258. }
  1259. [RANetwork request_orderdetail:params completionHandler:^(NSMutableDictionary *result) {
  1260. NSDictionary* order_json = result;
  1261. [waitalert dismissViewControllerAnimated:YES completion:^{
  1262. [self.mum stopAnimating];
  1263. if([[order_json valueForKey:@"result"] intValue]==2)
  1264. {
  1265. self.detailTable.hidden = false;
  1266. self.content_data = [order_json mutableCopy];
  1267. }
  1268. else {
  1269. self.content_data = nil;
  1270. if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1271. {
  1272. self.label_net_err.hidden=false;
  1273. self.detailTable.hidden=true;
  1274. }
  1275. else
  1276. {
  1277. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  1278. }
  1279. }
  1280. bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
  1281. if(web_order)
  1282. self.btnCopy.enabled = false;
  1283. else
  1284. self.btnCopy.enabled = true;
  1285. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1286. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1287. int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  1288. if(model_count>0)/*&& ! appDelegate.offline_mode*/
  1289. {
  1290. if(appDelegate.user_type== USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1291. self.btnPDF.enabled =true;
  1292. else
  1293. {
  1294. // || appDelegate.user_type==USER_ROLE_CUSTOMER
  1295. if(self.is_shoporder)
  1296. {
  1297. if(status_code==1||status_code==30)
  1298. self.btnPDF.enabled =true;
  1299. }
  1300. else
  1301. {
  1302. if(status_code==2)
  1303. self.btnPDF.enabled =true;
  1304. }
  1305. }
  1306. }
  1307. // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1308. // NSString* status = [self.content_data valueForKey:@"order_status"];
  1309. NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  1310. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1311. if(status_code==1)//[status isEqualToString:@"Saved Order"])
  1312. {
  1313. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1314. //
  1315. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1316. BOOL condition = offline_edit;
  1317. #ifdef OFFLINE_MODE
  1318. condition = condition || appDelegate.offline_mode==false;
  1319. #else
  1320. condition = YES;
  1321. #endif
  1322. if(condition)
  1323. {
  1324. self.btnOpen.enabled =true;
  1325. self.btnSign.enabled = true;
  1326. }
  1327. // if([lock_user isEqualToString:appDelegate.user])
  1328. // {
  1329. // self.btnCommit.enabled =true;
  1330. // }
  1331. // else
  1332. // self.btnCommit.enabled =false;
  1333. }
  1334. else
  1335. if(status_code==0)//[status isEqualToString:@"Quote Saved"])
  1336. {
  1337. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1338. //
  1339. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1340. BOOL condition = offline_edit;
  1341. #ifdef OFFLINE_MODE
  1342. condition = condition || appDelegate.offline_mode==false;
  1343. #else
  1344. condition = YES;
  1345. #endif
  1346. if (condition)
  1347. {
  1348. self.btnOpen.enabled =true;
  1349. self.btnSign.enabled = true;
  1350. }
  1351. // self.btnCommit.enabled =false;
  1352. }
  1353. BOOL lock_condition_1 = [lock_user isEqualToString:appDelegate.user];
  1354. BOOL lock_condition_2 = false;
  1355. #ifdef OFFLINE_MODE
  1356. lock_condition_1 = !appDelegate.offline_mode && lock_condition_1;
  1357. lock_condition_2 = appDelegate.offline_mode && [self.order_code isEqualToString:appDelegate.order_code];
  1358. #endif
  1359. if((lock_condition_1 || lock_condition_2)&& (status_code==1||status_code==0))
  1360. {
  1361. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1362. self.btnRelease.enabled =true;
  1363. }
  1364. else
  1365. {
  1366. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1367. self.btnRelease.enabled =false;
  1368. }
  1369. [self.detailTable reloadData];
  1370. self.isrefreshing=false;
  1371. if (self.order_code == nil) {
  1372. self.btnCopy.enabled = false;
  1373. } else {
  1374. self.btnCopy.enabled = true;
  1375. }
  1376. }];
  1377. }];
  1378. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1379. //
  1380. //
  1381. // NSDictionary* order_json = [RANetwork request_OrderDetail:params];
  1382. //
  1383. // dispatch_async(dispatch_get_main_queue(), ^{
  1384. //
  1385. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1386. // [self.mum stopAnimating];
  1387. // if([[order_json valueForKey:@"result"] intValue]==2)
  1388. // {
  1389. // self.detailTable.hidden = false;
  1390. // self.content_data = [order_json mutableCopy];
  1391. //
  1392. //
  1393. // }
  1394. // else {
  1395. // self.content_data = nil;
  1396. // if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  1397. // {
  1398. // self.label_net_err.hidden=false;
  1399. // self.detailTable.hidden=true;
  1400. // }
  1401. // else
  1402. // {
  1403. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  1404. // }
  1405. // }
  1406. //
  1407. // bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
  1408. // if(web_order)
  1409. // self.btnCopy.enabled = false;
  1410. // else
  1411. // self.btnCopy.enabled = true;
  1412. // int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1413. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1414. // int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  1415. // if(model_count>0)/*&& ! appDelegate.offline_mode*/
  1416. // {
  1417. // if(appDelegate.user_type== USER_ROLE_EMPLOYEE || (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer))
  1418. // self.btnPDF.enabled =true;
  1419. // else
  1420. // {
  1421. // // || appDelegate.user_type==USER_ROLE_CUSTOMER
  1422. // if(self.is_shoporder)
  1423. // {
  1424. // if(status_code==1||status_code==30)
  1425. // self.btnPDF.enabled =true;
  1426. //
  1427. // }
  1428. // else
  1429. // {
  1430. // if(status_code==2)
  1431. // self.btnPDF.enabled =true;
  1432. // }
  1433. // }
  1434. // }
  1435. // // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1436. //
  1437. //// NSString* status = [self.content_data valueForKey:@"order_status"];
  1438. //
  1439. // NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  1440. //
  1441. // bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1442. // if(status_code==1)//[status isEqualToString:@"Saved Order"])
  1443. // {
  1444. // // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1445. // //
  1446. // // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1447. //
  1448. // BOOL condition = offline_edit;
  1449. //#ifdef OFFLINE_MODE
  1450. // condition = condition || appDelegate.offline_mode==false;
  1451. //#else
  1452. // condition = YES;
  1453. //#endif
  1454. // if(condition)
  1455. // {
  1456. // self.btnOpen.enabled =true;
  1457. //
  1458. // self.btnSign.enabled = true;
  1459. // }
  1460. // // if([lock_user isEqualToString:appDelegate.user])
  1461. // // {
  1462. // // self.btnCommit.enabled =true;
  1463. // // }
  1464. // // else
  1465. // // self.btnCommit.enabled =false;
  1466. // }
  1467. // else
  1468. // if(status_code==0)//[status isEqualToString:@"Quote Saved"])
  1469. // {
  1470. // // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1471. // //
  1472. // // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1473. //
  1474. // BOOL condition = offline_edit;
  1475. //#ifdef OFFLINE_MODE
  1476. // condition = condition || appDelegate.offline_mode==false;
  1477. //#else
  1478. // condition = YES;
  1479. //#endif
  1480. // if (condition)
  1481. // {
  1482. // self.btnOpen.enabled =true;
  1483. //
  1484. // self.btnSign.enabled = true;
  1485. // }
  1486. // // self.btnCommit.enabled =false;
  1487. // }
  1488. // BOOL lock_condition_1 = [lock_user isEqualToString:appDelegate.user];
  1489. // BOOL lock_condition_2 = false;
  1490. //#ifdef OFFLINE_MODE
  1491. // lock_condition_1 = !appDelegate.offline_mode && lock_condition_1;
  1492. // lock_condition_2 = appDelegate.offline_mode && [self.order_code isEqualToString:appDelegate.order_code];
  1493. //#endif
  1494. //
  1495. // if((lock_condition_1 || lock_condition_2)&& (status_code==1||status_code==0))
  1496. // {
  1497. // // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1498. //
  1499. //
  1500. // self.btnRelease.enabled =true;
  1501. // }
  1502. // else
  1503. // {
  1504. //
  1505. //
  1506. // // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  1507. // self.btnRelease.enabled =false;
  1508. // }
  1509. //
  1510. // [self.detailTable reloadData];
  1511. // self.isrefreshing=false;
  1512. //
  1513. // if (self.order_code == nil) {
  1514. // self.btnCopy.enabled = false;
  1515. // } else {
  1516. // self.btnCopy.enabled = true;
  1517. // }
  1518. //
  1519. // });
  1520. //
  1521. // });
  1522. // });
  1523. }];
  1524. }
  1525. - (void)viewWillAppear:(BOOL)animated
  1526. {
  1527. [super viewWillAppear:animated];
  1528. // if(appDelegate.can_submit_order)
  1529. // {
  1530. //
  1531. //
  1532. // [self.btnCommit setImage:[UIImage imageNamed:@"commit"]];
  1533. // self.btnCommit.enabled = true;
  1534. // }
  1535. // else
  1536. // {
  1537. // [self.btnCommit setImage:nil];
  1538. // self.btnCommit.enabled = false;
  1539. // }
  1540. //
  1541. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1542. }
  1543. - (IBAction)imgbtnClicked:(UIButton*)sender {
  1544. // 这里有问题,npd 里order 提交后,product id 为空,暂时屏蔽掉
  1545. return;
  1546. // 以下为屏蔽前的代码
  1547. //
  1548. // UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  1549. //
  1550. // NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  1551. //
  1552. //// if(indexPath.section!=1)
  1553. //// return ;
  1554. // // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  1555. // NSDictionary * item_json = self.content_data[[NSString stringWithFormat:@"section_%ld",(long)indexPath.section]][@"data"][[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1556. //// NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1557. //
  1558. // NSString* product_id = [item_json valueForKey:@"product_id"];
  1559. //
  1560. // DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1561. // // dvc
  1562. //
  1563. // dvc.product_id=product_id;
  1564. // dvc.category_id=nil;
  1565. // dvc.ispush=true;
  1566. // [dvc reload];
  1567. // [self.navigationController pushViewController:dvc animated:true];
  1568. }
  1569. /*
  1570. #pragma mark - Navigation
  1571. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1572. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1573. // Get the new view controller using [segue destinationViewController].
  1574. // Pass the selected object to the new view controller.
  1575. }
  1576. */
  1577. #pragma mark - Table view data source
  1578. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1579. {
  1580. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1581. // if([item_json objectForKey:@"combine"] == nil)
  1582. // {
  1583. // return 120;
  1584. // }
  1585. // else
  1586. // return 150;
  1587. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1588. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1589. NSDictionary *data = [section_item objectForKey:@"data"];
  1590. NSString *type = [section_item objectForKey:@"type"];
  1591. if ([type isEqualToString:@"order_info"]) {
  1592. float height= self.web_info_height;
  1593. if(height==0)
  1594. height=DEF_TABLE_HEIGHT;
  1595. return height;
  1596. } else if ([type isEqualToString:@"sign_url"]) {
  1597. return 148;
  1598. } else if ([type isEqualToString:@"more_order_info"]) {
  1599. float height= self.web_moreinfo_height;
  1600. if(height==0)
  1601. height=DEF_TABLE_HEIGHT;
  1602. return height;
  1603. } else if ([type isEqualToString:@"sub_order"]) {
  1604. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1605. NSString *item_type = [item objectForKey:@"type"];
  1606. if ([item_type isEqualToString:@"pick_info"]) {
  1607. return 218;
  1608. } else {
  1609. NSString* notes =[item valueForKey:@"note"];
  1610. if(notes.length>0)
  1611. {
  1612. return 190;
  1613. }
  1614. else
  1615. return 162;
  1616. }
  1617. } else if ([type isEqualToString:@"price_info"]) {
  1618. return 44;
  1619. }
  1620. #endif
  1621. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1622. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1623. NSDictionary *data = [section_item objectForKey:@"data"];
  1624. NSString *type = [section_item objectForKey:@"type"];
  1625. if ([type isEqualToString:@"order_info"]) {
  1626. float height= self.web_info_height;
  1627. if(height==0)
  1628. height=DEF_TABLE_HEIGHT;
  1629. return height;
  1630. } else if ([type isEqualToString:@"sign_url"]) {
  1631. return 148;
  1632. } else if ([type isEqualToString:@"more_order_info"]) {
  1633. float height= self.web_moreinfo_height;
  1634. if(height==0)
  1635. height=DEF_TABLE_HEIGHT;
  1636. return height;
  1637. } else if ([type isEqualToString:@"sub_order"]) {
  1638. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1639. NSString *item_type = [item objectForKey:@"type"];
  1640. if ([item_type isEqualToString:@"pick_info"]) {
  1641. return 218;
  1642. } else {
  1643. NSString* notes =[item valueForKey:@"note"];
  1644. if(notes.length>0)
  1645. {
  1646. return 190;
  1647. }
  1648. else
  1649. return 162;
  1650. }
  1651. } else if ([type isEqualToString:@"price_info"]) {
  1652. return 44;
  1653. }
  1654. #endif
  1655. #ifdef BUILD_HMLG
  1656. switch (indexPath.section) {
  1657. case 0:
  1658. {
  1659. if(indexPath.row==0)
  1660. {
  1661. float height= self.web_info_height;
  1662. if(height==0)
  1663. height=DEF_TABLE_HEIGHT;
  1664. return height;
  1665. }
  1666. else
  1667. return 148;
  1668. }
  1669. break;
  1670. case 1:
  1671. {
  1672. float height= self.web_moreinfo_height;
  1673. if(height==0)
  1674. height=DEF_TABLE_HEIGHT;
  1675. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  1676. //wait(1000);
  1677. return height;
  1678. }
  1679. break;
  1680. case 2:
  1681. {
  1682. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1683. NSString* notes =[item_json valueForKey:@"note"];
  1684. if(notes.length>0)
  1685. {
  1686. return 190;
  1687. }
  1688. else
  1689. return 162;
  1690. }
  1691. case 3:
  1692. return 44;
  1693. default:
  1694. break;
  1695. }
  1696. #endif
  1697. return 44;
  1698. }
  1699. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1700. //{
  1701. // return 0;
  1702. //}
  1703. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1704. //{
  1705. // return 0;
  1706. //}
  1707. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1708. //{
  1709. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1710. // return myView;
  1711. //
  1712. //}
  1713. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1714. //{
  1715. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1716. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1717. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  1718. //// titleLabel.textColor=[UIColor whiteColor];
  1719. //// titleLabel.backgroundColor = [UIColor clearColor];
  1720. //// if(section==0)
  1721. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  1722. //// else
  1723. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1724. //// [titleLabel sizeToFit];
  1725. //// [myView addSubview:titleLabel];
  1726. ////
  1727. // return myView;
  1728. //}
  1729. //
  1730. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1731. {
  1732. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1733. if(value==nil)
  1734. value=@"";
  1735. unsigned long color = strtoul([value UTF8String],0,16);
  1736. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1737. // myView.backgroundColor = UIColorFromRGB(0x996633);;
  1738. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1739. // myView.layer.masksToBounds = false;
  1740. //添加四个边阴影
  1741. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1742. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1743. myView.layer.shadowOpacity = 0.5;
  1744. myView.layer.shadowRadius = 2.0;
  1745. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1746. NSString*labeltitle = nil;
  1747. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1748. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1749. NSString *title = [section_item objectForKey:@"title"];
  1750. labeltitle = title;
  1751. if ([title isEqualToString:@"More Info"]) {
  1752. NSString* btntitle=nil ;
  1753. if(self.showMore)
  1754. {
  1755. btntitle=@"Hide";
  1756. }
  1757. else{
  1758. btntitle=@"Show";
  1759. }
  1760. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1761. btn.tag=section;
  1762. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1763. [btn setTitle:btntitle forState:UIControlStateNormal];
  1764. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1765. [myView addSubview:btn];
  1766. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1767. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1768. NSString *normalTitle = @"Show";
  1769. NSString *selectedTitle = @"Hide";
  1770. if (item_switch == YES) {
  1771. normalTitle = @"Hide";
  1772. selectedTitle = @"Show";
  1773. }
  1774. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1775. btn.tag=section;
  1776. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1777. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1778. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1779. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1780. [myView addSubview:btn];
  1781. }
  1782. #endif
  1783. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1784. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1785. NSString *title = [section_item objectForKey:@"title"];
  1786. labeltitle = title;
  1787. if ([title isEqualToString:@"More Info"]) {
  1788. NSString* btntitle=nil ;
  1789. if(self.showMore)
  1790. {
  1791. btntitle=@"Hide";
  1792. }
  1793. else{
  1794. btntitle=@"Show";
  1795. }
  1796. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1797. btn.tag=section;
  1798. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1799. [btn setTitle:btntitle forState:UIControlStateNormal];
  1800. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1801. [myView addSubview:btn];
  1802. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1803. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1804. NSString *normalTitle = @"Show";
  1805. NSString *selectedTitle = @"Hide";
  1806. if (item_switch == YES) {
  1807. normalTitle = @"Hide";
  1808. selectedTitle = @"Show";
  1809. }
  1810. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1811. btn.tag=section;
  1812. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1813. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1814. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1815. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1816. [myView addSubview:btn];
  1817. }
  1818. #endif
  1819. #ifdef BUILD_HMLG
  1820. switch (section) {
  1821. case 0:
  1822. labeltitle= @"Order Info";
  1823. break;
  1824. case 1:
  1825. {
  1826. labeltitle= @"More Info";
  1827. NSString* btntitle=nil ;
  1828. if(self.showMore)
  1829. {
  1830. btntitle=@"Hide";
  1831. // [section setValue:@"false" forKey:@"hide"];
  1832. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  1833. }
  1834. else{
  1835. btntitle=@"Show";
  1836. }
  1837. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1838. btn.tag=section;
  1839. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1840. [btn setTitle:btntitle forState:UIControlStateNormal];
  1841. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1842. [myView addSubview:btn];
  1843. }
  1844. break;
  1845. case 2:{
  1846. labeltitle= @"Models";
  1847. NSString* btntitle=nil ;
  1848. if(self.showModels)
  1849. {
  1850. btntitle=@"Hide";
  1851. }
  1852. else{
  1853. btntitle=@"Show";
  1854. }
  1855. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1856. btn.tag=section;
  1857. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1858. [btn setTitle:btntitle forState:UIControlStateNormal];
  1859. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1860. [myView addSubview:btn];
  1861. }
  1862. break;
  1863. case 3:
  1864. labeltitle= @"Price Info";
  1865. default:
  1866. break;
  1867. }
  1868. #endif
  1869. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  1870. titlelabel.textColor=UIColorFromRGB(color);;
  1871. titlelabel.backgroundColor = [UIColor clearColor];
  1872. titlelabel.text=NSLocalizedString(labeltitle, nil);
  1873. [titlelabel sizeToFit];
  1874. titlelabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  1875. [myView addSubview:titlelabel];
  1876. //
  1877. return myView;
  1878. }
  1879. #pragma mark - hide section button clicked
  1880. - (void)HideSction:(UIButton *)sender {
  1881. /*
  1882. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
  1883. bool hide = [[section valueForKey:@"hide"]boolValue];
  1884. if(hide)
  1885. {
  1886. [section setValue:@"false" forKey:@"hide"];
  1887. [sender setTitle:@"Show" forState:UIControlStateNormal];
  1888. }
  1889. else{
  1890. [section setValue:@"true" forKey:@"hide"];
  1891. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1892. }
  1893. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
  1894. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1895. */
  1896. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1897. NSUInteger section = sender.tag;
  1898. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1899. NSString *title = [section_item objectForKey:@"title"];
  1900. if ([title isEqualToString:@"More Info"]) {
  1901. self.showMore = !self.showMore;
  1902. NSRange range = NSMakeRange(section, 1);
  1903. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1904. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1905. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1906. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1907. if (item_switch == YES) {
  1908. [section_item setObject:@(NO) forKey:@"switch"];
  1909. } else {
  1910. [section_item setObject:@(YES) forKey:@"switch"];
  1911. }
  1912. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1913. sender.selected = !sender.selected;
  1914. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1915. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1916. }
  1917. #endif
  1918. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1919. NSUInteger section = sender.tag;
  1920. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1921. NSString *title = [section_item objectForKey:@"title"];
  1922. if ([title isEqualToString:@"More Info"]) {
  1923. self.showMore = !self.showMore;
  1924. NSRange range = NSMakeRange(section, 1);
  1925. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1926. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1927. } else if ([title containsString:@"Models"] || [title containsString:@"Invoice#"]) {
  1928. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1929. if (item_switch == YES) {
  1930. [section_item setObject:@(NO) forKey:@"switch"];
  1931. } else {
  1932. [section_item setObject:@(YES) forKey:@"switch"];
  1933. }
  1934. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1935. sender.selected = !sender.selected;
  1936. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1937. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1938. }
  1939. #endif
  1940. #ifdef BUILD_HMLG
  1941. switch (sender.tag) {
  1942. case 0:{
  1943. }
  1944. break;
  1945. case 1:{
  1946. self.showMore=!self.showMore;
  1947. NSRange range = NSMakeRange(1, 1);
  1948. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1949. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1950. }
  1951. break;
  1952. case 2:{
  1953. self.showModels = !self.showModels;
  1954. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:2];
  1955. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1956. }
  1957. break;
  1958. default:
  1959. break;
  1960. }
  1961. #endif
  1962. }
  1963. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1964. switch (section) {
  1965. case 0:
  1966. return @"Order Info";
  1967. break;
  1968. case 1:
  1969. return @"More Info";
  1970. break;
  1971. case 2:
  1972. return @"Models";
  1973. case 3:
  1974. return @"Price Info";
  1975. default:
  1976. break;
  1977. }
  1978. return nil;
  1979. }
  1980. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1981. {
  1982. if(self.content_data==nil)
  1983. return 0;
  1984. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1985. return [[self.content_data objectForKey:@"count"] integerValue];
  1986. #endif
  1987. //#ifdef BUILD_USAI
  1988. // return [[self.content_data objectForKey:@"count"] integerValue];
  1989. //#endif
  1990. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1991. return [[self.content_data objectForKey:@"count"] integerValue];
  1992. #endif
  1993. #ifdef BUILD_HMLG
  1994. return 4;
  1995. #endif
  1996. return 4;
  1997. }
  1998. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1999. {
  2000. return 33;
  2001. }
  2002. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2003. {
  2004. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2005. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  2006. NSDictionary *data = [section_item objectForKey:@"data"];
  2007. NSString *section_type = [section_item objectForKey:@"type"];
  2008. if ([section_type isEqualToString:@"sub_order"]) {
  2009. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  2010. if (item_switch == YES) {
  2011. return [[data objectForKey:@"count"] integerValue];
  2012. } else {
  2013. return 0;
  2014. }
  2015. } else if ([section_type isEqualToString:@"order_info"]){
  2016. if (self.showModels) {
  2017. return 1;
  2018. } else {
  2019. return 0;
  2020. }
  2021. } else if ([section_type isEqualToString:@"sign_url"]){
  2022. return 1;
  2023. } else if ([section_type isEqualToString:@"more_order_info"]){
  2024. if(self.showMore)
  2025. return 1;
  2026. else
  2027. return 0;
  2028. }else if ([section_type isEqualToString:@"price_info"]){
  2029. return [[data objectForKey:@"count"] integerValue];
  2030. }
  2031. return 0;
  2032. #endif
  2033. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2034. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  2035. NSDictionary *data = [section_item objectForKey:@"data"];
  2036. NSString *section_type = [section_item objectForKey:@"type"];
  2037. if ([section_type isEqualToString:@"sub_order"]) {
  2038. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  2039. if (item_switch == YES) {
  2040. return [[data objectForKey:@"count"] integerValue];
  2041. } else {
  2042. return 0;
  2043. }
  2044. } else if ([section_type isEqualToString:@"order_info"]){
  2045. if (self.showModels) {
  2046. return 1;
  2047. } else {
  2048. return 0;
  2049. }
  2050. } else if ([section_type isEqualToString:@"sign_url"]){
  2051. return 1;
  2052. } else if ([section_type isEqualToString:@"more_order_info"]){
  2053. if(self.showMore)
  2054. return 1;
  2055. else
  2056. return 0;
  2057. }else if ([section_type isEqualToString:@"price_info"]){
  2058. return [[data objectForKey:@"count"] integerValue];
  2059. }
  2060. return 0;
  2061. #endif
  2062. #ifdef BUILD_HMLG
  2063. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2064. if(section==0)
  2065. return 2;
  2066. if(section==1)
  2067. {
  2068. if(self.showMore)
  2069. return 1;
  2070. else
  2071. return 0;
  2072. }
  2073. if(section==2)
  2074. {
  2075. if (self.showModels) {
  2076. int count =[[self.content_data valueForKey:@"model_count"] intValue];
  2077. return count;
  2078. } else {
  2079. return 0;
  2080. }
  2081. }
  2082. if(section==3) {
  2083. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2084. return 6;
  2085. #endif
  2086. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2087. return 6;
  2088. #endif
  2089. #ifdef BUILD_HMLG
  2090. return 4;
  2091. #endif
  2092. }
  2093. #endif
  2094. return 0;
  2095. }
  2096. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2097. {
  2098. UIApplication * app = [UIApplication sharedApplication];
  2099. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2100. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  2101. /**
  2102. * ver1.90
  2103. */
  2104. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  2105. NSString *type = [section objectForKey:@"type"];
  2106. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  2107. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2108. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2109. cell.html = nil;
  2110. cell.wkwebview.tag = indexPath.section;
  2111. cell.wkwebview.navigationDelegate = self;
  2112. // cell.webView.scrollView.contentSize.height = 0;
  2113. cell.wkwebview.scrollView.bounces=NO;
  2114. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2115. CGSize size= cell.wkwebview.scrollView.contentSize;
  2116. size.height=10;
  2117. cell.wkwebview.scrollView.contentSize=size;
  2118. cell.backgroundColor = [UIColor whiteColor];
  2119. cell.wkwebview.userInteractionEnabled = YES;
  2120. cell.html =[section valueForKey:@"data"];
  2121. NSLog(@"webview loadHTMLString 0");
  2122. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2123. NSLog(@"webview loadHTMLString 1");
  2124. return cell;
  2125. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  2126. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2127. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2128. NSString* img_url = [section valueForKey:@"data"];
  2129. cell.sign_img.userInteractionEnabled = NO;
  2130. __block BOOL hasTapGesture = NO;
  2131. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2132. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2133. hasTapGesture = YES;
  2134. *stop = YES;
  2135. }
  2136. }];
  2137. if (!hasTapGesture) {
  2138. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2139. [cell.sign_img addGestureRecognizer:signatureTap];
  2140. }
  2141. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2142. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2143. if(status_code==1) {
  2144. BOOL condition = offline_edit;
  2145. #ifdef OFFLINE_MODE
  2146. condition = condition || appDelegate.offline_mode==false;
  2147. #else
  2148. condition = YES;
  2149. #endif
  2150. if (condition)
  2151. {
  2152. cell.sign_img.userInteractionEnabled = YES;
  2153. }
  2154. }
  2155. else if(status_code==0) {
  2156. BOOL condition = offline_edit;
  2157. #ifdef OFFLINE_MODE
  2158. condition = condition || appDelegate.offline_mode==false;
  2159. #else
  2160. condition = YES;
  2161. #endif
  2162. if (condition)
  2163. {
  2164. cell.sign_img.userInteractionEnabled = YES;
  2165. }
  2166. }
  2167. NSString* file_name=[img_url lastPathComponent];
  2168. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2169. if(img_data!=nil)
  2170. {
  2171. UIImage * img =[UIImage imageWithData:img_data];
  2172. cell.sign_img.image=img ;
  2173. }
  2174. else
  2175. {
  2176. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2177. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2178. dispatch_async(dispatch_get_main_queue(), ^{
  2179. if(downloadimg_data!=nil)
  2180. {
  2181. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2182. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2183. cell.sign_img.image=img ;
  2184. }
  2185. else {
  2186. if (cell.sign_img.userInteractionEnabled) {
  2187. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2188. } else {
  2189. cell.sign_img.image = nil;
  2190. }
  2191. }
  2192. });
  2193. });
  2194. }
  2195. cell.backgroundColor = [UIColor whiteColor];
  2196. return cell;
  2197. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  2198. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2199. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2200. cell.wkwebview.tag = indexPath.section;
  2201. cell.wkwebview.navigationDelegate = self;
  2202. // cell.webView.scrollView.contentSize.height = 0;
  2203. cell.wkwebview.scrollView.bounces=NO;
  2204. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2205. CGSize size= cell.wkwebview.scrollView.contentSize;
  2206. size.height=10;
  2207. cell.wkwebview.scrollView.contentSize=size;
  2208. NSLog(@"webview loadHTMLString 3");
  2209. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2210. NSLog(@"webview loadHTMLString 4");
  2211. cell.backgroundColor = [UIColor whiteColor];
  2212. return cell;
  2213. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  2214. NSDictionary *data = [section objectForKey:@"data"];
  2215. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2216. NSString *item_type = [item objectForKey:@"type"];
  2217. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  2218. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  2219. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2220. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  2221. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  2222. NSString *track_number = [item objectForKey:@"tracking_number"];
  2223. NSString *status = [item objectForKey:@"status"];
  2224. cell.track_number_lb.text = track_number;
  2225. cell.status_lb.text = status;
  2226. cell.carrier_lb.text = carrier;
  2227. cell.url_lb.text = web_url;
  2228. return cell;
  2229. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  2230. NSString *CellIdentifier = @"OrderDetailModelCell";
  2231. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2232. NSDictionary * item_json = item;
  2233. // int count = [[item_json valueForKey:@"count"] intValue];
  2234. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2235. cell.bundle_item=combine_json;
  2236. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2237. if (cell.masterBtn != nil) {
  2238. if (master_json == nil) {
  2239. cell.masterBtn.hidden = YES;
  2240. } else{
  2241. cell.masterBtn.hidden = NO;
  2242. cell.master_items = master_json;
  2243. }
  2244. }
  2245. double dprice=0.0;
  2246. if(cell.bundle_item!=nil)
  2247. {
  2248. int citem=0;
  2249. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2250. for(int bc=0;bc<bcount;bc++)
  2251. {
  2252. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2253. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2254. citem+= modulus;
  2255. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2256. dprice+= uprice*modulus;
  2257. }
  2258. if(citem==1)
  2259. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2260. else
  2261. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2262. cell.buttonBundle.hidden = NO;
  2263. }
  2264. else
  2265. {
  2266. cell.buttonBundle.hidden = YES;
  2267. }
  2268. NSString* img_url = [item_json valueForKey:@"img"];
  2269. NSString* description = [item_json valueForKey:@"Item Number"];
  2270. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2271. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2272. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2273. NSString* qty = [item_json valueForKey:@"QTY"];
  2274. NSString* status = [item_json valueForKey:@"order_item_status"];
  2275. NSString* notes = [item_json valueForKey:@"note"];
  2276. if(notes.length>0)
  2277. {
  2278. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2279. }
  2280. else
  2281. cell.noteLabel.text = nil;
  2282. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2283. {
  2284. }
  2285. else
  2286. {
  2287. unitprice=nil;
  2288. origin_price=nil;
  2289. subtotal=nil;
  2290. }
  2291. float duprice = [unitprice floatValue];
  2292. float dsubtotal = (duprice+dprice)*[qty intValue];
  2293. cell.descriptionLabel.text=description;
  2294. if(dprice>0)
  2295. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2296. else
  2297. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2298. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2299. cell.qtyLabel.text = qty;
  2300. cell.statusLabel.text = status;
  2301. cell.labelOldPrice.text = origin_price;
  2302. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2303. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2304. cell.labelDiscount.text = discountstr;
  2305. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2306. if(isfree)
  2307. {
  2308. cell.labelOldPrice.hidden = false;
  2309. cell.labelOldPrice.textColor = [UIColor redColor];
  2310. cell.labelOldPrice.text=@"Free";
  2311. cell.labelOldPrice.hideline = true;
  2312. cell.labelDiscount.hidden = true;
  2313. }
  2314. else
  2315. {
  2316. cell.labelOldPrice.textColor = [UIColor blackColor];
  2317. cell.labelOldPrice.hideline = false;
  2318. if(discount==0)
  2319. {
  2320. cell.labelOldPrice.hidden = true;
  2321. cell.labelDiscount.hidden = true;
  2322. }
  2323. else
  2324. {
  2325. cell.labelOldPrice.hidden = false;
  2326. cell.labelDiscount.hidden = false;
  2327. }
  2328. }
  2329. // Button 设置了大小约束,Size就不会随内容变化
  2330. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2331. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2332. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2333. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2334. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2335. if (![cell.imageName isEqualToString:img_url]) {
  2336. cell.imageName = img_url;
  2337. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2338. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2339. NSString* file_name=[img_url lastPathComponent];
  2340. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2341. if(img_data!=nil)
  2342. {
  2343. UIImage * img =[UIImage imageWithData:img_data];
  2344. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2345. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2346. }
  2347. else
  2348. {
  2349. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2350. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2351. dispatch_async(dispatch_get_main_queue(), ^{
  2352. if(downloadimg_data!=nil)
  2353. {
  2354. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2355. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2356. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2357. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2358. }
  2359. else
  2360. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2361. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2362. });
  2363. });
  2364. }
  2365. }
  2366. cell.backgroundColor = [UIColor whiteColor];
  2367. return cell;
  2368. }
  2369. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  2370. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2371. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2372. NSDictionary *data = [section objectForKey:@"data"];
  2373. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2374. NSString *title = [item objectForKey:@"title"];
  2375. NSString *value = [item objectForKey:@"value"];
  2376. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  2377. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2378. {
  2379. }
  2380. else
  2381. {
  2382. value=nil;
  2383. }
  2384. }
  2385. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  2386. cell.priceLabel.text = value;
  2387. cell.backgroundColor = [UIColor whiteColor];
  2388. return cell;
  2389. }
  2390. #endif
  2391. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  2392. /**
  2393. * ver1.90
  2394. */
  2395. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  2396. NSString *type = [section objectForKey:@"type"];
  2397. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  2398. // NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2399. // OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2400. //
  2401. //
  2402. //
  2403. //
  2404. //
  2405. // cell.webview.tag = indexPath.section;
  2406. //
  2407. // cell.webview.delegate = self;
  2408. // // cell.webView.scrollView.contentSize.height = 0;
  2409. // cell.webview.scrollView.bounces=NO;
  2410. // cell.webview.scrollView.directionalLockEnabled = true;
  2411. // CGSize size= cell.webview.scrollView.contentSize;
  2412. // size.height=10;
  2413. // cell.webview.scrollView.contentSize=size;
  2414. //
  2415. // [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2416. //
  2417. // cell.backgroundColor = [UIColor whiteColor];
  2418. // return cell;
  2419. //
  2420. //
  2421. //
  2422. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2423. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2424. cell.html = nil;
  2425. cell.wkwebview.tag = indexPath.section;
  2426. cell.wkwebview.navigationDelegate = self;
  2427. // cell.webView.scrollView.contentSize.height = 0;
  2428. cell.wkwebview.scrollView.bounces=NO;
  2429. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2430. CGSize size= cell.wkwebview.scrollView.contentSize;
  2431. size.height=10;
  2432. cell.wkwebview.scrollView.contentSize=size;
  2433. cell.backgroundColor = [UIColor whiteColor];
  2434. cell.wkwebview.userInteractionEnabled = YES;
  2435. cell.html =[section valueForKey:@"data"];
  2436. NSLog(@"webview loadHTMLString 0");
  2437. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2438. NSLog(@"webview loadHTMLString 1");
  2439. return cell;
  2440. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  2441. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2442. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2443. NSString* img_url = [section valueForKey:@"data"];
  2444. cell.sign_img.userInteractionEnabled = NO;
  2445. __block BOOL hasTapGesture = NO;
  2446. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2447. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2448. hasTapGesture = YES;
  2449. *stop = YES;
  2450. }
  2451. }];
  2452. if (!hasTapGesture) {
  2453. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2454. [cell.sign_img addGestureRecognizer:signatureTap];
  2455. }
  2456. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2457. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2458. if(status_code==1) {
  2459. BOOL condition = offline_edit;
  2460. #ifdef OFFLINE_MODE
  2461. condition = condition || appDelegate.offline_mode==false;
  2462. #else
  2463. condition = YES;
  2464. #endif
  2465. if (condition)
  2466. {
  2467. cell.sign_img.userInteractionEnabled = YES;
  2468. }
  2469. }
  2470. else if(status_code==0) {
  2471. BOOL condition = offline_edit;
  2472. #ifdef OFFLINE_MODE
  2473. condition = condition || appDelegate.offline_mode==false;
  2474. #else
  2475. condition = YES;
  2476. #endif
  2477. if (condition)
  2478. {
  2479. cell.sign_img.userInteractionEnabled = YES;
  2480. }
  2481. }
  2482. NSString* file_name=[img_url lastPathComponent];
  2483. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2484. if(img_data!=nil)
  2485. {
  2486. UIImage * img =[UIImage imageWithData:img_data];
  2487. cell.sign_img.image=img ;
  2488. }
  2489. else
  2490. {
  2491. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2492. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2493. dispatch_async(dispatch_get_main_queue(), ^{
  2494. if(downloadimg_data!=nil)
  2495. {
  2496. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2497. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2498. cell.sign_img.image=img ;
  2499. }
  2500. else {
  2501. if (cell.sign_img.userInteractionEnabled) {
  2502. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2503. } else {
  2504. cell.sign_img.image = nil;
  2505. }
  2506. }
  2507. });
  2508. });
  2509. }
  2510. cell.backgroundColor = [UIColor whiteColor];
  2511. return cell;
  2512. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  2513. // NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2514. // OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2515. //
  2516. //
  2517. //
  2518. //
  2519. // cell.webview.tag = indexPath.section;
  2520. // cell.webview.delegate = self;
  2521. // // cell.webView.scrollView.contentSize.height = 0;
  2522. // cell.webview.scrollView.bounces=NO;
  2523. // cell.webview.scrollView.directionalLockEnabled = true;
  2524. // CGSize size= cell.webview.scrollView.contentSize;
  2525. // size.height=10;
  2526. // cell.webview.scrollView.contentSize=size;
  2527. //
  2528. //
  2529. //
  2530. // [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2531. //
  2532. // cell.backgroundColor = [UIColor whiteColor];
  2533. // return cell;
  2534. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2535. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2536. cell.wkwebview.tag = indexPath.section;
  2537. cell.wkwebview.navigationDelegate = self;
  2538. // cell.webView.scrollView.contentSize.height = 0;
  2539. cell.wkwebview.scrollView.bounces=NO;
  2540. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2541. CGSize size= cell.wkwebview.scrollView.contentSize;
  2542. size.height=10;
  2543. cell.wkwebview.scrollView.contentSize=size;
  2544. NSLog(@"webview loadHTMLString 3");
  2545. [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2546. NSLog(@"webview loadHTMLString 4");
  2547. cell.backgroundColor = [UIColor whiteColor];
  2548. return cell;
  2549. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  2550. NSDictionary *data = [section objectForKey:@"data"];
  2551. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2552. NSString *item_type = [item objectForKey:@"type"];
  2553. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  2554. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  2555. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2556. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  2557. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  2558. NSString *track_number = [item objectForKey:@"tracking_number"];
  2559. NSString *status = [item objectForKey:@"status"];
  2560. cell.track_number_lb.text = track_number;
  2561. cell.status_lb.text = status;
  2562. cell.carrier_lb.text = carrier;
  2563. cell.url_lb.text = web_url;
  2564. return cell;
  2565. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  2566. NSString *CellIdentifier = @"OrderDetailModelCell";
  2567. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2568. NSDictionary * item_json = item;
  2569. // int count = [[item_json valueForKey:@"count"] intValue];
  2570. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2571. cell.bundle_item=combine_json;
  2572. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2573. if (cell.masterBtn != nil) {
  2574. if (master_json == nil) {
  2575. cell.masterBtn.hidden = YES;
  2576. } else{
  2577. cell.masterBtn.hidden = NO;
  2578. cell.master_items = master_json;
  2579. }
  2580. }
  2581. double dprice=0.0;
  2582. if(cell.bundle_item!=nil)
  2583. {
  2584. int citem=0;
  2585. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2586. for(int bc=0;bc<bcount;bc++)
  2587. {
  2588. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2589. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2590. citem+= modulus;
  2591. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2592. dprice+= uprice*modulus;
  2593. }
  2594. if(citem==1)
  2595. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2596. else
  2597. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2598. cell.buttonBundle.hidden = NO;
  2599. }
  2600. else
  2601. {
  2602. cell.buttonBundle.hidden = YES;
  2603. }
  2604. NSString* img_url = [item_json valueForKey:@"img"];
  2605. NSString* description = [item_json valueForKey:@"Item Number"];
  2606. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2607. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2608. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2609. NSString* qty = [item_json valueForKey:@"QTY"];
  2610. NSString* status = [item_json valueForKey:@"order_item_status"];
  2611. NSString* notes = [item_json valueForKey:@"note"];
  2612. if(notes.length>0)
  2613. {
  2614. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2615. }
  2616. else
  2617. cell.noteLabel.text = nil;
  2618. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2619. {
  2620. }
  2621. else
  2622. {
  2623. unitprice=nil;
  2624. origin_price=nil;
  2625. subtotal=nil;
  2626. }
  2627. float duprice = [unitprice floatValue];
  2628. float dsubtotal = (duprice+dprice)*[qty intValue];
  2629. cell.descriptionLabel.text=description;
  2630. if(dprice>0)
  2631. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2632. else
  2633. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2634. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2635. cell.qtyLabel.text = qty;
  2636. cell.statusLabel.text = status;
  2637. cell.labelOldPrice.text = origin_price;
  2638. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2639. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2640. cell.labelDiscount.text = discountstr;
  2641. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2642. if(isfree)
  2643. {
  2644. cell.labelOldPrice.hidden = false;
  2645. cell.labelOldPrice.textColor = [UIColor redColor];
  2646. cell.labelOldPrice.text=@"Free";
  2647. cell.labelOldPrice.hideline = true;
  2648. cell.labelDiscount.hidden = true;
  2649. }
  2650. else
  2651. {
  2652. cell.labelOldPrice.textColor = [UIColor blackColor];
  2653. cell.labelOldPrice.hideline = false;
  2654. if(discount==0)
  2655. {
  2656. cell.labelOldPrice.hidden = true;
  2657. cell.labelDiscount.hidden = true;
  2658. }
  2659. else
  2660. {
  2661. cell.labelOldPrice.hidden = false;
  2662. cell.labelDiscount.hidden = false;
  2663. }
  2664. }
  2665. // Button 设置了大小约束,Size就不会随内容变化
  2666. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  2667. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  2668. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  2669. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  2670. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  2671. if (![cell.imageName isEqualToString:img_url]) {
  2672. cell.imageName = img_url;
  2673. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2674. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2675. NSString* file_name=[img_url lastPathComponent];
  2676. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2677. if(img_data!=nil)
  2678. {
  2679. UIImage * img =[UIImage imageWithData:img_data];
  2680. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2681. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2682. }
  2683. else
  2684. {
  2685. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2686. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2687. dispatch_async(dispatch_get_main_queue(), ^{
  2688. if(downloadimg_data!=nil)
  2689. {
  2690. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2691. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2692. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2693. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  2694. }
  2695. else
  2696. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2697. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2698. });
  2699. });
  2700. }
  2701. }
  2702. cell.backgroundColor = [UIColor whiteColor];
  2703. return cell;
  2704. }
  2705. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  2706. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2707. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2708. NSDictionary *data = [section objectForKey:@"data"];
  2709. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  2710. NSString *title = [item objectForKey:@"title"];
  2711. NSString *value = [item objectForKey:@"value"];
  2712. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  2713. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2714. {
  2715. }
  2716. else
  2717. {
  2718. value=nil;
  2719. }
  2720. }
  2721. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  2722. cell.priceLabel.text = value;
  2723. cell.backgroundColor = [UIColor whiteColor];
  2724. return cell;
  2725. }
  2726. #endif
  2727. #ifdef BUILD_HMLG
  2728. switch(indexPath.section)
  2729. {
  2730. case 0:
  2731. {
  2732. if(indexPath.row==0)
  2733. {
  2734. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2735. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2736. cell.html = nil;
  2737. cell.wkwebview.tag = indexPath.section;
  2738. cell.wkwebview.navigationDelegate = self;
  2739. // cell.webView.scrollView.contentSize.height = 0;
  2740. cell.wkwebview.scrollView.bounces=NO;
  2741. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2742. CGSize size= cell.wkwebview.scrollView.contentSize;
  2743. size.height=10;
  2744. cell.wkwebview.scrollView.contentSize=size;
  2745. cell.backgroundColor = [UIColor whiteColor];
  2746. cell.wkwebview.userInteractionEnabled = YES;
  2747. cell.html =[self.content_data valueForKey:@"order_info"];
  2748. [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  2749. // [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  2750. // cell.backgroundColor = [UIColor whiteColor];
  2751. return cell;
  2752. //
  2753. // NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2754. // OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2755. //
  2756. // cell.html = nil;
  2757. //
  2758. //
  2759. //
  2760. // cell.wkwebview.tag = indexPath.section;
  2761. //
  2762. // cell.wkwebview.navigationDelegate = self;
  2763. // // cell.webView.scrollView.contentSize.height = 0;
  2764. // cell.wkwebview.scrollView.bounces=NO;
  2765. // cell.wkwebview.scrollView.directionalLockEnabled = true;
  2766. // CGSize size= cell.wkwebview.scrollView.contentSize;
  2767. // size.height=10;
  2768. // cell.wkwebview.scrollView.contentSize=size;
  2769. // cell.backgroundColor = [UIColor whiteColor];
  2770. //
  2771. // cell.wkwebview.userInteractionEnabled = YES;
  2772. //
  2773. // cell.html =[section valueForKey:@"data"];
  2774. // NSLog(@"webview loadHTMLString 0");
  2775. // [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2776. // NSLog(@"webview loadHTMLString 1");
  2777. //
  2778. // return cell;
  2779. }
  2780. else
  2781. {
  2782. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  2783. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2784. NSString* img_url = [self.content_data valueForKey:@"sign_url"];
  2785. cell.sign_img.userInteractionEnabled = NO;
  2786. __block BOOL hasTapGesture = NO;
  2787. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2788. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  2789. hasTapGesture = YES;
  2790. *stop = YES;
  2791. }
  2792. }];
  2793. if (!hasTapGesture) {
  2794. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  2795. [cell.sign_img addGestureRecognizer:signatureTap];
  2796. }
  2797. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  2798. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  2799. if(status_code==1) {
  2800. BOOL condition = offline_edit;
  2801. #ifdef OFFLINE_MODE
  2802. condition = condition || appDelegate.offline_mode==false;
  2803. #else
  2804. condition = YES;
  2805. #endif
  2806. if (condition)
  2807. {
  2808. cell.sign_img.userInteractionEnabled = YES;
  2809. }
  2810. }
  2811. else if(status_code==0) {
  2812. BOOL condition = offline_edit;
  2813. #ifdef OFFLINE_MODE
  2814. condition = condition || appDelegate.offline_mode==false;
  2815. #else
  2816. condition = YES;
  2817. #endif
  2818. if (condition)
  2819. {
  2820. cell.sign_img.userInteractionEnabled = YES;
  2821. }
  2822. }
  2823. NSString* file_name=[img_url lastPathComponent];
  2824. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2825. if(img_data!=nil)
  2826. {
  2827. UIImage * img =[UIImage imageWithData:img_data];
  2828. cell.sign_img.image=img ;
  2829. }
  2830. else
  2831. {
  2832. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2833. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2834. dispatch_async(dispatch_get_main_queue(), ^{
  2835. if(downloadimg_data!=nil)
  2836. {
  2837. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2838. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2839. cell.sign_img.image=img ;
  2840. }
  2841. else {
  2842. if (cell.sign_img.userInteractionEnabled) {
  2843. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  2844. } else {
  2845. cell.sign_img.image = nil;
  2846. }
  2847. }
  2848. });
  2849. });
  2850. }
  2851. cell.backgroundColor = [UIColor whiteColor];
  2852. return cell;
  2853. }
  2854. }
  2855. break;
  2856. case 1:
  2857. {
  2858. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2859. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2860. cell.wkwebview.tag = indexPath.section;
  2861. cell.wkwebview.navigationDelegate = self;
  2862. // cell.webView.scrollView.contentSize.height = 0;
  2863. cell.wkwebview.scrollView.bounces=NO;
  2864. cell.wkwebview.scrollView.directionalLockEnabled = true;
  2865. CGSize size= cell.wkwebview.scrollView.contentSize;
  2866. size.height=10;
  2867. cell.wkwebview.scrollView.contentSize=size;
  2868. NSLog(@"webview loadHTMLString 3");
  2869. [cell.wkwebview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  2870. NSLog(@"webview loadHTMLString 4");
  2871. cell.backgroundColor = [UIColor whiteColor];
  2872. return cell;
  2873. // cell.webview.tag = indexPath.section;
  2874. // cell.webview.delegate = self;
  2875. // // cell.webView.scrollView.contentSize.height = 0;
  2876. // cell.webview.scrollView.bounces=NO;
  2877. // cell.webview.scrollView.directionalLockEnabled = true;
  2878. // CGSize size= cell.webview.scrollView.contentSize;
  2879. // size.height=10;
  2880. // cell.webview.scrollView.contentSize=size;
  2881. //
  2882. //
  2883. //
  2884. // [cell.webview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  2885. //
  2886. // cell.backgroundColor = [UIColor whiteColor];
  2887. return cell;
  2888. // { /** More Info */
  2889. //
  2890. // NSString *CellIdentifier = @"OrderDetailHtmlCell";
  2891. // OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2892. //
  2893. //
  2894. //
  2895. //
  2896. // cell.wkwebview.tag = indexPath.section;
  2897. // cell.wkwebview.navigationDelegate = self;
  2898. // // cell.webView.scrollView.contentSize.height = 0;
  2899. // cell.wkwebview.scrollView.bounces=NO;
  2900. // cell.wkwebview.scrollView.directionalLockEnabled = true;
  2901. // CGSize size= cell.wkwebview.scrollView.contentSize;
  2902. // size.height=10;
  2903. // cell.wkwebview.scrollView.contentSize=size;
  2904. //
  2905. //
  2906. //
  2907. // NSLog(@"webview loadHTMLString 3");
  2908. // [cell.wkwebview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  2909. // NSLog(@"webview loadHTMLString 4");
  2910. //
  2911. // cell.backgroundColor = [UIColor whiteColor];
  2912. // return cell;
  2913. //
  2914. // }
  2915. // NSString *CellIdentifier = @"OrderDetailInfoCell";
  2916. // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2917. //
  2918. // cell.infoLabel.text =[self.content_data valueForKey:@"more_order_info"];
  2919. //
  2920. //
  2921. //
  2922. //// float width = tableView.frame.size.width;
  2923. //// width-=CELL_MARGIN*2;
  2924. //// CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  2925. ////
  2926. //// NSString* key =[self.content_data valueForKey:@"order_info"];
  2927. ////
  2928. ////
  2929. ////
  2930. //// CGRect frame;
  2931. //// frame.size = constraintkey;
  2932. //// frame.origin.x=0;
  2933. //// frame.origin.y=0;
  2934. ////
  2935. //// RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  2936. ////
  2937. //// [rtlabel setText: key];
  2938. //// CGSize optimumSize = [rtlabel optimumSize];
  2939. ////
  2940. //// float height = optimumSize.height;
  2941. //// height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  2942. ////
  2943. ////
  2944. //// frame.origin.x=LABEL_MARGIN;
  2945. //// frame.size=CGSizeMake(width, height);
  2946. ////
  2947. //// cell.infoLabel.frame = frame;
  2948. //
  2949. //
  2950. //
  2951. //
  2952. // cell.backgroundColor = [UIColor whiteColor];
  2953. // return cell;
  2954. }
  2955. break;
  2956. case 2:
  2957. {
  2958. NSString *CellIdentifier = @"OrderDetailModelCell";
  2959. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2960. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2961. int count = [[item_json valueForKey:@"count"] intValue];
  2962. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2963. cell.bundle_item=combine_json;
  2964. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  2965. if (cell.masterBtn != nil) {
  2966. if (master_json == nil) {
  2967. cell.masterBtn.hidden = YES;
  2968. } else{
  2969. cell.masterBtn.hidden = NO;
  2970. cell.master_items = master_json;
  2971. }
  2972. }
  2973. double dprice=0.0;
  2974. if(cell.bundle_item!=nil)
  2975. {
  2976. int citem=0;
  2977. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2978. for(int bc=0;bc<bcount;bc++)
  2979. {
  2980. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2981. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2982. citem+= modulus;
  2983. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2984. dprice+= uprice*modulus;
  2985. }
  2986. if(citem==1)
  2987. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2988. else
  2989. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2990. cell.buttonBundle.hidden = NO;
  2991. }
  2992. else
  2993. {
  2994. cell.buttonBundle.hidden = YES;
  2995. }
  2996. NSString* img_url = [item_json valueForKey:@"img"];
  2997. NSString* description = [item_json valueForKey:@"Item Number"];
  2998. // NSString* description = [item_json valueForKey:@"Item Number"];
  2999. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  3000. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  3001. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  3002. NSString* qty = [item_json valueForKey:@"QTY"];
  3003. NSString* status = [item_json valueForKey:@"order_item_status"];
  3004. NSString* notes = [item_json valueForKey:@"note"];
  3005. if(notes.length>0)
  3006. {
  3007. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  3008. }
  3009. else
  3010. cell.noteLabel.text = nil;
  3011. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3012. {
  3013. }
  3014. else
  3015. {
  3016. unitprice=nil;
  3017. origin_price=nil;
  3018. subtotal=nil;
  3019. }
  3020. float duprice = [unitprice floatValue];
  3021. float dsubtotal = (duprice+dprice)*[qty intValue];
  3022. cell.descriptionLabel.text=description;
  3023. if(dprice>0)
  3024. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  3025. else
  3026. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  3027. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  3028. cell.qtyLabel.text = qty;
  3029. cell.statusLabel.text = status;
  3030. cell.labelOldPrice.text = origin_price;
  3031. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3032. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3033. cell.labelDiscount.text = discountstr;
  3034. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3035. if(isfree)
  3036. {
  3037. cell.labelOldPrice.hidden = false;
  3038. cell.labelOldPrice.textColor = [UIColor redColor];
  3039. cell.labelOldPrice.text=@"Free";
  3040. cell.labelOldPrice.hideline = true;
  3041. cell.labelDiscount.hidden = true;
  3042. }
  3043. else
  3044. {
  3045. cell.labelOldPrice.textColor = [UIColor blackColor];
  3046. cell.labelOldPrice.hideline = false;
  3047. if(discount==0)
  3048. {
  3049. cell.labelOldPrice.hidden = true;
  3050. cell.labelDiscount.hidden = true;
  3051. }
  3052. else
  3053. {
  3054. cell.labelOldPrice.hidden = false;
  3055. cell.labelDiscount.hidden = false;
  3056. }
  3057. }
  3058. // Button 设置了大小约束,Size就不会随内容变化
  3059. [cell.imgbtn setContentMode:UIViewContentModeScaleAspectFit];
  3060. [cell.imgbtn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  3061. [cell.imgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  3062. [cell.imgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  3063. cell.imgbtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  3064. if (![cell.imageName isEqualToString:img_url]) {
  3065. cell.imageName = img_url;
  3066. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3067. [cell.imgbtn setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3068. NSString* file_name=[img_url lastPathComponent];
  3069. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3070. if(img_data!=nil)
  3071. {
  3072. UIImage * img =[UIImage imageWithData:img_data];
  3073. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  3074. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  3075. }
  3076. else
  3077. {
  3078. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3079. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3080. dispatch_async(dispatch_get_main_queue(), ^{
  3081. if(downloadimg_data!=nil)
  3082. {
  3083. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3084. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3085. // [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  3086. [cell.imgbtn setImage:img forState:UIControlStateNormal];
  3087. }
  3088. else
  3089. // [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3090. [cell.imgbtn setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3091. });
  3092. });
  3093. }
  3094. }
  3095. cell.backgroundColor = [UIColor whiteColor];
  3096. return cell;
  3097. }
  3098. break;
  3099. case 3:
  3100. {
  3101. NSString *CellIdentifier = @"OrderDetailPriceCell";
  3102. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3103. switch (indexPath.row) {
  3104. case 0:
  3105. {
  3106. cell.chargeLabel.text =@"Sub-Total:";
  3107. NSString* price=[self.content_data valueForKey:@"Sub-Total"];
  3108. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3109. {
  3110. }
  3111. else
  3112. {
  3113. price=nil;
  3114. }
  3115. cell.priceLabel.text =price;
  3116. break;
  3117. }
  3118. case 1:
  3119. cell.chargeLabel.text = @"Shipping:";
  3120. cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
  3121. break;
  3122. case 2: {
  3123. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  3124. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  3125. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  3126. #endif
  3127. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  3128. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  3129. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  3130. #endif
  3131. #ifdef BUILD_HMLG
  3132. cell.chargeLabel.text = @"Tax:";
  3133. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  3134. cell.priceLabel.text = tax;
  3135. #endif
  3136. }
  3137. break;
  3138. case 3: {
  3139. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  3140. cell.chargeLabel.text = @"Handling Fee:";
  3141. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  3142. #endif
  3143. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  3144. cell.chargeLabel.text = @"Handling Fee:";
  3145. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  3146. #endif
  3147. #ifdef BUILD_HMLG
  3148. NSString* price=[self.content_data valueForKey:@"Total"];
  3149. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3150. {
  3151. }
  3152. else
  3153. {
  3154. price=nil;
  3155. }
  3156. cell.chargeLabel.text = @"Total:";
  3157. cell.priceLabel.text =price;
  3158. #endif
  3159. }
  3160. break;
  3161. case 4: {
  3162. cell.chargeLabel.text = @"Tax:";
  3163. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  3164. cell.priceLabel.text = tax;
  3165. }
  3166. break;
  3167. case 5:
  3168. {
  3169. NSString* price=[self.content_data valueForKey:@"Total"];
  3170. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3171. {
  3172. }
  3173. else
  3174. {
  3175. price=nil;
  3176. }
  3177. cell.chargeLabel.text = @"Total:";
  3178. cell.priceLabel.text =price;
  3179. break;
  3180. }
  3181. default:
  3182. break;
  3183. }
  3184. cell.backgroundColor = [UIColor whiteColor];
  3185. return cell;
  3186. }
  3187. }
  3188. #endif
  3189. return nil;
  3190. // if(tableView==self.itemListTable)
  3191. // {
  3192. // NSString *CellIdentifier = @"CartItemCell";
  3193. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3194. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3195. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3196. //
  3197. // cell.bundle_item=combine_json;
  3198. // NSString* img_url = [item_json valueForKey:@"img_url"];
  3199. // NSString* description = [item_json valueForKey:@"description"];
  3200. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  3201. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  3202. // NSString* currency = [item_json valueForKey:@"currency"];
  3203. // int count =[[item_json valueForKey:@"count"] intValue];
  3204. //
  3205. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3206. //
  3207. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3208. //
  3209. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3210. // cell.unit_price = unitprice;
  3211. // // cell.labelAttribute.text = attribute;
  3212. // // cell.labelCurrency.text = currency;
  3213. // cell.labelDescription.text = description;
  3214. // // cell.labelIdentifier.text = identifier;
  3215. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  3216. //
  3217. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  3218. //
  3219. //
  3220. //
  3221. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3222. // cell.cart_id = cart_item_id;
  3223. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3224. //
  3225. //
  3226. //
  3227. // [cell set_Count:count];
  3228. //
  3229. // NSString* file_name=[img_url lastPathComponent];
  3230. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3231. // if(img_data!=nil)
  3232. // {
  3233. //
  3234. // UIImage * img =[UIImage imageWithData:img_data];
  3235. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3236. // }
  3237. // else
  3238. // {
  3239. //
  3240. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3241. //
  3242. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3243. //
  3244. // dispatch_async(dispatch_get_main_queue(), ^{
  3245. //
  3246. //
  3247. //
  3248. // if(downloadimg_data!=nil)
  3249. // {
  3250. // [iSalesDB cache_img:downloadimg_data :file_name ];
  3251. //
  3252. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  3253. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3254. // }
  3255. //
  3256. // });
  3257. // });
  3258. //
  3259. //
  3260. // }
  3261. // return cell;
  3262. // }
  3263. // else
  3264. // {
  3265. // NSString *CellIdentifier = @"OrderInfoListItem";
  3266. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3267. // return cell;
  3268. // }
  3269. }
  3270. //#pragma mark - UIAlertViewDelegate
  3271. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  3272. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  3273. //{
  3274. //
  3275. // if(buttonIndex!=alertView.cancelButtonIndex)
  3276. // {
  3277. // [self copyOrder];
  3278. // }
  3279. //}
  3280. - (void)copyOrder {
  3281. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Copy Order" completion:^{
  3282. [RANetwork request_copy_order:self.order_code completionHandler:^(NSMutableDictionary *result) {
  3283. NSDictionary* order_json = result;
  3284. [waitalert dismissViewControllerAnimated:YES completion:^{
  3285. if([[order_json valueForKey:@"result"] intValue]==2)
  3286. {
  3287. // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  3288. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3289. // if([appDelegate.order_code isEqualToString: self.order_code])
  3290. // {
  3291. // [appDelegate closeOrder];
  3292. //// appDelegate.order_code= nil;
  3293. // [appDelegate SetSo:nil];
  3294. //
  3295. //
  3296. // }
  3297. [RAUtils message_alert:[NSString stringWithFormat:@"New order SO#: %@",[order_json valueForKey:@"so_id"]] title:@"Copy successful." controller:self];
  3298. // 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];
  3299. //
  3300. // [alert show];
  3301. //
  3302. #ifdef RA_NOTIFICATION
  3303. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3304. #else
  3305. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3306. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3307. #endif
  3308. [self.navigationController popViewControllerAnimated:false];
  3309. }
  3310. else
  3311. {
  3312. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  3313. }
  3314. }];
  3315. }];
  3316. }];
  3317. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3318. //
  3319. // NSDictionary* order_json = [RANetwork copy_Order:self.order_code];
  3320. //
  3321. // dispatch_async(dispatch_get_main_queue(), ^{
  3322. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3323. // if([[order_json valueForKey:@"result"] intValue]==2)
  3324. // {
  3325. // // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  3326. //
  3327. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3328. // // if([appDelegate.order_code isEqualToString: self.order_code])
  3329. // // {
  3330. // // [appDelegate closeOrder];
  3331. // //// appDelegate.order_code= nil;
  3332. // // [appDelegate SetSo:nil];
  3333. // //
  3334. // //
  3335. // // }
  3336. // 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];
  3337. //
  3338. // [alert show];
  3339. //
  3340. //
  3341. //
  3342. //#ifdef RA_NOTIFICATION
  3343. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3344. //#else
  3345. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3346. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3347. //#endif
  3348. //
  3349. // [self.navigationController popViewControllerAnimated:false];
  3350. //
  3351. // }
  3352. // else
  3353. // {
  3354. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  3355. // }
  3356. //
  3357. //
  3358. //
  3359. // });
  3360. // });
  3361. }
  3362. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
  3363. {
  3364. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  3365. NSLog(@"%@",message.name);
  3366. NSLog(@"body:%@",message.body);
  3367. }
  3368. #pragma mark - WKNavigationDelegate
  3369. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
  3370. {
  3371. NSLog(@"webview didFinishNavigation");
  3372. // [webView evaluateJavaScript:@"document.documentElement.outerHTML.toString()" completionHandler:^(id _Nullable html ,NSError * _Nullable error) {
  3373. //
  3374. // NSLog(html);
  3375. // }];
  3376. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  3377. NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
  3378. if(indexPath==nil)
  3379. {//for ios7
  3380. cell = (UITableViewCell *) webView.superview.superview.superview;
  3381. indexPath = [self.detailTable indexPathForCell:cell];
  3382. }
  3383. if(indexPath==nil)
  3384. return;
  3385. float height= 0;
  3386. if(indexPath.section==0)
  3387. height=self.web_info_height;
  3388. else
  3389. height = self.web_moreinfo_height;
  3390. if(height>0)
  3391. return;
  3392. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  3393. // CGSize size= webView.scrollView.contentSize;
  3394. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  3395. [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight,NSError * _Nullable error) {
  3396. NSLog(@"webview evaluateJavaScript");
  3397. CGRect frame = webView.frame;
  3398. if(height==[fitHeight floatValue])
  3399. {
  3400. NSLog(@"webview return no need reload table");
  3401. return;
  3402. }
  3403. frame.size.height = [fitHeight floatValue];
  3404. //webView.frame = frame;
  3405. // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  3406. if(indexPath.section==0)
  3407. self.web_info_height=frame.size.height;
  3408. else
  3409. self.web_moreinfo_height = frame.size.height;
  3410. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  3411. NSLog(@"webview need call table reload");
  3412. dispatch_async(dispatch_get_main_queue(), ^{
  3413. NSLog(@"reload tableview!!! %f",frame.size.height);
  3414. // UI更新代码
  3415. // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  3416. // [self.detailTable reloadData];
  3417. [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
  3418. // [self performSelector:@selector(rtable) withObject:nil afterDelay:1];
  3419. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  3420. });
  3421. }];
  3422. //
  3423. // NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  3424. //
  3425. // [self.table beginUpdates];
  3426. // [self.table endUpdates];
  3427. // [self.webviewoprationQueue addOperationWithBlock:^{
  3428. // }];
  3429. // [self.table endUpdates];
  3430. // }
  3431. }
  3432. //-(void) rtable
  3433. //{
  3434. // [self.detailTable reloadData];
  3435. //}
  3436. ////禁止链接跳转
  3437. //- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  3438. //
  3439. // NSLog(@"%s",__func__);
  3440. // NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL);
  3441. //
  3442. //// NSString *url = navigationAction.request.URL.absoluteString;
  3443. //// if (![url containsString:[NSBundle mainBundle].bundleURL.absoluteString]) {
  3444. //// self.url = url;
  3445. //// }
  3446. //
  3447. //
  3448. //
  3449. //
  3450. //
  3451. //
  3452. // if (navigationAction.navigationType != WKNavigationTypeLinkActivated ) {
  3453. // return decisionHandler(WKNavigationActionPolicyAllow);
  3454. // }
  3455. //
  3456. // if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
  3457. // [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
  3458. // }
  3459. //
  3460. // return decisionHandler(WKNavigationActionPolicyCancel);
  3461. //}
  3462. #pragma mark - web view delegate
  3463. - (void)reRefreshView {
  3464. [self.detailTable reloadData];
  3465. }
  3466. #pragma mark - RA_NOTIFICAITON
  3467. -(void) refresh_ui
  3468. {
  3469. [self.detailTable reloadData];
  3470. }
  3471. -(void) reload_data
  3472. {
  3473. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  3474. [reF endRefreshing];
  3475. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  3476. [self loaddata];
  3477. }
  3478. -(void) refresh_price
  3479. {
  3480. [self refresh_ui];
  3481. }
  3482. @end