AS_GoodsReviewsListC.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // AS_GoodsReviewsListC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/1/4.
  6. //
  7. #import "AS_GoodsReviewsListC.h"
  8. #import "ASGoodsDetailsVM.h"
  9. #import "RadioButton.h"
  10. #import "GoodsReviewsListTableV.h"
  11. #import "GoodsReviewsWriteC.h"
  12. #import "ReviewsTableHearV.h"
  13. @interface AS_GoodsReviewsListC ()<RY_baseVMprotocol,TT_BaseTableVDelegate>
  14. @property (nonatomic, strong) ASGoodsDetailsVM *VM;
  15. @property (nonatomic, strong) UIView *topBgV;
  16. @property (nonatomic, strong) UIImageView *topImgV;
  17. @property (nonatomic, strong) UILabel *goodsTitleLab;
  18. @property (nonatomic, strong) QMUILabel *priceLab;
  19. @property (nonatomic, strong) QMUILabel *soldLab;
  20. @property (nonatomic, strong) NSMutableArray *radioBtnAry;
  21. @property (nonatomic, strong) ReviewsTableHearV *tableHeadV;
  22. @property (nonatomic, strong) QMUILabel *reviewsLab;
  23. @property (nonatomic, strong) GoodsReviewsListTableV *TableV;
  24. @property (nonatomic, strong) NSMutableArray *sortreTypeAry;
  25. @property (nonatomic, strong) NSString *sortreType;
  26. @end
  27. @implementation AS_GoodsReviewsListC
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.title = [NSString stringWithFormat:@"Reviews (%@)",self.goodsM.review_nums];
  31. self.TableV.Page = 1;
  32. self.sortreType = [self.sortreTypeAry firstObject];
  33. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  34. [self reqNet_Goods_productGetProductsReview:self.sortreType];
  35. [self ucm_subVeiwsTapBlock];
  36. }
  37. - (void)initSubviews {
  38. [super initSubviews];
  39. [self.view addSubview:self.topBgV];
  40. self.sortreTypeAry = [NSMutableArray arrayWithArray:@[@"All",@"Newest",@"Pictures"]];
  41. self.sortreType = [self.sortreTypeAry firstObject];
  42. for (int i=0; i<self.sortreTypeAry.count; i++) {
  43. RadioButton *radBtn= [[RadioButton alloc]init];
  44. radBtn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  45. radBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:14];
  46. radBtn.layer.cornerRadius = 4;
  47. radBtn.clipsToBounds = YES;
  48. radBtn.tag = i;
  49. [radBtn setTitle:self.sortreTypeAry[i] forState:UIControlStateNormal];
  50. [radBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  51. [radBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateSelected];
  52. [radBtn addTarget:self action:@selector(handle_onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
  53. [self.view addSubview:radBtn];
  54. CGFloat btnWidth = (KScreenWidth-40)/3;
  55. radBtn.frame = CGRectMake(10 + i*(btnWidth+10), CGRectGetMaxY(self.topBgV.frame)+10,btnWidth, 40);
  56. [self.radioBtnAry addObject:radBtn];
  57. }
  58. RadioButton *firstBtn = self.radioBtnAry[0];
  59. [firstBtn setGroupButtons:self.radioBtnAry];
  60. [firstBtn setSelected:YES];
  61. firstBtn.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  62. [self setupTableV:[GoodsReviewsListTableV class] Frame:CGRectMake(0, CGRectGetMaxY(firstBtn.frame)+10, KScreenWidth, KScreenHeight- CGRectGetMaxY(firstBtn.frame)-10)];
  63. self.TableV.backgroundColor = [UIColor clearColor];
  64. self.TableV.tableHeaderView = self.tableHeadV;
  65. self.TableV.Page = 1;
  66. self.TableV.is_refreshHeader = YES;
  67. self.TableV.is_refreshfoot = YES;
  68. }
  69. - (void)ucm_subVeiwsTapBlock{
  70. @weakify(self)
  71. self.tableHeadV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  72. @strongify(self)
  73. if(num == 0){
  74. GoodsReviewsWriteC *vc = [[GoodsReviewsWriteC alloc]init];
  75. vc.goodsM = self.goodsM;
  76. vc.topBgV = self.topBgV;
  77. vc.nav_title = [NSString stringWithFormat:@"REVIEWS (%@)",self.goodsM.review_nums];
  78. [self.navigationController pushViewController:vc animated:YES];
  79. }
  80. };
  81. }
  82. - (void)ucm_changedefault{
  83. [self.topImgV sd_setImageWithURL:[NSURL URLWithString:self.goodsM.add_gooodsImgUrl] placeholderImage:UIImageDefaultImg_SD];
  84. self.goodsTitleLab.text = self.goodsM.name;
  85. self.priceLab.attributedText = self.goodsM.priceAtr;
  86. self.soldLab.text = [NSString stringWithFormat:@"SOLD: %@",self.goodsM.sold];
  87. [self.tableHeadV tt_confignewdata:self.goodsM];
  88. }
  89. - (void)ucm_bindvmmodel{
  90. self.VM = [[ASGoodsDetailsVM alloc]initDelegate:self];
  91. }
  92. #pragma mark - **************** TT_BaseTableVDelegate ****************
  93. - (void)refreshDataType:(NSInteger)type{
  94. [self reqNet_Goods_productGetProductsReview:self.sortreType];
  95. }
  96. #pragma mark - **************** reqNet ****************
  97. -(void)reqNet_Goods_productGetProductsReview:(NSString *)sortreType{
  98. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  99. [params setObject:self.goodsM.Id forKey:@"pid"];
  100. [params setObject:@1 forKey:@"img"];
  101. [params setObject:sortreType forKey:@"sortreview"];
  102. [params setObject:@(self.TableV.Page) forKey:@"p"];
  103. [params setObject:@10 forKey:@"limit"];
  104. [self.VM ry_requestGetApi:Goods_productGetProductsReview param:params];
  105. }
  106. -(void)ry_respnsData:(nullable id)data
  107. parseAry:(nullable NSMutableArray *)arry
  108. sucess:(BOOL)sucessOrFail
  109. mark:(NSString *)mark
  110. reqNetType:(ReqNetType)reqNetType{
  111. [MBProgressHUD hideHUDForView:self.view animated:YES];
  112. if(sucessOrFail){ ///如何加载相关的评论页面
  113. if([mark isEqualToString:Goods_productGetProductsReview]){
  114. [self.TableV configDataNew:arry has_more:arry.count==10 ? YES : NO];
  115. }
  116. }
  117. }
  118. #pragma mark - **************** handle ****************
  119. -(void)handle_onRadioButtonValueChanged:(RadioButton *)btn{
  120. if (btn.selected) {
  121. btn.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  122. self.TableV.Page = 1;
  123. self.sortreType = self.sortreTypeAry[btn.tag];
  124. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  125. [self reqNet_Goods_productGetProductsReview:self.sortreType];
  126. [self.TableV setContentOffset:CGPointMake(0, 0) animated:YES];
  127. }else{
  128. btn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  129. }
  130. }
  131. #pragma mark - **************** lazy ****************
  132. - (UIView *)topBgV {
  133. if (!_topBgV) {
  134. IPhoneXHeigh
  135. UIView *v= [[UIView alloc] initWithFrame:CGRectMake(0, securitytop_Y, KScreenWidth, 60)];
  136. v.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  137. [v addSubview:self.topImgV];
  138. [v addSubview:self.goodsTitleLab];
  139. [v addSubview:self.priceLab];
  140. [v addSubview:self.soldLab];
  141. [self.topImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.mas_equalTo(20);
  143. make.top.mas_equalTo(10);
  144. make.height.mas_equalTo(40);
  145. make.width.mas_equalTo(40);
  146. }];
  147. [self.soldLab mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.right.mas_equalTo(-10);
  149. make.centerY.mas_equalTo(0);
  150. make.height.mas_equalTo(40);
  151. }];
  152. [self.goodsTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.left.equalTo(self.topImgV.mas_right).offset(10);
  154. make.right.equalTo(self.soldLab.mas_left).offset(-10);
  155. make.top.mas_equalTo(10);
  156. make.height.mas_equalTo(20);
  157. }];
  158. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.equalTo(self.topImgV.mas_right).offset(10);
  160. make.right.equalTo(self.soldLab.mas_left).offset(-10);
  161. make.top.equalTo(self.goodsTitleLab.mas_bottom);
  162. make.height.mas_equalTo(20);
  163. }];
  164. _topBgV = v;
  165. }
  166. return _topBgV;
  167. }
  168. - (UIImageView *)topImgV {
  169. if (!_topImgV) {
  170. _topImgV = [[UIImageView alloc] initWithImage:nil];
  171. _topImgV.contentMode = UIViewContentModeScaleAspectFill;
  172. _topImgV.clipsToBounds = YES;
  173. }
  174. return _topImgV;
  175. }
  176. - (UILabel *)goodsTitleLab {
  177. if (!_goodsTitleLab) {
  178. _goodsTitleLab = [[UILabel alloc] initWithFrame:CGRectZero];
  179. _goodsTitleLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
  180. _goodsTitleLab.font = [UIFont fontWithName:Rob_Regular size:12];
  181. }
  182. return _goodsTitleLab;
  183. }
  184. - (QMUILabel *)priceLab {
  185. if (!_priceLab) {
  186. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  187. }
  188. return _priceLab;
  189. }
  190. - (QMUILabel *)soldLab {
  191. if (!_soldLab) {
  192. _soldLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  193. _soldLab.textAlignment = NSTextAlignmentRight;
  194. _soldLab.textColor = [UIColor colorWithHexString:@"#000000"];
  195. _soldLab.font = [UIFont fontWithName:Rob_Regular size:12];
  196. }
  197. return _soldLab;
  198. }
  199. - (NSMutableArray *)radioBtnAry {
  200. if (!_radioBtnAry) {
  201. _radioBtnAry = [[NSMutableArray alloc] init];
  202. }
  203. return _radioBtnAry;
  204. }
  205. - (ReviewsTableHearV *)tableHeadV {
  206. if (!_tableHeadV) {
  207. _tableHeadV = [[ReviewsTableHearV alloc] initWithFrame:CGRectFlatMake(0, 0, KScreenHeight, [ReviewsTableHearV xxx_viewHeight])];
  208. _tableHeadV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  209. }
  210. return _tableHeadV;
  211. }
  212. - (QMUILabel *)reviewsLab {
  213. if (!_reviewsLab) {
  214. _reviewsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  215. _reviewsLab.textAlignment = NSTextAlignmentLeft;
  216. _reviewsLab.textColor = [UIColor blackColor];
  217. _reviewsLab.font = [UIFont systemFontOfSize:18];
  218. _reviewsLab.text = @"test";
  219. }
  220. return _reviewsLab;
  221. }
  222. - (NSMutableArray *)sortreTypeAry {
  223. if (!_sortreTypeAry) {
  224. _sortreTypeAry = [[NSMutableArray alloc] init];
  225. }
  226. return _sortreTypeAry;
  227. }
  228. @end