DocumentLibraryListVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. //
  2. // DocumentLibraryListVC.m
  3. // Telemarketing
  4. //
  5. // Created by apple on 2021/4/28.
  6. // Copyright © 2021 刘惠萍. All rights reserved.
  7. //
  8. #import "DocumentLibraryListVC.h"
  9. #import "NewDynamicListShieldView.h"
  10. #import "WXApi.h"
  11. @interface DocumentLibraryListVC ()
  12. @end
  13. @implementation DocumentLibraryListVC
  14. - (BOOL)isShowNoResult{//显示无结果页
  15. return true;
  16. }
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self.tableView registerClass:[DocumentLibraryListCell class] forCellReuseIdentifier:@"DocumentLibraryListCell"];
  20. [self addRefresh];
  21. }
  22. #pragma mark table view delegate
  23. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  24. return self.aryDatas.count;
  25. }
  26. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  27. DocumentLibraryListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DocumentLibraryListCell" forIndexPath:indexPath];
  28. [cell resetCellWithModel:self.aryDatas[indexPath.row]];
  29. return cell;
  30. }
  31. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  32. return [DocumentLibraryListCell fetchHeight:self.aryDatas[indexPath.row]];
  33. }
  34. - (void)requestList{
  35. [RequestApi requestGetInformationListWithPage:strDotF(self.pageNum) size:@"20" typeId:UnPackStr(self.activeStatus) delegate:self success:^(NSDictionary * _Nonnull response, id _Nonnull mark) {
  36. NSArray * ary = [GlobalMethod exchangeDic:response[@"dataInfo"][@"dataList"] toAryWithModelName:@"ModelDocumentLibrary"];
  37. if (self.isRemoveAll) {
  38. [self.aryDatas removeAllObjects];
  39. }
  40. self.pageNum ++;
  41. if (!isAry(ary)) {
  42. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  43. }
  44. [self.aryDatas addObjectsFromArray:ary];
  45. [self.tableView reloadData];
  46. } failure:^(NSString * _Nonnull errorStr, id _Nonnull mark) {
  47. }];
  48. }
  49. #pragma mark scroll delegate
  50. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  51. [scrollView scrollLink:(LinkScrollView *)scrollView.superview.superview.superview];
  52. }
  53. @end
  54. @implementation DocumentLibraryListCell
  55. #pragma mark 懒加载
  56. - (UIImageView *)iconImg{
  57. if (_iconImg == nil) {
  58. _iconImg = [UIImageView new];
  59. _iconImg.widthHeight = XY(W(50),W(50));
  60. [GlobalMethod setRoundView:_iconImg color:[UIColor clearColor] numRound:_iconImg.width/2 width:0];
  61. }
  62. return _iconImg;
  63. }
  64. - (UILabel *)labelName{
  65. if (_labelName == nil) {
  66. _labelName = [UILabel new];
  67. [GlobalMethod setLabel:_labelName widthLimit:0 numLines:0 fontNum:F(14) textColor:COLOR_LABEL text:@""];
  68. }
  69. return _labelName;
  70. }
  71. - (UILabel *)labelTime{
  72. if (_labelTime == nil) {
  73. _labelTime = [UILabel new];
  74. [GlobalMethod setLabel:_labelTime widthLimit:0 numLines:0 fontNum:F(10) textColor:COLOR_DETAIL text:@""];
  75. }
  76. return _labelTime;
  77. }
  78. - (UILabel *)labelTitle{
  79. if (_labelTitle == nil) {
  80. _labelTitle = [UILabel new];
  81. [GlobalMethod setLabel:_labelTitle widthLimit:0 numLines:0 fontNum:F(17) textColor:COLOR_LABEL text:@""];
  82. }
  83. return _labelTitle;
  84. }
  85. - (MineListMindImgView *)contentImg{
  86. if (_contentImg == nil) {
  87. _contentImg = [MineListMindImgView new];
  88. }
  89. return _contentImg;
  90. }
  91. -(UIButton *)titleBtn{
  92. if (_titleBtn == nil) {
  93. _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  94. _titleBtn.tag = 1;
  95. [_titleBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  96. _titleBtn.titleLabel.font = [UIFont systemFontOfSize:F(11)];
  97. [_titleBtn setTitle:@" 复制文字" forState:(UIControlStateNormal)];
  98. [_titleBtn setTitleColor:COLOR_DETAIL forState:(UIControlStateNormal)];
  99. [_titleBtn setImage:[UIImage imageNamed:@"aicon_02"] forState:(UIControlStateNormal)];
  100. _titleBtn.widthHeight = XY(W(70),W(40));
  101. }
  102. return _titleBtn;
  103. }
  104. -(UIButton *)imgBtn{
  105. if (_imgBtn == nil) {
  106. _imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  107. _imgBtn.tag = 2;
  108. [_imgBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  109. _imgBtn.titleLabel.font = [UIFont systemFontOfSize:F(11)];
  110. [_imgBtn setTitle:@" 保存图片" forState:(UIControlStateNormal)];
  111. [_imgBtn setTitleColor:COLOR_DETAIL forState:(UIControlStateNormal)];
  112. [_imgBtn setImage:[UIImage imageNamed:@"aicon_01"] forState:(UIControlStateNormal)];
  113. _imgBtn.widthHeight = XY(W(70),W(40));
  114. }
  115. return _imgBtn;
  116. }
  117. -(UIButton *)shareBtn{
  118. if (_shareBtn == nil) {
  119. _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  120. _shareBtn.tag = 3;
  121. [_shareBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  122. _shareBtn.titleLabel.font = [UIFont systemFontOfSize:F(11)];
  123. [_shareBtn setTitle:@" 分享" forState:(UIControlStateNormal)];
  124. [_shareBtn setTitleColor:COLOR_DETAIL forState:(UIControlStateNormal)];
  125. [_shareBtn setImage:[UIImage imageNamed:@"aicon_03"] forState:(UIControlStateNormal)];
  126. _shareBtn.widthHeight = XY(W(70),W(40));
  127. }
  128. return _shareBtn;
  129. }
  130. #pragma mark 初始化
  131. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  132. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  133. if (self) {
  134. self.contentView.backgroundColor = [UIColor whiteColor];
  135. self.backgroundColor = [UIColor whiteColor];
  136. self.selectionStyle = UITableViewCellSelectionStyleNone;
  137. [self.contentView addSubview:self.iconImg];
  138. [self.contentView addSubview:self.labelName];
  139. [self.contentView addSubview:self.labelTime];
  140. [self.contentView addSubview:self.labelTitle];
  141. [self.contentView addSubview:self.contentImg];
  142. [self.contentView addSubview:self.titleBtn];
  143. [self.contentView addSubview:self.imgBtn];
  144. [self.contentView addSubview:self.shareBtn];
  145. }
  146. return self;
  147. }
  148. #pragma mark 刷新cell
  149. - (void)resetCellWithModel:(ModelDocumentLibrary *)model{
  150. [self.contentView removeSubViewWithTag:TAG_LINE];//移除线
  151. //刷新view
  152. self.model=model;
  153. [self.iconImg sd_setImageWithURL:[NSURL URLWithString:UnPackStr(model.sendicon)] placeholderImage:[UIImage imageNamed:IMAGE_HEAD_DEFAULT]];
  154. self.iconImg.leftTop = XY(W(15),W(15));
  155. [self.labelName fitTitle:UnPackStr(model.sendname) variable:0];
  156. self.labelName.leftCenterY = XY(self.iconImg.right+W(10),self.iconImg.centerY);
  157. [self.labelTime fitTitle:UnPackStr(model.createtime) variable:0];;
  158. self.labelTime.rightCenterY = XY(SCREEN_WIDTH-W(15),self.labelName.centerY);
  159. [self.labelTitle fitTitle:[UnPackStr(model.title) stringByReplacingOccurrencesOfString:@"\\n" withString:@"\r\n"] variable:SCREEN_WIDTH-W(30)];
  160. self.labelTitle.leftTop = XY(W(15),self.iconImg.bottom+W(15));
  161. [GlobalMethod setAttributeLabel:self.labelTitle content:[UnPackStr(model.title) stringByReplacingOccurrencesOfString:@"\\n" withString:@"\r\n"] width:self.labelTitle.width lineSpace:10];
  162. NSMutableArray *arr=[NSMutableArray new];
  163. NSArray *saleArray = [model.imageone componentsSeparatedByString:@","];
  164. if (isAry(saleArray)) {
  165. for (NSString *modelp in saleArray) {
  166. ModelImage *modeli=[ModelImage new];
  167. NSString *url=[modelp hasPrefix:@"http"]?modelp:modelp;
  168. modeli.url=url;
  169. [arr addObject:modeli];
  170. }
  171. self.contentImg.leftTop = XY(W(0),self.labelTitle.bottom+W(15));
  172. [self.contentImg resetViewWithArray:arr totalNum:arr.count];
  173. self.contentImg.hidden=false;
  174. }else{
  175. self.contentImg.hidden=true;
  176. }
  177. self.shareBtn.rightTop = XY(SCREEN_WIDTH-W(15),isAry(saleArray)?self.contentImg.bottom+W(15):self.labelTitle.bottom+W(15));
  178. self.imgBtn.rightCenterY = XY(self.shareBtn.left-W(5),self.shareBtn.centerY);
  179. self.titleBtn.rightCenterY = XY(self.imgBtn.left-W(5),self.shareBtn.centerY);
  180. self.height = [self.contentView addLineFrame:CGRectMake(0, self.shareBtn.bottom+W(15), SCREEN_WIDTH, 1)];
  181. }
  182. #pragma mark 点击事件
  183. - (void)btnClick:(UIButton *)sender{
  184. switch (sender.tag) {
  185. case 1:
  186. {
  187. [GlobalMethod copyToPlte:UnPackStr(self.model.content)];
  188. [GlobalMethod showAlert:@"复制成功"];
  189. }
  190. break;
  191. case 2:
  192. {
  193. NSMutableArray *arr=[NSMutableArray new];
  194. NSArray *saleArray = [self.model.imageone componentsSeparatedByString:@","];
  195. if (isAry(saleArray)) {
  196. for (NSString *modelp in saleArray) {
  197. ModelImage *modeli=[ModelImage new];
  198. modeli.url=modelp;
  199. [arr addObject:modeli];
  200. }
  201. }
  202. for (ModelImage *model in arr) {
  203. UIImageView * _iv = [UIImageView new];
  204. _iv.backgroundColor = [UIColor clearColor];
  205. _iv.widthHeight = XY(SCREEN_WIDTH,SCREEN_HEIGHT);
  206. _iv.leftTop = XY(0,0);
  207. _iv.contentMode = UIViewContentModeScaleAspectFit;
  208. NSString *cacheKey = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:model.url]];
  209. [[SDWebImageManager sharedManager].imageCache queryCacheOperationForKey:cacheKey done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
  210. if (image) {
  211. _iv.image = image;
  212. [_iv sd_setImageWithURL:[NSURL URLWithString:UnPackStr(model.url)] placeholderImage:[UIImage imageNamed:IMAGE_BIG_DEFAULT]];
  213. UIImageWriteToSavedPhotosAlbum(_iv.image,self,@selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),nil);
  214. return;
  215. }
  216. }];
  217. }
  218. }
  219. break;
  220. case 3:
  221. {
  222. WEAKSELF
  223. NewDynamicListShieldView * vc = [NewDynamicListShieldView new];
  224. vc.blockSelectBtnModel = ^(ModelBtn *modelBtn){
  225. [weakSelf modelBtnClick:modelBtn];
  226. };
  227. [vc resetWithModel:nil];
  228. UIView * window = [UIApplication sharedApplication].keyWindow;
  229. [window addSubview:vc];
  230. }
  231. break;
  232. default:
  233. break;
  234. }
  235. }
  236. - (void)imageSavedToPhotosAlbum:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
  237. NSString*message =@"";
  238. if(!error) {
  239. [GlobalMethod showAlert:@"成功保存到相册"];
  240. }else
  241. {
  242. message = [error description];
  243. [GlobalMethod showAlert:message];
  244. }
  245. }
  246. - (void)modelBtnClick:(ModelBtn *)model {
  247. switch (model.tag) {
  248. case 0:
  249. {
  250. [self shareWithWechatType:WXSceneSession];
  251. }
  252. break;
  253. case 1:
  254. {
  255. [self shareWithWechatType:WXSceneTimeline];
  256. }
  257. break;
  258. default:
  259. break;
  260. }
  261. }
  262. //微信
  263. - (void)shareWithWechatType:(int)type
  264. {
  265. if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
  266. // 分享出去,没有返回信息
  267. WXWebpageObject *webpageObject = [WXWebpageObject object];
  268. webpageObject.webpageUrl = [NSString stringWithFormat:@"%@phoneMobile/userRecCode?recCode=%@",URL_HEAD,[GlobalData sharedInstance].GB_UserModel.recCode];
  269. WXMediaMessage *message = [WXMediaMessage message];
  270. message.title = @"立即注册,开启您的财富之旅";
  271. message.description = @"POS机办理,信用卡申请,积分换钱......";
  272. [message setThumbImage:[UIImage imageNamed: @"icon"]];
  273. message.mediaObject = webpageObject;
  274. SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
  275. req.bText = NO;
  276. req.message = message;
  277. req.scene = type;
  278. [WXApi sendReq:req];
  279. } else {
  280. [GlobalMethod showAlert:@"你还没有安装微信"];
  281. }
  282. }
  283. @end