锶源昆仑商城

This commit is contained in:
2023-07-22 19:01:37 +08:00
commit 4ba3377084
223 changed files with 10557 additions and 0 deletions

103
pages/mall/buy/index.js Normal file
View File

@@ -0,0 +1,103 @@
/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
avatar : '', //用户头像
nickName : '', //用户昵称
identity : '', //用户身份
goodId : '', //商品id
surplus : '', //我的水滴
mallData : '', //商品详情
mallContent : '', //商品介绍
userLogin : '', //登录状态
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
goodId: options.id
})
// 获取商品详情
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 => {
console.log(res.data)
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,
})
}else {
// 去登录
wx.navigateTo({
url: "/pages/login/index"
})
}
}
})