| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // SelectClassVC.m
- // yunbaolive
- //
- // Created by ybRRR on 2020/3/2.
- // Copyright © 2020 cat. All rights reserved.
- //
- #import "SelectClassVC.h"
- #import "CommodityClassCell.h"
- #import "CommodityClassModel.h"
- @interface SelectClassVC ()<UITableViewDelegate, UITableViewDataSource>
- {
- NSMutableArray *classArray;
- NSMutableArray *selArr;
- }
- @property (nonatomic, strong)UITableView *classTable;
- @property (nonatomic, strong)NSArray *modelArr;
- @end
- @implementation SelectClassVC
- - (UIStatusBarStyle)preferredStatusBarStyle {
- if (@available(iOS 13.0,*)) {
- return UIStatusBarStyleDarkContent;
- }
- return UIStatusBarStyleDefault;
- }
- -(void)initData{
-
- classArray = [NSMutableArray array];
- selArr = [NSMutableArray array];
- selArr = self.havaSelArr;
- }
- -(NSArray *)modelArr{
- NSMutableArray *array = [NSMutableArray array];
-
- for (NSDictionary *dic in classArray) {
- CommodityClassModel *model = [CommodityClassModel modelWithDic:dic];
- [array addObject:model];
- }
- _modelArr = array;
- return _modelArr;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.titleL.text = YZMsg(@"经营类目设置");
-
- self.view.backgroundColor =UIColor.whiteColor;// RGB(250, 250, 250);
- self.subNavi.backgroundColor = UIColor.whiteColor;
- self.titleL.textColor = UIColor.blackColor;
- [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
- self.naviLine.hidden = NO;
- self.naviLine.backgroundColor = RGB(245, 245, 245);
- [self initData];
- [self.view addSubview:self.classTable];
- [self addBottomView];
- [self requestData];
-
- }
- -(UITableView *)classTable{
- if (!_classTable) {
- _classTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-60) style:UITableViewStylePlain];
- _classTable.delegate = self;
- _classTable.dataSource = self;
- _classTable.separatorStyle = 0;
- _classTable.backgroundColor = UIColor.whiteColor;
- }
- return _classTable;
- }
- -(void)addBottomView{
- UIButton *sureBtn = [UIButton buttonWithType:0];
- sureBtn.frame = CGRectMake(15, _window_height-60, _window_width-30, 45);
- [sureBtn setBackgroundColor:Pink_Cor];
- sureBtn.layer.cornerRadius = 5;
- sureBtn.layer.masksToBounds = YES;
- [sureBtn setTitle:YZMsg(@"提交") forState:0];
- sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- [sureBtn setTitleColor:[UIColor whiteColor] forState:0];
- [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:sureBtn];
- }
- -(void)sureBtnClick{
- if (selArr.count < 1) {
- [MBProgressHUD showError:YZMsg(@"请选择经营类目")];
- return;
- }
- if (self.classEvent) {
- self.classEvent(selArr);
- }
- [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
- }
- #pragma mark ------数据请求----------
- -(void)requestData{
- [YBNetworking postWithUrl:@"Shop.getOneGoodsClass" Dic:nil Suc:^(int code, id info, NSString *msg) {
- if (code ==0) {
- classArray = info;
- [self.classTable reloadData];
- }else{
- [MBProgressHUD showError:msg];
- }
- } Fail:^(id fail) {
-
- }];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.modelArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- CommodityClassCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommodityClassCell"];
- if (!cell) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"CommodityClassCell" owner:nil options:nil] lastObject];
- }
- CommodityClassModel *allmodel =self.modelArr[indexPath.row];
- for (CommodityClassModel *model in selArr) {
- if ([model.idStr isEqual:allmodel.idStr]) {
- allmodel.gc_isshow = @"0";
- }
- }
- cell.models = allmodel;
- cell.contentView.backgroundColor = UIColor.whiteColor;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 90)];
- view.backgroundColor = UIColor.whiteColor;
- UIView *backView = [[UIView alloc]init];
- backView.frame = CGRectMake(0, 0, _window_width, 50);
- backView.backgroundColor = UIColor.whiteColor;
- [view addSubview:backView];
-
- UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(12, 10, _window_width-20, 30)];
- label.font = [UIFont systemFontOfSize:13];
- label.textColor = UIColor.blackColor;// RGB(150, 150, 150);
- label.text = YZMsg(@"请谨慎选择,主营类目设置成功后将不可更改");
- [backView addSubview:label];
-
- UILabel *lb = [[UILabel alloc]init];
- lb.frame = CGRectMake(12, backView.bottom+5, _window_width, 30);
- lb.font = [UIFont systemFontOfSize:16];
- lb.textColor = UIColor.blackColor;// RGB(150, 150, 150);
- lb.text = YZMsg(@"选择主营类目");
- [view addSubview:lb];
-
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 90;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 50;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [self.classTable deselectRowAtIndexPath:indexPath animated:YES];
- CommodityClassModel *model = self.modelArr[indexPath.row];
- __block NSInteger indexsss;
- __block BOOL isExist = NO;
- [selArr enumerateObjectsUsingBlock:^(CommodityClassModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj.idStr isEqualToString:model.idStr]) {//数组中已经存在该对象
- *stop = YES;
- isExist = YES;
- indexsss = idx;
- }
- }];
- if (!isExist) {
- //如果不存在就添加进去
- [selArr addObject:model];
- }else{
- [selArr removeObjectAtIndex:indexsss];
- }
- [self.classTable reloadData];
- NSLog(@"----------selarr:-----1111:%@",selArr);
- }
- @end
|