Açıklama Yok

goods.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //获取地址栏参数
  2. function parseQueryString(url) {
  3. var urlObj = {};
  4. var reg = /([^?=&]+)=([^?=&]+)/g;
  5. url.replace(reg, ($0, $1, $2) => {
  6. urlObj[$1] = decodeURIComponent($2);
  7. })
  8. return urlObj;
  9. }
  10. var qs = parseQueryString(window.location.href);
  11. var token = '';
  12. var category_id = null;
  13. var page =1;
  14. var maxPage =1;
  15. var loadingFlag = false;
  16. var goodsData = [];//商品列表
  17. var name = '';//品牌区分标题
  18. $().ready(function () {
  19. if(qs.token){token = qs.token}
  20. if(qs.category_id) {
  21. category_id = qs.category_id;
  22. }
  23. if(qs.name){
  24. name = qs.name;
  25. }
  26. if(name == '品牌券'){
  27. getSpecialInfo(1);//淘宝专区
  28. document.title="品牌好券";
  29. }else if(name == '大额券'){
  30. stocklistByCategoryId(1)
  31. document.title="大额券专区";
  32. $('.banner').html('<img src="imgs/deq_banner.png" />')
  33. }
  34. $(window).scroll(function(){
  35. if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){
  36. //到达底部加载数据
  37. if(loadingFlag){
  38. page ++ ;
  39. if(name == '品牌券'){
  40. getSpecialInfo(page);//淘宝专区
  41. }else if(name == '大额券'){
  42. stocklistByCategoryId(page)
  43. }
  44. }
  45. }
  46. });
  47. })
  48. function stocklistByCategoryId (pageIndex) {
  49. loadingFlag = false;
  50. if(maxPage < page){
  51. $(".loading").html("没有更多了")
  52. return;
  53. }
  54. $.ajax({
  55. type:"post",
  56. url:"/api/v2/goods/stocklistByCategoryId",
  57. dataType:'json',
  58. data:{
  59. category_id:category_id,
  60. page:pageIndex
  61. },
  62. success:function (res) {
  63. console.log(res)
  64. if(res.errno == "0" && res.rst){
  65. htmlEvent(res)
  66. }
  67. }
  68. });
  69. }
  70. //淘宝专题数据
  71. function getSpecialInfo (pageIndex) {
  72. loadingFlag = false;
  73. if(maxPage < page){
  74. $(".loading").html("没有更多了")
  75. return;
  76. }
  77. $.ajax({
  78. type:"post",
  79. url:"/api/v2/goods/getSpecialInfo",
  80. dataType:'json',
  81. data:{
  82. material_id:category_id,
  83. page:pageIndex
  84. },
  85. success:function (res) {
  86. console.log(res)
  87. if(res.errno == "0" && res.rst){
  88. htmlEvent(res)
  89. }
  90. }
  91. });
  92. }
  93. function htmlEvent (res) {
  94. var data = res.rst.data;
  95. var headerName= '';
  96. var tabHtml= '',topHtml = '';
  97. var conHtml= '';
  98. var quan = '';
  99. maxPage = res.rst.pageInfo.maxPage;
  100. headerName = data.parentName;
  101. if(res.rst.pageInfo.page == 1){
  102. //第一页
  103. res.rst.data.forEach(function (item, index) {
  104. if(index < 3){
  105. topHtml += `<div class="special" onclick="toDetails({goods_id:${item.goods_id},coupon_price:${item.coupon_price},is_coupon:${item.is_coupon},price:${item.price},discount_price:${item.discount_price}})">
  106. <img src="${item.img}" alt="" class="show" style="background: #F4F4F4;"/>
  107. <div class="name">${item.title}</div>
  108. <div class="price">
  109. <span class="new_price">¥${item.discount_price}</span>
  110. <span class="old_price">¥${item.price}</span>
  111. </div>
  112. </div>`
  113. }
  114. })
  115. $("#hot_bottom").html(topHtml)
  116. }
  117. //商品
  118. if( data.length > 0){
  119. if(goodsData.length != 0){
  120. goodsData = goodsData.concat(data);
  121. goodsData.forEach(function (item, index) {
  122. var shop_type = item.shop_type, shop_type_img = '';//店铺类型,0淘宝,1天猫
  123. if(shop_type == 1){ shop_type_img = '<img src="imgs/tianmao.png" class="icon"/>' }
  124. var is_coupon = item.is_coupon, quan; //有没有券
  125. if(is_coupon == 1){ quan = `<div class="goods_coupon" ><span>券</span><span>${item.coupon_price}元</span></div>` }
  126. conHtml +=`<div class="goods_item" onclick="toDetails({goods_id:${item.goods_id},coupon_price:${item.coupon_price},is_coupon:${item.is_coupon},price:${item.price},discount_price:${item.discount_price}})">
  127. <img src="${item.img}" alt="" class="goods_img">
  128. <div class="goods_name">
  129. ${shop_type_img}
  130. ${item.title}
  131. </div>
  132. <div class="quan">
  133. ${quan}
  134. </div>
  135. <div class="goods_price">
  136. <span>券后</span>
  137. <span class="new_price">¥${item.discount_price}</span>
  138. <span class="old_price">¥${item.price}</span>
  139. </div>
  140. </div>`
  141. })
  142. }else{
  143. goodsData = res.rst.data.slice(3,);//00000
  144. goodsData.forEach(function (item, index) {
  145. var shop_type = item.shop_type, shop_type_img = '';//店铺类型,0淘宝,1天猫
  146. if(shop_type == 1){ shop_type_img = '<img src="imgs/tianmao.png" class="icon"/>' }
  147. var is_coupon = item.is_coupon, quan; //有没有券
  148. if(is_coupon == 1){ quan = `<div class="goods_coupon" ><span>券</span><span>${item.coupon_price}元</span></div>` }
  149. conHtml +=`<div class="goods_item" onclick="toDetails({goods_id:${item.goods_id},coupon_price:${item.coupon_price},is_coupon:${item.is_coupon},price:${item.price},discount_price:${item.discount_price}})">
  150. <img src="${item.img}" alt="" class="goods_img">
  151. <div class="goods_name">
  152. ${shop_type_img}
  153. ${item.title}
  154. </div>
  155. <div class="quan">
  156. ${quan}
  157. </div>
  158. <div class="goods_price">
  159. <span>券后</span>
  160. <span class="new_price">¥${item.discount_price}</span>
  161. <span class="old_price">¥${item.price}</span>
  162. </div>
  163. </div>`
  164. })
  165. }
  166. loadingFlag = true;
  167. $('#goodsList').html(conHtml)
  168. $(".loading").html("努力加载中...")
  169. }else{
  170. $(".loading").html('暂无数据')
  171. }
  172. }
  173. //跳转详情页
  174. function toDetails (res) {
  175. console.log(res)
  176. window.location.href="details.html?coupon_price=" + res.coupon_price + "&discount_price=" + res.discount_price + "&goods_id=" + res.goods_id + "&is_coupon=" + res.is_coupon + "&price=" + res.price + "&token=" + token
  177. }