// // YOUPAIMessafeTemplateListVC.m // MSYOUPAI // // Created by admin on 2022/3/11. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAIMessafeTemplateListVC.h" #import "YOUPAIMessafeTemplateListCell.h" #import "YOUPAIMessageTemplateEdit.h" #import "YOUPAIMessageTemplate.h" #import "YOUPAIMessageTemplateName.h" #import "UIViewController+TFPresent.h" #import "YYKit.h" #import "UIViewController+YOUPAIAlert.h" #import "UIViewController+YOUPAIYBImageBrowser.h" #import "UIViewController+YOUPAIVideo.h" #import "UIViewController+YOUPAIVoice.h" @interface YOUPAIMessafeTemplateListVC () @property(strong, nonatomic) UITableView *ypupaipTableView; @property(strong, nonatomic) UIButton * youpaipCreateBtn; @property(strong, nonatomic) NSMutableArray *ypupaipDataSouce; @end @implementation YOUPAIMessafeTemplateListVC -(UITableView *)ypupaipTableView{ if(_ypupaipTableView == nil){ _ypupaipTableView = [[UITableView alloc] init]; _ypupaipTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _ypupaipTableView.backgroundColor = UIColor.clearColor; _ypupaipTableView.delegate = self; _ypupaipTableView.dataSource = self; [_ypupaipTableView registerClass:[YOUPAIMessafeTemplateListCell class] forCellReuseIdentifier:@"YOUPAIMessafeTemplateListCell"]; } return _ypupaipTableView; } -(UIButton *)youpaipCreateBtn{ if(_youpaipCreateBtn == nil){ _youpaipCreateBtn = [UIButton new]; [_youpaipCreateBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(280, 49) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1] forState:UIControlStateNormal]; [_youpaipCreateBtn setTitle:@"新建模板" forState:UIControlStateNormal]; [_youpaipCreateBtn ms_radius:24]; [_youpaipCreateBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; @weakify(self) [_youpaipCreateBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) YOUPAIMessageTemplateEdit *vc = [YOUPAIMessageTemplateEdit new]; [self.navigationController pushViewController:vc animated:true]; }]; } return _youpaipCreateBtn; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"打招呼设置"; self.view.backgroundColor = LZFAFAFCColor; [self youpaiMakeUI]; [self youpaiMakeLayout]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self youpaifloadData]; } -(void)youpaiMakeUI{ [self.view addSubview:self.ypupaipTableView]; [self.view addSubview:self.youpaipCreateBtn]; } -(void)youpaiMakeLayout{ [_ypupaipTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(NavBarHeight); make.left.right.mas_equalTo(0); make.bottom.mas_equalTo(self.youpaipCreateBtn.mas_top).offset(-2); }]; [_youpaipCreateBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(0); make.bottom.mas_offset(-SafeHeight); make.size.mas_equalTo(CGSizeMake(280, 49)); }]; } -(void)youpaifloadData{ @weakify(self); [ZCHUDHelper showWithStatus:@"请稍后..."]; [LCHttpHelper requestWithURLString:api_greetlists_new parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSString *code = responseObject[@"code"]; NSString *msg = responseObject[@"message"]; if ( code.intValue == 0){ [ZCHUDHelper dismiss]; NSDictionary *data = responseObject[@"data"]; // NSInteger count = data[@"count"]; NSArray* list = data[@"list"]; self.ypupaipDataSouce = [YOUPAIMessageTemplate mj_objectArrayWithKeyValuesArray:list]; [self.ypupaipTableView reloadData]; if (self.ypupaipDataSouce.count != 0) { [self.ypupaipTableView lz_hideEmptyView]; }else{ [self.ypupaipTableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"添加自定义打招呼\n会优先推荐给男用户哦~"]; } }else{ [ZCHUDHelper showTitle:msg]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:@"失败"]; }]; } // MARK: 删除模版 -(void)youpaifDeleteTemplate:(NSInteger)index{ @weakify(self); [ZCHUDHelper showWithStatus:@"请稍后..."]; YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index]; NSDictionary *param = @{@"id":celldata.id}; [LCHttpHelper requestWithURLString:api_greetdelete_new parameters:param needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSString *code = responseObject[@"code"]; if (code.integerValue == 0){ [ZCHUDHelper dismiss]; [self youpaifloadData]; }else{ NSString *msg = responseObject[@"message"]; [ZCHUDHelper showTitle:msg]; } } failure:^(NSError *error) { [ZCHUDHelper dismiss]; [ZCHUDHelper showTitle:@"失败"]; }]; } // MARK: 设置为默认模版 -(void)youpaifsetDefualTemplate:(NSInteger)index{ @weakify(self); YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index]; [ZCHUDHelper showWithStatus:@"请稍后..."]; [LCHttpHelper requestWithURLString:api_greetset_default parameters:@{@"id":celldata.id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSString *code = responseObject[@"code"]; if (code.integerValue == 0){ [ZCHUDHelper dismiss]; [self youpaifloadData]; }else{ NSString *msg = responseObject[@"message"]; [ZCHUDHelper showTitle:msg]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:@"失败"]; }]; } // MARK: 修改模版名 -(void)youpaifsetTemplateName:(NSInteger)index name:(NSString*)name{ @weakify(self); YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index]; NSDictionary *params = @{ @"id":celldata.id, @"name":name }; [ZCHUDHelper showWithStatus:@"请稍后..."]; [LCHttpHelper requestWithURLString:api_greetset_name parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSString *code = responseObject[@"code"]; if (code.integerValue == 0){ [ZCHUDHelper dismiss]; [self youpaifloadData]; }else{ NSString *msg = responseObject[@"message"]; [ZCHUDHelper showTitle:msg]; } } failure:^(NSError *error) { [ZCHUDHelper dismiss]; [ZCHUDHelper showTitle:@"失败"]; }]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.ypupaipDataSouce.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIMessafeTemplateListCell *cell = (YOUPAIMessafeTemplateListCell*)[tableView dequeueReusableCellWithIdentifier:@"YOUPAIMessafeTemplateListCell" forIndexPath:indexPath]; YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:indexPath.row]; // 审核状态:0=审核中,1=审核通过,2=审核不通过 展开 if (celldata.status.integerValue == 0){ [cell.youpaipeditBtn setHidden:true]; [cell.youpaipdeleteBtn setHidden:true]; [cell.youpaipselectBtn setHidden:true]; [cell.youpaipstateImageView setHidden:false]; cell.youpaipstateImageView.image = [UIImage imageNamed:@"icon_messagetemplate_inreview"]; }else if(celldata.status.integerValue == 1){ [cell.youpaipeditBtn setHidden:false]; [cell.youpaipdeleteBtn setHidden:false]; [cell.youpaipselectBtn setHidden:false]; [cell.youpaipstateImageView setHidden:true]; }else if(celldata.status.integerValue == 2){ [cell.youpaipeditBtn setHidden:false]; [cell.youpaipdeleteBtn setHidden:false]; [cell.youpaipselectBtn setHidden:false]; [cell.youpaipstateImageView setHidden:false]; cell.youpaipstateImageView.image = [UIImage imageNamed:@"icon_messagetemplate_reviewfailure"]; } [cell.youpaipselectBtn setSelected:celldata.is_default.boolValue]; [cell.youpaipselectBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:4]; if (celldata.name.length>0){ cell.youpaiptitleLab.text = celldata.name; }else{ cell.youpaiptitleLab.text = @"我的模版"; } cell.youpaiptextLab.text = celldata.title; if (celldata.file.length>0){ NSURL *imgurl = [LCTools getImageUrlWithAddress:celldata.file]; [cell.youpaipimgView sd_setImageWithURL:imgurl]; [cell.youpaipimgView setHidden:false]; }else{ [cell.youpaipimgView setHidden:true]; } if (celldata.video_file.length>0){ NSURL *videourl = [LCTools getImageUrlWithAddress:celldata.video_file]; cell.youpaipvideoView.image = [UIImage imageWithVideo:videourl]; [cell.youpaipvideoView setHidden:false]; }else{ [cell.youpaipvideoView setHidden:true]; } if (celldata.voice_file.length>0){ cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%@”",celldata.len];; [cell.youpaipvoiceView setHidden:false]; }else{ [cell.youpaipvoiceView setHidden:true]; } cell.backgroundColor = UIColor.clearColor; @weakify(self) // 编辑 [cell.youpaipeditBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) YOUPAIMessageTemplateName *VC= [[YOUPAIMessageTemplateName alloc]init]; VC.vWidth = KScreenWidth -68; VC.vHeight = ScaleHeight(223); [VC setCommitBlock:^(YOUPAIMessageTemplateName * _Nonnull view) { [self youpaifsetTemplateName:indexPath.row name:view.youpaiptextField.text]; }]; [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{ }]; }]; // 删除 [cell.youpaipdeleteBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) [self youpaifAlertWithTitle:nil content:@"确定删除当前模板?" cancelBtn:@"取消" confimBtn:@"确定" confimBlock:^{ [self youpaifDeleteTemplate:indexPath.row]; }]; }]; // 设为默认 [cell.youpaipselectBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) { @strongify(self) [self youpaifsetDefualTemplate:indexPath.row]; }]; // 查看大图 [cell.youpaipimgView setUserInteractionEnabled:true]; [cell.youpaipimgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { @strongify(self) [self youpaiScanImages:@[celldata.file] currentPage:0 view:nil]; }]]; // 查看视频 [cell.youpaipvideoView setUserInteractionEnabled:true]; [cell.youpaipvideoView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { @strongify(self) NSURL *url = [LCTools getImageUrlWithAddress:celldata.video_file]; [self youpaifAVPlayer:url]; }]]; // 听录音 [cell.youpaipvoiceView setUserInteractionEnabled:true]; [cell.youpaipvoiceView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { @strongify(self) if (celldata.voice_file.length>0){ NSURL *url = [LCTools getImageUrlWithAddress:celldata.voice_file]; [self youpaifvoicePlay:url cutDownblock:^(FSAudioStream * _Nonnull player) { if (player.isPlaying){ FSStreamPosition cur = player.currentTimePlayed; FSStreamPosition end = player.duration; CGFloat loadTime = cur.minute *60 + cur.second; CGFloat endTime = end.minute *60 + end.second; CGFloat show = endTime-loadTime; cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%0.0f”",show]; }else{ cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%@”",celldata.len];; } }]; }else{ NSLog(@"路径错误"); } }]]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 189; } @end