DetailViewController.m 101 KB

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