ExperienceCentreViewController.m 26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//
//  ExperienceCentreViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/1.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ExperienceCentreViewController.h"
#import "SceneViewController.h"
11 12
#import "sceneScreeningCollectionViewCell.h"
#import "ProductScreeningTableViewCell.h"
勾芒's avatar
勾芒 committed
13 14
#import "GoodsImageView.h"
#import "ShareGoodsViewController.h"
曹云霄's avatar
曹云霄 committed
15
#import "DeviceDirectionManager.h"
曹云霄's avatar
曹云霄 committed
16 17
#import "HelpController.h"
#import "ShoppingBagViewController.h"
18

勾芒's avatar
勾芒 committed
19 20 21 22 23

#define LEFTWIDTH 100
#define RIGHTWIDTH 200
#define TOPWIDTH 300

24
@interface ExperienceCentreViewController ()<AddImagesDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
25

勾芒's avatar
勾芒 committed
26

27 28 29 30 31

@end

@implementation ExperienceCentreViewController

32 33 34 35 36 37 38 39


- (NSMutableArray *)sceneDatasArray
{
    if (!_sceneDatasArray) {
        _sceneDatasArray = [NSMutableArray array];
    }
    return _sceneDatasArray;
40 41 42
}


43 44 45 46 47 48 49
- (NSMutableArray *)productDatasArray
{
    if (!_productDatasArray) {
        _productDatasArray = [NSMutableArray array];
    }
    return _productDatasArray;
}
50 51


勾芒's avatar
勾芒 committed
52 53 54 55 56 57 58 59
- (NSMutableArray *)shareGoodsArray
{
    if (!_shareGoodsArray) {
        _shareGoodsArray = [NSMutableArray array];
    }
    return _shareGoodsArray;
}

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
- (NSMutableArray *)sceneTempArray
{
    if (!_sceneTempArray) {
        _sceneTempArray = [NSMutableArray array];
    }
    return _sceneTempArray;
}

- (NSMutableArray *)productTempArray
{
    if (!_productTempArray) {
        _productTempArray = [NSMutableArray array];
    }
    return _productTempArray;
}

76 77 78 79 80 81 82
- (NSMutableArray *)lampArray
{
    if (!_lampArray) {
        _lampArray = [NSMutableArray array];
    }
    return _lampArray;
}
83

84 85 86 87 88
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
}
89 90


91 92 93 94
#pragma mark -UI
- (void)uiConfigAction
{
    //场景
95
    self.sceneLayout.itemSize = CGSizeMake(130, 100);
96 97 98 99 100 101 102
    self.sceneLayout.minimumLineSpacing = 10;
    self.sceneLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    self.sceneScrollview.delegate = self;
    self.sceneScrollview.dataSource = self;
    //产品
    self.productScrollview.dataSource = self;
    self.productScrollview.delegate = self;
103 104 105 106
    if (self.boolValue) {
        SceneListModel *model = [self.sceneDatasArray firstObject];
        [self.sceneImageView sd_setImageWithURL:[NSURL URLWithString:model.pricure] placeholderImage:REPLACEIMAGE];
    }
107 108 109 110 111 112 113
}

#pragma mark -UICollectionViewDataSource场景
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.sceneDatasArray.count;
}
114

115 116 117
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    sceneScreeningCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"sceneScreeningCollectionViewCell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
118 119
     SceneListModel *model = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
    [cell.selectedScrenImageView sd_setImageWithURL:[NSURL URLWithString:model.pricure] placeholderImage:REPLACEIMAGE];
120 121 122
    cell.selectedScrenImageView.tag = indexPath.item+100;
    cell.selectedScrenImageView.userInteractionEnabled = YES;
    [cell.selectedScrenImageView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressRemove:)]];
勾芒's avatar
勾芒 committed
123 124
    cell.selectedScrenImageView.layer.masksToBounds = YES;
    cell.selectedScrenImageView.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
125
    if (model.isSelectedSate) {
勾芒's avatar
勾芒 committed
126 127 128 129 130 131
        cell.selectedScrenImageView.layer.borderWidth = 2.0f;
        cell.selectedScrenImageView.layer.borderColor = kMainBlueColor.CGColor;
    }else
    {
        cell.selectedScrenImageView.layer.borderWidth = 0;
    }
