PriceSettingViewController.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // PriceSetting.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 2016/10/11.
  6. // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PriceSettingViewController.h"
  9. #import "const.h"
  10. #import "EnumSelectViewController.h"
  11. #import "CategoryPriceViewController.h"
  12. #import "RANetwork.h"
  13. #import "Singleton.h"
  14. #import <objc/runtime.h>
  15. #import "MainViewController.h"
  16. #import "NotificationNameCenter.h"
  17. @interface PriceSettingViewController ()
  18. @property (strong, nonatomic) IBOutlet UIButton *priceTypeButton;
  19. @property (strong, nonatomic) IBOutlet UIButton *showButton;
  20. @property (strong, nonatomic) IBOutlet UIButton *setPriceButton;
  21. @end
  22. @implementation PriceSettingViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.priceType = [Singleton sharedInstance].npd_shop_price_type;
  27. [self configAppearance];
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. // Dispose of any resources that can be recreated.
  32. }
  33. #pragma mark - Customer Inint
  34. - (void)configAppearance {
  35. self.setPriceButton.hidden = ![Singleton sharedInstance].permissions_price_setting;
  36. UIApplication * app = [UIApplication sharedApplication];
  37. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  38. self.showPrice = !appDelegate.price_hidden;
  39. [self changePriceType:self.priceType];
  40. self.showButton.selected = !self.showPrice;
  41. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  42. style:UIBarButtonItemStylePlain
  43. target:self
  44. action:@selector(onCloseClick:)];
  45. self.navigationItem.rightBarButtonItem = closeButton;
  46. }
  47. - (void)changePriceType:(NSInteger)type {
  48. NSString *title = [Singleton sharedInstance].deliveryString;
  49. switch (type) {
  50. case 0: {
  51. title = [Singleton sharedInstance].deliveryString;
  52. }
  53. break;
  54. case 1: {
  55. title = flat_price;
  56. }
  57. break;
  58. case 2: {
  59. title = given_price;
  60. }
  61. break;
  62. default:
  63. break;
  64. }
  65. self.priceType = type;
  66. [self.priceTypeButton setTitle:title forState:UIControlStateNormal];
  67. }
  68. #pragma mark - action
  69. - (void)onCloseClick:(id)sender {
  70. [self dismissViewControllerAnimated:YES completion:^{
  71. }];
  72. }
  73. - (IBAction)showOrHidePriceButtonClick:(UIButton *)sender {
  74. sender.selected = !sender.selected;
  75. self.showPrice = !sender.selected;
  76. UIApplication * app = [UIApplication sharedApplication];
  77. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  78. [appDelegate set_priceHidden:sender.selected];
  79. // objc_msgSend(appDelegate.main_vc,@selector(initMenuItems));// initMenuItems 不是公开的方法
  80. [(MainViewController *)appDelegate.main_vc initMenuItems];
  81. }
  82. - (IBAction)calculatePriceButtonClick:(UIButton *)sender {
  83. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Load Data" completion:^{
  84. [RANetwork request_npd_shop_givenprice:^(NSMutableDictionary *result) {
  85. NSDictionary *dic = result;
  86. // [waitalert dismissWithClickedButtonIndex:0 animated:YES];
  87. [waitalert dismissViewControllerAnimated:YES completion:^{
  88. if ([[dic objectForKey:@"result"] integerValue] == 2) {
  89. CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
  90. categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
  91. [self.navigationController pushViewController:categoryPriceVC animated:YES];
  92. } else {
  93. NSString *msg = [dic objectForKey:@"msg"];
  94. if (!msg) {
  95. msg = @"Some Error Occured,Please Try Again";
  96. }
  97. [RAUtils message_alert:msg title:@"Set Store Price" controller:self];
  98. };
  99. }];
  100. }];
  101. }];
  102. // NSDictionary *dic = [RANetwork get_npd_shop_givenPrice];
  103. //
  104. //// [waitalert dismissWithClickedButtonIndex:0 animated:YES];
  105. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  106. //
  107. //
  108. // if ([[dic objectForKey:@"result"] integerValue] == 2) {
  109. //
  110. // CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
  111. //
  112. // categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
  113. //
  114. // [self.navigationController pushViewController:categoryPriceVC animated:YES];
  115. // } else {
  116. //
  117. // NSString *msg = [dic objectForKey:@"msg"];
  118. // if (!msg) {
  119. // msg = @"Some Error Occured,Please Try Again";
  120. // }
  121. // [RAUtils message_alert:msg title:@"Set Store Price" controller:self];
  122. //
  123. // }
  124. }
  125. - (NSString *)checkPriceType:(NSInteger)priceType {
  126. return self.priceType == priceType ? @"1" : @"0";
  127. }
  128. - (NSInteger)checkedCadedate:(NSDictionary *)cadedate {
  129. int priceType = 0;
  130. int count = [[cadedate objectForKey:@"count"] intValue];
  131. for (int i = 0; i < count; i++) {
  132. NSDictionary *dic = [cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  133. int check = [[dic objectForKey:@"check"] intValue];
  134. if (check) {
  135. priceType = [[dic objectForKey:@"value_code"] intValue];
  136. break;
  137. }
  138. }
  139. return priceType;
  140. }
  141. - (IBAction)priceTypeButtonClick:(UIButton *)sender {
  142. EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  143. enumvc.max_select = 1;
  144. // enumvc.cadedate = @{
  145. // @"count" : @"3",
  146. // @"val_0" : @{@"value" : [Singleton sharedInstance].deliveryString,@"value_code" : @"0",@"check" : [self checkPriceType:0]},
  147. // @"val_1" : @{@"value" : flat_price,@"value_code" : @"1",@"check" : [self checkPriceType:1]},
  148. // @"val_2" : @{@"value" : given_price,@"value_code" : @"2",@"check" : [self checkPriceType:2]}
  149. // }.mutableCopy;
  150. enumvc.cadedate = @{
  151. @"count" : @"2",
  152. @"val_0" : @{@"value" : flat_price,@"value_code" : @"1",@"check" : [self checkPriceType:1]},
  153. @"val_1" : @{@"value" : given_price,@"value_code" : @"2",@"check" : [self checkPriceType:2]}
  154. }.mutableCopy;
  155. enumvc.title = @"";
  156. enumvc.single_select =true;
  157. __weak typeof(self) weakSelf = self;
  158. enumvc.returnValue = ^(NSMutableDictionary* value){
  159. if (weakSelf) {
  160. __strong typeof(weakSelf) strongSelf = weakSelf;
  161. [strongSelf changePriceType:[strongSelf checkedCadedate:value]];
  162. }
  163. };
  164. [self.navigationController pushViewController:enumvc animated:true];
  165. }
  166. - (IBAction)saveButtonClick:(UIButton *)sender {
  167. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Set PriceType" completion:^{
  168. [RANetwork request_update_npd_shop_price_type:self.priceType completionHandler:^(NSMutableDictionary *result) {
  169. NSDictionary *dic=result;
  170. [waitalert dismissViewControllerAnimated:YES completion:^{
  171. // 成功
  172. if ([[dic objectForKey:@"result"] integerValue] == 2) {
  173. [Singleton sharedInstance].npd_shop_price_type = self.priceType;
  174. #ifdef RA_NOTIFICATION
  175. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  176. #else
  177. // 刷新 Cart、Order List
  178. [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
  179. #endif
  180. } else { // 失败
  181. DebugLog(@"set price type failure");
  182. }
  183. [self dismissViewControllerAnimated:YES completion:nil];;
  184. }];
  185. }];
  186. }];
  187. // NSDictionary *dic = [RANetwork set_npd_shop_price_type:self.priceType];
  188. //
  189. //// [waitalert dismissWithClickedButtonIndex:0 animated:YES];
  190. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  191. //
  192. // // 成功
  193. // if ([[dic objectForKey:@"result"] integerValue] == 2) {
  194. //
  195. // [Singleton sharedInstance].npd_shop_price_type = self.priceType;
  196. //
  197. //
  198. //
  199. //#ifdef RA_NOTIFICATION
  200. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  201. //#else
  202. // // 刷新 Cart、Order List
  203. // [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
  204. //#endif
  205. //
  206. // } else { // 失败
  207. //
  208. // DebugLog(@"set price type failure");
  209. // }
  210. //
  211. // [self dismissViewControllerAnimated:YES completion:nil];
  212. }
  213. @end