HomerModelDetailHeaderCell.m 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. //
  2. // HomerModelDetailHeaderCell.m
  3. // iSales-HOMER
  4. //
  5. // Created by Jack on 2017/10/25.
  6. // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "HomerModelDetailHeaderCell.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. @implementation HomerModelDetailHeaderCell
  22. @synthesize celldelegate;
  23. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  24. {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. // Initialization code
  28. }
  29. return self;
  30. }
  31. - (void)awakeFromNib
  32. {
  33. [super awakeFromNib];
  34. self.quantity_text.delegate = self;
  35. // MDHTMLLabelVerticalAlignmentCenter = 0,
  36. // MDHTMLLabelVerticalAlignmentTop = 1,
  37. self.informationLabel.numberOfLines = 0;
  38. // self.informationLabel.verticalAlignment=MDHTMLLabelVerticalAlignmentTop;
  39. // self.informationLabel.backgroundColor = [UIColor yellowColor];
  40. // self.selector_Button.layer.borderWidth = 0.5;
  41. // self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  42. // self.selector_Button.layer.cornerRadius = 0;
  43. [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  44. [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
  45. [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
  46. [self addObserver:self
  47. forKeyPath:@"stack_contents"
  48. options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  49. context:@"content changed"];
  50. self.inforframe=self.informationLabel.frame.size;
  51. // [self generate_information];
  52. }
  53. -(void) dealloc
  54. {
  55. [self removeObserver:self forKeyPath:@"stack_contents"];
  56. }
  57. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  58. {
  59. if([keyPath isEqualToString:@"stack_contents"])
  60. {
  61. [self.playerView stopVideo];
  62. self.playerView.hidden=true;
  63. }
  64. }
  65. - (void)layoutSubviews
  66. {
  67. [super layoutSubviews];
  68. // [self generate_information];
  69. }
  70. -(void) generate_information
  71. {
  72. NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
  73. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Availability:</b> %@</font>",self.count_Label.text]];
  74. if(self.incomingcount_Label.text.length>0)
  75. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' >&emsp;Incoming stock: %@</font>",self.incomingcount_Label.text]];
  76. if(self.etaval_label.text.length>0)
  77. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' >&emsp;Arrival Date: %@</font>",self.etaval_label.text]];
  78. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Availability in 7-10 days:</b> %@</font>",self.hmlg_stock_count_lb.text]];
  79. if(self.cqyt_label.text.length>0)
  80. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;color:red';font-family:Helvetica><b>%@</b></font>",self.cqyt_label.text]];
  81. NSString * information_str = [RAConvertor arr2string:arr_addr separator:@"<br>" trim:true];
  82. // UIFont *font=[UIFont systemFontOfSize:14];
  83. //// label.font=font;
  84. NSDictionary *optoins=@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
  85. NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[information_str dataUsingEncoding:NSUnicodeStringEncoding] options:optoins documentAttributes:nil error:nil];
  86. // self.informationLabel.numberOfLines
  87. // self.informationLabel.lineBreakMode
  88. //
  89. // self.informationLabel.adjustsFontSizeToFitWidth = YES;
  90. // self.informationLabel.minimumFontSize = 0.5;
  91. self.informationLabel.attributedText=attrStr;
  92. // self.informationLabel.text = @"文字在语言学中指书面语的视觉形式,古代把独体字叫做“文”,把合体字叫做“字”,如今联合起来叫做“文字”,文字的基本个体叫做“字”。在日常生活中,";
  93. // [self.informationLabel sizeToFit];
  94. // CGSize inforsize=[self.informationLabel sizeThatFits:self.informationLabel.frame.size];
  95. // CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrStr);
  96. // //计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
  97. // CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.informationLabel.frame.size.width, MAXFLOAT), NULL);
  98. //
  99. //
  100. //
  101. // CFRelease(framesetter);
  102. // CGSize lblSize = [self.informationLabel.text boundingRectWithSize:self.informationLabel.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
  103. // self.informationLabel.frame = CGRectMake(self.informationLabel.frame.origin.x, self.informationLabel.frame.origin.y, tmpSize.width, tmpSize.height);
  104. // [self.informationLabel sizeToFit];
  105. UILabel* textLabel = [UILabel new];
  106. textLabel.attributedText = attrStr;
  107. textLabel.numberOfLines = 0;
  108. textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  109. // [textLabel sizeToFit];
  110. CGSize newsize = [textLabel sizeThatFits:self.inforframe];
  111. float new_height=newsize.height<self.inforframe.height?newsize.height:self.inforframe.height;
  112. // self.informationLabel.frame = CGRectMake(self.informationLabel_arch.frame.origin.x, CGRectGetMaxY(self.informationLabel.frame)-newsize.height, newsize.width, newsize.height);
  113. self.informationLabel.frame = CGRectMake(self.informationLabel.frame.origin.x, self.informationLabel.frame.origin.y, self.inforframe.width, new_height);
  114. }
  115. - (IBAction)add_toPortfolio:(id)sender {
  116. UIApplication * app = [UIApplication sharedApplication];
  117. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  118. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  119. [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil];
  120. return;
  121. }
  122. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  123. if(appDelegate.bLogin==false)
  124. {
  125. UIViewController *vc= [RAUtils getViewController:self];
  126. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  127. loginvc.returnValue = ^(bool blogin){
  128. if(blogin)
  129. {
  130. if(self.set_update_data)
  131. self.set_update_data(true);
  132. [main_vc checklogin:true];
  133. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  134. NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  135. dispatch_async(dispatch_get_main_queue(), ^{
  136. if([[return_json valueForKey:@"result"] intValue]==2)
  137. {
  138. #ifdef RA_NOTIFICATION
  139. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  140. #else
  141. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  142. #endif
  143. if(self.WatchlistBlock!=nil)
  144. {
  145. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  146. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  147. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  148. iv.image = img;
  149. self.PortfolioBlock(iv);
  150. }
  151. }
  152. else
  153. {
  154. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  155. }
  156. });
  157. });
  158. }
  159. };
  160. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  161. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  162. [vc presentViewController:navi animated:YES completion:^{
  163. }];
  164. }
  165. else
  166. {
  167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  168. NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  169. dispatch_async(dispatch_get_main_queue(), ^{
  170. if([[return_json valueForKey:@"result"] intValue]==2)
  171. {
  172. #ifdef RA_NOTIFICATION
  173. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  174. #else
  175. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  176. #endif
  177. if(self.WatchlistBlock!=nil)
  178. {
  179. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  180. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  181. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  182. iv.image = img;
  183. self.PortfolioBlock(iv);
  184. }
  185. }
  186. else
  187. {
  188. UIViewController *vc= [RAUtils getViewController:self];
  189. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  190. }
  191. });
  192. });
  193. }
  194. }
  195. - (IBAction)add_toWatchList:(id)sender {
  196. UIApplication * app = [UIApplication sharedApplication];
  197. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  198. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  199. if(appDelegate.bLogin==false)
  200. {
  201. UIViewController *vc= [RAUtils getViewController:self];
  202. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  203. loginvc.returnValue = ^(bool blogin){
  204. if(blogin)
  205. {
  206. if(self.set_update_data)
  207. self.set_update_data(true);
  208. [main_vc checklogin:true];
  209. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  210. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  211. dispatch_async(dispatch_get_main_queue(), ^{
  212. if([[return_json valueForKey:@"result"] intValue]==2)
  213. {
  214. #ifdef RA_NOTIFICATION
  215. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  216. #else
  217. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  218. #endif
  219. if(self.WatchlistBlock!=nil)
  220. {
  221. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  222. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  223. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  224. iv.image = img;
  225. self.WatchlistBlock(iv);
  226. }
  227. }
  228. else
  229. {
  230. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  231. }
  232. });
  233. });
  234. }
  235. };
  236. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  237. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  238. [vc presentViewController:navi animated:YES completion:^{
  239. }];
  240. }
  241. else
  242. {
  243. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  244. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  245. dispatch_async(dispatch_get_main_queue(), ^{
  246. if([[return_json valueForKey:@"result"] intValue]==2)
  247. {
  248. #ifdef RA_NOTIFICATION
  249. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  250. #else
  251. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  252. #endif
  253. if(self.WatchlistBlock!=nil)
  254. {
  255. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  256. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  257. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  258. iv.image = img;
  259. self.WatchlistBlock(iv);
  260. }
  261. }
  262. else
  263. {
  264. UIViewController *vc= [RAUtils getViewController:self];
  265. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  266. }
  267. });
  268. });
  269. }
  270. }
  271. - (IBAction)add_toCart:(id)sender {
  272. UIViewController *vc= [RAUtils getViewController:self];
  273. [CartUtils add_to_cart:vc selectorholder:self selector:@selector(addtocart)];
  274. return;
  275. }
  276. -(void) addtocart
  277. {
  278. int count=[self.quantity_text.text intValue];
  279. #ifdef MPACK
  280. if (count % self.step != 0) {
  281. UIViewController *vc= [RAUtils getViewController:self];
  282. [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Add to cart" controller:vc];
  283. return;
  284. }
  285. #endif
  286. int c=[self.count_Label.text intValue];
  287. DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  288. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  289. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  290. if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
  291. {
  292. NSString *msg = nil;
  293. BOOL continueAdd = YES;
  294. // #if defined(BUILD_NPD) || defined(BUILD_USAI)
  295. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  296. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  297. if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  298. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
  299. continueAdd = NO;
  300. } else { // Shop Order购买数量大于库存需要确认
  301. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  302. continueAdd = YES;
  303. }
  304. }
  305. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  306. msg = @"Item is OUT OF STOCK and not available to order.";
  307. continueAdd = NO;
  308. }
  309. // #endif
  310. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  311. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  312. if (continueAdd) {
  313. [self addtocart:count];
  314. }
  315. }];
  316. [alertControl addAction:alertthree];
  317. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  318. }];
  319. if (continueAdd) {
  320. [alertControl addAction:alertcancel];
  321. }
  322. UIViewController *vc= [RAUtils getViewController:self];
  323. [vc presentViewController:alertControl animated:YES completion:nil];
  324. }
  325. else
  326. {
  327. [self addtocart:count];
  328. }
  329. }
  330. -(void)Hide_selector:(bool) bhide
  331. {
  332. // self.selector_Button.hidden=bhide;
  333. // self.selector_dorpdown.hidden=bhide;
  334. // self.selector_imageView.hidden=bhide;
  335. //
  336. }
  337. -(void) addtocart:(int) count
  338. {
  339. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  340. if(self.cqty>0)
  341. {
  342. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  343. //block代码块取代了delegate
  344. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  345. int c=self.cqty+count;
  346. int m=c%self.step;
  347. if(m!=0&&appDelegate.alert_sold_in_quantities)
  348. {
  349. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  350. //block代码块取代了delegate
  351. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  352. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  353. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  354. dispatch_async(dispatch_get_main_queue(), ^{
  355. if([[return_json valueForKey:@"result"] intValue]==2)
  356. {
  357. // NSString* order_code = [return_json valueForKey:@"order_code"];
  358. #ifdef RA_NOTIFICATION
  359. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  360. #else
  361. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  362. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  363. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  364. #endif
  365. if(self.shopCartBlock!=nil)
  366. {
  367. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  368. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  369. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  370. iv.image = img;
  371. // [self.contentView addSubview:iv];
  372. self.shopCartBlock(iv);
  373. self.cqty +=count;
  374. if(self.set_cqty)
  375. self.set_cqty(self.cqty);
  376. }
  377. }
  378. else
  379. {
  380. UIViewController *vc= [RAUtils getViewController:self];
  381. NSString *msg = [return_json valueForKey:@"err_msg"];
  382. NSString *title = @"Add To Cart";
  383. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  384. title = @"Add To Cart: Out of Stock";
  385. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  386. self.btnNotifyMe.enabled = YES;
  387. self.btnaddCart.enabled = NO;
  388. }
  389. [RAUtils message_alert:msg title:title controller:vc] ;
  390. }
  391. });
  392. });
  393. }];
  394. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  395. DebugLog(@"No");
  396. }];
  397. [alertControl addAction:actionOne];
  398. [alertControl addAction:alertthree];
  399. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  400. UIViewController *vc= [RAUtils getViewController:self];
  401. [vc presentViewController:alertControl animated:YES completion:nil];
  402. }
  403. else
  404. {
  405. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  406. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  407. dispatch_async(dispatch_get_main_queue(), ^{
  408. if([[return_json valueForKey:@"result"] intValue]==2)
  409. {
  410. // NSString* order_code = [return_json valueForKey:@"order_code"];
  411. #ifdef RA_NOTIFICATION
  412. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  413. #else
  414. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  415. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  416. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  417. #endif
  418. if(self.shopCartBlock!=nil)
  419. {
  420. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  421. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  422. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  423. iv.image = img;
  424. // [self.contentView addSubview:iv];
  425. self.shopCartBlock(iv);
  426. self.cqty +=count;
  427. if(self.set_cqty)
  428. self.set_cqty(self.cqty);
  429. }
  430. }
  431. else
  432. {
  433. UIViewController *vc= [RAUtils getViewController:self];
  434. NSString *msg = [return_json valueForKey:@"err_msg"];
  435. NSString *title = @"Add To Cart";
  436. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  437. title = @"Add To Cart: Out of Stock";
  438. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  439. self.btnNotifyMe.enabled = YES;
  440. self.btnaddCart.enabled = NO;
  441. }
  442. [RAUtils message_alert:msg title:title controller:vc] ;
  443. }
  444. });
  445. });
  446. }
  447. }];
  448. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  449. DebugLog(@"No");
  450. }];
  451. [alertControl addAction:actionOne];
  452. [alertControl addAction:alertthree];
  453. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  454. UIViewController *vc= [RAUtils getViewController:self];
  455. [vc presentViewController:alertControl animated:YES completion:nil];
  456. }
  457. else
  458. {
  459. int c=self.cqty+count;
  460. int m=c%self.step;
  461. if(m!=0&&appDelegate.alert_sold_in_quantities)
  462. {
  463. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  464. //block代码块取代了delegate
  465. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  466. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  467. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  468. dispatch_async(dispatch_get_main_queue(), ^{
  469. if([[return_json valueForKey:@"result"] intValue]==2)
  470. {
  471. // NSString* order_code = [return_json valueForKey:@"order_code"];
  472. #ifdef RA_NOTIFICATION
  473. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  474. #else
  475. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  476. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  477. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  478. #endif
  479. if(self.shopCartBlock!=nil)
  480. {
  481. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  482. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  483. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  484. iv.image = img;
  485. // [self.contentView addSubview:iv];
  486. self.shopCartBlock(iv);
  487. self.cqty +=count;
  488. if(self.set_cqty)
  489. self.set_cqty(self.cqty);
  490. }
  491. }
  492. else
  493. {
  494. UIViewController *vc= [RAUtils getViewController:self];
  495. NSString *msg = [return_json valueForKey:@"err_msg"];
  496. NSString *title = @"Add To Cart";
  497. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  498. title = @"Add To Cart: Out of Stock";
  499. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  500. self.btnNotifyMe.enabled = YES;
  501. self.btnaddCart.enabled = NO;
  502. }
  503. [RAUtils message_alert:msg title:title controller:vc] ;
  504. }
  505. });
  506. });
  507. }];
  508. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  509. DebugLog(@"No");
  510. }];
  511. [alertControl addAction:actionOne];
  512. [alertControl addAction:alertthree];
  513. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  514. UIViewController *vc= [RAUtils getViewController:self];
  515. [vc presentViewController:alertControl animated:YES completion:nil];
  516. }
  517. else
  518. {
  519. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  520. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  521. dispatch_async(dispatch_get_main_queue(), ^{
  522. if([[return_json valueForKey:@"result"] intValue]==2)
  523. {
  524. // NSString* order_code = [return_json valueForKey:@"order_code"];
  525. #ifdef RA_NOTIFICATION
  526. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  527. #else
  528. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  529. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  530. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  531. #endif
  532. if(self.shopCartBlock!=nil)
  533. {
  534. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  535. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  536. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  537. iv.image = img;
  538. // [self.contentView addSubview:iv];
  539. self.shopCartBlock(iv);
  540. self.cqty +=count;
  541. if(self.set_cqty)
  542. self.set_cqty(self.cqty);
  543. }
  544. }
  545. else
  546. {
  547. UIViewController *vc= [RAUtils getViewController:self];
  548. NSString *msg = [return_json valueForKey:@"err_msg"];
  549. NSString *title = @"Add To Cart";
  550. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  551. title = @"Add To Cart: Out of Stock";
  552. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  553. self.btnNotifyMe.enabled = YES;
  554. self.btnaddCart.enabled = NO;
  555. }
  556. [RAUtils message_alert:msg title:title controller:vc] ;
  557. }
  558. });
  559. });
  560. }
  561. }
  562. }
  563. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  564. {
  565. [super setSelected:selected animated:animated];
  566. // Configure the view for the selected state
  567. }
  568. - (IBAction)selectorOnClick:(id)sender {
  569. DebugLog(@"select click");
  570. [celldelegate SelectorClicked:(UIButton*) sender];
  571. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  572. }
  573. #pragma mark -
  574. #pragma mark Deck DataSource Protocol Methods
  575. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  576. return [self.photos count];
  577. }
  578. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  579. if(self.photos.count==0)
  580. return nil;
  581. return [self.photos objectAtIndex:index];
  582. }
  583. #pragma mark -
  584. #pragma mark Deck Delegate Protocol Methods
  585. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  586. // User started moving a photo
  587. }
  588. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  589. // User flicked the photo away, revealing the next one in the stack
  590. }
  591. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  592. self.pageControl.currentPage = index;
  593. }
  594. - (UIView *)createVideoView:(NSString*) videoID
  595. {
  596. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  597. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  598. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  599. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  600. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  601. titleLabel.text=@"a separated player will show here:";
  602. titleLabel.numberOfLines = 0;
  603. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  604. // titleLabel.textAlignment = NSTextAlignmentRight;
  605. titleLabel.textAlignment = NSTextAlignmentCenter;
  606. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  607. CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  608. //[titleLabel sizeToFit];
  609. // titleLabel.center.x = demoView.center.x;
  610. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  611. [demoView addSubview:titleLabel];
  612. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  613. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  614. lineLabel.text=videoID;
  615. lineLabel.numberOfLines = 0;
  616. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  617. CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  618. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  619. //[lineLabel sizeToFit];
  620. [demoView addSubview:lineLabel];
  621. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  622. return demoView;
  623. }
  624. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  625. DebugLog(@"selected %lu", (unsigned long)index);
  626. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  627. if([item[@"type"] isEqualToString:@"video"])
  628. {
  629. NSString* video_code=item[@"code"];
  630. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  631. NSString* video_id=[self.playerView Embed2VID:video_code];
  632. NSDictionary *playerVars = @{
  633. @"playsinline" : @1,
  634. @"autoplay" : @(1),
  635. @"rel":@0,
  636. @"showinfo": @0,
  637. @"modestbranding":@0,
  638. @"enablejsapi":@1
  639. };
  640. [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  641. for(UIView *v in self.playerView.subviews)
  642. {
  643. if([v isKindOfClass:[UIButton class] ])
  644. [self.playerView bringSubviewToFront:v];
  645. }
  646. self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
  647. self.playerView.hidden=false;
  648. return;
  649. } else {
  650. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  651. return;
  652. }
  653. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  654. preVC.content = self.stack_contents;
  655. // preVC.currentIndex = index;
  656. [preVC setOffset:index];
  657. UIViewController *superVC= [RAUtils getViewController:self];
  658. [superVC.navigationController pushViewController:preVC animated:true];
  659. return;
  660. }
  661. // }
  662. // 调用展示窗口
  663. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  664. UIViewController *vc= [RAUtils getViewController:self];
  665. [vc.navigationController pushViewController:imgShow animated:true];
  666. }
  667. -(void) neworder
  668. {
  669. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  670. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  671. NSDictionary* return_json = [RANetwork new_Order];
  672. dispatch_async(dispatch_get_main_queue(), ^{
  673. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  674. if([[return_json valueForKey:@"result"] intValue]==2)
  675. {
  676. int result=[[return_json valueForKey:@"result"] intValue];
  677. if(result==2)
  678. {
  679. //successed.
  680. NSString* order_code = [return_json valueForKey:@"orderCode"];
  681. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  682. appDelegate.order_code = order_code;
  683. int count=[self.quantity_text.text intValue];
  684. [self addtocart:count];
  685. }
  686. }
  687. else
  688. {
  689. UIViewController *vc= [RAUtils getViewController:self];
  690. NSString *msg = [return_json valueForKey:@"err_msg"];
  691. NSString *title = @"Add To Cart";
  692. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  693. title = @"Add To Cart: Out of Stock";
  694. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  695. self.btnNotifyMe.enabled = YES;
  696. self.btnaddCart.enabled = NO;
  697. }
  698. [RAUtils message_alert:msg title:title controller:vc] ;
  699. }
  700. });
  701. });
  702. }
  703. #pragma mark - UIAlertViewDelegate
  704. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  705. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  706. {
  707. UIApplication * app = [UIApplication sharedApplication];
  708. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  709. if(alertView.tag==1234)//库存小于0
  710. {
  711. // availability warring;
  712. int count=[self.quantity_text.text intValue];
  713. if(buttonIndex!=alertView.cancelButtonIndex)
  714. {
  715. if(appDelegate.order_code==nil)
  716. {
  717. [self neworder];
  718. }
  719. else
  720. {
  721. [self addtocart:count];
  722. }
  723. }
  724. return;
  725. }
  726. // int count=[self.quantity_text.text intValue];
  727. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  728. if(buttonIndex==alertView.cancelButtonIndex)
  729. {
  730. }
  731. else if(buttonIndex==1)
  732. {
  733. //open exist
  734. UIViewController *vc= [RAUtils getViewController:self];
  735. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  736. ovc.showNavibar = true;
  737. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  738. if(appDelegate.order_code==nil)
  739. {
  740. [self neworder];
  741. }
  742. else
  743. {
  744. if(self.set_update_data)
  745. self.set_update_data(true);
  746. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  747. for(int i=0;i<model_count;i++)
  748. {
  749. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  750. NSString* product_id = [item valueForKey:@"product_id"];
  751. if([product_id isEqualToString:self.product_id])
  752. {
  753. self.cqty = [[item valueForKey:@"QTY"]intValue];
  754. if(self.set_cqty)
  755. self.set_cqty(self.cqty);
  756. break;
  757. }
  758. }
  759. int count=[self.quantity_text.text intValue];
  760. [self addtocart:count];
  761. [main_vc checklogin:true];
  762. }
  763. };
  764. ovc.init_style = OL_OPEN;
  765. ovc.onCancel = ^(){
  766. [main_vc checklogin:true];
  767. };
  768. [vc.navigationController pushViewController:ovc animated:true];
  769. }
  770. else
  771. {
  772. //create new;
  773. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  774. {
  775. UIViewController *vc= [RAUtils getViewController:self];
  776. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  777. cvc.showNavibar = true;
  778. cvc.contact_type = @"Sales_Order_Customer";
  779. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  780. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  781. appDelegate.customerInfo = value;
  782. if(appDelegate.order_code==nil)
  783. [self neworder];
  784. [main_vc checklogin:true];
  785. };
  786. cvc.onCancel = ^(){
  787. UIViewController *vc= [RAUtils getViewController:self];
  788. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
  789. };
  790. cvc.onReset = ^(){
  791. [main_vc checklogin:true];
  792. };
  793. [vc.navigationController pushViewController:cvc animated:true];
  794. }
  795. else
  796. {
  797. [self neworder];
  798. }
  799. }
  800. }
  801. - (void)valueChanged:(UIStepper *)sender {
  802. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  803. [celldelegate stepClicked:(int)sender.value];
  804. }
  805. #pragma mark -
  806. #pragma mark Actions
  807. -(void)ClearPhotos
  808. {
  809. NSMutableArray *photosMutable = [self.photos mutableCopy];
  810. [photosMutable removeAllObjects];
  811. self.photos = photosMutable;
  812. [self.photoStack reloadData];
  813. }
  814. - (void)AddPhoto :(UIImage*)photo {
  815. NSMutableArray *photosMutable = [self.photos mutableCopy];
  816. [photosMutable addObject:photo];
  817. self.photos = photosMutable;
  818. [self.photoStack reloadData];
  819. self.pageControl.numberOfPages = [self.photos count];
  820. if(self.photos.count<2-1)//1 for qrcode;
  821. self.photoStack.showBorder=false;
  822. else
  823. self.photoStack.showBorder=true;
  824. }
  825. #pragma mark -
  826. #pragma mark Setup
  827. -(void)setup {
  828. // int availability = [self.count_Label.text intValue];
  829. self.stepper.minimumValue= self.step;
  830. self.stepper.maximumValue = INTMAX_MAX;
  831. self.stepper.stepValue= self.step;
  832. self.stepper.value= self.quantity;
  833. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  834. if(true)//(self.photos==nil)
  835. {
  836. self.photos = [NSArray array];
  837. }
  838. if(true)//(self.photoStack==nil)
  839. {
  840. self.photoStack.dataSource = self;
  841. self.photoStack.delegate = self;
  842. // [self addSubview:self.photoStack];
  843. self.pageControl.numberOfPages = [self.photos count];
  844. }
  845. }
  846. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  847. if (self.notifyMeBlock) {
  848. self.notifyMeBlock();
  849. }
  850. }
  851. #pragma mark - TextField Delegate
  852. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  853. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  854. int buyQTY = [newString intValue];
  855. self.stepper.value = buyQTY;
  856. return YES;
  857. }
  858. #pragma mark - Private
  859. /**检查是否缺货*/
  860. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  861. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  862. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  863. if (!appDelegate.bLogin || buyQty < 1) {
  864. return;
  865. }
  866. #ifdef OFFLINE_MODE
  867. if (appDelegate.offline_mode) {
  868. return;
  869. }
  870. #endif
  871. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  872. if (!appDelegate.order_code) { // 未打开订单状态
  873. if ((buyQty + cartQty) > availability) {
  874. self.btnaddCart.enabled = NO;
  875. self.btnNotifyMe.enabled = YES;
  876. } else {
  877. self.btnaddCart.enabled = YES;
  878. self.btnNotifyMe.enabled = NO;
  879. }
  880. } else {
  881. // 打开订单状态
  882. if (![Singleton sharedInstance].currentOrderIsMerged) {
  883. // Shop Order
  884. self.btnaddCart.enabled = YES;
  885. // 默认未缺货
  886. self.btnNotifyMe.enabled = NO;
  887. if ((buyQty + cartQty) > availability) { // 缺货
  888. self.btnNotifyMe.enabled = YES;
  889. }
  890. } else {
  891. // Purchase Order
  892. if ((buyQty + cartQty) > availability) { // 缺货
  893. self.btnaddCart.enabled = NO;
  894. self.btnNotifyMe.enabled = YES;
  895. } else { // 未缺货
  896. self.btnNotifyMe.enabled = NO;
  897. self.btnaddCart.enabled = YES;
  898. }
  899. }
  900. }
  901. } else { // empoyee
  902. if ((buyQty + cartQty) > availability) { // 缺货
  903. self.btnaddCart.enabled = NO;
  904. self.btnNotifyMe.enabled = YES;
  905. } else { // 未缺货
  906. self.btnNotifyMe.enabled = NO;
  907. self.btnaddCart.enabled = YES;
  908. }
  909. }
  910. //#endif
  911. }
  912. - (IBAction)introduceBtnClick:(UIButton *)sender {
  913. if (self.introduceBlock) {
  914. self.introduceBlock(sender);
  915. }
  916. }
  917. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  918. if (self.descriptionBlock) {
  919. self.descriptionBlock(sender);
  920. }
  921. }
  922. - (IBAction)OnClosePlayer:(id)sender {
  923. [self.playerView stopVideo];
  924. self.playerView.hidden=true;
  925. }
  926. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  927. UIApplication * app = [UIApplication sharedApplication];
  928. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  929. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  930. if(appDelegate.bLogin==false) {
  931. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  932. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  933. loginvc.returnValue = ^(bool blogin){
  934. if(blogin) {
  935. [vc reload];
  936. [main_vc checklogin:true];
  937. }
  938. };
  939. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  940. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  941. [vc presentViewController:navi animated:YES completion:^{
  942. }];
  943. }
  944. }
  945. @end