Files
xuan_wechat/pages/mall/index.js
2023-08-25 14:04:31 +08:00

195 lines
4.8 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
scrollLeft : '', // 商品分类
bannerArr : [], // 轮播信息
categorieArr : [], // 分类信息
goodsArr : [], // 商品信息
articlesArr : [], // 公告列表
page : {}, // 分页信息
lodingStats : false,// 加载状态
buy_sku_id : false,// 身份包产品
can_buy : false,// 是否可购买
certification : false,// 是否已认证
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let sceneCode = options.scene || null
if(sceneCode != null ){
let inviteCode = decodeURIComponent(sceneCode)
let invite = inviteCode.match(new RegExp("(^|&)" + 'invite' + "=([^&]*)(&|$)", "i"));
getApp().globalData.invite = invite[2] || null
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 获取banner信息
this.bannerInfo();
// 获取商品分类
this.categorieInfo();
// 获取商品列表
this.goodsInfo();
// 获取公告列表
this.articlesInfo();
// 获取身份包产品
this.getidpackage()
},
/**
* 身份包
*/
getidpackage(){
wx.$api.mall.idpackage().then(res => {
let { buy_sku_id, can_buy, certification } = res.data
this.setData({
buy_sku_id,
can_buy,
certification
})
})
},
/**
* banner信息
*/
bannerInfo() {
wx.$api.mall.Banner().then(res => {
this.setData({
bannerArr: res.data
})
})
},
/**
* 商品分类信息
*/
categorieInfo() {
wx.$api.mall.Categorie().then(res => {
this.setData({
categorieArr: res.data
})
})
},
/**
* 商品列表信息
*/
goodsInfo(page) {
wx.$api.mall.Goods({
page : page || 1
}).then(res => {
let listArr = this.data.goodsArr,
newData = []
if(page == 1 || page == undefined) listArr = []
newData = listArr.concat(res.data.data)
this.setData({
goodsArr : newData,
page : res.data.page,
lodingStats : false
})
wx.stopPullDownRefresh()
})
},
/**
* 获取公告列表
*/
articlesInfo() {
wx.$api.mall.articles().then(res => {
this.setData({
articlesArr: res.data.data
})
})
},
/**
* 分类选择
*/
tabsTap(e) {
let newOffsetLeft = e.currentTarget.offsetLeft,
newScrollLeft = ''
if(newOffsetLeft < 270) {
newScrollLeft = 0
} else {
newScrollLeft = newOffsetLeft - this.data.scrollViewWidth / 2 + 40
}
this.setData({
scrollLeft: newScrollLeft,
categoryId: e.currentTarget.dataset.id
})
},
/**
* 购买产品包
*/
onCapsule(){
if(wx.getStorageSync("token") != ''){
if(!this.data.certification){
wx.showModal({
title : '提示',
content : '您还未完成账号实名认证,暂不可购买',
cancelText : '稍后',
cancelColor : '#333',
confirmText : '去认证',
confirmColor : '#da2b54',
success : res => {
if(res.confirm){
wx.navigateTo({
url: '/pages/idcard/idcard',
})
}
}
})
return
}
wx.navigateTo({
url: '/pages/mall/confirm/confirm?qty=1&skuId=' + this.data.buy_sku_id
})
return
}
wx.navigateTo({
url: "/pages/login/index"
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
// 获取商品列表
this.goodsInfo();
},
/**
* 上拉加载
*/
onReachBottom(){
this.setData({
lodingStats: true
})
let pageNumber = this.data.page.current
if(this.data.page.has_more){
pageNumber++
// 获取商品列表
this.goodsInfo(pageNumber);
}
}
})