132 133
    return cell;
}
134

135 136
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
勾芒's avatar
勾芒 committed
137 138
    for (SceneListModel *model in self.sceneDatasArray) {
        model.isSelectedSate = NO;
勾芒's avatar
勾芒 committed
139
    }
勾芒's avatar
勾芒 committed
140 141 142
   SceneListModel *model = [self.sceneDatasArray objectAtIndex_opple:indexPath.item];
    model.isSelectedSate = YES;
    [self.sceneImageView sd_setImageWithURL:[NSURL URLWithString:model.pricure] placeholderImage:REPLACEIMAGE];
勾芒's avatar
勾芒 committed
143
    [self.sceneScrollview reloadData];
144
}
145 146 147



148 149 150 151 152
#pragma mark -UITableViewDataSource商品
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.productDatasArray.count;
}
153

154 155 156 157 158
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductScreeningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductScreeningTableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
勾芒's avatar
勾芒 committed
159
    TOGoodsEntityModel *model = [self.productDatasArray objectAtIndex_opple:indexPath.row];
勾芒's avatar
勾芒 committed
160 161 162 163 164 165 166
    if (model.isSelectedState) {
        cell.selectedGoodsImageView.layer.borderWidth = 2.0f;
        cell.selectedGoodsImageView.layer.borderColor = kMainBlueColor.CGColor;
    }else
    {
        cell.selectedGoodsImageView.layer.borderWidth = 0;
    }
勾芒's avatar
勾芒 committed
167
    NSArray *imags = [model.pictures componentsSeparatedByString:@","];
168
    [cell.selectedGoodsImageView sd_setImageWithURL:[NSURL URLWithString:[imags firstObject]]];
169 170 171
    cell.selectedGoodsImageView.userInteractionEnabled = YES;
    cell.selectedGoodsImageView.tag = indexPath.row + 100;
    [cell.selectedGoodsImageView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(productLongPressRemove:)]];
172 173
    return cell;
}
174 175


176 177 178 179
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
180

勾芒's avatar
勾芒 committed
181 182
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
183
    WS(weakSelf);
勾芒's avatar
勾芒 committed
184
    ProductScreeningTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
勾芒's avatar
勾芒 committed
185
    TOGoodsEntityModel *model = [self.productDatasArray objectAtIndex_opple:indexPath.row];
勾芒's avatar
勾芒 committed
186 187
    CGRect cellRect = [cell convertRect:cell.bounds toView:self.view];
    GoodsImageView *imageView = [[GoodsImageView alloc]initWithFrame:cellRect];
勾芒's avatar
勾芒 committed
188
    imageView.model = model;
189
    [imageView setDelectedBlock:^(TOGoodsEntityModel *delectedModel,GoodsImageView *deleteImageView) {
曹云霄's avatar
曹云霄 committed
190
        //删除先判断数量
191
        for (TOGoodsEntityModel *newModel in weakSelf.shareGoodsArray) {
曹云霄's avatar
曹云霄 committed
192 193
            if ([newModel.fid isEqualToString:delectedModel.fid]) {
                if (newModel.goodsNumber <= 1) {
194 195
                    [weakSelf.shareGoodsArray removeObject:delectedModel];
                    [weakSelf.lampArray removeObject:deleteImageView];
曹云霄's avatar
曹云霄 committed
196 197 198 199 200 201 202
                }else
                {
                    newModel.goodsNumber --;
                }
                break;
            }
        }
勾芒's avatar
勾芒 committed
203
    }];
勾芒's avatar
勾芒 committed
204 205 206
    imageView.userInteractionEnabled = YES;
    [UIView animateWithDuration:0.5 animations:^{
        
勾芒's avatar
勾芒 committed
207
        imageView.frame = CGRectMake((ScreenWidth-266)/2, (ScreenHeight-200)/2, 266, 200);
勾芒's avatar
勾芒 committed
208
    }];
209
    for (TOGoodsEntityModel *model in weakSelf.productDatasArray) {
勾芒's avatar
勾芒 committed
210 211 212
        model.isSelectedState = NO;
    }
    model.isSelectedState = YES;
