Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,14 @@
//
// IFishVideoPalyViewController.h
// Ifish
//
// Created by imac on 2017/5/24.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "ClearNavBaseViewController.h"
@interface IFishVideoPalyViewController : ClearNavBaseViewController
@property (nonatomic, strong) NSString *videoPath;
@end
@@ -0,0 +1,180 @@
//
// IFishVideoPalyViewController.m
// Ifish
//
// Created by imac on 2017/5/24.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IFishVideoPalyViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "SVProgressHUD.h"
@interface IFishVideoPalyViewController ()
@property (nonatomic,strong) MPMoviePlayerController *moviePlayer;//视频播放控制器
@property (nonatomic,strong) UIView * coverView;
@end
@implementation IFishVideoPalyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//[self creatPalyer];
self.view.backgroundColor= [UIColor colorWithPatternImage:[UIImage imageNamed:@"enter_background"]];
//播放
[self.moviePlayer play];
[self addNotification];
[self.view bringSubviewToFront:self.coverView];
[SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeNone];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[SVProgressHUD dismiss];
}
-(void)initNav{
self.bakbutton = [UIButton buttonWithType:UIButtonTypeCustom];
self.bakbutton.frame = CGRectMake(0,0,48,44);
[self.bakbutton setImage:[UIImage imageNamed:@"arrow_b"] forState:UIControlStateNormal];
[self.bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
self.back=[[UIBarButtonItem alloc] initWithCustomView:self.bakbutton];
self.navigationItem.leftBarButtonItem=self.back;
}
/**
* 取得本地文件路径
*
* @return 文件路径
*/
-(NSURL *)getFileUrl
{
NSURL *url=[NSURL fileURLWithPath:self.videoPath];
return url;
}
/**
* 取得网络文件路径
*
* @return 文件路径
*/
-(NSURL *)getNetworkUrl{
NSString *urlStr = self.videoPath;
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
return url;
}
-(MPMoviePlayerController *)moviePlayer{
NSURL *url = nil;
if (!_moviePlayer) {
//字条串是否包含有某字符串
if ([self.videoPath rangeOfString:@"http"].location == NSNotFound) {
//本地连接
url = [self getFileUrl];
}else{
//网络链接
url = [self getNetworkUrl];
}
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
//_moviePlayer.view.frame = CGRectMake(0,kScreenSize.height/2 - kScreenSize.width*0.75/2, kScreenSize.width, kScreenSize.width*0.75);
_moviePlayer.view.frame = CGRectMake(0, self.view.frame.size.height/2 - self.view.frame.size.width*0.75/2, self.view.frame.size.width, self.view.frame.size.height);
_moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_moviePlayer.view];
}
return _moviePlayer;
}
-(UIView *)coverView{
//视频录制为全凭录制展示录制窗口试图 裁剪方法行不通这里加coverView遮挡下半部分视频
if (!_coverView) {
_coverView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height/2 + self.view.frame.size.width*0.75/2 , self.view.frame.size.width, self.view.frame.size.height)];
_coverView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"enter_background"]];;
[self.view addSubview:_coverView];
}
return _coverView;
}
/**
* 添加通知监控媒体播放控制器状态
*/
-(void)addNotification{
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];
[notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
}
-(void)mediaPlayerPlaybackStateChange:(NSNotification *)notification{
switch (self.moviePlayer.playbackState) {
case MPMoviePlaybackStatePlaying:
NSLog(@"正在播放...");
[SVProgressHUD dismiss];
break;
case MPMoviePlaybackStatePaused:
NSLog(@"暂停播放.");
break;
case MPMoviePlaybackStateStopped:
NSLog(@"停止播放.");
break;
default:
NSLog(@"播放状态:%li",(long)self.moviePlayer.playbackState);
break;
}
}
-(void)mediaPlayerPlaybackFinished:(NSNotification *)notification{
NSLog(@"播放完成.%li",(long)self.moviePlayer.playbackState);
[self.moviePlayer play];
}
-(void)dealloc{
//移除所有通知监控
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)goBackAction{
[self.moviePlayer stop];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
@@ -0,0 +1,23 @@
//
// ShopAddGoodsViewController.h
// Ifish
//
// Created by imac on 2017/5/17.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "WhiteNavBaseViewController.h"
#import "IfishVideoModel.h"
#import "ShopGoodsListData.h"
typedef NS_ENUM(NSInteger,ShopGoodsEditeType){
ShopGoodsEditeTypeNew = 0,
ShopGoodsEditeTypeUpDate = 1
};
@interface ShopAddGoodsViewController : WhiteNavBaseViewController
@property (nonatomic) ShopGoodsEditeType viewType;
@property (nonatomic,strong) IfishVideoModel *videoModel;
@property (nonatomic,strong) ShopGoodsListData *listData;
@end
@@ -0,0 +1,419 @@
//
// ShopAddGoodsViewController.m
// Ifish
//
// Created by imac on 2017/5/17.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "ShopAddGoodsViewController.h"
#import "VideoEditeVideoCell.h"
#import "VideoEditeNameViewCell.h"
#import "IfishShopGoodsVideoRecordViewController.h"
#define GOODS_CELLTAG 111000111
#import "CertificationShopModel.h"
#import "MBProgressHUD.h"
#import "LXCompressionVideo.h"
#import "IFishVideoPalyViewController.h"
@interface ShopAddGoodsViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,MBProgressHUDDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) MBProgressHUD *hud;
@property (nonatomic) BOOL isNewed;//是否提交新加商品
@end
@implementation ShopAddGoodsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_isNewed = NO;
self.viewType==0?[self addTitleViewWithTitle:@"新增商品"]:[self addTitleViewWithTitle:@"编辑商品"];
UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStyleDone target:self action:@selector(tijiaoAction)];
self.navigationItem.rightBarButtonItem= rightItem;
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[self creatTab];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)goBackAction{
if (_viewType==0) {
if (_isNewed) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}else{
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"商品信息还未提交,是否退出?" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:ac animated:YES completion:nil];
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
}]];
[ac addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
[self clearLocalVideoInfo];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}]];
}
}else{
[self.navigationController popViewControllerAnimated:YES];
}
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
VideoEditeVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VideoEditeVideoCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"VideoEditeVideoCell" owner:self options:nil]lastObject];
}
if (_viewType ==0) {
//新加
if (self.videoModel) {
[cell addImgWithViewTypeNew:self.videoModel];
}
}else{
//修改
if (self.listData) {
[cell addImgWithViewTypeUpDate:self.listData];
}
}
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playVideo)];
cell.videoShotImg.userInteractionEnabled = YES;
[cell.videoShotImg addGestureRecognizer:tap];
cell.videoStartImg.userInteractionEnabled = YES;
[cell.videoStartImg addGestureRecognizer:tap];
return cell;
}
VideoEditeNameViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VideoEditeNameViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"VideoEditeNameViewCell" owner:self options:nil]lastObject];
}
cell.tag = GOODS_CELLTAG ;
cell.goodsNameTextView.delegate = self;
if (_viewType==1) {
cell.goodsNameTextView.text = self.listData.commodityName;
[cell.holderLabel setHidden:YES];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
return kScreenSize.width* 0.75;
}
return 136;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *header = [[UIView alloc] init];
header.backgroundColor = RGB(242, 242, 242);
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section==1) {
return 10;
}
return 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark--UITextViewDelegate
// 设置textView的默认提示文字
-(void)textViewDidChange:(UITextView *)textView{
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
if (textView.text.length ==0) {
[cell.holderLabel setHidden:NO];
}else{
[cell.holderLabel setHidden:YES];
}
}
-(void)textViewDidBeginEditing:(UITextView *)textView{
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
[cell.holderLabel setHidden:YES];
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
if (textView ==cell.goodsNameTextView){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goodsNameTextViewkeyboradWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
return YES;
}
-(void)goodsNameTextViewkeyboradWillShow:(NSNotification *)notification
{
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
CGRect QianMingViewRect = [cell.goodsNameTextView convertRect:cell.goodsNameTextView.bounds toView:self.view];
CGFloat offset = (QianMingViewRect.origin.y+QianMingViewRect.size.height+INTERVAL_KEYBOARD) - (self.tableView.frame.size.height - kbHeight);
double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
if(offset > 0) {
[UIView animateWithDuration:duration animations:^{
self.view.frame = CGRectMake(0.0f, -offset , self.view.frame.size.width, self.view.frame.size.height);
}];
}
}
//键盘消失事件
- (void)keyboardWillHide:(NSNotification *)notify {
// 键盘动画时间
double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//视图下沉恢复原状
[UIView animateWithDuration:duration animations:^{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}];
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
[textView resignFirstResponder];
return YES;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if ([text isEqualToString:@"\n"]) {
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
if (textView == cell.goodsNameTextView) {
if (textView.text.length ==0) {
[cell.holderLabel setHidden:NO];
}else{
[cell.holderLabel setHidden:YES];
}
[cell.goodsNameTextView resignFirstResponder];
}
return NO;
}
return YES;
}
#pragma mark - 视频 paly
-(void)playVideo{
IFishVideoPalyViewController *palyvc= [[IFishVideoPalyViewController alloc] init];
if (_viewType ==0) {
//播放本地视频
palyvc.videoPath = self.videoModel.videoAbsolutePath;
}else{
//播放网络视频
palyvc.videoPath = self.listData.commodityVideo;
}
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:palyvc];
[self presentViewController:nav animated:YES completion:nil];
}
#pragma mark - 提交
-(void)tijiaoAction
{
VideoEditeNameViewCell *cell =[self.view viewWithTag:GOODS_CELLTAG];
if (cell.goodsNameTextView.text.length==0) {
[self.view makeToast:@"请输入商品名"];
return;
}
if (cell.goodsNameTextView.text.length>15) {
[self.view makeToast:@"商品名不能超过15字"];
return;
}
CertificationShopModel *shopsInfo= [[DataCenter defaultDtacenter] valueForKey:@"ShopsInfo"];
NSString *userId = [dataContorl dataControlGetUserIdInfo];
_hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
_hud.delegate=self;
if (_viewType==0) {
[self newCreatGoods:shopsInfo.shopsId userId:userId goodsName:cell.goodsNameTextView.text];
}else{
//修改
NSString *commodityId = [NSString stringWithFormat:@"%@",_listData.commodityId];
[self updateGoodsInfo:shopsInfo.shopsId userId:userId goodsName:cell.goodsNameTextView.text commodityId:commodityId];
}
}
#pragma amrk - 新加商品
-(void)newCreatGoods:(NSString *)shopId userId:(NSString *)userId goodsName:(NSString *)goodsName
{
NSData *shotimgData;
NSData *videodata;
//新加
NSString *imgfilePath = self.videoModel.thumAbsolutePath;
UIImage * shotImage = [UIImage imageWithContentsOfFile:imgfilePath];
shotimgData = [self imageConversationDataWith:shotImage];
videodata = [self videoDataPath:self.videoModel.videoAbsolutePath];
[AFHttpTool createCommodity:shopId userId:userId commodityName:goodsName imgpath:imgfilePath mediapath:self.videoModel.videoAbsolutePath success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
[_hud hide:YES];
NSLog(@"redic:%@",reDic);
if ([reDic[@"result"] isEqualToString:@"100"]){
[self.view makeToast:@"商品添加成功"];
_isNewed = YES;
NSDictionary *dataDic = reDic[@"data"];
ShopGoodsListData *data = [[ShopGoodsListData alloc] initWithDict:dataDic];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NewshopGoodsAdd" object:data];
[self clearLocalVideoInfo];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(popCurrenView) userInfo:nil repeats:NO];
}else{
[self.view makeToast:@"商品添加失败请重试"];
}
} failure:^(NSError *err) {
[self.view makeToast:@"商品添加失败请重试"];
[_hud hide:YES];
}];
}
#pragma mark - 修改商品
-(void)updateGoodsInfo:(NSString *)shopId userId:(NSString *)userId goodsName:(NSString *)goodsName commodityId:(NSString *)commodityId
{
__weak typeof (self)weskSelf=self;
[AFHttpTool updateCommodity:shopId userId:userId commodityName:goodsName commodityId:commodityId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
[_hud hide:YES];
if ([reDic[@"result"] isEqualToString:@"100"]){
[weskSelf.view makeToast:@"修改成功"];
NSDictionary *dataDic = reDic[@"data"];
ShopGoodsListData *data = [[ShopGoodsListData alloc] initWithDict:dataDic];
[[NSNotificationCenter defaultCenter] postNotificationName:@"shopGoodsDataDidChange" object:data];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(popCurrenView) userInfo:nil repeats:NO];
}else{
[weskSelf.view makeToast:@"请求失败"];
}
} failure:^(NSError *err) {
[_hud hide:YES];
[weskSelf.view makeToast:@"请求异常"];
}];
}
- (NSData *)imageConversationDataWith:(UIImage *)image {
NSData *data;
if (UIImagePNGRepresentation(image)) {
// png图像。
data = UIImagePNGRepresentation(image);
}else {
// JPEG图像。
data = UIImageJPEGRepresentation(image, 1);
}
return data;
}
-(NSData *)videoDataPath:(NSString *)path{
NSData *data;
data = [NSData dataWithContentsOfFile:path];
return data;
}
#pragma mark - 清除视频 和 截图
-(void)clearLocalVideoInfo{
[LXCompressionVideo removeAllShotImages];
[LXCompressionVideo removeCompressedVideoFromDocuments];
}
-(void)popCurrenView{
if (_viewType ==0) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}else{
[self.navigationController popViewControllerAnimated:YES];
}
}
@end
@@ -0,0 +1,14 @@
//
// ShopGoodsManageViewController.h
// Ifish
//
// Created by imac on 2017/4/27.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "WhiteNavBaseViewController.h"
@interface ShopGoodsManageViewController : WhiteNavBaseViewController
@property (nonatomic,strong) NSString *shopID;
@end
@@ -0,0 +1,350 @@
//
// ShopGoodsManageViewController.m
// Ifish
//
// Created by imac on 2017/4/27.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "ShopGoodsManageViewController.h"
#import "ShopGoodsListViewCell.h"
#import "ShopGoodsListData.h"
#import "ShopAddGoodsViewController.h"
#import "JHRefresh.h"
#import "IfishShopGoodsVideoRecordViewController.h"
#import "MBProgressHUD.h"
@interface ShopGoodsManageViewController ()<UITableViewDelegate,UITableViewDataSource,MBProgressHUDDelegate>
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) UIView *noDataView;
@property(nonatomic,strong) NSMutableArray *dataArr;
@property(nonatomic,copy) NSString* total;
@property(nonatomic)BOOL isLoadMore;
@property(nonatomic) int page;
@property(nonatomic) BOOL isUpdate;
@property (nonatomic) NSInteger editeIndex;
@property (nonatomic,strong) MBProgressHUD *hud;
@end
@implementation ShopGoodsManageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"商品管理"];
_dataArr = [[NSMutableArray alloc] init];
_page = 0;
_isUpdate = NO;
UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"新增" style:UIBarButtonItemStyleDone target:self action:@selector(addGoodsAction)];
self.navigationItem.rightBarButtonItem= rightItem;
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
_dataArr = [[NSMutableArray alloc] init];
[self initData];
[self creatNodataView];
[self creatTab];
[self creatReatRefreshView];
//修改 商品列表可用FMDB 做缓存处理 减少更新UI麻烦
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shopGoodsDataDidChange:) name:@"shopGoodsDataDidChange" object:nil];
//新加 @"NewshopGoodsAdd"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newshopGoodsAdd:) name:@"NewshopGoodsAdd" object:nil];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_isUpdate) {
if (self.dataArr.count!=0) {
[self removeNoDataState];
}
[self.tableView reloadData];
}
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"shopGoodsDataDidChange" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NewshopGoodsAdd" object:nil];
}
//修改
-(void)shopGoodsDataDidChange:(NSNotification *)noty{
ShopGoodsListData *model=[noty object];
_isUpdate = YES;
[self.dataArr replaceObjectAtIndex:_editeIndex withObject:model];
}
//新加
-(void)newshopGoodsAdd:(NSNotification *)noty{
ShopGoodsListData *model=[noty object];
_isUpdate = YES;
[self.dataArr insertObject:model atIndex:0];
}
-(void)initData{
_hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
_hud.delegate=self;
NSInteger first = 0;
[self loadpageData:first isRefresh:NO];
}
-(void)loadpageData:(NSInteger)firstResult isRefresh:(BOOL)isRefresh{
[self addTaskWithfirsStr:firstResult pageSize:20 isRefresh:NO];
}
-(void)creatReatRefreshView{
__weak typeof (self)weskSelf=self;
//上拉加载更多
[weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
if (weskSelf.isLoadMore) {
return ;
}
weskSelf.isLoadMore=YES;
NSInteger pagecount =[_total integerValue]/20 + 1;
if (_page<pagecount-1) {
_page++;
//firstResult 服务器返回数据知道总数total 获取分页数据 暂不需要
NSInteger first=(NSInteger)_page*20 ;
NSInteger pageSize= 20 ;
[weskSelf addTaskWithfirsStr:first pageSize:pageSize isRefresh:NO];
}else{
[weskSelf endRefreshing];
[weskSelf.view makeToast:@"已无更多数据"];
}
}];
}
-(void)endRefreshing{
if (self.isLoadMore) {
self.isLoadMore=NO;
[self.tableView footerEndRefreshing];
}
}
-(void)addTaskWithfirsStr:(NSInteger)firsStr pageSize:(NSInteger)pageSize isRefresh:(BOOL)isRefresh{
__weak typeof (self)weskSelf=self;
[AFHttpTool getCommodityInfoByPage:self.shopID pageSize:pageSize firstResult:firsStr commodityState:@"0" success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
_total = [reDic objectForKey:@"total"];
NSArray *daA =reDic[@"data"];
for (NSDictionary *dic in daA) {
ShopGoodsListData *data = [[ShopGoodsListData alloc] initWithDict:dic];
[_dataArr addObject:data];
}
if (daA&&![daA isKindOfClass:[NSNull class]]) {
//dataArr = [[NSArray alloc] init];
if ([daA count]!=0) {
[weskSelf.tableView reloadData];
}else{
[weskSelf resetNoDataState];
}
}
}else{
[weskSelf.view makeToast:@"请求失败"];
}
[_hud hide:YES];
} failure:^(NSError *err) {
[_hud hide:YES];
[weskSelf.view makeToast:@"请求异常"];
}];
}
-(void)resetNoDataState{
self.tableView.hidden =YES;
self.noDataView.hidden = NO;
}
-(void)creatNodataView{
UIView *nodataView = [[UIView alloc] initWithFrame:CGRectMake(0, 64,kScreenSize.width, kScreenSize.height)];
self.noDataView = nodataView;
self.noDataView.backgroundColor =TABLE_BACKGROUD_COLOR;
[self.view addSubview:self.noDataView];
UIImageView *backImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 98/2 ,self.view.frame.size.height/4, 108, 98)];
backImg.image = [UIImage imageNamed:@"nurse_empty_picture"];
[self.noDataView addSubview:backImg];
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backImg.frame) + 30, self.view.frame.size.width,20)];
title.text = @"还里空空如也";
title.textAlignment = NSTextAlignmentCenter;
title.font =[UIFont systemFontOfSize:15];
title.textColor = RGB(51, 51, 51);
[self.noDataView addSubview:title];
UILabel *title2=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame) + 7, self.view.frame.size.width,20)];
title2.text = @"快去右上角新增一个商品吧~";
title2.font =[UIFont systemFontOfSize:12];
title2.textAlignment = NSTextAlignmentCenter;
title2.textColor = RGB(153, 153, 153);
[self.noDataView addSubview:title2];
}
-(void)removeNoDataState{
self.tableView.hidden =NO;
self.noDataView.hidden = YES;
[self.view bringSubviewToFront:self.tableView];
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,64,self.view.frame.size.width,self.view.frame.size.height-64) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR;
[self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _dataArr.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.dataArr ==0) {
[self resetNoDataState];
}
ShopGoodsListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopGoodsListViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle]loadNibNamed:@"ShopGoodsListViewCell" owner:self options:nil]lastObject];
}
ShopGoodsListData *data = self.dataArr[indexPath.row];
[cell loadCellDataWith:data];
cell.eduteBtn.tag = indexPath.row;
[cell.eduteBtn addTarget:self action:@selector(editeAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 106.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 1.0;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
_hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
_hud.delegate=self;
[self listdataRemoveAt:indexPath];
}
}
#pragma mark 删除商品
-(void)listdataRemoveAt:(NSIndexPath *)indexPath
{
ShopGoodsListData *data = _dataArr[indexPath.row];
__weak typeof (self)weskSelf=self;
[AFHttpTool deleteCommodityById:data.commodityId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
[weskSelf.dataArr removeObjectAtIndex:indexPath.row];
[weskSelf.tableView reloadData];
if (weskSelf.dataArr.count==0) {
[weskSelf removeNoDataState];
}
}else{
[weskSelf.view makeToast:@"删除失败"];
}
[_hud hide:YES];
} failure:^(NSError *err) {
[_hud hide:YES];
[weskSelf.view makeToast:@"请求异常"];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 前往新增
-(void)addGoodsAction
{
IfishShopGoodsVideoRecordViewController *recordVC=[[IfishShopGoodsVideoRecordViewController alloc] init];
[self.navigationController pushViewController:recordVC animated:YES];
}
#pragma mark - 编辑
-(void)editeAction:(UIButton *)btn{
ShopGoodsListData *data = self.dataArr[btn.tag];
_editeIndex = btn.tag;
ShopAddGoodsViewController *shopEditeVC = [[ShopAddGoodsViewController alloc] init];
shopEditeVC.viewType = 1;
shopEditeVC.listData= data;
[self.navigationController pushViewController:shopEditeVC animated:YES];
}
/*
#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