deguodaigou/pages/product/product.js

123 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-12-23 10:04:09 +08:00
// pages/product/product.js'
import { request } from "../../utils/bin"
2019-12-24 14:47:52 +08:00
var WxParse = require('../../utils/wxParse/wxParse');
2019-12-23 10:04:09 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
array: ['20粒', '30粒', '50粒', '100粒'],
2019-12-24 14:47:52 +08:00
userid: 0,
specs: [{ 'item': '默认规格' }],
article:""
2019-12-23 10:04:09 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
2019-12-24 14:47:52 +08:00
onLoad: function (options) {
2019-12-23 10:04:09 +08:00
console.log(options)
request({
url: "Goods/goodsInfo",
data: {
id: options.shopid
}
}).then((res) => {
// console.log(res)
this.setData({
info: res.data.result,
2019-12-24 14:47:52 +08:00
shopid: options.shopid,
2019-12-23 10:04:09 +08:00
})
2019-12-24 14:47:52 +08:00
var that = this;
WxParse.wxParse('article', 'html', that.data.info.goods.goods_content, that, 5);
2019-12-23 10:04:09 +08:00
// console.log(this.data.type, 150)
})
request({
2019-12-24 14:47:52 +08:00
url: "User/validateOpenid"
}).then((res) => {
2019-12-23 10:04:09 +08:00
console.log(res)
this.setData({
2019-12-24 14:47:52 +08:00
userid: res.data.data.user_id
2019-12-23 10:04:09 +08:00
})
})
},
// goshop() {
// },
bindPickerChange(e) {
console.log(e.detail.value)
2019-12-24 14:53:06 +08:00
if(this.data.userid == 0){
wx.showToast({
title: '请先登陆',
icon: 'none',
duration: 2000
})
return ;
}
2019-12-23 10:04:09 +08:00
request({
url: "Cart/addCart",
data: {
goods_id: this.data.shopid,
goods_num: 1,
2019-12-24 14:47:52 +08:00
goods_spec: this.data.info.goods.goods_spec_list ? this.data.info.goods.goods_spec_list[0][e.detail.value].item_id : '',
user_id: this.data.userid
2019-12-23 10:04:09 +08:00
},
2019-12-24 14:47:52 +08:00
name: "session_id"
}).then((res) => {
2019-12-23 10:04:09 +08:00
console.log(res)
wx.switchTab({
url: '/pages/shopping/shopping'
})
2019-12-24 14:47:52 +08:00
})
2019-12-23 10:04:09 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
2019-12-24 14:47:52 +08:00
onReady: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 生命周期函数--监听页面显示
*/
2019-12-24 14:47:52 +08:00
onShow: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 生命周期函数--监听页面隐藏
*/
2019-12-24 14:47:52 +08:00
onHide: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 生命周期函数--监听页面卸载
*/
2019-12-24 14:47:52 +08:00
onUnload: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
2019-12-24 14:47:52 +08:00
onPullDownRefresh: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 页面上拉触底事件的处理函数
*/
2019-12-24 14:47:52 +08:00
onReachBottom: function () {
2019-12-23 10:04:09 +08:00
},
/**
* 用户点击右上角分享
*/
2019-12-24 14:47:52 +08:00
onShareAppMessage: function () {
2019-12-23 10:04:09 +08:00
}
2019-12-14 00:31:41 +08:00
})