|
|
@@ -8,8 +8,10 @@ const updateManager = wx.getUpdateManager()
|
|
|
import eventBus from '../../utils/eventBus';
|
|
|
|
|
|
Page({
|
|
|
- isHand:false,
|
|
|
data: {
|
|
|
+ isHand:false,
|
|
|
+ shopList:[],
|
|
|
+ showShopList:false,
|
|
|
isScroll:false,
|
|
|
active:1,
|
|
|
imgUrl:'',
|
|
|
@@ -42,7 +44,6 @@ Page({
|
|
|
hotList: [],
|
|
|
recommendedList: [],
|
|
|
totalNum: 1,
|
|
|
- addCarshow: false,
|
|
|
shopDetail: {},
|
|
|
select_address: '',
|
|
|
categoryList: [],
|
|
|
@@ -79,10 +80,7 @@ Page({
|
|
|
this.setData({
|
|
|
select_address: wx.getStorageSync('ADDRESS')
|
|
|
})
|
|
|
- // 默认店铺
|
|
|
- if(!wx.getStorageSync('shopInfo')){
|
|
|
- wx.setStorageSync('shopInfo',{shopName:'瑞果商链-“星闪豹”',shopId:1})
|
|
|
- }
|
|
|
+
|
|
|
if(wx.getStorageSync('loginResult').userId){
|
|
|
this.getUserInfo().then(()=>{
|
|
|
this.getAllData();
|
|
|
@@ -553,132 +551,49 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- /**
|
|
|
- * 秒杀
|
|
|
- */
|
|
|
- getSnapUpList: function () {
|
|
|
- wx.showLoading()
|
|
|
- var params = {
|
|
|
- url: "/seckill/pageProd",
|
|
|
- method: "GET",
|
|
|
- data: {
|
|
|
- size: 4,
|
|
|
- lat: wx.getStorageSync('LATITUDE'),
|
|
|
- lon: wx.getStorageSync('LONGITUDE'),
|
|
|
- distance: wx.getStorageSync('DISTANCE') || 0
|
|
|
- },
|
|
|
- callBack: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
- let result = res.records.filter(item => util.dateToTimestamp(item.endTime) > new Date().getTime()) //过滤掉秒杀时间已结束的商品
|
|
|
- let img = ''
|
|
|
- result.map(e => {
|
|
|
- img = e.pic.split(',')
|
|
|
- e.pic = img[0]
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- snapUpList: result
|
|
|
- });
|
|
|
- let closestItem = null;
|
|
|
- let minTimeDiff = Infinity;
|
|
|
- this.data.snapUpList.forEach((e) => {
|
|
|
- const endTime = util.dateToTimestamp(e.endTime);
|
|
|
- const now = new Date().getTime();
|
|
|
- const timeDiff = endTime - now;
|
|
|
- // 获取距离时间最近的秒杀时间
|
|
|
- if (timeDiff < minTimeDiff && timeDiff > 0) {
|
|
|
- minTimeDiff = timeDiff;
|
|
|
- closestItem = e;
|
|
|
- }
|
|
|
- })
|
|
|
- if (closestItem) {
|
|
|
- const endTime = util.dateToTimestamp(closestItem.endTime);
|
|
|
- const interval = setInterval(() => {
|
|
|
- const now = new Date().getTime();
|
|
|
- const timeDiff = endTime - now;
|
|
|
- if (timeDiff <= 0) {
|
|
|
- clearInterval(interval);
|
|
|
- return;
|
|
|
- }
|
|
|
- const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
|
|
|
- const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
|
|
- const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
|
|
|
- const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
|
|
|
- this.setData({
|
|
|
- days: days,
|
|
|
- hours: hours,
|
|
|
- minutes: minutes,
|
|
|
- seconds: seconds
|
|
|
- });
|
|
|
- }, 1000);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- http.request(params);
|
|
|
- },
|
|
|
- /**
|
|
|
- * 新品推荐
|
|
|
- */
|
|
|
- getNewList: function () {
|
|
|
- // var params = {
|
|
|
- // url: "/prod/lastedProdPage",
|
|
|
- // method: "GET",
|
|
|
- // data: {
|
|
|
- // current: 1,
|
|
|
- // size: 4,
|
|
|
- // lat: wx.getStorageSync('LATITUDE'),
|
|
|
- // lon: wx.getStorageSync('LONGITUDE'),
|
|
|
- // distance: wx.getStorageSync('DISTANCE') || 0,
|
|
|
- // shopId:this.data.shop_id
|
|
|
- // },
|
|
|
- // callBack: (res) => {
|
|
|
- // let img = ''
|
|
|
- // res.records.map(e => {
|
|
|
- // img = e.pic.split(',')
|
|
|
- // e.pic = img[0]
|
|
|
- // })
|
|
|
- // this.setData({
|
|
|
- // newList: res.records,
|
|
|
- // })
|
|
|
- // }
|
|
|
- // };
|
|
|
- // http.request(params);
|
|
|
- },
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取距离最近店铺id
|
|
|
* @param {*} e
|
|
|
*/
|
|
|
get_neighborShop: function () {
|
|
|
- var params = {
|
|
|
- url: "/shop/neighborShop",
|
|
|
- method: "GET",
|
|
|
- data: {
|
|
|
- lat: wx.getStorageSync('LATITUDE'),
|
|
|
- lon: wx.getStorageSync('LONGITUDE'),
|
|
|
- channelId:wx.getStorageSync('channelId')||3
|
|
|
- },
|
|
|
- callBack: (res) => {
|
|
|
- if(typeof res == 'number'){
|
|
|
- // this.getaddress_transports(res)
|
|
|
+ return new Promise((resolve,reject)=>{
|
|
|
+ var params = {
|
|
|
+ // url: "/shop/neighborShop",
|
|
|
+ url: "/shop/addrShop",
|
|
|
+ method: "GET",
|
|
|
+ data: {
|
|
|
+ lat: wx.getStorageSync('LATITUDE'),
|
|
|
+ lon: wx.getStorageSync('LONGITUDE'),
|
|
|
+ channelId:wx.getStorageSync('channelId')||3
|
|
|
+ },
|
|
|
+ callBack: (res) => {
|
|
|
this.setData({
|
|
|
- shop_id: res
|
|
|
+ shopList:res
|
|
|
})
|
|
|
- setTimeout(() => {
|
|
|
- this.getClassInfo(res);
|
|
|
- }, 300)
|
|
|
- }else{
|
|
|
- wx.setStorageSync('shopInfo', res)
|
|
|
- // this.getaddress_transports(res.shopId)
|
|
|
- this.setData({
|
|
|
- shop_id: res.shopId,
|
|
|
- shopName:res.shopName
|
|
|
+ if(res.every(i=>!i.hasProduct)){
|
|
|
+ return this.setData({
|
|
|
+ showShopList:true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ res.forEach(item=>{
|
|
|
+ if(item.hasProduct){
|
|
|
+ wx.setStorageSync('shopInfo', item)
|
|
|
+ // this.getaddress_transports(item.shopId)
|
|
|
+ this.setData({
|
|
|
+ shop_id: item.shopId,
|
|
|
+ shopName:item.shopName
|
|
|
+ })
|
|
|
+ resolve()
|
|
|
+ return this.getClassInfo(item.shopId);
|
|
|
+ }
|
|
|
+
|
|
|
})
|
|
|
- setTimeout(() => {
|
|
|
- this.getClassInfo(res.shopId);
|
|
|
- }, 300)
|
|
|
}
|
|
|
- }
|
|
|
- };
|
|
|
- http.request(params);
|
|
|
+ };
|
|
|
+ http.request(params);
|
|
|
+ })
|
|
|
},
|
|
|
/**
|
|
|
* 获取最大配送范围
|
|
|
@@ -708,7 +623,7 @@ Page({
|
|
|
},
|
|
|
onClose: function () {
|
|
|
this.setData({
|
|
|
- addCarshow: false
|
|
|
+ showShopList: false
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
@@ -843,18 +758,13 @@ Page({
|
|
|
* 选择定位后更新列表
|
|
|
*/
|
|
|
go_update() {
|
|
|
- // this.get_neighborShop()
|
|
|
this.setData({
|
|
|
current:1,
|
|
|
- shop_id: wx.getStorageSync("shopInfo").shopId,
|
|
|
- shopName:wx.getStorageSync("shopInfo").shopName
|
|
|
})
|
|
|
-
|
|
|
- setTimeout(() => {
|
|
|
- this.getNewList();
|
|
|
- this.getSnapUpList();
|
|
|
+ this.get_neighborShop().then(res=>{
|
|
|
this.getHotSalesProds()
|
|
|
- }, 1000)
|
|
|
+ })
|
|
|
+
|
|
|
},
|
|
|
getAllData() {
|
|
|
this.setData({
|
|
|
@@ -864,18 +774,15 @@ Page({
|
|
|
})
|
|
|
http.getCartCount(); //重新计算购物车总数量
|
|
|
this.getIndexImgs();
|
|
|
- this.getClassInfo(this.data.shopId);
|
|
|
- // this.get_neighborShop()
|
|
|
+ // this.getClassInfo(this.data.shopId);
|
|
|
// this.getNoticeList();
|
|
|
this.getAbulk();
|
|
|
this.getRecommended()
|
|
|
this.getRecommendeds()
|
|
|
this.getAdv()
|
|
|
- setTimeout(() => {
|
|
|
- this.getNewList();
|
|
|
- this.getSnapUpList();
|
|
|
- this.getHotSalesProds();
|
|
|
- }, 500)
|
|
|
+ this.get_neighborShop().then(res=>{
|
|
|
+ this.getHotSalesProds()
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
//加载轮播图
|