DetailViewController.m 98 KB

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