YOUPAIMessafeTemplateListVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // YOUPAIMessafeTemplateListVC.m
  3. // MSYOUPAI
  4. //
  5. // Created by admin on 2022/3/11.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAIMessafeTemplateListVC.h"
  9. #import "YOUPAIMessafeTemplateListCell.h"
  10. #import "YOUPAIMessageTemplateEdit.h"
  11. #import "YOUPAIMessageTemplate.h"
  12. #import "YOUPAIMessageTemplateName.h"
  13. #import "UIViewController+TFPresent.h"
  14. #import "YYKit.h"
  15. #import "UIViewController+YOUPAIAlert.h"
  16. #import "UIViewController+YOUPAIYBImageBrowser.h"
  17. #import "UIViewController+YOUPAIVideo.h"
  18. #import "UIViewController+YOUPAIVoice.h"
  19. @interface YOUPAIMessafeTemplateListVC ()<UITableViewDelegate,UITableViewDataSource>
  20. @property(strong, nonatomic) UITableView *ypupaipTableView;
  21. @property(strong, nonatomic) UIButton * youpaipCreateBtn;
  22. @property(strong, nonatomic) NSMutableArray<YOUPAIMessageTemplate*> *ypupaipDataSouce;
  23. @end
  24. @implementation YOUPAIMessafeTemplateListVC
  25. -(UITableView *)ypupaipTableView{
  26. if(_ypupaipTableView == nil){
  27. _ypupaipTableView = [[UITableView alloc] init];
  28. _ypupaipTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  29. _ypupaipTableView.backgroundColor = UIColor.clearColor;
  30. _ypupaipTableView.delegate = self;
  31. _ypupaipTableView.dataSource = self;
  32. [_ypupaipTableView registerClass:[YOUPAIMessafeTemplateListCell class] forCellReuseIdentifier:@"YOUPAIMessafeTemplateListCell"];
  33. }
  34. return _ypupaipTableView;
  35. }
  36. -(UIButton *)youpaipCreateBtn{
  37. if(_youpaipCreateBtn == nil){
  38. _youpaipCreateBtn = [UIButton new];
  39. [_youpaipCreateBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(280, 49) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1] forState:UIControlStateNormal];
  40. [_youpaipCreateBtn setTitle:@"新建模板" forState:UIControlStateNormal];
  41. [_youpaipCreateBtn ms_radius:24];
  42. [_youpaipCreateBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  43. @weakify(self)
  44. [_youpaipCreateBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  45. @strongify(self)
  46. YOUPAIMessageTemplateEdit *vc = [YOUPAIMessageTemplateEdit new];
  47. [self.navigationController pushViewController:vc animated:true];
  48. }];
  49. }
  50. return _youpaipCreateBtn;
  51. }
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. self.title = @"打招呼设置";
  55. self.view.backgroundColor = LZFAFAFCColor;
  56. [self youpaiMakeUI];
  57. [self youpaiMakeLayout];
  58. }
  59. -(void)viewWillAppear:(BOOL)animated{
  60. [super viewWillAppear:animated];
  61. [self youpaifloadData];
  62. }
  63. -(void)youpaiMakeUI{
  64. [self.view addSubview:self.ypupaipTableView];
  65. [self.view addSubview:self.youpaipCreateBtn];
  66. }
  67. -(void)youpaiMakeLayout{
  68. [_ypupaipTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.mas_equalTo(NavBarHeight);
  70. make.left.right.mas_equalTo(0);
  71. make.bottom.mas_equalTo(self.youpaipCreateBtn.mas_top).offset(-2);
  72. }];
  73. [_youpaipCreateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.centerX.mas_equalTo(0);
  75. make.bottom.mas_offset(-SafeHeight);
  76. make.size.mas_equalTo(CGSizeMake(280, 49));
  77. }];
  78. }
  79. -(void)youpaifloadData{
  80. @weakify(self);
  81. [ZCHUDHelper showWithStatus:@"请稍后..."];
  82. [LCHttpHelper requestWithURLString:api_greetlists_new parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  83. @strongify(self);
  84. NSString *code = responseObject[@"code"];
  85. NSString *msg = responseObject[@"message"];
  86. if ( code.intValue == 0){
  87. [ZCHUDHelper dismiss];
  88. NSDictionary *data = responseObject[@"data"];
  89. // NSInteger count = data[@"count"];
  90. NSArray* list = data[@"list"];
  91. self.ypupaipDataSouce = [YOUPAIMessageTemplate mj_objectArrayWithKeyValuesArray:list];
  92. [self.ypupaipTableView reloadData];
  93. if (self.ypupaipDataSouce.count != 0) {
  94. [self.ypupaipTableView lz_hideEmptyView];
  95. }else{
  96. [self.ypupaipTableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"添加自定义打招呼\n会优先推荐给男用户哦~"];
  97. }
  98. }else{
  99. [ZCHUDHelper showTitle:msg];
  100. }
  101. } failure:^(NSError *error) {
  102. [ZCHUDHelper showTitle:@"失败"];
  103. }];
  104. }
  105. // MARK: 删除模版
  106. -(void)youpaifDeleteTemplate:(NSInteger)index{
  107. @weakify(self);
  108. [ZCHUDHelper showWithStatus:@"请稍后..."];
  109. YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index];
  110. NSDictionary *param = @{@"id":celldata.id};
  111. [LCHttpHelper requestWithURLString:api_greetdelete_new parameters:param needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  112. @strongify(self);
  113. NSString *code = responseObject[@"code"];
  114. if (code.integerValue == 0){
  115. [ZCHUDHelper dismiss];
  116. [self youpaifloadData];
  117. }else{
  118. NSString *msg = responseObject[@"message"];
  119. [ZCHUDHelper showTitle:msg];
  120. }
  121. } failure:^(NSError *error) {
  122. [ZCHUDHelper dismiss];
  123. [ZCHUDHelper showTitle:@"失败"];
  124. }];
  125. }
  126. // MARK: 设置为默认模版
  127. -(void)youpaifsetDefualTemplate:(NSInteger)index{
  128. @weakify(self);
  129. YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index];
  130. [ZCHUDHelper showWithStatus:@"请稍后..."];
  131. [LCHttpHelper requestWithURLString:api_greetset_default parameters:@{@"id":celldata.id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  132. @strongify(self);
  133. NSString *code = responseObject[@"code"];
  134. if (code.integerValue == 0){
  135. [ZCHUDHelper dismiss];
  136. [self youpaifloadData];
  137. }else{
  138. NSString *msg = responseObject[@"message"];
  139. [ZCHUDHelper showTitle:msg];
  140. }
  141. } failure:^(NSError *error) {
  142. [ZCHUDHelper showTitle:@"失败"];
  143. }];
  144. }
  145. // MARK: 修改模版名
  146. -(void)youpaifsetTemplateName:(NSInteger)index name:(NSString*)name{
  147. @weakify(self);
  148. YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:index];
  149. NSDictionary *params = @{
  150. @"id":celldata.id,
  151. @"name":name
  152. };
  153. [ZCHUDHelper showWithStatus:@"请稍后..."];
  154. [LCHttpHelper requestWithURLString:api_greetset_name parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  155. @strongify(self);
  156. NSString *code = responseObject[@"code"];
  157. if (code.integerValue == 0){
  158. [ZCHUDHelper dismiss];
  159. [self youpaifloadData];
  160. }else{
  161. NSString *msg = responseObject[@"message"];
  162. [ZCHUDHelper showTitle:msg];
  163. }
  164. } failure:^(NSError *error) {
  165. [ZCHUDHelper dismiss];
  166. [ZCHUDHelper showTitle:@"失败"];
  167. }];
  168. }
  169. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  170. return self.ypupaipDataSouce.count;
  171. }
  172. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  173. YOUPAIMessafeTemplateListCell *cell = (YOUPAIMessafeTemplateListCell*)[tableView dequeueReusableCellWithIdentifier:@"YOUPAIMessafeTemplateListCell" forIndexPath:indexPath];
  174. YOUPAIMessageTemplate *celldata = [_ypupaipDataSouce objectAtIndex:indexPath.row];
  175. // 审核状态:0=审核中,1=审核通过,2=审核不通过 展开
  176. if (celldata.status.integerValue == 0){
  177. [cell.youpaipeditBtn setHidden:true];
  178. [cell.youpaipdeleteBtn setHidden:true];
  179. [cell.youpaipselectBtn setHidden:true];
  180. [cell.youpaipstateImageView setHidden:false];
  181. cell.youpaipstateImageView.image = [UIImage imageNamed:@"icon_messagetemplate_inreview"];
  182. }else if(celldata.status.integerValue == 1){
  183. [cell.youpaipeditBtn setHidden:false];
  184. [cell.youpaipdeleteBtn setHidden:false];
  185. [cell.youpaipselectBtn setHidden:false];
  186. [cell.youpaipstateImageView setHidden:true];
  187. }else if(celldata.status.integerValue == 2){
  188. [cell.youpaipeditBtn setHidden:false];
  189. [cell.youpaipdeleteBtn setHidden:false];
  190. [cell.youpaipselectBtn setHidden:false];
  191. [cell.youpaipstateImageView setHidden:false];
  192. cell.youpaipstateImageView.image = [UIImage imageNamed:@"icon_messagetemplate_reviewfailure"];
  193. }
  194. [cell.youpaipselectBtn setSelected:celldata.is_default.boolValue];
  195. [cell.youpaipselectBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:4];
  196. if (celldata.name.length>0){
  197. cell.youpaiptitleLab.text = celldata.name;
  198. }else{
  199. cell.youpaiptitleLab.text = @"我的模版";
  200. }
  201. cell.youpaiptextLab.text = celldata.title;
  202. if (celldata.file.length>0){
  203. NSURL *imgurl = [LCTools getImageUrlWithAddress:celldata.file];
  204. [cell.youpaipimgView sd_setImageWithURL:imgurl];
  205. [cell.youpaipimgView setHidden:false];
  206. }else{
  207. [cell.youpaipimgView setHidden:true];
  208. }
  209. if (celldata.video_file.length>0){
  210. NSURL *videourl = [LCTools getImageUrlWithAddress:celldata.video_file];
  211. cell.youpaipvideoView.image = [UIImage imageWithVideo:videourl];
  212. [cell.youpaipvideoView setHidden:false];
  213. }else{
  214. [cell.youpaipvideoView setHidden:true];
  215. }
  216. if (celldata.voice_file.length>0){
  217. cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%@”",celldata.len];;
  218. [cell.youpaipvoiceView setHidden:false];
  219. }else{
  220. [cell.youpaipvoiceView setHidden:true];
  221. }
  222. cell.backgroundColor = UIColor.clearColor;
  223. @weakify(self)
  224. // 编辑
  225. [cell.youpaipeditBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  226. @strongify(self)
  227. YOUPAIMessageTemplateName *VC= [[YOUPAIMessageTemplateName alloc]init];
  228. VC.vWidth = KScreenWidth -68;
  229. VC.vHeight = ScaleHeight(223);
  230. [VC setCommitBlock:^(YOUPAIMessageTemplateName * _Nonnull view) {
  231. [self youpaifsetTemplateName:indexPath.row name:view.youpaiptextField.text];
  232. }];
  233. [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{
  234. }];
  235. }];
  236. // 删除
  237. [cell.youpaipdeleteBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  238. @strongify(self)
  239. [self youpaifAlertWithTitle:nil content:@"确定删除当前模板?" cancelBtn:@"取消" confimBtn:@"确定" confimBlock:^{
  240. [self youpaifDeleteTemplate:indexPath.row];
  241. }];
  242. }];
  243. // 设为默认
  244. [cell.youpaipselectBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  245. @strongify(self)
  246. [self youpaifsetDefualTemplate:indexPath.row];
  247. }];
  248. // 查看大图
  249. [cell.youpaipimgView setUserInteractionEnabled:true];
  250. [cell.youpaipimgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  251. @strongify(self)
  252. [self youpaiScanImages:@[celldata.file] currentPage:0 view:nil];
  253. }]];
  254. // 查看视频
  255. [cell.youpaipvideoView setUserInteractionEnabled:true];
  256. [cell.youpaipvideoView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  257. @strongify(self)
  258. NSURL *url = [LCTools getImageUrlWithAddress:celldata.video_file];
  259. [self youpaifAVPlayer:url];
  260. }]];
  261. // 听录音
  262. [cell.youpaipvoiceView setUserInteractionEnabled:true];
  263. [cell.youpaipvoiceView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  264. @strongify(self)
  265. if (celldata.voice_file.length>0){
  266. NSURL *url = [LCTools getImageUrlWithAddress:celldata.voice_file];
  267. [self youpaifvoicePlay:url cutDownblock:^(FSAudioStream * _Nonnull player) {
  268. if (player.isPlaying){
  269. FSStreamPosition cur = player.currentTimePlayed;
  270. FSStreamPosition end = player.duration;
  271. CGFloat loadTime = cur.minute *60 + cur.second;
  272. CGFloat endTime = end.minute *60 + end.second;
  273. CGFloat show = endTime-loadTime;
  274. cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%0.0f”",show];
  275. }else{
  276. cell.youpaipvoideCutDownLab.text = [NSString stringWithFormat:@"%@”",celldata.len];;
  277. }
  278. }];
  279. }else{
  280. NSLog(@"路径错误");
  281. }
  282. }]];
  283. return cell;
  284. }
  285. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  286. return 189;
  287. }
  288. @end