AddOtherSaleGoodsVC.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // AddOtherSaleGoodsVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/12/3.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "AddOtherSaleGoodsVC.h"
  9. #import "RelationGoodsModel.h"
  10. #import "goodsShowCell.h"
  11. @interface AddOtherSaleGoodsVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  12. {
  13. int page;
  14. NSMutableArray *goodsList;
  15. RelationGoodsModel *selectModel;
  16. }
  17. @property (nonatomic,strong)UITextField *searchT;
  18. @property (nonatomic,strong) UITableView *goodsTableV;
  19. @end
  20. @implementation AddOtherSaleGoodsVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.titleL.text = YZMsg(@"添加商品");
  24. page = 1;
  25. goodsList = [NSMutableArray array];
  26. [self creatSearch];
  27. [self.view addSubview:self.goodsTableV];
  28. [self searchAnchorWithText:@""];
  29. }
  30. - (void)creatSearch{
  31. _searchT = [[UITextField alloc]initWithFrame:CGRectMake(13, statusbarHeight + 64 + 8, _window_width-26, 30)];
  32. _searchT.backgroundColor = RGB_COLOR(@"#fafafa", 1);
  33. _searchT.font = SYS_Font(15);
  34. _searchT.placeholder = YZMsg(@"请输入商品名称");
  35. _searchT.layer.cornerRadius = 15;
  36. _searchT.layer.masksToBounds = YES;
  37. _searchT.delegate = self;
  38. _searchT.leftViewMode = UITextFieldViewModeAlways;
  39. _searchT.keyboardType = UIKeyboardTypeWebSearch;
  40. UIImageView *leftImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
  41. leftImgView.image = [UIImage imageNamed:@"left_search"];
  42. _searchT.leftView = leftImgView;
  43. [self.view addSubview:_searchT];
  44. }
  45. - (UITableView *)goodsTableV{
  46. if (!_goodsTableV) {
  47. _goodsTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, _searchT.bottom+8, _window_width, _window_height-ShowDiff-(_searchT.bottom+8)) style:0];
  48. _goodsTableV.delegate = self;
  49. _goodsTableV.dataSource = self;
  50. _goodsTableV.separatorStyle = 0;
  51. _goodsTableV.backgroundColor = [UIColor whiteColor];
  52. _goodsTableV.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
  53. page = 1;
  54. [self searchAnchorWithText:_searchT.text];
  55. }];
  56. _goodsTableV.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
  57. page ++;
  58. [self searchAnchorWithText:_searchT.text];
  59. }];
  60. }
  61. return _goodsTableV;
  62. }
  63. #pragma mark ================ searchBar代理 ===============
  64. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  65. [_searchT resignFirstResponder];
  66. page = 1;
  67. [self searchAnchorWithText:_searchT.text];
  68. return YES;
  69. }
  70. - (void)searchAnchorWithText:(NSString *)searchStr{
  71. [YBNetworking postWithUrl:[NSString stringWithFormat:@"Shop.searchShopGoods&keywords=%@&p=%@",searchStr,@(page)] Dic:nil Suc:^(int code, id info, NSString *msg) {
  72. [_goodsTableV.mj_header endRefreshing];
  73. [_goodsTableV.mj_footer endRefreshing];
  74. if (code == 0) {
  75. if (page == 1) {
  76. [goodsList removeAllObjects];
  77. }
  78. for (NSDictionary *dic in info) {
  79. RelationGoodsModel *model = [[RelationGoodsModel alloc]initWithDic:dic];
  80. model.goosdType = 3;
  81. [goodsList addObject:model];
  82. }
  83. [_goodsTableV reloadData];
  84. }
  85. } Fail:^(id fail) {
  86. [_goodsTableV.mj_header endRefreshing];
  87. [_goodsTableV.mj_footer endRefreshing];
  88. }];
  89. }
  90. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  91. return goodsList.count;
  92. }
  93. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  94. goodsShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"goodsShowCELL"];
  95. if (!cell) {
  96. cell = [[[NSBundle mainBundle] loadNibNamed:@"goodsShowCell" owner:nil options:nil] lastObject];
  97. }
  98. RelationGoodsModel *model = goodsList[indexPath.row];
  99. cell.setBtn.hidden = NO;
  100. cell.stateImgV.hidden = YES;
  101. cell.model = model;
  102. return cell;
  103. }
  104. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  105. return 101;
  106. }
  107. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  108. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  109. }
  110. - (void)doReturn{
  111. // [super doReturn];
  112. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  113. }
  114. @end