OutsideGoodsDetailVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. //
  2. // OutsideGoodsDetailVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/5/27.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "OutsideGoodsDetailVC.h"
  9. #import "JCHATConversationViewController.h"
  10. #import "CommodityDetailModel.h"
  11. #import "OutsideHeadCell.h"
  12. #import "CommodityCell2Row1.h"
  13. #import "CommodityCell2Row2.h"
  14. #import "CommodityCell3.h"
  15. #import "shopDetailVC.h"
  16. #import "GuaranteeView.h"
  17. #import "ShareGoodsAlert.h"
  18. @interface OutsideGoodsDetailVC ()<UITableViewDelegate, UITableViewDataSource,goshopDelegate>
  19. {
  20. UIButton *isCollectBtn;
  21. }
  22. @property (nonatomic, strong)CommodityDetailModel *commodityModel;
  23. @property (nonatomic, strong)UITableView *commodityTable;
  24. @property (nonatomic, strong)GuaranteeView *guarView;
  25. @end
  26. @implementation OutsideGoodsDetailVC
  27. - (UIStatusBarStyle)preferredStatusBarStyle {
  28. if (@available(iOS 13.0,*)) {
  29. return UIStatusBarStyleDarkContent;
  30. }
  31. return UIStatusBarStyleDefault;
  32. }
  33. #pragma mark ----添加商品访问记录------
  34. -(void)addGoodsVisit{
  35. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"goodsid":self.goodsID, @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  36. NSString *sign = [PublicObj sortString:signdic];
  37. NSDictionary *dic = @{
  38. @"uid":[Config getOwnID],
  39. @"token":[Config getOwnToken],
  40. @"goodsid":self.goodsID,
  41. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  42. @"sign":sign
  43. };
  44. [YBNetworking postWithUrl:@"Buyer.addGoodsVisitRecord" Dic:dic Suc:^(int code, id info, NSString *msg) {
  45. if (code ==0) {
  46. }else{
  47. if (code!=1001) {
  48. [MBProgressHUD showError:msg];
  49. }
  50. }
  51. } Fail:^(id fail) {
  52. }];
  53. }
  54. #pragma mark----获取商品详情------
  55. -(void)getGoodInfo{
  56. NSDictionary *dic = @{
  57. @"uid":[Config getOwnID],
  58. @"token":[Config getOwnToken],
  59. @"goodsid":self.goodsID,
  60. };
  61. [YBNetworking postWithUrl:@"Shop.getGoodsInfo" Dic:dic Suc:^(int code, id info, NSString *msg) {
  62. if (code ==0) {
  63. self.commodityModel = [CommodityDetailModel modelWithDic:[info firstObject]];
  64. [self.commodityTable reloadData];
  65. if ([self.commodityModel.iscollect isEqual:@"1"]) {
  66. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏亮")] forState:0];
  67. }else{
  68. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏")] forState:0];
  69. }
  70. }else{
  71. [MBProgressHUD showError:msg];
  72. }
  73. } Fail:^(id fail) {
  74. }];
  75. }
  76. - (void)viewDidLoad {
  77. [super viewDidLoad];
  78. if ([self.fromWhere isEqual:@"seller"]) {
  79. self.titleL.text = YZMsg(@"预览商品");
  80. }else{
  81. self.titleL.text = YZMsg(@"商品详情");
  82. [self addGoodsVisit];
  83. }
  84. self.subNavi.backgroundColor = UIColor.whiteColor;
  85. self.titleL.textColor = UIColor.blackColor;
  86. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  87. self.naviLine.hidden = NO;
  88. self.naviLine.backgroundColor = RGB(245, 245, 245);
  89. self.rightBtn.hidden = NO;
  90. [self.rightBtn setImage:[UIImage imageNamed:@"goods_share"] forState:0];
  91. [self.view addSubview:self.commodityTable];
  92. [self createBottom];
  93. [self getGoodInfo];
  94. }
  95. -(void)clickNaviRightBtn
  96. {
  97. ShareGoodsAlert *alert = [[ShareGoodsAlert alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andGoodsModel:self.commodityModel];
  98. [self.view addSubview:alert];
  99. }
  100. -(UITableView *)commodityTable{
  101. if (!_commodityTable) {
  102. _commodityTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-60-ShowDiff) style:UITableViewStylePlain];
  103. _commodityTable.delegate = self;
  104. _commodityTable.dataSource = self;
  105. _commodityTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  106. _commodityTable.estimatedRowHeight = 0;
  107. _commodityTable.estimatedSectionHeaderHeight = 0;
  108. _commodityTable.estimatedSectionFooterHeight = 0;
  109. }
  110. return _commodityTable;
  111. }
  112. #pragma mark-------UITableviewDelegate--------------
  113. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  114. {
  115. return 3;
  116. }
  117. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  118. {
  119. return 1;
  120. }
  121. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. if (indexPath.section == 0) {
  124. return 505;
  125. }else if(indexPath.section == 1){
  126. return 45;
  127. }else{
  128. return 170;
  129. }
  130. }
  131. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  132. {
  133. return 5;
  134. }
  135. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  136. {
  137. UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 5)];
  138. footer.backgroundColor = RGB(250, 250, 250);
  139. return footer;
  140. }
  141. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  142. {
  143. if (indexPath.section == 0) {
  144. OutsideHeadCell *cell1 = [[OutsideHeadCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
  145. cell1.model = self.commodityModel;
  146. cell1.selectionStyle = UITableViewCellSelectionStyleNone;
  147. cell1.contentView.backgroundColor = UIColor.clearColor;
  148. cell1.backgroundColor = UIColor.clearColor;
  149. return cell1;
  150. }else if(indexPath.section == 1){
  151. CommodityCell2Row2 *row2 = [[NSBundle mainBundle]loadNibNamed:@"CommodityCell2Row2" owner:self options:nil].firstObject;
  152. return row2;
  153. }else{
  154. CommodityCell3 *cell3 = [[CommodityCell3 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell3"];
  155. cell3.model = self.commodityModel;
  156. cell3.delegate = self;
  157. return cell3;
  158. }
  159. }
  160. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  161. {
  162. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  163. if ([self.fromWhere isEqual:@"seller"]) {
  164. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  165. return;
  166. }
  167. YBWeakSelf;
  168. if(indexPath.section == 1){
  169. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  170. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  171. return;
  172. }
  173. if (_guarView) {
  174. [_guarView removeFromSuperview];
  175. _guarView = nil;
  176. }
  177. _guarView = [[NSBundle mainBundle]loadNibNamed:@"GuaranteeView" owner:self options:nil].firstObject;
  178. _guarView.frame = CGRectMake(0, 0, _window_width, _window_height);
  179. _guarView.hideEvent = ^{
  180. [weakSelf.guarView removeFromSuperview];
  181. weakSelf.guarView = nil;
  182. };
  183. [self.view addSubview:_guarView];
  184. }
  185. }
  186. #pragma mark------添加底部按钮---------
  187. -(void)createBottom{
  188. UIView *bottomBack = [[UIView alloc]init];
  189. bottomBack.frame = CGRectMake(0, _window_height-60-ShowDiff, _window_width, 60+ShowDiff);
  190. bottomBack.backgroundColor = [UIColor whiteColor];
  191. [self.view addSubview:bottomBack];
  192. [PublicObj lineViewWithFrame:CGRectMake(0, 0, _window_width, 1) andColor:RGB(240, 240, 240) andView:bottomBack];
  193. NSArray *arr = @[@"店铺",@"客服",@"收藏",@"立即购买"];
  194. NSArray *arrTitle = @[YZMsg(@"店铺"),YZMsg(@"客服"),YZMsg(@"收藏"),YZMsg(@"立即购买")];
  195. for (int i = 0; i < arr.count; i ++) {
  196. if ( i < 3) {
  197. UIButton *btn = [UIButton buttonWithType:0];
  198. btn.frame = CGRectMake(i * _window_width *0.2, 0, _window_width *0.2, 60);
  199. NSString *langStr = @"";
  200. if ([lagType isEqual:EN]) {
  201. langStr = [common getLanguage];
  202. }
  203. [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"commodity_%@%@",arr[i],langStr]] forState:0];
  204. btn.tag = 100000+i;
  205. [btn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  206. [bottomBack addSubview:btn];
  207. if (i == 2) {
  208. isCollectBtn = btn;
  209. }
  210. }else{
  211. UIButton *btn = [UIButton buttonWithType:0];
  212. btn.frame = CGRectMake( _window_width *0.6, 0, _window_width *0.4, 60);
  213. [btn setTitle:arrTitle[i] forState:0];
  214. [btn setTitleColor:[UIColor whiteColor] forState:0];
  215. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  216. btn.tag = 100000+i;
  217. [btn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  218. [btn setBackgroundColor:Pink_Cor];
  219. [bottomBack addSubview:btn];
  220. }
  221. }
  222. }
  223. -(void)bottomBtnClick:(UIButton *)sender{
  224. if ([self.fromWhere isEqual:@"seller"]) {
  225. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  226. return;
  227. }
  228. switch (sender.tag) {
  229. case 100000:
  230. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  231. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  232. return;
  233. }
  234. [self goshopClick];
  235. break;
  236. case 100001:{
  237. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  238. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  239. return;
  240. }
  241. NSDictionary *userDic = @{
  242. @"id":self.commodityModel.shop_uid,
  243. @"user_nickname":self.commodityModel.shop_name,
  244. @"avatar":self.commodityModel.shop_avatar,
  245. };
  246. [[YBMessageManager shareManager] chatWithUser:userDic];
  247. }
  248. break;
  249. case 100002:{
  250. [self collectionGoods];
  251. }
  252. break;
  253. case 100003:{
  254. if ([self.commodityModel.goods_status isEqual:@"-1"]){
  255. [MBProgressHUD showError:YZMsg(@"商品已下架")];
  256. return;
  257. }
  258. //立即购买
  259. [self showBuyAlert];
  260. }
  261. break;
  262. default:
  263. break;
  264. }
  265. }
  266. -(void)collectionGoods{
  267. NSDictionary *dic = @{
  268. @"uid":[Config getOwnID],
  269. @"token":[Config getOwnToken],
  270. @"goodsid":self.goodsID
  271. };
  272. [YBNetworking postWithUrl:@"Shop.setCollect" Dic:dic Suc:^(int code, id info, NSString *msg) {
  273. if (code ==0) {
  274. NSDictionary *infos = [info firstObject];
  275. NSString *iscollect = minstr([infos valueForKey:@"iscollect"]);
  276. if ([iscollect isEqual:@"1"]) {
  277. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏亮")] forState:0];
  278. [MBProgressHUD showError:YZMsg(@"已收藏")];
  279. }else{
  280. [isCollectBtn setImage:[UIImage imageNamed:getImagename(@"commodity_收藏")] forState:0];
  281. [MBProgressHUD showError:YZMsg(@"已取消收藏")];
  282. }
  283. }else{
  284. [MBProgressHUD showError:msg];
  285. }
  286. } Fail:^(id fail) {
  287. }];
  288. }
  289. -(void)showBuyAlert{
  290. UIAlertController *alert = [UIAlertController alertControllerWithTitle:YZMsg(@"提示") message:YZMsg(@"此商品属于站外链接商品,可能存在一定风险,请谨慎购买") preferredStyle:UIAlertControllerStyleAlert];
  291. UIAlertAction *cancel = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  292. }];
  293. UIAlertAction *sure = [UIAlertAction actionWithTitle:YZMsg(@"继续购买") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  294. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.commodityModel.href]];
  295. }];
  296. //修改title
  297. NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:YZMsg(@"提示")];
  298. [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 2)];
  299. [alert setValue:alertControllerStr forKey:@"attributedTitle"];
  300. [cancel setValue:[UIColor blackColor] forKey:@"_titleTextColor"];
  301. [sure setValue:Pink_Cor forKey:@"_titleTextColor"];
  302. [alert addAction:cancel];
  303. [alert addAction:sure];
  304. [self presentViewController:alert animated:YES completion:nil];
  305. }
  306. #pragma mark--------店铺主页-----------
  307. -(void)goshopClick
  308. {
  309. if ([self.fromWhere isEqual:@"seller"]) {
  310. [MBProgressHUD showError:YZMsg(@"预览不支持该功能")];
  311. return;
  312. }
  313. shopDetailVC *vc = [[shopDetailVC alloc]init];
  314. vc.toUserID = minstr([self.commodityModel.shop_info valueForKey:@"uid"]);
  315. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  316. }
  317. @end