| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- //
- // EditSaleSlipSortVC.m
- // IBOSSmini
- //
- // Created by ssl on 2018/2/24.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "EditSaleSlipSortVC.h"
- #import "DragItemInfo.h"
- @interface EditSaleSlipSortVC () <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate>
- /** 数据列表 */
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *titleArray;
- @end
- @implementation EditSaleSlipSortVC
- - (UITableView *)tableView
- {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width,Screen_Height-70) style: UITableViewStyleGrouped];
- _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
- _tableView.dataSource = self;
- _tableView.delegate = self;
-
- [self.view addSubview:_tableView];
- }
- return _tableView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
- if (section == 0){
- [headerView setBackgroundColor:[UIColor whiteColor]];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 6, tableView.bounds.size.width - 10, 18)];
- label.text = @" ";
- label.textColor = [UIColor whiteColor];
- [headerView addSubview:label];
- }
-
- else{
- [headerView setBackgroundColor:[UIColor lightGrayColor]];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 6, tableView.bounds.size.width - 10, 18)];
- label.text = @"更多信息";
- label.textColor = [UIColor whiteColor];
- [headerView addSubview:label];
- }
-
- return headerView;
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 0.1;
- }
- -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
-
- UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 0.1)];
- view.backgroundColor = [UIColor whiteColor];
- return view ;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if(section==0){
- return 10;
- }
- else{
- return 30;
- }
- }
- -(void)initData{
- NSData *encodeTopObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"SalsSlipTopList"];
- _topDataList = [NSKeyedUnarchiver unarchiveObjectWithData:encodeTopObject];
-
- NSData *encodeBottomObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"SalsSlipBottomList"];
- _bottomDataList = [NSKeyedUnarchiver unarchiveObjectWithData:encodeBottomObject];
- if((_topDataList==nil||_topDataList.count==0)&&(_bottomDataList==nil||_bottomDataList.count==0)){
- _topDataList=[[NSMutableArray alloc]init];
- _bottomDataList=[[NSMutableArray alloc]init];
- DragItemInfo *topInfo;
- topInfo =[DragItemInfo new];
- [topInfo setComponentId:1000];
- [topInfo setComponentName:@"客户地址"];
- [_topDataList addObject:topInfo];
- topInfo =[DragItemInfo new];
- [topInfo setComponentId:1001];
- [topInfo setComponentName:@"备 注"];
- [_topDataList addObject:topInfo];
-
- DragItemInfo *bottomItemInfo;
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1002;
- bottomItemInfo.componentName = @"客户性质";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1003;
- bottomItemInfo.componentName = @"使用定金";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1004;
- bottomItemInfo.componentName = @"中间客户";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1005;
- bottomItemInfo.componentName = @"货物总额";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1006;
- bottomItemInfo.componentName = @"合计总额";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1007;
- bottomItemInfo.componentName = @"合同号";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1008;
- bottomItemInfo.componentName = @"联系人";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1009;
- bottomItemInfo.componentName = @"联系方式";
- [_bottomDataList addObject:bottomItemInfo];
-
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1010;
- bottomItemInfo.componentName = @"整单折扣";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1012;
- bottomItemInfo.componentName = @"安装日期";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1013;
- bottomItemInfo.componentName = @"配送日期";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1014;
- bottomItemInfo.componentName = @"楼层";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1015;
- bottomItemInfo.componentName = @"装修进度";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1016;
- bottomItemInfo.componentName = @"重量";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1017;
- bottomItemInfo.componentName = @"总体积";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1018;
- bottomItemInfo.componentName = @"定金比率";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1019;
- bottomItemInfo.componentName = @"标价总额";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1020;
- bottomItemInfo.componentName = @"销售单号";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1021;
- bottomItemInfo.componentName = @"收款金额";
- [_bottomDataList addObject:bottomItemInfo];
-
- bottomItemInfo = [DragItemInfo new];
- bottomItemInfo.componentId = 1022;
- bottomItemInfo.componentName = @"使用预存";
- [_bottomDataList addObject:bottomItemInfo];
- }
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self initData];
- [self initUI];
- [self tableView];
- [self.tableView reloadData];
-
-
- // 开始编辑,一旦editing == YES就默认开启删除模式
- self.tableView.editing = YES;
- }
- -(void)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- self.navigationItem.title = @"编辑排序";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- //右边
- UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
- btnAdd.frame = CGRectMake(0, 0,60,14);
- [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
- [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
- [btnAdd addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
- self.navigationItem.rightBarButtonItem = menubtnAdd;
- }
- -(void)saveData{
- NSData *encodeTopData = [NSKeyedArchiver archivedDataWithRootObject:_topDataList];
- [[NSUserDefaults standardUserDefaults] setObject:encodeTopData forKey:@"SalsSlipTopList"];
- NSData *encodeBottomData = [NSKeyedArchiver archivedDataWithRootObject:_bottomDataList];
- [[NSUserDefaults standardUserDefaults] setObject:encodeBottomData forKey:@"SalsSlipBottomList"];
- [self.orderNav popViewControllerAnimated:YES];
- if([self.refreshDelegate respondsToSelector:@selector(refreshData: bottomDataList:)]){
- [self.refreshDelegate refreshData:_topDataList bottomDataList:_bottomDataList];
- }
- }
- - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 2;
- }
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark - table数据源方法
- /**每组多少行*/
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if(section==0){
- return self.topDataList.count;
- }
- else{
- return self.bottomDataList.count;
- }
- }
- /**设置单元格*/
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *ID = @"SortCell";
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
-
- if (cell == nil) {
-
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
-
- }
-
- NSInteger section= indexPath.section;
- DragItemInfo *item;
- if(section==0){
- item=[_topDataList objectAtIndex:indexPath.row];
- }
- else{
- item=[_bottomDataList objectAtIndex:indexPath.row];
- }
-
- cell.textLabel.text =item.componentName ;
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
-
- NSInteger row= indexPath.row;
- DragItemInfo *item= [_topDataList objectAtIndex:row];
- [self.topDataList removeObject:item];
- [_bottomDataList addObject:item];
-
-
- } else if (editingStyle == UITableViewCellEditingStyleInsert) {
-
- NSInteger row= indexPath.row;
- DragItemInfo *item= [_bottomDataList objectAtIndex:row];
- [self.bottomDataList removeObject:item];
- [_topDataList addObject:item];
-
- }
- [self.tableView reloadData ];
- }
- -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
- return @"删除";
- }
- // 只要实现此方法,就可以显示拖动控件
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
- {
-
- NSInteger sourceSection= sourceIndexPath.section;
- NSInteger destSection=destinationIndexPath.section;
-
- if(sourceSection==0&&destSection==1){
- DragItemInfo *source = _topDataList[sourceIndexPath.row];
- [_topDataList removeObjectAtIndex:(sourceIndexPath.row)];
- [_bottomDataList insertObject:source atIndex:destinationIndexPath.row ];
-
- }
- else if(sourceSection==1&&destSection==0){
- DragItemInfo *source = _bottomDataList[sourceIndexPath.row];
- [_bottomDataList removeObjectAtIndex:(sourceIndexPath.row)];
- [_topDataList insertObject:source atIndex:destinationIndexPath.row ];
- }
- else if(sourceSection==1&&destSection==1){
- DragItemInfo *source = _bottomDataList[sourceIndexPath.row];
- [_bottomDataList removeObjectAtIndex:(sourceIndexPath.row)];
- [_bottomDataList insertObject:source atIndex:destinationIndexPath.row ];
- }
- else if(sourceSection==0&&destSection==0){
- DragItemInfo *source = _topDataList[sourceIndexPath.row];
- [_topDataList removeObjectAtIndex:(sourceIndexPath.row)];
- [_topDataList insertObject:source atIndex:destinationIndexPath.row ];
- }
- [self.tableView reloadData];
-
- }
- #pragma mark - tableView代理方法
- // 返回编辑样式,如果没有实现此方法,默认都是删除
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSInteger section= indexPath.section;
- if(section==0){
- return UITableViewCellEditingStyleDelete;
- }
- else if(section==1){
- return UITableViewCellEditingStyleInsert;
- }
- return UITableViewCellEditingStyleDelete;
- }
- - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
-
- return YES;
-
- }
- @end
|