123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- //
- // YOUPAIMineLabelEditVC.m
- // MSYOUPAI
- //
- // Created by admin on 2022/3/2.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAIMineLabelEditVC.h"
- #import "YOUPAIZYLabelModel.h"
- @interface YOUPAIMineLabelEditVC ()
- @property(strong,nonatomic) NSMutableArray*selectids;
- @property(strong,nonatomic) NSMutableArray<YOUPAIZYLabelModel*>*selectData;
- @property(strong,nonatomic) NSMutableArray<YOUPAIZYLabelModel*>*dataSouce;
- @end
- @implementation YOUPAIMineLabelEditVC
- -(UICollectionViewFlowLayout *)youpaipflowLayout{
- if (_youpaipflowLayout == nil){
- _youpaipflowLayout = [UICollectionViewFlowLayout new];
- _youpaipflowLayout.minimumLineSpacing = 4;
- _youpaipflowLayout.minimumInteritemSpacing = 4;
- _youpaipflowLayout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
- }
- return _youpaipflowLayout;
- }
- -(UICollectionViewFlowLayout *)youpaipSelectflowLayout{
- if (_youpaipSelectflowLayout == nil){
- _youpaipSelectflowLayout = [UICollectionViewFlowLayout new];
- _youpaipSelectflowLayout.minimumLineSpacing = 4;
- _youpaipSelectflowLayout.minimumInteritemSpacing = 4;
- _youpaipSelectflowLayout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
- }
- return _youpaipSelectflowLayout;
- }
- -(UICollectionView *)youpaipcollectionView{
- if (_youpaipcollectionView == nil){
- _youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.youpaipflowLayout];
- _youpaipcollectionView.dataSource = self;
- _youpaipcollectionView.delegate = self;
- _youpaipcollectionView.backgroundColor = UIColor.whiteColor;
- [_youpaipcollectionView registerClass:[YOUPAIMineLabelEditCell class] forCellWithReuseIdentifier:@"YOUPAIMineLabelEditCell"];
-
- }
- return _youpaipcollectionView;
- }
- -(UICollectionView *)youpaipSelectcollectionView{
- if (_youpaipSelectcollectionView == nil){
- _youpaipSelectcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.youpaipSelectflowLayout];
- _youpaipSelectcollectionView.dataSource = self;
- _youpaipSelectcollectionView.delegate = self;
- [_youpaipSelectcollectionView registerClass:[YOUPAIMineLabelEditCell class] forCellWithReuseIdentifier:@"YOUPAIMineLabelEditCell"];
- _youpaipSelectcollectionView.backgroundColor = UIColor.clearColor;
- }
- return _youpaipSelectcollectionView;
- }
- -(UIBarButtonItem *)rightItem{
- if (_rightItem == nil){
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(youpaifdidSave) forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 56, 24);
- [button setTitle:@"保存" forState:0];
- [button setTitleColor:LZA3AABEColor forState:0];
- // [button setBackgroundColor:HexColorFromRGB(0xFF5CA2)];
- button.titleLabel.font = LCFont14;
- button.layer.cornerRadius = 12;
- button.layer.masksToBounds = YES;
- [self.view addSubview:button];
- // 设置rightBarButtonItem
- _rightItem = [[UIBarButtonItem alloc] initWithCustomView:button];
- }
- return _rightItem;
- }
- -(void)youpaifdidSave{
- if(_didFinishSaveBlock){
-
- _didFinishSaveBlock(self.selectData);
- [self.navigationController popViewControllerAnimated:true];
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"我的标签";
- self.navigationItem.rightBarButtonItem = self.rightItem;
- self.selectData = [NSMutableArray new];
- self.selectids = [NSMutableArray new];
- self.dataSouce = [NSMutableArray new];
- [self ypupaifgetuserLable];
- [self configUI];
- [self makeLayout];
-
-
- }
- -(void)reloadData{
- [self.selectData removeAllObjects];
- for (YOUPAIZYLabelModel *item in self.dataSouce) {
- if ([self.selectids containsObject:item.youpaiptag_id]){
- [self.selectData addObject:item];
- }
- }
- [_youpaipSelectcollectionView reloadData];
- [_youpaipcollectionView reloadData];
-
- }
- -(void)configUI{
- [self.view addSubview:self.youpaipSelectcollectionView];
- [self.view addSubview:self.youpaipcollectionView];
- }
- -(void)makeLayout{
- [_youpaipSelectcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0).mas_offset(NavBarHeight);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(224);
- }];
- [_youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaipSelectcollectionView.mas_bottom);
- make.left.right.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- }];
- [self.view layoutIfNeeded];
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:_youpaipcollectionView size:CGSizeMake(16, 16)];
- }
- -(void)ypupaifgetuserLable{
-
- @weakify(self);
- NSDictionary *params = @{};
- [LCHttpHelper requestWithURLString:api_getUserTag
- parameters:params
- needToken:YES
- type:(HttpRequestTypePost)
- success:^(id responseObject) {
-
- @strongify(self);
-
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSDictionary *dic = [dict objectForKey:@"data"];
- [self.dataSouce removeAllObjects];
- for (NSDictionary *item in dic[@"tag_list"]) {
- YOUPAIZYLabelModel *data = [YOUPAIZYLabelModel mj_objectWithKeyValues:item];
- NSArray *colors = [item[@"color"] componentsSeparatedByString:@","];
- data.youpaipstart_color = colors.firstObject;
- data.youpaipover_color = colors.lastObject;
- [self.dataSouce addObject:data];
- }
-
- for (NSDictionary *item in dic[@"user_tag"]) {
- [self.selectids addObject:[NSString stringWithFormat:@"%@",item[@"id"]]];
- }
- [self reloadData];
- }
- } failure:^(NSError *error) {
-
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- // MARK: delegate
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- if (collectionView == _youpaipSelectcollectionView){
- return _selectData.count;
- }else{
- return _dataSouce.count;
- }
- }
- -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- if (collectionView == _youpaipSelectcollectionView){
- YOUPAIMineLabelEditCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIMineLabelEditCell" forIndexPath:indexPath];
- YOUPAIZYLabelModel*dic = _selectData[indexPath.row];
- cell.youpaipLabel.text = dic.youpaipname;
- cell.youpaipLabel.textColor = [UIColor colorWithHexString:dic.youpaipover_color];
- cell.youpaipLabel.backgroundColor = [UIColor colorWithHexString:dic.youpaipstart_color];
- [cell.youpaipXBtn setHidden:NO];
- return cell;
- }else{
- YOUPAIMineLabelEditCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIMineLabelEditCell" forIndexPath:indexPath];
- YOUPAIZYLabelModel*dic = _dataSouce[indexPath.row];
- cell.youpaipLabel.text = dic.youpaipname;
-
- if([self.selectids containsObject:dic.youpaiptag_id]){
- cell.youpaipLabel.textColor = [UIColor colorWithHexString:dic.youpaipover_color];
- cell.youpaipLabel.backgroundColor = [UIColor colorWithHexString:dic.youpaipstart_color];
- }else{
- cell.youpaipLabel.backgroundColor = LZFAFAFCColor;
- cell.youpaipLabel.textColor = LZ273145Color;
- }
- [cell.youpaipXBtn setHidden:YES];
- return cell;
- }
-
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAIZYLabelModel *item = nil;
- if (collectionView == _youpaipcollectionView){
- item = _dataSouce[indexPath.row];
- }else{
- item = _selectData[indexPath.row];
- }
- NSString *title = item.youpaipname;
- CGSize size = [title sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]}];
- size.width += 24;
- size.height += 12;
- return size;
-
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if (collectionView == _youpaipSelectcollectionView){
- YOUPAIZYLabelModel* item = _selectData[indexPath.row];
-
-
- [self.selectids removeObject:item.youpaiptag_id];
- [self reloadData];
- }else{
- YOUPAIZYLabelModel* item = _dataSouce[indexPath.row];
- if ([_selectData containsObject:item]){
- return;
- }
- [self.selectids addObject:item.youpaiptag_id];
- [self reloadData];
- }
- }
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
- if (collectionView == _youpaipSelectcollectionView){
- return UIEdgeInsetsMake(20, 12, 0, 12);
- }else{
- return UIEdgeInsetsMake(20, 12, 0, 12);
- }
- }
- @end
- @implementation YOUPAIMineLabelEditCell
- -(UGLabel *)youpaipLabel{
- if (_youpaipLabel == nil){
- _youpaipLabel = [UGLabel new];
- _youpaipLabel.textColor = UIColor.whiteColor;
- _youpaipLabel.textAlignment = NSTextAlignmentCenter;
- _youpaipLabel.font = [UIFont systemFontOfSize:12];
- [_youpaipLabel ms_radius:14];
-
- }
- return _youpaipLabel;
- }
- -(UIButton *)youpaipXBtn{
- if(_youpaipXBtn == nil){
- _youpaipXBtn = [UIButton new];
- [_youpaipXBtn setImage:[UIImage imageNamed:@"vqu_images_editmineinfo_delete"] forState:UIControlStateNormal];
- [_youpaipXBtn setEnabled:NO];
- }
- return _youpaipXBtn;
- }
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self == [super initWithFrame:frame]){
- [self.contentView addSubview:self.youpaipLabel];
- [self.contentView addSubview:self.youpaipXBtn];
- [self makeLayout];
-
- }
- return self;
- }
- -(void)makeLayout{
- [_youpaipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.mas_equalTo(0);
- }];
- [_youpaipXBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.right.mas_equalTo(0);
- make.size.mas_equalTo(13);
- }];
- }
- @end
|