Files
sykl-new/pages/mall/buy/index.js
2023-12-15 17:53:08 +08:00

105 lines
2.5 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
avatar : '', //用户头像
nickName : '', //用户昵称
identity : '', //用户身份
goodId : '', //商品id
goodType : '', //商品类型
surplus : '', //我的水滴
mallData : '', //商品详情
mallContent : '', //商品介绍
userLogin : '', //登录状态
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options.type)
this.setData({
goodId : options.id,
goodType: options.type
})
// 获取商品详情
this.goodInfo(options.id);
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
if(wx.getStorageSync("token")){
this.setData({
userLogin: true
})
// 获取用户信息
this.userInfo();
}
},
/**
* 用户信息
*/
userInfo() {
wx.$api.user.home().then(res => {
this.setData({
avatar : res.data.avatar,
nickName : res.data.nickname,
identity : res.data.identity,
surplus : res.data.account.score.surplus
})
}).catch(err => {})
},
/**
* 商品详情
*/
goodInfo(id) {
wx.$api.mall.goodsShow(id).then(res => {
this.setData({
mallData : res.data,
mallContent : res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'),
})
}).catch(err => {})
},
/**
* 放大轮播相册图片
*/
opneBanner(e){
let imgs = [],
index = e.currentTarget.dataset.index
for (let img of e.currentTarget.dataset.imgs){
imgs.push(img)
}
wx.previewImage({
urls : imgs,
current : imgs[index]
})
},
// 购买
buyTap(e) {
if(wx.getStorageSync("token")){
wx.navigateTo({
url: '../submit/index?skuid=' + this.data.mallData.skus[0].sku_id + '&goodsid=' + this.data.mallData.goods_id + '&qty=' + 1 + '&goodtype=' + this.data.goodType
})
}else {
// 去登录
wx.navigateTo({
url: "/pages/login/index"
})
}
}
})