DetailViewController.m 117 KB

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