CommodityDetailVC.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. //
  2. // CommodityDetailVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/2.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "CommodityDetailVC.h"
  9. #import "StoreInfoView.h"
  10. #import "CommodityCell1.h"
  11. #import "CommodityCell2Row1.h"
  12. #import "CommodityCell2Row2.h"
  13. #import "CommodityCell3.h"
  14. #import "CommodityDetailModel.h"
  15. #import "shopDetailVC.h"
  16. #import "GuaranteeView.h"
  17. #import "SelectStandardsView.h"
  18. #import "CommodityEvaluationCell.h"
  19. #import "GoodsEvaluationListVC.h"
  20. #import "GoodsExplainCell.h"
  21. #import "JCHATConversationViewController.h"
  22. #import "ShareGoodsAlert.h"
  23. #import "XHWebImageAutoSize.h"
  24. #import "GoodsDetailCell.h"
  25. @interface CommodityDetailVC ()<UITableViewDelegate, UITableViewDataSource,goshopDelegate>{
  26. UILabel *sel_line;
  27. UIButton *allBtn;
  28. UIButton *detailBtn;
  29. UIButton *isCollectBtn;
  30. BOOL isEvaluate;
  31. }
  32. @property (nonatomic, strong)UITableView *commodityTable;
  33. @property (nonatomic, strong)CommodityDetailModel *commodityModel;
  34. @property (nonatomic, strong)GuaranteeView *guarView;
  35. @property (nonatomic, strong)SelectStandardsView *standardsView;
  36. @end
  37. @implementation CommodityDetailVC
  38. - (UIStatusBarStyle)preferredStatusBarStyle {
  39. if (@available(iOS 13.0,*)) {
  40. return UIStatusBarStyleDarkContent;
  41. }
  42. return UIStatusBarStyleDefault;
  43. }
  44. #pragma mark ----添加商品访问记录------
  45. -(void)addGoodsVisit{
  46. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"goodsid":self.goodsID, @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  47. NSString *sign = [PublicObj sortString:signdic];
  48. NSDictionary *dic = @{
  49. @"uid":[Config getOwnID],
  50. @"token":[Config getOwnToken],
  51. @"goodsid":self.goodsID,
  52. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  53. @"sign":sign
  54. };
  55. [YBNetworking postWithUrl:@"Buyer.addGoodsVisitRecord" Dic:dic Suc:^(int code, id info, NSString *msg) {
  56. if (code ==0) {
  57. }else{
  58. if (code !=1001) {
  59. [MBProgressHUD showError:msg];
  60. }
  61. }
  62. } Fail:^(id fail) {
  63. }];
  64. }
  65. #pragma mark----获取商品详情------
  66. -(void)getGoodInfo{
  67. NSString *url = [purl stringByAppendingFormat:@"?service=Shop.getGoodsInfo"];
  68. NSDictionary *dic = @{
  69. @"uid":[Config getOwnID],
  70. @"token":[Config getOwnToken],
  71. @"goodsid":self.goodsID,
  72. };
  73. [YBNetworking postWithUrl:@"Shop.getGoodsInfo" Dic:dic Suc:^(int code, id info, NSString *msg) {
  74. if (code ==0) {
  75. self.commodityModel = [CommodityDetailModel modelWithDic:[info firstObject]];
  76. [self.commodityTable reloadData];
  77. if ([self.commodityModel.iscollect isEqual:@"1"]) {
  78. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏亮")] forState:0];
  79. }else{
  80. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏")] forState:0];
  81. }
  82. }else{
  83. [MBProgressHUD showError:msg];
  84. }
  85. } Fail:^(id fail) {
  86. }];
  87. }
  88. -(void)viewWillDisappear:(BOOL)animated
  89. {
  90. [super viewWillDisappear:YES];
  91. [[NSNotificationCenter defaultCenter]postNotificationName:@"stopGoodsVideo" object:nil];
  92. }
  93. - (void)viewDidLoad {
  94. [super viewDidLoad];
  95. if ([self.fromWhere isEqual:@"seller"]) {
  96. self.titleL.text = YZMsg(@"预览商品");
  97. }else{
  98. self.titleL.text = YZMsg(@"商品详情");
  99. [self addGoodsVisit];
  100. }
  101. self.subNavi.backgroundColor = UIColor.whiteColor;
  102. self.titleL.textColor = UIColor.blackColor;
  103. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  104. self.naviLine.hidden = NO;
  105. self.naviLine.backgroundColor = RGB(245, 245, 245);
  106. self.rightBtn.hidden = NO;
  107. [self.rightBtn setImage:[UIImage imageNamed:@"goods_share"] forState:0];
  108. isEvaluate = NO;
  109. [self.view addSubview:self.commodityTable];
  110. [self createBottom];
  111. [self getGoodInfo];
  112. }
  113. -(void)clickNaviRightBtn
  114. {
  115. if ([[Config getOwnID] intValue] <= 0) {
  116. [PublicObj warnLogin];
  117. return;
  118. }
  119. ShareGoodsAlert *alert = [[ShareGoodsAlert alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andGoodsModel:self.commodityModel];
  120. [self.view addSubview:alert];
  121. }
  122. -(UITableView *)commodityTable{
  123. if (!_commodityTable) {
  124. _commodityTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-60-ShowDiff) style:UITableViewStylePlain];
  125. _commodityTable.delegate = self;
  126. _commodityTable.dataSource = self;
  127. _commodityTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  128. // _commodityTable.estimatedRowHeight = 0;
  129. // _commodityTable.estimatedSectionHeaderHeight = 0;
  130. // _commodityTable.estimatedSectionFooterHeight = 0;
  131. _commodityTable.showsVerticalScrollIndicator = NO;
  132. }
  133. return _commodityTable;
  134. }
  135. #pragma mark-------UITableviewDelegate--------------
  136. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  137. {
  138. return 4;
  139. }
  140. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  141. {
  142. if (section == 0) {
  143. return 1;
  144. }else if (section == 1){
  145. return 2;
  146. }else if (section == 2){
  147. return 1;
  148. }else {
  149. if (isEvaluate) {
  150. return self.commodityModel.comment_lists.count+1;
  151. }else{
  152. return self.commodityModel.pictures_format.count+1;
  153. }
  154. }
  155. }
  156. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  157. {
  158. if (indexPath.section == 0) {
  159. return 505;
  160. }else if(indexPath.section == 1){
  161. return 45;
  162. }else if (indexPath.section == 2){
  163. return 170;
  164. }else{
  165. NSLog(@"ddddddddddd:%f", self.commodityModel.commentCellHeight);
  166. if (isEvaluate) {
  167. if (indexPath.row == self.commodityModel.comment_lists.count) {
  168. return 44;
  169. }else{
  170. return self.commodityModel.commentCellHeight;
  171. }
  172. }else{
  173. // return _window_height-64-statusbarHeight-50-80;
  174. if (indexPath.row == 0) {
  175. // CGFloat content_height= [[pub sharedInstance]heightOfString:self.commodityModel.content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-32];
  176. CGFloat content_height = [PublicObj heightOfString:self.commodityModel.content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-32];
  177. return content_height;
  178. }else{
  179. NSString *imageUrl = self.commodityModel.pictures_format[indexPath.row-1];
  180. return [XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:imageUrl] layoutWidth:_window_width estimateHeight:200];
  181. }
  182. }
  183. }
  184. }
  185. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  186. {
  187. if (section == 0) {
  188. return 5;
  189. }else if(section == 1){
  190. return 5;
  191. }else if (section == 2){
  192. return 5;
  193. }else{
  194. return 0;
  195. }
  196. }
  197. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  198. {
  199. if (section == 3) {
  200. return 50;
  201. }else{
  202. return 0.01;
  203. }
  204. }
  205. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  206. {
  207. UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 5)];
  208. footer.backgroundColor = RGB(250, 250, 250);
  209. return footer;
  210. }
  211. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  212. {
  213. if (section == 3) {
  214. UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 50)];
  215. footer.backgroundColor = [UIColor whiteColor];
  216. allBtn = [UIButton buttonWithType:0];
  217. allBtn.frame =CGRectMake(_window_width/2+10, 10, 110, 30);// CGRectMake(_window_width/2-120, 10, 110, 30);
  218. if (![lagType isEqual:ZH_CN]) {
  219. allBtn.frame = CGRectMake(_window_width/2+10, 10, 160, 30);
  220. }
  221. [allBtn setTitle:[NSString stringWithFormat:@"%@ (%@)",YZMsg(@"宝贝评价"),self.commodityModel.comment_nums] forState:0];
  222. allBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  223. [allBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
  224. [allBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  225. allBtn.titleLabel.textAlignment = NSTextAlignmentRight;
  226. [allBtn addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
  227. allBtn.tag = 30000;
  228. [footer addSubview: allBtn];
  229. detailBtn = [UIButton buttonWithType:0];
  230. detailBtn.frame = CGRectMake(_window_width/2-120, 10, 110, 30);//CGRectMake(_window_width/2+10, 10, 110, 30);
  231. [detailBtn setTitle:[NSString stringWithFormat:@"%@",YZMsg(@"宝贝详情")] forState:0];
  232. detailBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  233. [detailBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
  234. [detailBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  235. [detailBtn addTarget:self action:@selector(evaluateClick:) forControlEvents:UIControlEventTouchUpInside];
  236. detailBtn.tag = 30001;
  237. [footer addSubview: detailBtn];
  238. allBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  239. detailBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  240. sel_line = [[UILabel alloc]init];
  241. sel_line.frame = CGRectMake(0, allBtn.bottom, 20, 2);
  242. sel_line.backgroundColor = Pink_Cor ;
  243. [footer addSubview:sel_line];
  244. if (isEvaluate) {
  245. allBtn.selected = YES;
  246. detailBtn.selected = NO;
  247. sel_line.centerX = allBtn.centerX;
  248. }else{
  249. detailBtn.selected = YES;
  250. allBtn.selected = NO;
  251. sel_line.centerX = detailBtn.centerX;
  252. }
  253. return footer;
  254. }else{
  255. UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
  256. return view;
  257. }
  258. }
  259. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  260. {
  261. if (indexPath.section == 0) {
  262. CommodityCell1 *cell1 = [[CommodityCell1 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
  263. cell1.model = self.commodityModel;
  264. cell1.selectionStyle = UITableViewCellSelectionStyleNone;
  265. cell1.contentView.backgroundColor = UIColor.clearColor;
  266. cell1.backgroundColor = UIColor.clearColor;
  267. return cell1;
  268. }else if(indexPath.section == 1){
  269. if (indexPath.row == 0) {
  270. CommodityCell2Row1 *row1 = [[NSBundle mainBundle]loadNibNamed:@"CommodityCell2Row1" owner:self options:nil].firstObject;
  271. return row1;
  272. }else{
  273. CommodityCell2Row2 *row2 = [[NSBundle mainBundle]loadNibNamed:@"CommodityCell2Row2" owner:self options:nil].firstObject;
  274. return row2;
  275. }
  276. }else if(indexPath.section == 2){
  277. CommodityCell3 *cell3 = [[CommodityCell3 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell3"];
  278. cell3.model = self.commodityModel;
  279. cell3.delegate = self;
  280. cell3.selectionStyle = UITableViewCellSelectionStyleNone;
  281. return cell3;
  282. }else{
  283. if (isEvaluate) {
  284. if (indexPath.row == self.commodityModel.comment_lists.count) {
  285. UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cells"];
  286. UILabel *lookMore = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _window_width, 40)];
  287. lookMore.font =[UIFont systemFontOfSize:14];
  288. lookMore.textColor = [UIColor grayColor];
  289. if (self.commodityModel.comment_lists.count == 0) {
  290. lookMore.text = YZMsg(@"还没有收到任何评价");
  291. }else{
  292. lookMore.text = YZMsg(@"查看更多评价");
  293. }
  294. lookMore.textAlignment = NSTextAlignmentCenter;
  295. [cell addSubview:lookMore];
  296. return cell;
  297. }else{
  298. NSString *CellIdentifier = [NSString stringWithFormat:@"CommodityEvaluationCell%ld%ld",indexPath.section,indexPath.row];
  299. CommodityEvaluationCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  300. if (!cell) {
  301. cell = [[CommodityEvaluationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  302. }
  303. //最外层用户评价
  304. [cell setCommodityModel:self.commodityModel andListModel:self.commodityModel.comment_lists[indexPath.row]];
  305. self.commodityModel.comment_dic =self.commodityModel.comment_lists[indexPath.row];
  306. CGFloat content_height = [PublicObj heightOfString:[self.commodityModel.comment_dic valueForKey:@"content"] andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-50];
  307. self.commodityModel.commentCellHeight = content_height + 80;
  308. NSLog(@"66666666666:%f", self.commodityModel.commentCellHeight);
  309. if (cell.allArr.count > 0) {
  310. if (cell.allArr.count > 3) {
  311. self.commodityModel.commentCellHeight += cell.imgWidth*2+30+30;
  312. }else{
  313. self.commodityModel.commentCellHeight += cell.imgWidth+20+30;
  314. }
  315. }else{
  316. self.commodityModel.commentCellHeight+=40;
  317. }
  318. NSLog(@"7777777777:%f", self.commodityModel.commentCellHeight);
  319. return cell;
  320. }
  321. }else{
  322. // GoodsExplainCell *cell = [[GoodsExplainCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GoodsExplainCell"];
  323. // cell.model = self.commodityModel;
  324. GoodsDetailCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"GoodsDetailCell" owner:nil options:nil]objectAtIndex:0];
  325. NSString *url = self.commodityModel.pictures_format[indexPath.row-1];
  326. [cell.thumbImg sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  327. /** 缓存image size */
  328. [XHWebImageAutoSize storeImageSize:image forURL:imageURL completed:^(BOOL result) {
  329. /** reload */
  330. if(result) [tableView xh_reloadDataForURL:imageURL];
  331. }];
  332. }];
  333. return cell;
  334. }
  335. }
  336. }
  337. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  338. {
  339. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  340. if ([self.fromWhere isEqual:@"seller"]) {
  341. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  342. return;
  343. }
  344. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  345. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  346. return;
  347. }
  348. YBWeakSelf;
  349. if(indexPath.section == 1){
  350. if (indexPath.row == 0) {
  351. if ([[Config getOwnID] intValue] <= 0) {
  352. [PublicObj warnLogin];
  353. return;
  354. }
  355. if (_standardsView) {
  356. [_standardsView removeFromSuperview];
  357. _standardsView = nil;
  358. }
  359. _standardsView = [[SelectStandardsView alloc]init];
  360. _standardsView.frame = CGRectMake(0, 0, _window_width, _window_height);
  361. _standardsView.model = self.commodityModel;
  362. _standardsView.shareUID = self.shareuid;
  363. _standardsView.standarEvent = ^(NSString * _Nonnull standards, NSString * _Nonnull countStr, NSString * _Nonnull type) {
  364. if ([type isEqual:@"0"]) {
  365. [weakSelf.standardsView removeFromSuperview];
  366. weakSelf.standardsView = nil;
  367. }
  368. };
  369. [self.view addSubview:_standardsView];
  370. }else{
  371. if (_guarView) {
  372. [_guarView removeFromSuperview];
  373. _guarView = nil;
  374. }
  375. _guarView = [[NSBundle mainBundle]loadNibNamed:@"GuaranteeView" owner:self options:nil].firstObject;
  376. _guarView.frame = CGRectMake(0, 0, _window_width, _window_height);
  377. _guarView.hideEvent = ^{
  378. [weakSelf.guarView removeFromSuperview];
  379. weakSelf.guarView = nil;
  380. };
  381. [self.view addSubview:_guarView];
  382. }
  383. }else if (indexPath.section == 3){
  384. if (isEvaluate){
  385. if (self.commodityModel.comment_lists.count == 0) {
  386. return;
  387. }
  388. if (indexPath.row == self.commodityModel.comment_lists.count) {
  389. if ([[Config getOwnID] intValue] <= 0) {
  390. [PublicObj warnLogin];
  391. return;
  392. }
  393. GoodsEvaluationListVC *listVC = [[GoodsEvaluationListVC alloc]init];
  394. listVC.goodsIDStr = self.goodsID;
  395. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:listVC animated:YES];
  396. }
  397. }
  398. }else
  399. {
  400. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  401. }
  402. }
  403. -(void)evaluateClick:(UIButton *)sender{
  404. if (sender.tag == 30000) {
  405. sel_line.centerX = allBtn.centerX;
  406. isEvaluate = YES;
  407. }else{
  408. sel_line.centerX = detailBtn.centerX;
  409. isEvaluate = NO;
  410. }
  411. [UIView performWithoutAnimation:^{
  412. NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:3];
  413. [self.commodityTable reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
  414. }];
  415. }
  416. #pragma mark------添加底部按钮---------
  417. -(void)createBottom{
  418. UIView *bottomBack = [[UIView alloc]init];
  419. bottomBack.frame = CGRectMake(0, _window_height-60-ShowDiff, _window_width, 60+ShowDiff);
  420. bottomBack.backgroundColor = [UIColor whiteColor];
  421. [self.view addSubview:bottomBack];
  422. [PublicObj lineViewWithFrame:CGRectMake(0, 0, _window_width, 1) andColor:RGB(240, 240, 240) andView:bottomBack];
  423. NSArray *arr = @[@"店铺",@"客服",@"收藏",@"立即购买"];
  424. NSArray *titlearr = @[YZMsg(@"店铺"),YZMsg(@"客服"),YZMsg(@"收藏"),YZMsg(@"立即购买")];
  425. for (int i = 0; i < arr.count; i ++) {
  426. if ( i < 3) {
  427. UIButton *btn = [UIButton buttonWithType:0];
  428. btn.frame = CGRectMake(i * _window_width *0.2, 0, _window_width *0.2, 60);
  429. NSString *langStr = @"";
  430. if ([lagType isEqual:EN]) {
  431. langStr = [common getLanguage];
  432. }
  433. [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"commodity_%@%@",arr[i],langStr]] forState:0];
  434. btn.tag = 100000+i;
  435. [btn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  436. [bottomBack addSubview:btn];
  437. if (i == 2) {
  438. isCollectBtn = btn;
  439. }
  440. }else{
  441. UIButton *btn = [UIButton buttonWithType:0];
  442. btn.frame = CGRectMake( _window_width *0.6, 0, _window_width *0.4, 60);
  443. [btn setTitle:titlearr[i] forState:0];
  444. [btn setTitleColor:[UIColor whiteColor] forState:0];
  445. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  446. btn.tag = 100000+i;
  447. [btn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  448. [btn setBackgroundColor:Pink_Cor];
  449. [bottomBack addSubview:btn];
  450. }
  451. }
  452. }
  453. -(void)bottomBtnClick:(UIButton *)sender{
  454. NSLog(@"yonghuUID-----:%@",self.commodityModel.shop_uid);
  455. if ([self.fromWhere isEqual:@"seller"] || [self.commodityModel.shop_uid isEqual:[Config getOwnID]]) {
  456. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  457. return;
  458. }
  459. if ([[Config getOwnID] intValue] <= 0) {
  460. [PublicObj warnLogin];
  461. return;
  462. }
  463. switch (sender.tag) {
  464. case 100000:
  465. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  466. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  467. return;
  468. }
  469. [self goshopClick];
  470. break;
  471. case 100001:{
  472. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  473. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  474. return;
  475. }
  476. if ([self.commodityModel.type isEqual:@"2"]) {
  477. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:nil message:YZMsg(@"请到个性设置-关于我们中联系客服") preferredStyle:UIAlertControllerStyleAlert];
  478. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  479. }];
  480. [sureAction setValue:Normal_Color forKey:@"_titleTextColor"];
  481. [alertControl addAction:sureAction];
  482. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:alertControl animated:YES completion:nil];
  483. }else{
  484. NSDictionary *userDic = @{
  485. @"id":self.commodityModel.shop_uid,
  486. @"user_nickname":self.commodityModel.shop_usernicename,
  487. @"avatar":self.commodityModel.shop_avatar,
  488. };
  489. [[YBMessageManager shareManager] chatWithUser:userDic];
  490. }
  491. }
  492. break;
  493. case 100002:{
  494. [self collectionGoods];
  495. }
  496. break;
  497. case 100003:{
  498. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  499. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  500. return;
  501. }
  502. YBWeakSelf;
  503. if (_standardsView) {
  504. [_standardsView removeFromSuperview];
  505. _standardsView = nil;
  506. }
  507. _standardsView = [[SelectStandardsView alloc]init];
  508. _standardsView.frame = CGRectMake(0, 0, _window_width, _window_height);
  509. _standardsView.model = self.commodityModel;
  510. _standardsView.liveId = self.liveUid;
  511. _standardsView.shareUID = self.shareuid;
  512. _standardsView.standarEvent = ^(NSString * _Nonnull standards, NSString * _Nonnull countStr, NSString * _Nonnull type) {
  513. if ([type isEqual:@"0"]) {
  514. [weakSelf.standardsView removeFromSuperview];
  515. weakSelf.standardsView = nil;
  516. }
  517. };
  518. [self.view addSubview:_standardsView];
  519. }
  520. break;
  521. default:
  522. break;
  523. }
  524. }
  525. -(void)collectionGoods{
  526. NSDictionary *dic = @{
  527. @"uid":[Config getOwnID],
  528. @"token":[Config getOwnToken],
  529. @"goodsid":self.goodsID
  530. };
  531. [YBNetworking postWithUrl:@"Shop.setCollect" Dic:dic Suc:^(int code, id info, NSString *msg) {
  532. if (code ==0) {
  533. NSDictionary *infos = [info firstObject];
  534. NSString *iscollect = minstr([infos valueForKey:@"iscollect"]);
  535. if ([iscollect isEqual:@"1"]) {
  536. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏亮")] forState:0];
  537. [MBProgressHUD showError:YZMsg(@"已收藏")];
  538. }else{
  539. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏")] forState:0];
  540. [MBProgressHUD showError:YZMsg(@"已取消收藏")];
  541. }
  542. }else{
  543. [MBProgressHUD showError:msg];
  544. }
  545. } Fail:^(id fail) {
  546. }];
  547. }
  548. #pragma mark--------店铺主页-----------
  549. -(void)goshopClick
  550. {
  551. if ([self.fromWhere isEqual:@"seller"]) {
  552. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  553. return;
  554. }
  555. if ([self.backTags isEqual:@"shop"]) {
  556. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  557. return;
  558. }
  559. if ([[Config getOwnID] intValue] <= 0) {
  560. [PublicObj warnLogin];
  561. return;
  562. }
  563. shopDetailVC *vc = [[shopDetailVC alloc]init];
  564. vc.toUserID = minstr([self.commodityModel.shop_info valueForKey:@"uid"]);
  565. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  566. }
  567. @end