DetailViewController.m 112 KB

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