goPromotion.js 2.5 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    s4_id: '',
    Promotion: [],
    noCar: ''
  },
  onLoad: function (options) {
    let that = this
    let token = wx.getStorageSync("token")
    that.setData({
      s4_id: options.id
    })
    if (token) {
      that.getPromotion()
    } else {
      that.popConfirm()
    }
  },
  ToActivityDetails(e) {
    let id = e.currentTarget.dataset.id
    let type = e.currentTarget.dataset.types
    if (type == 1) {
      wx.navigateTo({
        url: '/pages/activityDetails/activityDetails?id=' + id + '&type=' + type + '&tap=0'
      })
    } else if (type == 2) {
      wx.navigateTo({
        url: '/pages/details/details?id=' + id + '&type=' + type
      })
    } else if (type == 3) {
      wx.navigateTo({
        url: '/pages/detail/detail?id=' + id
      })
    }

  },
  onReady: function () {},
  onShow: function () {},
  popConfirm() {
    wx.showModal({
      title: '提示',
      content: '您尚未登录,请登录后操作',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/authorization/authorization'
          })
        } else {
          wx.switchTab({
            url: '/pages/home/home'
          })
        }
      }
    })

  },
  async getPromotion() { // 获取促销活动
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/active/index4s',
        data: {
          s4_id: that.data.s4_id
        }
      })
      if (data.length != 0) {
        that.setData({
          noCar: 0,
          Promotion: data
        })
      } else {
        that.setData({
          noCar: 1,
          Promotion: data
        })
      }
      console.log(data);
    } catch (err) {
      console.log(err);
      a.popTest(err.msg)
      that.setData({
        noCar: 1,
      })
    }
  },
  onShareAppMessage(options) {
    var that = this;
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: "车唛分享", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/goPromotion/goPromotion', // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
    };
    // 返回shareObj
    return shareObj;

  },

})