| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- //
- // PriceSetting.m
- // iSales-NPD
- //
- // Created by Jack on 2016/10/11.
- // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
- //
- #import "PriceSettingViewController.h"
- #import "const.h"
- #import "EnumSelectViewController.h"
- #import "CategoryPriceViewController.h"
- #import "iSalesNetwork.h"
- #import "Singleton.h"
- #import <objc/runtime.h>
- #import "MainViewController.h"
- #import "NotificationNameCenter.h"
- @interface PriceSettingViewController ()
- @property (strong, nonatomic) IBOutlet UIButton *priceTypeButton;
- @property (strong, nonatomic) IBOutlet UIButton *showButton;
- @property (strong, nonatomic) IBOutlet UIButton *setPriceButton;
- @end
- @implementation PriceSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.priceType = [Singleton sharedInstance].npd_shop_price_type;
-
- [self configAppearance];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Customer Inint
- - (void)configAppearance {
-
- self.setPriceButton.hidden = ![Singleton sharedInstance].permissions_price_setting;
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- self.showPrice = !appDelegate.price_hidden;
-
- [self changePriceType:self.priceType];
- self.showButton.selected = !self.showPrice;
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCloseClick:)];
- self.navigationItem.rightBarButtonItem = closeButton;
-
- }
- - (void)changePriceType:(NSInteger)type {
-
- NSString *title = [Singleton sharedInstance].deliveryString;
- switch (type) {
- case 0: {
- title = [Singleton sharedInstance].deliveryString;
- }
- break;
- case 1: {
- title = flat_price;
- }
- break;
- case 2: {
- title = given_price;
- }
- break;
-
- default:
- break;
- }
-
- self.priceType = type;
- [self.priceTypeButton setTitle:title forState:UIControlStateNormal];
-
- }
- #pragma mark - action
- - (void)onCloseClick:(id)sender {
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
- }
- - (IBAction)showOrHidePriceButtonClick:(UIButton *)sender {
-
- sender.selected = !sender.selected;
- self.showPrice = !sender.selected;
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- [appDelegate set_priceHidden:sender.selected];
-
- // objc_msgSend(appDelegate.main_vc,@selector(initMenuItems));// initMenuItems 不是公开的方法
- [(MainViewController *)appDelegate.main_vc initMenuItems];
- }
- - (IBAction)calculatePriceButtonClick:(UIButton *)sender {
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Load Data"];
-
- NSDictionary *dic = [iSalesNetwork get_npd_shop_givenPrice];
- [waitalert dismissWithClickedButtonIndex:0 animated:YES];
-
- if ([[dic objectForKey:@"result"] integerValue] == 2) {
-
- CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
-
- categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
-
- [self.navigationController pushViewController:categoryPriceVC animated:YES];
- } else {
-
- NSString *msg = [dic objectForKey:@"msg"];
- if (!msg) {
- msg = @"Some Error Occured,Please Try Again";
- }
- [RAUtils message_alert:msg title:@"Set Store Price" controller:self];
-
- }
- }
- - (NSString *)checkPriceType:(NSInteger)priceType {
- return self.priceType == priceType ? @"1" : @"0";
- }
- - (NSInteger)checkedCadedate:(NSDictionary *)cadedate {
-
- int priceType = 0;
- int count = [[cadedate objectForKey:@"count"] intValue];
- for (int i = 0; i < count; i++) {
- NSDictionary *dic = [cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[dic objectForKey:@"check"] intValue];
- if (check) {
-
- priceType = [[dic objectForKey:@"value_code"] integerValue];
-
- break;
- }
- }
-
- return priceType;
- }
- - (IBAction)priceTypeButtonClick:(UIButton *)sender {
-
- EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
- enumvc.max_select = 1;
-
-
- // enumvc.cadedate = @{
- // @"count" : @"3",
- // @"val_0" : @{@"value" : [Singleton sharedInstance].deliveryString,@"value_code" : @"0",@"check" : [self checkPriceType:0]},
- // @"val_1" : @{@"value" : flat_price,@"value_code" : @"1",@"check" : [self checkPriceType:1]},
- // @"val_2" : @{@"value" : given_price,@"value_code" : @"2",@"check" : [self checkPriceType:2]}
- // }.mutableCopy;
-
- enumvc.cadedate = @{
- @"count" : @"2",
- @"val_0" : @{@"value" : flat_price,@"value_code" : @"1",@"check" : [self checkPriceType:1]},
- @"val_1" : @{@"value" : given_price,@"value_code" : @"2",@"check" : [self checkPriceType:2]}
- }.mutableCopy;
-
- enumvc.title = @"";
-
-
- enumvc.single_select =true;
-
- __weak typeof(self) weakSelf = self;
-
- enumvc.returnValue = ^(NSMutableDictionary* value){
-
- if (weakSelf) {
-
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- [strongSelf changePriceType:[strongSelf checkedCadedate:value]];
- }
-
- };
-
- [self.navigationController pushViewController:enumvc animated:true];
- }
- - (IBAction)saveButtonClick:(UIButton *)sender {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Set PriceType"];
-
- NSDictionary *dic = [iSalesNetwork set_npd_shop_price_type:self.priceType];
-
- [waitalert dismissWithClickedButtonIndex:0 animated:YES];
- // 成功
- if ([[dic objectForKey:@"result"] integerValue] == 2) {
-
- [Singleton sharedInstance].npd_shop_price_type = self.priceType;
-
- // 刷新 Cart、Order List
- [[NSNotificationCenter defaultCenter] postNotificationName:Change_Price_Type_Notification object:nil];
-
- } else { // 失败
-
- DebugLog(@"set price type failure");
- }
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- @end
|