DetailViewController.m 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586
  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 0
  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. CGSize sizeval=rtlabel.optimumSize;
  786. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  787. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  788. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  789. float height = MAX(sizekey.height,sizeval.height);
  790. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  791. return height;
  792. }
  793. else if([type isEqualToString:@"img"])
  794. {
  795. int img_count = [[item_json valueForKey:@"count"] intValue];
  796. double ret = 0;
  797. for(int j=0;j<img_count;j++)
  798. {
  799. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  800. float width = [[img_json valueForKey:@"width"]floatValue];
  801. float height = [[img_json valueForKey:@"height"]floatValue];
  802. ret+=height*tableView.bounds.size.width / width;
  803. }
  804. return ret;
  805. }
  806. else if([type isEqualToString:@"content"])
  807. return 270;
  808. return 44;
  809. }
  810. else
  811. {
  812. if(indexPath.section==1)
  813. return 270;
  814. else
  815. {
  816. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-2]];
  817. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  818. NSString* type=[section_json valueForKey:@"type"] ;
  819. if([type isEqualToString:@"kv"])
  820. {
  821. float width = tableView.frame.size.width;
  822. width-=CELL_MARGIN*2;
  823. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  824. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  825. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  826. NSString* key =[item_json valueForKey:@"key"] ;
  827. // [cell.keyLabel sizeToFit];
  828. NSString* val=[item_json valueForKey:@"val"] ;
  829. if([val isEqual:[NSNull null]])
  830. val=@"";
  831. if(val==nil)
  832. val=@"";
  833. if([val isEqualToString:@"null"])
  834. val=@"";
  835. CGRect frame;
  836. frame.size = constraintval;
  837. frame.origin.x=0;
  838. frame.origin.y=0;
  839. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  840. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  841. // rtlabel.lineSpacing = 20.0;
  842. [rtlabel setText: val];
  843. CGSize sizeval=rtlabel.optimumSize;
  844. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  845. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  846. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  847. float height = MAX(sizekey.height,sizeval.height);
  848. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  849. return height;
  850. }
  851. else if([type isEqualToString:@"img"])
  852. {
  853. int img_count = [[item_json valueForKey:@"count"] intValue];
  854. double ret = 0;
  855. for(int j=0;j<img_count;j++)
  856. {
  857. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  858. float width = [[img_json valueForKey:@"width"]floatValue];
  859. float height = [[img_json valueForKey:@"height"]floatValue];
  860. ret+=height*tableView.bounds.size.width / width;
  861. }
  862. return ret;
  863. }
  864. return 44;
  865. }
  866. }
  867. }
  868. - (BOOL)isOutofStock {
  869. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  870. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  871. // 2018-01-10 修改通过lowercase判断
  872. if (!qtyStr || !qtyStr.length || [qtyStr.lowercaseString isEqualToString:@"in production"] || [qtyStr isEqualToString:@"0"] || [qtyStr.lowercaseString isEqualToString:@"sold out"] || [qtyStr.lowercaseString isEqualToString:@"out of stock"]) {
  873. return YES;
  874. }
  875. return NO;
  876. }
  877. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  878. {
  879. // DebugLog(@"cellForRowAtIndexPath");
  880. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  881. if(indexPath.section==0)
  882. {
  883. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  884. NSString *CellIdentifier = @"HomerModelDetailHeaderCell";
  885. HomerModelDetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  886. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
  887. CGFloat w = CGRectGetWidth(tableView.bounds);
  888. CGFloat h = CGRectGetHeight(tableView.bounds);
  889. CGFloat space_w = w - 320;
  890. CGFloat photoStackWidth = space_w - (35 * 2);
  891. CGFloat photoStackHeight = h - 102 - 70;
  892. CGFloat a = MIN(photoStackWidth, photoStackHeight);
  893. CGFloat x = (space_w - a) * 0.5, y = 102 + (photoStackHeight - a) * 0.5;
  894. if (x > 50) {
  895. x -= 20;
  896. }
  897. cell.photoStack.frame = CGRectMake(x, y, a, a);
  898. cell.pageControl.frame = CGRectMake((space_w - 319) * 0.5, h - 50, 319, 37);
  899. } else {
  900. cell.photoStack.frame = CGRectMake(35, 107, 349, 348);
  901. cell.pageControl.frame = CGRectMake(50, 466, 319, 37);
  902. }
  903. #else
  904. NSString *CellIdentifier = @"DetailHeaderCell";
  905. DetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  906. cell.btn_hangtag.hidden = YES;
  907. #endif
  908. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  909. // Homer添加的View
  910. cell.hmlg_stock_lb.hidden = YES;
  911. cell.hmlg_stock_count_lb.hidden = YES;
  912. cell.on_sale_lb.hidden = YES;
  913. if (!RASingleton.sharedInstance.user) { // 没有登录时隐藏add to portfolio,使add to cart与add to wishlist对齐
  914. cell.btnaddPortfolio.hidden = YES;
  915. cell.btnNotifyMe.hidden = YES;
  916. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  917. // cell.hmlg_stock_lb.hidden = NO;
  918. // cell.hmlg_stock_count_lb.hidden = NO;
  919. BOOL is_special_model = [[section_json objectForKey:@"is_special_model"] boolValue];
  920. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  921. if (hmlg_stock == nil) {
  922. hmlg_stock = @"";
  923. }
  924. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  925. cell.on_sale_lb.hidden = !is_special_model;
  926. #endif
  927. } else {
  928. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  929. // NSString *qtyStr = [section_json valueForKey:@"Availability"];
  930. __weak typeof(self) weakself = self;
  931. cell.notifyMeBlock = ^{
  932. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  933. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  934. [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  935. NSMutableDictionary *dic =result;
  936. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  937. [pop hide];
  938. int result_code = [[dic valueForKey:@"result"] intValue];
  939. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS) {
  940. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  941. if ([dic valueForKey:@"err_msg"]) {
  942. msg = [dic valueForKey:@"err_msg"];
  943. }
  944. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  945. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  946. }];
  947. [errorAlertVC addAction:action];
  948. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  949. } else if (result_code == RESULT_TRUE){
  950. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  951. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  952. [self showEmailAddrBox];
  953. }
  954. // }];
  955. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  956. }];
  957. // }];
  958. };
  959. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  960. cell.btnaddPortfolio.hidden = YES;
  961. if (!notifyMe_switch) {
  962. cell.btnNotifyMe.hidden = YES;
  963. } else {
  964. cell.btnNotifyMe.hidden = NO;
  965. if (!appDelegate.order_code) { // 未打开订单状态
  966. if ([self isOutofStock]) {
  967. if (!appDelegate.can_create_backorder) {
  968. cell.btnaddCart.enabled = NO;
  969. }
  970. cell.btnNotifyMe.enabled = YES;
  971. } else {
  972. cell.btnaddCart.enabled = YES;
  973. cell.btnNotifyMe.enabled = NO;
  974. }
  975. } else {
  976. // 打开订单状态
  977. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  978. // Shop Order
  979. cell.btnaddCart.enabled = YES;
  980. // 默认未缺货
  981. cell.btnNotifyMe.enabled = NO;
  982. if ([self isOutofStock]) { // 缺货
  983. cell.btnNotifyMe.enabled = YES;
  984. }
  985. } else {
  986. // Purchase Order
  987. if ([self isOutofStock]) { // 缺货
  988. if (!appDelegate.can_create_backorder) {
  989. cell.btnaddCart.enabled = NO;
  990. }
  991. cell.btnNotifyMe.enabled = YES;
  992. } else { // 未缺货
  993. cell.btnNotifyMe.enabled = NO;
  994. cell.btnaddCart.enabled = YES;
  995. }
  996. }
  997. }
  998. }
  999. } else { // employee
  1000. // online
  1001. cell.btnaddPortfolio.hidden = NO;
  1002. cell.btnNotifyMe.hidden = NO;
  1003. if ([self isOutofStock]) { // 缺货
  1004. if (!appDelegate.can_create_backorder) {
  1005. cell.btnaddCart.enabled = NO;
  1006. }
  1007. cell.btnNotifyMe.enabled = YES;
  1008. } else { // 未缺货
  1009. cell.btnNotifyMe.enabled = NO;
  1010. cell.btnaddCart.enabled = YES;
  1011. }
  1012. // offline
  1013. #ifdef OFFLINE_MODE
  1014. if (appDelegate.offline_mode) {
  1015. cell.btnNotifyMe.hidden = YES;
  1016. }
  1017. #endif
  1018. }
  1019. #endif
  1020. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1021. // cell.hmlg_stock_lb.hidden = NO;
  1022. // cell.hmlg_stock_count_lb.hidden = NO;
  1023. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  1024. if (hmlg_stock == nil) {
  1025. hmlg_stock = @"";
  1026. }
  1027. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  1028. cell.on_sale_lb.hidden = !is_special_model;
  1029. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  1030. __weak typeof(self) weakself = self;
  1031. cell.notifyMeBlock = ^{
  1032. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1033. [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  1034. NSMutableDictionary *dic =result;
  1035. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1036. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  1037. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  1038. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1039. if ([dic valueForKey:@"err_msg"]) {
  1040. msg = [dic valueForKey:@"err_msg"];
  1041. }
  1042. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1043. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1044. }];
  1045. [errorAlertVC addAction:action];
  1046. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1047. } else if (result == RESULT_TRUE){
  1048. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  1049. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  1050. [self showEmailAddrBox];
  1051. }
  1052. }];
  1053. };
  1054. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1055. cell.btnaddPortfolio.hidden = YES;
  1056. if (!notifyMe_switch) {
  1057. cell.btnNotifyMe.hidden = YES;
  1058. } else {
  1059. cell.btnNotifyMe.hidden = NO;
  1060. if (!appDelegate.order_code) { // 未打开订单状态
  1061. if ([self isOutofStock]) {
  1062. if (!appDelegate.can_create_backorder) {
  1063. cell.btnaddCart.enabled = NO;
  1064. }
  1065. cell.btnNotifyMe.enabled = YES;
  1066. } else {
  1067. cell.btnaddCart.enabled = YES;
  1068. cell.btnNotifyMe.enabled = NO;
  1069. }
  1070. } else {
  1071. // 打开订单状态
  1072. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1073. // Shop Order
  1074. cell.btnaddCart.enabled = YES;
  1075. // 默认未缺货
  1076. cell.btnNotifyMe.enabled = NO;
  1077. if ([self isOutofStock]) { // 缺货
  1078. cell.btnNotifyMe.enabled = YES;
  1079. }
  1080. } else {
  1081. // Purchase Order
  1082. if ([self isOutofStock]) { // 缺货
  1083. if (!appDelegate.can_create_backorder) {
  1084. cell.btnaddCart.enabled = NO;
  1085. }
  1086. cell.btnNotifyMe.enabled = YES;
  1087. } else { // 未缺货
  1088. cell.btnNotifyMe.enabled = NO;
  1089. cell.btnaddCart.enabled = YES;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. } else { // employee
  1095. // online
  1096. cell.btnaddPortfolio.hidden = NO;
  1097. cell.btnNotifyMe.hidden = NO;
  1098. if ([self isOutofStock]) { // 缺货
  1099. if (!appDelegate.can_create_backorder) {
  1100. cell.btnaddCart.enabled = NO;
  1101. }
  1102. cell.btnNotifyMe.enabled = YES;
  1103. } else { // 未缺货
  1104. cell.btnNotifyMe.enabled = NO;
  1105. cell.btnaddCart.enabled = YES;
  1106. }
  1107. // offline
  1108. #ifdef OFFLINE_MODE
  1109. if (appDelegate.offline_mode) {
  1110. cell.btnNotifyMe.hidden = YES;
  1111. }
  1112. #endif
  1113. }
  1114. #endif
  1115. #ifdef BUILD_HMLG
  1116. cell.btnaddPortfolio.hidden = NO;
  1117. cell.btnNotifyMe.hidden = YES;
  1118. #endif
  1119. }
  1120. // self.anchor_button.frame=cell.selector_Button.frame;
  1121. cell.celldelegate=self;
  1122. cell.quantity_text.text = [NSString stringWithFormat:@"%d",self.quantity];
  1123. cell.step = self.step;
  1124. cell.quantity = self.quantity;
  1125. // cell.stepper.stepValue = self.step;
  1126. // cell.stepper.value = self.quantity;
  1127. NSString* price = [section_json valueForKey:@"price"];
  1128. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1129. if(appDelegate.contact_id ==nil)
  1130. {
  1131. // appDelegate.bLogin = false;
  1132. // cell.btnaddCart.enabled = false;
  1133. }
  1134. else
  1135. {
  1136. if ([price isEqualToString:@"No Price."]) {
  1137. // cell.btnaddCart.enabled = false;
  1138. }
  1139. else
  1140. {
  1141. // cell.btnaddCart.enabled = true;
  1142. }
  1143. }
  1144. int cqty = [[section_json valueForKey:@"Model QTY in cart"] intValue];
  1145. cell.cqty = cqty;
  1146. cell.set_cqty=^(int cqty)
  1147. {
  1148. [section_json setValue:[NSString stringWithFormat:@"%d",cqty] forKey:@"Model QTY in cart"];
  1149. [self.detail_data setObject:section_json forKey:@"img_section"];
  1150. [self.detailTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  1151. };
  1152. cell.set_update_data=^(bool bupdate)
  1153. {
  1154. //self.update_data = bupdate;
  1155. #ifdef RA_NOTIFICATION
  1156. if(bupdate)
  1157. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1158. else
  1159. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1160. #else
  1161. if(bupdate)
  1162. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  1163. else
  1164. [((MainViewController*)appDelegate.main_vc) reloadCategory:false immediately:false];
  1165. #endif
  1166. };
  1167. if(cqty>0)
  1168. {
  1169. cell.cqyt_label.hidden=false;
  1170. cell.cqyt_label.text=[NSString stringWithFormat:@"Model QTY in Cart:%d",cqty];
  1171. }
  1172. else
  1173. {
  1174. cell.cqyt_label.hidden=true;
  1175. cell.cqyt_label.text=nil;
  1176. }
  1177. cell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1178. // cell.descriptionLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1179. cell.model_label.text =[section_json valueForKey:@"model_name"];
  1180. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:80];
  1181. // cell.qrcode_imageview.image = qrimg;
  1182. if(appDelegate.bLogin==true)
  1183. {
  1184. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1185. {
  1186. }
  1187. else
  1188. {
  1189. price=nil;
  1190. }
  1191. }
  1192. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1193. NSString *old_price = [section_json objectForKey:@"old_price"];
  1194. if (RASingleton.sharedInstance.user && old_price != nil && old_price.length > 0) {
  1195. cell.priceLabel.text = nil;
  1196. NSString *new_price_str = [NSString stringWithFormat:@"%@ %@",price,old_price];
  1197. NSRange range = [new_price_str rangeOfString:@"$" options:NSBackwardsSearch];
  1198. range = NSMakeRange(range.location,new_price_str.length - range.location);
  1199. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:new_price_str];
  1200. [attrStr addAttributes:@{
  1201. NSStrikethroughStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle]
  1202. }
  1203. range:range];
  1204. cell.priceLabel.attributedText = attrStr;
  1205. } else {
  1206. cell.priceLabel.attributedText = nil;
  1207. cell.priceLabel.text =price;
  1208. }
  1209. #else
  1210. cell.priceLabel.text =price;
  1211. #endif
  1212. // cell.shipLabel.text = [section_json valueForKey:@"ship"];
  1213. cell.count_Label.text =[section_json valueForKey:@"Availability"] ;
  1214. NSString* eta =[section_json valueForKey:@"ETA"] ;
  1215. if(eta.length>0)
  1216. {
  1217. cell.eta_label.hidden = false;
  1218. cell.etaval_label.text = eta;
  1219. cell.etaval_label.hidden = false;
  1220. cell.incoming_stock_label.hidden=false;
  1221. cell.incomingcount_Label.text =[section_json valueForKey:@"incoming_stock"] ;
  1222. cell.incomingcount_Label.hidden = false;
  1223. }
  1224. else
  1225. {
  1226. cell.eta_label.hidden = true;
  1227. cell.etaval_label.text = nil;
  1228. cell.etaval_label.hidden = true;
  1229. cell.incoming_stock_label.hidden = true;
  1230. cell.incomingcount_Label.text = nil;
  1231. cell.incomingcount_Label.hidden = true;
  1232. }
  1233. self.selector = [section_json objectForKey:@"selector"];
  1234. if(self.selector!=nil)
  1235. {
  1236. [cell Hide_selector:false];
  1237. cell.selector_nameLabel.text =[self.selector valueForKey:@"name"];
  1238. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  1239. cell.selector_imageView.image = [UIImage imageNamed:@"loading_s"];
  1240. for(int i=0;i<selector_count;i++)
  1241. {
  1242. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  1243. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  1244. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  1245. {
  1246. cell.selector_valLabel.text=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"];
  1247. NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
  1248. if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
  1249. selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
  1250. cell.selector_label.text = selectstr;
  1251. NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
  1252. NSString* file_name=[img_url lastPathComponent];
  1253. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  1254. if(img_data!=nil)
  1255. {
  1256. dispatch_async(dispatch_get_main_queue(), ^{
  1257. UIImage * img =[UIImage imageWithData:img_data];
  1258. cell.selector_imageView.image=img;
  1259. });
  1260. }
  1261. else
  1262. {
  1263. NSData* downloadimg_data = nil;
  1264. // BOOL offline = NO;
  1265. //#ifdef OFFLINE_MODE
  1266. // offline = appDelegate.offline_mode;
  1267. //#endif
  1268. // if (!offline) {
  1269. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1270. // }
  1271. dispatch_async(dispatch_get_main_queue(), ^{
  1272. if(downloadimg_data!=nil)
  1273. {
  1274. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1275. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1276. cell.selector_imageView.image=img;
  1277. }
  1278. else
  1279. cell.selector_imageView.image = [UIImage imageNamed:@"notfound_s"];
  1280. });
  1281. }
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. [cell Hide_selector:true];
  1288. }
  1289. // cell.selector_valLabel.text =[[section_json objectForKey:@"selector"] valueForKey:@"name"];
  1290. NSDictionary* property_json = [section_json objectForKey:@"property"];
  1291. // int pcount = [[property_json valueForKey:@"count"]intValue];
  1292. cell.property_nameLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
  1293. cell.property_valLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
  1294. cell.product_id = self.product_id;
  1295. // cell.itemIDLabel.text = [NSString stringWithFormat:@"Item id:%d",3947105];
  1296. [cell setup];
  1297. [cell ClearPhotos];
  1298. // NSDictionary* imgs_json = [section_json objectForKey:@"images"];
  1299. NSDictionary* contents_json = [section_json objectForKey:@"stack_contents"];
  1300. cell.stack_contents = contents_json;
  1301. int count = [[contents_json valueForKey:@"count"]intValue];
  1302. int hcount=2;
  1303. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1304. hcount=1; //homer 没有qrcode
  1305. #endif
  1306. if(count<hcount)//1 for qrcode;
  1307. cell.pageControl.hidden = true;
  1308. else
  1309. cell.pageControl.hidden = false;
  1310. // NSMutableArray* urls= [[NSMutableArray alloc]init];
  1311. // cell.urls = urls;
  1312. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1313. for(int i=0;i<count;i++)
  1314. {
  1315. NSDictionary* item_json=[contents_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1316. NSString* type = item_json[@"type"];
  1317. // if([type isEqualToString:@"video"])
  1318. // {
  1319. // [cell AddPhoto:[UIImage imageNamed:@"play"]];
  1320. // ;
  1321. // }
  1322. // else if([type isEqualToString:@"image"])
  1323. {
  1324. NSString* img_url = [item_json valueForKey:@"s"];
  1325. // NSString* img_url_l = [img_json valueForKey:@"l"];
  1326. // if(img_url_l.length>0)
  1327. // [urls addObject:img_url_l];
  1328. NSString* file_name=[img_url lastPathComponent];
  1329. NSData* img_data=nil;
  1330. if([type isEqualToString:@"video"])
  1331. {
  1332. img_data = UIImagePNGRepresentation([UIImage imageNamed:@"play"]);
  1333. }
  1334. else
  1335. {
  1336. if([item_json[@"is_localfile"] boolValue])
  1337. img_data = [NSData dataWithContentsOfFile:img_url];
  1338. else
  1339. img_data = [FileCache load_cached_img:file_name loadFrom:img_url];
  1340. }
  1341. if(img_data!=nil)
  1342. {
  1343. dispatch_async(dispatch_get_main_queue(), ^{
  1344. UIImage * img =[UIImage imageWithData:img_data];
  1345. [cell AddPhoto:img];
  1346. // if(i==count-1)
  1347. // {
  1348. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1349. // if(qrimg!=nil)
  1350. // [cell AddPhoto:qrimg];
  1351. // }
  1352. // if(i==0)
  1353. // cell.imageView.image = img;
  1354. });
  1355. }
  1356. else
  1357. {
  1358. NSData* downloadimg_data = nil;
  1359. // BOOL offline = NO;
  1360. //#ifdef OFFLINE_MODE
  1361. // offline = appDelegate.offline_mode;
  1362. //#endif
  1363. // if (!offline) {
  1364. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1365. // }
  1366. dispatch_async(dispatch_get_main_queue(), ^{
  1367. if(downloadimg_data!=nil)
  1368. {
  1369. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1370. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1371. [cell AddPhoto:img];
  1372. // if(i==count-1)
  1373. // {
  1374. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1375. // if(qrimg!=nil)
  1376. // [cell AddPhoto:qrimg];
  1377. // }
  1378. // if(i==0)
  1379. // cell.imageView.image = img;
  1380. }
  1381. else
  1382. {
  1383. UIImage * img =[UIImage imageNamed:@"notfound_l"];
  1384. [cell AddPhoto:img];
  1385. // if(i==count-1)
  1386. // {
  1387. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1388. // if(qrimg!=nil)
  1389. // [cell AddPhoto:qrimg];
  1390. // }
  1391. // if(i==0)
  1392. // cell.imageView.image = img;
  1393. }
  1394. });
  1395. }
  1396. }
  1397. }
  1398. });
  1399. // cell.backgroundColor = [UIColor whiteColor];
  1400. __weak typeof(self) weakself = self;
  1401. cell.shopCartBlock = ^(UIImageView *imageView){
  1402. self.add_cart=true;
  1403. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1404. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1405. CGRect headRect = imageView.frame;
  1406. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1407. [self startAnimationWithRect:headRect ImageView:imageView];
  1408. [self.navigationController popToRootViewControllerAnimated:false];
  1409. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1410. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1411. };
  1412. cell.WatchlistBlock = ^(UIImageView *imageView){
  1413. self.add_wish=true;
  1414. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1415. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1416. CGRect headRect = imageView.frame;
  1417. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1418. [self startAnimationWithRect:headRect ImageView:imageView];
  1419. };
  1420. cell.PortfolioBlock = ^(UIImageView *imageView){
  1421. self.add_portfolio=true;
  1422. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1423. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1424. CGRect headRect = imageView.frame;
  1425. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1426. [self startAnimationWithRect:headRect ImageView:imageView];
  1427. #ifdef RA_NOTIFICATION
  1428. [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1429. #else
  1430. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1431. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  1432. #endif
  1433. };
  1434. NSString *introduce = [section_json objectForKey:@"assembly_pdf_path"];
  1435. if (introduce == nil || introduce.length == 0) {
  1436. cell.introduceBtn.hidden = YES;
  1437. } else {
  1438. cell.introduceBtn.hidden = NO;
  1439. }
  1440. cell.introduceBlock = ^(UIButton *sender) {
  1441. [weakself showIntroducePDF:introduce];
  1442. };
  1443. NSString *desc = [section_json objectForKey:@"product_content_writing"];
  1444. if (!desc.length) {
  1445. cell.descriptionBtn.hidden = YES;
  1446. } else {
  1447. cell.descriptionBtn.hidden = NO;
  1448. NSDictionary *attrs = @{
  1449. NSFontAttributeName : [UIFont systemFontOfSize:18.0f],
  1450. NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]
  1451. };
  1452. NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:@"Read More" attributes:attrs];
  1453. [cell.descriptionBtn setAttributedTitle:attrTitle forState:UIControlStateNormal];
  1454. }
  1455. cell.descriptionBlock = ^(UIButton *sender) {
  1456. [weakself showModelDescription:desc];
  1457. };
  1458. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1459. [cell generate_information];
  1460. cell.incoming_stock_label.hidden = YES;
  1461. cell.count_Label.hidden = YES;
  1462. cell.hmlg_stock_lb.hidden = YES;
  1463. cell.hmlg_stock_count_lb.hidden = YES;
  1464. cell.incomingcount_Label.hidden = YES;
  1465. cell.eta_label.hidden = YES;
  1466. cell.etaval_label.hidden = YES;
  1467. cell.cqyt_label.hidden = YES;
  1468. #endif
  1469. return cell;
  1470. }
  1471. // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1472. // if(related_json==nil)
  1473. else
  1474. {
  1475. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  1476. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1477. NSString *CellIdentifier = @"DetailInfoCell";
  1478. NSString* type=[section_json valueForKey:@"type"] ;
  1479. if([type isEqualToString:@"kv"])
  1480. {
  1481. float width = tableView.frame.size.width;
  1482. width-=CELL_MARGIN*2;
  1483. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1484. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1485. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1486. NSString* key =[item_json valueForKey:@"key"] ;
  1487. NSString* val=[item_json valueForKey:@"val"] ;
  1488. NSString* type=[item_json valueForKey:@"type"] ;
  1489. if([type isEqualToString:@"price"])
  1490. {
  1491. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1492. {
  1493. }
  1494. else
  1495. {
  1496. val=nil;
  1497. }
  1498. }
  1499. if([val isEqual:[NSNull null]])
  1500. val=@"";
  1501. if(val==nil)
  1502. val=@"";
  1503. if([val isEqualToString:@"null"])
  1504. val=@"";
  1505. CGRect frame;
  1506. frame.size = constraintval;
  1507. frame.origin.x=0;
  1508. frame.origin.y=0;
  1509. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1510. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1511. // rtlabel.lineSpacing = 20.0;
  1512. [rtlabel setText: val];
  1513. CGSize sizeval=rtlabel.optimumSize;
  1514. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1515. CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1516. float height = MAX(sizekey.height,sizeval.height);
  1517. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1518. sizekey.height = height;
  1519. sizekey.width = constraintkey.width;
  1520. // sizeval.height = height;
  1521. sizeval.width =constraintval.width;
  1522. // NSString *CellIdentifier = @"detail_item_kv";
  1523. DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1524. if(cell==nil)
  1525. DebugLog(@"cell is nil.........................");
  1526. CGRect framekey = cell.keyLabel.frame;
  1527. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  1528. framekey.origin.y=LINE_WIDTH;
  1529. framekey.size = sizekey;
  1530. cell.keyLabel.frame = framekey;
  1531. cell.keyLabel.text=key;
  1532. CGRect frameval = cell.valLabel.frame;
  1533. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  1534. frameval.origin.y=LINE_WIDTH;
  1535. frameval.size = sizeval;
  1536. cell.valLabel.frame = frameval;
  1537. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  1538. cell.valLabel.text= val;
  1539. CGPoint rcenter;
  1540. rcenter.x = width * 0.4+width * 0.6/2;
  1541. rcenter.y = height /2;
  1542. cell.valLabel.center=rcenter;
  1543. // cell.valLabel.backgroundColor =[UIColor redColor];
  1544. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  1545. // cell.backgroundColor = [UIColor whiteColor];
  1546. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1547. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1548. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1549. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1550. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1551. cell.backgroundColor = [UIColor whiteColor];
  1552. return cell;
  1553. }
  1554. else if ([type isEqualToString:@"img"])
  1555. {
  1556. DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  1557. int img_count = [[item_json valueForKey:@"count"] intValue];
  1558. double posy = 0;
  1559. for(int j=0;j<img_count;j++)
  1560. {
  1561. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  1562. float width = [[img_json valueForKey:@"width"]floatValue];
  1563. float height = [[img_json valueForKey:@"height"]floatValue];
  1564. //
  1565. UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  1566. imgview.contentMode = UIViewContentModeScaleAspectFit;
  1567. NSString* img_url = [img_json valueForKey:@"img_url"];
  1568. posy+=height*tableView.bounds.size.width / width;
  1569. NSString* file_name=[img_url lastPathComponent];
  1570. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  1571. if(img_data!=nil)
  1572. {
  1573. UIImage * img =[UIImage imageWithData:img_data];
  1574. imgview.image = img;
  1575. [cell addSubview:imgview];
  1576. }
  1577. else
  1578. {
  1579. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1580. NSData* downloadimg_data = nil;
  1581. // BOOL offline = NO;
  1582. //#ifdef OFFLINE_MODE
  1583. // offline = appDelegate.offline_mode;
  1584. //#endif
  1585. // if (!offline) {
  1586. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1587. // }
  1588. dispatch_async(dispatch_get_main_queue(), ^{
  1589. if(downloadimg_data!=nil)
  1590. {
  1591. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1592. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1593. imgview.image = img;
  1594. [cell addSubview:imgview];
  1595. }
  1596. else
  1597. {
  1598. imgview.image = [UIImage imageNamed:@"notfound_l"];
  1599. [cell addSubview:imgview];
  1600. }
  1601. });
  1602. });
  1603. }
  1604. }
  1605. cell.backgroundColor = [UIColor whiteColor];
  1606. return cell;
  1607. }
  1608. else if ([type isEqualToString:@"content"])
  1609. {
  1610. NSString *CellIdentifier = @"DetailTopicCell";
  1611. NSString* data=[section_json valueForKey:@"data"] ;
  1612. if([data isEqualToString:@"local"])
  1613. {
  1614. [appDelegate.recent_model addEntriesFromDictionary:section_json];
  1615. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1616. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1617. cell.itemdelegate = self;
  1618. cell.related_data = appDelegate.recent_model;
  1619. [cell.topicCollectionView reloadData];
  1620. cell.backgroundColor = [UIColor whiteColor];
  1621. return cell;
  1622. }
  1623. else
  1624. {
  1625. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1626. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1627. cell.itemdelegate = self;
  1628. cell.related_data = section_json;
  1629. [cell.topicCollectionView reloadData];
  1630. cell.backgroundColor = [UIColor whiteColor];
  1631. return cell;
  1632. }
  1633. }
  1634. return nil;
  1635. }
  1636. }
  1637. -(void)startAnimationWithRect:(CGRect)rect ImageView:(UIImageView *)imageView
  1638. {
  1639. if (!_layer) {
  1640. // _btn.enabled = NO;
  1641. _layer = [CALayer layer];
  1642. _layer.contents = (id)imageView.layer.contents;
  1643. _layer.contentsGravity = kCAGravityResizeAspectFill;
  1644. _layer.bounds = rect;
  1645. [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
  1646. _layer.masksToBounds = YES;
  1647. // 导航64
  1648. _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
  1649. // [_tableView.layer addSublayer:_layer];
  1650. [self.view.layer addSublayer:_layer];
  1651. self.path = [UIBezierPath bezierPath];
  1652. // [_path moveToPoint:_layer.position];
  1653. [_path moveToPoint:imageView.center];
  1654. [_path addLineToPoint:CGPointMake(imageView.center.x, imageView.center.y-100)];
  1655. // (SCREEN_WIDTH - 60), 0, 50, 50)
  1656. // [_path addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH - 40, SCREEN_HEIGHT-40) controlPoint:CGPointMake(SCREEN_WIDTH/2,rect.origin.y-80)];
  1657. // [_path addLineToPoint:CGPointMake(SCREEN_WIDTH-40, 30)];
  1658. }
  1659. [self groupAnimation];
  1660. }
  1661. -(void)groupAnimation
  1662. {
  1663. self.detailTable.userInteractionEnabled = NO;
  1664. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  1665. animation.path = _path.CGPath;
  1666. // animation.rotationMode = kCAAnimationRotateAuto;
  1667. //
  1668. CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1669. expandAnimation.duration = 0.3f;
  1670. expandAnimation.fromValue = [NSNumber numberWithFloat:1];
  1671. expandAnimation.toValue = [NSNumber numberWithFloat:2.0f];
  1672. expandAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  1673. CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1674. narrowAnimation.beginTime = 0.3;
  1675. narrowAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
  1676. narrowAnimation.duration = 0.9f;
  1677. narrowAnimation.toValue = [NSNumber numberWithFloat:0.3f];
  1678. //
  1679. // narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  1680. CAAnimationGroup *groups = [CAAnimationGroup animation];
  1681. groups.animations = @[animation,expandAnimation,narrowAnimation];
  1682. groups.duration = 1.0f;
  1683. groups.removedOnCompletion=NO;
  1684. groups.fillMode=kCAFillModeForwards;
  1685. groups.delegate = self;
  1686. [_layer addAnimation:groups forKey:@"group"];
  1687. }
  1688. -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  1689. {
  1690. // [anim def];
  1691. if (anim == [_layer animationForKey:@"group"]) {
  1692. self.detailTable.userInteractionEnabled = YES;
  1693. // _btn.enabled = YES;
  1694. [_layer removeFromSuperlayer];
  1695. _layer = nil;
  1696. // _cnt++;
  1697. // if (_cnt) {
  1698. // _cntLabel.hidden = NO;
  1699. // }
  1700. // CATransition *animation = [CATransition animation];
  1701. // animation.duration = 0.25f;
  1702. // _cntLabel.text = [NSString stringWithFormat:@"%d",_cnt];
  1703. // [_cntLabel.layer addAnimation:animation forKey:nil];
  1704. // CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  1705. // shakeAnimation.duration = 0.25f;
  1706. // shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
  1707. // shakeAnimation.toValue = [NSNumber numberWithFloat:5];
  1708. // shakeAnimation.autoreverses = YES;
  1709. // [_btn.layer addAnimation:shakeAnimation forKey:nil];
  1710. }
  1711. }
  1712. #pragma mark - hide section button clicked
  1713. - (void)RefreshSection:(UIButton *)sender {
  1714. sender.enabled=false;
  1715. NSDictionary* section_json = nil;
  1716. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1717. if(related_json==nil)
  1718. {
  1719. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(sender.tag-1)]];
  1720. }
  1721. else
  1722. {
  1723. if(sender.tag==1)
  1724. {
  1725. section_json = related_json ;
  1726. }
  1727. else
  1728. {
  1729. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)sender.tag-2]];
  1730. }
  1731. }
  1732. NSString* url = section_json[@"data_interface"];
  1733. NSMutableDictionary* params = [section_json[@"params"] mutableCopy];
  1734. if(params==nil)
  1735. params = [[NSMutableDictionary alloc] init];
  1736. NSUInteger ii[2] = {sender.tag,0};
  1737. NSIndexPath* indexpath= [NSIndexPath indexPathWithIndexes:ii length:2];
  1738. DetailTopicCell * cell=[self.detailTable cellForRowAtIndexPath:indexpath];
  1739. [cell begin_refresh];
  1740. // UIAlertController * waitalert = [RAUtils waiting_alert:selftitle:@"Refreshing"];
  1741. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  1742. NSDictionary* editor_json =result;
  1743. [cell end_refresh ];
  1744. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1745. sender.enabled=true;
  1746. if([[editor_json valueForKey:@"result"] intValue]==2)
  1747. {
  1748. [self.detail_data addEntriesFromDictionary:editor_json];
  1749. NSRange range = NSMakeRange(sender.tag, 1);
  1750. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1751. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1752. }
  1753. else
  1754. {
  1755. [RAUtils message_box:nil message:[editor_json valueForKey:@"err_msg"] completion:nil];
  1756. }
  1757. }];
  1758. }
  1759. #pragma mark - Support scanner
  1760. -(void) onDecodedData:(NSString*) value
  1761. {
  1762. // UIApplication * app = [UIApplication sharedApplication];
  1763. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1764. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1765. //
  1766. self.model_name = value;
  1767. self.product_id = nil;
  1768. self.use_model_name = true;
  1769. [self reload];
  1770. DebugLog(@"color selected");
  1771. }
  1772. #pragma mark - Handle Notification
  1773. - (void)dealloc {
  1774. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1775. }
  1776. - (void)registeObserver {
  1777. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoRightMsg:) name:No_Rights_Notification object:nil];
  1778. }
  1779. - (void)handleNoRightMsg:(NSNotification *)notification {
  1780. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You have no rights to do that." preferredStyle:UIAlertControllerStyleAlert];
  1781. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1782. [alertController dismissViewControllerAnimated:YES completion:nil];
  1783. }];
  1784. [alertController addAction:action];
  1785. [self presentViewController:alertController animated:YES completion:nil];
  1786. }
  1787. #pragma mark - action
  1788. - (void)showEmailAddrBox {
  1789. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1790. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  1791. emailAddrVC.textFiled.secureTextEntry = NO;
  1792. emailAddrVC.yesButtonTitle = @"send";
  1793. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  1794. __weak typeof(self) weakself = self;
  1795. emailAddrVC.textHandler = ^(NSString *text){
  1796. // 验证邮箱格式是否正确
  1797. // NSString *match = EMAIL_MATCHES;
  1798. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  1799. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  1800. BOOL isEmailAddr = YES;
  1801. if (isEmailAddr) {
  1802. // 验证是邮件地址,发送邮件
  1803. [weakVC dismissViewControllerAnimated:YES completion:^{
  1804. // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  1805. PopWaitAlert* pop = [RAUtils waiting_pop:@"Sending Email" completion:nil];
  1806. [RANetwork request_notifymodel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  1807. DebugLog(@"email cart result: %@",result);
  1808. // [waitting_alert dismissViewControllerAnimated:YES completion:^{
  1809. [pop hide];
  1810. int resultStatus = [[result objectForKey:@"result"] intValue];
  1811. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  1812. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1813. if ([result valueForKey:@"err_msg"]) {
  1814. msg = [result valueForKey:@"err_msg"];
  1815. }
  1816. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1817. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1818. }];
  1819. [errorAlertVC addAction:action];
  1820. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1821. }else if(resultStatus == RESULT_TRUE){
  1822. [RAUtils message_box:@"Message" message:@"Notification is sent to default email address." completion:nil];
  1823. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  1824. [weakself showEmailAddrBox];
  1825. }
  1826. // }];
  1827. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1828. }];
  1829. // }];
  1830. }];
  1831. } else {
  1832. // 非邮件地址,警告
  1833. [weakVC warning:@"Please enter right email address"];
  1834. }
  1835. };
  1836. [self presentViewController:emailAddrVC animated:YES completion:nil];
  1837. }
  1838. - (void)showIntroducePDF:(NSString *)link {
  1839. if (link.length == 0) {
  1840. [RAUtils message_box:@"Warning" message:@"There is no resource to open" completion:nil];
  1841. return;
  1842. }
  1843. NSArray *tmpArr = [link componentsSeparatedByString:@"="];
  1844. BOOL isLocalFile = NO;
  1845. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  1846. NSString *name = [section_json valueForKey:@"model_name"];
  1847. NSString *path = [NSString stringWithFormat:@"%@/Introduce/%@.pdf",[RAUtils appCacheDirectory],tmpArr.lastObject];
  1848. if ([RAUtils fileExistsAtPath:path]) { // 检查缓存
  1849. isLocalFile = YES;
  1850. link = path;
  1851. } else {
  1852. // 创建缓存目录
  1853. NSString *dir = [path stringByDeletingLastPathComponent];
  1854. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  1855. }
  1856. name = [NSString stringWithFormat:@"%@ Assembly Instruction",name];
  1857. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  1858. ViewController.url = link;
  1859. ViewController.canSave = false;
  1860. ViewController.isLocalfile=isLocalFile;
  1861. ViewController.cachePath = path;
  1862. NSString* subject = name;
  1863. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1864. NSString* customer_email = [appDelegate.customerInfo valueForKey:@"customer_email"];
  1865. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  1866. if(customer_email.length>0)
  1867. {
  1868. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  1869. }
  1870. ViewController.mail_to = send_to;
  1871. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",name];
  1872. ViewController.mail_subject = subject;
  1873. ViewController.hidenavi = false;
  1874. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
  1875. // nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  1876. // CGSize size = [UIScreen mainScreen].bounds.size;
  1877. // nav.preferredContentSize = CGSizeMake(size.width * 0.8, size.height * 0.8);
  1878. [self.navigationController pushViewController:ViewController animated:YES];
  1879. }
  1880. - (void)showModelDescription:(NSString *)desc {
  1881. ModelDescriptionController *vc = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ModelDescriptionController"];
  1882. vc.model_desc = desc;
  1883. vc.title = [NSString stringWithFormat:@"%@ Description",self.model_name];
  1884. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  1885. nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  1886. nav.preferredContentSize = CGSizeMake(400, 380);// 只有在 UIModalPresentationFormSheet 的时候起作用
  1887. [self presentViewController:nav animated:YES completion:nil];
  1888. }
  1889. - (void)reRefreshView {
  1890. [self.detailTable reloadData];
  1891. }
  1892. #pragma mark - RA_NOTIFICAITON
  1893. -(void) refresh_ui
  1894. {
  1895. [self.detailTable reloadData];
  1896. }
  1897. -(void) reload_data
  1898. {
  1899. [self reload];
  1900. }
  1901. -(void) refresh_price
  1902. {
  1903. [self refresh_ui];
  1904. }
  1905. @end