AnnountcementDetailViewController.m 6.51 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  AnnountcementDetailViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/23.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "AnnountcementDetailViewController.h"
曹云霄's avatar
曹云霄 committed
10 11 12
#import "WkWebViewViewController.h"
#import "AnnouncementContentTableViewCell.h"
#import "AnnouncementListTableViewCell.h"
13
#import "CustomWKWebViewController.h"
曹云霄's avatar
曹云霄 committed
14 15 16 17 18 19 20 21 22

@interface AnnountcementDetailViewController ()<UITableViewDelegate,UITableViewDataSource>


/**
 公告标题
 */
@property (weak, nonatomic) IBOutlet UILabel *annountcementTitleLabel;

23 24 25 26 27
/**
 公告headerView
 */
@property (weak, nonatomic) IBOutlet UIView *announcementHeaderView;

曹云霄's avatar
曹云霄 committed
28 29 30
/**
 公告类型
 */
31
@property (weak, nonatomic) IBOutlet CustomBorderLabel *annountcementTypeLabel;
曹云霄's avatar
曹云霄 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

/**
 公告时间
 */
@property (weak, nonatomic) IBOutlet UILabel *annountcementTimeLabel;

/**
 公告阅读数
 */
@property (weak, nonatomic) IBOutlet UILabel *annountcementReadCountLabel;

/**
 公告内容高度
 */
@property (nonatomic,assign) CGFloat annountcementContentHeigt;

/**
 公告数据源
 */
51
@property (nonatomic,strong) CustomTOAfficheEntity *afficheResult;
曹云霄's avatar
曹云霄 committed
52

53 54 55 56 57 58 59 60


@end

@implementation AnnountcementDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
曹云霄's avatar
曹云霄 committed
61 62 63 64 65 66 67 68 69 70 71
    
    [self setUpTableViewAction];
    [self addChildWebViewController];
    [self getAnnouncementDetailsDatasAction];
}

#pragma mark - 设置Tableview
- (void)setUpTableViewAction
{
    self.announcementDetailsTableView.tableFooterView = [UIView new];
    [self.announcementDetailsTableView registerClass:[AnnouncementContentTableViewCell class] forCellReuseIdentifier:@"AnnouncementContentTableViewCell"];
72 73 74 75
    self.announcementDetailsTableView.tableHeaderView = self.announcementHeaderView;
}

#pragma mark - 设置HeaderView
76
- (void)setUpTableViewHeaderView:(CustomTOAfficheEntity *)entity
77 78
{
    self.annountcementTitleLabel.text = entity.title;
79
    self.announcementHeaderView.height = entity.titleHeight + 44;
80 81
    self.annountcementTimeLabel.text = entity.createDate;
    self.annountcementTypeLabel.customText = entity.afficheType;
82
    self.annountcementReadCountLabel.text = [NSString stringWithFormat:@"%ld",entity.attachmentUrls.count];
曹云霄's avatar
曹云霄 committed
83 84 85 86 87 88 89 90 91
}

#pragma mark - WKWebView
- (void)addChildWebViewController
{
    WS(weakSelf);
    WkWebViewViewController *webView = [[WkWebViewViewController alloc]initWithReturnContentSize:^(CGFloat contentHeight) {
        weakSelf.annountcementContentHeigt = contentHeight;
        webView.view.frame = CGRectMake(0, 0, ScreenWidth, contentHeight);
92
        [weakSelf.announcementDetailsTableView reloadData];
曹云霄's avatar
曹云霄 committed
93
    }];
94 95
    self.annountcementContentHeigt = 44;//默认值
    webView.view.frame = CGRectMake(0, 0, ScreenWidth, self.annountcementContentHeigt);
曹云霄's avatar
曹云霄 committed
96 97 98 99 100 101 102
    [self addChildViewController:webView];
}

#pragma mark - 获取公告详情数据
- (void)getAnnouncementDetailsDatasAction
{
    WS(weakSelf);
103
    [XBLoadingView showHUDViewWithDefault];;
104
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(AFFICHEdETAILS),self.announcementEntity.fid] WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
105
        
106
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
107
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
108
            weakSelf.afficheResult = [[CustomTOAfficheEntity alloc]initWithDictionary:returnValue[@"data"] error:nil];
曹云霄's avatar
曹云霄 committed
109 110
            WkWebViewViewController *webView = [weakSelf.childViewControllers firstObject];
            webView.htmlString = weakSelf.afficheResult.content;
111
            [weakSelf setUpTableViewHeaderView:weakSelf.afficheResult];
112 113 114
            if (!weakSelf.announcementEntity.readed) {
                [weakSelf announcementRead];
            }
曹云霄's avatar
曹云霄 committed
115
        }else {
116
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
117 118 119
        }
        [weakSelf.announcementDetailsTableView reloadData];
        
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    } WithFailureBlock:^(NSError *error) {
        [XBLoadingView hideHUDViewWithDefault];
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

#pragma mark - 公告已读
- (void)announcementRead
{
    WS(weakSelf);
    NSString *url = [NSString stringWithFormat:SERVERREQUESTURL(READANNOUNCEMENT),self.announcementEntity.fid,[Shoppersmanager manager].Shoppers.employee.departid,[Shoppersmanager manager].Shoppers.employee.fid,[[NSDate date] httpParameterString]];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:url WithRequestType:ZERO WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            if (weakSelf.readBlock) {
                weakSelf.readBlock();
            }
        }else {
           [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
        }
曹云霄's avatar
曹云霄 committed
141
    } WithFailureBlock:^(NSError *error) {
142
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
143
    }];
144 145
}

曹云霄's avatar
曹云霄 committed
146 147 148 149 150 151 152 153 154 155 156
#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        AnnouncementContentTableViewCell *contentCell = [tableView dequeueReusableCellWithIdentifier:@"AnnouncementContentTableViewCell" forIndexPath:indexPath];
        [contentCell.contentView addSubview:self.childViewControllers[0].view];
        return contentCell;
    }
    AnnouncementListTableViewCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"AnnouncementListTableViewCell" forIndexPath:indexPath];
    listCell.attachmentEntity = self.afficheResult.attachmentUrls[indexPath.row-1];
    return listCell;
157 158
}

曹云霄's avatar
曹云霄 committed
159 160 161 162 163
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.afficheResult.attachmentUrls.count+1;
}
164

曹云霄's avatar
曹云霄 committed
165 166 167 168 169 170
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return self.annountcementContentHeigt;
    }
    return 80;
171 172
}

173 174 175 176 177
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
    TOAttachmentEntity *attachment = self.afficheResult.attachmentUrls[indexPath.row-1];
曹云霄's avatar
曹云霄 committed
178
    wkWebView.urlString = attachment.fileUrl;
179 180 181
    [self presentViewController:wkWebView animated:YES completion:nil];
}

182
@end