DetailHeaderCell.m 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255
  1. //
  2. // DetailHeaderCell.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-5.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailHeaderCell.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "LoginViewController.h"
  12. #import "ContactListViewController.h"
  13. #import "RAUtils.h"
  14. #import "OrderListViewController.h"
  15. #import "ImageScrollerViewController.h"
  16. #import "CartUtils.h"
  17. #import "CustomIOSAlertView.h"
  18. #import "TextUtils.h"
  19. #import "ContentPreviewController.h"
  20. #import "DetailViewController.h"
  21. #import "RAPDFViewController.h"
  22. @implementation DetailHeaderCell
  23. @synthesize celldelegate;
  24. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  25. {
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self) {
  28. // Initialization code
  29. }
  30. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  31. // self.selector_imageView.layer.borderWidth = 1;
  32. return self;
  33. }
  34. - (void)awakeFromNib
  35. {
  36. [super awakeFromNib];
  37. #ifdef BUILD_UWAVER
  38. // self.addPortfolioBtn.title = @"Add to Hang Tag";
  39. self.btn_hangtag.hidden=false;
  40. #else
  41. self.btn_hangtag.hidden=true;
  42. #endif
  43. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  44. // self.selector_imageView.layer.borderWidth = 1;
  45. self.quantity_text.delegate = self;
  46. self.selector_Button.layer.borderWidth = 0.5;
  47. self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  48. self.selector_Button.layer.cornerRadius = 0;
  49. [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  50. [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
  51. [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
  52. // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  53. // self.label_net_err.layer.borderWidth = 2.0;
  54. // self.label_net_err.layer.cornerRadius=15;
  55. // self.label_net_err.layer.masksToBounds=true;
  56. // Initialization code
  57. [self addObserver:self
  58. forKeyPath:@"stack_contents"
  59. options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  60. context:@"content changed"];
  61. }
  62. -(void) dealloc
  63. {
  64. [self removeObserver:self forKeyPath:@"stack_contents"];
  65. }
  66. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  67. {
  68. if([keyPath isEqualToString:@"stack_contents"])
  69. {
  70. [self.ytplayerView stopVideo];
  71. self.ytplayerView.hidden=true;
  72. }
  73. }
  74. - (IBAction)create_HangTag:(id)sender {
  75. // DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  76. //
  77. // NSString *catelog_name = [NSString stringWithFormat:@"%@ Hang Tag",vc.groupName];
  78. //
  79. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing"];
  80. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  81. //
  82. // NSDictionary* editor_json = [RANetwork request_hangTag:vc.groupName];
  83. //
  84. // dispatch_async(dispatch_get_main_queue(), ^{
  85. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  86. //
  87. //
  88. // if([[editor_json valueForKey:@"result"] intValue]==2)
  89. // {
  90. //
  91. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  92. //
  93. // NSString* url = [editor_json valueForKey:@"pdf_path"];
  94. // bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  95. // RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  96. // ViewController.url = url;
  97. // ViewController.canSave = false;
  98. // ViewController.isLocalfile=isLocalFile;
  99. //
  100. // ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  101. //
  102. //
  103. // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  104. //
  105. // if(company==nil)
  106. // company=@"";
  107. //
  108. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  109. //
  110. //
  111. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  112. // if(customer_email.length>0)
  113. // {
  114. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  115. // }
  116. // ViewController.mail_to = send_to;
  117. //
  118. // NSString* subject;
  119. //
  120. // subject =catelog_name;
  121. //
  122. // ViewController.mail_subject = subject;
  123. //
  124. // ViewController.hidenavi = false;
  125. // [vc.navigationController pushViewController:ViewController animated:YES];
  126. //
  127. // }
  128. // else
  129. // {
  130. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
  131. // }
  132. //
  133. // });
  134. // });
  135. //
  136. //
  137. }
  138. - (IBAction)add_toPortfolio:(id)sender {
  139. // int count=[self.quantity_text.text intValue];
  140. UIApplication * app = [UIApplication sharedApplication];
  141. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  142. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  143. [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil];
  144. return;
  145. }
  146. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  147. if(appDelegate.bLogin==false)
  148. {
  149. UIViewController *vc= [RAUtils getViewController:self];
  150. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  151. // loginvc.delegate = self;
  152. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  153. loginvc.returnValue = ^(bool blogin){
  154. // UIApplication * app = [UIApplication sharedApplication];
  155. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  156. if(blogin)
  157. {
  158. if(self.set_update_data)
  159. self.set_update_data(true);
  160. [main_vc checklogin:true];
  161. [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  162. NSDictionary* return_json =result;
  163. if([[return_json valueForKey:@"result"] intValue]==2)
  164. {
  165. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  166. #ifdef RA_NOTIFICATION
  167. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  168. #else
  169. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  170. #endif
  171. if(self.WatchlistBlock!=nil)
  172. {
  173. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  174. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  175. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  176. iv.image = img;
  177. // [self.contentView addSubview:iv];
  178. self.PortfolioBlock(iv);
  179. }
  180. }
  181. else
  182. {
  183. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  184. }
  185. }];
  186. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  187. //
  188. // NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  189. //
  190. // dispatch_async(dispatch_get_main_queue(), ^{
  191. //
  192. // if([[return_json valueForKey:@"result"] intValue]==2)
  193. // {
  194. //
  195. // // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  196. //
  197. //
  198. //#ifdef RA_NOTIFICATION
  199. // [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  200. //#else
  201. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  202. //#endif
  203. //
  204. // if(self.WatchlistBlock!=nil)
  205. // {
  206. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  207. //
  208. //
  209. // CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  210. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  211. // iv.image = img;
  212. // // [self.contentView addSubview:iv];
  213. // self.PortfolioBlock(iv);
  214. //
  215. // }
  216. // }
  217. // else
  218. // {
  219. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  220. // }
  221. //
  222. //
  223. //
  224. // });
  225. // });
  226. }
  227. // self.offset = 0;
  228. // [self.content_data removeAllObjects];
  229. // [self loadpage];
  230. //
  231. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  232. };
  233. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  234. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  235. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  236. [vc presentViewController:navi animated:YES completion:^{
  237. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  238. DebugLog(@"LoginViewController present.........");
  239. // self.btop = false;
  240. // <#code#>
  241. }];
  242. }
  243. else
  244. {
  245. [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  246. NSDictionary* return_json =result;
  247. if([[return_json valueForKey:@"result"] intValue]==2)
  248. {
  249. #ifdef RA_NOTIFICATION
  250. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  251. #else
  252. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  253. #endif
  254. if(self.WatchlistBlock!=nil)
  255. {
  256. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  257. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  258. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  259. iv.image = img;
  260. // [self.contentView addSubview:iv];
  261. self.PortfolioBlock(iv);
  262. }
  263. }
  264. else
  265. {
  266. UIViewController *vc= [RAUtils getViewController:self];
  267. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  268. }
  269. }];
  270. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  271. //
  272. // NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  273. //
  274. // dispatch_async(dispatch_get_main_queue(), ^{
  275. //
  276. // if([[return_json valueForKey:@"result"] intValue]==2)
  277. // {
  278. //
  279. //#ifdef RA_NOTIFICATION
  280. // [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  281. //#else
  282. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  283. //#endif
  284. // if(self.WatchlistBlock!=nil)
  285. // {
  286. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  287. //
  288. //
  289. // CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  290. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  291. // iv.image = img;
  292. // // [self.contentView addSubview:iv];
  293. // self.PortfolioBlock(iv);
  294. //
  295. // }
  296. // }
  297. // else
  298. // {
  299. // UIViewController *vc= [RAUtils getViewController:self];
  300. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  301. // }
  302. //
  303. //
  304. //
  305. // });
  306. // });
  307. }
  308. }
  309. - (IBAction)add_toWatchList:(id)sender {
  310. // int count=[self.quantity_text.text intValue];
  311. UIApplication * app = [UIApplication sharedApplication];
  312. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  313. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  314. if(appDelegate.bLogin==false)
  315. {
  316. UIViewController *vc= [RAUtils getViewController:self];
  317. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  318. // loginvc.delegate = self;
  319. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  320. loginvc.returnValue = ^(bool blogin){
  321. // UIApplication * app = [UIApplication sharedApplication];
  322. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  323. if(blogin)
  324. {
  325. if(self.set_update_data)
  326. self.set_update_data(true);
  327. [main_vc checklogin:true];
  328. [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  329. NSDictionary* return_json =result;
  330. if([[return_json valueForKey:@"result"] intValue]==2)
  331. {
  332. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  333. #ifdef RA_NOTIFICATION
  334. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  335. #else
  336. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  337. #endif
  338. if(self.WatchlistBlock!=nil)
  339. {
  340. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  341. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  342. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  343. iv.image = img;
  344. // [self.contentView addSubview:iv];
  345. self.WatchlistBlock(iv);
  346. }
  347. }
  348. else
  349. {
  350. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  351. }
  352. }];
  353. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  354. //
  355. // NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  356. //
  357. // dispatch_async(dispatch_get_main_queue(), ^{
  358. //
  359. // if([[return_json valueForKey:@"result"] intValue]==2)
  360. // {
  361. //
  362. // // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  363. //
  364. //
  365. //#ifdef RA_NOTIFICATION
  366. // [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  367. //#else
  368. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  369. //#endif
  370. //
  371. // if(self.WatchlistBlock!=nil)
  372. // {
  373. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  374. //
  375. //
  376. // CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  377. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  378. // iv.image = img;
  379. // // [self.contentView addSubview:iv];
  380. // self.WatchlistBlock(iv);
  381. //
  382. // }
  383. // }
  384. // else
  385. // {
  386. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  387. // }
  388. //
  389. //
  390. //
  391. // });
  392. // });
  393. }
  394. // self.offset = 0;
  395. // [self.content_data removeAllObjects];
  396. // [self loadpage];
  397. //
  398. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  399. };
  400. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  401. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  402. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  403. [vc presentViewController:navi animated:YES completion:^{
  404. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  405. DebugLog(@"LoginViewController present.........");
  406. // self.btop = false;
  407. // <#code#>
  408. }];
  409. }
  410. else
  411. {
  412. [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  413. NSDictionary* return_json =result;
  414. if([[return_json valueForKey:@"result"] intValue]==2)
  415. {
  416. #ifdef RA_NOTIFICATION
  417. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  418. #else
  419. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  420. #endif
  421. if(self.WatchlistBlock!=nil)
  422. {
  423. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  424. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  425. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  426. iv.image = img;
  427. // [self.contentView addSubview:iv];
  428. self.WatchlistBlock(iv);
  429. }
  430. }
  431. else
  432. {
  433. UIViewController *vc= [RAUtils getViewController:self];
  434. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  435. }
  436. }];
  437. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  438. //
  439. // NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  440. //
  441. // dispatch_async(dispatch_get_main_queue(), ^{
  442. //
  443. // if([[return_json valueForKey:@"result"] intValue]==2)
  444. // {
  445. //
  446. //
  447. //#ifdef RA_NOTIFICATION
  448. // [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  449. //#else
  450. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  451. //#endif
  452. //
  453. // if(self.WatchlistBlock!=nil)
  454. // {
  455. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  456. //
  457. //
  458. // CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  459. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  460. // iv.image = img;
  461. // // [self.contentView addSubview:iv];
  462. // self.WatchlistBlock(iv);
  463. //
  464. // }
  465. // }
  466. // else
  467. // {
  468. // UIViewController *vc= [RAUtils getViewController:self];
  469. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  470. // }
  471. //
  472. //
  473. //
  474. // });
  475. // });
  476. }
  477. }
  478. - (IBAction)add_toCart:(id)sender {
  479. [CartUtils add_to_cart:[RAUtils getViewController:self] selectorholder:self selector:@selector(addtocart)];
  480. return;
  481. //
  482. //
  483. // int count=[self.quantity_text.text intValue];
  484. //
  485. // UIApplication * app = [UIApplication sharedApplication];
  486. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  487. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  488. // if(appDelegate.bLogin==false)
  489. // {
  490. // UIViewController *vc= [RAUtils getViewController:self];
  491. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  492. // // loginvc.delegate = self;
  493. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  494. //
  495. // loginvc.returnValue = ^(bool blogin){
  496. //
  497. //
  498. // // UIApplication * app = [UIApplication sharedApplication];
  499. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  500. //
  501. //
  502. //
  503. //
  504. // if(blogin)
  505. // {
  506. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
  507. // {
  508. // if(self.set_update_data)
  509. // self.set_update_data(true);
  510. // [main_vc checklogin:false];
  511. //
  512. //
  513. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to pending a order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  514. //
  515. //
  516. //
  517. // // alert.
  518. // [alert show];
  519. // }
  520. // else
  521. // {
  522. // [main_vc checklogin:true];
  523. //
  524. // int c=[self.count_Label.text intValue];
  525. // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  526. //
  527. // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  528. //
  529. //
  530. //
  531. // if(!appDelegate.can_create_backorder && c<count)
  532. // {
  533. //
  534. // NSString *msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  535. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"No", nil) otherButtonTitles:NSLocalizedString(@"Yes", nil), nil];
  536. //
  537. // // alert.
  538. //
  539. // alert.tag = 1234;
  540. // [alert show];
  541. // }
  542. // else
  543. // {
  544. // if(appDelegate.order_code==nil)
  545. // [ self neworder];
  546. // else
  547. // [self addtocart:count];
  548. // }
  549. //
  550. //
  551. // }
  552. // }
  553. //
  554. // // self.offset = 0;
  555. // // [self.content_data removeAllObjects];
  556. // // [self loadpage];
  557. // //
  558. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  559. //
  560. // };
  561. //
  562. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  563. //
  564. //
  565. //
  566. //
  567. //
  568. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  569. //
  570. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  571. // [vc presentViewController:navi animated:YES completion:^{
  572. //
  573. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  574. //
  575. // DebugLog(@"LoginViewController present.........");
  576. //
  577. // // self.btop = false;
  578. // // <#code#>
  579. // }];
  580. // }
  581. // else
  582. // {
  583. //
  584. //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&appDelegate.order_code==nil)
  585. // if(appDelegate.order_code==nil)
  586. // {
  587. // [main_vc checklogin:false];
  588. //
  589. // if(appDelegate.can_create_order)
  590. // {
  591. // NSString* msg =@"";
  592. // if(appDelegate.contact_id.length>0)
  593. // {
  594. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  595. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  596. //
  597. // }
  598. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  599. //
  600. // // alert.
  601. // [alert show];
  602. // }
  603. // else
  604. // {
  605. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  606. //
  607. // // alert.
  608. // [alert show];
  609. // }
  610. // }
  611. // else
  612. // {
  613. //
  614. //// if ([self.priceLabel.text isEqualToString:@"No Price."])
  615. //// {
  616. ////// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  617. //////
  618. //////
  619. //////
  620. ////// [alert show];
  621. ////
  622. ////
  623. ////
  624. //// [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
  625. //// }
  626. //// else
  627. // {
  628. //
  629. // int c=[self.count_Label.text intValue];
  630. // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  631. //
  632. // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  633. //
  634. //
  635. //
  636. // if(c<count)
  637. // {
  638. //
  639. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(@"Confirm add to cart. ", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Confirm", nil), nil];
  640. //
  641. // // alert.
  642. //
  643. // alert.tag = 1234;
  644. // [alert show];
  645. // }
  646. // else
  647. // {
  648. // if(appDelegate.order_code==nil)
  649. // [ self neworder];
  650. // else
  651. // [self addtocart:count];
  652. // }
  653. // }
  654. //
  655. // }
  656. // }
  657. //
  658. //
  659. //
  660. //
  661. //
  662. //
  663. //
  664. //
  665. }
  666. -(void) addtocart
  667. {
  668. int count=[self.quantity_text.text intValue];
  669. #ifdef MPACK
  670. if (count % self.step != 0) {
  671. UIViewController *vc= [RAUtils getViewController:self];
  672. [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Add to cart" controller:vc];
  673. return;
  674. }
  675. #endif
  676. int c=[self.count_Label.text intValue];
  677. DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  678. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  679. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  680. if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
  681. {
  682. NSString *msg = nil;
  683. BOOL continueAdd = YES;
  684. // #if defined(BUILD_NPD) || defined(BUILD_USAI)
  685. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  686. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  687. if ([RASingleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  688. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
  689. continueAdd = NO;
  690. } else { // Shop Order购买数量大于库存需要确认
  691. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  692. continueAdd = YES;
  693. }
  694. }
  695. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  696. msg = @"Item is OUT OF STOCK and not available to order.";
  697. continueAdd = NO;
  698. }
  699. // #endif
  700. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  701. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  702. if (continueAdd) {
  703. [self addtocart:count];
  704. }
  705. }];
  706. [alertControl addAction:alertthree];
  707. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  708. }];
  709. if (continueAdd) {
  710. [alertControl addAction:alertcancel];
  711. }
  712. UIViewController *vc= [RAUtils getViewController:self];
  713. [vc presentViewController:alertControl animated:YES completion:nil];
  714. }
  715. else
  716. {
  717. [self addtocart:count];
  718. }
  719. }
  720. -(void)Hide_selector:(bool) bhide
  721. {
  722. self.selector_Button.hidden=bhide;
  723. self.selector_dorpdown.hidden=bhide;
  724. self.selector_imageView.hidden=bhide;
  725. }
  726. -(void) addtocart:(int) count
  727. {
  728. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  729. #ifdef MPACK
  730. if(self.cqty>0)
  731. {
  732. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  733. //block代码块取代了delegate
  734. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  735. int c=self.cqty+count;
  736. int m=c%self.step;
  737. if(m!=0&&appDelegate.alert_sold_in_quantities)
  738. {
  739. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  740. //block代码块取代了delegate
  741. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  742. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  743. NSDictionary* return_json = result;
  744. if([[return_json valueForKey:@"result"] intValue]==2)
  745. {
  746. // NSString* order_code = [return_json valueForKey:@"order_code"];
  747. #ifdef RA_NOTIFICATION
  748. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  749. #else
  750. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  751. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  752. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  753. #endif
  754. if(self.shopCartBlock!=nil)
  755. {
  756. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  757. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  758. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  759. iv.image = img;
  760. // [self.contentView addSubview:iv];
  761. self.shopCartBlock(iv);
  762. self.cqty +=count;
  763. if(self.set_cqty)
  764. self.set_cqty(self.cqty);
  765. }
  766. }
  767. else
  768. {
  769. UIViewController *vc= [RAUtils getViewController:self];
  770. NSString *msg = [return_json valueForKey:@"err_msg"];
  771. NSString *title = @"Add To Cart";
  772. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  773. title = @"Add To Cart: Out of Stock";
  774. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  775. self.btnNotifyMe.enabled = YES;
  776. self.btnaddCart.enabled = NO;
  777. }
  778. [RAUtils message_alert:msg title:title controller:vc] ;
  779. }
  780. }];
  781. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  782. //
  783. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  784. //
  785. // dispatch_async(dispatch_get_main_queue(), ^{
  786. //
  787. //
  788. //
  789. // if([[return_json valueForKey:@"result"] intValue]==2)
  790. // {
  791. //
  792. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  793. //
  794. //
  795. //
  796. //
  797. //#ifdef RA_NOTIFICATION
  798. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  799. //#else
  800. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  801. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  802. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  803. //#endif
  804. // if(self.shopCartBlock!=nil)
  805. // {
  806. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  807. //
  808. //
  809. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  810. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  811. // iv.image = img;
  812. // // [self.contentView addSubview:iv];
  813. // self.shopCartBlock(iv);
  814. //
  815. // self.cqty +=count;
  816. // if(self.set_cqty)
  817. // self.set_cqty(self.cqty);
  818. //
  819. // }
  820. //
  821. //
  822. // }
  823. // else
  824. // {
  825. // UIViewController *vc= [RAUtils getViewController:self];
  826. // NSString *msg = [return_json valueForKey:@"err_msg"];
  827. // NSString *title = @"Add To Cart";
  828. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  829. // title = @"Add To Cart: Out of Stock";
  830. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  831. // self.btnNotifyMe.enabled = YES;
  832. // self.btnaddCart.enabled = NO;
  833. // }
  834. //
  835. // [RAUtils message_alert:msg title:title controller:vc] ;
  836. // }
  837. //
  838. //
  839. //
  840. //
  841. // });
  842. // });
  843. }];
  844. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  845. DebugLog(@"No");
  846. }];
  847. [alertControl addAction:actionOne];
  848. [alertControl addAction:alertthree];
  849. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  850. UIViewController *vc= [RAUtils getViewController:self];
  851. [vc presentViewController:alertControl animated:YES completion:nil];
  852. }
  853. else
  854. {
  855. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  856. NSDictionary* return_json = result;
  857. if([[return_json valueForKey:@"result"] intValue]==2)
  858. {
  859. // NSString* order_code = [return_json valueForKey:@"order_code"];
  860. #ifdef RA_NOTIFICATION
  861. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  862. #else
  863. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  864. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  865. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  866. #endif
  867. if(self.shopCartBlock!=nil)
  868. {
  869. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  870. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  871. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  872. iv.image = img;
  873. // [self.contentView addSubview:iv];
  874. self.shopCartBlock(iv);
  875. self.cqty +=count;
  876. if(self.set_cqty)
  877. self.set_cqty(self.cqty);
  878. }
  879. }
  880. else
  881. {
  882. UIViewController *vc= [RAUtils getViewController:self];
  883. NSString *msg = [return_json valueForKey:@"err_msg"];
  884. NSString *title = @"Add To Cart";
  885. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  886. title = @"Add To Cart: Out of Stock";
  887. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  888. self.btnNotifyMe.enabled = YES;
  889. self.btnaddCart.enabled = NO;
  890. }
  891. [RAUtils message_alert:msg title:title controller:vc] ;
  892. }
  893. }];
  894. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  895. //
  896. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  897. //
  898. // dispatch_async(dispatch_get_main_queue(), ^{
  899. //
  900. //
  901. //
  902. // if([[return_json valueForKey:@"result"] intValue]==2)
  903. // {
  904. //
  905. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  906. //
  907. //
  908. //#ifdef RA_NOTIFICATION
  909. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  910. //#else
  911. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  912. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  913. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  914. //#endif
  915. // if(self.shopCartBlock!=nil)
  916. // {
  917. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  918. //
  919. //
  920. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  921. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  922. // iv.image = img;
  923. // // [self.contentView addSubview:iv];
  924. // self.shopCartBlock(iv);
  925. //
  926. // self.cqty +=count;
  927. // if(self.set_cqty)
  928. // self.set_cqty(self.cqty);
  929. //
  930. // }
  931. //
  932. //
  933. // }
  934. // else
  935. // {
  936. // UIViewController *vc= [RAUtils getViewController:self];
  937. // NSString *msg = [return_json valueForKey:@"err_msg"];
  938. // NSString *title = @"Add To Cart";
  939. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  940. // title = @"Add To Cart: Out of Stock";
  941. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  942. // self.btnNotifyMe.enabled = YES;
  943. // self.btnaddCart.enabled = NO;
  944. // }
  945. //
  946. // [RAUtils message_alert:msg title:title controller:vc] ;
  947. // }
  948. //
  949. //
  950. //
  951. //
  952. // });
  953. // });
  954. }
  955. //
  956. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  957. //
  958. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  959. //
  960. // dispatch_async(dispatch_get_main_queue(), ^{
  961. //
  962. //
  963. //
  964. // if([[return_json valueForKey:@"result"] intValue]==2)
  965. // {
  966. //
  967. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  968. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  969. //// appDelegate.order_code = order_code;
  970. ////
  971. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  972. //// appDelegate.order_code = order_code;
  973. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  974. //
  975. //
  976. // if(self.shopCartBlock!=nil)
  977. // {
  978. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  979. //
  980. //
  981. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  982. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  983. // iv.image = img;
  984. // // [self.contentView addSubview:iv];
  985. // self.shopCartBlock(iv);
  986. //
  987. // self.cqty +=count;
  988. // if(self.set_cqty)
  989. // self.set_cqty(self.cqty);
  990. //
  991. // }
  992. //
  993. //
  994. // }
  995. // else
  996. // {
  997. // UIViewController *vc= [RAUtils getViewController:self];
  998. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  999. // }
  1000. //
  1001. //
  1002. //
  1003. //
  1004. // });
  1005. // });
  1006. //
  1007. }];
  1008. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1009. DebugLog(@"No");
  1010. }];
  1011. [alertControl addAction:actionOne];
  1012. [alertControl addAction:alertthree];
  1013. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1014. UIViewController *vc= [RAUtils getViewController:self];
  1015. [vc presentViewController:alertControl animated:YES completion:nil];
  1016. }
  1017. else
  1018. #endif
  1019. {
  1020. #ifdef MPACK
  1021. int c=self.cqty+count;
  1022. int m=c%self.step;
  1023. if(m!=0&&appDelegate.alert_sold_in_quantities)
  1024. {
  1025. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  1026. //block代码块取代了delegate
  1027. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1028. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  1029. NSDictionary* return_json =result;
  1030. if([[return_json valueForKey:@"result"] intValue]==2)
  1031. {
  1032. #ifdef RA_NOTIFICATION
  1033. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1034. #else
  1035. // NSString* order_code = [return_json valueForKey:@"order_code"];
  1036. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1037. // appDelegate.order_code = order_code;
  1038. //
  1039. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1040. // appDelegate.order_code = order_code;
  1041. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1042. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1043. #endif
  1044. if(self.shopCartBlock!=nil)
  1045. {
  1046. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1047. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1048. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1049. iv.image = img;
  1050. // [self.contentView addSubview:iv];
  1051. self.shopCartBlock(iv);
  1052. self.cqty +=count;
  1053. if(self.set_cqty)
  1054. self.set_cqty(self.cqty);
  1055. }
  1056. }
  1057. else
  1058. {
  1059. UIViewController *vc= [RAUtils getViewController:self];
  1060. NSString *msg = [return_json valueForKey:@"err_msg"];
  1061. NSString *title = @"Add To Cart";
  1062. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1063. title = @"Add To Cart: Out of Stock";
  1064. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1065. self.btnNotifyMe.enabled = YES;
  1066. self.btnaddCart.enabled = NO;
  1067. }
  1068. [RAUtils message_alert:msg title:title controller:vc] ;
  1069. }
  1070. }];
  1071. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1072. //
  1073. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  1074. //
  1075. // dispatch_async(dispatch_get_main_queue(), ^{
  1076. //
  1077. //
  1078. //
  1079. // if([[return_json valueForKey:@"result"] intValue]==2)
  1080. // {
  1081. //
  1082. //
  1083. //
  1084. //#ifdef RA_NOTIFICATION
  1085. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1086. //#else
  1087. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  1088. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1089. // // appDelegate.order_code = order_code;
  1090. // //
  1091. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1092. // // appDelegate.order_code = order_code;
  1093. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1094. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1095. //#endif
  1096. // if(self.shopCartBlock!=nil)
  1097. // {
  1098. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1099. //
  1100. //
  1101. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1102. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1103. // iv.image = img;
  1104. // // [self.contentView addSubview:iv];
  1105. // self.shopCartBlock(iv);
  1106. //
  1107. // self.cqty +=count;
  1108. // if(self.set_cqty)
  1109. // self.set_cqty(self.cqty);
  1110. //
  1111. // }
  1112. //
  1113. //
  1114. // }
  1115. // else
  1116. // {
  1117. // UIViewController *vc= [RAUtils getViewController:self];
  1118. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1119. // NSString *title = @"Add To Cart";
  1120. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1121. // title = @"Add To Cart: Out of Stock";
  1122. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1123. // self.btnNotifyMe.enabled = YES;
  1124. // self.btnaddCart.enabled = NO;
  1125. // }
  1126. //
  1127. // [RAUtils message_alert:msg title:title controller:vc] ;
  1128. // }
  1129. //
  1130. //
  1131. //
  1132. //
  1133. // });
  1134. // });
  1135. }];
  1136. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1137. DebugLog(@"No");
  1138. }];
  1139. [alertControl addAction:actionOne];
  1140. [alertControl addAction:alertthree];
  1141. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1142. UIViewController *vc= [RAUtils getViewController:self];
  1143. [vc presentViewController:alertControl animated:YES completion:nil];
  1144. }
  1145. else
  1146. #endif
  1147. {
  1148. NSString* model_name=self.model_label.text;
  1149. [RANetwork request_addto_cart:self.product_id count:count name:model_name completionHandler:^(NSMutableDictionary *result) {
  1150. NSDictionary* return_json = result;
  1151. if([[return_json valueForKey:@"result"] intValue]==2)
  1152. {
  1153. #ifdef RA_NOTIFICATION
  1154. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1155. #else
  1156. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1157. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1158. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1159. #endif
  1160. if(self.shopCartBlock!=nil)
  1161. {
  1162. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1163. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1164. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1165. iv.image = img;
  1166. // [self.contentView addSubview:iv];
  1167. self.shopCartBlock(iv);
  1168. self.cqty +=count;
  1169. if(self.set_cqty)
  1170. self.set_cqty(self.cqty);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. UIViewController *vc= [RAUtils getViewController:self];
  1176. NSString *msg = [return_json valueForKey:@"err_msg"];
  1177. NSString *title = @"Add To Cart";
  1178. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1179. title = @"Add To Cart: Out of Stock";
  1180. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1181. self.btnNotifyMe.enabled = YES;
  1182. self.btnaddCart.enabled = NO;
  1183. }
  1184. [RAUtils message_alert:msg title:title controller:vc] ;
  1185. }
  1186. }];
  1187. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1188. //
  1189. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:model_name];
  1190. //
  1191. // dispatch_async(dispatch_get_main_queue(), ^{
  1192. //
  1193. //
  1194. //
  1195. // if([[return_json valueForKey:@"result"] intValue]==2)
  1196. // {
  1197. //
  1198. //
  1199. //#ifdef RA_NOTIFICATION
  1200. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1201. //#else
  1202. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1203. //
  1204. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1205. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1206. //#endif
  1207. // if(self.shopCartBlock!=nil)
  1208. // {
  1209. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1210. //
  1211. //
  1212. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1213. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1214. // iv.image = img;
  1215. // // [self.contentView addSubview:iv];
  1216. // self.shopCartBlock(iv);
  1217. //
  1218. // self.cqty +=count;
  1219. // if(self.set_cqty)
  1220. // self.set_cqty(self.cqty);
  1221. //
  1222. // }
  1223. //
  1224. //
  1225. // }
  1226. // else
  1227. // {
  1228. // UIViewController *vc= [RAUtils getViewController:self];
  1229. //
  1230. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1231. // NSString *title = @"Add To Cart";
  1232. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1233. // title = @"Add To Cart: Out of Stock";
  1234. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1235. // self.btnNotifyMe.enabled = YES;
  1236. // self.btnaddCart.enabled = NO;
  1237. // }
  1238. //
  1239. // [RAUtils message_alert:msg title:title controller:vc] ;
  1240. // }
  1241. //
  1242. //
  1243. //
  1244. //
  1245. // });
  1246. // });
  1247. }
  1248. //
  1249. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1250. //
  1251. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  1252. //
  1253. // dispatch_async(dispatch_get_main_queue(), ^{
  1254. //
  1255. //
  1256. //
  1257. // if([[return_json valueForKey:@"result"] intValue]==2)
  1258. // {
  1259. //
  1260. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  1261. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1262. //// appDelegate.order_code = order_code;
  1263. ////
  1264. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1265. //// appDelegate.order_code = order_code;
  1266. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1267. //
  1268. //
  1269. // if(self.shopCartBlock!=nil)
  1270. // {
  1271. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1272. //
  1273. //
  1274. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1275. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1276. // iv.image = img;
  1277. // // [self.contentView addSubview:iv];
  1278. // self.shopCartBlock(iv);
  1279. //
  1280. // self.cqty +=count;
  1281. // if(self.set_cqty)
  1282. // self.set_cqty(self.cqty);
  1283. //
  1284. // }
  1285. //
  1286. //
  1287. // }
  1288. // else
  1289. // {
  1290. // UIViewController *vc= [RAUtils getViewController:self];
  1291. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  1292. // }
  1293. //
  1294. //
  1295. //
  1296. //
  1297. // });
  1298. // });
  1299. //
  1300. }
  1301. }
  1302. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  1303. {
  1304. [super setSelected:selected animated:animated];
  1305. // Configure the view for the selected state
  1306. }
  1307. - (IBAction)selectorOnClick:(id)sender {
  1308. DebugLog(@"select click");
  1309. [celldelegate SelectorClicked:(UIButton*) sender];
  1310. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  1311. }
  1312. #pragma mark -
  1313. #pragma mark Deck DataSource Protocol Methods
  1314. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  1315. return [self.photos count];
  1316. }
  1317. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  1318. if(self.photos.count==0)
  1319. return nil;
  1320. return [self.photos objectAtIndex:index];
  1321. }
  1322. #pragma mark -
  1323. #pragma mark Deck Delegate Protocol Methods
  1324. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  1325. // User started moving a photo
  1326. }
  1327. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  1328. // User flicked the photo away, revealing the next one in the stack
  1329. }
  1330. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  1331. self.pageControl.currentPage = index;
  1332. }
  1333. - (UIView *)createVideoView:(NSString*) videoID
  1334. {
  1335. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  1336. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  1337. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  1338. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  1339. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  1340. titleLabel.text=@"a separated player will show here:";
  1341. titleLabel.numberOfLines = 0;
  1342. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1343. // titleLabel.textAlignment = NSTextAlignmentRight;
  1344. titleLabel.textAlignment = NSTextAlignmentCenter;
  1345. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  1346. // CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1347. CGSize sizetitle = [RAUtils sizeWithFont:@"a separated player will show here:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1348. //[titleLabel sizeToFit];
  1349. // titleLabel.center.x = demoView.center.x;
  1350. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  1351. [demoView addSubview:titleLabel];
  1352. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  1353. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  1354. lineLabel.text=videoID;
  1355. lineLabel.numberOfLines = 0;
  1356. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1357. // CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1358. CGSize sizemsg = [RAUtils sizeWithFont:videoID font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1359. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  1360. //[lineLabel sizeToFit];
  1361. [demoView addSubview:lineLabel];
  1362. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  1363. return demoView;
  1364. }
  1365. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  1366. DebugLog(@"selected %lu", (unsigned long)index);
  1367. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  1368. if([item[@"type"] isEqualToString:@"video"])
  1369. {
  1370. NSString* video_code=item[@"code"];
  1371. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  1372. // video_code=@"hqNcj6_lYg0";
  1373. // NSString* video_id=[self.playerView Embed2VID:video_code];
  1374. //
  1375. // NSDictionary *playerVars = @{
  1376. // @"playsinline" : @1,
  1377. // @"autoplay" : @(1),
  1378. // @"rel":@0,
  1379. // @"showinfo": @0,
  1380. // @"modestbranding":@0,
  1381. // @"enablejsapi":@1
  1382. // };
  1383. //
  1384. // [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  1385. [self.ytplayerView LoadWithVid:video_code];
  1386. for(UIView *v in self.ytplayerView.subviews)
  1387. {
  1388. if([v isKindOfClass:[UIButton class] ])
  1389. [self.ytplayerView bringSubviewToFront:v];
  1390. }
  1391. self.ytplayerView.hidden=false;
  1392. return;
  1393. } else {
  1394. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  1395. return;
  1396. }
  1397. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  1398. preVC.content = self.stack_contents;
  1399. // preVC.currentIndex = index;
  1400. [preVC setOffset:index];
  1401. UIViewController *superVC= [RAUtils getViewController:self];
  1402. [superVC.navigationController pushViewController:preVC animated:true];
  1403. return;
  1404. }
  1405. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  1406. // for (int i = 0; i < _data.count; i++) {
  1407. // UIImage *imgMod = _data[i];
  1408. // [imgList addObject:imgMod];
  1409. // }
  1410. // 调用展示窗口
  1411. // ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  1412. //
  1413. // UIViewController *vc= [RAUtils getViewController:self];
  1414. // [vc.navigationController pushViewController:imgShow animated:true];
  1415. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  1416. // [self presentViewController:nav animated:YES completion:nil];
  1417. // UIDocumentInteractionController
  1418. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  1419. // preview.delegate = self;
  1420. // [preview presentPreviewAnimated:YES];
  1421. }
  1422. -(void) neworder
  1423. {
  1424. __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{
  1425. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  1426. NSMutableDictionary* return_json = result;
  1427. [waitalert dismissViewControllerAnimated:YES completion:^{
  1428. if([[return_json valueForKey:@"result"] intValue]==2)
  1429. {
  1430. int result=[[return_json valueForKey:@"result"] intValue];
  1431. if(result==2)
  1432. {
  1433. //successed.
  1434. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1435. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1436. appDelegate.order_code = order_code;
  1437. int count=[self.quantity_text.text intValue];
  1438. [self addtocart:count];
  1439. // [self ReloadData];
  1440. // if(self.shopCartBlock!=nil)
  1441. // {
  1442. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1443. //
  1444. //
  1445. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1446. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1447. // iv.image = img;
  1448. // // [self.contentView addSubview:iv];
  1449. // self.shopCartBlock(iv);
  1450. //
  1451. // }
  1452. }
  1453. }
  1454. else
  1455. {
  1456. UIViewController *vc= [RAUtils getViewController:self];
  1457. NSString *msg = [return_json valueForKey:@"err_msg"];
  1458. NSString *title = @"Add To Cart";
  1459. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1460. title = @"Add To Cart: Out of Stock";
  1461. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1462. self.btnNotifyMe.enabled = YES;
  1463. self.btnaddCart.enabled = NO;
  1464. }
  1465. [RAUtils message_alert:msg title:title controller:vc] ;
  1466. }
  1467. }];
  1468. }];
  1469. }];
  1470. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1471. //
  1472. // NSDictionary* return_json = [RANetwork new_Order];
  1473. //
  1474. // dispatch_async(dispatch_get_main_queue(), ^{
  1475. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1476. //
  1477. //
  1478. // if([[return_json valueForKey:@"result"] intValue]==2)
  1479. // {
  1480. // int result=[[return_json valueForKey:@"result"] intValue];
  1481. // if(result==2)
  1482. // {
  1483. // //successed.
  1484. //
  1485. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  1486. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1487. // appDelegate.order_code = order_code;
  1488. //
  1489. // int count=[self.quantity_text.text intValue];
  1490. // [self addtocart:count];
  1491. //
  1492. //
  1493. // // [self ReloadData];
  1494. //
  1495. //
  1496. // // if(self.shopCartBlock!=nil)
  1497. // // {
  1498. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1499. // //
  1500. // //
  1501. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1502. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1503. // // iv.image = img;
  1504. // // // [self.contentView addSubview:iv];
  1505. // // self.shopCartBlock(iv);
  1506. // //
  1507. // // }
  1508. //
  1509. // }
  1510. // }
  1511. // else
  1512. // {
  1513. // UIViewController *vc= [RAUtils getViewController:self];
  1514. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1515. // NSString *title = @"Add To Cart";
  1516. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1517. // title = @"Add To Cart: Out of Stock";
  1518. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1519. // self.btnNotifyMe.enabled = YES;
  1520. // self.btnaddCart.enabled = NO;
  1521. // }
  1522. //
  1523. // [RAUtils message_alert:msg title:title controller:vc] ;
  1524. // }
  1525. //
  1526. //
  1527. //
  1528. //
  1529. // });
  1530. // });
  1531. }
  1532. //#pragma mark - UIAlertViewDelegate
  1533. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1534. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1535. //{
  1536. // UIApplication * app = [UIApplication sharedApplication];
  1537. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1538. // if(alertView.tag==1234)//库存小于0
  1539. // {
  1540. //
  1541. // // availability warring;
  1542. //
  1543. // int count=[self.quantity_text.text intValue];
  1544. // if(buttonIndex!=alertView.cancelButtonIndex)
  1545. // {
  1546. // if(appDelegate.order_code==nil)
  1547. // {
  1548. // [self neworder];
  1549. // }
  1550. // else
  1551. // {
  1552. // [self addtocart:count];
  1553. // }
  1554. // }
  1555. // return;
  1556. // }
  1557. // // int count=[self.quantity_text.text intValue];
  1558. //
  1559. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1560. // if(buttonIndex==alertView.cancelButtonIndex)
  1561. // {
  1562. //
  1563. //
  1564. //
  1565. // }
  1566. // else if(buttonIndex==1)
  1567. // {
  1568. // //open exist
  1569. // UIViewController *vc= [RAUtils getViewController:self];
  1570. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1571. // ovc.showNavibar = true;
  1572. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1573. // if(appDelegate.order_code==nil)
  1574. // {
  1575. // [self neworder];
  1576. // }
  1577. // else
  1578. // {
  1579. // if(self.set_update_data)
  1580. // self.set_update_data(true);
  1581. //
  1582. // int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  1583. // for(int i=0;i<model_count;i++)
  1584. // {
  1585. // NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1586. // NSString* product_id = [item valueForKey:@"product_id"];
  1587. // if([product_id isEqualToString:self.product_id])
  1588. // {
  1589. // self.cqty = [[item valueForKey:@"QTY"]intValue];
  1590. // if(self.set_cqty)
  1591. // self.set_cqty(self.cqty);
  1592. // break;
  1593. // }
  1594. //
  1595. // }
  1596. // int count=[self.quantity_text.text intValue];
  1597. // [self addtocart:count];
  1598. // [main_vc checklogin:true];
  1599. //
  1600. //
  1601. // }
  1602. //
  1603. // };
  1604. // ovc.init_style = OL_OPEN;
  1605. // ovc.onCancel = ^(){
  1606. //
  1607. // [main_vc checklogin:true];
  1608. //
  1609. // };
  1610. //
  1611. // [vc.navigationController pushViewController:ovc animated:true];
  1612. // }
  1613. // else
  1614. // {
  1615. // //create new;
  1616. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1617. // {
  1618. // UIViewController *vc= [RAUtils getViewController:self];
  1619. //
  1620. //
  1621. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1622. //
  1623. // cvc.showNavibar = true;
  1624. // cvc.contact_type = @"Sales_Order_Customer";
  1625. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1626. //
  1627. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1628. // appDelegate.customerInfo = value;
  1629. //
  1630. //
  1631. // if(appDelegate.order_code==nil)
  1632. // [self neworder];
  1633. //
  1634. // [main_vc checklogin:true];
  1635. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1636. //
  1637. // //
  1638. // // if(self.returnValue)
  1639. // // self.returnValue(value);
  1640. // };
  1641. //
  1642. // cvc.onCancel = ^(){
  1643. //
  1644. // UIViewController *vc= [RAUtils getViewController:self];
  1645. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"New Order" controller:vc];
  1646. //
  1647. // };
  1648. // cvc.onReset = ^(){
  1649. // [main_vc checklogin:true];
  1650. // };
  1651. //
  1652. // [vc.navigationController pushViewController:cvc animated:true];
  1653. // }
  1654. // else
  1655. // {
  1656. // [self neworder];
  1657. // }
  1658. //
  1659. //
  1660. // }
  1661. //}
  1662. - (void)valueChanged:(UIStepper *)sender {
  1663. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  1664. [celldelegate stepClicked:(int)sender.value];
  1665. // -(void) stepClicked:(int) value;
  1666. // 检查缺货
  1667. // NSString *cartQtyString = nil;
  1668. // if (self.cqyt_label.text) {
  1669. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  1670. // }
  1671. //
  1672. // int availability = [self.count_Label.text intValue];
  1673. // int buyQTY = [self.quantity_text.text intValue];
  1674. // int cartQTY = [cartQtyString intValue];
  1675. //
  1676. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  1677. }
  1678. #pragma mark -
  1679. #pragma mark Actions
  1680. -(void)ClearPhotos
  1681. {
  1682. NSMutableArray *photosMutable = [self.photos mutableCopy];
  1683. [photosMutable removeAllObjects];
  1684. self.photos = photosMutable;
  1685. [self.photoStack reloadData];
  1686. }
  1687. - (void)AddPhoto :(UIImage*)photo {
  1688. NSMutableArray *photosMutable = [self.photos mutableCopy];
  1689. [photosMutable addObject:photo];
  1690. self.photos = photosMutable;
  1691. [self.photoStack reloadData];
  1692. self.pageControl.numberOfPages = [self.photos count];
  1693. if(self.photos.count<2-1)//1 for qrcode;
  1694. self.photoStack.showBorder=false;
  1695. else
  1696. self.photoStack.showBorder=true;
  1697. }
  1698. #pragma mark -
  1699. #pragma mark Setup
  1700. -(void)setup {
  1701. // int availability = [self.count_Label.text intValue];
  1702. self.stepper.minimumValue= self.step;
  1703. self.stepper.maximumValue = INTMAX_MAX;
  1704. self.stepper.stepValue= self.step;
  1705. self.stepper.value= self.quantity;
  1706. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  1707. if(true)//(self.photos==nil)
  1708. {
  1709. self.photos = [NSArray array];
  1710. }
  1711. if(true)//(self.photoStack==nil)
  1712. {
  1713. // if(self.photoStack!=nil)
  1714. // [self.photoStack removeFromSuperview];
  1715. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  1716. // self.photoStack.backgroundColor =[UIColor redColor];
  1717. // self.photoStack.center = CGPointMake(self.center.x, 220);
  1718. self.photoStack.dataSource = self;
  1719. self.photoStack.delegate = self;
  1720. // [self addSubview:self.photoStack];
  1721. self.pageControl.numberOfPages = [self.photos count];
  1722. }
  1723. }
  1724. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  1725. if (self.notifyMeBlock) {
  1726. self.notifyMeBlock();
  1727. }
  1728. }
  1729. #pragma mark - TextField Delegate
  1730. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  1731. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  1732. // NSString *cartQtyString = nil;
  1733. // if (self.cqyt_label.text) {
  1734. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  1735. // }
  1736. // int availability = [self.count_Label.text intValue];
  1737. int buyQTY = [newString intValue];
  1738. // int cartQTY = [cartQtyString intValue];
  1739. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  1740. self.stepper.value = buyQTY;
  1741. return YES;
  1742. }
  1743. #pragma mark - Private
  1744. /**检查是否缺货*/
  1745. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  1746. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  1747. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1748. if (!appDelegate.bLogin || buyQty < 1) {
  1749. return;
  1750. }
  1751. #ifdef OFFLINE_MODE
  1752. if (appDelegate.offline_mode) {
  1753. return;
  1754. }
  1755. #endif
  1756. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  1757. if (!appDelegate.order_code) { // 未打开订单状态
  1758. if ((buyQty + cartQty) > availability) {
  1759. self.btnaddCart.enabled = NO;
  1760. self.btnNotifyMe.enabled = YES;
  1761. } else {
  1762. self.btnaddCart.enabled = YES;
  1763. self.btnNotifyMe.enabled = NO;
  1764. }
  1765. } else {
  1766. // 打开订单状态
  1767. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1768. // Shop Order
  1769. self.btnaddCart.enabled = YES;
  1770. // 默认未缺货
  1771. self.btnNotifyMe.enabled = NO;
  1772. if ((buyQty + cartQty) > availability) { // 缺货
  1773. self.btnNotifyMe.enabled = YES;
  1774. }
  1775. } else {
  1776. // Purchase Order
  1777. if ((buyQty + cartQty) > availability) { // 缺货
  1778. self.btnaddCart.enabled = NO;
  1779. self.btnNotifyMe.enabled = YES;
  1780. } else { // 未缺货
  1781. self.btnNotifyMe.enabled = NO;
  1782. self.btnaddCart.enabled = YES;
  1783. }
  1784. }
  1785. }
  1786. } else { // empoyee
  1787. if ((buyQty + cartQty) > availability) { // 缺货
  1788. self.btnaddCart.enabled = NO;
  1789. self.btnNotifyMe.enabled = YES;
  1790. } else { // 未缺货
  1791. self.btnNotifyMe.enabled = NO;
  1792. self.btnaddCart.enabled = YES;
  1793. }
  1794. }
  1795. //#endif
  1796. }
  1797. - (IBAction)introduceBtnClick:(UIButton *)sender {
  1798. if (self.introduceBlock) {
  1799. self.introduceBlock(sender);
  1800. }
  1801. }
  1802. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  1803. if (self.descriptionBlock) {
  1804. self.descriptionBlock(sender);
  1805. }
  1806. }
  1807. - (IBAction)OnClosePlayer:(id)sender {
  1808. [self.ytplayerView stopVideo];
  1809. self.ytplayerView.hidden=true;
  1810. }
  1811. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  1812. UIApplication * app = [UIApplication sharedApplication];
  1813. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1814. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1815. if(appDelegate.bLogin==false) {
  1816. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  1817. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1818. loginvc.returnValue = ^(bool blogin){
  1819. if(blogin) {
  1820. [vc reload];
  1821. [main_vc checklogin:true];
  1822. }
  1823. };
  1824. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1825. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1826. [vc presentViewController:navi animated:YES completion:^{
  1827. }];
  1828. }
  1829. }
  1830. @end