DetailViewController.m 103 KB

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