DetailViewController.m 98 KB

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