DetailViewController.m 112 KB

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