DetailViewController.m 114 KB

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