123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- //
- // GroupNoticeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/24.
- //
- #import "GroupNoticeViewController.h"
- #import "GroupNoticeCell.h"
- #import "GroupNoticeEditController.h"
- #import "LFPopupMenu.h"
- #import "GroupNoticeModel.h"
- @interface GroupNoticeViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation GroupNoticeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"群公告"];
- [self configUI];
- [self createNavButton];
- }
- - (void)createNavButton {
- if (self.canEdit) {
- [self rightButton:[UIImage imageNamed:@"edit_button"]];
- }
- }
- - (void)rightBtnClick {
- GroupNoticeEditController *eidtVC = [[GroupNoticeEditController alloc] init];
- eidtVC.groupId = self.groupId;
- eidtVC.isModify = NO;
- [self.navigationController pushViewController:eidtVC animated:YES];
- }
- - (void)configUI {
- [self.view addSubview:self.tableView];
- [self setPromptString:@"暂无群公告" imageName:@"wd_img_zwsj" inView:self.tableView];
- MJWeakSelf;
- self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf resetParamenter];
- [weakSelf requestData];
- }];
-
- self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
- if (weakSelf.isLoadMore) {
- weakSelf.pages += 1;
- [weakSelf requestData];
- }
- else {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- }];
- }
- - (void)endRefresh {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- });
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self resetParamenter];
- [self requestData];
- }
- - (void)resetParamenter {
- self.isLoadMore = YES;
- self.pages = 1;
- self.rows = 10;
- self.dataArray = [NSMutableArray array];
- [self.tableView.mj_footer resetNoMoreData];
- [self setPromptString:@"暂无群公告" imageName:@"wd_img_zwsj" inView:self.tableView];
- [self.tableView reloadData];
- }
- - (void)requestData {
- [self showhud];
- [KSNetworkingManager queryNoticeListRequest:KS_POST groupId:self.groupId page:[NSString stringWithFormat:@"%zd", self.pages] rows:[NSString stringWithFormat:@"%zd", self.rows] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- [self endRefresh];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- // 赋值
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- for (NSDictionary *parm in sourceArray) {
- GroupNoticeModel *model = [[GroupNoticeModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
- if (sourceArray.count < self.rows) {
- self.isLoadMore = NO;
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- [self changePromptLabelState];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- [self endRefresh];
- if (self.networkAvaiable == NO) {
- [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
- }
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- [self changePromptLabelState];
- }];
- }
- #pragma mark ---- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- GroupNoticeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupNoticeCell"];
- GroupNoticeModel *model = self.dataArray[indexPath.row];
- MJWeakSelf;
- [cell configWithSource:model enable:self.canEdit callback:^(id _Nonnull sourceModel, UIButton * _Nonnull sender) {
- [weakSelf showPopViewWithSource:sourceModel inView:sender];
- }];
- return cell;
- }
- - (void)showPopViewWithSource:(id)source inView:(UIView *)view {
- GroupNoticeModel *model = source;
- MJWeakSelf;
- LFPopupMenuItem *item1 = [LFPopupMenuItem createWithTitle:@"编辑公告" image:nil action:^{
- // 编辑公告
- [weakSelf editNotice:source];
- }];
- NSString *title = model.top ? @"取消置顶" : @"置顶";
- LFPopupMenuItem *item2 = [LFPopupMenuItem createWithTitle:title image:nil action:^{
- // 置顶或者取消置顶
- [weakSelf operationAction:source];
- }];
- LFPopupMenuItem *item3 = [LFPopupMenuItem createWithTitle:@"删除公告" image:nil action:^{
- // 删除公告
- [weakSelf deleteNotice:source];
- }];
- LFPopupMenu *menu = [[LFPopupMenu alloc] init];
- menu.needBorder = YES;
- menu.rowHeight = 40.0f;
- menu.minWidth = 150;
- menu.textColor = HexRGB(0x333333);
- menu.textFont = [UIFont systemFontOfSize:14.0f];
- [menu configWithItems:@[item1,item2,item3]];
- [menu showArrowToView:view];
- }
- - (void)deleteNotice:(id)source {
- GroupNoticeModel *model = source;
- [self showhud];
- [KSNetworkingManager imGroupNoticeDelRequest:KS_POST noticeID:[NSString stringWithFormat:@"%.0f",model.internalBaseClassIdentifier] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- MJWeakSelf;
- [self KSShowMsg:@"删除成功" promptCompletion:^{
- [weakSelf resetParamenter];
- [weakSelf requestData];
- }];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- - (void)editNotice:(id)source {
- GroupNoticeModel *model = source;
- GroupNoticeEditController *editVC = [[GroupNoticeEditController alloc] init];
- editVC.groupId = self.groupId;
- editVC.isModify = YES;
- editVC.titles = model.title;
- editVC.content = model.content;
- editVC.noticeID = [NSString stringWithFormat:@"%.0f",model.internalBaseClassIdentifier];
- editVC.isOn = model.top == 1 ? YES : NO;
- [self.navigationController pushViewController:editVC animated:YES];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- return [UIView new];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- return [UIView new];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (void)operationAction:(id)source {
- GroupNoticeModel *model = source;
- NSString *isTop = nil;
- // 取反
- if (model.top == YES) {
- isTop = @"0";
- }
- else {
- isTop = @"1";
- }
- [self showhud];
- [KSNetworkingManager imGroupNoticeUpdateRequest:KS_POST groupId:self.groupId title:model.title content:model.content isTop:isTop noticeID:[NSString stringWithFormat:@"%.0f",model.internalBaseClassIdentifier] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [self resetParamenter];
- [self requestData];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- #pragma mark --- lazy
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = HexRGB(0xf5f5f5);
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.estimatedRowHeight = 270.0f;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.showsVerticalScrollIndicator = NO;
- [_tableView registerNib:[UINib nibWithNibName:@"GroupNoticeCell" bundle:nil] forCellReuseIdentifier:@"GroupNoticeCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = HexRGB(0xf5f5f5);
- _tableView.tableFooterView = bottomView;
- }
- return _tableView;
- }
- /*
- #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
|