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