EditSaleSlipSortVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //
  2. // EditSaleSlipSortVC.m
  3. // IBOSSmini
  4. //
  5. // Created by ssl on 2018/2/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "EditSaleSlipSortVC.h"
  9. #import "DragItemInfo.h"
  10. @interface EditSaleSlipSortVC () <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate>
  11. /** 数据列表 */
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *titleArray;
  14. @end
  15. @implementation EditSaleSlipSortVC
  16. - (UITableView *)tableView
  17. {
  18. if (_tableView == nil) {
  19. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width,Screen_Height-70) style: UITableViewStyleGrouped];
  20. _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  21. _tableView.dataSource = self;
  22. _tableView.delegate = self;
  23. [self.view addSubview:_tableView];
  24. }
  25. return _tableView;
  26. }
  27. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  28. {
  29. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
  30. if (section == 0){
  31. [headerView setBackgroundColor:[UIColor whiteColor]];
  32. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 6, tableView.bounds.size.width - 10, 18)];
  33. label.text = @" ";
  34. label.textColor = [UIColor whiteColor];
  35. [headerView addSubview:label];
  36. }
  37. else{
  38. [headerView setBackgroundColor:[UIColor lightGrayColor]];
  39. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 6, tableView.bounds.size.width - 10, 18)];
  40. label.text = @"更多信息";
  41. label.textColor = [UIColor whiteColor];
  42. [headerView addSubview:label];
  43. }
  44. return headerView;
  45. }
  46. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  47. {
  48. return 0.1;
  49. }
  50. -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  51. UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 0.1)];
  52. view.backgroundColor = [UIColor whiteColor];
  53. return view ;
  54. }
  55. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  56. {
  57. if(section==0){
  58. return 10;
  59. }
  60. else{
  61. return 30;
  62. }
  63. }
  64. -(void)initData{
  65. NSData *encodeTopObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"SalsSlipTopList"];
  66. _topDataList = [NSKeyedUnarchiver unarchiveObjectWithData:encodeTopObject];
  67. NSData *encodeBottomObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"SalsSlipBottomList"];
  68. _bottomDataList = [NSKeyedUnarchiver unarchiveObjectWithData:encodeBottomObject];
  69. if((_topDataList==nil||_topDataList.count==0)&&(_bottomDataList==nil||_bottomDataList.count==0)){
  70. _topDataList=[[NSMutableArray alloc]init];
  71. _bottomDataList=[[NSMutableArray alloc]init];
  72. DragItemInfo *topInfo;
  73. topInfo =[DragItemInfo new];
  74. [topInfo setComponentId:1000];
  75. [topInfo setComponentName:@"客户地址"];
  76. [_topDataList addObject:topInfo];
  77. topInfo =[DragItemInfo new];
  78. [topInfo setComponentId:1001];
  79. [topInfo setComponentName:@"备 注"];
  80. [_topDataList addObject:topInfo];
  81. DragItemInfo *bottomItemInfo;
  82. bottomItemInfo = [DragItemInfo new];
  83. bottomItemInfo.componentId = 1002;
  84. bottomItemInfo.componentName = @"客户性质";
  85. [_bottomDataList addObject:bottomItemInfo];
  86. bottomItemInfo = [DragItemInfo new];
  87. bottomItemInfo.componentId = 1003;
  88. bottomItemInfo.componentName = @"使用定金";
  89. [_bottomDataList addObject:bottomItemInfo];
  90. bottomItemInfo = [DragItemInfo new];
  91. bottomItemInfo.componentId = 1004;
  92. bottomItemInfo.componentName = @"中间客户";
  93. [_bottomDataList addObject:bottomItemInfo];
  94. bottomItemInfo = [DragItemInfo new];
  95. bottomItemInfo.componentId = 1005;
  96. bottomItemInfo.componentName = @"货物总额";
  97. [_bottomDataList addObject:bottomItemInfo];
  98. bottomItemInfo = [DragItemInfo new];
  99. bottomItemInfo.componentId = 1006;
  100. bottomItemInfo.componentName = @"合计总额";
  101. [_bottomDataList addObject:bottomItemInfo];
  102. bottomItemInfo = [DragItemInfo new];
  103. bottomItemInfo.componentId = 1007;
  104. bottomItemInfo.componentName = @"合同号";
  105. [_bottomDataList addObject:bottomItemInfo];
  106. bottomItemInfo = [DragItemInfo new];
  107. bottomItemInfo.componentId = 1008;
  108. bottomItemInfo.componentName = @"联系人";
  109. [_bottomDataList addObject:bottomItemInfo];
  110. bottomItemInfo = [DragItemInfo new];
  111. bottomItemInfo.componentId = 1009;
  112. bottomItemInfo.componentName = @"联系方式";
  113. [_bottomDataList addObject:bottomItemInfo];
  114. bottomItemInfo = [DragItemInfo new];
  115. bottomItemInfo.componentId = 1010;
  116. bottomItemInfo.componentName = @"整单折扣";
  117. [_bottomDataList addObject:bottomItemInfo];
  118. bottomItemInfo = [DragItemInfo new];
  119. bottomItemInfo.componentId = 1012;
  120. bottomItemInfo.componentName = @"安装日期";
  121. [_bottomDataList addObject:bottomItemInfo];
  122. bottomItemInfo = [DragItemInfo new];
  123. bottomItemInfo.componentId = 1013;
  124. bottomItemInfo.componentName = @"配送日期";
  125. [_bottomDataList addObject:bottomItemInfo];
  126. bottomItemInfo = [DragItemInfo new];
  127. bottomItemInfo.componentId = 1014;
  128. bottomItemInfo.componentName = @"楼层";
  129. [_bottomDataList addObject:bottomItemInfo];
  130. bottomItemInfo = [DragItemInfo new];
  131. bottomItemInfo.componentId = 1015;
  132. bottomItemInfo.componentName = @"装修进度";
  133. [_bottomDataList addObject:bottomItemInfo];
  134. bottomItemInfo = [DragItemInfo new];
  135. bottomItemInfo.componentId = 1016;
  136. bottomItemInfo.componentName = @"重量";
  137. [_bottomDataList addObject:bottomItemInfo];
  138. bottomItemInfo = [DragItemInfo new];
  139. bottomItemInfo.componentId = 1017;
  140. bottomItemInfo.componentName = @"总体积";
  141. [_bottomDataList addObject:bottomItemInfo];
  142. bottomItemInfo = [DragItemInfo new];
  143. bottomItemInfo.componentId = 1018;
  144. bottomItemInfo.componentName = @"定金比率";
  145. [_bottomDataList addObject:bottomItemInfo];
  146. bottomItemInfo = [DragItemInfo new];
  147. bottomItemInfo.componentId = 1019;
  148. bottomItemInfo.componentName = @"标价总额";
  149. [_bottomDataList addObject:bottomItemInfo];
  150. bottomItemInfo = [DragItemInfo new];
  151. bottomItemInfo.componentId = 1020;
  152. bottomItemInfo.componentName = @"销售单号";
  153. [_bottomDataList addObject:bottomItemInfo];
  154. bottomItemInfo = [DragItemInfo new];
  155. bottomItemInfo.componentId = 1021;
  156. bottomItemInfo.componentName = @"收款金额";
  157. [_bottomDataList addObject:bottomItemInfo];
  158. bottomItemInfo = [DragItemInfo new];
  159. bottomItemInfo.componentId = 1022;
  160. bottomItemInfo.componentName = @"使用预存";
  161. [_bottomDataList addObject:bottomItemInfo];
  162. }
  163. }
  164. - (void)viewDidLoad
  165. {
  166. [super viewDidLoad];
  167. [self initData];
  168. [self initUI];
  169. [self tableView];
  170. [self.tableView reloadData];
  171. // 开始编辑,一旦editing == YES就默认开启删除模式
  172. self.tableView.editing = YES;
  173. }
  174. -(void)initUI{
  175. [self.view setBackgroundColor:[UIColor whiteColor]];
  176. self.navigationItem.title = @"编辑排序";
  177. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  178. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  179. forState:UIControlStateNormal];
  180. [button addTarget:self action:@selector(goBack)
  181. forControlEvents:UIControlEventTouchUpInside];
  182. button.frame = CGRectMake(0, 0, 15, 18);
  183. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  184. self.navigationItem.leftBarButtonItem = menuButton;
  185. //右边
  186. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  187. btnAdd.frame = CGRectMake(0, 0,60,14);
  188. [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  189. btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
  190. [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
  191. [btnAdd addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
  192. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  193. self.navigationItem.rightBarButtonItem = menubtnAdd;
  194. }
  195. -(void)saveData{
  196. NSData *encodeTopData = [NSKeyedArchiver archivedDataWithRootObject:_topDataList];
  197. [[NSUserDefaults standardUserDefaults] setObject:encodeTopData forKey:@"SalsSlipTopList"];
  198. NSData *encodeBottomData = [NSKeyedArchiver archivedDataWithRootObject:_bottomDataList];
  199. [[NSUserDefaults standardUserDefaults] setObject:encodeBottomData forKey:@"SalsSlipBottomList"];
  200. [self.orderNav popViewControllerAnimated:YES];
  201. if([self.refreshDelegate respondsToSelector:@selector(refreshData: bottomDataList:)]){
  202. [self.refreshDelegate refreshData:_topDataList bottomDataList:_bottomDataList];
  203. }
  204. }
  205. - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
  206. {
  207. return 2;
  208. }
  209. - (void)goBack
  210. {
  211. [self.navigationController popViewControllerAnimated:YES];
  212. }
  213. #pragma mark - table数据源方法
  214. /**每组多少行*/
  215. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  216. {
  217. if(section==0){
  218. return self.topDataList.count;
  219. }
  220. else{
  221. return self.bottomDataList.count;
  222. }
  223. }
  224. /**设置单元格*/
  225. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  226. {
  227. static NSString *ID = @"SortCell";
  228. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  229. if (cell == nil) {
  230. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  231. }
  232. NSInteger section= indexPath.section;
  233. DragItemInfo *item;
  234. if(section==0){
  235. item=[_topDataList objectAtIndex:indexPath.row];
  236. }
  237. else{
  238. item=[_bottomDataList objectAtIndex:indexPath.row];
  239. }
  240. cell.textLabel.text =item.componentName ;
  241. return cell;
  242. }
  243. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  244. {
  245. if (editingStyle == UITableViewCellEditingStyleDelete) {
  246. NSInteger row= indexPath.row;
  247. DragItemInfo *item= [_topDataList objectAtIndex:row];
  248. [self.topDataList removeObject:item];
  249. [_bottomDataList addObject:item];
  250. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  251. NSInteger row= indexPath.row;
  252. DragItemInfo *item= [_bottomDataList objectAtIndex:row];
  253. [self.bottomDataList removeObject:item];
  254. [_topDataList addObject:item];
  255. }
  256. [self.tableView reloadData ];
  257. }
  258. -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  259. return @"删除";
  260. }
  261. // 只要实现此方法,就可以显示拖动控件
  262. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
  263. {
  264. NSInteger sourceSection= sourceIndexPath.section;
  265. NSInteger destSection=destinationIndexPath.section;
  266. if(sourceSection==0&&destSection==1){
  267. DragItemInfo *source = _topDataList[sourceIndexPath.row];
  268. [_topDataList removeObjectAtIndex:(sourceIndexPath.row)];
  269. [_bottomDataList insertObject:source atIndex:destinationIndexPath.row ];
  270. }
  271. else if(sourceSection==1&&destSection==0){
  272. DragItemInfo *source = _bottomDataList[sourceIndexPath.row];
  273. [_bottomDataList removeObjectAtIndex:(sourceIndexPath.row)];
  274. [_topDataList insertObject:source atIndex:destinationIndexPath.row ];
  275. }
  276. else if(sourceSection==1&&destSection==1){
  277. DragItemInfo *source = _bottomDataList[sourceIndexPath.row];
  278. [_bottomDataList removeObjectAtIndex:(sourceIndexPath.row)];
  279. [_bottomDataList insertObject:source atIndex:destinationIndexPath.row ];
  280. }
  281. else if(sourceSection==0&&destSection==0){
  282. DragItemInfo *source = _topDataList[sourceIndexPath.row];
  283. [_topDataList removeObjectAtIndex:(sourceIndexPath.row)];
  284. [_topDataList insertObject:source atIndex:destinationIndexPath.row ];
  285. }
  286. [self.tableView reloadData];
  287. }
  288. #pragma mark - tableView代理方法
  289. // 返回编辑样式,如果没有实现此方法,默认都是删除
  290. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  291. {
  292. NSInteger section= indexPath.section;
  293. if(section==0){
  294. return UITableViewCellEditingStyleDelete;
  295. }
  296. else if(section==1){
  297. return UITableViewCellEditingStyleInsert;
  298. }
  299. return UITableViewCellEditingStyleDelete;
  300. }
  301. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
  302. return YES;
  303. }
  304. @end