单军华
2018-03-29 89d748b77b478905732e60f0b4c5807c274b6565
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//
//  AdvertisePage.m
//  istanbul
//
//  Created by WindShan on 2017/6/14.
//  Copyright © 2017年 WindShan. All rights reserved.
//
 
#import "AdvertisePage.h"
#import "WenDuPickerView.h"
#import "ASValueTrackingSlider.h"
#import "GloriaLabel.h"
#import "UITextView+Expand.h"
#import "NetworkSingleton.h"
#import "AdModel.h"
 
@interface AdvertisePage ()<ASValueTrackingSliderDelegate,ASValueTrackingSliderDataSource,UITextViewDelegate>
{
     UITextView * adContextTextView;
     UIButton * updownScrolBtn;
     UIButton * rightleftScrolBtn;
     AdModel * hotelSelModel;
}
 
@property (nonatomic, strong)  ASValueTrackingSlider * trackingSlider;
@property (nonatomic, strong)  GloriaLabel * adContextLabel;
@end
 
@implementation AdvertisePage
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"发布广告";
    [self setNavigationLeft:@"返回" sel:@selector(backAction)];
    
    UIImageView * ad_context_bk = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, SCREEN_WIDTH-20, 148)];
    ad_context_bk.image = [UIImage imageNamed:@"ad_context_bk"];
    ad_context_bk.userInteractionEnabled = YES;
    [self.view addSubview:ad_context_bk];
    
    UIImageView * ad_context_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 16, 16)];
    ad_context_tag.image = [UIImage imageNamed:@"ad_context_tag"];
    [ad_context_bk addSubview:ad_context_tag];
    
    _adContextLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,100, 30)];
    _adContextLabel.font = [UIFont systemFontOfSize:14];
    _adContextLabel.textAlignment = UITextAlignmentLeft;
    _adContextLabel.textColor = kUIColorFromRGB(0x00b744);
    _adContextLabel.text = @"广告内容";
    [ad_context_bk addSubview:_adContextLabel];
    
    UIImageView * ad_context_line = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_context_bk.frame.size.width-20, 1)];
    ad_context_line.image = [UIImage imageNamed:@"ad_context_line"];
    [ad_context_bk addSubview:ad_context_line];
    
    adContextTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, 32, ad_context_bk.frame.size.width-20, 110)]; //初始化大小并自动释放
    adContextTextView.textColor = [UIColor blackColor];//设置textview里面的字体颜色
    adContextTextView.font = [UIFont fontWithName:@"Arial"size:14.0];//设置字体名字和字体大小
    adContextTextView.delegate = self;//设置它的委托方法
    adContextTextView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色
    adContextTextView.keyboardType = UIKeyboardTypeDefault;//键盘类型
    adContextTextView.scrollEnabled = YES;//是否可以拖动
    adContextTextView.placeholder = @"在这里输入广告内容";
    adContextTextView.limitLength = [[NSNumber alloc] initWithInt:200]; // 限制字数
    [ad_context_bk addSubview: adContextTextView];//加入到整个页面中
    
    
    UIImageView * ad_scroll_type_bk = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20+148+20, SCREEN_WIDTH-20, 93)];
    ad_scroll_type_bk.image = [UIImage imageNamed:@"ad_scroll_type_bk"];
    ad_scroll_type_bk.userInteractionEnabled = YES;
    [self.view addSubview:ad_scroll_type_bk];
    
    UIImageView * ad_scroll_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 16, 16)];
    ad_scroll_tag.image = [UIImage imageNamed:@"ad_scroll_tag"];
    [ad_scroll_type_bk addSubview:ad_scroll_tag];
    
    _adContextLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,SCREEN_WIDTH-60, 30)];
    _adContextLabel.font = [UIFont systemFontOfSize:14];
    _adContextLabel.textAlignment = UITextAlignmentLeft;
    _adContextLabel.textColor = kUIColorFromRGB(0x00b744);
    _adContextLabel.text = @"设置广告滚动方式";
    [ad_scroll_type_bk addSubview:_adContextLabel];
    
    UIImageView * ad_context_line2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_scroll_type_bk.frame.size.width-20, 1)];
    ad_context_line2.image = [UIImage imageNamed:@"ad_context_line"];
    [ad_scroll_type_bk addSubview:ad_context_line2];
    
    CGFloat scrollW = ad_scroll_type_bk.frame.size.width/2-20;
    
    updownScrolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    updownScrolBtn.frame = CGRectMake((ad_scroll_type_bk.frame.size.width/2 - scrollW)/2, 45, scrollW, 26);
    
    [updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
    [updownScrolBtn setTitle:@"上下滚动" forState:UIControlStateNormal];
    updownScrolBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    [updownScrolBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    updownScrolBtn.layer.masksToBounds=YES;
    updownScrolBtn.layer.cornerRadius=8.0f;
    [updownScrolBtn addTarget:self action:@selector(updownAction) forControlEvents:UIControlEventTouchUpInside];
    [ad_scroll_type_bk addSubview:updownScrolBtn];
    
    rightleftScrolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightleftScrolBtn.frame = CGRectMake(ad_scroll_type_bk.frame.size.width/2+(ad_scroll_type_bk.frame.size.width/2 - scrollW)/2, 45, scrollW, 26);
    
    [rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
    [rightleftScrolBtn setTitle:@"左右滚动" forState:UIControlStateNormal];
    rightleftScrolBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    [rightleftScrolBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightleftScrolBtn.layer.masksToBounds=YES;
    rightleftScrolBtn.layer.cornerRadius=8.0f;
    [rightleftScrolBtn addTarget:self action:@selector(rightleftAction) forControlEvents:UIControlEventTouchUpInside];
    [ad_scroll_type_bk addSubview:rightleftScrolBtn];
    
    
    UIImageView * ad_scroll_type_bk2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20+148+20+93+20, SCREEN_WIDTH-20, 93)];
    ad_scroll_type_bk2.image = [UIImage imageNamed:@"ad_scroll_type_bk"];
    ad_scroll_type_bk2.userInteractionEnabled = YES;
    [self.view addSubview:ad_scroll_type_bk2];
    
    UIImageView * ad_scroll_speed_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 17, 17)];
    ad_scroll_speed_tag.image = [UIImage imageNamed:@"ad_scroll_speed_tag"];
    [ad_scroll_type_bk2 addSubview:ad_scroll_speed_tag];
    
    GloriaLabel *_adContextLabel2 = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,SCREEN_WIDTH-60, 30)];
    _adContextLabel2.font = [UIFont systemFontOfSize:14];
    _adContextLabel2.textAlignment = UITextAlignmentLeft;
    _adContextLabel2.textColor = kUIColorFromRGB(0x00b744);
    _adContextLabel2.text = @"设置广告滚动速度";
    [ad_scroll_type_bk2 addSubview:_adContextLabel2];
    
    UIImageView * ad_context_line3 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_scroll_type_bk2.frame.size.width-20, 1)];
    ad_context_line3.image = [UIImage imageNamed:@"ad_context_line"];
    [ad_scroll_type_bk2 addSubview:ad_context_line3];
    
    _trackingSlider = [[ASValueTrackingSlider alloc]initWithFrame:CGRectMake(10, 70, ad_scroll_type_bk2.frame.size.width-20, 40)];
    
    _trackingSlider.delegate = self;
    _trackingSlider.dataSource = self;
    _trackingSlider.popUpViewCornerRadius = 5.0;
    [_trackingSlider setMaxFractionDigitsDisplayed:0];
    _trackingSlider.popUpViewColor = kUIColorFromRGB(0x00b744);
    _trackingSlider.font = [UIFont fontWithName:@"GillSans-Bold" size:12];
    _trackingSlider.textColor = [UIColor whiteColor];
    _trackingSlider.maximumValue = 100;
    _trackingSlider.minimumValue = 0;
    //_trackingSlider.formatStr = @"%@℃";
    //[_trackingSlider setValue: [__wenDuStr intValue]];
    [_trackingSlider showPopUpView];
    [ad_scroll_type_bk2 addSubview:_trackingSlider];
    
    
    UIButton * fabuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fabuBtn.frame = CGRectMake((SCREEN_WIDTH-350)/2, 20+148+20+93+20+93+20, 350, 40);
    
    [fabuBtn setBackgroundImage:[UIImage imageNamed:@"ad_fabu_btn_bk" ] forState:UIControlStateNormal];
    [fabuBtn setTitle:@"发 布" forState:UIControlStateNormal];
    fabuBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    [fabuBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    fabuBtn.layer.masksToBounds=YES;
    fabuBtn.layer.cornerRadius=8.0f;
    [fabuBtn addTarget:self action:@selector(fabuAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fabuBtn];
    
    [self get_device_ad];
    // Do any additional setup after loading the view.
}
 
-(void)fabuAction
{
    //[UserDefault stringForKey:@"user_id"]
    NSString *path = [[NSString alloc] initWithFormat:UPDATE_AD];
    
    //params.put("mac",mac);
    //params.put("ad_content",ad_content);
    //params.put("ad_rollmd",ad_rollmd+"");
    //params.put("ad_speed",ad_speed+"");
    //params.put("ad_mode",ad_mode+"");
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
    
    [param setObject:_currentModel.mac forKey:@"mac"];
      [param setObject:adContextTextView.text forKey:@"ad_content"];
      [param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_rollmd] forKey:@"ad_rollmd"];
      [param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_speed] forKey:@"ad_speed"];
      [param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_mode] forKey:@"ad_mode"];
    
    
    MPWeakSelf(self);
    [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody)
     {
         MPStrongSelf(self);
         BaseResModel * resModel = [Global toBaseModel:responseBody];
         
         if(resModel.code == 0)
         {
             //发送成功提示
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
         else
         {
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
     }
                                  failure:^(NSString *error)
     {
         
         [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }]; 
}
 
-(void)get_device_ad
{
    
    //[UserDefault stringForKey:@"user_id"]
    NSString *path = [[NSString alloc] initWithFormat:@"%@",[NSString stringWithFormat:GET_DEVICE_AD,self.currentModel.mac]];
    
    //params.put("mac",mac);
    //params.put("ad_content",ad_content);
    //params.put("ad_rollmd",ad_rollmd+"");
    //params.put("ad_speed",ad_speed+"");
    //params.put("ad_mode",ad_mode+"");
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
    
    //param setObject:<#(nonnull id)#> forKey:<#(nonnull id<NSCopying>)#>
    
    MPWeakSelf(self);
    [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody)
     {
         MPStrongSelf(self);
         BaseResModel * resModel = [Global toBaseModel:responseBody];
         
         if(resModel.code == 0)
         {
             //发送成功提示
             if(![Global isEmptyObject:resModel.content])
             {
  
                 hotelSelModel = [AdModel mj_objectWithKeyValues:resModel.content];
                 
                 adContextTextView.placeholderLabel.hidden = YES;
                 adContextTextView.text = hotelSelModel.ad_content;
                 //@property(nonatomic, strong) NSString * _id;//": "590abf002b153bee6e5b682b",
                 //@property(nonatomic, strong) NSString * ad_content;//": "广告内容-200字以内",
                 //@property(nonatomic, assign) int  ad_rollmd;//": 1,
                 //@property(nonatomic, assign) int  ad_speed;//": 50,
                 //@property(nonatomic, assign) int  ad_mode;//": 1
                 //滚动方式 1左右,2上下
                 if(hotelSelModel.ad_rollmd == 1)
                 {
                     [rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
                     [updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
                 }
                 else if(hotelSelModel.ad_rollmd == 2)
                 {
                     [rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk1" ] forState:UIControlStateNormal];
                     [updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk2" ] forState:UIControlStateNormal];
                 }
                 
                 [_trackingSlider setValue: hotelSelModel.ad_speed];
             }
             else
             {
                 [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
             }
         }
         else
         {
             [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         }
     }
                                  failure:^(NSString *error)
     {
         
         [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }];
    
}
 
-(void)updownAction
{
    //滚动方式 1左右,2上下
    if(hotelSelModel.ad_rollmd == 1)
    {
        [rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk1" ] forState:UIControlStateNormal];
        [updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk2" ] forState:UIControlStateNormal];
    }
    
    hotelSelModel.ad_rollmd = 2;
}
 
-(void)rightleftAction
{
    //滚动方式 1左右,2上下
    if(hotelSelModel.ad_rollmd == 2)
    {
        [rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
        [updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
    }
    
    hotelSelModel.ad_rollmd = 1;
}
 
-(void)backAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
#pragma mark - ASValueTrackingSliderDelegate
- (NSString *)slider:(ASValueTrackingSlider *)slider stringForValue:(float)value
{
    NSString * valueStr = [NSString stringWithFormat:@"%d",(int)value];
    //self._wenDuStr = valueStr;
    
    // LOG_INFO(@"当前选择数值:%@℃",self._wenDuStr);
    
    hotelSelModel.ad_speed = (int)value;
    
    return valueStr;
}
 
- (void)sliderWillDisplayPopUpView:(ASValueTrackingSlider *)slider{
    
}
 
- (void)sliderDidHidePopUpView:(ASValueTrackingSlider *)slider{
    
}
 
#pragma mark disappear keyboard begin
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    // 在编辑范围是否允许输入某些text
    // 如果你的textView里面不允许用回车,可以用此方法通过按回车回收键盘
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    else
    {
        return YES;
    }
}
 
 
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if ([textView isFirstResponder]) {
        [textView resignFirstResponder];
    }
}
 
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self textViewDidEndEditing:adContextTextView];
}
 
/*
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 
@end