259 lines
5.5 KiB
JavaScript
259 lines
5.5 KiB
JavaScript
![]() |
// pages/integral/integral.js
|
||
|
const app = getApp()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
bgImg: app.globalData.bgImg,
|
||
|
statusBarHeight: app.globalData.statusBarHeight,
|
||
|
goods: [],
|
||
|
title: '三品慧采',
|
||
|
topImg: '', //头部图片
|
||
|
page: 1,
|
||
|
num: 10,
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
if (options.title) {
|
||
|
this.setData({
|
||
|
title: options.title
|
||
|
})
|
||
|
if (options.title == '积分专区') {
|
||
|
this.topImg({
|
||
|
type: 3
|
||
|
})
|
||
|
this.goodsList()
|
||
|
}
|
||
|
if (options.title == '热卖专区') {
|
||
|
this.topImg({
|
||
|
type: 4
|
||
|
})
|
||
|
this.goodsList2({
|
||
|
type: 1
|
||
|
})
|
||
|
}
|
||
|
if (options.title == '节令甄选') {
|
||
|
this.topImg({
|
||
|
type: 5
|
||
|
})
|
||
|
this.goodsList2({
|
||
|
type: 2
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
},
|
||
|
//头部图片 积分3 热卖4 节令5
|
||
|
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: options.type
|
||
|
},
|
||
|
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: function (e) {
|
||
|
wx.showLoading({
|
||
|
title: '加载中',
|
||
|
})
|
||
|
wx.request({
|
||
|
url: app.globalData.ip + '/wisdommining/api/goods/getIntegralGoods',
|
||
|
method: 'GET',
|
||
|
header: {
|
||
|
"content-type": "application/x-www-form-urlencoded",
|
||
|
},
|
||
|
data: {
|
||
|
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,
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
//商品列表 热卖 节令
|
||
|
goodsList2(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: options.type,
|
||
|
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()
|
||
|
},
|
||
|
//积分类型选择
|
||
|
type(e) {
|
||
|
let index = e.currentTarget.dataset.index;
|
||
|
this.setData({
|
||
|
typeIndex: index
|
||
|
})
|
||
|
},
|
||
|
//商品详情
|
||
|
goodsDetails(e) {
|
||
|
let id = e.currentTarget.dataset.id;
|
||
|
if (this.data.title == '积分专区') {
|
||
|
wx.navigateTo({
|
||
|
url: '/pages/goodsDetails/goodsDetails?integral=1' + '&goodsId=' + id,
|
||
|
})
|
||
|
} else {
|
||
|
wx.navigateTo({
|
||
|
url: '/pages/goodsDetails/goodsDetails?goodsId=' + id,
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
let title = this.data.title
|
||
|
if (title == '积分专区') {
|
||
|
this.goodsList()
|
||
|
}
|
||
|
if (title == '热卖专区') {
|
||
|
this.goodsList2({
|
||
|
type: 1
|
||
|
})
|
||
|
}
|
||
|
if (title == '节令甄选') {
|
||
|
this.goodsList2({
|
||
|
type: 2
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
})
|