| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016 |
- //index.js
- //获取应用实例
- var http = require("../../utils/http.js");
- var util = require('../../utils/util.js');
- var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
- var qqmapsdk;
- const updateManager = wx.getUpdateManager()
- import eventBus from '../../utils/eventBus';
- Page({
- isHand:false,
- data: {
- isScroll:false,
- active:1,
- imgUrl:'',
- swiperCurrent:0,
- swiperList:[],
- shopName:'附近暂无可配送门店',
- indicatorDots: true,
- indicatorColor: '#d1e5fb',
- indicatorActiveColor: '#1b7dec',
- autoplay: true,
- interval: 2000,
- duration: 1000,
- indexImgs: [],
- seq: 0,
- news: [],
- hotSalesList: [],
- sts: 0,
- current: 1,
- sort: 1,
- isAll: false,
- snapUpList: [], //秒杀列表
- aBulkList: [], //团购列表
- pageTopHeight: wx.getWindowInfo().statusBarHeight + 30 + 7,
- gapTop: 1,
- titleOpacity: 1,
- days: 0,
- hours: 0,
- minutes: 0,
- seconds: 0,
- hotList: [],
- recommendedList: [],
- totalNum: 1,
- addCarshow: false,
- shopDetail: {},
- select_address: '',
- categoryList: [],
- categoryList1: [],
- currentIndex: 0,
- topCurrentIndex: 0,
- currentTop: 0,
- shop_id: 0,
- get_distance: '',
- banner_img: [
- {
- img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/JrXik2T4vhwp7c25b370159a7498499e7b4b76cfb288.png/1.png',
- name:''
- },
- {
- img:'https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/OFG6necEvIOpcd39097fe6f106894503a4d77c14d7b8.png/1.png',
- name:''
- },
- ]
- },
- onLoad: function () {
- // 实例化API核心类
- qqmapsdk = new QQMapWX({
- key: 'D3MBZ-LQK6U-IONVC-GJDPK-C43GF-UYFOC'
- // key: 'UNBBZ-OKDCB-FSTU4-N5EGG-CMJ67-CKB6H'
- });
- // 绑定页面滚动事件
- wx.pageScrollTo({
- scrollTop: 0, // 初始滚动位置,可按需调整
- duration: 0
- });
- this.get_setting()
- 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();
- })
- }else{
- setTimeout(() => {
- this.getAllData();
- }, 1000)
- }
- },
- handleTab(e){
- this.setData({
- active:Number(e.currentTarget.dataset.active),
- current:1||Number(e.currentTarget.dataset.active),
- hotSalesList:[],
- isHand:true
- })
- setTimeout(() => {
- this.getHotSalesProds()
- }, 100);
- },
- // 顶部轮播滚动
- changeIndex(e){
- this.setData({
- swiperCurrent:e.detail.current
- })
- },
- get_setting: function () {
- let that = this
- wx.getSetting({
- success: (res) => {
- let authSetting = res.authSetting
- if (authSetting['scope.userLocation'] || authSetting['scope.userFuzzyLocation']) {
- that.getCurrentLocation()
- } else if (authSetting['scope.userLocation'] || authSetting['scope.userFuzzyLocation'] === false) {
- wx.removeStorageSync('ADDRESS')
- wx.showModal({
- title: '您未开启地理位置授权',
- content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
- success: (res) => {
- if (res.confirm) {
- wx.openSetting()
- }
- }
- })
- } else {
- wx.authorize({
- scope: 'scope.userLocation',
- scope: 'scope.userFuzzyLocation',
- success: () => {
- that.getCurrentLocation()
- },
- fail: () => {
- wx.removeStorageSync('ADDRESS')
- wx.showModal({
- title: '您未开启地理位置授权',
- content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
- success: (res) => {
- if (res.confirm) {
- wx.openSetting()
- }
- }
- })
- }
- })
- }
- }
- })
- },
- getCurrentLocation() {
- let that = this
- wx.getFuzzyLocation({
- type: 'wgs84',
- success: function (res) {
- const latitude = res.latitude
- const longitude = res.longitude
- 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');
- }
- });
- },
- fail: function (err) {
- wx.removeStorageSync('ADDRESS')
- console.log(err);
- if (err.errMsg === 'getFuzzyLocation:fail system permission denied') {
- wx.showModal({
- title: '系统定位未开启',
- content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
- success: (res) => {}
- })
- } else if (err.errMsg === 'getFuzzyLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' ||
- err.errMsg === 'getFuzzyLocation:fail system permission denied' ||
- err.errMsg === 'getFuzzyLocation:fail:system permission denied' || err.errMsg === 'getFuzzyLocation:fail auth deny') {
- wx.showModal({
- title: '您未开启地理位置授权',
- content: '请在系统设置中打开位置授权,以便我们为您提供更好的服务',
- success: (res) => {
- if (res.confirm) {
- wx.openSetting()
- }
- }
- })
- }
- }
- })
- },
- // 页面滚动到指定位置指定元素固定在顶部
- onPageScroll: function (e) { //监听页面滚动
- if (e.scrollTop < 10) {
- this.setData({
- titleOpacity: 1
- })
- }
- if (e.scrollTop > 10) {
- this.setData({
- titleOpacity: 0.8
- })
- }
- if (e.scrollTop > 20) {
- this.setData({
- titleOpacity: 0.6
- })
- }
- if (e.scrollTop > 30) {
- this.setData({
- titleOpacity: 0.2
- })
- }
- if (e.scrollTop >= 40) {
- this.setData({
- titleOpacity: 0,
- })
- }
- if (e.scrollTop >= 140) {
- this.setData({
- isScroll:true
- })
- }else{
- this.setData({
- isScroll:false
- })
- }
- this.handlePageScroll(e.scrollTop);
- this.setData({
- scrollTop: e.scrollTop
- })
- },
- handlePageScroll: function (scrollTop) {
- const query = wx.createSelectorQuery().in(this);
- query.select('#my-element').boundingClientRect();
- query.exec((res) => {
- if (res && res[0]) {
- const elementTop = res[0].top;
- const relativeTop = elementTop - scrollTop;
- // 也可以将这个距离数据存储到data中,方便在页面中进行展示或其他操作
- if (relativeTop < 0.5) {
- this.setData({
- gapTop: relativeTop
- });
- } else {
- this.setData({
- gapTop: 1
- });
- }
- }
- });
- },
- /**
- * 广告位
- */
- getAdv: function () {
- var params = {
- url: "/advert/search",
- method: "GET",
- data: {
- current: 1,
- size:99,
- status:1
- },
- callBack: (res) => {
- this.setData({
- swiperList: res.records
- })
- }
- };
- http.request(params);
- },
- /**
- * 推荐词,type:1关键词,2热门搜索词,3推荐搜索词
- */
- getRecommended: function () {
- var params = {
- url: "/searchTerm/hotSearchWord",
- method: "GET",
- data: {
- current:1,
- size:9999
- },
- callBack: (res) => {
- let reslut = res.records.filter(item => item.status !== 2) //过滤下线词
- let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未生效词
- this.setData({
- hotList: timeReslut
- })
- console.log(2222,this.data.hotList);
- }
- };
- http.request(params);
- },
- getRecommendeds: function () {
- var params = {
- url: "/searchTerm/recommendSearchWord",
- method: "GET",
- data: {
- current:1,
- size:9999
- },
- callBack: (res) => {
- let reslut = res.records.filter(item => item.status !== 2) //过滤已线下推荐词
- let timeReslut = reslut.filter(e => util.dateToTimestamp(e.effectiveTime) < new Date().getTime()) //过滤未到生效时间推荐词
- this.setData({
- recommendedList: timeReslut
- })
- }
- };
- http.request(params);
- },
- /**
- * 推荐词搜索
- */
- topSwiperChange: function (e) {
- this.setData({
- topCurrentIndex: e.detail.current // 获取当前滚动到的swiper-item的索引并更新到data中
- })
- },
- topHotSearch: function () {
- const topname = this.data.hotList[this.data.topCurrentIndex].name
- wx.navigateTo({
- // url: '/pages/search-prod-show/search-prod-show?prodName=' + topname,
- url: `/pages/search-prod-show/search-prod-show?prodName=${topname}&shopId=${this.data.shop_id}`,
- })
- },
- swiperChange: function (e) {
- this.setData({
- currentIndex: e.detail.current
- });
- },
- inputSearch: function () {
- const currentName = this.data.hotList[this.data.currentIndex].name;
- wx.navigateTo({
- // url: '/pages/search-prod-show/search-prod-show?prodName=' + currentName,
- url: `/pages/search-prod-show/search-prod-show?prodName=${currentName}&shopId=${this.data.shop_id}`,
- })
- },
- recommendedSearch: function (e) {
- let name = e.currentTarget.dataset.name
- wx.navigateTo({
- url: `/pages/search-prod-show/search-prod-show?prodName=${name}&shopId=${this.data.shop_id}`,
- })
- },
- /**
- * 对象映射,每多一个swiper-item需+10,用以金刚区的分类跳转到指定分类菜单,当菜单类大于三十个时需再次手动添加
- * @param {*} e
- */
- menuSwiper: function (e) {
- const topMap = {
- 0: 0,
- 1: 10,
- 2: 20
- };
- const currentValue = topMap[e.detail.current];
- if (currentValue !== undefined) {
- this.setData({
- currentTop: currentValue
- });
- }
- },
- /**
- * 当分类大于10时进行切割
- */
- splitList: function (arr) {
- let result = [];
- let groupCount = Math.ceil(arr.length / 5);
- for (let i = 0; i < groupCount; i++) {
- let startIndex = i * 5;
- let endIndex = Math.min((i + 1) * 5, arr.length);
- result.push(arr.slice(startIndex, endIndex));
- }
- return result;
- },
- /**
- * 获取用户信息
- */
- getUserInfo: function() {
- return new Promise((resolve,reject)=>{
- var that = this;
- var param = {
- url: '/p/user/userInfo',
- method: 'GET',
- data: {},
- callBack: (res) => {
- res.channelId&&wx.setStorageSync('channelId',res.channelId)
- resolve()
- }
- }
- http.request(param)
- })
- },
- /**
- * 宫格分类
- */
- getClassInfo: function (shopId) {
- let _this = this
- //加载分类列表
- var params = {
- url: "/category/listCategoryForUser",
- method: "GET",
- data: {
- shopId: wx.getStorageSync('shopInfo').shopId,
- channelId:wx.getStorageSync('channelId')||3
- },
- callBack: function (res) {
- console.log(res);
- let categoryName = ''
- res.forEach(e => {
- categoryName = e.categoryName.split('>')
- e.categoryName = categoryName[0]
- })
- let newRes = _this.splitList(res)
- let categoryList = newRes.splice(0,2)
- if(categoryList.length == 2){
- categoryList = categoryList[0].concat(categoryList[1])
- }else if(categoryList.length == 1){
- categoryList = categoryList[0]
- }
- newRes = newRes.flat(Infinity)
- _this.setData({
- categoryList: categoryList,
- categoryList1: newRes,
- });
- }
- };
- http.request(params);
- },
- /**
- * 点击宫格
- */
- selectMenu: function (e) {
- console.log(e);
- let categoryId = e.currentTarget.dataset.itemid
- let hassecond = e.currentTarget.dataset.hassecond
- let index = e.currentTarget.dataset.index + this.data.currentTop
- let pic = e.currentTarget.dataset.pic
- let categories = e.currentTarget.dataset.categories
- wx.setStorageSync('categoryId', categoryId)
- wx.navigateTo({
- url: '/pages/category1/category'
- })
- // wx.switchTab({
- // url: '/pages/category/category'
- // })
- },
- // 领红包
- toRedPackage: function () {
- wx.navigateTo({
- url: '/pages/ledRedPackage/ledRedPackage',
- })
- },
- /**
- * banner图跳转
- * @param {判断条件} e
- */
- goToLevelPage: function (e) {
- let name = e.currentTarget.dataset.name
- if (name == 'new') {
- wx.navigateTo({
- url: '/pages/prod-classify/prod-classify?sts=' + 1
- })
- } else if (name == 'favorable') {
- wx.navigateTo({
- url: '/pages/specialDiscount/specialDiscount'
- })
- } else if (name == 'groupBuy') {
- wx.navigateTo({
- url: '/pages/aBulkList/aBulkList',
- })
- } else {
- wx.navigateTo({
- url: '/pages/snapUpList/snapUpList',
- })
- }
- },
- /**
- * 跳转到商品详情页
- */
- toProdPage: function (e) {
- var prodid = e.currentTarget.dataset.prodid;
- var shopid = e.currentTarget.dataset.shopid;
- if (prodid) {
- wx.navigateTo({
- url: `/pages/prod/prod?prodid=${prodid}&shopid=${this.data.shop_id}`,
- })
- }
- },
- toCouponCenter: function () {
- wx.navigateTo({
- url: '/pages/couponCenter/couponCenter',
- })
- },
- newToProdPage: function (e) {
- let prodId = e.currentTarget.dataset.prod
- if (prodId) {
- wx.navigateTo({
- url: '/pages/prod/prod?prodid=' + prodId,
- })
- }
- },
- /**
- * 跳转秒杀列表页
- */
- toSpecialDiscount: function () {
- wx.navigateTo({
- url: '/pages/specialDiscount/specialDiscount',
- })
- },
- /**
- * 跳转到定位页面
- */
- toLocationPage: function () {
- wx.navigateTo({
- url: '/pages/locationAdd/locationAdd',
- })
- },
- /**
- * 秒杀
- */
- 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)
- this.setData({
- shop_id: res.shopId,
- shopName:res.shopName
- })
- setTimeout(() => {
- this.getClassInfo(res.shopId);
- }, 300)
- }
- }
- };
- http.request(params);
- },
- /**
- * 获取最大配送范围
- */
- getaddress_transports: function (shopId) {
- let _this = this
- var params = {
- url: "/p/address/transport2",
- method: "GET",
- data: {
- shopId: shopId,
- latitude: wx.getStorageSync('LATITUDE'),
- longitude: wx.getStorageSync('LONGITUDE'),
- },
- callBack: function (res) {
- wx.setStorageSync('DISTANCE', res.distance)
- _this.setData({
- get_distance: res.distance
- })
- },
- errCallBack(res) {
- console.log(res);
- wx.setStorageSync('DISTANCE', 0)
- }
- };
- http.request(params);
- },
- onClose: function () {
- this.setData({
- addCarshow: false
- })
- },
- /**
- * 步进器
- */
- minusButton: function (e) {
- let totalNum = this.data.totalNum
- if (totalNum > 0) {
- this.setData({
- totalNum: totalNum - 1
- })
- }
- },
- addButton: function (e) {
- let totalNum = this.data.totalNum
- this.setData({
- totalNum: totalNum + 1
- })
- },
- /**
- * 跳转秒杀列表页
- */
- toSnapUpPage: function () {
- wx.navigateTo({
- url: '/pages/snapUpList/snapUpList',
- })
- },
- toSnapUpListPage: function (e) {
- var seckillId = e.currentTarget.dataset.seckillid;
- wx.navigateTo({
- url: "/pages/snapUpDetail/snapUpDetail?seckillid=" + seckillId,
- })
- },
- /**
- * 团购
- */
- getAbulk: function () {
- wx.showLoading()
- var param = {
- url: "/groupProd/indexList",
- method: "GET",
- data: {},
- callBack: (res) => {
- wx.hideLoading();
- this.setData({
- aBulkList: res
- });
- }
- };
- http.request(param);
- },
- /**
- * 跳转团购列表页
- */
- toAbulkPage: function () {
- wx.navigateTo({
- url: '/pages/aBulkList/aBulkList',
- })
- },
- toAbulkListPage: function (e) {
- var prodId = e.currentTarget.dataset.prodid;
- var groupActivityId = e.currentTarget.dataset.groupactivityid;
- wx.navigateTo({
- url: '/pages/prod/prod?prodid=' + prodId + "&groupActivityId=" + groupActivityId
- })
- },
- // 跳转搜索页
- toSearchPage: function () {
- wx.navigateTo({
- // url: '/pages/search-page/search-page',
- url: `/pages/search-page/search-page?shopId=${this.data.shop_id}`,
- })
- },
- //跳转商品活动页面
- toClassifyPage: function (e) {
- var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
- var id = e.currentTarget.dataset.id;
- var title = e.currentTarget.dataset.title;
- if (id) {
- url += "&tagid=" + id + "&title=" + title;
- }
- wx.navigateTo({
- url: url
- })
- },
- toSecKillPage: function () {
- wx.navigateTo({
- url: '/pages/snapUpList/snapUpList',
- })
- },
- //跳转公告列表页面
- onNewsPage: function () {
- wx.navigateTo({
- url: '/pages/recent-news/recent-news',
- })
- },
- onShow: function () {
-
- // this.get_test()
- this.setData({
- select_address: wx.getStorageSync('ADDRESS')
- })
- // this.getCurrentLocation()
- updateManager.onCheckForUpdate(function (res) {
- updateManager.onUpdateReady(function () {
- wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
- })
- http.getCartCount(); //重新计算购物车总数量
- },
- /**
- * 接口测试用
- */
- /**
- * 选择定位后更新列表
- */
- 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.getHotSalesProds()
- }, 1000)
- },
- getAllData() {
- this.setData({
- current:1,
- shop_id: wx.getStorageSync("shopInfo").shopId,
- shopName:wx.getStorageSync("shopInfo").shopName
- })
- http.getCartCount(); //重新计算购物车总数量
- this.getIndexImgs();
- this.getClassInfo(this.data.shopId);
- // this.get_neighborShop()
- // this.getNoticeList();
- this.getAbulk();
- this.getRecommended()
- this.getRecommendeds()
- this.getAdv()
- setTimeout(() => {
- this.getNewList();
- this.getSnapUpList();
- this.getHotSalesProds();
- }, 500)
- },
- //加载轮播图
- getIndexImgs() {
- console.log('getIndexImgs');
- //加载轮播图
- var params = {
- url: "/indexImgs/0",
- method: "GET",
- data: {},
- callBack: (res) => {
- this.setData({
- indexImgs: res,
- seq: res
- });
- wx.hideLoading();
- }
- };
- http.request(params);
- },
- // getNoticeList() {
- // // 加载公告
- // var params = {
- // url: "/shop/notice/topNoticeList/0",
- // method: "GET",
- // data: {},
- // callBack: (res) => {
- // this.setData({
- // news: res,
- // });
- // wx.hideLoading();
- // }
- // };
- // http.request(params);
- // },
- /**
- * 加载热销商品列表
- */
- getHotSalesProds() {
- if(!this.data.shop_id||this.data.shop_id == 0){
- return console.log('店铺不存在');
- }
- var param = {
- url: "/search/searchProdPage",
- method: "GET",
- data: {
- current: this.data.current,
- size: 10,
- sort: 3,
- orderBy: 1,
- lat: wx.getStorageSync('LATITUDE'),
- lon: wx.getStorageSync('LONGITUDE'),
- distance: 9999999||wx.getStorageSync('DISTANCE') || 0,
- shopId: this.data.shop_id,
- channelId:wx.getStorageSync('channelId')||3
- },
- callBack: (res) => {
- var hotSalesList = []
- let img = ''
- res.records.map(e => {
- if(e.pic){
- img = e.pic.split(',')
- e.pic = img[0]
- }
- })
- if (this.data.current == 1) {
- setTimeout(() => {
- this.setData({
- hotSalesList: res.records,
- pages: res.pages,
- current: res.current
- });
- }, 500)
- } else {
- hotSalesList = this.data.hotSalesList
- hotSalesList.push(...res.records)
- this.setData({
- hotSalesList
- })
- if (res.records.length < 1) {
- this.setData({
- isAll: true
- })
- }
- }
- this.setData({
- isHand:false
- })
- }
- };
- http.request(param);
- },
- // 触底加载下一页
- getNextPage() {
- console.log('getNextPage',this.data.current);
- if (this.data.pages > this.data.current) {
- this.setData({
- current: this.data.current + 1
- })
- !this.data.isHand&&this.getHotSalesProds()
- } else {
- this.setData({
- isAll: true
- })
- }
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.getNextPage()
- },
- onPullDownRefresh: function () {
- // wx.showNavigationBarLoading() //在标题栏中显示加载
- //模拟加载
- var ths = this;
- this.setData({ //下拉刷新
- current: 1
- })
- setTimeout(function () {
- ths.getAllData();
- // wx.hideNavigationBarLoading() //完成停止加载
- wx.stopPullDownRefresh() //停止下拉刷新
- }, 100);
- },
- onShareAppMessage: function (e) {
- return {
- path: "pages/index/index"
- }
- }
- })
|