// // QXMineSongListViewController.m // QXLive // // Created by 启星 on 2025/11/13. // #import "QXMineSongListViewController.h" #import "QXMineNetwork.h" #import "QXMineSongListCell.h" #import "QXMineAddSongView.h" #import "QXMineAddSongGiftView.h" #import "QXCustomAlertView.h" @interface QXMineSongListViewController () @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)UILabel *countLabel; @property (nonatomic,strong)QXMineAddSongView *addSongView; @end @implementation QXMineSongListViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } -(void)setNavgationItems{ [super setNavgationItems];; self.navigationItem.title = @"歌单列表"; UIButton*recordBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; [recordBtn setTitle:QXText(@"新增") forState:(UIControlStateNormal)]; [recordBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)]; recordBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [recordBtn addTarget:self action:@selector(addAction) forControlEvents:(UIControlEventTouchUpInside)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:recordBtn]; } -(void)initSubViews{ self.page = 1; self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, NavContentHeight+12, 200, 35)]; self.countLabel.textColor = RGB16(0x666666); self.countLabel.font = [UIFont systemFontOfSize:12]; self.countLabel.text = @"共0首歌"; [self.view addSubview:self.countLabel]; UIButton*recordBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.width-35-16, NavContentHeight+12, 35, 35)]; [recordBtn setImage:[[UIImage imageNamed:@"nobility_help_icon"] imageByTintColor:RGB16(0x666666)] forState:(UIControlStateNormal)]; recordBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [recordBtn addTarget:self action:@selector(helpAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.view addSubview:recordBtn]; [self.view addSubview:self.tableView]; [self getSongList]; } -(void)getSongList{ MJWeakSelf [QXMineNetwork getUserSongListWithRoomId:@"" user_id:QXGlobal.shareGlobal.loginModel.user_id page:self.page SuccessBlock:^(NSArray * _Nonnull list, NSString * _Nonnull count) { weakSelf.countLabel.text = [NSString stringWithFormat:@"共有%@首歌",count]; if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.tableView reloadData]; [weakSelf.tableView.mj_header endRefreshing]; if (list.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_header endRefreshing]; } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)helpAction{ NSString *urlString = [NSString stringWithFormat:@"%@api/Page/page_show?id=%@",ServerUrl,@"34"]; QXBaseWebViewController *vc = [[QXBaseWebViewController alloc] init]; vc.urlStr = urlString; [self.navigationController pushViewController:vc animated:YES]; } -(void)didSeletedGift:(QXGiftModel *)giftModel giftCount:(nonnull NSString *)giftCount{ giftModel.num = giftCount; self.addSongView.giftModel = giftModel; } -(void)qx_mineAddSongViewDidSeleteGift{ QXMineAddSongGiftView *giftView = [[QXMineAddSongGiftView alloc] initWithFrame:[UIScreen mainScreen].bounds]; giftView.delegate = self; [giftView showInView:self.view]; } -(void)qx_mineAddSongViewCommitWithSongName:(NSString *)songName giftModel:(QXGiftModel *)giftModel{ MJWeakSelf [QXMineNetwork mineUserAddAndDeleteAndEditWithType:0 Id:@"" songName:songName giftId:giftModel.gift_id giftNum:giftModel.num successBlock:^(NSDictionary * _Nonnull dict) { showToast(@"添加成功"); [weakSelf.addSongView hide]; weakSelf.page = 1; [weakSelf getSongList]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(@"添加失败"); }]; } -(void)qx_mineAddSongViewDidRemove{ self.addSongView = nil; } -(void)qx_mineEditSongViewCommitWithSongModel:(QXUserSongListModel *)songModel{ MJWeakSelf [QXMineNetwork mineUserAddAndDeleteAndEditWithType:1 Id:songModel.id songName:songModel.song_name giftId:songModel.gift_id giftNum:songModel.gift_num successBlock:^(NSDictionary * _Nonnull dict) { showToast(@"修改成功"); [weakSelf.addSongView hide]; weakSelf.page = 1; [weakSelf getSongList]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(@"修改失败"); }]; } -(void)addAction{ self.addSongView = [[QXMineAddSongView alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.addSongView.delegate = self; [self.addSongView showInView:self.view]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXMineSongListCell *cell = [QXMineSongListCell cellWithTableView:tableView]; cell.model = self.dataArray[indexPath.row]; return cell; } -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } -(UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath{ QXUserSongListModel *model = self.dataArray[indexPath.row]; MJWeakSelf UIContextualAction *deletAction = [UIContextualAction contextualActionWithStyle:(UIContextualActionStyleDestructive) title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf deleteSongWithModel:model]; completionHandler(YES); }]; UIContextualAction *editAction = [UIContextualAction contextualActionWithStyle:(UIContextualActionStyleNormal) title:@"编辑" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf editSongWithModel:model]; completionHandler(YES); }]; editAction.backgroundColor = RGB16(0x3665F9); UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deletAction,editAction]]; return config; } -(void)deleteSongWithModel:(QXUserSongListModel*)model{ QXCustomAlertView *alertView = [[QXCustomAlertView alloc] init]; [alertView showInView:self.view title:@"您确定要删除歌曲吗" message:[NSString stringWithFormat:@"歌曲名称:%@\n礼物信息:%@ x%@",model.song_name,model.gift_name,model.gift_num] cancleTitle:@"取消" commitTitle:@"确定"]; MJWeakSelf alertView.commitBlock = ^{ [QXMineNetwork mineUserAddAndDeleteAndEditWithType:2 Id:model.id songName:model.song_name giftId:model.gift_id giftNum:model.gift_num successBlock:^(NSDictionary * _Nonnull dict) { showToast(@"删除成功"); weakSelf.page = 1; [weakSelf getSongList]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(@"删除失败"); }]; }; } -(void)editSongWithModel:(QXUserSongListModel*)model{ self.addSongView = [[QXMineAddSongView alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.addSongView.delegate = self; self.addSongView.songModel = model; [self.addSongView showInView:self.view]; } -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(16, self.countLabel.bottom+5, SCREEN_WIDTH-32, SCREEN_HEIGHT-NavContentHeight) style:(UITableViewStylePlain)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.backgroundColor = [UIColor whiteColor]; [_tableView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; _tableView.rowHeight = 45; // _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } else { // Fallback on earlier versions } MJWeakSelf _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; [weakSelf getSongList]; }]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getSongList]; }]; } return _tableView; } @end