|
|
@@ -8,8 +8,12 @@ const updateManager = wx.getUpdateManager()
|
|
|
import eventBus from '../../utils/eventBus';
|
|
|
|
|
|
Page({
|
|
|
- isHand:false,
|
|
|
data: {
|
|
|
+ showPopup:false,
|
|
|
+ imageUrl:'',
|
|
|
+ isHand:false,
|
|
|
+ shopList:[],
|
|
|
+ showShopList:false,
|
|
|
isScroll:false,
|
|
|
active:1,
|
|
|
imgUrl:'',
|
|
|
@@ -42,7 +46,6 @@ Page({
|
|
|
hotList: [],
|
|
|
recommendedList: [],
|
|
|
totalNum: 1,
|
|
|
- addCarshow: false,
|
|
|
shopDetail: {},
|
|
|
select_address: '',
|
|
|
categoryList: [],
|
|
|
@@ -65,6 +68,7 @@ Page({
|
|
|
},
|
|
|
|
|
|
onLoad: function () {
|
|
|
+ console.log('load');
|
|
|
// 实例化API核心类
|
|
|
qqmapsdk = new QQMapWX({
|
|
|
key: 'D3MBZ-LQK6U-IONVC-GJDPK-C43GF-UYFOC'
|
|
|
@@ -79,10 +83,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();
|
|
|
@@ -163,32 +164,32 @@ Page({
|
|
|
wx.setStorageSync('LATITUDE', res.latitude)
|
|
|
wx.setStorageSync('LONGITUDE', res.longitude)
|
|
|
// 调用腾讯地图api获取当前位置
|
|
|
- qqmapsdk.reverseGeocoder({
|
|
|
- location: {
|
|
|
- latitude: latitude,
|
|
|
- longitude: longitude
|
|
|
- },
|
|
|
- success: function (res) {
|
|
|
- console.log(res.result, '---address_success');
|
|
|
- wx.setStorageSync('ADDRESS', res.result.address_component.street)
|
|
|
- that.setData({
|
|
|
- select_address: wx.getStorageSync('ADDRESS')
|
|
|
- })
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- console.log(res, '---address_err');
|
|
|
- wx.showToast({
|
|
|
- title: res + '地址信息获取失败',
|
|
|
- icon: "none"
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- wx.hideToast();
|
|
|
- }, 2000)
|
|
|
- },
|
|
|
- complete: function (res) {
|
|
|
- // console.log(res, '---callback');
|
|
|
- }
|
|
|
- });
|
|
|
+ // qqmapsdk.reverseGeocoder({
|
|
|
+ // location: {
|
|
|
+ // latitude: latitude,
|
|
|
+ // longitude: longitude
|
|
|
+ // },
|
|
|
+ // success: function (res) {
|
|
|
+ // console.log(res.result, '---address_success');
|
|
|
+ // wx.setStorageSync('ADDRESS', res.result.address_component.street)
|
|
|
+ // that.setData({
|
|
|
+ // select_address: wx.getStorageSync('ADDRESS')
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ // fail: function (res) {
|
|
|
+ // console.log(res, '---address_err');
|
|
|
+ // wx.showToast({
|
|
|
+ // title: res + '地址信息获取失败',
|
|
|
+ // icon: "none"
|
|
|
+ // })
|
|
|
+ // setTimeout(() => {
|
|
|
+ // wx.hideToast();
|
|
|
+ // }, 2000)
|
|
|
+ // },
|
|
|
+ // complete: function (res) {
|
|
|
+ // // console.log(res, '---callback');
|
|
|
+ // }
|
|
|
+ // });
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
wx.removeStorageSync('ADDRESS')
|
|
|
@@ -279,6 +280,27 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 弹窗公告
|
|
|
+ */
|
|
|
+ getDialog: function () {
|
|
|
+ var params = {
|
|
|
+ url: "/popup/config",
|
|
|
+ method: "GET",
|
|
|
+ data: {
|
|
|
+ },
|
|
|
+ callBack: (res) => {
|
|
|
+ this.setData({
|
|
|
+ showPopup:res.showPopup,
|
|
|
+ imageUrl:res.imageUrl
|
|
|
+ })
|
|
|
+ }
|
|
|
+ };
|
|
|
+ http.request(params);
|
|
|
+ },
|
|
|
+ onClickHide:function(){
|
|
|
+ this.setData({showPopup:false})
|
|
|
+ },
|
|
|
/**
|
|
|
* 广告位
|
|
|
*/
|
|
|
@@ -553,132 +575,54 @@ 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)
|
|
|
- this.setData({
|
|
|
- shop_id: res
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- this.getClassInfo(res);
|
|
|
- }, 300)
|
|
|
- }else{
|
|
|
- wx.setStorageSync('shopInfo', res)
|
|
|
- // this.getaddress_transports(res.shopId)
|
|
|
+ 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.shopId,
|
|
|
- shopName:res.shopName
|
|
|
+ shopList:res
|
|
|
})
|
|
|
- setTimeout(() => {
|
|
|
- this.getClassInfo(res.shopId);
|
|
|
- }, 300)
|
|
|
+ if(res.every(i=>!i.hasProduct)){
|
|
|
+ return this.setData({
|
|
|
+ showShopList:true
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < res.length; i++) {
|
|
|
+ const item = res[i];
|
|
|
+ if(item.hasProduct){
|
|
|
+ console.log('==========================');
|
|
|
+ wx.setStorageSync('shopInfo', item)
|
|
|
+ // this.getaddress_transports(item.shopId)
|
|
|
+ this.setData({
|
|
|
+ shop_id: item.shopId,
|
|
|
+ shopName:item.shopName
|
|
|
+ })
|
|
|
+ this.getClassInfo(item.shopId);
|
|
|
+ resolve()
|
|
|
+ break; // 直接终止整个循环(输出1,2)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
- };
|
|
|
- http.request(params);
|
|
|
+ };
|
|
|
+ http.request(params);
|
|
|
+ })
|
|
|
},
|
|
|
/**
|
|
|
* 获取最大配送范围
|
|
|
@@ -708,7 +652,7 @@ Page({
|
|
|
},
|
|
|
onClose: function () {
|
|
|
this.setData({
|
|
|
- addCarshow: false
|
|
|
+ showShopList: false
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
@@ -814,7 +758,7 @@ Page({
|
|
|
},
|
|
|
|
|
|
onShow: function () {
|
|
|
-
|
|
|
+ this.getDialog()
|
|
|
// this.get_test()
|
|
|
this.setData({
|
|
|
select_address: wx.getStorageSync('ADDRESS')
|
|
|
@@ -843,20 +787,16 @@ 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() {
|
|
|
+ getAllData(type) {
|
|
|
+ console.log('=========type',type);
|
|
|
this.setData({
|
|
|
current:1,
|
|
|
shop_id: wx.getStorageSync("shopInfo").shopId,
|
|
|
@@ -864,18 +804,19 @@ 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)
|
|
|
+ if(type == 'refresh'){//切换店铺
|
|
|
+ this.getHotSalesProds()
|
|
|
+ }else{
|
|
|
+ this.get_neighborShop().then(res=>{
|
|
|
+ this.getHotSalesProds()
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//加载轮播图
|
|
|
@@ -957,7 +898,7 @@ Page({
|
|
|
this.setData({
|
|
|
hotSalesList
|
|
|
})
|
|
|
- if (res.records.length < 1) {
|
|
|
+ if (hotSalesList.length>=res.total) {
|
|
|
this.setData({
|
|
|
isAll: true
|
|
|
})
|