productDetails.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. {extend name="base" /}
  2. {block name="title"}GoodsDetail{/block}
  3. {block name="styles"}
  4. <link rel="stylesheet" href="/assets/index/css/productDetails.css?t=11101">
  5. {/block}
  6. {block name="mainArea"}
  7. <section class="sectionContainer">
  8. <div class="elementorContainer">
  9. <!-- 产品模块 -->
  10. <section class="productContainer">
  11. <!-- 产品图片 -->
  12. <div class="productImgContainer">
  13. <div class="prViewImgBox">
  14. <img class="prViewImg lazy" src="/assets/index/asstes/icon/transparent.png"
  15. data-original="{$goods.goods_image}" alt="">
  16. </div>
  17. <div class="prImgContainer">
  18. <div class="prImgList">
  19. {foreach $goods.goods_images as $img}
  20. <div class="prImgItem">
  21. <img class="lazy" src="/assets/index/asstes/icon/transparent.png"
  22. data-original="{$img.preview_url}" alt="">
  23. </div>
  24. {/foreach}
  25. </div>
  26. <div class="prevArrow">&lt;</div>
  27. <div class="nextArrow">&gt;</div>
  28. </div>
  29. </div>
  30. <!-- 产品信息 -->
  31. <div class="productInfoContainer">
  32. <div>
  33. <h1 class="productTitle">{$goods.goods_name}</h1>
  34. <div class="productPrice">
  35. <p><span>$</span>{$goods.goods_price_min}</p>
  36. </div>
  37. </div>
  38. <div>
  39. <!-- 数量 -->
  40. <div class="productNContainer">
  41. <div class="productNumberBox">
  42. <div class="numberReduce">-</div>
  43. <input id="numberInput" value="1" type="text"/>
  44. <div class="numberAdd">+</div>
  45. </div>
  46. <div class="addToCart">
  47. <p class="tag">+</p>
  48. <p>Add To Cart</p>
  49. </div>
  50. </div>
  51. <div class="safeContainer">
  52. <p class="safeTag">Guaranteed Safe Checkout</p>
  53. <div class="safeList">
  54. <div class="safeItem">
  55. <img src="https://img2.baidu.com/it/u=810087687,2144202516&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1710003600&t=5d86d51c836405ef2225baf3d4aa9349"
  56. alt="">
  57. </div>
  58. <div class="safeItem">
  59. <img src="https://img2.baidu.com/it/u=810087687,2144202516&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1710003600&t=5d86d51c836405ef2225baf3d4aa9349"
  60. alt="">
  61. </div>
  62. <div class="safeItem">
  63. <img src="https://img2.baidu.com/it/u=810087687,2144202516&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1710003600&t=5d86d51c836405ef2225baf3d4aa9349"
  64. alt="">
  65. </div>
  66. <div class="safeItem">
  67. <img src="https://img2.baidu.com/it/u=810087687,2144202516&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1710003600&t=5d86d51c836405ef2225baf3d4aa9349"
  68. alt="">
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </section>
  75. <!-- 文案模块 -->
  76. <article class="articleContainer">
  77. <div class="articleTabBox">
  78. <div class="articleTabItem active" data-type="description">
  79. <p class="tabTag"></p>
  80. <h2 class="articleTabTitle">Description</h2>
  81. </div>
  82. <div class="articleTabItem" data-type="reviews">
  83. <p class="tabTag"></p>
  84. <h2 class="articleTabTitle">Reviews ({$comment_total})</h2>
  85. </div>
  86. </div>
  87. <!-- 商品详情容器 -->
  88. <div class="articleInfo" id="articleInfo">
  89. <h2 class="articleTitle">Product description</h2>
  90. <div id="richTextContainer"></div>
  91. </div>
  92. <!-- 评价内容容器 -->
  93. <div id="reviewsInfo">
  94. <div id="reviews">
  95. </div>
  96. <div id="loadingIndicator">loading...</div>
  97. <div id="reviewsButtonContainer">
  98. <div id="reviewsButtonBox">
  99. <div id="prevPage">Prev page</div>
  100. <div id="nextPage">Next page</div>
  101. </div>
  102. </div>
  103. </div>
  104. </article>
  105. <!-- 悬浮底部模块 -->
  106. <section class="fixedAddSection">
  107. <div class="fixedAddContainer">
  108. <div class="elementorContainer">
  109. <div class="fixedAddBox">
  110. <div class="fPrInfo">
  111. <img class="img lazy" src="/assets/index/asstes/icon/transparent.png"
  112. data-original="https://www.buranshao.com/Content/Img/iqos3duo.jpg" alt="">
  113. <h3 class="fTitle">NEW VAPES</h3>
  114. </div>
  115. <div class="fPrNumberContainer">
  116. <p class="fPrPrice">${$goods.goods_price_min}</p>
  117. <div class="fPrNumberBox">
  118. <div class="fPrNumberReduce">-</div>
  119. <input id="fPrNumberInput" value="1" type="text"/>
  120. <div class="fPrNumberAdd">+</div>
  121. </div>
  122. <div class="fPrAddToCart">
  123. <p class="tag">+</p>
  124. <p>Add To Cart</p>
  125. </div>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </section>
  131. </div>
  132. </section>
  133. {/block}
  134. {block name="scriptSrc"}
  135. <script>
  136. $(document).ready(function () {
  137. //触屏事件 || 点击事件
  138. const tap = "ontouchstart" in window ? "touchstart" : "click";
  139. var goodsId = {$goods.goods_id};
  140. var goodsSkuId = {$goods['skuList'][0]['goods_sku_id']};
  141. //富文本处理
  142. function initRichText() {
  143. $("#richTextContainer").html(`{$goods.content | raw}`)
  144. }
  145. /**
  146. * 添加购物车
  147. * @param number 数量
  148. * @returns
  149. */
  150. function addCart(number) {
  151. if (!number || number <= 0) {
  152. showToast("Please enter the quantity of products")
  153. return
  154. }
  155. var dp = {
  156. goodsId: goodsId,
  157. goodsSkuId: goodsSkuId,
  158. goodsNum: number
  159. }
  160. $.ajax({
  161. url: "/index/cart/add",
  162. headers: {platform: 'H5'},
  163. dataType: 'json',
  164. data: JSON.stringify(dp),
  165. type: "POST",
  166. contentType: 'application/json',
  167. success: function (obj) {
  168. //注册成功后进入
  169. if (obj.status === 200 || obj.status === '200') {
  170. showToast("Successful")
  171. window.location.href = '/index/cart/shoppingCart.html';
  172. return
  173. } else if (obj.status === 401 || obj.status === '401') {
  174. window.location.replace('../passport/logIn.html')
  175. } else {
  176. showToast(obj.message)
  177. }
  178. }
  179. })
  180. }
  181. /**
  182. * 吐司提示
  183. * @param message 消息
  184. * @returns
  185. */
  186. function showToast(message) {
  187. var toastElement = $('#toastContainer');
  188. toastElement.text(message);
  189. toastElement.stop(true, true).fadeIn(200).delay(2000).fadeOut(200);
  190. }
  191. //商品数量减少
  192. $('.numberReduce, .fPrNumberReduce').click(function () {
  193. var container = $(this).closest('.productNumberBox, .fPrNumberBox');
  194. var inputElement = container.find('#numberInput, #fPrNumberInput');
  195. var currentValue = parseInt(inputElement.val());
  196. if (currentValue > 1) {
  197. inputElement.val(currentValue - 1);
  198. var totalMoney = {$goods.goods_price_min} * (currentValue - 1)
  199. $('.fPrPrice').html('$' + totalMoney.toFixed(2))
  200. }
  201. });
  202. //商品数量增加
  203. $('.numberAdd, .fPrNumberAdd').click(function () {
  204. var container = $(this).closest('.productNumberBox, .fPrNumberBox');
  205. var inputElement = container.find('#numberInput, #fPrNumberInput');
  206. var currentValue = parseInt(inputElement.val());
  207. inputElement.val(currentValue + 1);
  208. var totalMoney = {$goods.goods_price_min} * (currentValue + 1)
  209. console.log(totalMoney)
  210. $('.fPrPrice').html('$' + totalMoney.toFixed(2))
  211. });
  212. // 输入框禁止为空小于等于0
  213. $('#numberInput, #fPrNumberInput').change(function () {
  214. var inputElement = $(this);
  215. var currentValue = parseInt(inputElement.val());
  216. if (currentValue < 1 || isNaN(currentValue)) {
  217. inputElement.val(1);
  218. }
  219. });
  220. //上面的添加按钮
  221. $(".addToCart").on(tap, function () {
  222. const number = $('#numberInput').val();
  223. addCart(number)
  224. });
  225. //悬浮模块的添加按钮
  226. $(".fPrAddToCart").on(tap, function () {
  227. const number = $('#fPrNumberInput').val();
  228. addCart(number)
  229. });
  230. initRichText()
  231. //页码
  232. let page = 1;
  233. //总页数
  234. let totalPage = {$comment_total}
  235. //页数
  236. let itemsPerPage = 10;
  237. //加载中
  238. let isLoading = false;
  239. //详情 & 评论切换
  240. $(".articleTabItem").on(tap, function () {
  241. const type = $(this).attr("data-type")
  242. $(this).addClass("active").siblings().removeClass("active")
  243. // 评论
  244. if (type === "reviews") {
  245. $("#reviewsInfo").show(0)
  246. $("#articleInfo").hide(0)
  247. getReviews()
  248. page = 1
  249. } else {
  250. // 详情
  251. $("#articleInfo").show(0)
  252. $("#reviewsInfo").hide(0)
  253. }
  254. });
  255. //上一页
  256. $("#prevPage").on(tap, function () {
  257. if (page > 1) {
  258. page--
  259. } else {
  260. page = 1
  261. }
  262. getReviews()
  263. });
  264. //下一页
  265. $("#nextPage").on(tap, function () {
  266. if (page >= totalPage) {
  267. page = totalPage
  268. } else {
  269. page++
  270. }
  271. getReviews()
  272. });
  273. // 获取评价列表
  274. function getReviews() {
  275. if (isLoading) {
  276. return;
  277. }
  278. isLoading = true;
  279. // 显示加载指示器
  280. $('#loadingIndicator').show();
  281. //调试后记得去除这段代码
  282. $.ajax({
  283. url: '/index/comment/listPage?goodsId=' + goodsId,
  284. type: 'GET',
  285. data: {
  286. page: page,
  287. per_page: itemsPerPage
  288. },
  289. success: function (response) {
  290. console.log(response.data)
  291. const data = response.data.list.data
  292. // 在页面中添加数据
  293. const container = $('#reviews');
  294. //var html = container.html();
  295. var html = '';
  296. //container.html("")
  297. $.each(data, function (index, item) {
  298. const rating = item.score / 10;
  299. let starHtml = "";
  300. for (let i = 0; i < 5; i++) {
  301. if (i < rating) {
  302. starHtml += '<img src="/assets/index/asstes/icon/selStar.png" alt="">';
  303. } else {
  304. starHtml += '<img src="/assets/index/asstes/icon/star.png" alt="">';
  305. }
  306. }
  307. html += `
  308. <div class="reviewItem">
  309. <div class="userInfo">
  310. <div class="userImg">
  311. <img src="https://himg.bdimg.com/sys/portrait/item/tb.1.772a23f6.WIunUru1_286k2Q9BG9SJg" alt="">
  312. </div>
  313. <p class="userName">${item.user.nick_name}</p>
  314. </div>
  315. <div class="reInfo">
  316. <div class="starBox">${starHtml}
  317. </div>
  318. <h3 class="reviewValues">${item.content}</h3>
  319. </div>
  320. </div>`;
  321. });
  322. container.html(html);
  323. //数据长度大于0显示上下页按钮
  324. //$('#reviewsButtonContainer').show();
  325. console.log(response.data.list.last_page, page, response.data.list.last_page > page)
  326. if (response.data.list.last_page > page) {
  327. $("#nextPage").show()
  328. } else {
  329. $("#nextPage").hide()
  330. }
  331. if (page > 1) {
  332. $("#prevPage").show()
  333. } else {
  334. $("#prevPage").hide()
  335. }
  336. // 隐藏加载指示器
  337. $('#loadingIndicator').hide();
  338. isLoading = false;
  339. },
  340. error: function () {
  341. // 处理错误情况
  342. console.log('请求数据失败');
  343. // 隐藏加载指示器
  344. $('#loadingIndicator').hide();
  345. isLoading = false;
  346. }
  347. });
  348. }
  349. });
  350. </script>
  351. {/block}