曹云霄's avatar
曹云霄 committed
213 214 215 216 217 218 219 220 221 222 223
    //判断选中的商品是否已经存在
    if ([self.shareGoodsArray containsObject:model]) {
        for (TOGoodsEntityModel *newModel in self.shareGoodsArray) {
            if ([newModel.fid isEqualToString:model.fid]) {
                newModel.goodsNumber ++;
                break;
            }
        }
    }else
    {
       [self.shareGoodsArray addObject:model];
224
        [self.lampArray addObject:imageView];
曹云霄's avatar
曹云霄 committed
225
    }
勾芒's avatar
勾芒 committed
226 227
    NSArray *imags = [model.pictures componentsSeparatedByString:@","];
    [imageView sd_setImageWithURL:[NSURL URLWithString:[imags firstObject]] placeholderImage:REPLACEIMAGE];
228
    imageView.showImageViewAddress = [imags firstObject];
勾芒's avatar
勾芒 committed
229
    [self.sceneBackView addSubview:imageView];
勾芒's avatar
勾芒 committed
230
    [self.productScrollview reloadData];
勾芒's avatar
勾芒 committed
231
}
232 233 234 235 236


#pragma mark -返回
- (IBAction)ReturnButtonClickAction:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
237 238
    SHARED_APPDELEGATE.sceneArray = nil;
    SHARED_APPDELEGATE.productArray = nil;
239 240 241 242 243 244
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark -购物袋
- (IBAction)ShoppingBagButtonClickAction:(UIButton *)sender {
勾芒's avatar
勾芒 committed
245
    
曹云霄's avatar
曹云霄 committed
246
    sender.selected = YES;
曹云霄's avatar
曹云霄 committed
247
    ShoppingBagViewController *shoppingBag = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"ShoppingBagViewController"];
曹云霄's avatar
曹云霄 committed
248 249 250 251 252 253 254 255
    [shoppingBag setDismissBlock:^{
        sender.selected = NO;
    }];
    shoppingBag.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *pop = shoppingBag.popoverPresentationController;
    pop.sourceView = shoppingBag.view;
    shoppingBag.datasArray = self.shareGoodsArray;
    [self presentViewController:shoppingBag animated:YES completion:nil];
256 257 258 259
}

#pragma mark -分享
- (IBAction)ShareButtonClickAction:(UIButton *)sender {
勾芒's avatar
勾芒 committed
260
    
261
    if (!self.shareGoodsArray.count) {
曹云霄's avatar
曹云霄 committed
262
        [XBLoadingView showHUDViewWithText:@"没有选择需要分享的商品"];
263 264
        return;
    }
265 266 267
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        UIImageWriteToSavedPhotosAlbum([self capture], self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    });
勾芒's avatar
勾芒 committed
268
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
勾芒's avatar
勾芒 committed
269 270 271 272 273
    //商品id拼接
    NSMutableString *goodsID = [[NSMutableString alloc]init];
    for (TOGoodsEntityModel *model in self.shareGoodsArray) {
        [goodsID appendFormat:@"%@,",model.fid];
    }
274
    shareController.shareID = goodsID;
勾芒's avatar
勾芒 committed
275
    shareController.shareImage = [self capture];
276
    shareController.type = SHARE_GOODS;
勾芒's avatar
勾芒 committed
277 278 279 280 281 282 283
    shareController.preferredContentSize = CGSizeMake(290, 120);
    shareController.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *popover = shareController.popoverPresentationController;
    popover.permittedArrowDirections = UIPopoverArrowDirectionLeft;
    popover.sourceView = shareController.view;
    popover.sourceRect =  CGRectMake(sender.mj_x, sender.mj_y-30, sender.mj_w, sender.mj_h);
    [self presentViewController:shareController animated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
284 285 286 287 288 289
}

#pragma mark -保存图片到相册
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    if (error != NULL) {
曹云霄's avatar
曹云霄 committed
290
        [XBLoadingView showHUDViewWithText:@"保存相册失败"];
曹云霄's avatar
曹云霄 committed
291
    }
292 293 294 295
}

