myPrize.js 2.9 KB
// pages/myPrize/myPrize.js
import {
  request
} from "../../request/index.js";
const a = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userMsg:'',
    s4:"",
    tablist:['待领取','已领取'],
    drawid: 0,
    active: 1,
    prizeList: [],
    s4_name: '',
    showGetMydetail: false,
    banner: '',
    myDetail: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,111);
    this.setData({
      drawid: options.drawid,
      s4_name: wx.getStorageSync('s4_name'),
      active:options.type,
      userMsg:JSON.parse(options.userMsg),
      s4:wx.getStorageSync('s4_name')
    })
  },
  onShow(){
    this.getBanner()
    this.getMyjiang()
  },
  getBanner(){
    request({
      url: 'api/chou_banner/get_banner',
      data: {}
    }).then((res) => {
      console.log(res)
      this.setData({
        banner: res.data.data[0]['image']
      })
    })
  },
  toscore(){
    wx.switchTab({
      url: '/pages/stores/index',
    })
  },
  onClick(event) {
    console.log(event)
    wx.showToast({
      title: '加载中',
      icon: 'none',
    });
    this.setData({
      drawid: this.data.drawid,
      active: event.currentTarget.dataset.idx
    })
    console.log(this.data.active)
    this.getMyjiang()
  },
  // 获取奖品列表
  getMyjiang(id) {
    request({
      url: 'api/h5/myJiang',
      data: {
        id: wx.getStorageSync('drawId'),
        way: this.data.active
      }
    }).then((res) => {
      console.log(res)
      this.setData({
        prizeList: res.data.data
      })
      console.log(this.data.prizeList)
    })
  },
  // 立即领取
  getPrize(e) {
    console.log(e)
    console.log(e.currentTarget.dataset.thisdraw)
    let thisDraw = e.currentTarget.dataset.thisdraw
    console.log(thisDraw)
    //判断是否填写过获奖信息
    request({
      url: 'api/h5/haveInfo',
      data: {
        id: wx.getStorageSync('drawId')
      }
    }).then((res) => {
      console.log(res)
      if (res.data.have_id == 0) {
        a.popText('请先填写获奖信息')
        return
      } else {
        request({
          url: 'api/h5/lingJiang',
          data: {
            log_id: thisDraw
          }
        }).then((res) => {
          if(res.code == 1) {
            a.popTest('领取成功')
          } else {
            a.popTest(res.msg)
          }
        }).catch((err) => {
          a.popTest(err.msg)
        })
      }
    })
  },
  // 查看个人信息
  getMydetail() {
    this.setData({
      showGetMydetail: true
    })
    request({
      url: 'api/h5/userInfo',
      data: {
        id: wx.getStorageSync('drawId')
      }
    }).then((res) => {
      console.log(res.data.data)
      this.setData({
        myDetail: res.data.data
      })
    })
  },
  closeMydetail() {
    console.log('123')
    this.setData({
      showGetMydetail: false
    })
  }
})