DetailHeaderCell.m 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250
  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. if(self.cqty>0)
  730. {
  731. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  732. //block代码块取代了delegate
  733. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  734. int c=self.cqty+count;
  735. int m=c%self.step;
  736. if(m!=0&&appDelegate.alert_sold_in_quantities)
  737. {
  738. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  739. //block代码块取代了delegate
  740. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  741. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  742. NSDictionary* return_json = result;
  743. if([[return_json valueForKey:@"result"] intValue]==2)
  744. {
  745. // NSString* order_code = [return_json valueForKey:@"order_code"];
  746. #ifdef RA_NOTIFICATION
  747. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  748. #else
  749. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  750. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  751. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  752. #endif
  753. if(self.shopCartBlock!=nil)
  754. {
  755. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  756. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  757. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  758. iv.image = img;
  759. // [self.contentView addSubview:iv];
  760. self.shopCartBlock(iv);
  761. self.cqty +=count;
  762. if(self.set_cqty)
  763. self.set_cqty(self.cqty);
  764. }
  765. }
  766. else
  767. {
  768. UIViewController *vc= [RAUtils getViewController:self];
  769. NSString *msg = [return_json valueForKey:@"err_msg"];
  770. NSString *title = @"Add To Cart";
  771. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  772. title = @"Add To Cart: Out of Stock";
  773. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  774. self.btnNotifyMe.enabled = YES;
  775. self.btnaddCart.enabled = NO;
  776. }
  777. [RAUtils message_alert:msg title:title controller:vc] ;
  778. }
  779. }];
  780. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  781. //
  782. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  783. //
  784. // dispatch_async(dispatch_get_main_queue(), ^{
  785. //
  786. //
  787. //
  788. // if([[return_json valueForKey:@"result"] intValue]==2)
  789. // {
  790. //
  791. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  792. //
  793. //
  794. //
  795. //
  796. //#ifdef RA_NOTIFICATION
  797. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  798. //#else
  799. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  800. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  801. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  802. //#endif
  803. // if(self.shopCartBlock!=nil)
  804. // {
  805. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  806. //
  807. //
  808. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  809. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  810. // iv.image = img;
  811. // // [self.contentView addSubview:iv];
  812. // self.shopCartBlock(iv);
  813. //
  814. // self.cqty +=count;
  815. // if(self.set_cqty)
  816. // self.set_cqty(self.cqty);
  817. //
  818. // }
  819. //
  820. //
  821. // }
  822. // else
  823. // {
  824. // UIViewController *vc= [RAUtils getViewController:self];
  825. // NSString *msg = [return_json valueForKey:@"err_msg"];
  826. // NSString *title = @"Add To Cart";
  827. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  828. // title = @"Add To Cart: Out of Stock";
  829. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  830. // self.btnNotifyMe.enabled = YES;
  831. // self.btnaddCart.enabled = NO;
  832. // }
  833. //
  834. // [RAUtils message_alert:msg title:title controller:vc] ;
  835. // }
  836. //
  837. //
  838. //
  839. //
  840. // });
  841. // });
  842. }];
  843. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  844. DebugLog(@"No");
  845. }];
  846. [alertControl addAction:actionOne];
  847. [alertControl addAction:alertthree];
  848. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  849. UIViewController *vc= [RAUtils getViewController:self];
  850. [vc presentViewController:alertControl animated:YES completion:nil];
  851. }
  852. else
  853. {
  854. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  855. NSDictionary* return_json = result;
  856. if([[return_json valueForKey:@"result"] intValue]==2)
  857. {
  858. // NSString* order_code = [return_json valueForKey:@"order_code"];
  859. #ifdef RA_NOTIFICATION
  860. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  861. #else
  862. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  863. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  864. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  865. #endif
  866. if(self.shopCartBlock!=nil)
  867. {
  868. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  869. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  870. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  871. iv.image = img;
  872. // [self.contentView addSubview:iv];
  873. self.shopCartBlock(iv);
  874. self.cqty +=count;
  875. if(self.set_cqty)
  876. self.set_cqty(self.cqty);
  877. }
  878. }
  879. else
  880. {
  881. UIViewController *vc= [RAUtils getViewController:self];
  882. NSString *msg = [return_json valueForKey:@"err_msg"];
  883. NSString *title = @"Add To Cart";
  884. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  885. title = @"Add To Cart: Out of Stock";
  886. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  887. self.btnNotifyMe.enabled = YES;
  888. self.btnaddCart.enabled = NO;
  889. }
  890. [RAUtils message_alert:msg title:title controller:vc] ;
  891. }
  892. }];
  893. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  894. //
  895. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  896. //
  897. // dispatch_async(dispatch_get_main_queue(), ^{
  898. //
  899. //
  900. //
  901. // if([[return_json valueForKey:@"result"] intValue]==2)
  902. // {
  903. //
  904. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  905. //
  906. //
  907. //#ifdef RA_NOTIFICATION
  908. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  909. //#else
  910. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  911. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  912. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  913. //#endif
  914. // if(self.shopCartBlock!=nil)
  915. // {
  916. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  917. //
  918. //
  919. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  920. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  921. // iv.image = img;
  922. // // [self.contentView addSubview:iv];
  923. // self.shopCartBlock(iv);
  924. //
  925. // self.cqty +=count;
  926. // if(self.set_cqty)
  927. // self.set_cqty(self.cqty);
  928. //
  929. // }
  930. //
  931. //
  932. // }
  933. // else
  934. // {
  935. // UIViewController *vc= [RAUtils getViewController:self];
  936. // NSString *msg = [return_json valueForKey:@"err_msg"];
  937. // NSString *title = @"Add To Cart";
  938. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  939. // title = @"Add To Cart: Out of Stock";
  940. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  941. // self.btnNotifyMe.enabled = YES;
  942. // self.btnaddCart.enabled = NO;
  943. // }
  944. //
  945. // [RAUtils message_alert:msg title:title controller:vc] ;
  946. // }
  947. //
  948. //
  949. //
  950. //
  951. // });
  952. // });
  953. }
  954. //
  955. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  956. //
  957. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  958. //
  959. // dispatch_async(dispatch_get_main_queue(), ^{
  960. //
  961. //
  962. //
  963. // if([[return_json valueForKey:@"result"] intValue]==2)
  964. // {
  965. //
  966. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  967. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  968. //// appDelegate.order_code = order_code;
  969. ////
  970. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  971. //// appDelegate.order_code = order_code;
  972. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  973. //
  974. //
  975. // if(self.shopCartBlock!=nil)
  976. // {
  977. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  978. //
  979. //
  980. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  981. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  982. // iv.image = img;
  983. // // [self.contentView addSubview:iv];
  984. // self.shopCartBlock(iv);
  985. //
  986. // self.cqty +=count;
  987. // if(self.set_cqty)
  988. // self.set_cqty(self.cqty);
  989. //
  990. // }
  991. //
  992. //
  993. // }
  994. // else
  995. // {
  996. // UIViewController *vc= [RAUtils getViewController:self];
  997. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  998. // }
  999. //
  1000. //
  1001. //
  1002. //
  1003. // });
  1004. // });
  1005. //
  1006. }];
  1007. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1008. DebugLog(@"No");
  1009. }];
  1010. [alertControl addAction:actionOne];
  1011. [alertControl addAction:alertthree];
  1012. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1013. UIViewController *vc= [RAUtils getViewController:self];
  1014. [vc presentViewController:alertControl animated:YES completion:nil];
  1015. }
  1016. else
  1017. {
  1018. int c=self.cqty+count;
  1019. int m=c%self.step;
  1020. if(m!=0&&appDelegate.alert_sold_in_quantities)
  1021. {
  1022. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  1023. //block代码块取代了delegate
  1024. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1025. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  1026. NSDictionary* return_json =result;
  1027. if([[return_json valueForKey:@"result"] intValue]==2)
  1028. {
  1029. #ifdef RA_NOTIFICATION
  1030. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1031. #else
  1032. // NSString* order_code = [return_json valueForKey:@"order_code"];
  1033. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1034. // appDelegate.order_code = order_code;
  1035. //
  1036. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1037. // appDelegate.order_code = order_code;
  1038. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1039. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1040. #endif
  1041. if(self.shopCartBlock!=nil)
  1042. {
  1043. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1044. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1045. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1046. iv.image = img;
  1047. // [self.contentView addSubview:iv];
  1048. self.shopCartBlock(iv);
  1049. self.cqty +=count;
  1050. if(self.set_cqty)
  1051. self.set_cqty(self.cqty);
  1052. }
  1053. }
  1054. else
  1055. {
  1056. UIViewController *vc= [RAUtils getViewController:self];
  1057. NSString *msg = [return_json valueForKey:@"err_msg"];
  1058. NSString *title = @"Add To Cart";
  1059. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1060. title = @"Add To Cart: Out of Stock";
  1061. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1062. self.btnNotifyMe.enabled = YES;
  1063. self.btnaddCart.enabled = NO;
  1064. }
  1065. [RAUtils message_alert:msg title:title controller:vc] ;
  1066. }
  1067. }];
  1068. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1069. //
  1070. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  1071. //
  1072. // dispatch_async(dispatch_get_main_queue(), ^{
  1073. //
  1074. //
  1075. //
  1076. // if([[return_json valueForKey:@"result"] intValue]==2)
  1077. // {
  1078. //
  1079. //
  1080. //
  1081. //#ifdef RA_NOTIFICATION
  1082. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1083. //#else
  1084. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  1085. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1086. // // appDelegate.order_code = order_code;
  1087. // //
  1088. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1089. // // appDelegate.order_code = order_code;
  1090. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1091. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1092. //#endif
  1093. // if(self.shopCartBlock!=nil)
  1094. // {
  1095. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1096. //
  1097. //
  1098. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1099. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1100. // iv.image = img;
  1101. // // [self.contentView addSubview:iv];
  1102. // self.shopCartBlock(iv);
  1103. //
  1104. // self.cqty +=count;
  1105. // if(self.set_cqty)
  1106. // self.set_cqty(self.cqty);
  1107. //
  1108. // }
  1109. //
  1110. //
  1111. // }
  1112. // else
  1113. // {
  1114. // UIViewController *vc= [RAUtils getViewController:self];
  1115. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1116. // NSString *title = @"Add To Cart";
  1117. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1118. // title = @"Add To Cart: Out of Stock";
  1119. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1120. // self.btnNotifyMe.enabled = YES;
  1121. // self.btnaddCart.enabled = NO;
  1122. // }
  1123. //
  1124. // [RAUtils message_alert:msg title:title controller:vc] ;
  1125. // }
  1126. //
  1127. //
  1128. //
  1129. //
  1130. // });
  1131. // });
  1132. }];
  1133. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1134. DebugLog(@"No");
  1135. }];
  1136. [alertControl addAction:actionOne];
  1137. [alertControl addAction:alertthree];
  1138. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1139. UIViewController *vc= [RAUtils getViewController:self];
  1140. [vc presentViewController:alertControl animated:YES completion:nil];
  1141. }
  1142. else
  1143. {
  1144. NSString* model_name=self.model_label.text;
  1145. [RANetwork request_addto_cart:self.product_id count:count name:model_name completionHandler:^(NSMutableDictionary *result) {
  1146. NSDictionary* return_json = result;
  1147. if([[return_json valueForKey:@"result"] intValue]==2)
  1148. {
  1149. #ifdef RA_NOTIFICATION
  1150. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1151. #else
  1152. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1153. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1154. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1155. #endif
  1156. if(self.shopCartBlock!=nil)
  1157. {
  1158. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1159. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1160. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1161. iv.image = img;
  1162. // [self.contentView addSubview:iv];
  1163. self.shopCartBlock(iv);
  1164. self.cqty +=count;
  1165. if(self.set_cqty)
  1166. self.set_cqty(self.cqty);
  1167. }
  1168. }
  1169. else
  1170. {
  1171. UIViewController *vc= [RAUtils getViewController:self];
  1172. NSString *msg = [return_json valueForKey:@"err_msg"];
  1173. NSString *title = @"Add To Cart";
  1174. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1175. title = @"Add To Cart: Out of Stock";
  1176. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1177. self.btnNotifyMe.enabled = YES;
  1178. self.btnaddCart.enabled = NO;
  1179. }
  1180. [RAUtils message_alert:msg title:title controller:vc] ;
  1181. }
  1182. }];
  1183. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1184. //
  1185. // NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:model_name];
  1186. //
  1187. // dispatch_async(dispatch_get_main_queue(), ^{
  1188. //
  1189. //
  1190. //
  1191. // if([[return_json valueForKey:@"result"] intValue]==2)
  1192. // {
  1193. //
  1194. //
  1195. //#ifdef RA_NOTIFICATION
  1196. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1197. //#else
  1198. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1199. //
  1200. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1201. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1202. //#endif
  1203. // if(self.shopCartBlock!=nil)
  1204. // {
  1205. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1206. //
  1207. //
  1208. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1209. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1210. // iv.image = img;
  1211. // // [self.contentView addSubview:iv];
  1212. // self.shopCartBlock(iv);
  1213. //
  1214. // self.cqty +=count;
  1215. // if(self.set_cqty)
  1216. // self.set_cqty(self.cqty);
  1217. //
  1218. // }
  1219. //
  1220. //
  1221. // }
  1222. // else
  1223. // {
  1224. // UIViewController *vc= [RAUtils getViewController:self];
  1225. //
  1226. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1227. // NSString *title = @"Add To Cart";
  1228. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1229. // title = @"Add To Cart: Out of Stock";
  1230. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1231. // self.btnNotifyMe.enabled = YES;
  1232. // self.btnaddCart.enabled = NO;
  1233. // }
  1234. //
  1235. // [RAUtils message_alert:msg title:title controller:vc] ;
  1236. // }
  1237. //
  1238. //
  1239. //
  1240. //
  1241. // });
  1242. // });
  1243. }
  1244. //
  1245. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1246. //
  1247. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  1248. //
  1249. // dispatch_async(dispatch_get_main_queue(), ^{
  1250. //
  1251. //
  1252. //
  1253. // if([[return_json valueForKey:@"result"] intValue]==2)
  1254. // {
  1255. //
  1256. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  1257. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1258. //// appDelegate.order_code = order_code;
  1259. ////
  1260. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1261. //// appDelegate.order_code = order_code;
  1262. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1263. //
  1264. //
  1265. // if(self.shopCartBlock!=nil)
  1266. // {
  1267. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1268. //
  1269. //
  1270. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1271. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1272. // iv.image = img;
  1273. // // [self.contentView addSubview:iv];
  1274. // self.shopCartBlock(iv);
  1275. //
  1276. // self.cqty +=count;
  1277. // if(self.set_cqty)
  1278. // self.set_cqty(self.cqty);
  1279. //
  1280. // }
  1281. //
  1282. //
  1283. // }
  1284. // else
  1285. // {
  1286. // UIViewController *vc= [RAUtils getViewController:self];
  1287. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  1288. // }
  1289. //
  1290. //
  1291. //
  1292. //
  1293. // });
  1294. // });
  1295. //
  1296. }
  1297. }
  1298. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  1299. {
  1300. [super setSelected:selected animated:animated];
  1301. // Configure the view for the selected state
  1302. }
  1303. - (IBAction)selectorOnClick:(id)sender {
  1304. DebugLog(@"select click");
  1305. [celldelegate SelectorClicked:(UIButton*) sender];
  1306. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  1307. }
  1308. #pragma mark -
  1309. #pragma mark Deck DataSource Protocol Methods
  1310. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  1311. return [self.photos count];
  1312. }
  1313. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  1314. if(self.photos.count==0)
  1315. return nil;
  1316. return [self.photos objectAtIndex:index];
  1317. }
  1318. #pragma mark -
  1319. #pragma mark Deck Delegate Protocol Methods
  1320. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  1321. // User started moving a photo
  1322. }
  1323. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  1324. // User flicked the photo away, revealing the next one in the stack
  1325. }
  1326. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  1327. self.pageControl.currentPage = index;
  1328. }
  1329. - (UIView *)createVideoView:(NSString*) videoID
  1330. {
  1331. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  1332. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  1333. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  1334. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  1335. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  1336. titleLabel.text=@"a separated player will show here:";
  1337. titleLabel.numberOfLines = 0;
  1338. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1339. // titleLabel.textAlignment = NSTextAlignmentRight;
  1340. titleLabel.textAlignment = NSTextAlignmentCenter;
  1341. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  1342. // CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1343. CGSize sizetitle = [RAUtils sizeWithFont:@"a separated player will show here:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1344. //[titleLabel sizeToFit];
  1345. // titleLabel.center.x = demoView.center.x;
  1346. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  1347. [demoView addSubview:titleLabel];
  1348. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  1349. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  1350. lineLabel.text=videoID;
  1351. lineLabel.numberOfLines = 0;
  1352. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1353. // CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1354. CGSize sizemsg = [RAUtils sizeWithFont:videoID font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1355. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  1356. //[lineLabel sizeToFit];
  1357. [demoView addSubview:lineLabel];
  1358. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  1359. return demoView;
  1360. }
  1361. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  1362. DebugLog(@"selected %lu", (unsigned long)index);
  1363. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  1364. if([item[@"type"] isEqualToString:@"video"])
  1365. {
  1366. NSString* video_code=item[@"code"];
  1367. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  1368. // video_code=@"hqNcj6_lYg0";
  1369. // NSString* video_id=[self.playerView Embed2VID:video_code];
  1370. //
  1371. // NSDictionary *playerVars = @{
  1372. // @"playsinline" : @1,
  1373. // @"autoplay" : @(1),
  1374. // @"rel":@0,
  1375. // @"showinfo": @0,
  1376. // @"modestbranding":@0,
  1377. // @"enablejsapi":@1
  1378. // };
  1379. //
  1380. // [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  1381. [self.ytplayerView LoadWithVid:video_code];
  1382. for(UIView *v in self.ytplayerView.subviews)
  1383. {
  1384. if([v isKindOfClass:[UIButton class] ])
  1385. [self.ytplayerView bringSubviewToFront:v];
  1386. }
  1387. self.ytplayerView.hidden=false;
  1388. return;
  1389. } else {
  1390. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  1391. return;
  1392. }
  1393. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  1394. preVC.content = self.stack_contents;
  1395. // preVC.currentIndex = index;
  1396. [preVC setOffset:index];
  1397. UIViewController *superVC= [RAUtils getViewController:self];
  1398. [superVC.navigationController pushViewController:preVC animated:true];
  1399. return;
  1400. }
  1401. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  1402. // for (int i = 0; i < _data.count; i++) {
  1403. // UIImage *imgMod = _data[i];
  1404. // [imgList addObject:imgMod];
  1405. // }
  1406. // 调用展示窗口
  1407. // ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  1408. //
  1409. // UIViewController *vc= [RAUtils getViewController:self];
  1410. // [vc.navigationController pushViewController:imgShow animated:true];
  1411. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  1412. // [self presentViewController:nav animated:YES completion:nil];
  1413. // UIDocumentInteractionController
  1414. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  1415. // preview.delegate = self;
  1416. // [preview presentPreviewAnimated:YES];
  1417. }
  1418. -(void) neworder
  1419. {
  1420. __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{
  1421. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  1422. NSMutableDictionary* return_json = result;
  1423. [waitalert dismissViewControllerAnimated:YES completion:^{
  1424. if([[return_json valueForKey:@"result"] intValue]==2)
  1425. {
  1426. int result=[[return_json valueForKey:@"result"] intValue];
  1427. if(result==2)
  1428. {
  1429. //successed.
  1430. NSString* order_code = [return_json valueForKey:@"orderCode"];
  1431. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1432. appDelegate.order_code = order_code;
  1433. int count=[self.quantity_text.text intValue];
  1434. [self addtocart:count];
  1435. // [self ReloadData];
  1436. // if(self.shopCartBlock!=nil)
  1437. // {
  1438. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1439. //
  1440. //
  1441. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1442. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1443. // iv.image = img;
  1444. // // [self.contentView addSubview:iv];
  1445. // self.shopCartBlock(iv);
  1446. //
  1447. // }
  1448. }
  1449. }
  1450. else
  1451. {
  1452. UIViewController *vc= [RAUtils getViewController:self];
  1453. NSString *msg = [return_json valueForKey:@"err_msg"];
  1454. NSString *title = @"Add To Cart";
  1455. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1456. title = @"Add To Cart: Out of Stock";
  1457. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1458. self.btnNotifyMe.enabled = YES;
  1459. self.btnaddCart.enabled = NO;
  1460. }
  1461. [RAUtils message_alert:msg title:title controller:vc] ;
  1462. }
  1463. }];
  1464. }];
  1465. }];
  1466. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1467. //
  1468. // NSDictionary* return_json = [RANetwork new_Order];
  1469. //
  1470. // dispatch_async(dispatch_get_main_queue(), ^{
  1471. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1472. //
  1473. //
  1474. // if([[return_json valueForKey:@"result"] intValue]==2)
  1475. // {
  1476. // int result=[[return_json valueForKey:@"result"] intValue];
  1477. // if(result==2)
  1478. // {
  1479. // //successed.
  1480. //
  1481. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  1482. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1483. // appDelegate.order_code = order_code;
  1484. //
  1485. // int count=[self.quantity_text.text intValue];
  1486. // [self addtocart:count];
  1487. //
  1488. //
  1489. // // [self ReloadData];
  1490. //
  1491. //
  1492. // // if(self.shopCartBlock!=nil)
  1493. // // {
  1494. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  1495. // //
  1496. // //
  1497. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  1498. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  1499. // // iv.image = img;
  1500. // // // [self.contentView addSubview:iv];
  1501. // // self.shopCartBlock(iv);
  1502. // //
  1503. // // }
  1504. //
  1505. // }
  1506. // }
  1507. // else
  1508. // {
  1509. // UIViewController *vc= [RAUtils getViewController:self];
  1510. // NSString *msg = [return_json valueForKey:@"err_msg"];
  1511. // NSString *title = @"Add To Cart";
  1512. // if ([msg hasPrefix:@"Out of Stock.\n"]) {
  1513. // title = @"Add To Cart: Out of Stock";
  1514. // msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  1515. // self.btnNotifyMe.enabled = YES;
  1516. // self.btnaddCart.enabled = NO;
  1517. // }
  1518. //
  1519. // [RAUtils message_alert:msg title:title controller:vc] ;
  1520. // }
  1521. //
  1522. //
  1523. //
  1524. //
  1525. // });
  1526. // });
  1527. }
  1528. //#pragma mark - UIAlertViewDelegate
  1529. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1530. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1531. //{
  1532. // UIApplication * app = [UIApplication sharedApplication];
  1533. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1534. // if(alertView.tag==1234)//库存小于0
  1535. // {
  1536. //
  1537. // // availability warring;
  1538. //
  1539. // int count=[self.quantity_text.text intValue];
  1540. // if(buttonIndex!=alertView.cancelButtonIndex)
  1541. // {
  1542. // if(appDelegate.order_code==nil)
  1543. // {
  1544. // [self neworder];
  1545. // }
  1546. // else
  1547. // {
  1548. // [self addtocart:count];
  1549. // }
  1550. // }
  1551. // return;
  1552. // }
  1553. // // int count=[self.quantity_text.text intValue];
  1554. //
  1555. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1556. // if(buttonIndex==alertView.cancelButtonIndex)
  1557. // {
  1558. //
  1559. //
  1560. //
  1561. // }
  1562. // else if(buttonIndex==1)
  1563. // {
  1564. // //open exist
  1565. // UIViewController *vc= [RAUtils getViewController:self];
  1566. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1567. // ovc.showNavibar = true;
  1568. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1569. // if(appDelegate.order_code==nil)
  1570. // {
  1571. // [self neworder];
  1572. // }
  1573. // else
  1574. // {
  1575. // if(self.set_update_data)
  1576. // self.set_update_data(true);
  1577. //
  1578. // int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  1579. // for(int i=0;i<model_count;i++)
  1580. // {
  1581. // NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1582. // NSString* product_id = [item valueForKey:@"product_id"];
  1583. // if([product_id isEqualToString:self.product_id])
  1584. // {
  1585. // self.cqty = [[item valueForKey:@"QTY"]intValue];
  1586. // if(self.set_cqty)
  1587. // self.set_cqty(self.cqty);
  1588. // break;
  1589. // }
  1590. //
  1591. // }
  1592. // int count=[self.quantity_text.text intValue];
  1593. // [self addtocart:count];
  1594. // [main_vc checklogin:true];
  1595. //
  1596. //
  1597. // }
  1598. //
  1599. // };
  1600. // ovc.init_style = OL_OPEN;
  1601. // ovc.onCancel = ^(){
  1602. //
  1603. // [main_vc checklogin:true];
  1604. //
  1605. // };
  1606. //
  1607. // [vc.navigationController pushViewController:ovc animated:true];
  1608. // }
  1609. // else
  1610. // {
  1611. // //create new;
  1612. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1613. // {
  1614. // UIViewController *vc= [RAUtils getViewController:self];
  1615. //
  1616. //
  1617. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1618. //
  1619. // cvc.showNavibar = true;
  1620. // cvc.contact_type = @"Sales_Order_Customer";
  1621. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1622. //
  1623. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1624. // appDelegate.customerInfo = value;
  1625. //
  1626. //
  1627. // if(appDelegate.order_code==nil)
  1628. // [self neworder];
  1629. //
  1630. // [main_vc checklogin:true];
  1631. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1632. //
  1633. // //
  1634. // // if(self.returnValue)
  1635. // // self.returnValue(value);
  1636. // };
  1637. //
  1638. // cvc.onCancel = ^(){
  1639. //
  1640. // UIViewController *vc= [RAUtils getViewController:self];
  1641. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
  1642. //
  1643. // };
  1644. // cvc.onReset = ^(){
  1645. // [main_vc checklogin:true];
  1646. // };
  1647. //
  1648. // [vc.navigationController pushViewController:cvc animated:true];
  1649. // }
  1650. // else
  1651. // {
  1652. // [self neworder];
  1653. // }
  1654. //
  1655. //
  1656. // }
  1657. //}
  1658. - (void)valueChanged:(UIStepper *)sender {
  1659. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  1660. [celldelegate stepClicked:(int)sender.value];
  1661. // -(void) stepClicked:(int) value;
  1662. // 检查缺货
  1663. // NSString *cartQtyString = nil;
  1664. // if (self.cqyt_label.text) {
  1665. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  1666. // }
  1667. //
  1668. // int availability = [self.count_Label.text intValue];
  1669. // int buyQTY = [self.quantity_text.text intValue];
  1670. // int cartQTY = [cartQtyString intValue];
  1671. //
  1672. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  1673. }
  1674. #pragma mark -
  1675. #pragma mark Actions
  1676. -(void)ClearPhotos
  1677. {
  1678. NSMutableArray *photosMutable = [self.photos mutableCopy];
  1679. [photosMutable removeAllObjects];
  1680. self.photos = photosMutable;
  1681. [self.photoStack reloadData];
  1682. }
  1683. - (void)AddPhoto :(UIImage*)photo {
  1684. NSMutableArray *photosMutable = [self.photos mutableCopy];
  1685. [photosMutable addObject:photo];
  1686. self.photos = photosMutable;
  1687. [self.photoStack reloadData];
  1688. self.pageControl.numberOfPages = [self.photos count];
  1689. if(self.photos.count<2-1)//1 for qrcode;
  1690. self.photoStack.showBorder=false;
  1691. else
  1692. self.photoStack.showBorder=true;
  1693. }
  1694. #pragma mark -
  1695. #pragma mark Setup
  1696. -(void)setup {
  1697. // int availability = [self.count_Label.text intValue];
  1698. self.stepper.minimumValue= self.step;
  1699. self.stepper.maximumValue = INTMAX_MAX;
  1700. self.stepper.stepValue= self.step;
  1701. self.stepper.value= self.quantity;
  1702. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  1703. if(true)//(self.photos==nil)
  1704. {
  1705. self.photos = [NSArray array];
  1706. }
  1707. if(true)//(self.photoStack==nil)
  1708. {
  1709. // if(self.photoStack!=nil)
  1710. // [self.photoStack removeFromSuperview];
  1711. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  1712. // self.photoStack.backgroundColor =[UIColor redColor];
  1713. // self.photoStack.center = CGPointMake(self.center.x, 220);
  1714. self.photoStack.dataSource = self;
  1715. self.photoStack.delegate = self;
  1716. // [self addSubview:self.photoStack];
  1717. self.pageControl.numberOfPages = [self.photos count];
  1718. }
  1719. }
  1720. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  1721. if (self.notifyMeBlock) {
  1722. self.notifyMeBlock();
  1723. }
  1724. }
  1725. #pragma mark - TextField Delegate
  1726. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  1727. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  1728. // NSString *cartQtyString = nil;
  1729. // if (self.cqyt_label.text) {
  1730. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  1731. // }
  1732. // int availability = [self.count_Label.text intValue];
  1733. int buyQTY = [newString intValue];
  1734. // int cartQTY = [cartQtyString intValue];
  1735. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  1736. self.stepper.value = buyQTY;
  1737. return YES;
  1738. }
  1739. #pragma mark - Private
  1740. /**检查是否缺货*/
  1741. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  1742. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  1743. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1744. if (!appDelegate.bLogin || buyQty < 1) {
  1745. return;
  1746. }
  1747. #ifdef OFFLINE_MODE
  1748. if (appDelegate.offline_mode) {
  1749. return;
  1750. }
  1751. #endif
  1752. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  1753. if (!appDelegate.order_code) { // 未打开订单状态
  1754. if ((buyQty + cartQty) > availability) {
  1755. self.btnaddCart.enabled = NO;
  1756. self.btnNotifyMe.enabled = YES;
  1757. } else {
  1758. self.btnaddCart.enabled = YES;
  1759. self.btnNotifyMe.enabled = NO;
  1760. }
  1761. } else {
  1762. // 打开订单状态
  1763. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1764. // Shop Order
  1765. self.btnaddCart.enabled = YES;
  1766. // 默认未缺货
  1767. self.btnNotifyMe.enabled = NO;
  1768. if ((buyQty + cartQty) > availability) { // 缺货
  1769. self.btnNotifyMe.enabled = YES;
  1770. }
  1771. } else {
  1772. // Purchase Order
  1773. if ((buyQty + cartQty) > availability) { // 缺货
  1774. self.btnaddCart.enabled = NO;
  1775. self.btnNotifyMe.enabled = YES;
  1776. } else { // 未缺货
  1777. self.btnNotifyMe.enabled = NO;
  1778. self.btnaddCart.enabled = YES;
  1779. }
  1780. }
  1781. }
  1782. } else { // empoyee
  1783. if ((buyQty + cartQty) > availability) { // 缺货
  1784. self.btnaddCart.enabled = NO;
  1785. self.btnNotifyMe.enabled = YES;
  1786. } else { // 未缺货
  1787. self.btnNotifyMe.enabled = NO;
  1788. self.btnaddCart.enabled = YES;
  1789. }
  1790. }
  1791. //#endif
  1792. }
  1793. - (IBAction)introduceBtnClick:(UIButton *)sender {
  1794. if (self.introduceBlock) {
  1795. self.introduceBlock(sender);
  1796. }
  1797. }
  1798. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  1799. if (self.descriptionBlock) {
  1800. self.descriptionBlock(sender);
  1801. }
  1802. }
  1803. - (IBAction)OnClosePlayer:(id)sender {
  1804. [self.ytplayerView stopVideo];
  1805. self.ytplayerView.hidden=true;
  1806. }
  1807. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  1808. UIApplication * app = [UIApplication sharedApplication];
  1809. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1810. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1811. if(appDelegate.bLogin==false) {
  1812. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  1813. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1814. loginvc.returnValue = ^(bool blogin){
  1815. if(blogin) {
  1816. [vc reload];
  1817. [main_vc checklogin:true];
  1818. }
  1819. };
  1820. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1821. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1822. [vc presentViewController:navi animated:YES completion:^{
  1823. }];
  1824. }
  1825. }
  1826. @end