goodsDetail.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <?php
  2. use common\components\stringUtil;
  3. ?>
  4. <link href="/css/mobile/hdx.min.css?version=<?= $this->context->version ?>" rel="stylesheet" type="text/css">
  5. <style>
  6. .goodsDetail img{
  7. width:100%;
  8. }
  9. #event_content img {
  10. max-width: 100% !important;
  11. height: auto !important;
  12. }
  13. .navbar-fixed-bottom {
  14. border-top: 1px solid #bcbcbc;
  15. box-sizing: border-box;
  16. height: 50px;
  17. z-index:90;
  18. }
  19. .navbar-bottom-small {
  20. background: #fff;
  21. }
  22. .navbar-bottom-small a.btn {
  23. padding-top: 5px;
  24. height: 50px;
  25. color: #999999
  26. }
  27. .navbar-bottom-small a.btn span {
  28. margin-right: 0px;
  29. }
  30. #reg_event_btn_enabled {
  31. height: 50px;
  32. line-height: 50px;
  33. padding: 0;
  34. }
  35. .open-app-img {
  36. width: 20px;
  37. }
  38. .navbar-bottom-small:nth-of-type(1) {
  39. border-right: 1px solid #bcbcbc;
  40. }
  41. @media all and (max-width:400px) {
  42. .modal.pay-complete.in .modal-dialog {
  43. width: 100% !important;
  44. }
  45. }
  46. @media all and (max-width:320px) {
  47. .modal.pay-complete.in .go-ticket {
  48. padding-top: 220px !important;
  49. }
  50. }
  51. @media all and (min-width:350px) and (max-width:400px) {
  52. .modal.pay-complete.in .modal-dialog {
  53. width: 350px !important;
  54. }
  55. }
  56. @media all and (min-width:401px) and (max-width:450px) {
  57. .modal.pay-complete.in .modal-dialog {
  58. width: 85% !important;
  59. }
  60. }
  61. .activeContent {
  62. position: relative;
  63. margin-top: 15px;
  64. z-index:1;
  65. }
  66. .activeContent img{
  67. width:100%;
  68. }
  69. .good-select{
  70. background:#7bb0b8;
  71. color: #ffffff;
  72. border:none;
  73. }
  74. .price-area {
  75. display:block;
  76. border:1px red;
  77. border-top: 1px solid #e0e0e0;
  78. border-bottom: 1px solid #e0e0e0;
  79. padding: 10px 0;
  80. margin-top:12px;
  81. font-size:12px;
  82. }
  83. .lay-foot .talk{
  84. display:inline-block;
  85. float:left;
  86. width:20%;
  87. border-right:1px solid #bcbcbc;
  88. }
  89. .lay-foot .talk p{
  90. margin-top:-25px;
  91. font-size:11px;
  92. color:#333;
  93. }
  94. .lay-foot .shop-card p{
  95. margin-top:-24px;
  96. font-size:11px;
  97. color:#333;
  98. }
  99. .lay-foot .shop-card{
  100. display:inline-block;
  101. float:left;
  102. width:20%;
  103. }
  104. .lay-foot .talk-img{
  105. height: 20px;
  106. width: 20px;
  107. }
  108. .lay-foot .shop-img{
  109. height: 20px;
  110. width: 20px;
  111. }
  112. .lay-foot .add-to-card{
  113. float:left;
  114. border-right:1px solid white;
  115. font-size:14px;
  116. width:30%;
  117. }
  118. .lay-foot .buy-btn{
  119. float:left;
  120. font-size:14px;
  121. width:30%;
  122. }
  123. </style>
  124. <script type="text/javascript" src="/js/idangerous.swiper.min.js?version=<?= $this->context->version ?>"></script>
  125. <div name="activeBeCenterMask" class="xhMask" ></div>
  126. <div name="shareMask" style="position:fixed;left:0;top:0;width:100%;height:100%;z-index:990;background-color:gray;filter:alpha(opacity=10);opacity:0.8;display:none;">
  127. <img style="float:right;width:60%;" src="/images/goods/share.png" />
  128. </div>
  129. <div class="lay-body lay-body2" id="J_MainBody" style="padding-top:45px;">
  130. <div class="list">
  131. <div class="swiper-container">
  132. <div class="swiper-wrapper">
  133. <?php
  134. $shopImg = json_decode($goods['shopImg'],true);
  135. foreach($shopImg as $imgVal){
  136. ?>
  137. <div class="swiper-slide swiper-slide-visible swiper-slide-active"><img name="slideImg" src="<?= Yii::$app->params['imgUrl'].$imgVal ?>"></div>
  138. <?php } ?>
  139. </div>
  140. <div class="pagination" style="margin-left: -13px;"><span class="swiper-pagination-switch swiper-visible-switch swiper-active-switch"></span></div>
  141. </div>
  142. <div class="detail-head">
  143. <h2><?= $goods['goodsName'] ?></h2>
  144. </div>
  145. <div class="detail-price clearfix">
  146. <p class="fl" id="itemPriceFl">¥<?= $goods['price'] ?></p><span style="float:right;font-size:12px;color:#888">销量 <?= stringUtil::calcAdd($goods['sold'], $goods['actualSold']) ?></span>
  147. </div>
  148. <div class="m-detail-info">
  149. <div class="info-til J_DetailToggle">
  150. <h3>简短介绍 <span>DETAILS</span></h3>
  151. <i class="minus-sign"></i>
  152. </div>
  153. <div class="info-container J_Node goodsDetail">
  154. <?= $goods['content'] ?>
  155. </div>
  156. </div>
  157. <div class="m-detail-info">
  158. <div class="info-til J_DetailToggle">
  159. <h3>简要说明 <span>OUTLINE</span></h3>
  160. <i class="minus-sign"></i>
  161. </div>
  162. <div class="info-container J_Node goodsDetail">
  163. <?= $goods['goodSIntroduce'] ?>
  164. </div>
  165. </div>
  166. <div class="m-detail-info">
  167. <div class="info-til">
  168. <h3>分享给朋友 <span>ShARE</span></h3>
  169. <!-- <i class="icon-minus-sign"></i> -->
  170. </div>
  171. <div class="info-share">
  172. <div class="bdsharebuttonbox bdshare-button-style0-24" data-bd-bind="1439564077661">
  173. <a title="分享到微信" href="javascript:void(0)" name="weixinShare" class="bds_weixin" data-cmd="weixin"><img src="/images/wxsharelogo.png" width="28" /></a>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. <footer class="lay-foot J_MenuBody">
  179. <!-- 商品数据表单 -->
  180. <form action="/mobile/goods-order?account=<?= $_GET['account'] ?>" id="goodsOrder" method="POST">
  181. <input type="hidden" name="_csrf" value="=<?= Yii::$app->request->csrfToken ?>" />
  182. <input type="hidden" name="sourceType" value="0" />
  183. <input type="hidden" name="goodsInfo[0][goodsId]" value="<?= $goods['id']?>" />
  184. <input type="hidden" name="goodsInfo[0][check]" value="<?= $goods['id'] ?>" />
  185. <input type="hidden" id="goodsNum" name="goodsInfo[0][num]" value="1" />
  186. <!-- 多价格表单项 -->
  187. <input type="hidden" name="multiPriceGoodId" value="<?= $goods['id']?>"/>
  188. <input type="hidden" name="isMultiPrice" value="0" />
  189. <input type="hidden" name="goodsInfo[0][multiPriceId]" class="multi-price-id"/>
  190. <!-- 多价格表单项结束 -->
  191. <?php if($this->context->isLogin){ ?>
  192. <?php if($goods['multiPrice'] == ''){ ?>
  193. <a href="/chat/index?account=<?=$merchant['id']?>&goodsId=<?=$goods['id']?>" class="talk"><div style="margin-top:-13px;"><img class="talk-img" src="/images/chatIcon.png"><p>客服</p></div></a>
  194. <a href="/cart/index?account=<?=$merchant['id']?>" class="shop-card"><div style="margin-top:-14px;"><img class="shop-img" src="/images/shopIcon.png"><p>购物车</p></div></a>
  195. <button type="button" class="foot-btn add-to-card" onclick="showMultiPrice('addToCart')" data-id="<?= $goods['id'] ?>">+购物车</button>
  196. <button type="button" class="foot-btn buy-btn" onclick="showMultiPrice('buy')">&nbsp;购&nbsp;买&nbsp;&nbsp;</button>
  197. <?php }else{ ?>
  198. <a href="/chat/index?account=<?=$merchant['id']?>&goodsId=<?=$goods['id']?>" class="talk"><div style="margin-top:-13px;"><img class="talk-img" src="/images/chatIcon.png"><p>客服</p></div></a>
  199. <a href="/cart/index?account=<?=$merchant['id']?>" class="shop-card"><div style="margin-top:-14px;"><img src="/images/shopIcon.png"><p>购物车</p></div></a>
  200. <button type="button" class="foot-btn add-to-card" onclick="showMultiPrice('addToCart')" data-id="<?= $goods['id'] ?>">+购物车</button>
  201. <button type="button" class="foot-btn buy-btn" onclick="showMultiPrice('buy')">&nbsp;购&nbsp;买&nbsp;&nbsp;</button>
  202. <?php } ?>
  203. <?php }else{ ?>
  204. <a href="/chat/index?account=<?=$merchant['id']?>&goodsId=<?=$goods['id']?>" class="talk"><div style="margin-top:-13px;"><img class="talk-img" src="/images/chatIcon.png"><p>客服</p></div></a>
  205. <a href="/cart/index?account=<?=$merchant['id']?>" class="shop-card"><div style="margin-top:-14px;"><img class="shop-img" src="/images/shopIcon.png"><p>购物车</p></div></a>
  206. <button type="button" class="foot-btn add-to-card" onclick="goToLogin('<?= $_SERVER['REQUEST_URI'].'&wantLogin=yes' ?>');">加入购物车</button>
  207. <button type="button" class="foot-btn buy-btn" onclick="goToLogin('<?= $_SERVER['REQUEST_URI'].'&wantLogin=yes' ?>');">&nbsp;购&nbsp;买&nbsp;&nbsp;</button>
  208. <?php } ?>
  209. </form>
  210. </footer>
  211. <div class="modal fade ticket-modal ticket-modal-bottom in" id="price-modal" data-scroll="true" aria-hidden="false" style="display:none; transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);-webkit-overflow-scrolling: touch; z-index:9999;">
  212. <div class="modal-dialog">
  213. <div class="modal-content" style="position: relative; overflow:auto;-webkit-overflow-scrolling: touch; overflow-x: hidden;">
  214. <h4 class="modal-header" style="font-size:14px;">
  215. 商品选择
  216. <div class="close" name="activeClose" data-dismiss="modal"><span class="icon-close-bubble"></span></div>
  217. </h4>
  218. <div class="media">
  219. <img class="pull-left" src="<?= Yii::$app->params['imgUrl'].$shopImg[0] ?>" alt="">
  220. <div class="media-body">
  221. <h3><?= $goods['goodsName'] ?></h3>
  222. <div>¥<span id="current-good-price"><?= $goods['actualSold'] ?></span></div>
  223. </div>
  224. </div>
  225. <div class="modal-body" style="overflow:auto; overflow-x:-webkit-overflow-scrolling: touch; hidden;margin-bottom: 40px;max-height:300px;">
  226. <div>
  227. <?php
  228. if(!empty($goods['multiPrice'])){
  229. ?>
  230. <div class="popover-box" id="event_tickets_area" style="overflow:auto; overflow-x:-webkit-overflow-scrolling: touch;font-size:12px;">
  231. 选项:
  232. <ul name="event_tickets_thumbs" class="price-choise-btn">
  233. <?php
  234. foreach($goods['goodsPriceArr'] as $key => $item){
  235. ?>
  236. <div style="display:block;padding-top:12px;">
  237. <button class="btn btn-default btn-xs" style="font-size:11px;" data-id="<?=$item['id']?>" data-price="<?=$item['price']?>" data-price="<?=$item['price']?>" data-img-url="<?=$item['picture']?>" ><?=$item['title']?></button>
  238. </div>
  239. <?php
  240. }
  241. ?>
  242. </ul>
  243. </div>
  244. <?php
  245. }
  246. ?>
  247. <div class="price-area">
  248. 购买数量
  249. <button class="btn btn-default" style="height:25px;padding:0 5px;" onclick="changeNumber('reduce')">&nbsp;-&nbsp;</button><input type="text" value="1" style="text-align:center;margin:0 12px;margin-top:8px;color:#4B797E;width:15%;height:25px;border-color:#e5e5e5;" id="buy-count"/><button class="btn btn-default" style="height:25px;padding:0 5px;" onclick="changeNumber('increase')">&nbsp;+&nbsp;</button>
  250. </div>
  251. </div>
  252. </div>
  253. </div>
  254. <footer class="lay-foot J_MenuBody">
  255. <div class="clearfix" id="confirm-btn">
  256. <button class="btn-block foot-btn" style="font-size: 14px;"></button>
  257. </div>
  258. </footer>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. <script type="text/javascript">
  264. //微信分享到朋友圈
  265. $("a[name=weixinShare]").click(function(){
  266. $("div[name=shareMask]").css("display","block");
  267. });
  268. $("div[name=shareMask]").click(function(){
  269. $(this).css("display","none");
  270. });
  271. /*banner轮播*/
  272. var mySwiper = new Swiper('.swiper-container',{
  273. pagination: '.pagination',
  274. loop:true,
  275. autoplay: 2000,//可选选项,自动滑动
  276. speed: 2000,
  277. grabCursor: true,
  278. paginationClickable: true
  279. });
  280. $('.pagination').eq(0).css({marginLeft:-$('.pagination').width()/2+'px'});
  281. $('.swiper-container').on('swipeLeft', function(e){ e.stopPropagation(); });
  282. $('.swiper-container').on('swipeRight', function(e){ e.stopPropagation(); });
  283. //幻灯片图片外框自适应图片大小
  284. $(window).load(function() {
  285. var thisSwiperHeight = $("img[name=slideImg]").eq(0).css('height');
  286. $('.swiper-container').css('height',thisSwiperHeight);
  287. $('.banner-container').css('height',thisSwiperHeight);
  288. });
  289. $('.swiper-container img').each(function(){
  290. var src = $(this).attr('src');
  291. $(this).on('tap',function(e){
  292. e.preventDefault();
  293. var img = new Image();
  294. img.src = src, img.className = 'pro-detail-pic J_Pic';
  295. $('body').append(img);
  296. $('.J_Mask').show().css({opacity:0.5, height:$('.lay-wrap').height()+'px'});
  297. $('.J_Pic').on('tap', function(){
  298. $('.J_Mask').hide();
  299. $(this).remove();
  300. });
  301. });
  302. });
  303. //添加到购物车
  304. $(function(){
  305. $("button[name=addToCart]").click(function(){
  306. var num = $("#goodsNum").val();
  307. num = parseInt(num) > 0 ? parseInt(num) : 1;
  308. var goodsId = $(this).attr('data-id');
  309. var data = "num="+num+"&goodsId="+goodsId+"&_csrf=<?= Yii::$app->request->csrfToken ?>";
  310. $.ajax({
  311. type:"POST",
  312. url:'/cart/add?account=<?= $_GET['account'] ?>',
  313. data:data,
  314. dataType:'json',
  315. async:false,
  316. success:function(data){
  317. if(data.code == 'A0001'){
  318. xhPopMsg(data.msg);
  319. }
  320. }
  321. });
  322. });
  323. });
  324. <?php if($this->context->isWeixin){ ?>
  325. //微信分享
  326. var shareTitle = '<?= $goods['goodsName'] ?>';
  327. var descContent = '<?= $goods['material'] ?>';
  328. var lineLink = '<?= Yii::$app->request->hostInfo ?>/mobile/goods-detail?id=<?= $goods['id'] ?>&account=<?= $_GET['account'] ?>&weixinShare=yes';
  329. var imgUrl = '<?= Yii::$app->params['imgUrl'].$goods['cover'] ?>';
  330. wx.config({
  331. debug:false,
  332. appId: '<?= $this->context->signPackage['appId'] ?>',
  333. timestamp: <?= $this->context->signPackage['timestamp'] ?>,
  334. nonceStr: '<?= $this->context->signPackage['nonceStr'] ?>',
  335. signature: '<?= $this->context->signPackage['signature'] ?>',
  336. jsApiList: [
  337. 'checkJsApi',
  338. 'onMenuShareTimeline',
  339. 'onMenuShareAppMessage',
  340. 'onMenuShareQQ',
  341. 'onMenuShareWeibo',
  342. ]
  343. });
  344. wx.ready(function () {
  345. var shareData = {
  346. title: shareTitle,
  347. link: lineLink,
  348. imgUrl: imgUrl,
  349. desc:descContent,
  350. };
  351. wx.onMenuShareAppMessage(shareData);
  352. wx.onMenuShareTimeline({
  353. title: shareTitle,
  354. link: lineLink,
  355. imgUrl: imgUrl,
  356. desc:descContent,
  357. success: function () {
  358. //分享成功后的操作
  359. },
  360. cancel: function () {
  361. // 用户取消分享后执行的回调函数
  362. }
  363. });
  364. wx.onMenuShareQQ({
  365. title: shareTitle,
  366. link: lineLink,
  367. imgUrl: imgUrl,
  368. desc:descContent,
  369. success: function () {
  370. //分享成功后的操作
  371. },
  372. cancel: function () {
  373. // 用户取消分享后执行的回调函数
  374. }
  375. });
  376. wx.onMenuShareWeibo(shareData);
  377. });
  378. <?php } ?>
  379. /*幻灯片/触摸屏向下滑动隐藏/向上滑动显示*/
  380. (function(){
  381. var startX, startY, endX, endY, mainbody = $('#J_MainBody').get(0);
  382. mainbody.addEventListener('touchstart',function(event){
  383. startX = event.changedTouches[0].pageX;
  384. startY = event.changedTouches[0].pageY;
  385. });
  386. mainbody.addEventListener('touchend', function(event){
  387. endX = event.changedTouches[0].pageX;
  388. endY = event.changedTouches[0].pageY;
  389. if( (startY-endY) > 50 ){
  390. $('#J_SubHead').css({top:0});
  391. }else if( (startY-endY) < -50 ){
  392. $('#J_SubHead').css({top:'45px'});
  393. }
  394. });
  395. })();
  396. //========================= 多价格选项 浮层 ================================
  397. var multiPrice = "<?= $goods['multiPrice'] ?>";
  398. var activeBeCenterMask = $("div[name=activeBeCenterMask]");
  399. function showMultiPrice(action){
  400. var price = "<?= $goods['price'] ?>";
  401. var priceArr = price.split("-");
  402. var count = priceArr.length;
  403. if(action == 'buy'){
  404. $("#confirm-btn").find('.foot-btn').html('确定购买');
  405. $('#current-good-price').html(priceArr[0]);
  406. $('#buy-count').val(1);
  407. if(count == 2){
  408. $('#goodsOrder input[name=isMultiPrice]').val(1);
  409. }else{
  410. $('#goodsOrder .multi-price-id').remove();
  411. }
  412. }else if(action == 'addToCart'){
  413. $("#confirm-btn").find('.foot-btn').html('加入购物车');
  414. $('#current-good-price').html(priceArr[0]);
  415. $('#buy-count').val(1);
  416. if(count == 2){
  417. $('#goodsOrder input[name=isMultiPrice]').val(1);
  418. }else{
  419. $('#goodsOrder .multi-price-id').remove();
  420. }
  421. }
  422. $("#price-modal").css('display','block');
  423. activeBeCenterMask.css('display','block');
  424. $('html').addClass('noscroll');//有浮层不允许底部滚动
  425. }
  426. //价格上下调动
  427. function changeNumber(action){
  428. var num = parseInt($("#buy-count").val());
  429. if(action == 'reduce'){
  430. num -= 1;
  431. if(num < 1){
  432. //alert('退出操作');
  433. return;
  434. }
  435. $("#buy-count").val(num);
  436. $("#goodsNum").val(num);//表单Id(goodsOrder)里的商品数量
  437. }else if(action == 'increase'){
  438. num += 1;
  439. $("#buy-count").val(num);
  440. $("#goodsNum").val(num);//表单Id(goodsOrder)里的商品数量
  441. }
  442. }
  443. $("div[name=activeClose]").click(function(){
  444. $("#price-modal").css('display','none');
  445. activeBeCenterMask.css('display','none');
  446. $('#goodsOrder input[name=isMultiPrice]').val(0);
  447. $('html').removeClass('noscroll');//允许底部滚动
  448. });
  449. //价格选项
  450. $("#price-modal .price-choise-btn .btn").on('click', function(){
  451. var id = $(this).attr('data-id');
  452. var price = $(this).attr('data-price');
  453. var imgUrl = $(this).attr('data-img-url');
  454. var preImgUrl = "<?= Yii::$app->params['imgUrl']; ?>";
  455. $(this).addClass('btn-turquoise good-select');
  456. $(this).parent().siblings().find('.btn').removeClass('btn-turquoise good-select');
  457. $('#current-good-price').html(price);
  458. $('#goodsOrder input[name=isMultiPrice]').val(1);
  459. $('#goodsOrder .multi-price-id').val(id);
  460. if(imgUrl != ''){
  461. $('img.pull-left').attr('src', preImgUrl+imgUrl);
  462. }
  463. });
  464. $("#confirm-btn .foot-btn").on('click', function(){
  465. var content = $(this).html();
  466. var multiPriceId = $('#goodsOrder .multi-price-id').val();
  467. if((multiPriceId == '' || isNaN(multiPriceId)) && multiPrice != ''){
  468. xhPopMsg('请选择其中一选项');
  469. return;
  470. }
  471. if(content == '确定购买'){//多价格的商品 确定购买
  472. $('#goodsOrder').submit();
  473. }else if(content == '加入购物车'){//多价格的商品 添加到购物车
  474. var num = $("#buy-count").val();
  475. num = parseInt(num) > 0 ? parseInt(num) : 1;
  476. var goodsId = $('#goodsOrder input[name=multiPriceGoodId]').val();
  477. var data = "num="+num+"&goodsId="+goodsId+"&_csrf=<?= Yii::$app->request->csrfToken ?>";
  478. if(multiPrice != ''){
  479. data += "&multiPriceId="+multiPriceId+"&isMultiPrice=1";
  480. }
  481. $.ajax({
  482. type:"POST",
  483. url:'/cart/add?account=<?= $_GET['account'] ?>',
  484. data:data,
  485. dataType:'json',
  486. async:false,
  487. success:function(data){
  488. if(data.code == 'A0001'){
  489. $("#price-modal").css('display','none');
  490. activeBeCenterMask.css('display','none');
  491. xhPopMsg(data.msg);
  492. }
  493. }
  494. });
  495. }
  496. })
  497. </script>