RelationGoodsVC.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // RelationGoodsVC.m
  3. // yunbaolive
  4. //
  5. // Created by IOS1 on 2019/8/30.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "RelationGoodsVC.h"
  9. #import "goodsShowCell.h"
  10. @interface RelationGoodsVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>{
  11. int page;
  12. NSMutableArray *goodsList;
  13. RelationGoodsModel *selectModel;
  14. NSString *pullUrl;
  15. }
  16. @property (nonatomic,strong)UITextField *searchT;
  17. @property (nonatomic,strong) UITableView *goodsTableV;
  18. @end
  19. @implementation RelationGoodsVC
  20. - (void)viewWillAppear:(BOOL)animated{
  21. [super viewWillAppear:animated];
  22. if (_isVideo) {
  23. self.titleL.text = YZMsg(@"关联商品");
  24. }else{
  25. self.titleL.text = YZMsg(@"添加商品");
  26. }
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.subNavi.backgroundColor = [UIColor whiteColor];
  31. self.titleL.textColor = [UIColor blackColor];
  32. self.view.backgroundColor= [UIColor whiteColor];
  33. [self.leftBtn setImage:[UIImage imageNamed:@"left_back"] forState:0];
  34. self.naviLine.backgroundColor = RGB(240, 240, 240);
  35. self.naviLine.hidden = NO;
  36. page = 1;
  37. goodsList = [NSMutableArray array];
  38. if (_isOtherSale) {
  39. pullUrl = @"Shop.searchOnsalePlatformGoods";
  40. }else{
  41. pullUrl = @"Shop.searchShopGoods";
  42. }
  43. [self creatSearch];
  44. [self.view addSubview:self.goodsTableV];
  45. [self searchAnchorWithText:@""];
  46. }
  47. - (void)creatSearch{
  48. _searchT = [[UITextField alloc]initWithFrame:CGRectMake(13, statusbarHeight + 64 + 8, _window_width-26, 30)];
  49. _searchT.backgroundColor = RGB_COLOR(@"#fafafa", 1);
  50. _searchT.font = SYS_Font(15);
  51. _searchT.placeholder = YZMsg(@"请输入商品名称");
  52. _searchT.layer.cornerRadius = 15;
  53. _searchT.layer.masksToBounds = YES;
  54. _searchT.delegate = self;
  55. _searchT.leftViewMode = UITextFieldViewModeAlways;
  56. _searchT.keyboardType = UIKeyboardTypeWebSearch;
  57. UIImageView *leftImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
  58. leftImgView.image = [UIImage imageNamed:@"left_search"];
  59. _searchT.leftView = leftImgView;
  60. [self.view addSubview:_searchT];
  61. }
  62. - (UITableView *)goodsTableV{
  63. if (!_goodsTableV) {
  64. _goodsTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, _searchT.bottom+8, _window_width, _window_height-ShowDiff-(_searchT.bottom+8)) style:0];
  65. _goodsTableV.delegate = self;
  66. _goodsTableV.dataSource = self;
  67. _goodsTableV.separatorStyle = 0;
  68. _goodsTableV.backgroundColor = [UIColor whiteColor];
  69. _goodsTableV.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
  70. page = 1;
  71. [self searchAnchorWithText:_searchT.text];
  72. }];
  73. _goodsTableV.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
  74. page ++;
  75. [self searchAnchorWithText:_searchT.text];
  76. }];
  77. }
  78. return _goodsTableV;
  79. }
  80. #pragma mark ================ searchBar代理 ===============
  81. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  82. [_searchT resignFirstResponder];
  83. page = 1;
  84. [self searchAnchorWithText:_searchT.text];
  85. return YES;
  86. }
  87. - (void)searchAnchorWithText:(NSString *)searchStr{
  88. [YBNetworking postWithUrl:[NSString stringWithFormat:@"%@&keywords=%@&p=%@",pullUrl,searchStr,@(page)] Dic:nil Suc:^(int code, id info, NSString *msg) {
  89. [_goodsTableV.mj_header endRefreshing];
  90. [_goodsTableV.mj_footer endRefreshing];
  91. if (code == 0) {
  92. if (page == 1) {
  93. [goodsList removeAllObjects];
  94. }
  95. for (NSDictionary *dic in info) {
  96. RelationGoodsModel *model = [[RelationGoodsModel alloc]initWithDic:dic];
  97. model.goosdType = 3;
  98. [goodsList addObject:model];
  99. }
  100. if (goodsList.count > 0) {
  101. [PublicView hiddenTextNoData:_goodsTableV];
  102. }else{
  103. [PublicView showTextNoData:_goodsTableV text1:YZMsg(@"您的店铺内暂无商品") text2:YZMsg(@"请先前往店铺内添加商品") centerY:0.8];
  104. }
  105. [_goodsTableV reloadData];
  106. }
  107. } Fail:^(id fail) {
  108. [_goodsTableV.mj_header endRefreshing];
  109. [_goodsTableV.mj_footer endRefreshing];
  110. }];
  111. }
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  113. return goodsList.count;
  114. }
  115. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  116. goodsShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"goodsShowCELL"];
  117. if (!cell) {
  118. cell = [[[NSBundle mainBundle] loadNibNamed:@"goodsShowCell" owner:nil options:nil] lastObject];
  119. }
  120. RelationGoodsModel *model = goodsList[indexPath.row];
  121. if (_isVideo) {
  122. cell.setBtn.hidden = YES;
  123. cell.stateImgV.hidden = NO;
  124. if ([model.goodsid isEqual:_selectID]) {
  125. cell.stateImgV.image = [UIImage imageNamed:@"shop_sel"];
  126. if (!selectModel) {
  127. selectModel = model;
  128. }
  129. }else{
  130. cell.stateImgV.image = [UIImage imageNamed:@"shop_nor"];
  131. }
  132. }else{
  133. cell.setBtn.hidden = NO;
  134. cell.stateImgV.hidden = YES;
  135. if (_isOtherSale) {
  136. cell.priceOldL.hidden = NO;
  137. cell.priceOldL.text =[NSString stringWithFormat:YZMsg(@"佣 ¥%@"),model.commission];
  138. cell.priceOldL.textColor = Pink_Cor;
  139. model.isOtherSale = @"1";
  140. }
  141. cell.contentView.backgroundColor = [UIColor whiteColor];
  142. cell.nameL.textColor = [UIColor blackColor];
  143. cell.bottomLine.backgroundColor = RGB(240, 240, 240);
  144. }
  145. cell.model = model;
  146. cell.haveList = self.haveGoods;
  147. return cell;
  148. }
  149. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  150. return 101;
  151. }
  152. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  153. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  154. if (_isVideo) {
  155. RelationGoodsModel *model = goodsList[indexPath.row];
  156. if (model.goodsid == _selectID) {
  157. _selectID = @"0";
  158. selectModel = nil;
  159. }else{
  160. selectModel = model;
  161. _selectID = selectModel.goodsid;
  162. }
  163. [tableView reloadData];
  164. }
  165. }
  166. - (void)doReturn{
  167. if (_isVideo) {
  168. if (selectModel) {
  169. self.block(selectModel.name, selectModel.goodsid);
  170. }else{
  171. self.block(YZMsg(@"关联商品"), @"0");
  172. }
  173. }
  174. // [super doReturn];
  175. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  176. }
  177. @end