Files
sphc/pages/chuxiao/integral.js
2024-05-06 15:34:15 +08:00

126 lines
2.7 KiB
JavaScript

// pages/integral/integral.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
bgImg: app.globalData.bgImg,
statusBarHeight: app.globalData.statusBarHeight,
goods: [],
topImg: '', //头部图片
page: 1,
num: 10,
title:'促销专区'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.goodsList()
this.topImg()
},
//头部图片
topImg(options) {
console.log(options)
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/banner/getBanner',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
type: 12
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
let topImg = res.data.value;
this.setData({
topImg: topImg
})
} else {
wx.showModal({
title: '获取数据失败!',
content: res.data.message,
showCancel: false,
})
}
}
})
},
//商品列表
goodsList(options) {
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/goods/gethotGoods',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
type: 3,
userId: app.globalData.userId,
page: this.data.page,
num: this.data.num,
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
if (res.data.value.records.length > 0) {
let goods = this.data.goods;
for (let i = 0; i < res.data.value.records.length; i++) {
goods.push(res.data.value.records[i])
}
this.setData({
page: this.data.page + 1,
goods: goods
})
} else {
if (this.data.page != 1) {
wx.showToast({
title: '暂无更多~',
icon: 'none'
})
}
}
} else {
wx.showModal({
title: '获取数据失败!',
content: res.data.message,
showCancel: false,
})
}
}
})
},
//返回
back() {
wx.navigateBack()
},
//商品详情
goodsDetails(e) {
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/chuxiao/cx_details/goodsDetails?goodsId=' + id,
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.goodsList()
},
})