#pragma mark -拍照
- (IBAction)TakingPhotoButtonClickAction:(UIButton *)sender {
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
    // 判断应用是否有使用相机的权限
    if(![BaseViewController determineCameraPermissions]){
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在iPad的“设置-隐私-相机”选项中,允许欧立方访问你的相机" preferredStyle:UIAlertControllerStyleAlert];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:nil]];
        [self presentViewController:alertVC animated:YES completion:nil];
        
    }else{
        
        sender.selected = YES;
        UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
        UIImagePickerController *PcCamera = [[UIImagePickerController alloc]init];
        PcCamera.delegate = self;
        [DeviceDirectionManager instance].isHorizontal=YES;
        [alertView addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //拍照
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                [PcCamera setSourceType:UIImagePickerControllerSourceTypeCamera];
                PcCamera.allowsEditing = YES;
                [self presentViewController:PcCamera animated:YES completion:nil];
            }
            else
            {
曹云霄's avatar
曹云霄 committed
318
                [XBLoadingView showHUDViewWithText:@"相机无法使用"];
319 320 321 322 323 324 325 326 327 328 329 330
                sender.selected = NO;
            }
        }]];
        [alertView addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //从相册中选择
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
                [PcCamera setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                PcCamera.allowsEditing = YES;
                [self presentViewController:PcCamera animated:YES completion:nil];
            }
            else
            {
曹云霄's avatar
曹云霄 committed
331
                [XBLoadingView showHUDViewWithText:@"相册无法打开"];
332 333 334 335 336 337 338 339 340
                sender.selected = NO;
            }
        }]];
        [alertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            self.takingPicturesButton.selected = NO;
            [alertView dismissViewControllerAnimated:YES completion:nil];
        }]];
        [self presentViewController:alertView animated:YES completion:nil];
    }
曹云霄's avatar
曹云霄 committed
341
}
勾芒's avatar
勾芒 committed
342

曹云霄's avatar
曹云霄 committed
343 344 345 346
#pragma mark -拍照、从相册选择
#pragma -mark -UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
曹云霄's avatar
曹云霄 committed
347
    [DeviceDirectionManager instance].isHorizontal = NO;
曹云霄's avatar
曹云霄 committed
348 349 350
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *Headimage = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.sceneImageView.image = Headimage;
曹云霄's avatar
曹云霄 committed
351
    self.takingPicturesButton.selected = NO;
勾芒's avatar
勾芒 committed
352
}
勾芒's avatar
勾芒 committed
353

勾芒's avatar
勾芒 committed
354 355 356 357 358 359 360 361 362 363 364 365 366
#pragma mark -截屏
- (UIImage *)capture
{
    // 创建一个context
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    //把当前的全部画面导入到栈顶context中并进行渲染
    [self.sceneBackView.layer renderInContext:UIGraphicsGetCurrentContext()];
    // 从当前context中创建一个新图片
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    return img;
}
勾芒's avatar
勾芒 committed
367

曹云霄's avatar
曹云霄 committed
368

