YOUPAILCEditUserMsgVC.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. //
  2. // YOUPAILCEditUserMsgVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/26.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCEditUserMsgVC.h"
  9. #import "YOUPAIZYSettingCell.h"
  10. #import "YOUPAILCImageCollectionCell.h"
  11. #import "YOUPAILCImageDeleteView.h"
  12. #import "YOUPAILCUpdateNickVC.h"
  13. #import "YOUPAILCUpdateCityVC.h"
  14. #import "PGDatePickManager.h"
  15. #import "LCTZImageConfigHelper.h"
  16. #import "YOUPAILZUpdateSignVC.h"
  17. #import "UIViewController+TFPresent.h"
  18. #import "YOUPAIZYEditUserShowAlertWindow.h"
  19. @interface YOUPAILCEditUserMsgVC ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,PGDatePickerDelegate,TZImagePickerControllerDelegate,YBImageBrowserDelegate,ZYEditUserShowAlertWindowDelegate>
  20. @property(nonatomic,strong)YOUPAILCUserModel* youpaipuserModel;
  21. @property(nonatomic,strong)UITableView* youpaiptableView;
  22. @property(nonatomic,strong)UIView *youpaipheaderView;
  23. @property(nonatomic,strong)NSMutableArray* youpaipimages;
  24. @property(nonatomic,copy)NSMutableArray* youpaipoldAlbum_list;
  25. @property(nonatomic,strong)UICollectionView *youpaipcollectionView;
  26. @property(nonatomic,assign)CGPoint youpaiplastPressPoint;
  27. @property(nonatomic,strong)NSMutableArray *youpaipcellAttributesArray;
  28. @property(nonatomic,strong)YOUPAILCImageDeleteView* youpaipdeleteView;
  29. @property (nonatomic, strong) UIButton *youpaipordinaryUserHeadImageBtn;/// 普通用户头像
  30. @property(nonatomic,assign)CGFloat youpaipKWidth;
  31. @property(nonatomic,strong)UIView *youpaipbaseView;
  32. @property (nonatomic, assign)NSInteger youpaipimageIndex; /// 图片下标
  33. @property (nonatomic, strong)YBImageBrowser *youpaipbrowser; ///图片预览
  34. @end
  35. @implementation YOUPAILCEditUserMsgVC
  36. - (void)viewWillDisappear:(BOOL)animated{
  37. [super viewWillDisappear:animated];
  38. if (![self.youpaipoldAlbum_list isEqual:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list]) {
  39. [self youpaifupdateUserPhotos];
  40. }
  41. }
  42. - (YOUPAILCImageDeleteView*)youpaipdeleteView{
  43. if (!_youpaipdeleteView) {
  44. _youpaipdeleteView = [[YOUPAILCImageDeleteView alloc]initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, 50)];
  45. [self.view addSubview:_youpaipdeleteView];
  46. _youpaipdeleteView.hidden = YES;
  47. }
  48. return _youpaipdeleteView;
  49. }
  50. - (NSMutableArray *)youpaipcellAttributesArray{
  51. if (!_youpaipcellAttributesArray) {
  52. _youpaipcellAttributesArray = [NSMutableArray arrayWithCapacity:0];
  53. }
  54. return _youpaipcellAttributesArray;
  55. }
  56. - (UITableView *)youpaiptableView{
  57. if (!_youpaiptableView) {
  58. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  59. _youpaiptableView.showsVerticalScrollIndicator = NO;
  60. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  61. // _tableView.backgroundColor = DecColorFromRGB(246,246,246);
  62. _youpaiptableView.backgroundColor = [UIColor clearColor];
  63. _youpaiptableView.delegate = self;
  64. _youpaiptableView.dataSource = self;
  65. if (@available(iOS 15.0, *)) {
  66. _youpaiptableView.sectionHeaderTopPadding = 0;
  67. }
  68. }
  69. return _youpaiptableView;
  70. }
  71. -(void)youpaifaddImage
  72. {
  73. // if (self.userModel.userinfo.album_list.count == 6) {
  74. // [ZCHUDHelper showTitle:@"照片已达最大数量,不能再添加照片"];
  75. // }else{
  76. // [self youpaifopenAlbum];
  77. // }
  78. UIAlertController *alertV = [UIAlertController alertControllerWithTitle:@"" message:@"提交成功 审核通过后方可展示" preferredStyle:UIAlertControllerStyleAlert];
  79. [alertV addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
  80. [self presentViewController:alertV animated:YES completion:nil];
  81. }
  82. - (void)viewDidLoad {
  83. [super viewDidLoad];
  84. self.title = @"编辑资料";
  85. self.view.backgroundColor = LCBkgColor;
  86. self.youpaipKWidth = KScreenWidth - 28.0f;
  87. self.youpaipuserModel = [LCSaveModel getUserModel];
  88. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifaddImage) title:@"提交审核" font:LCFont15 titleColor:ZYPinkColor highlightedColor:ZYPinkColor titleEdgeInsets:UIEdgeInsetsZero];
  89. self.youpaipimages = [NSMutableArray array];
  90. self.youpaipoldAlbum_list = [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list copy];
  91. [self.view addSubview:self.youpaiptableView];
  92. [self youpaifsetupHeaderView];
  93. [self youpaifredHidden];
  94. //长按可拖动排序 下面会出现垃圾篓删除
  95. //iOS下拉图片缩小为没有
  96. }
  97. -(void)youpaifredHidden{
  98. [LCHttpHelper requestWithURLString:UserCenter parameters:@{@"type":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  99. NSDictionary* dict = (NSDictionary*)responseObject;
  100. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  101. if (code==0) {//成功
  102. }
  103. } failure:^(NSError *error) {
  104. }];
  105. }
  106. - (void)youpaifsetupHeaderView{
  107. // if(self.userModel.userinfo.is_anchor == 1){
  108. [self youpaifsetupAnchorHeaderView];
  109. // }else{
  110. // [self youpaifsetupOrdinaryHeaderView];
  111. // }
  112. }
  113. /// 普通用户headerView
  114. - (void)youpaifsetupOrdinaryHeaderView{
  115. self.youpaipheaderView = [[UIView alloc]initWithFrame:CGRectMake(0,0, KScreenWidth, 197.0f)];
  116. self.youpaipheaderView.backgroundColor = [UIColor clearColor];
  117. self.youpaiptableView.tableHeaderView = self.youpaipheaderView;
  118. self.youpaipordinaryUserHeadImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  119. self.youpaipordinaryUserHeadImageBtn.layer.cornerRadius = 54.5f;
  120. self.youpaipordinaryUserHeadImageBtn.clipsToBounds = YES;
  121. self.youpaipordinaryUserHeadImageBtn.backgroundColor = LCBkgColor;
  122. self.youpaipordinaryUserHeadImageBtn.contentMode = UIViewContentModeScaleAspectFill;
  123. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count > 0) {
  124. [self.youpaipordinaryUserHeadImageBtn setImage:nil forState:UIControlStateNormal];
  125. NSURL *url = [[LCTools getImageUrlWithAddress:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[0]] urlWithImageScale:60];
  126. [self.youpaipordinaryUserHeadImageBtn sd_setImageWithURL:url forState:UIControlStateNormal];
  127. }else{
  128. [self.youpaipordinaryUserHeadImageBtn setImage:[UIImage imageNamed:@"vqu_images_ic_profile_norheader"] forState:UIControlStateNormal];
  129. [self.youpaipordinaryUserHeadImageBtn setBackgroundImage:nil forState:UIControlStateNormal];
  130. }
  131. self.youpaipordinaryUserHeadImageBtn.tag = 0;
  132. [self.youpaipordinaryUserHeadImageBtn addTarget:self action:@selector(youpaifeditUserHeaderImage:) forControlEvents:UIControlEventTouchUpInside];
  133. [self.youpaipheaderView addSubview:self.youpaipordinaryUserHeadImageBtn];
  134. [self.youpaipordinaryUserHeadImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.center.equalTo(self.youpaipheaderView);
  136. make.width.height.offset(109.0f);
  137. }];
  138. }
  139. /// 女神headerView
  140. - (void)youpaifsetupAnchorHeaderView{
  141. self.youpaipheaderView = [[UIView alloc]initWithFrame:CGRectMake(0,0, KScreenWidth, 56.0f + (KScreenWidth - 48.0f) / 3.0f * 2.0f+30)];
  142. self.youpaipheaderView.backgroundColor = [UIColor clearColor];
  143. self.youpaiptableView.tableHeaderView = self.youpaipheaderView;
  144. // UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(16,30,KScreenWidth-32,self.headerView.frame.size.height - 48.0f)];
  145. // baseView.backgroundColor = [UIColor whiteColor];
  146. // baseView.layer.cornerRadius = 8;
  147. // baseView.layer.masksToBounds = YES;
  148. // [self.headerView addSubview:baseView];
  149. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  150. CGFloat margin = 8.0;
  151. CGFloat itemWH = (KScreenWidth - 48.0f) / 3.0f;
  152. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  153. layout.itemSize = CGSizeMake(itemWH, itemWH);
  154. layout.minimumInteritemSpacing = margin;
  155. layout.minimumLineSpacing = margin;
  156. _youpaipcollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(14,24.0f,KScreenWidth-28.0f, self.youpaipheaderView.mj_h - 48.0f-30) collectionViewLayout:layout];
  157. _youpaipcollectionView.backgroundColor = [UIColor clearColor];
  158. _youpaipcollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  159. _youpaipcollectionView.layer.masksToBounds = NO;
  160. _youpaipcollectionView.dataSource = self;
  161. _youpaipcollectionView.delegate = self;
  162. _youpaipcollectionView.scrollEnabled = NO;
  163. [_youpaipcollectionView registerClass:[YOUPAILCImageCollectionCell class] forCellWithReuseIdentifier:@"YOUPAILCImageCollectionCell"];
  164. UILabel* txtTip = [[UILabel alloc]initWithFrame:CGRectMake(14,CGRectGetMaxY(_youpaipcollectionView.frame), KScreenWidth-28, 47)];
  165. txtTip.numberOfLines = 0;
  166. txtTip.font = [UIFont systemFontOfSize:11];
  167. txtTip.textColor = HexColorFromRGB(0x6C6B70) ;
  168. txtTip.text = @"1.拖拽相片可以更改排序,单击查看大图可删除相册\n2.照片涉黄或者审核不通过将被删除,严重者冻结账号";
  169. [UILabel changeLineSpaceForLabel:txtTip WithSpace:4.0];
  170. [self.youpaipheaderView addSubview:txtTip];
  171. [self.youpaipheaderView addSubview:_youpaipcollectionView];
  172. }
  173. #pragma mark - CollectionView
  174. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  175. return 6;
  176. }
  177. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  178. YOUPAILCImageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILCImageCollectionCell" forIndexPath:indexPath];
  179. CGFloat width = (KScreenWidth-64-8)/3;
  180. cell.youpaipimageView.image = [UIImage imageWithColor:HexColorFromRGB(0x31303A) size:CGSizeMake(width, (KScreenWidth-64-8)/3.0/3.0*4)];
  181. cell.youpaipitem = indexPath.item;
  182. cell.youpaipimagev.hidden = YES;
  183. cell.youpaiphasImage = NO;
  184. cell.youpaipdefaultImgV.hidden = NO;
  185. if (indexPath.item < self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count) {
  186. // 1通过,0待审核,2,未通过
  187. album_list_newModel *newModel = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new[indexPath.item];
  188. cell.youpaipreviewStatus = newModel.youpaipstatus;
  189. cell.youpaipdefaultImgV.hidden = YES;
  190. [cell.youpaipimageView sd_setImageWithURL:[[LCTools getImageUrlWithAddress:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[indexPath.item]] urlWithImageScale:60]];
  191. cell.youpaiphasImage = YES;
  192. if (indexPath.item == 0) {
  193. cell.youpaipimagev.hidden = NO;
  194. }
  195. }
  196. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongPressHandel:)];
  197. [cell addGestureRecognizer:longPress];
  198. return cell;
  199. }
  200. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  201. YOUPAILCImageCollectionCell *cell = (YOUPAILCImageCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:indexPath];
  202. if (cell.youpaiphasImage) {
  203. if (cell.youpaipreviewStatus == review_zero|| cell.youpaipreviewStatus == review_two) {
  204. [ZCHUDHelper showTitle:@"图片正在审核中,不能重复操作"];
  205. }else{
  206. if (indexPath.item == 0) {
  207. YOUPAIZYEditUserShowAlertWindow *vc= [[YOUPAIZYEditUserShowAlertWindow alloc]init];
  208. vc.youpaipbtntitleArr = @[@"查看",@"更换",@"取消"];
  209. vc.youpaipdelegate = self;
  210. vc.isTouchDismiss = YES;
  211. [self TFPresentVC:vc completion:^{}];
  212. }else{
  213. YOUPAIZYEditUserShowAlertWindow *vc= [[YOUPAIZYEditUserShowAlertWindow alloc]init];
  214. vc.youpaipbtntitleArr = @[@"查看",@"设为头像",@"更换",@"删除",@"取消"];
  215. vc.youpaipdelegate = self;
  216. vc.isTouchDismiss = YES;
  217. [self TFPresentVC:vc completion:^{}];
  218. }
  219. }
  220. NSMutableArray *tempArr = [NSMutableArray array];
  221. for (int i=0; i<self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count; i++) {
  222. YBIBImageData *model = [YBIBImageData new];
  223. model.imageURL = [LCTools getImageUrlWithAddress:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[i]];
  224. YOUPAILCImageCollectionCell *tmpCell = (YOUPAILCImageCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  225. model.projectiveView = tmpCell.youpaipimageView ;
  226. [tempArr addObject:model];
  227. }
  228. // YBImageBrowserFunctionModel *fModel = [[YBImageBrowserFunctionModel alloc] init];
  229. // fModel.name = @"";
  230. // fModel.ID = @"removeImage";
  231. self.youpaipbrowser = [YBImageBrowser new];
  232. self.youpaipbrowser.dataSourceArray = tempArr;
  233. self.youpaipbrowser.currentPage = indexPath.item;
  234. // self.browser.fuctionDataArray = @[fModel];//nil;
  235. self.youpaipbrowser.delegate = self;
  236. // self.browser.toolBar.backgroundColor = LCBkgColor;
  237. // self.browser.toolBar.rightButton.titleLabel.font = LCFont(15.0f);
  238. // self.browser.toolBar.titleLabel.font = LCFont(17.0f);
  239. // self.browser.toolBar.titleLabel.textColor = [UIColor whiteColor];
  240. // [self.browser.toolBar.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  241. // self.browser.toolBar.hideLeftBtn = NO;
  242. }else{
  243. [self youpaifopenAlbum:8];
  244. }
  245. }
  246. #pragma mark-底部alert弹框事件
  247. - (void)youpaifimSessionMoreWindowAction:(YOUPAIZYEditUserShowAlertWindow *)alert
  248. type:(NSString *)type
  249. tag:(NSInteger)tag
  250. andUserId:(NSString *)user_id{
  251. if ([type isEqualToString:@"look"]){//查看
  252. [self.youpaipbrowser show];
  253. }else if ([type isEqualToString:@"setprofile"]){//设为头像
  254. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count>1) {
  255. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count>self.youpaipimageIndex) {
  256. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list exchangeObjectAtIndex:0 withObjectAtIndex:self.youpaipbrowser.currentPage];
  257. self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list;
  258. }
  259. [self.youpaipcollectionView reloadData];
  260. if (self.youpaipisChange) {
  261. if (self.youpaipupdateIconBlock) {
  262. self.youpaipupdateIconBlock(self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[0]);
  263. }
  264. }
  265. }
  266. }else if ([type isEqualToString:@"change"]){//更换
  267. [self youpaifopenAlbum:self.youpaipbrowser.currentPage];
  268. }
  269. else if ([type isEqualToString:@"delete"]){//删除
  270. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count>1) {
  271. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count>self.youpaipimageIndex) {
  272. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list removeObjectAtIndex:self.youpaipbrowser.currentPage];
  273. }
  274. [self.youpaipcollectionView reloadData];
  275. NSMutableArray *tempArr = [NSMutableArray array];
  276. for (int i=0; i<self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count; i++) {
  277. YBIBImageData *model = [YBIBImageData new];
  278. model.imageURL = [LCTools getImageUrlWithAddress:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[i]];
  279. YOUPAILCImageCollectionCell *tmpCell = (YOUPAILCImageCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  280. model.projectiveView = tmpCell.youpaipimageView ;
  281. [tempArr addObject:model];
  282. }
  283. self.youpaipbrowser.dataSourceArray = tempArr;
  284. [self.youpaipbrowser reloadData];
  285. self.youpaipbrowser.currentPage = 0;
  286. }
  287. else{
  288. [ZCHUDHelper showTitle:@"再删除就没头像啦"];
  289. }
  290. }else if ([type isEqualToString:@"cancel"]){//取消
  291. }
  292. // }else{ /// 普通用户删除图片
  293. // if ([type isEqual:@"edit"]) {
  294. // if (self.userModel.userinfo.album_list.count>self.imageIndex) {
  295. // [self.userModel.userinfo.album_list removeObjectAtIndex:self.imageIndex];
  296. // }
  297. // [self.browser hide];
  298. // if (self.userModel.userinfo.album_list.count > 0) {
  299. // [self.ordinaryUserHeadImageBtn setImage:nil forState:UIControlStateNormal];
  300. // NSURL *url = [LCTools getImageUrlWithAddress:self.userModel.userinfo.album_list[0]];
  301. // [self.ordinaryUserHeadImageBtn sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
  302. // }else{
  303. // [self.ordinaryUserHeadImageBtn setImage:[UIImage imageNamed:@"vqu_images_ic_profile_norheader"] forState:UIControlStateNormal];
  304. // [self.ordinaryUserHeadImageBtn setBackgroundImage:nil forState:UIControlStateNormal];
  305. // }
  306. // }
  307. // }
  308. }
  309. - (void)youpaifeditUserHeaderImage:(UIButton *)sender{
  310. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count > 0) {
  311. NSMutableArray *tempArr = [NSMutableArray array];
  312. for (int i=0; i < 1; i++) {
  313. YBIBImageData *model = [YBIBImageData new];
  314. model.imageURL = [LCTools getImageUrlWithAddress:self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[i]];
  315. YOUPAILCImageCollectionCell *tmpCell = (YOUPAILCImageCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  316. model.projectiveView = tmpCell.youpaipimageView ;
  317. [tempArr addObject:model];
  318. }
  319. // YBImageBrowserFunctionModel *fModel = [[YBImageBrowserFunctionModel alloc] init];
  320. // fModel.name = @"删除";
  321. // fModel.ID = @"removeImage";
  322. self.youpaipbrowser = [YBImageBrowser new];
  323. self.youpaipbrowser.dataSourceArray = tempArr;
  324. self.youpaipbrowser.currentPage = 0;
  325. // self.browser.fuctionDataArray = @[fModel];//nil;
  326. self.youpaipbrowser.delegate = self;
  327. // self.browser.toolBar.backgroundColor = [UIColor whiteColor];
  328. // self.browser.toolBar.rightButton.titleLabel.font = LCFont(15.0f);
  329. // self.browser.toolBar.titleLabel.font = LCFont(17.0f);
  330. // self.browser.toolBar.titleLabel.textColor = HexColorFromRGB(0x333333);
  331. // [self.browser.toolBar.rightButton setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  332. // self.browser.toolBar.hideLeftBtn = NO;
  333. [self.youpaipbrowser show];
  334. }else{
  335. [self youpaifopenAlbum:8];
  336. }
  337. }
  338. #pragma mark - tableViewDelegate
  339. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  340. return 4;
  341. }
  342. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  343. return 54.0f;
  344. }
  345. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  346. return 0.0001;
  347. }
  348. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  349. return 0.0001;
  350. }
  351. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  352. YOUPAIZYSettingCell* cell = [[YOUPAIZYSettingCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"commonCell"];
  353. cell.youpaipbaseView.frame = CGRectMake(0, 0, KScreenWidth, 54.0f);
  354. cell.youpaiparrowLabel.textColor = HexColorFromRGB(0xAAAAAA);
  355. cell.youpaiparrowLabel.font = LCFont(13.0f);
  356. cell.youpaipheadLabel.font = LCFont(15.0f);
  357. if (indexPath.row==0) {
  358. cell.youpaipheadLabel.text = @"昵称";
  359. // cell.arrowLabel.font = LCFont(15.0f);
  360. if ([self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""]) {
  361. cell.youpaiparrowLabel.text = @"请输入昵称";
  362. }else{
  363. cell.youpaiparrowLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipnickname;
  364. }
  365. }else if (indexPath.row==1){
  366. cell.youpaipheadLabel.text = @"生日";
  367. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) {
  368. cell.youpaiparrowLabel.text = @"请选择日期";
  369. }else{
  370. cell.youpaiparrowLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  371. }
  372. }else if (indexPath.row==2){
  373. cell.youpaipheadLabel.text = @"城市";
  374. cell.youpaiparrowLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  375. }else if (indexPath.row==3){
  376. cell.youpaipheadLabel.text = @"个人介绍";
  377. if (self.youpaipuserModel.youpaipuserinfo.youpaipsign.length == 0) {
  378. cell.youpaiparrowLabel.text = @"简单介绍一下自己吧…";
  379. }else{
  380. cell.youpaiparrowLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipsign;
  381. }
  382. }
  383. return cell;
  384. }
  385. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  386. if (indexPath.row==0) {
  387. YOUPAILCUpdateNickVC* nickVC = [[YOUPAILCUpdateNickVC alloc]init];
  388. nickVC.youpaipnickName = self.youpaipuserModel.youpaipuserinfo.youpaipnickname;
  389. nickVC.youpaipblock = ^(NSString *nickname) {
  390. self.youpaipuserModel.youpaipuserinfo.youpaipnickname = nickname;
  391. [self.youpaiptableView reloadData];
  392. };
  393. [self.navigationController pushViewController:nickVC animated:YES];
  394. }else if (indexPath.row==1){
  395. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  396. datePickManager.isShadeBackground = true;
  397. datePickManager.cancelButtonFont = LCFont(15);
  398. datePickManager.confirmButtonFont = LCFont(15);
  399. datePickManager.cancelButtonTextColor = HexColorFromRGB(0x9F9DA5);
  400. datePickManager.confirmButtonTextColor = [UIColor whiteColor];
  401. datePickManager.headerViewBackgroundColor = LCBkgColor;
  402. datePickManager.headerHeight = 50;
  403. PGDatePicker *datePicker = datePickManager.datePicker;
  404. datePicker.backgroundColor = LCBkgColor;
  405. datePicker.rowHeight = 35;
  406. datePicker.middleTextColor = [UIColor whiteColor];
  407. datePicker.textColorOfSelectedRow = [UIColor whiteColor];
  408. datePicker.textColorOfOtherRow = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
  409. datePicker.textFontOfSelectedRow = LCFont(17);
  410. datePicker.textFontOfOtherRow = LCFont(17);
  411. datePicker.lineBackgroundColor = [UIColor clearColor];
  412. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  413. NSDate* currentDate = [NSDate date];
  414. [dateFormatter setDateFormat:@"yyyy"];
  415. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  416. [dateFormatter setDateFormat:@"MM"];
  417. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  418. [dateFormatter setDateFormat:@"dd"];
  419. NSString* currentDay=[dateFormatter stringFromDate:currentDate] ;
  420. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-18,currentMonth,currentDay];
  421. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-50,currentMonth,currentDay];
  422. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  423. NSString* defaultDateStr;
  424. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@""]) {
  425. defaultDateStr = @"1999-03-15";
  426. }else{
  427. defaultDateStr = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  428. }
  429. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  430. [datePicker setDate:date];
  431. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  432. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  433. datePicker.delegate = self;
  434. datePicker.datePickerType = PGDatePickerTypeLine;
  435. datePicker.isHiddenMiddleText = false;
  436. datePicker.datePickerMode = PGDatePickerModeDate;
  437. [self presentViewController:datePickManager animated:false completion:nil];
  438. }else if (indexPath.row==2){
  439. YOUPAILCUpdateCityVC* cityVC = [[YOUPAILCUpdateCityVC alloc]init];
  440. cityVC.youpaipcityName = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  441. cityVC.youpaipblock = ^(NSString *cityName) {
  442. self.youpaipuserModel.youpaipuserinfo.youpaipcity = cityName;
  443. [self youpaifupdateCity];
  444. };
  445. [self.navigationController pushViewController:cityVC animated:YES];
  446. }else if (indexPath.row == 3){
  447. YOUPAILZUpdateSignVC* cityVC = [[YOUPAILZUpdateSignVC alloc]init];
  448. cityVC.youpaipsign = self.youpaipuserModel.youpaipuserinfo.youpaipsign;
  449. cityVC.youpaipblock = ^(NSString *sign) {
  450. self.youpaipuserModel.youpaipuserinfo.youpaipsign = sign;
  451. [self youpaifupdateSign];
  452. };
  453. [self.navigationController pushViewController:cityVC animated:YES];
  454. }
  455. }
  456. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  457. NSLog(@"dateComponents = %@", dateComponents);
  458. NSInteger year=[dateComponents year];
  459. NSInteger month=[dateComponents month];
  460. NSInteger day=[dateComponents day];
  461. NSString* birthday = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
  462. self.youpaipuserModel.youpaipuserinfo.youpaipbirthday = birthday;
  463. [self youpaifupdateBirthday];
  464. }
  465. - (void)youpaifupdateCity{
  466. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"cityId":[LCTools getCityIDWithCityName:self.youpaipuserModel.youpaipuserinfo.youpaipcity]}
  467. needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  468. NSDictionary* dict = (NSDictionary*)responseObject;
  469. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  470. if (code==0) {//成功
  471. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  472. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  473. [LCSaveModel saveUserModel:userModel];
  474. [self.youpaiptableView reloadData];
  475. }
  476. } failure:^(NSError *error) {
  477. }];
  478. }
  479. - (void)youpaifupdateBirthday{
  480. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"birthday":self.youpaipuserModel.youpaipuserinfo.youpaipbirthday}
  481. needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  482. NSDictionary* dict = (NSDictionary*)responseObject;
  483. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  484. if (code==0) {//成功
  485. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  486. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  487. [LCSaveModel saveUserModel:userModel];
  488. [self.youpaiptableView reloadData];
  489. }
  490. } failure:^(NSError *error) {
  491. }];
  492. }
  493. - (void)youpaifupdateSign{
  494. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"signature":self.youpaipuserModel.youpaipuserinfo.youpaipsign}
  495. needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  496. NSDictionary* dict = (NSDictionary*)responseObject;
  497. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  498. if (code==0) {//成功
  499. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  500. userModel.youpaipuserinfo.youpaipsign = self.youpaipuserModel.youpaipuserinfo.youpaipsign;
  501. [LCSaveModel saveUserModel:userModel];
  502. [self.youpaiptableView reloadData];
  503. }
  504. } failure:^(NSError *error) {
  505. }];
  506. }
  507. - (void)youpaifupdateUserPhotos{
  508. NSString* albumStr = @"";
  509. if (self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count>0) {
  510. for (int i =0; i<self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count; i++) {
  511. NSString* str = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[i];
  512. if (i==0) {
  513. albumStr = [NSString stringWithFormat:@"%@%@",albumStr,str];
  514. }else{
  515. albumStr = [NSString stringWithFormat:@"%@,%@",albumStr,str];
  516. }
  517. }
  518. }
  519. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"albums":albumStr} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  520. NSDictionary* dict = (NSDictionary*)responseObject;
  521. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  522. if (code==0) {//成功
  523. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  524. userModel.youpaipuserinfo.youpaipalbum_list = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list;
  525. [LCSaveModel saveUserModel:userModel];
  526. }
  527. } failure:^(NSError *error) {
  528. }];
  529. }
  530. #pragma mark - 拖拽事件照片处理
  531. - (void)youpaiflongPressHandel:(UILongPressGestureRecognizer*)sender{
  532. YOUPAILCImageCollectionCell *cell = (YOUPAILCImageCollectionCell *)sender.view;
  533. if (!cell.youpaiphasImage) {
  534. return ;
  535. }
  536. NSIndexPath *cellIndexPath = [self.youpaipcollectionView indexPathForCell:cell];
  537. cell.transform = CGAffineTransformMakeScale(1.1, 1.1);
  538. [self.youpaipcollectionView bringSubviewToFront:cell];
  539. BOOL isChanged = NO;
  540. if (sender.state == UIGestureRecognizerStateBegan) {
  541. [self.youpaipcellAttributesArray removeAllObjects];
  542. for (int i = 0;i< self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list.count; i++) {
  543. [self.youpaipcellAttributesArray addObject:[self.youpaipcollectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]]];
  544. }
  545. self.youpaiplastPressPoint = [sender locationInView:self.youpaipcollectionView];
  546. }else if (sender.state == UIGestureRecognizerStateChanged){
  547. cell.center = [sender locationInView:self.youpaipcollectionView];
  548. if (cell.center.y-10>self.youpaiplastPressPoint.y) {
  549. [UIView animateWithDuration:0.25 animations:^{
  550. self.youpaipdeleteView.frame = CGRectMake(0, KScreenHeight-50, KScreenWidth, 50);
  551. }];
  552. }
  553. for (UICollectionViewLayoutAttributes *attributes in self.youpaipcellAttributesArray) {
  554. if (CGRectContainsPoint(attributes.frame, cell.center) && cellIndexPath != attributes.indexPath ) {
  555. isChanged = YES;
  556. //对数组中存放的元素重新排序
  557. NSString* photoStr = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list[cellIndexPath.item];
  558. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list removeObjectAtIndex:cellIndexPath.item];
  559. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list insertObject:photoStr atIndex:attributes.indexPath.item];
  560. album_list_newModel *model = self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new[cellIndexPath.item];
  561. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new removeObjectAtIndex:cellIndexPath.item];
  562. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new insertObject:model atIndex:attributes.indexPath.item];
  563. [self.youpaipcollectionView moveItemAtIndexPath:cellIndexPath toIndexPath:attributes.indexPath];
  564. // if (attributes.indexPath.item == 0) {
  565. // cell.imagev.hidden = NO;
  566. // }else{
  567. // cell.imagev.hidden = YES;
  568. // }
  569. }
  570. }
  571. CGPoint viewPoint = [sender locationInView:self.view];
  572. if (viewPoint.y>=KScreenHeight-50) {
  573. self.youpaipdeleteView.youpaipstatu = 2;
  574. }else{
  575. self.youpaipdeleteView.youpaipstatu = 1;
  576. }
  577. }else if (sender.state == UIGestureRecognizerStateEnded) {
  578. if (!isChanged) {
  579. cell.center = [self.youpaipcollectionView layoutAttributesForItemAtIndexPath:cellIndexPath].center;
  580. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  581. //
  582. // [self.collectionView reloadData];
  583. // });
  584. }
  585. cell.transform = CGAffineTransformIdentity;
  586. // if (self.deleteView.statu==2) {
  587. // if (self.userModel.userinfo.album_list.count>1) {
  588. // if (self.userModel.userinfo.album_list.count>cell.item) {
  589. // [self.userModel.userinfo.album_list removeObjectAtIndex:cell.item];
  590. // }
  591. // [self.collectionView reloadData];
  592. // }else{
  593. // [ZCHUDHelper showTitle:@"再删除就没头像啦"];
  594. // }
  595. // }
  596. [UIView animateWithDuration:0.25 animations:^{
  597. self.youpaipdeleteView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, 50);
  598. } completion:nil];
  599. }
  600. }
  601. - (void)youpaifopenAlbum:(NSInteger)index{
  602. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
  603. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  604. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  605. imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
  606. imagePickerVc.allowPickingImage = YES;//是否允许选择照片
  607. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  608. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  609. imagePickerVc.allowCrop = NO;//是否允许裁剪
  610. // // 裁剪框的尺寸
  611. // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
  612. // 4. 照片排列按修改时间升序
  613. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  614. // You can get the photos by block, the same as by delegate.
  615. // 你可以通过block或者代理,来得到用户选择的照片.
  616. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  617. [ZCHUDHelper showWithStatus:@"上传中..."];
  618. // [LCCommonHttp uploadImages:photos type:@"album" succress:^(NSArray *imageArray) {
  619. // [ZCHUDHelper dismiss];
  620. // for (NSDictionary* dict in imageArray) {
  621. // if ([[dict objectForKey:@"type"] isEqualToString:@"album"]) {
  622. // NSString* str = [dict objectForKey:@"url"];
  623. // [self.userModel.userinfo.album_list addObject:str];
  624. // [self.collectionView reloadData];
  625. // [self setupHeaderView];
  626. // }
  627. // }
  628. // }];
  629. // NSMutableArray *images = [NSMutableArray array];
  630. // for (UIImage *image in photos) {
  631. // NSData *data = UIImageJPEGRepresentation(image, 0.2f);
  632. // [images addObject:[UIImage imageWithData:data]];
  633. // }
  634. // 1通过,0待审核,2,未通过
  635. [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  636. [ZCHUDHelper dismiss];
  637. album_list_newModel *model = [album_list_newModel new];
  638. model.youpaipurl = ossImagePaths.firstObject;
  639. model.youpaipstatus = 1;
  640. if (index !=8) {
  641. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list removeObjectAtIndex:index];
  642. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list insertObject:ossImagePaths.firstObject atIndex:index];
  643. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new removeObjectAtIndex:index];
  644. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new insertObject:model atIndex:index];
  645. }else{
  646. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list addObjectsFromArray:ossImagePaths];
  647. [self.youpaipuserModel.youpaipuserinfo.youpaipalbum_list_new addObject:model];
  648. }
  649. [self.youpaipcollectionView reloadData];
  650. [self youpaifsetupHeaderView];
  651. }];
  652. }];
  653. [self presentViewController:imagePickerVc animated:YES completion:nil];
  654. }
  655. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
  656. NSLog(@"%@",photos[0]);
  657. }
  658. @end