DetailViewController.m 98 KB

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