Files
yinmeng-ios/xplan-ios/Main/Room/PrivilegeCard/View/XPPrivilegeCardVC.m
2023-08-18 14:52:57 +08:00

290 lines
12 KiB
Objective-C

//
// XPPrivilegeCardVC.m
// xplan-ios
//
// Created by duoban on 2023/7/24.
//
#import "XPPrivilegeCardVC.h"
#import "XPPrivilegeCardPresenter.h"
#import <JXCategoryView/JXCategoryView.h>
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
#import <JXCategoryView/JXCategoryListContainerView.h>
#import "XPPrivilegeCardItemVC.h"
#import "UploadImage.h"
#import "Api+Mine.h"
#import "XPPrivilegeCardTitlView.h"
#import "XPPrivilegeCardProduceView.h"
#import <TZImagePickerController/TZImagePickerController.h>
#import "XPPrivilegeCardConfirmView.h"
#import "XPPrivilegeCardProtocol.h"
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
@interface XPPrivilegeCardVC ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate,XPPrivilegeCardProduceViewDelegate,TZImagePickerControllerDelegate,XPPrivilegeCardItemVCDelegate>
///分页标题
@property (nonatomic, strong) NSArray<NSString *> *titles;
///分页控件
@property (nonatomic, strong) XPPrivilegeCardTitlView *titleView;
///分页lineView
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
///新建
@property(nonatomic,strong) UIButton *newBtn;
///图片的上传链接
@property (nonatomic,strong) NSArray *uploadImageList;
///新建
@property(nonatomic,strong) XPPrivilegeCardProduceView *produceView;
@end
@implementation XPPrivilegeCardVC
- (__kindof id)createPresenter {
return [[XPPrivilegeCardPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self installUI];
[self installConstraints];
}
-(void)installUI{
self.title = @"特权卡";
[self.view addSubview:self.titleView];
[self.view addSubview:self.contentView];
[self.view addSubview:self.newBtn];
}
-(void)installConstraints{
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(62));
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.titleView.mas_bottom);
make.left.right.bottom.mas_equalTo(self.view);
}];
[self.newBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(15));
make.width.mas_equalTo(kGetScaleWidth(60));
make.height.mas_equalTo(kGetScaleWidth(28));
make.centerY.equalTo(self.titleView);
}];
}
#pragma mark - JXCategoryViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
UIViewController<JXCategoryListContentViewDelegate> * list = (UIViewController<JXCategoryListContentViewDelegate> *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];
if (list) {
return list;
} else {
XPPrivilegeCardItemVC *vc = [XPPrivilegeCardItemVC new];
vc.roomUid = self.roomUid;
vc.delegate = self;
vc.cardStatus = index == 0 ? @"" : @(index-1).stringValue;
return vc;
}
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
}
-(void)creatViewAction{
self.produceView.cardModel = nil;
self.uploadImageList = @[];
[kWindow addSubview:self.produceView];
}
#pragma mark - XPPrivilegeCardProduceViewDelegate
///确认
-(void)verifyCreatPrivilegeCardWithParameter:(NSDictionary *_Nonnull)parameter{
if(self.uploadImageList.count == 0 && self.produceView.cardModel.cardUrl.length == 0){
[self showErrorToast:@"请选择特权卡图片"];
return;
}
NSString *cardName = parameter[@"cardName"];
NSString *dailyNum = parameter[@"dailyNum"];
NSString *description = parameter[@"description"];
NSString *effectTime = parameter[@"effectTime"];
NSString *erbanNoStr = parameter[@"erbanNoStr"];
XPPrivilegeCardConfirmView *confirmView = [[XPPrivilegeCardConfirmView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
@kWeakify(self);
confirmView.text = @"确认卡片信息填写是否正确\n审核通过后卡片将生效";
confirmView.confirmHanle = ^{
@kStrongify(self);
[self showLoading];
if(self.produceView.cardModel.cardUrl.length > 0){
[self.presenter savePrivilegeCardWittCardName:cardName dailyNum:dailyNum description:description effectDay:effectTime erbanNoStr:erbanNoStr cardUrl:self.produceView.cardModel.cardUrl roomUid:self.roomUid];
return;
}
[self uploadAlbumPicList:self.uploadImageList finish:^(NSArray *list) {
if(list.count == 0){
[self hideHUD];
[self showErrorToast:@"上传图片失败,请重新上传"];
return;
}
[self.presenter savePrivilegeCardWittCardName:cardName dailyNum:dailyNum description:description effectDay:effectTime erbanNoStr:erbanNoStr cardUrl:list.firstObject roomUid:self.roomUid];
}];
};
[TTPopup popupView:confirmView style:TTPopupStyleAlert];
}
///上传图片
-(void)uploadPictures{
[self.view endEditing:YES];
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
imagePickerVc.modalPresentationStyle = UIModalPresentationOverFullScreen;
imagePickerVc.allowPickingVideo = NO;
imagePickerVc.allowTakeVideo = NO;
imagePickerVc.allowPickingGif = YES;
imagePickerVc.maxImagesCount = 1;
imagePickerVc.naviBgColor = [ThemeColor appCellBackgroundColor];
imagePickerVc.naviTitleColor = [ThemeColor mainTextColor];
imagePickerVc.barItemTextColor = [ThemeColor mainTextColor];
[self presentViewController:imagePickerVc animated:YES completion:nil];
}
-(void)delPictures{
self.uploadImageList = @[];
}
# pragma mark - TZImagePickerControllerDelegate
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
if(photos.count > 0){
self.produceView.chooseImage = photos.firstObject;
}
self.uploadImageList = photos;
}
#pragma mark - XPPrivilegeCardProtocol
-(void)savePrivilegeCardSuccess{
[self hideHUD];
[XCHUDTool showSuccessWithMessage:@"提交成功"];
[self.produceView removeFromSuperview];
[[NSNotificationCenter defaultCenter]postNotificationName:@"kSavePrivilegeCardSuccess" object:nil];
}
-(void)deletePrivilegeCardSuccess{
[XCHUDTool showSuccessWithMessage:@"删除成功"];
[[NSNotificationCenter defaultCenter]postNotificationName:@"kSavePrivilegeCardSuccess" object:nil];
}
- (void)uploadAlbumPicList:(NSArray *)array finish:(void(^)(NSArray *list))finish {
for (UIImage * image in array) {
[Api qiniuUpLoadImage:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
NSString *key = data.data[@"key"];
NSString *token = data.data[@"token"];
[UploadImage uploadImage:image named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
NSString *path = resp[@"path"];
if(path != nil){
dispatch_async(dispatch_get_main_queue(), ^{
finish(@[path]);
});
}
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
dispatch_async(dispatch_get_main_queue(), ^{
finish(@[]);
});
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
finish(@[]);
});
}
}];
}
}
-(void)savePrivilegeCardFail{
[self hideHUD];
}
#pragma XPPrivilegeCardItemVCDelegate
///删除
-(void)deleteExpiredPrivilegeCardWithVC:(XPPrivilegeCardItemVC *_Nullable)VC cardModel:(XPPrivilegeCardItemModel *_Nullable)cardModel{
[self.presenter deletePrivilegeCardWithID:cardModel.ID];
}
///重新编辑
-(void)againEditPrivilegeCardWithCell:(XPPrivilegeCardItemVC *_Nullable)VC cardModel:(XPPrivilegeCardItemModel *_Nullable)cardModel{
self.produceView.cardModel = cardModel;
self.uploadImageList = @[];
[kWindow addSubview:self.produceView];
}
#pragma mark - Getters And Setters
- (XPPrivilegeCardTitlView *)titleView {
if (!_titleView) {
_titleView = [[XPPrivilegeCardTitlView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.titles;
_titleView.backgroundColor = [UIColor clearColor];
_titleView.titleColor = UIColorFromRGB(0xA2A7B8);
_titleView.titleSelectedColor = UIColorFromRGB(0x2B2D33);
_titleView.titleFont = kFontMedium(13);
_titleView.titleSelectedFont = kFontSemibold(14);
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.cellSpacing = kGetScaleWidth(15);
_titleView.cellWidth = kGetScaleWidth(39);
_titleView.averageCellSpacingEnabled = NO;
_titleView.defaultSelectedIndex = 0;
_titleView.listContainer = self.contentView;
JXCategoryIndicatorBackgroundView * indocator = [[JXCategoryIndicatorBackgroundView alloc] init];
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFDA24),UIColorFromRGB(0xFFDA24),UIColorFromRGB(0xFFDA24)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(12), kGetScaleWidth(4))];
indocator.indicatorColor = [UIColor colorWithPatternImage:image];
indocator.indicatorWidth = kGetScaleWidth(12);
indocator.indicatorHeight = kGetScaleWidth(4);
indocator.verticalMargin = -kGetScaleWidth(12);
indocator.indicatorWidthIncrement = 0;
[indocator setCornerWithLeftTopCorner:kGetScaleWidth(2) rightTopCorner:0 bottomLeftCorner:kGetScaleWidth(2) bottomRightCorner:kGetScaleWidth(2) size:CGSizeMake(kGetScaleWidth(12), kGetScaleWidth(4))];
_titleView.indicators = @[indocator];
}
return _titleView;
}
- (NSArray<NSString *> *)titles{
return @[@"全部",@"审核中",@"生效中",@"未通过",@"已过期"];
}
- (JXCategoryListContainerView *)contentView {
if (!_contentView) {
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_contentView.defaultSelectedIndex = 0;
}
return _contentView;
}
- (UIButton *)newBtn{
if(!_newBtn){
_newBtn = [UIButton new];
[_newBtn setTitle:@"新建" forState:UIControlStateNormal];
[_newBtn setTitleColor:UIColorFromRGB(0x2B2D33) forState:UIControlStateNormal];
_newBtn.titleLabel.font = kFontMedium(13);
_newBtn.backgroundColor = UIColorFromRGB(0xFFDA24);
[_newBtn setImage:kImage(@"room_Privilege_Card_create") forState:UIControlStateNormal];
[_newBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0,kGetScaleWidth(7))];
_newBtn.layer.cornerRadius = kGetScaleWidth(6);
_newBtn.layer.masksToBounds = YES;
[_newBtn addTarget:self action:@selector(creatViewAction) forControlEvents:UIControlEventTouchUpInside];
}
return _newBtn;
}
- (XPPrivilegeCardProduceView *)produceView{
if(!_produceView){
_produceView = [[XPPrivilegeCardProduceView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_produceView.delegate = self;
}
return _produceView;
}
@end