DetailViewController.m 90 KB

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