369 370
#pragma mark -全屏
- (IBAction)AmplificationButtonClickAction:(UIButton *)sender {
勾芒's avatar
勾芒 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    
    if (!sender.selected) {
        
        [UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            
            self.returnButton.frame = CGRectMake(self.returnButton.mj_x-LEFTWIDTH, self.returnButton.mj_y, self.returnButton.mj_w, self.returnButton.mj_h);
            self.shoppingbagButton.frame = CGRectMake(self.shoppingbagButton.mj_x-LEFTWIDTH, self.shoppingbagButton.mj_y, self.shoppingbagButton.mj_w, self.shoppingbagButton.mj_h);
            self.shareButton.frame = CGRectMake(self.shareButton.mj_x-LEFTWIDTH, self.shareButton.mj_y, self.shareButton.mj_w, self.shareButton.mj_h);
            self.takingPicturesButton.frame = CGRectMake(self.takingPicturesButton.mj_x-LEFTWIDTH, self.takingPicturesButton.mj_y, self.takingPicturesButton.mj_w, self.takingPicturesButton.mj_h);
            self.helpButton.frame = CGRectMake(self.helpButton.mj_x-LEFTWIDTH, self.helpButton.mj_y, self.helpButton.mj_w, self.helpButton.mj_h);
            self.sceneSelectedButton.frame = CGRectMake(self.sceneSelectedButton.mj_x, self.sceneSelectedButton.mj_y+RIGHTWIDTH, self.sceneSelectedButton.mj_w, self.sceneSelectedButton.mj_h);
            self.sceneScrollview.frame = CGRectMake(self.sceneScrollview.mj_x, self.sceneScrollview.mj_y+RIGHTWIDTH, self.sceneScrollview.mj_w, self.sceneScrollview.mj_h);
            self.productSelectedButton.frame = CGRectMake(self.productSelectedButton.mj_x+RIGHTWIDTH, self.productSelectedButton.mj_y, self.productSelectedButton.mj_w, self.productSelectedButton.mj_h);
            self.productScrollview.frame = CGRectMake(self.productScrollview.mj_x+RIGHTWIDTH, self.productScrollview.mj_y, self.productScrollview.mj_w, self.productScrollview.mj_h);
             self.amplificationButton.frame = CGRectMake(self.amplificationButton.mj_x, self.amplificationButton.mj_y-(RIGHTWIDTH+LEFTWIDTH), self.amplificationButton.mj_w, self.amplificationButton.mj_h);
            
        } completion:nil];
    }else
    {
        [UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            
            self.returnButton.frame = CGRectMake(self.returnButton.mj_x+LEFTWIDTH, self.returnButton.mj_y, self.returnButton.mj_w, self.returnButton.mj_h);
            self.shoppingbagButton.frame = CGRectMake(self.shoppingbagButton.mj_x+LEFTWIDTH, self.shoppingbagButton.mj_y, self.shoppingbagButton.mj_w, self.shoppingbagButton.mj_h);
            self.shareButton.frame = CGRectMake(self.shareButton.mj_x+LEFTWIDTH, self.shareButton.mj_y, self.shareButton.mj_w, self.shareButton.mj_h);
            self.takingPicturesButton.frame = CGRectMake(self.takingPicturesButton.mj_x+LEFTWIDTH, self.takingPicturesButton.mj_y, self.takingPicturesButton.mj_w, self.takingPicturesButton.mj_h);
            self.helpButton.frame = CGRectMake(self.helpButton.mj_x+LEFTWIDTH, self.helpButton.mj_y, self.helpButton.mj_w, self.helpButton.mj_h);
            self.sceneSelectedButton.frame = CGRectMake(self.sceneSelectedButton.mj_x, self.sceneSelectedButton.mj_y-RIGHTWIDTH, self.sceneSelectedButton.mj_w, self.sceneSelectedButton.mj_h);
            self.sceneScrollview.frame = CGRectMake(self.sceneScrollview.mj_x, self.sceneScrollview.mj_y-RIGHTWIDTH, self.sceneScrollview.mj_w, self.sceneScrollview.mj_h);
            self.productSelectedButton.frame = CGRectMake(self.productSelectedButton.mj_x-RIGHTWIDTH, self.productSelectedButton.mj_y, self.productSelectedButton.mj_w, self.productSelectedButton.mj_h);
            self.productScrollview.frame = CGRectMake(self.productScrollview.mj_x-RIGHTWIDTH, self.productScrollview.mj_y, self.productScrollview.mj_w, self.productScrollview.mj_h);
            self.amplificationButton.frame = CGRectMake(self.amplificationButton.mj_x, self.amplificationButton.mj_y+(RIGHTWIDTH+LEFTWIDTH), self.amplificationButton.mj_w, self.amplificationButton.mj_h);
            
        } completion:nil];
    }
    sender.selected = !sender.selected;
406 407 408 409
}

