DetailViewController.m 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909
  1. //
  2. // DetailViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 7/25/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailViewController.h"
  9. #import "DetailHeaderCell.h"
  10. #import "DetailImageCell.h"
  11. #import "RANetwork.h"
  12. #import "RTLabel.h"
  13. #import "DetailKVCell.h"
  14. #import "LineView.h"
  15. //#import "SelectorViewController.h"
  16. #import "RAUtils.h"
  17. #import "MainViewController.h"
  18. #import "QRCodeGenerator.h"
  19. #import "DefaultTableHeaderView.h"
  20. #import "DefaultAppearance.h"
  21. #import "JKMessageBoxController.h"
  22. #import "CartUtils.h"
  23. #import "ImageUtils.h"
  24. #import "RAPDFViewController.h"
  25. #import "ModelDescriptionController.h"
  26. #import "TextUtils.h"
  27. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  28. #import "HomerModelDetailHeaderCell.h"
  29. #endif
  30. #define DEF_CELL_HEIGHT 44
  31. #define DEF_TABLE_HEIGHT 44
  32. #define LINE_WIDTH 0
  33. #define CELL_MARGIN 0
  34. #define LABEL_MARGIN 10
  35. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  36. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  37. #define NavColor ([UIColor colorWithRed:237/255.0 green:20/255.0f blue:91/255.0f alpha:1.0f])
  38. @interface DetailViewController ()
  39. @property (nonatomic,strong) UIBezierPath *path;
  40. @end
  41. @implementation DetailViewController
  42. {
  43. CALayer *_layer;
  44. }
  45. #ifndef RA_NOTIFICATION
  46. -(void) reload_container_getdata:(bool) update_data
  47. {
  48. [super reload_container_getdata:update_data];
  49. if(update_data)
  50. [self reload];
  51. else
  52. {
  53. [self.detailTable reloadData];
  54. // [self refresh_total];
  55. }
  56. }
  57. #endif
  58. -(void)manually_refresh
  59. {
  60. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  61. if(self.isrefreshing)
  62. {
  63. [reF endRefreshing];
  64. return;
  65. }
  66. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  67. if ([self respondsToSelector:@selector(ReloadData)])
  68. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  69. // DebugLog(@"refresh!!!!!!!!");
  70. }
  71. -(void) ReloadData
  72. {
  73. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  74. [reF endRefreshing];
  75. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  76. [self reload];
  77. }
  78. -(void) reload
  79. {
  80. dispatch_async(dispatch_get_main_queue(), ^{
  81. if(self.isrefreshing)
  82. return;
  83. #ifdef BUILD_UWAVER
  84. self.navigationItem.rightBarButtonItem.enabled = false;
  85. #endif
  86. self.label_net_err.hidden=true;
  87. self.detailTable.hidden = true;
  88. self.isrefreshing=true;
  89. self.mum.center = self.view.center;
  90. self.mum.hidden = false;
  91. [self.mum startAnimating];
  92. //self.detailTable.hidden=true;
  93. [RANetwork request_modeldetail:self.product_id model_name:self.model_name upc_code:self.upc_code category_id:self.category_id use_name:self.use_model_name use_upc:self.use_upc_code groupName:self.groupName completionHandler:^(NSMutableDictionary *result) {
  94. NSMutableDictionary* detail_json=result;
  95. [self.mum stopAnimating];
  96. #ifdef BUILD_UWAVER
  97. self.navigationItem.rightBarButtonItem.enabled = true;
  98. #endif
  99. self.groupName = nil;
  100. if([[detail_json valueForKey:@"result"] intValue]==2)
  101. {
  102. self.detail_data = [detail_json mutableCopy];
  103. self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
  104. NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
  105. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  106. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
  107. self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
  108. // else
  109. // self.quantity =1;
  110. if(self.quantity==0)
  111. self.quantity=1;
  112. self.step=self.quantity;
  113. [self.detailTable reloadData];
  114. //
  115. self.detailTable.hidden = false;
  116. NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
  117. NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
  118. NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
  119. NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
  120. NSMutableDictionary* contents = [NSMutableDictionary new];
  121. int count = 0;
  122. {
  123. for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  124. {
  125. NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  126. // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
  127. //
  128. // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
  129. //
  130. // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  131. // count++;
  132. NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  133. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  134. count++;
  135. }
  136. }
  137. {
  138. for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  139. {
  140. NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  141. item[@"type"]=@"image";
  142. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  143. count++;
  144. }
  145. //#ifndef BUILD_HOMER
  146. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  147. // homer 要求去掉qrcode 2017/12/20
  148. NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
  149. // UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
  150. if(qrpath!=nil)
  151. {
  152. NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
  153. contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  154. count++;
  155. }
  156. #endif
  157. }
  158. contents[@"count"]=@(count);
  159. imgsection[@"stack_contents"]=contents;
  160. self.detail_data[@"img_section"]=imgsection;
  161. // self.detail_data[@"img_section"][@"stack_contents"]=contents;
  162. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  163. [item setValue:self.product_id forKey:@"product_id"];
  164. [item setValue:self.category_id forKey:@"category"];
  165. [item setValue:model_name forKey:@"fash_name"];
  166. [item setValue:img_url forKey:@"picture_path"];
  167. [CartUtils add_recent_model:item];
  168. NSUInteger ii[2] = {0,0};
  169. [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  170. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  171. // int count=[appDelegate.recent_model[@"count"] intValue];
  172. // bool bexist = false;
  173. // for(int i=0;i<count;i++)
  174. // {
  175. // NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  176. // if([mitem[@"product_id"] isEqualToString:self.product_id])
  177. // {
  178. // bexist=true;
  179. // break;
  180. // }
  181. // }
  182. //
  183. // if(!bexist)
  184. // {
  185. // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  186. // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  187. // }
  188. self.groupName = [detail_json objectForKey:@"groupName"];
  189. }
  190. else
  191. if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  192. {
  193. self.detailTable.hidden = true;
  194. self.label_net_err.hidden=false;
  195. }
  196. else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
  197. {
  198. self.detailTable.hidden = true;
  199. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  200. if(self.ispush)
  201. [ self.navigationController popViewControllerAnimated:true];
  202. }
  203. else
  204. {
  205. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  206. }
  207. self.isrefreshing=false;
  208. }];
  209. return;
  210. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  211. //
  212. // NSMutableDictionary* detail_json = [[RANetwork request_ItemDetail:self.product_id model_name:self.model_name category_id:self.category_id use_name:self.use_model_name groupName:self.groupName] mutableCopy];
  213. //
  214. // dispatch_async(dispatch_get_main_queue(), ^{
  215. // [self.mum stopAnimating];
  216. //#ifdef BUILD_UWAVER
  217. // self.navigationItem.rightBarButtonItem.enabled = true;
  218. //#endif
  219. // self.groupName = nil;
  220. // if([[detail_json valueForKey:@"result"] intValue]==2)
  221. // {
  222. //
  223. // self.detail_data = [detail_json mutableCopy];
  224. // self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
  225. // NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
  226. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  227. // if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
  228. // self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
  229. // else
  230. // self.quantity =1;
  231. //
  232. // if(self.quantity==0)
  233. // self.quantity=1;
  234. // self.step=self.quantity;
  235. // [self.detailTable reloadData];
  236. //
  237. // //
  238. // self.detailTable.hidden = false;
  239. //
  240. // NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
  241. //
  242. // NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
  243. //
  244. // NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
  245. // NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
  246. //
  247. // NSMutableDictionary* contents = [NSMutableDictionary new];
  248. // int count = 0;
  249. //
  250. // {
  251. // for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  252. // {
  253. // NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  254. //
  255. //
  256. // // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
  257. // //
  258. // // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
  259. // //
  260. // // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  261. // // count++;
  262. //
  263. // NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  264. //
  265. // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  266. // count++;
  267. // }
  268. // }
  269. //
  270. // {
  271. // for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  272. // {
  273. // NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  274. // item[@"type"]=@"image";
  275. // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  276. // count++;
  277. // }
  278. ////#ifndef BUILD_HOMER
  279. //#if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  280. // // homer 要求去掉qrcode 2017/12/20
  281. // NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
  282. //// UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
  283. // if(qrpath!=nil)
  284. // {
  285. // NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
  286. //
  287. // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  288. // count++;
  289. // }
  290. //#endif
  291. // }
  292. //
  293. //
  294. //
  295. //
  296. // contents[@"count"]=@(count);
  297. // imgsection[@"stack_contents"]=contents;
  298. // self.detail_data[@"img_section"]=imgsection;
  299. //// self.detail_data[@"img_section"][@"stack_contents"]=contents;
  300. //
  301. // NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  302. // [item setValue:self.product_id forKey:@"product_id"];
  303. // [item setValue:self.category_id forKey:@"category"];
  304. // [item setValue:model_name forKey:@"fash_name"];
  305. // [item setValue:img_url forKey:@"picture_path"];
  306. //
  307. // [CartUtils add_recent_model:item];
  308. //
  309. // NSUInteger ii[2] = {0,0};
  310. //
  311. // [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  312. //
  313. //
  314. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  315. //// int count=[appDelegate.recent_model[@"count"] intValue];
  316. //// bool bexist = false;
  317. //// for(int i=0;i<count;i++)
  318. //// {
  319. //// NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  320. //// if([mitem[@"product_id"] isEqualToString:self.product_id])
  321. //// {
  322. //// bexist=true;
  323. //// break;
  324. //// }
  325. //// }
  326. ////
  327. //// if(!bexist)
  328. //// {
  329. //// [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  330. //// appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  331. //// }
  332. //
  333. // self.groupName = [detail_json objectForKey:@"groupName"];
  334. // }
  335. // else
  336. // if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  337. // {
  338. // self.detailTable.hidden = true;
  339. // self.label_net_err.hidden=false;
  340. // }
  341. // else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
  342. // {
  343. // self.detailTable.hidden = true;
  344. // [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  345. // if(self.ispush)
  346. // [ self.navigationController popViewControllerAnimated:true];
  347. // }
  348. // else
  349. // {
  350. // [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  351. // }
  352. //
  353. //self.isrefreshing=false;
  354. //
  355. // });
  356. // });
  357. });
  358. }
  359. - (void)onBackClick:(UIButton *)sender {
  360. if(self.OnBack)
  361. {
  362. self.OnBack(self.add_cart,self.add_wish,self.update_data);
  363. }
  364. [self.navigationController popViewControllerAnimated:(false)];
  365. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  366. // ;
  367. // }];
  368. }
  369. - (void)viewDidLoad {
  370. [super viewDidLoad];
  371. #ifdef RA_NOTIFICATION
  372. self.support_scanner = true;
  373. #endif
  374. [self registeObserver];
  375. self.refresh_type = REFRESH_VIEW;
  376. [self registNotification];
  377. [self setupNavigationBar];
  378. // self.detailTable.style = UITableViewStylePlain;
  379. self.edgesForExtendedLayout = UIRectEdgeNone;
  380. if(self.ispush)
  381. {
  382. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
  383. [line setBackgroundColor:[UIColor clearColor]];
  384. self.detailTable.tableHeaderView = line;
  385. }
  386. //
  387. //
  388. // self.automaticallyAdjustsScrollViewInsets = false;
  389. self.step=1;
  390. self.quantity=1;
  391. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  392. ref.tag = 300 ;
  393. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  394. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  395. // ref.hidden = true;
  396. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  397. [self.detailTable addSubview:ref];
  398. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  399. self.label_net_err.layer.borderWidth = 2.0;
  400. self.label_net_err.layer.cornerRadius=15;
  401. self.label_net_err.layer.masksToBounds=true;
  402. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  403. // tap.minimumPressDuration = 0.8; //定义按的时间
  404. [self.label_net_err addGestureRecognizer:tap];
  405. // Do any additional setup after loading the view.
  406. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  407. [self.detailTable registerNib:[UINib nibWithNibName:@"HomerModelDetailHeaderCell" bundle:nil] forCellReuseIdentifier:@"HomerModelDetailHeaderCell"];
  408. #endif
  409. }
  410. - (void)viewWillAppear:(BOOL)animated
  411. {
  412. if(self.ispush)
  413. {
  414. [super viewWillAppear:animated];
  415. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  416. }
  417. }
  418. - (void) viewWillDisappear:(BOOL)animated
  419. {
  420. [super viewWillDisappear:animated];
  421. if(self.ispush)
  422. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  423. }
  424. - (void)didReceiveMemoryWarning {
  425. [super didReceiveMemoryWarning];
  426. // Dispose of any resources that can be recreated.
  427. }
  428. /*
  429. #pragma mark - Navigation
  430. // In a storyboard-based application, you will often want to do a little preparation before navigation
  431. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  432. // Get the new view controller using [segue destinationViewController].
  433. // Pass the selected object to the new view controller.
  434. }
  435. */
  436. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  437. //将page2设定成Storyboard Segue的目标UIViewController
  438. id page2 = segue.destinationViewController;
  439. //将值透过Storyboard Segue带给页面2的string变数
  440. [page2 setValue: _selector forKey:@"selector"];
  441. [page2 setValue: self forKey:@"selectordelegate"];
  442. }
  443. //- (IBAction)OnAddPortfolio:(id)sender {
  444. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  445. //
  446. // [appDelegate test_onDecodedDataResult:@"371252"];
  447. //// [self onDecodedData:@"3712524-235"];
  448. // return;
  449. //}
  450. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  451. //{
  452. //// [self.detailTable reloadData];
  453. //// return;
  454. // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  455. //
  456. //// NSMutableIndexSet *sectionToReload = [[NSMutableIndexSet alloc] init];
  457. //// int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  458. ////
  459. //// for(int i=0;i<section_count;i++)
  460. //// {
  461. //// NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)i]];
  462. ////
  463. ////
  464. ////
  465. //// NSString* type=[section_json valueForKey:@"type"] ;
  466. ////
  467. //// if([type isEqualToString:@"kv"])
  468. //// {
  469. ////
  470. //// [sectionToReload addIndex:i+1];
  471. //// }
  472. //// }
  473. ////
  474. ////
  475. //// [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationNone];
  476. ////
  477. //
  478. // [self.detailTable reloadData];
  479. //
  480. //
  481. //
  482. //}
  483. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  484. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  485. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  486. // what ever you want to prepare
  487. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  488. [self.detailTable reloadData];
  489. }];
  490. }
  491. #pragma mark - Notification
  492. - (void)registNotification {
  493. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLoginNotification:) name:User_LoginOK_Notification object:nil];
  494. }
  495. - (void)unregistNotification {
  496. [[NSNotificationCenter defaultCenter] removeObserver:self name:User_LoginOK_Notification object:nil];
  497. }
  498. #pragma mark - Nav Bar
  499. - (void)setupNavigationBar {
  500. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  501. style:UIBarButtonItemStylePlain
  502. target:self
  503. action:@selector( onBackClick:)];
  504. self.navigationItem.leftBarButtonItem = backButton;
  505. #ifdef BUILD_UWAVER
  506. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  507. if (appDelegate.bLogin) {
  508. // UIBarButtonItem *hangTagItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(hanTagBtnClick:)];
  509. UIBarButtonItem *hangTagItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_print_order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  510. style:UIBarButtonItemStylePlain
  511. target:self
  512. action:@selector(hanTagBtnClick:)];
  513. hangTagItem.enabled = false;
  514. self.navigationItem.rightBarButtonItem = hangTagItem;
  515. }
  516. #endif
  517. }
  518. #pragma mark - Action
  519. - (void)handleUserLoginNotification:(NSNotification *)notification {
  520. [self setupNavigationBar];
  521. }
  522. - (void)hanTagBtnClick:(id)sender {
  523. DetailViewController *vc = self;
  524. NSString *catelog_name = [NSString stringWithFormat:@"%@ Hang Tag",vc.groupName];
  525. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  526. [RANetwork request_hangtag:vc.groupName completionHandler:^(NSMutableDictionary *result) {
  527. NSMutableDictionary* editor_json =result;
  528. [waitalert dismissViewControllerAnimated:YES completion:^{
  529. if([[editor_json valueForKey:@"result"] intValue]==2)
  530. {
  531. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  532. NSString* url = [editor_json valueForKey:@"pdf_path"];
  533. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  534. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  535. ViewController.url = url;
  536. ViewController.canSave = false;
  537. ViewController.isLocalfile=isLocalFile;
  538. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  539. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  540. if(company==nil)
  541. company=@"";
  542. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  543. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  544. if(customer_email.length>0)
  545. {
  546. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  547. }
  548. ViewController.mail_to = send_to;
  549. NSString* subject;
  550. subject =catelog_name;
  551. ViewController.mail_subject = subject;
  552. ViewController.hidenavi = false;
  553. [vc.navigationController pushViewController:ViewController animated:YES];
  554. }
  555. else
  556. {
  557. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
  558. }
  559. }];
  560. }];
  561. }];
  562. return;
  563. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  564. //
  565. // NSDictionary* editor_json = [RANetwork request_hangTag:vc.groupName];
  566. //
  567. // dispatch_async(dispatch_get_main_queue(), ^{
  568. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  569. //
  570. //
  571. // if([[editor_json valueForKey:@"result"] intValue]==2)
  572. // {
  573. //
  574. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  575. //
  576. // NSString* url = [editor_json valueForKey:@"pdf_path"];
  577. // bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  578. // RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  579. // ViewController.url = url;
  580. // ViewController.canSave = false;
  581. // ViewController.isLocalfile=isLocalFile;
  582. //
  583. // ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  584. //
  585. //
  586. // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  587. //
  588. // if(company==nil)
  589. // company=@"";
  590. //
  591. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  592. //
  593. //
  594. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  595. // if(customer_email.length>0)
  596. // {
  597. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  598. // }
  599. // ViewController.mail_to = send_to;
  600. //
  601. // NSString* subject;
  602. //
  603. // subject =catelog_name;
  604. //
  605. // ViewController.mail_subject = subject;
  606. //
  607. // ViewController.hidenavi = false;
  608. // [vc.navigationController pushViewController:ViewController animated:YES];
  609. //
  610. // }
  611. // else
  612. // {
  613. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
  614. // }
  615. //
  616. // });
  617. // });
  618. }
  619. #pragma mark - Selector delegate
  620. -(void) selected:(NSString*) detail_id category:(NSString*) category
  621. {
  622. self.product_id = detail_id;
  623. self.use_model_name = false;
  624. [self reload];
  625. DebugLog(@"color selected");
  626. }
  627. #pragma mark - Header cell delegate
  628. -(void) SelectorClicked:(UIView*) trigger
  629. {
  630. // int selcount = [[self.selector valueForKey:@"count"] intValue];
  631. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  632. int current_sel = -1;
  633. for(int i=0;i<selector_count;i++)
  634. {
  635. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  636. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  637. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  638. {
  639. current_sel = i;
  640. }
  641. }
  642. // NSArray * arr = [[NSArray alloc] init];
  643. // arr = [NSArray arrayWithObjects:@"Hello 0", @"Hello 1", @"Hello 2", @"Hello 3", @"Hello 4", @"Hello 5", @"Hello 6", @"Hello 7", @"Hello 8", @"Hello 9",nil];
  644. // NSArray * arrImage = [[NSArray alloc] init];
  645. // arrImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], nil];
  646. if(self.dropDown == nil)
  647. {
  648. CGFloat height = 70*selector_count;
  649. if (selector_count > 4) {
  650. height = 70 * 4.5;
  651. }
  652. self.dropDown =[[NIDropDown alloc] showDropDown:self.detailTable based:(id)trigger height:height data:self.selector direction:@"down" current_sel:current_sel];
  653. //Capturing strongly warring;
  654. __block DetailViewController *brself= self;
  655. self.dropDown.dropDownTouchOutsideBlk = ^{
  656. [brself.dropDown hideDropDown:(id)trigger];
  657. brself.dropDown= nil;
  658. };
  659. self.dropDown.selectChanged =^(long index){
  660. NSDictionary* item = [brself.selector objectForKey:[NSString stringWithFormat:@"item_%ld",index]];
  661. NSDictionary* params = [item objectForKey:@"params"];
  662. NSString* detail_id=[[[params objectForKey:@"param_0"] valueForKey:@"val" ] stringValue];
  663. brself.product_id = detail_id;
  664. brself.use_model_name = false;
  665. [brself reload];
  666. // DebugLog(@"color selected");
  667. brself.dropDown = nil;
  668. };
  669. //[[NIDropDown alloc]showDropDown:(id)trigger :&f :arr :arrImage :@"down"];
  670. // self.dropDown.delegate = self;
  671. }
  672. else {
  673. [self.dropDown hideDropDown:(id)trigger];
  674. self.dropDown= nil;
  675. // [self rel];
  676. }
  677. return;
  678. }
  679. -(void) stepClicked:(int) value
  680. {
  681. self.quantity = value;
  682. }
  683. #pragma mark - Topic cell delegate
  684. -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
  685. {
  686. // self.model_name = value;
  687. self.product_id = product_id;
  688. self.category_id=category;
  689. [self reload];
  690. DebugLog(@"color selected");
  691. }
  692. #pragma mark - Table view data source
  693. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  694. //{
  695. // return 0;
  696. //}
  697. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  698. //{
  699. // return 0;
  700. //}
  701. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  702. //{
  703. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  704. // return myView;
  705. //
  706. //}
  707. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  708. //{
  709. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  710. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  711. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  712. //// titleLabel.textColor=[UIColor whiteColor];
  713. //// titleLabel.backgroundColor = [UIColor clearColor];
  714. //// if(section==0)
  715. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  716. //// else
  717. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  718. //// [titleLabel sizeToFit];
  719. //// [myView addSubview:titleLabel];
  720. ////
  721. // return myView;
  722. //}
  723. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  724. if(section==0)
  725. return nil;
  726. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  727. if(related_json==nil)
  728. {
  729. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  730. return [section_json valueForKey:@"title"] ;
  731. }
  732. else
  733. {
  734. if(section==1)
  735. return @"related model";
  736. else
  737. {
  738. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  739. return [section_json valueForKey:@"title"] ;
  740. }
  741. }
  742. }
  743. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  744. //{
  745. // return 33;
  746. //}
  747. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  748. {
  749. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  750. if(value==nil)
  751. value=@"";
  752. unsigned long color = strtoul([value UTF8String],0,16);
  753. NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
  754. if (sectionTitle == nil) {
  755. return nil;
  756. }
  757. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  758. // myView.backgroundColor = UIColorFromRGB(0x996633);
  759. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  760. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  761. myView.layer.shadowOffset = CGSizeMake(0, 0);
  762. myView.layer.shadowOpacity = 0.5;
  763. myView.layer.shadowRadius = 2.0;
  764. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5.5, 90, 22)];
  765. titlelabel.textColor=UIColorFromRGB(color);
  766. // titlelabel.backgroundColor = [UIColor clearColor];
  767. titlelabel.text=sectionTitle;
  768. [titlelabel sizeToFit];
  769. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  770. bool refresh= [[section_json valueForKey:@"partial_refresh"] boolValue] ;
  771. if(refresh)
  772. {
  773. NSString* btntitle=@"Refresh" ;
  774. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DetailTableHeaderView" valuename:@"refresh_button_color"];
  775. //
  776. // if(value==nil)
  777. // value=@"";
  778. // unsigned long color = strtoul([value UTF8String],0,16);
  779. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-100-15, 0, 100, 33)];
  780. // [btn setTitleColor:UIColorFromRGB(color) forState:UIControlStateNormal];
  781. btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  782. btn.tag=section;
  783. [btn addTarget:self action:@selector(RefreshSection:) forControlEvents:UIControlEventTouchUpInside];
  784. [btn setTitle:btntitle forState:UIControlStateNormal];
  785. [myView addSubview:btn];
  786. }
  787. [myView addSubview:titlelabel];
  788. return myView;
  789. }
  790. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  791. {
  792. int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  793. if(section_count==0)
  794. return section_count;
  795. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  796. if(related_json==nil)
  797. return section_count+1;
  798. else
  799. return section_count+2;
  800. }
  801. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  802. //{
  803. // DebugLog(@"canMoveRowAtIndexPath");
  804. //
  805. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  806. // return true;
  807. // else
  808. // return false;
  809. //}
  810. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  811. //{
  812. // NSMutableArray * from;
  813. // NSMutableArray * to ;
  814. // if(fromIndexPath.section==0)
  815. // from = self.displayfields;
  816. // else
  817. // from = self.hidefields;
  818. // if(toIndexPath.section==0)
  819. // to = self.displayfields;
  820. // else
  821. // to = self.hidefields;
  822. // id content=from[fromIndexPath.row];
  823. // [from removeObjectAtIndex:fromIndexPath.row];
  824. // [to insertObject:content atIndex:toIndexPath.row];
  825. //
  826. // [tableView reloadData];
  827. //
  828. //}
  829. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  830. {
  831. if(section==0)
  832. return 1;
  833. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  834. if(related_json==nil)
  835. {
  836. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]];
  837. NSString* type=[section_json valueForKey:@"type"] ;
  838. if([type isEqualToString:@"content"])
  839. return 1;
  840. return [[section_json valueForKey:@"count"] intValue];
  841. }
  842. else
  843. {
  844. if(section==1)
  845. return 1;
  846. else
  847. {
  848. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  849. NSString* type=[section_json valueForKey:@"type"] ;
  850. if([type isEqualToString:@"content"])
  851. return 1;
  852. return [[section_json valueForKey:@"count"] intValue];
  853. }
  854. }
  855. }
  856. //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  857. //{
  858. // return UITableViewCellEditingStyleNone;
  859. //}
  860. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  861. //{
  862. // //如果两次点击的时间间隔小于1秒,则断定为双击事件
  863. //
  864. // if(tableView.editing==false)
  865. // return;
  866. //
  867. //
  868. // if([tableView numberOfRowsInSection:indexPath.section]<=1)
  869. // return;
  870. // // int between = 1;
  871. // NSUInteger curr = [[NSDate date] timeIntervalSince1970];
  872. //
  873. // if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
  874. // {
  875. // if (curr-self.taptime<1) {
  876. // DebugLog(@"double click!");
  877. // self.lasttap =nil;
  878. //
  879. // NSMutableArray * from;
  880. // NSMutableArray * to ;
  881. // int section;
  882. // if(indexPath.section==0)
  883. // {
  884. // from = self.displayfields;
  885. // to = self.hidefields;
  886. // section = 1;
  887. // }
  888. // else
  889. // {
  890. //
  891. // from = self.hidefields;
  892. // to = self.displayfields;
  893. // section = 0;
  894. // }
  895. // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
  896. // // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
  897. // // NSIndexPath * headerIndexPath1 = toIndexPath;
  898. //
  899. // id content=from[indexPath.row];
  900. // [tableView beginUpdates];
  901. // [from removeObjectAtIndex:indexPath.row];
  902. // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  903. //
  904. // [to insertObject:content atIndex:0];
  905. // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  906. // [tableView endUpdates];
  907. //
  908. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  909. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  910. // [tableView reloadData];
  911. //
  912. //
  913. // }
  914. // self.taptime = curr;
  915. //
  916. //
  917. // }
  918. // else
  919. // {
  920. // self.taptime = curr;
  921. // self.lasttap = indexPath;
  922. // }
  923. //}
  924. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  925. {
  926. if(section ==0)
  927. return 0;
  928. else
  929. return 33;
  930. }
  931. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  932. {
  933. if(indexPath.section ==0) {
  934. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  935. CGFloat height = CGRectGetHeight(self.view.bounds);
  936. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
  937. return height;
  938. }
  939. #endif
  940. return 550;
  941. }
  942. // NSDictionary* nsdic = self.detail_data;
  943. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  944. if(related_json==nil)
  945. {
  946. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  947. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  948. NSString* type=[section_json valueForKey:@"type"] ;
  949. if([type isEqualToString:@"kv"])
  950. {
  951. float width = tableView.frame.size.width;
  952. width-=CELL_MARGIN*2;
  953. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  954. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  955. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  956. NSString* key =[item_json valueForKey:@"key"] ;
  957. // [cell.keyLabel sizeToFit];
  958. NSString* val=[item_json valueForKey:@"val"] ;
  959. if([val isEqual:[NSNull null]])
  960. val=@"";
  961. if(val==nil)
  962. val=@"";
  963. if([val isEqualToString:@"null"])
  964. val=@"";
  965. CGRect frame;
  966. frame.size = constraintval;
  967. frame.origin.x=0;
  968. frame.origin.y=0;
  969. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  970. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  971. // rtlabel.lineSpacing = 20.0;
  972. [rtlabel setText: val];
  973. CGSize sizeval=rtlabel.optimumSize;
  974. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  975. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  976. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  977. float height = MAX(sizekey.height,sizeval.height);
  978. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  979. return height;
  980. }
  981. else if([type isEqualToString:@"img"])
  982. {
  983. int img_count = [[item_json valueForKey:@"count"] intValue];
  984. double ret = 0;
  985. for(int j=0;j<img_count;j++)
  986. {
  987. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  988. float width = [[img_json valueForKey:@"width"]floatValue];
  989. float height = [[img_json valueForKey:@"height"]floatValue];
  990. ret+=height*tableView.bounds.size.width / width;
  991. }
  992. return ret;
  993. }
  994. else if([type isEqualToString:@"content"])
  995. return 270;
  996. return 44;
  997. }
  998. else
  999. {
  1000. if(indexPath.section==1)
  1001. return 270;
  1002. else
  1003. {
  1004. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-2]];
  1005. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1006. NSString* type=[section_json valueForKey:@"type"] ;
  1007. if([type isEqualToString:@"kv"])
  1008. {
  1009. float width = tableView.frame.size.width;
  1010. width-=CELL_MARGIN*2;
  1011. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1012. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1013. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1014. NSString* key =[item_json valueForKey:@"key"] ;
  1015. // [cell.keyLabel sizeToFit];
  1016. NSString* val=[item_json valueForKey:@"val"] ;
  1017. if([val isEqual:[NSNull null]])
  1018. val=@"";
  1019. if(val==nil)
  1020. val=@"";
  1021. if([val isEqualToString:@"null"])
  1022. val=@"";
  1023. CGRect frame;
  1024. frame.size = constraintval;
  1025. frame.origin.x=0;
  1026. frame.origin.y=0;
  1027. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1028. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1029. // rtlabel.lineSpacing = 20.0;
  1030. [rtlabel setText: val];
  1031. CGSize sizeval=rtlabel.optimumSize;
  1032. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1033. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1034. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  1035. float height = MAX(sizekey.height,sizeval.height);
  1036. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  1037. return height;
  1038. }
  1039. else if([type isEqualToString:@"img"])
  1040. {
  1041. int img_count = [[item_json valueForKey:@"count"] intValue];
  1042. double ret = 0;
  1043. for(int j=0;j<img_count;j++)
  1044. {
  1045. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  1046. float width = [[img_json valueForKey:@"width"]floatValue];
  1047. float height = [[img_json valueForKey:@"height"]floatValue];
  1048. ret+=height*tableView.bounds.size.width / width;
  1049. }
  1050. return ret;
  1051. }
  1052. return 44;
  1053. }
  1054. }
  1055. }
  1056. - (BOOL)isOutofStock {
  1057. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  1058. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  1059. // 2018-01-10 修改通过lowercase判断
  1060. if (!qtyStr || !qtyStr.length || [qtyStr.lowercaseString isEqualToString:@"in production"] || [qtyStr isEqualToString:@"0"] || [qtyStr.lowercaseString isEqualToString:@"sold out"] || [qtyStr.lowercaseString isEqualToString:@"out of stock"]) {
  1061. return YES;
  1062. }
  1063. return NO;
  1064. }
  1065. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1066. {
  1067. // DebugLog(@"cellForRowAtIndexPath");
  1068. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1069. if(indexPath.section==0)
  1070. {
  1071. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1072. NSString *CellIdentifier = @"HomerModelDetailHeaderCell";
  1073. HomerModelDetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1074. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
  1075. CGFloat w = CGRectGetWidth(tableView.bounds);
  1076. CGFloat h = CGRectGetHeight(tableView.bounds);
  1077. CGFloat space_w = w - 320;
  1078. CGFloat photoStackWidth = space_w - (35 * 2);
  1079. CGFloat photoStackHeight = h - 102 - 70;
  1080. CGFloat a = MIN(photoStackWidth, photoStackHeight);
  1081. CGFloat x = (space_w - a) * 0.5, y = 102 + (photoStackHeight - a) * 0.5;
  1082. if (x > 50) {
  1083. x -= 20;
  1084. }
  1085. cell.photoStack.frame = CGRectMake(x, y, a, a);
  1086. cell.pageControl.frame = CGRectMake((space_w - 319) * 0.5, h - 50, 319, 37);
  1087. } else {
  1088. cell.photoStack.frame = CGRectMake(35, 107, 349, 348);
  1089. cell.pageControl.frame = CGRectMake(50, 466, 319, 37);
  1090. }
  1091. #else
  1092. NSString *CellIdentifier = @"DetailHeaderCell";
  1093. DetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1094. cell.btn_hangtag.hidden = YES;
  1095. #endif
  1096. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  1097. // Homer添加的View
  1098. cell.hmlg_stock_lb.hidden = YES;
  1099. cell.hmlg_stock_count_lb.hidden = YES;
  1100. cell.on_sale_lb.hidden = YES;
  1101. if (!appDelegate.user) { // 没有登录时隐藏add to portfolio,使add to cart与add to wishlist对齐
  1102. cell.btnaddPortfolio.hidden = YES;
  1103. cell.btnNotifyMe.hidden = YES;
  1104. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1105. // cell.hmlg_stock_lb.hidden = NO;
  1106. // cell.hmlg_stock_count_lb.hidden = NO;
  1107. BOOL is_special_model = [[section_json objectForKey:@"is_special_model"] boolValue];
  1108. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  1109. if (hmlg_stock == nil) {
  1110. hmlg_stock = @"";
  1111. }
  1112. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  1113. cell.on_sale_lb.hidden = !is_special_model;
  1114. #endif
  1115. } else {
  1116. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  1117. // NSString *qtyStr = [section_json valueForKey:@"Availability"];
  1118. __weak typeof(self) weakself = self;
  1119. cell.notifyMeBlock = ^{
  1120. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  1121. [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  1122. NSMutableDictionary *dic =result;
  1123. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  1124. int result_code = [[dic valueForKey:@"result"] intValue];
  1125. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS) {
  1126. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1127. if ([dic valueForKey:@"err_msg"]) {
  1128. msg = [dic valueForKey:@"err_msg"];
  1129. }
  1130. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1131. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1132. }];
  1133. [errorAlertVC addAction:action];
  1134. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1135. } else if (result_code == RESULT_TRUE){
  1136. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1137. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  1138. [self showEmailAddrBox];
  1139. }
  1140. }];
  1141. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1142. }];
  1143. }];
  1144. // dispatch_async(dispatch_get_global_queue(0,0), ^{
  1145. //
  1146. // NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
  1147. //
  1148. // dispatch_async(dispatch_get_main_queue(), ^{
  1149. //
  1150. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1151. //
  1152. // NSInteger result = [[dic valueForKey:@"result"] integerValue];
  1153. //
  1154. // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  1155. //
  1156. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1157. //
  1158. // if ([dic valueForKey:@"err_msg"]) {
  1159. // msg = [dic valueForKey:@"err_msg"];
  1160. // }
  1161. //
  1162. //
  1163. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1164. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1165. //
  1166. // }];
  1167. //
  1168. // [errorAlertVC addAction:action];
  1169. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1170. //
  1171. // } else if (result == RESULT_TRUE){
  1172. //
  1173. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1174. //
  1175. // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  1176. //
  1177. // [self showEmailAddrBox];
  1178. //
  1179. // }
  1180. // });
  1181. //
  1182. //
  1183. // });
  1184. };
  1185. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1186. cell.btnaddPortfolio.hidden = YES;
  1187. if (!notifyMe_switch) {
  1188. cell.btnNotifyMe.hidden = YES;
  1189. } else {
  1190. cell.btnNotifyMe.hidden = NO;
  1191. if (!appDelegate.order_code) { // 未打开订单状态
  1192. if ([self isOutofStock]) {
  1193. if (!appDelegate.can_create_backorder) {
  1194. cell.btnaddCart.enabled = NO;
  1195. }
  1196. cell.btnNotifyMe.enabled = YES;
  1197. } else {
  1198. cell.btnaddCart.enabled = YES;
  1199. cell.btnNotifyMe.enabled = NO;
  1200. }
  1201. } else {
  1202. // 打开订单状态
  1203. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1204. // Shop Order
  1205. cell.btnaddCart.enabled = YES;
  1206. // 默认未缺货
  1207. cell.btnNotifyMe.enabled = NO;
  1208. if ([self isOutofStock]) { // 缺货
  1209. cell.btnNotifyMe.enabled = YES;
  1210. }
  1211. } else {
  1212. // Purchase Order
  1213. if ([self isOutofStock]) { // 缺货
  1214. if (!appDelegate.can_create_backorder) {
  1215. cell.btnaddCart.enabled = NO;
  1216. }
  1217. cell.btnNotifyMe.enabled = YES;
  1218. } else { // 未缺货
  1219. cell.btnNotifyMe.enabled = NO;
  1220. cell.btnaddCart.enabled = YES;
  1221. }
  1222. }
  1223. }
  1224. }
  1225. } else { // employee
  1226. // online
  1227. cell.btnaddPortfolio.hidden = NO;
  1228. cell.btnNotifyMe.hidden = NO;
  1229. if ([self isOutofStock]) { // 缺货
  1230. if (!appDelegate.can_create_backorder) {
  1231. cell.btnaddCart.enabled = NO;
  1232. }
  1233. cell.btnNotifyMe.enabled = YES;
  1234. } else { // 未缺货
  1235. cell.btnNotifyMe.enabled = NO;
  1236. cell.btnaddCart.enabled = YES;
  1237. }
  1238. // offline
  1239. #ifdef OFFLINE_MODE
  1240. if (appDelegate.offline_mode) {
  1241. cell.btnNotifyMe.hidden = YES;
  1242. }
  1243. #endif
  1244. }
  1245. #endif
  1246. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1247. // cell.hmlg_stock_lb.hidden = NO;
  1248. // cell.hmlg_stock_count_lb.hidden = NO;
  1249. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  1250. if (hmlg_stock == nil) {
  1251. hmlg_stock = @"";
  1252. }
  1253. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  1254. cell.on_sale_lb.hidden = !is_special_model;
  1255. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  1256. __weak typeof(self) weakself = self;
  1257. cell.notifyMeBlock = ^{
  1258. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1259. [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  1260. NSMutableDictionary *dic =result;
  1261. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1262. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  1263. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  1264. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1265. if ([dic valueForKey:@"err_msg"]) {
  1266. msg = [dic valueForKey:@"err_msg"];
  1267. }
  1268. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1269. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1270. }];
  1271. [errorAlertVC addAction:action];
  1272. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1273. } else if (result == RESULT_TRUE){
  1274. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1275. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  1276. [self showEmailAddrBox];
  1277. }
  1278. }];
  1279. // dispatch_async(dispatch_get_global_queue(0,0), ^{
  1280. //
  1281. // NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
  1282. //
  1283. // dispatch_async(dispatch_get_main_queue(), ^{
  1284. //
  1285. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1286. //
  1287. // NSInteger result = [[dic valueForKey:@"result"] integerValue];
  1288. //
  1289. // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  1290. //
  1291. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1292. //
  1293. // if ([dic valueForKey:@"err_msg"]) {
  1294. // msg = [dic valueForKey:@"err_msg"];
  1295. // }
  1296. //
  1297. //
  1298. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1299. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1300. //
  1301. // }];
  1302. //
  1303. // [errorAlertVC addAction:action];
  1304. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1305. //
  1306. // } else if (result == RESULT_TRUE){
  1307. //
  1308. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1309. //
  1310. // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  1311. //
  1312. // [self showEmailAddrBox];
  1313. //
  1314. // }
  1315. // });
  1316. //
  1317. //
  1318. // });
  1319. };
  1320. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1321. cell.btnaddPortfolio.hidden = YES;
  1322. if (!notifyMe_switch) {
  1323. cell.btnNotifyMe.hidden = YES;
  1324. } else {
  1325. cell.btnNotifyMe.hidden = NO;
  1326. if (!appDelegate.order_code) { // 未打开订单状态
  1327. if ([self isOutofStock]) {
  1328. if (!appDelegate.can_create_backorder) {
  1329. cell.btnaddCart.enabled = NO;
  1330. }
  1331. cell.btnNotifyMe.enabled = YES;
  1332. } else {
  1333. cell.btnaddCart.enabled = YES;
  1334. cell.btnNotifyMe.enabled = NO;
  1335. }
  1336. } else {
  1337. // 打开订单状态
  1338. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1339. // Shop Order
  1340. cell.btnaddCart.enabled = YES;
  1341. // 默认未缺货
  1342. cell.btnNotifyMe.enabled = NO;
  1343. if ([self isOutofStock]) { // 缺货
  1344. cell.btnNotifyMe.enabled = YES;
  1345. }
  1346. } else {
  1347. // Purchase Order
  1348. if ([self isOutofStock]) { // 缺货
  1349. if (!appDelegate.can_create_backorder) {
  1350. cell.btnaddCart.enabled = NO;
  1351. }
  1352. cell.btnNotifyMe.enabled = YES;
  1353. } else { // 未缺货
  1354. cell.btnNotifyMe.enabled = NO;
  1355. cell.btnaddCart.enabled = YES;
  1356. }
  1357. }
  1358. }
  1359. }
  1360. } else { // employee
  1361. // online
  1362. cell.btnaddPortfolio.hidden = NO;
  1363. cell.btnNotifyMe.hidden = NO;
  1364. if ([self isOutofStock]) { // 缺货
  1365. if (!appDelegate.can_create_backorder) {
  1366. cell.btnaddCart.enabled = NO;
  1367. }
  1368. cell.btnNotifyMe.enabled = YES;
  1369. } else { // 未缺货
  1370. cell.btnNotifyMe.enabled = NO;
  1371. cell.btnaddCart.enabled = YES;
  1372. }
  1373. // offline
  1374. #ifdef OFFLINE_MODE
  1375. if (appDelegate.offline_mode) {
  1376. cell.btnNotifyMe.hidden = YES;
  1377. }
  1378. #endif
  1379. }
  1380. #endif
  1381. #ifdef BUILD_HMLG
  1382. cell.btnaddPortfolio.hidden = NO;
  1383. cell.btnNotifyMe.hidden = YES;
  1384. #endif
  1385. }
  1386. // self.anchor_button.frame=cell.selector_Button.frame;
  1387. cell.celldelegate=self;
  1388. cell.quantity_text.text = [NSString stringWithFormat:@"%d",self.quantity];
  1389. cell.step = self.step;
  1390. cell.quantity = self.quantity;
  1391. // cell.stepper.stepValue = self.step;
  1392. // cell.stepper.value = self.quantity;
  1393. NSString* price = [section_json valueForKey:@"price"];
  1394. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1395. if(appDelegate.contact_id ==nil)
  1396. {
  1397. // appDelegate.bLogin = false;
  1398. // cell.btnaddCart.enabled = false;
  1399. }
  1400. else
  1401. {
  1402. if ([price isEqualToString:@"No Price."]) {
  1403. // cell.btnaddCart.enabled = false;
  1404. }
  1405. else
  1406. {
  1407. // cell.btnaddCart.enabled = true;
  1408. }
  1409. }
  1410. int cqty = [[section_json valueForKey:@"Model QTY in cart"] intValue];
  1411. cell.cqty = cqty;
  1412. cell.set_cqty=^(int cqty)
  1413. {
  1414. [section_json setValue:[NSString stringWithFormat:@"%d",cqty] forKey:@"Model QTY in cart"];
  1415. [self.detail_data setObject:section_json forKey:@"img_section"];
  1416. [self.detailTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  1417. };
  1418. cell.set_update_data=^(bool bupdate)
  1419. {
  1420. //self.update_data = bupdate;
  1421. #ifdef RA_NOTIFICATION
  1422. if(bupdate)
  1423. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1424. else
  1425. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1426. #else
  1427. if(bupdate)
  1428. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  1429. else
  1430. [((MainViewController*)appDelegate.main_vc) reloadCategory:false immediately:false];
  1431. #endif
  1432. };
  1433. if(cqty>0)
  1434. {
  1435. cell.cqyt_label.hidden=false;
  1436. cell.cqyt_label.text=[NSString stringWithFormat:@"Model QTY in Cart:%d",cqty];
  1437. }
  1438. else
  1439. {
  1440. cell.cqyt_label.hidden=true;
  1441. cell.cqyt_label.text=nil;
  1442. }
  1443. cell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1444. // cell.descriptionLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1445. cell.model_label.text =[section_json valueForKey:@"model_name"];
  1446. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:80];
  1447. // cell.qrcode_imageview.image = qrimg;
  1448. if(appDelegate.bLogin==true)
  1449. {
  1450. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1451. {
  1452. }
  1453. else
  1454. {
  1455. price=nil;
  1456. }
  1457. }
  1458. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1459. NSString *old_price = [section_json objectForKey:@"old_price"];
  1460. if (appDelegate.user && old_price != nil && old_price.length > 0) {
  1461. cell.priceLabel.text = nil;
  1462. NSString *new_price_str = [NSString stringWithFormat:@"%@ %@",price,old_price];
  1463. NSRange range = [new_price_str rangeOfString:@"$" options:NSBackwardsSearch];
  1464. range = NSMakeRange(range.location,new_price_str.length - range.location);
  1465. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:new_price_str];
  1466. [attrStr addAttributes:@{
  1467. NSStrikethroughStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle]
  1468. }
  1469. range:range];
  1470. cell.priceLabel.attributedText = attrStr;
  1471. } else {
  1472. cell.priceLabel.attributedText = nil;
  1473. cell.priceLabel.text =price;
  1474. }
  1475. #else
  1476. cell.priceLabel.text =price;
  1477. #endif
  1478. // cell.shipLabel.text = [section_json valueForKey:@"ship"];
  1479. cell.count_Label.text =[section_json valueForKey:@"Availability"] ;
  1480. NSString* eta =[section_json valueForKey:@"ETA"] ;
  1481. if(eta.length>0)
  1482. {
  1483. cell.eta_label.hidden = false;
  1484. cell.etaval_label.text = eta;
  1485. cell.etaval_label.hidden = false;
  1486. cell.incoming_stock_label.hidden=false;
  1487. cell.incomingcount_Label.text =[section_json valueForKey:@"incoming_stock"] ;
  1488. cell.incomingcount_Label.hidden = false;
  1489. }
  1490. else
  1491. {
  1492. cell.eta_label.hidden = true;
  1493. cell.etaval_label.text = nil;
  1494. cell.etaval_label.hidden = true;
  1495. cell.incoming_stock_label.hidden = true;
  1496. cell.incomingcount_Label.text = nil;
  1497. cell.incomingcount_Label.hidden = true;
  1498. }
  1499. self.selector = [section_json objectForKey:@"selector"];
  1500. if(self.selector!=nil)
  1501. {
  1502. [cell Hide_selector:false];
  1503. cell.selector_nameLabel.text =[self.selector valueForKey:@"name"];
  1504. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  1505. cell.selector_imageView.image = [UIImage imageNamed:@"loading_s"];
  1506. for(int i=0;i<selector_count;i++)
  1507. {
  1508. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  1509. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  1510. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  1511. {
  1512. cell.selector_valLabel.text=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"];
  1513. NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
  1514. if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
  1515. selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
  1516. cell.selector_label.text = selectstr;
  1517. NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
  1518. NSString* file_name=[img_url lastPathComponent];
  1519. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1520. if(img_data!=nil)
  1521. {
  1522. dispatch_async(dispatch_get_main_queue(), ^{
  1523. UIImage * img =[UIImage imageWithData:img_data];
  1524. cell.selector_imageView.image=img;
  1525. });
  1526. }
  1527. else
  1528. {
  1529. NSData* downloadimg_data = nil;
  1530. // BOOL offline = NO;
  1531. //#ifdef OFFLINE_MODE
  1532. // offline = appDelegate.offline_mode;
  1533. //#endif
  1534. // if (!offline) {
  1535. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1536. // }
  1537. dispatch_async(dispatch_get_main_queue(), ^{
  1538. if(downloadimg_data!=nil)
  1539. {
  1540. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1541. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1542. cell.selector_imageView.image=img;
  1543. }
  1544. else
  1545. cell.selector_imageView.image = [UIImage imageNamed:@"notfound_s"];
  1546. });
  1547. }
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. [cell Hide_selector:true];
  1554. }
  1555. // cell.selector_valLabel.text =[[section_json objectForKey:@"selector"] valueForKey:@"name"];
  1556. NSDictionary* property_json = [section_json objectForKey:@"property"];
  1557. // int pcount = [[property_json valueForKey:@"count"]intValue];
  1558. cell.property_nameLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
  1559. cell.property_valLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
  1560. cell.product_id = self.product_id;
  1561. // cell.itemIDLabel.text = [NSString stringWithFormat:@"Item id:%d",3947105];
  1562. [cell setup];
  1563. [cell ClearPhotos];
  1564. // NSDictionary* imgs_json = [section_json objectForKey:@"images"];
  1565. NSDictionary* contents_json = [section_json objectForKey:@"stack_contents"];
  1566. cell.stack_contents = contents_json;
  1567. int count = [[contents_json valueForKey:@"count"]intValue];
  1568. int hcount=2;
  1569. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1570. hcount=1; //homer 没有qrcode
  1571. #endif
  1572. if(count<hcount)//1 for qrcode;
  1573. cell.pageControl.hidden = true;
  1574. else
  1575. cell.pageControl.hidden = false;
  1576. // NSMutableArray* urls= [[NSMutableArray alloc]init];
  1577. // cell.urls = urls;
  1578. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1579. for(int i=0;i<count;i++)
  1580. {
  1581. NSDictionary* item_json=[contents_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1582. NSString* type = item_json[@"type"];
  1583. // if([type isEqualToString:@"video"])
  1584. // {
  1585. // [cell AddPhoto:[UIImage imageNamed:@"play"]];
  1586. // ;
  1587. // }
  1588. // else if([type isEqualToString:@"image"])
  1589. {
  1590. NSString* img_url = [item_json valueForKey:@"s"];
  1591. // NSString* img_url_l = [img_json valueForKey:@"l"];
  1592. // if(img_url_l.length>0)
  1593. // [urls addObject:img_url_l];
  1594. NSString* file_name=[img_url lastPathComponent];
  1595. NSData* img_data=nil;
  1596. if([type isEqualToString:@"video"])
  1597. {
  1598. img_data = UIImagePNGRepresentation([UIImage imageNamed:@"play"]);
  1599. }
  1600. else
  1601. {
  1602. if([item_json[@"is_localfile"] boolValue])
  1603. img_data = [NSData dataWithContentsOfFile:img_url];
  1604. else
  1605. img_data = [iSalesDB load_cached_img:file_name loadFrom:img_url];
  1606. }
  1607. if(img_data!=nil)
  1608. {
  1609. dispatch_async(dispatch_get_main_queue(), ^{
  1610. UIImage * img =[UIImage imageWithData:img_data];
  1611. [cell AddPhoto:img];
  1612. // if(i==count-1)
  1613. // {
  1614. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1615. // if(qrimg!=nil)
  1616. // [cell AddPhoto:qrimg];
  1617. // }
  1618. // if(i==0)
  1619. // cell.imageView.image = img;
  1620. });
  1621. }
  1622. else
  1623. {
  1624. NSData* downloadimg_data = nil;
  1625. // BOOL offline = NO;
  1626. //#ifdef OFFLINE_MODE
  1627. // offline = appDelegate.offline_mode;
  1628. //#endif
  1629. // if (!offline) {
  1630. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1631. // }
  1632. dispatch_async(dispatch_get_main_queue(), ^{
  1633. if(downloadimg_data!=nil)
  1634. {
  1635. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1636. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1637. [cell AddPhoto:img];
  1638. // if(i==count-1)
  1639. // {
  1640. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1641. // if(qrimg!=nil)
  1642. // [cell AddPhoto:qrimg];
  1643. // }
  1644. // if(i==0)
  1645. // cell.imageView.image = img;
  1646. }
  1647. else
  1648. {
  1649. UIImage * img =[UIImage imageNamed:@"notfound_l"];
  1650. [cell AddPhoto:img];
  1651. // if(i==count-1)
  1652. // {
  1653. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1654. // if(qrimg!=nil)
  1655. // [cell AddPhoto:qrimg];
  1656. // }
  1657. // if(i==0)
  1658. // cell.imageView.image = img;
  1659. }
  1660. });
  1661. }
  1662. }
  1663. }
  1664. });
  1665. // cell.backgroundColor = [UIColor whiteColor];
  1666. __weak typeof(self) weakself = self;
  1667. cell.shopCartBlock = ^(UIImageView *imageView){
  1668. self.add_cart=true;
  1669. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1670. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1671. CGRect headRect = imageView.frame;
  1672. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1673. [self startAnimationWithRect:headRect ImageView:imageView];
  1674. [self.navigationController popToRootViewControllerAnimated:false];
  1675. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1676. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1677. };
  1678. cell.WatchlistBlock = ^(UIImageView *imageView){
  1679. self.add_wish=true;
  1680. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1681. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1682. CGRect headRect = imageView.frame;
  1683. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1684. [self startAnimationWithRect:headRect ImageView:imageView];
  1685. };
  1686. cell.PortfolioBlock = ^(UIImageView *imageView){
  1687. self.add_portfolio=true;
  1688. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1689. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1690. CGRect headRect = imageView.frame;
  1691. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1692. [self startAnimationWithRect:headRect ImageView:imageView];
  1693. #ifdef RA_NOTIFICATION
  1694. [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1695. #else
  1696. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1697. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  1698. #endif
  1699. };
  1700. NSString *introduce = [section_json objectForKey:@"assembly_pdf_path"];
  1701. if (introduce == nil || introduce.length == 0) {
  1702. cell.introduceBtn.hidden = YES;
  1703. } else {
  1704. cell.introduceBtn.hidden = NO;
  1705. }
  1706. cell.introduceBlock = ^(UIButton *sender) {
  1707. [weakself showIntroducePDF:introduce];
  1708. };
  1709. NSString *desc = [section_json objectForKey:@"product_content_writing"];
  1710. if (!desc.length) {
  1711. cell.descriptionBtn.hidden = YES;
  1712. } else {
  1713. cell.descriptionBtn.hidden = NO;
  1714. NSDictionary *attrs = @{
  1715. NSFontAttributeName : [UIFont systemFontOfSize:18.0f],
  1716. NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]
  1717. };
  1718. NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:@"Read More" attributes:attrs];
  1719. [cell.descriptionBtn setAttributedTitle:attrTitle forState:UIControlStateNormal];
  1720. }
  1721. cell.descriptionBlock = ^(UIButton *sender) {
  1722. [weakself showModelDescription:desc];
  1723. };
  1724. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1725. [cell generate_information];
  1726. cell.incoming_stock_label.hidden = YES;
  1727. cell.count_Label.hidden = YES;
  1728. cell.hmlg_stock_lb.hidden = YES;
  1729. cell.hmlg_stock_count_lb.hidden = YES;
  1730. cell.incomingcount_Label.hidden = YES;
  1731. cell.eta_label.hidden = YES;
  1732. cell.etaval_label.hidden = YES;
  1733. cell.cqyt_label.hidden = YES;
  1734. #endif
  1735. return cell;
  1736. }
  1737. // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1738. // if(related_json==nil)
  1739. else
  1740. {
  1741. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  1742. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1743. NSString *CellIdentifier = @"DetailInfoCell";
  1744. NSString* type=[section_json valueForKey:@"type"] ;
  1745. if([type isEqualToString:@"kv"])
  1746. {
  1747. float width = tableView.frame.size.width;
  1748. width-=CELL_MARGIN*2;
  1749. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1750. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1751. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1752. NSString* key =[item_json valueForKey:@"key"] ;
  1753. NSString* val=[item_json valueForKey:@"val"] ;
  1754. NSString* type=[item_json valueForKey:@"type"] ;
  1755. if([type isEqualToString:@"price"])
  1756. {
  1757. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1758. {
  1759. }
  1760. else
  1761. {
  1762. val=nil;
  1763. }
  1764. }
  1765. if([val isEqual:[NSNull null]])
  1766. val=@"";
  1767. if(val==nil)
  1768. val=@"";
  1769. if([val isEqualToString:@"null"])
  1770. val=@"";
  1771. CGRect frame;
  1772. frame.size = constraintval;
  1773. frame.origin.x=0;
  1774. frame.origin.y=0;
  1775. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1776. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1777. // rtlabel.lineSpacing = 20.0;
  1778. [rtlabel setText: val];
  1779. CGSize sizeval=rtlabel.optimumSize;
  1780. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1781. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1782. float height = MAX(sizekey.height,sizeval.height);
  1783. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1784. sizekey.height = height;
  1785. sizekey.width = constraintkey.width;
  1786. // sizeval.height = height;
  1787. sizeval.width =constraintval.width;
  1788. // NSString *CellIdentifier = @"detail_item_kv";
  1789. DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1790. if(cell==nil)
  1791. DebugLog(@"cell is nil.........................");
  1792. CGRect framekey = cell.keyLabel.frame;
  1793. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  1794. framekey.origin.y=LINE_WIDTH;
  1795. framekey.size = sizekey;
  1796. cell.keyLabel.frame = framekey;
  1797. cell.keyLabel.text=key;
  1798. CGRect frameval = cell.valLabel.frame;
  1799. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  1800. frameval.origin.y=LINE_WIDTH;
  1801. frameval.size = sizeval;
  1802. cell.valLabel.frame = frameval;
  1803. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  1804. cell.valLabel.text= val;
  1805. CGPoint rcenter;
  1806. rcenter.x = width * 0.4+width * 0.6/2;
  1807. rcenter.y = height /2;
  1808. cell.valLabel.center=rcenter;
  1809. // cell.valLabel.backgroundColor =[UIColor redColor];
  1810. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  1811. // cell.backgroundColor = [UIColor whiteColor];
  1812. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1813. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1814. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1815. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1816. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1817. cell.backgroundColor = [UIColor whiteColor];
  1818. return cell;
  1819. }
  1820. else if ([type isEqualToString:@"img"])
  1821. {
  1822. DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  1823. int img_count = [[item_json valueForKey:@"count"] intValue];
  1824. double posy = 0;
  1825. for(int j=0;j<img_count;j++)
  1826. {
  1827. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  1828. float width = [[img_json valueForKey:@"width"]floatValue];
  1829. float height = [[img_json valueForKey:@"height"]floatValue];
  1830. //
  1831. UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  1832. imgview.contentMode = UIViewContentModeScaleAspectFit;
  1833. NSString* img_url = [img_json valueForKey:@"img_url"];
  1834. posy+=height*tableView.bounds.size.width / width;
  1835. NSString* file_name=[img_url lastPathComponent];
  1836. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1837. if(img_data!=nil)
  1838. {
  1839. UIImage * img =[UIImage imageWithData:img_data];
  1840. imgview.image = img;
  1841. [cell addSubview:imgview];
  1842. }
  1843. else
  1844. {
  1845. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1846. NSData* downloadimg_data = nil;
  1847. // BOOL offline = NO;
  1848. //#ifdef OFFLINE_MODE
  1849. // offline = appDelegate.offline_mode;
  1850. //#endif
  1851. // if (!offline) {
  1852. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1853. // }
  1854. dispatch_async(dispatch_get_main_queue(), ^{
  1855. if(downloadimg_data!=nil)
  1856. {
  1857. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1858. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1859. imgview.image = img;
  1860. [cell addSubview:imgview];
  1861. }
  1862. else
  1863. {
  1864. imgview.image = [UIImage imageNamed:@"notfound_l"];
  1865. [cell addSubview:imgview];
  1866. }
  1867. });
  1868. });
  1869. }
  1870. }
  1871. cell.backgroundColor = [UIColor whiteColor];
  1872. return cell;
  1873. }
  1874. else if ([type isEqualToString:@"content"])
  1875. {
  1876. NSString *CellIdentifier = @"DetailTopicCell";
  1877. NSString* data=[section_json valueForKey:@"data"] ;
  1878. if([data isEqualToString:@"local"])
  1879. {
  1880. [appDelegate.recent_model addEntriesFromDictionary:section_json];
  1881. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1882. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1883. cell.itemdelegate = self;
  1884. cell.related_data = appDelegate.recent_model;
  1885. [cell.topicCollectionView reloadData];
  1886. cell.backgroundColor = [UIColor whiteColor];
  1887. return cell;
  1888. }
  1889. else
  1890. {
  1891. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1892. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1893. cell.itemdelegate = self;
  1894. cell.related_data = section_json;
  1895. [cell.topicCollectionView reloadData];
  1896. cell.backgroundColor = [UIColor whiteColor];
  1897. return cell;
  1898. }
  1899. }
  1900. return nil;
  1901. }
  1902. }
  1903. -(void)startAnimationWithRect:(CGRect)rect ImageView:(UIImageView *)imageView
  1904. {
  1905. if (!_layer) {
  1906. // _btn.enabled = NO;
  1907. _layer = [CALayer layer];
  1908. _layer.contents = (id)imageView.layer.contents;
  1909. _layer.contentsGravity = kCAGravityResizeAspectFill;
  1910. _layer.bounds = rect;
  1911. [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
  1912. _layer.masksToBounds = YES;
  1913. // 导航64
  1914. _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
  1915. // [_tableView.layer addSublayer:_layer];
  1916. [self.view.layer addSublayer:_layer];
  1917. self.path = [UIBezierPath bezierPath];
  1918. // [_path moveToPoint:_layer.position];
  1919. [_path moveToPoint:imageView.center];
  1920. [_path addLineToPoint:CGPointMake(imageView.center.x, imageView.center.y-100)];
  1921. // (SCREEN_WIDTH - 60), 0, 50, 50)
  1922. // [_path addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH - 40, SCREEN_HEIGHT-40) controlPoint:CGPointMake(SCREEN_WIDTH/2,rect.origin.y-80)];
  1923. // [_path addLineToPoint:CGPointMake(SCREEN_WIDTH-40, 30)];
  1924. }
  1925. [self groupAnimation];
  1926. }
  1927. -(void)groupAnimation
  1928. {
  1929. self.detailTable.userInteractionEnabled = NO;
  1930. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  1931. animation.path = _path.CGPath;
  1932. // animation.rotationMode = kCAAnimationRotateAuto;
  1933. //
  1934. CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1935. expandAnimation.duration = 0.3f;
  1936. expandAnimation.fromValue = [NSNumber numberWithFloat:1];
  1937. expandAnimation.toValue = [NSNumber numberWithFloat:2.0f];
  1938. expandAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  1939. CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1940. narrowAnimation.beginTime = 0.3;
  1941. narrowAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
  1942. narrowAnimation.duration = 0.9f;
  1943. narrowAnimation.toValue = [NSNumber numberWithFloat:0.3f];
  1944. //
  1945. // narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  1946. CAAnimationGroup *groups = [CAAnimationGroup animation];
  1947. groups.animations = @[animation,expandAnimation,narrowAnimation];
  1948. groups.duration = 1.0f;
  1949. groups.removedOnCompletion=NO;
  1950. groups.fillMode=kCAFillModeForwards;
  1951. groups.delegate = self;
  1952. [_layer addAnimation:groups forKey:@"group"];
  1953. }
  1954. -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  1955. {
  1956. // [anim def];
  1957. if (anim == [_layer animationForKey:@"group"]) {
  1958. self.detailTable.userInteractionEnabled = YES;
  1959. // _btn.enabled = YES;
  1960. [_layer removeFromSuperlayer];
  1961. _layer = nil;
  1962. // _cnt++;
  1963. // if (_cnt) {
  1964. // _cntLabel.hidden = NO;
  1965. // }
  1966. // CATransition *animation = [CATransition animation];
  1967. // animation.duration = 0.25f;
  1968. // _cntLabel.text = [NSString stringWithFormat:@"%d",_cnt];
  1969. // [_cntLabel.layer addAnimation:animation forKey:nil];
  1970. // CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  1971. // shakeAnimation.duration = 0.25f;
  1972. // shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
  1973. // shakeAnimation.toValue = [NSNumber numberWithFloat:5];
  1974. // shakeAnimation.autoreverses = YES;
  1975. // [_btn.layer addAnimation:shakeAnimation forKey:nil];
  1976. }
  1977. }
  1978. #pragma mark - hide section button clicked
  1979. - (void)RefreshSection:(UIButton *)sender {
  1980. sender.enabled=false;
  1981. NSDictionary* section_json = nil;
  1982. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1983. if(related_json==nil)
  1984. {
  1985. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(sender.tag-1)]];
  1986. }
  1987. else
  1988. {
  1989. if(sender.tag==1)
  1990. {
  1991. section_json = related_json ;
  1992. }
  1993. else
  1994. {
  1995. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)sender.tag-2]];
  1996. }
  1997. }
  1998. NSString* url = section_json[@"data_interface"];
  1999. NSMutableDictionary* params = [section_json[@"params"] mutableCopy];
  2000. if(params==nil)
  2001. params = [[NSMutableDictionary alloc] init];
  2002. NSUInteger ii[2] = {sender.tag,0};
  2003. NSIndexPath* indexpath= [NSIndexPath indexPathWithIndexes:ii length:2];
  2004. DetailTopicCell * cell=[self.detailTable cellForRowAtIndexPath:indexpath];
  2005. [cell begin_refresh];
  2006. // UIAlertController * waitalert = [RAUtils waiting_alert:selftitle:@"Refreshing"];
  2007. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  2008. NSDictionary* editor_json =result;
  2009. [cell end_refresh ];
  2010. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2011. sender.enabled=true;
  2012. if([[editor_json valueForKey:@"result"] intValue]==2)
  2013. {
  2014. [self.detail_data addEntriesFromDictionary:editor_json];
  2015. NSRange range = NSMakeRange(sender.tag, 1);
  2016. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  2017. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  2018. }
  2019. else
  2020. {
  2021. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  2022. }
  2023. }];
  2024. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2025. //
  2026. // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  2027. //
  2028. // dispatch_async(dispatch_get_main_queue(), ^{
  2029. // [cell end_refresh ];
  2030. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2031. // sender.enabled=true;
  2032. //
  2033. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2034. // {
  2035. //
  2036. // [self.detail_data addEntriesFromDictionary:editor_json];
  2037. //
  2038. // NSRange range = NSMakeRange(sender.tag, 1);
  2039. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  2040. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  2041. //
  2042. // }
  2043. // else
  2044. // {
  2045. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  2046. // }
  2047. //
  2048. //
  2049. // });
  2050. // });
  2051. // self.showMore=!self.showMore;
  2052. // NSRange range = NSMakeRange(1, 1);
  2053. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  2054. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  2055. }
  2056. #pragma mark - Support scanner
  2057. -(void) onDecodedData:(NSString*) value
  2058. {
  2059. // UIApplication * app = [UIApplication sharedApplication];
  2060. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2061. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2062. //
  2063. self.model_name = value;
  2064. self.product_id = nil;
  2065. self.use_model_name = true;
  2066. [self reload];
  2067. DebugLog(@"color selected");
  2068. }
  2069. #pragma mark - Handle Notification
  2070. - (void)dealloc {
  2071. [[NSNotificationCenter defaultCenter] removeObserver:self];
  2072. }
  2073. - (void)registeObserver {
  2074. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoRightMsg:) name:No_Rights_Notification object:nil];
  2075. }
  2076. - (void)handleNoRightMsg:(NSNotification *)notification {
  2077. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You have no rights to do that." preferredStyle:UIAlertControllerStyleAlert];
  2078. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2079. [alertController dismissViewControllerAnimated:YES completion:nil];
  2080. }];
  2081. [alertController addAction:action];
  2082. [self presentViewController:alertController animated:YES completion:nil];
  2083. }
  2084. #pragma mark - action
  2085. - (void)showEmailAddrBox {
  2086. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  2087. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  2088. emailAddrVC.textFiled.secureTextEntry = NO;
  2089. emailAddrVC.yesButtonTitle = @"send";
  2090. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  2091. __weak typeof(self) weakself = self;
  2092. emailAddrVC.textHandler = ^(NSString *text){
  2093. // 验证邮箱格式是否正确
  2094. // NSString *match = EMAIL_MATCHES;
  2095. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  2096. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  2097. BOOL isEmailAddr = YES;
  2098. if (isEmailAddr) {
  2099. // 验证是邮件地址,发送邮件
  2100. [weakVC dismissViewControllerAnimated:YES completion:^{
  2101. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  2102. [RANetwork request_notifymodel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  2103. DebugLog(@"email cart result: %@",result);
  2104. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  2105. int resultStatus = [[result objectForKey:@"result"] intValue];
  2106. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  2107. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2108. if ([result valueForKey:@"err_msg"]) {
  2109. msg = [result valueForKey:@"err_msg"];
  2110. }
  2111. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2112. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2113. }];
  2114. [errorAlertVC addAction:action];
  2115. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2116. }else if(resultStatus == RESULT_TRUE){
  2117. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  2118. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  2119. [weakself showEmailAddrBox];
  2120. }
  2121. }];
  2122. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2123. }];
  2124. }];
  2125. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  2126. //
  2127. // NSDictionary *result = [RANetwork notifyModel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo];
  2128. // DebugLog(@"email cart result: %@",result);
  2129. // dispatch_async(dispatch_get_main_queue(), ^{
  2130. //
  2131. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  2132. //
  2133. // int resultStatus = [[result objectForKey:@"result"] intValue];
  2134. // if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  2135. //
  2136. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  2137. // if ([result valueForKey:@"err_msg"]) {
  2138. // msg = [result valueForKey:@"err_msg"];
  2139. // }
  2140. //
  2141. //
  2142. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  2143. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2144. //
  2145. // }];
  2146. //
  2147. // [errorAlertVC addAction:action];
  2148. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  2149. //
  2150. // }else if(resultStatus == RESULT_TRUE){
  2151. //
  2152. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  2153. //
  2154. // } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  2155. //
  2156. // [weakself showEmailAddrBox];
  2157. //
  2158. // }
  2159. //
  2160. // });
  2161. //
  2162. // });
  2163. }];
  2164. } else {
  2165. // 非邮件地址,警告
  2166. [weakVC warning:@"Please enter right email address"];
  2167. }
  2168. };
  2169. [self presentViewController:emailAddrVC animated:YES completion:nil];
  2170. }
  2171. - (void)showIntroducePDF:(NSString *)link {
  2172. if (link.length == 0) {
  2173. [RAUtils message_alert:@"There is no resource to open" title:@"Warning" controller:self];
  2174. return;
  2175. }
  2176. NSArray *tmpArr = [link componentsSeparatedByString:@"="];
  2177. BOOL isLocalFile = NO;
  2178. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  2179. NSString *name = [section_json valueForKey:@"model_name"];
  2180. NSString *path = [NSString stringWithFormat:@"%@/Introduce/%@.pdf",[RAUtils appCacheDirectory],tmpArr.lastObject];
  2181. if ([RAUtils fileExistsAtPath:path]) { // 检查缓存
  2182. isLocalFile = YES;
  2183. link = path;
  2184. } else {
  2185. // 创建缓存目录
  2186. NSString *dir = [path stringByDeletingLastPathComponent];
  2187. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  2188. }
  2189. name = [NSString stringWithFormat:@"%@ Assembly Instruction",name];
  2190. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  2191. ViewController.url = link;
  2192. ViewController.canSave = false;
  2193. ViewController.isLocalfile=isLocalFile;
  2194. ViewController.cachePath = path;
  2195. NSString* subject = name;
  2196. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2197. NSString* customer_email = [appDelegate.customerInfo valueForKey:@"customer_email"];
  2198. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  2199. if(customer_email.length>0)
  2200. {
  2201. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  2202. }
  2203. ViewController.mail_to = send_to;
  2204. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",name];
  2205. ViewController.mail_subject = subject;
  2206. ViewController.hidenavi = false;
  2207. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
  2208. // nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  2209. // CGSize size = [UIScreen mainScreen].bounds.size;
  2210. // nav.preferredContentSize = CGSizeMake(size.width * 0.8, size.height * 0.8);
  2211. [self.navigationController pushViewController:ViewController animated:YES];
  2212. }
  2213. - (void)showModelDescription:(NSString *)desc {
  2214. ModelDescriptionController *vc = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ModelDescriptionController"];
  2215. vc.model_desc = desc;
  2216. vc.title = [NSString stringWithFormat:@"%@ Description",self.model_name];
  2217. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  2218. nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  2219. nav.preferredContentSize = CGSizeMake(400, 380);// 只有在 UIModalPresentationFormSheet 的时候起作用
  2220. [self presentViewController:nav animated:YES completion:nil];
  2221. }
  2222. - (void)reRefreshView {
  2223. [self.detailTable reloadData];
  2224. }
  2225. #pragma mark - RA_NOTIFICAITON
  2226. -(void) refresh_ui
  2227. {
  2228. [self.detailTable reloadData];
  2229. }
  2230. -(void) reload_data
  2231. {
  2232. [self reload];
  2233. }
  2234. -(void) refresh_price
  2235. {
  2236. [self refresh_ui];
  2237. }
  2238. @end