You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

234 lines
10 KiB

//
// MemberListViewController.m
// LekangGuard
//
// Created by ecell on 2023/8/29.
//
#import "MemberListViewController.h"
#import "MemberListTableViewCell.h"
#import "AmendContactsViewController.h"
@interface MemberListViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic ,strong) CommonTableView *listTable;
/// 用户身份(0:游客,1:普通用户(关注的人),2:管理员)
@property (nonatomic ,assign) NSInteger identity;
@end
@implementation MemberListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = KKBackgroundGrey;
[self.view addSubview:self.listTable];
[self.listTable mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
[self GetQueryAddressList];
}
- (CommonTableView *)listTable
{
if (!_listTable)
{
_listTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:88 cellRow:0 isAdaptive:NO isLine:NO commonCell:MemberListTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) {
MemberListTableViewCell *cell = (MemberListTableViewCell *)cells;
cell.contactsModel = self.modelListArr[indexPath.row];
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
ContactsModel *contacts = self.modelListArr[indexPath.row];
if(self.identity == 2)/// 如果自己是管理员可操作其他联系人
{
//如果自己是管理员
kWeakSelf(self)
//是自己---直接跳
if([contacts.openId isEqualToString:APIManager.sharedManager.loginModel.openid]){
[self jumpContactVCWith:contacts];
return;
}
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:nil subtitle:F(@"%@ %@",GJText(@"联系人"),contacts.name) AlertViewType:AlertViewTypeSystemActionSheet config:nil];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil];
}];
[alertV addAlertItemWithTitle:GJText(@"删除") type:AlertItemTypeSystemDestructive callback:^(EasyAlertView *showview, long index) {
[weakself deleteContactFuntionWith:@[contacts.Id]];
}];
if(contacts.identity != 2 && contacts.openId)
{
[alertV addAlertItemWithTitle:GJText(@"设置为管理员") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
NSString *msg = [NSString stringWithFormat:@"%@ %@ ?",GJText(@"您将管理员转给用户"),contacts.relation];
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"提示") subtitle:msg AlertViewType:AlertViewTypeSystemAlert config:nil];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil];
}];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
[weakself SetAdmin:contacts.Id identity:2];
}];
}];
[alertV showAlertView];
}];
}
if(contacts.setBind == 0)
{
[alertV addAlertItemWithTitle:GJText(@"编辑联系人") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
[weakself jumpContactVCWith:contacts];
}];
}
[alertV showAlertView];
}
else
{
//成员
//是自己---直接跳
if([contacts.openId isEqualToString:APIManager.sharedManager.loginModel.openid])
{
[self jumpContactVCWith:contacts];
return;
}
else if(contacts.openId)
{
// 非自己的成员(也包括管理员)
return;
}
else
{
//普通联系人
kWeakSelf(self)
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:nil subtitle:[NSString stringWithFormat:@"%@ %@",GJText(@"联系人"),contacts.name] AlertViewType:AlertViewTypeSystemActionSheet config:nil];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil];
}];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"删除") type:AlertItemTypeSystemDestructive callback:^(EasyAlertView *showview, long index) {
[weakself deleteContactFuntionWith:@[contacts.Id]];
}];
}];
[alertV addAlertItemWithTitleArray:@[GJText(@"编辑联系人")] callback:^(EasyAlertView *showview, long index) {
NSLog(@"%ld",index);
[weakself jumpContactVCWith:contacts];
}];
[alertV showAlertView];
}
}
} DidscrollView:^(UIScrollView * _Nonnull scrollView) {
}];
_listTable.backgroundColor = KKClearColor;
}
return _listTable;
}
#pragma mark 查询通讯录成员
/// 查询通讯录成员
- (void)GetQueryAddressList
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:QueryAddressList_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) {
[UICommon HidenLoading];
if (ARRAYHASVALUE(arr))
{
[self.modelListArr removeAllObjects];
for (NSDictionary *dic in arr)
{
ContactsModel *model = [ContactsModel yy_modelWithJSON:dic];
if ([model.openId isEqualToString:APIManager.sharedManager.loginModel.openid])
self.identity = model.identity;
model.isSelect = NO;
if (model.setBind == 1)
[self.modelListArr addObject:model];
}
}
self.listTable.cellRow = self.modelListArr.count;
[self.listTable reloadData];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 跳转到 修改/添加 联系人 页面
- (void)jumpContactVCWith:(ContactsModel*)contacts
{
AmendContactsViewController *vc = [AmendContactsViewController new];
vc.conModel = contacts;
vc.isUpdateSucceed = ^{
[self GetQueryAddressList];
};
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
vc.zx_navTitle = @"修改家庭成员";
}
#pragma mark 删除
/// 删除
- (void)deleteContactFuntionWith:(NSArray *)IdArr
{
if(IdArr.count == 0)
{
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:GJText(@"注意") message:GJText(@"请选择要删除的联系人") style:LGAlertViewStyleAlert buttonTitles:@[GJText(@"确定")] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView * _Nonnull alertView, NSUInteger index, NSString * _Nullable title) {} cancelHandler:^(LGAlertView * _Nonnull alertView) {} destructiveHandler:^(LGAlertView * _Nonnull alertView) {}];
[alertView showAnimated:YES completionHandler:nil];
return;
}
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:GJText(@"注意") message:F(GJText(@"确认要删除%ld个联系人?"),IdArr.count) style:LGAlertViewStyleAlert buttonTitles:@[GJText(@"确定")] cancelButtonTitle:GJText(@"取消") destructiveButtonTitle:nil actionHandler:^(LGAlertView * _Nonnull alertView, NSUInteger index, NSString * _Nullable title) {
[UICommon MessageUpload:@"加载中"];
[[[APIManager sharedManager] PostBodyWithApi:F(@"%@?imei=%@", DelBatchAddress_URL,APIManager.sharedManager.deviceModel.imei) json:[IdArr yy_modelToJSONString]] subscribeNext:^(id _Nullable x) {
[UICommon MessageSuccessText:@"删除成功"];
[self GetQueryAddressList];
} completed:^{
}];
} cancelHandler:^(LGAlertView * _Nonnull alertView) {} destructiveHandler:^(LGAlertView * _Nonnull alertView) {}];
[alertView showAnimated:YES completionHandler:nil];
}
#pragma mark 转让管理员
/// 转让管理员
- (void)SetAdmin:(NSString *)Id identity:(NSInteger)identity
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:Id forKey:@"id"];
[parameters setValue:@(identity) forKey:@"identity"];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APPOST:SetAdmin_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
[UICommon MessageSuccessText:@"管理员转让成功"];
[self GetQueryAddressList];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end