//
//  ShareGoodsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/3.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShareGoodsViewController.h"

@interface ShareGoodsViewController ()

@end

@implementation ShareGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -分享
- (IBAction)ShareWeiChatAntWeiboAction:(UIButton *)sender {
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    NSData *imageData = UIImageJPEGRepresentation(self.shareImage, 1.0);
    //    0b44439e5504e371015504f73d4f0025,0b44439e5504e371015504feae270028
    NSDictionary *parameterDict = [NSDictionary dictionaryWithObjectsAndKeys:@"0b44439e5504e371015504f73d4f0025,0b44439e5504e371015504feae270028",@"goodsIds",@"",@"title",@"",@"remark",nil];
    
    //上传图片
    [[NetworkRequestClassManager Manager] UploadImageWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/system/shareGoods"] WithRequestType:0 WithImageDatas:imageData WithParameter:parameterDict WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            UMSocialUrlResource *resource = [[UMSocialUrlResource alloc]init];
            [resource setResourceType:UMSocialUrlResourceTypeImage url:@"http://139.196.195.30:8090/opple-web/temp2/16052615120001.jpg"];
            NSString *shareWeb = returnValue[@"data"][@"url"];
            switch (sender.tag) {
                case 101: //微信好友
                {//自定义样式
                    
                    //使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
                    [UMSocialData defaultData].extConfig.wechatSessionData.url = shareWeb;
                    [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:ShareTitle image:nil location:nil urlResource:resource presentedController:self completion:^(UMSocialResponseEntity *response){
                        if (response.responseCode == UMSResponseCodeSuccess) {
                            
                            [self SuccessMBProgressView:@"分享微信好友成功"];
                        }
                    }];
                }
                    
                    break;
                case 102://微信朋友圈
                {
                    //使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
                    [UMSocialData defaultData].extConfig.wechatTimelineData.url = shareWeb;
                    [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:ShareTitle image:nil location:nil urlResource:resource presentedController:self completion:^(UMSocialResponseEntity *response){
                        if (response.responseCode == UMSResponseCodeSuccess) {
                            
                            [self SuccessMBProgressView:@"分享微信朋友圈成功"];
                        }
                    }];
                }
                    break;
                case 103://新浪微博
                {
                    
                    //自定义分享样式
                    [UMSocialData defaultData].extConfig.sinaData.shareText = [NSString stringWithFormat:@"%@%@",@"欧普照明",shareWeb];
                    [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:ShareTitle image:nil location:nil urlResource:resource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                        if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                            
                            [self SuccessMBProgressView:@"分享新浪微博成功"];
                        }
                    }];
                }
                    
                    break;
                default:
                    break;
            }
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    }WithprogressBlock:^(double progress) {
        
        if (progress >= 1) {
            
            if ([self.delegate respondsToSelector:@selector(UploadImageSuccess)]) {
                
                [self.delegate UploadImageSuccess];
            }
            
        }else
        {
            if ([self.delegate respondsToSelector:@selector(UploadImageProgress:)]) {
                
                [self.delegate UploadImageProgress:progress];
            }
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(NSError *error) {
        
        if ([self.delegate respondsToSelector:@selector(UploadImageFailue)]) {
            
            [self.delegate UploadImageFailue];
        }
        [self ErrorMBProgressView:error.localizedDescription];
    }];
}



@end