#pragma mark -帮助
- (IBAction)HelpButtonClickAction:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
    
    sender.selected = YES;
    HelpController *helpView = [[HelpController alloc]init];
    helpView.backButtonPoint = self.returnButton.mj_origin;
    helpView.shoppingbagPoint = self.shoppingbagButton.mj_origin;
    helpView.sharePoint = self.shareButton.mj_origin;
    helpView.photoPoint = self.takingPicturesButton.mj_origin;
    helpView.fullScreenPoint = self.amplificationButton.mj_origin;
    helpView.helpPoint = self.helpButton.mj_origin;
    helpView.scenePoint = self.sceneSelectedButton.center;
    helpView.productPoint = self.productSelectedButton.center;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissAction:)];
    [helpView.view addGestureRecognizer:tap];
    [self.view addSubview:helpView.view];
}

#pragma mark -销毁
- (void)dismissAction:(UITapGestureRecognizer *)tap
{
    self.helpButton.selected = NO;
    [tap.view removeFromSuperview];
431 432 433 434 435 436 437
}


/**************************功能区**************************/
#pragma mark -场景筛选
- (IBAction)SceneSelectedButtonClickAction:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
438
    sender.selected = YES;
439
    [UserDefault setBool:YES forKey:@"SCENE"];
曹云霄's avatar
曹云霄 committed
440
    SceneViewController *sceneVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"SceneController"];
曹云霄's avatar
曹云霄 committed
441 442 443
    [sceneVC setDismissBlock:^{
        sender.selected = NO;
    }];
勾芒's avatar
勾芒 committed
444
    sceneVC.view.backgroundColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
445
    sceneVC.titleLabe.text = @"选择场景";
勾芒's avatar
勾芒 committed
446 447 448 449
    sceneVC.searchBackView.hidden = YES;
    sceneVC.materialButton.hidden = YES;
    sceneVC.priceButton.hidden = YES;
    sceneVC.typeButton.hidden = YES;
450 451
    sceneVC.delegate = self;
    sceneVC.endAnimationPoint = self.sceneSelectedButton.center;
452 453 454 455 456 457 458 459
    sceneVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *pop = sceneVC.popoverPresentationController;
    pop.sourceView = sceneVC.view;
    [self presentViewController:sceneVC animated:YES completion:nil];
}

#pragma mark -产品筛选
- (IBAction)ProductSelectedButtonClickAction:(UIButton *)sender {
勾芒's avatar
勾芒 committed
460
    
曹云霄's avatar
曹云霄 committed
461
    sender.selected = YES;
462
    [UserDefault setBool:NO forKey:@"SCENE"];
曹云霄's avatar
曹云霄 committed
463
    SceneViewController *sceneVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"SceneController"];
曹云霄's avatar
曹云霄 committed
464 465 466
    [sceneVC setDismissBlock:^{
        sender.selected = NO;
    }];
勾芒's avatar
勾芒 committed
467
    sceneVC.view.backgroundColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
468
    sceneVC.titleLabe.text = @"选择商品";
勾芒's avatar
勾芒 committed
469 470 471 472
    sceneVC.searchBackView.hidden = NO;
    sceneVC.materialButton.hidden = NO;
    sceneVC.priceButton.hidden = NO;
    sceneVC.typeButton.hidden = NO;
473 474
    sceneVC.delegate = self;
    sceneVC.endAnimationPoint = self.productSelectedButton.center;
勾芒's avatar
勾芒 committed
475 476 477 478
    sceneVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *pop = sceneVC.popoverPresentationController;
    pop.sourceView = sceneVC.view;
    [self presentViewController:sceneVC animated:YES completion:nil];
479 480 481 482
}



483
#pragma mark -AddImagesDelegate选中图片
勾芒's avatar
勾芒 committed
484
- (void)SelectedImageswithModel:(JSONModel *)model withisScene:(BOOL)isScene returnResponse:(void (^)(BOOL))isThere
485 486
{
    if (isScene) {
勾芒's avatar
勾芒 committed
487
        //场景
曹云霄's avatar
曹云霄 committed
488
        SceneListModel *sceneModel = [(SceneListModel *)model copy];
489 490 491
        for (int i=0; i<self.sceneDatasArray.count; i++) {
            SceneListModel * model = [self.sceneDatasArray objectAtIndex_opple:i];
            if ([model.fid isEqualToString:sceneModel.fid]) {
勾芒's avatar
勾芒 committed
492
                isThere(YES);
493 494
                [self.sceneDatasArray removeObject:model];
                [self.sceneScrollview deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:i inSection:0]]];
勾芒's avatar
勾芒 committed
495 496
                return;
            }
497
        }
