猎豆优选官网

flash_time.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. var sex = 0;
  2. var loadingFlag = false;
  3. var pageNum = 1;
  4. var maxPage = 1;
  5. var start_time = 0;
  6. var end_time = 0;
  7. var meiriData = [];
  8. var navListData = [];
  9. var con = '已开抢';
  10. $().ready(function () {
  11. $(window).scroll(function(){
  12. if($(window).scrollTop()>= $(document).height()-$(window).height() - 318){
  13. //到达底部加载数据
  14. if(loadingFlag){
  15. pageNum ++ ;
  16. flashSaleData(start_time,end_time,pageNum,con)
  17. }
  18. }
  19. if($(window).scrollTop()>400){
  20. $('.head_item_nav').css({
  21. "display": "block",
  22. "position":"fixed",
  23. "top":"46px"
  24. })
  25. }else{
  26. $('.head_item_nav').css({
  27. "display": "none",
  28. "position":"static"
  29. })
  30. }
  31. });
  32. navlistData();
  33. flashSale();
  34. ieFontColor();
  35. })
  36. //ie浏览器
  37. function ieFontColor () {
  38. if(!!window.ActiveXObject || "ActiveXObject" in window){
  39. $(".activity_title .activity_title_left span").css({"color":"#CC1C0E","background":"#ffffff"})
  40. $(".Recommend .activity_title .activity_title_left span").css({"color":"#5A6CFF","background":"#ffffff"})
  41. }
  42. }
  43. //限时抢购
  44. function flashSale () {
  45. var html = '';
  46. var nowTime = Date.parse(new Date()).toString().substr(0,10);
  47. var timeIndex = 0;
  48. activityTime.forEach(function (item, index) {
  49. if(nowTime < item.timeStamp){
  50. item.con = "即将开始"
  51. }else{
  52. item.con = "已开抢"
  53. }
  54. if(nowTime - item.timeStamp <= 151200 && nowTime - item.timeStamp > 0){
  55. timeIndex = index;
  56. }else if(nowTime > activityTime[0].timeStamp && nowTime < activityTime[1].timeStamp){
  57. timeIndex = 0;
  58. }
  59. html += "<li><div>" + item.time + "</div><span>" + item.con + "</span></li>"
  60. })
  61. if(activityTime[timeIndex+1] == undefined){
  62. start_time = activityTime[timeIndex].timeStamp;
  63. end_time = time_24;
  64. }else{
  65. start_time = activityTime[timeIndex].timeStamp;
  66. end_time = activityTime[timeIndex+1].timeStamp;
  67. }
  68. $(".flash_time ul").html(html);
  69. $(".flash_time ul li").eq(timeIndex).addClass('flash_time_active')
  70. flashSaleData(start_time,end_time,1,"已开抢")//首次渲染时候调取
  71. clickFlash()
  72. }
  73. //点击各时间段的限时抢购
  74. function clickFlash () {
  75. $(".flash_time ul li").click(function () {
  76. pageNum = 1;
  77. meiriData = [];
  78. start_time = activityTime[$(this).index()].timeStamp;
  79. con = activityTime[$(this).index()].con;
  80. if($(this).index() == $(".flash_time ul li").length-1){
  81. end_time = activityTime[0].timeStamp;
  82. }else{
  83. end_time = activityTime[$(this).index()+1].timeStamp;
  84. }
  85. $(".flash_time ul li").eq($(this).index()).addClass('flash_time_active').siblings().removeClass('flash_time_active');
  86. flashSaleData(start_time,end_time,1,con)
  87. })
  88. }
  89. //限时抢购接口
  90. function flashSaleData (start_time,end_time,page,content) {
  91. loadingFlag = false;
  92. $.ajax({
  93. type:'post',
  94. url: api.BASEURL + api.flashTime,
  95. headers:{
  96. sex:api.sex,
  97. source:api.source
  98. },
  99. dataType:"json",
  100. data:{
  101. start_time: start_time,
  102. end_time: end_time,
  103. platform: 1,
  104. page: page,
  105. page_size: 20
  106. },
  107. success: function (res) {
  108. if(res && res.errno == 0 && res.rst){
  109. var html = '';
  110. if(res.rst.data.list.length == 0 && meiriData.length == 0){
  111. if(page == 1){
  112. $(".flash_sale .commodity_list ul").html('');
  113. }
  114. $(".loading").html("没有更多了")
  115. return;
  116. }
  117. if(res.rst.data.list.length>0){
  118. pageNum ++ ;
  119. if(meiriData.length != 0){
  120. meiriData = meiriData.concat(res.rst.data.list);
  121. if(content == "已开抢"){
  122. html = flash_time(meiriData)
  123. }else if(content == '即将开始'){
  124. html = flash_time_noStart(meiriData)
  125. }
  126. }else{
  127. meiriData = res.rst.data.list;
  128. if(content == "已开抢"){
  129. html = flash_time(meiriData)
  130. }else if(content == '即将开始'){
  131. html = flash_time_noStart(meiriData)
  132. }
  133. }
  134. $(".flash_sale .commodity_list ul").html(html)
  135. loadingFlag = true;
  136. $(".loading").html("努力加载中...")
  137. }else{
  138. $(".loading").html("没有更多了")
  139. }
  140. }else{
  141. alert(res.err)
  142. }
  143. },
  144. fail: function (err) {
  145. console.log(err)
  146. }
  147. })
  148. }
  149. //导航栏目(商品分类)
  150. function navlistData (){
  151. $.ajax({
  152. type:"get",
  153. url: api.BASEURL + api.navList,
  154. headers:{
  155. sex:api.sex,
  156. source:api.source
  157. },
  158. dataType:"json",
  159. success: function (res) {
  160. if(res.errno == 0 && res.rst){
  161. if(res.rst.data){
  162. navListData = res.rst.data;
  163. var navListHtml = '';
  164. navListData.forEach(function (item,index) {
  165. navListHtml += `<li data-id=${item.id}><a href="../list/index.html?id=${item.id}&path=nav">${item.name}</a></li>`
  166. })
  167. $(".head_item_nav ul").html(navListHtml);
  168. }
  169. }
  170. },
  171. fail: function (err) {
  172. console.log(err)
  173. }
  174. });
  175. }
  176. //导航栏目(商品分类)
  177. function navlistData (){
  178. $.ajax({
  179. type:"get",
  180. url: api.BASEURL + api.navList,
  181. headers:{
  182. sex:api.sex,
  183. source:api.source
  184. },
  185. dataType:"json",
  186. success: function (res) {
  187. if(res.errno == 0 && res.rst){
  188. if(res.rst.data){
  189. navListData = res.rst.data;
  190. var navListHtml = '';
  191. navListData.forEach(function (item,index) {
  192. navListHtml += `<li data-id=${item.id}><a href="../list/index.html?id=${item.id}&path=nav">${item.name}</a></li>`
  193. })
  194. $(".head_item_nav ul").html(navListHtml);
  195. }
  196. }
  197. },
  198. fail: function (err) {
  199. console.log(err)
  200. }
  201. });
  202. }