DetailViewController.m 117 KB

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