123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- var qs = parseQueryString(window.location.href);
- var token = '';
- var category_id = null;
- var page =1;
- var maxPage =1;
- var loadingFlag = false;
- var goodsData = [];//商品列表
- var name = '';//品牌区分标题
- $().ready(function () {
- if(qs.token){token = qs.token}
- if(qs.category_id) {
- category_id = qs.category_id;
- }
- if(qs.name){
- name = qs.name;
- }
- if(name == '品牌券'){
- getSpecialInfo(1);//淘宝专区
- document.title="品牌好券";
- }else if(name == '大额券'){
- stocklistByCategoryId(1)
- document.title="大额券专区";
- $('.banner').html('<img src="imgs/deq_banner.png" />')
- }
- $(window).scroll(function(){
- if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){
- //到达底部加载数据
- if(loadingFlag){
- page ++ ;
- if(name == '品牌券'){
- getSpecialInfo(page);//淘宝专区
- }else if(name == '大额券'){
- stocklistByCategoryId(page)
- }
- }
- }
- });
- })
- function stocklistByCategoryId (pageIndex) {
- loadingFlag = false;
- if(maxPage < page){
- $(".loading").html("没有更多了")
- return;
- }
- $.ajax({
- type:"post",
- url:"/api/v2/goods/stocklistByCategoryId",
- dataType:'json',
- data:{
- category_id:category_id,
- page:pageIndex
- },
- success:function (res) {
- console.log(res)
- if(res.errno == "0" && res.rst){
- htmlEvent(res)
- }
- }
- });
- }
- //淘宝专题数据
- function getSpecialInfo (pageIndex) {
- loadingFlag = false;
- if(maxPage < page){
- $(".loading").html("没有更多了")
- return;
- }
- $.ajax({
- type:"post",
- url:"/api/v2/goods/getSpecialInfo",
- dataType:'json',
- data:{
- material_id:category_id,
- page:pageIndex
- },
- success:function (res) {
- console.log(res)
- if(res.errno == "0" && res.rst){
- htmlEvent(res)
- }
- }
- });
- }
- function htmlEvent (res) {
- var data = res.rst.data;
- var headerName= '';
- var tabHtml= '',topHtml = '';
- var conHtml= '';
- var quan = '';
- maxPage = res.rst.pageInfo.maxPage;
- headerName = data.parentName;
- if(res.rst.pageInfo.page == 1){
- //第一页
- res.rst.data.forEach(function (item, index) {
- if(index < 3){
- 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}})">
- <img src="${item.img}" alt="" class="show" style="background: #F4F4F4;"/>
- <div class="name">${item.title}</div>
- <div class="price">
- <span class="new_price">¥${item.discount_price}</span>
- <span class="old_price">¥${item.price}</span>
- </div>
- </div>`
- }
- })
- $("#hot_bottom").html(topHtml)
- }
-
- //商品
- if( data.length > 0){
- if(goodsData.length != 0){
- goodsData = goodsData.concat(data);
- goodsData.forEach(function (item, index) {
- var shop_type = item.shop_type, shop_type_img = '';//店铺类型,0淘宝,1天猫
- if(shop_type == 1){ shop_type_img = '<img src="imgs/tianmao.png" class="icon"/>' }
- var is_coupon = item.is_coupon, quan; //有没有券
- if(is_coupon == 1){ quan = `<div class="goods_coupon" ><span>券</span><span>${item.coupon_price}元</span></div>` }
- 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}})">
- <img src="${item.img}" alt="" class="goods_img">
- <div class="goods_name">
- ${shop_type_img}
- ${item.title}
- </div>
- <div class="quan">
- ${quan}
- </div>
- <div class="goods_price">
- <span>券后</span>
- <span class="new_price">¥${item.discount_price}</span>
- <span class="old_price">¥${item.price}</span>
- </div>
- </div>`
- })
-
- }else{
- goodsData = res.rst.data.slice(3,);//00000
- goodsData.forEach(function (item, index) {
- var shop_type = item.shop_type, shop_type_img = '';//店铺类型,0淘宝,1天猫
- if(shop_type == 1){ shop_type_img = '<img src="imgs/tianmao.png" class="icon"/>' }
-
- var is_coupon = item.is_coupon, quan; //有没有券
- if(is_coupon == 1){ quan = `<div class="goods_coupon" ><span>券</span><span>${item.coupon_price}元</span></div>` }
- 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}})">
- <img src="${item.img}" alt="" class="goods_img">
- <div class="goods_name">
- ${shop_type_img}
- ${item.title}
- </div>
- <div class="quan">
- ${quan}
- </div>
- <div class="goods_price">
- <span>券后</span>
- <span class="new_price">¥${item.discount_price}</span>
- <span class="old_price">¥${item.price}</span>
- </div>
- </div>`
- })
- }
- loadingFlag = true;
- $('#goodsList').html(conHtml)
- $(".loading").html("努力加载中...")
- }else{
- $(".loading").html('暂无数据')
- }
- }
- //跳转详情页
- function toDetails (res) {
- console.log(res)
- 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
- }
|