勾芒's avatar
勾芒 committed
498
        isThere(NO);
499
        [self.sceneTempArray addObject:sceneModel];
500 501 502
        
    }else
    {
勾芒's avatar
勾芒 committed
503
        //产品
曹云霄's avatar
曹云霄 committed
504
        TOGoodsEntityModel *goodsModel = [(TOGoodsEntityModel *)model copy];
505 506 507
        for (int i=0; i<self.productDatasArray.count; i++) {
            TOGoodsEntityModel *model = [self.productDatasArray objectAtIndex_opple:i];
            if ([model.fid isEqualToString:goodsModel.fid]) {
勾芒's avatar
勾芒 committed
508
                isThere(YES);
509 510
                [self.productDatasArray removeObject:model];
                [self.productScrollview deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
勾芒's avatar
勾芒 committed
511 512
                return;
            }
513
        }
勾芒's avatar
勾芒 committed
514
        isThere(NO);
515
        [self.productTempArray addObject:goodsModel];
516 517 518 519 520 521 522 523
    }
}

#pragma mark -刷新
- (void)RefreshSceneAndProduct:(BOOL)isScene
{
    if (isScene) {
        
524 525 526 527 528 529
        SceneListModel *model = [self.sceneTempArray firstObject];
        model.isSelectedSate = NO;
        [self.sceneDatasArray addObject:model];
        SHARED_APPDELEGATE.sceneArray = self.sceneDatasArray;
        [self.sceneTempArray removeObjectAtIndex:0];
        [self.sceneScrollview insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.sceneDatasArray.count-1 inSection:0]]];
530 531 532 533
        [self.sceneScrollview selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.sceneDatasArray.count-1 inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionRight];
        
    }else
    {
534 535 536 537 538 539
        TOGoodsEntityModel *goodsModel = [self.productTempArray firstObject];
        goodsModel.isSelectedState = NO;
        [self.productDatasArray addObject:goodsModel];
        SHARED_APPDELEGATE.productArray = self.productDatasArray;
        [self.productTempArray removeObjectAtIndex:0];
        [self.productScrollview insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.productDatasArray.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
540 541 542 543
        [self.productScrollview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.productDatasArray.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
}

544 545 546 547 548 549 550 551 552 553 554 555
#pragma mark -场景长按删除
- (void)longPressRemove:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateBegan) {
        NSInteger index = longPress.view.tag-100;
        [self.sceneDatasArray removeObjectAtIndex:index];
        [self.sceneScrollview deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.sceneScrollview reloadData];
        });
    }
}
556

557 558 559 560 561 562 563 564 565 566 567 568
#pragma mark -产品长按删除
- (void)productLongPressRemove:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateBegan) {
        NSInteger index = longPress.view.tag-100;
        [self.productDatasArray removeObjectAtIndex:index];
        [self.productScrollview deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.productScrollview reloadData];
        });
    }
}
勾芒's avatar
勾芒 committed
569

570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
#pragma mark -切换灯图片
- (IBAction)changeLampImageClickAction:(UIButton *)sender {

    //满足多组灯同时切换
    for (GoodsImageView *imageView in self.lampArray) {
        for (TOGoodsEntityModel *model in self.shareGoodsArray) {
            NSArray *images = [model.pictures componentsSeparatedByString:@","];
            if (![images containsObject:imageView.showImageViewAddress])continue;
            NSInteger index = [images indexOfObject:imageView.showImageViewAddress];
            if (index < images.count-1) {
                [imageView sd_setImageWithURL:[NSURL URLWithString:[images objectAtIndex:index+=1]]];
                imageView.showImageViewAddress = [images objectAtIndex:index];
            } else {
                [imageView sd_setImageWithURL:[NSURL URLWithString:[images firstObject]]];
                imageView.showImageViewAddress = [images firstObject];
            }
        }
    }
曹云霄's avatar
曹云霄 committed
588
    sender.selected = !sender.selected;
589 590
}

曹云霄's avatar
曹云霄 committed
591 592 593 594
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
595 596

@end