DetailViewController.m 101 KB

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