123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- // pages/detail/detail.js
- const app = getApp()
- const { axios, token } = app.globalData;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 数据模拟
- shopdetail: {}
- },
- // 点击图标事件
- onClickIcon (e) {
- let { type } = e.currentTarget.dataset;
- if (type == 'share') {
- wx.lxd.Share({
- show: true,
- })
- }
- },
- // 点击按钮事件
- onClickButton (e) {
- let { type } = e.currentTarget.dataset;
- // 点击立即购买
- if (type == "buy") {
- if (!token()) {
- wx.navigateTo({
- url: '/pages/sgin/sgin',
- })
- return false
- }
- let { id, shopdetail } = this.data;
- wx.navigateTo({
- url: `/pages/pay/pay?data=${JSON.stringify({ id, shopdetail })}`,
- })
- return false;
- }
- },
- // 请求数据
- ShopRequest () {
- let { id, shopdetail } = this.data, that = this;
- axios({
- url: `/commodity/wx_commodity_detail/${id}/`,
- method: "get",
- success (res) {
- let { amount: price, detail_images: detaillist, introduce: desc, main_image: img, name } = res.data.data;
- shopdetail = {
- name, price, detaillist, desc, img
- };
- that.setData({
- shopdetail
- })
- wx.stopPullDownRefresh();
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.lxd.Ctr({
- // nav
- title: "商品详情", //标题
- back: true,//返回按钮,tabber必须false(除非会改)
- })
- let { data } = options;
- if (!!data) {
- data = JSON.parse(data);
- this.setData({
- ...data
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.ShopRequest();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.ShopRequest();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: this.data.shopdetail.name,
- path: `/pages/detail/detail?data=${JSON.stringify({ id: this.data.id })}`
- }
- },
- onShareTimeline: function (res) {
- return {
- title: this.data.shopdetail.name,
- query: `data=${JSON.stringify({ id: this.data.id })}`
- }
- }
- })
|