123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- // pages/luckDraw/profile.js
- import LuckDraw from '../../api/luck-draw'
- import { parseTime } from '../../utils/util'
- import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
- import WelfareMall from '../../api/welfareMall';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- page: 1,
- pageSize: 10,
- lock: false,
- noResult: false,
- noMore: false,
- isLogin: false,
- hidden1: true,
- hidden2: true,
- noCoupon: false,
- noPrize: false,
- mobileTop: 'TONY WU',
- couponNum: 0,
- productNum: 0,
- thirdPrizeNum: 0,
- goodsType: 1,
- goodsItemList: [],
- showCustomPreview: false,
- prizeImgList: [],
- config: {},
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- this.setData({
- isLogin: getMobileCache() != '',
- mobileTop:getMobileCache(),
- })
- if(this.data.isLogin){
- this.setData({
- hidden1: false,
- hidden2: true,
- noCoupon: true,
- noPrize: false,
- })
- this.getUserPrizeList();
- }
- let info = await WelfareMall.getIndexList();
- this.setData({
- prizeImgList:info.data.prizeImgList,
- config:info.data.config,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- getUserPrizeList: function() {
- LuckDraw.getUserPrizeList({
- page: this.data.page,
- pageSize: this.data.pageSize,
- mobile: getMobileCache(),
- goodsType: this.data.goodsType
- }).then(res => {
- if (res.code == 200) {
- this.uaerPrizeListView(res.data)
- }
- this.data.lock = false
- }).catch(_ => {
- console.log(_)
- this.data.lock = false
- })
- },
- uaerPrizeListView: function(data) {
- if (!Array.isArray(data.goodsItemList) || data.goodsItemList.length == 0) {
- console.log("数据为空");
- if (this.data.page == 1) {
- this.setData({
- mobileTop:getMobileCache(),
- couponNum: data.couponNum,
- productNum: data.productNum,
- thirdPrizeNum: data.thirdPrizeNum,
- noResult: true
- })
- } else {
- this.setData({
- mobileTop:getMobileCache(),
- noMore: true
- })
- }
- return
- }
- data.goodsItemList.forEach(v => {
- let createTime = v.createTime
- v.couponStartTime = v.couponBeginTimestamp
- v.couponEndTime = v.couponEndTimestamp
- v.isSn = true
- v.couponBeginTimestamp = parseTime(v.couponBeginTimestamp, "{y}.{m}.{d}")
- v.couponEndTimestamp = parseTime(v.couponEndTimestamp, "{y}.{m}.{d}")
- v.createTime = parseTime(createTime, "{y}.{m}.{d} {h}:{i}")
- })
- if (this.data.page == 1) {
- this.setData({
- couponNum: data.couponNum,
- productNum: data.productNum,
- thirdPrizeNum: data.thirdPrizeNum,
- })
- }
- this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
- this.setData({
- mobileTop:getMobileCache(),
- goodsItemList: this.data.goodsItemList
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (this.data.lock || this.data.noMore) {
- return
- }
- this.data.lock = true
- this.data.page++
- this.getUserPrizeList()
- },
- toPrize(e) {
- const url = "prize?id=" + e.currentTarget.dataset.id
- wx.redirectTo({
- url
- })
- },
- getProfile(e) {
- this.setData({
- hidden1: false,
- hidden2: true,
- page: 1,
- goodsType: 1,
- noMore: false,
- noResult: false,
- noCoupon: true,
- noPrize: false,
- goodsItemList: [],
- })
- this.getUserPrizeList()
- },
- getPrize(e) {
- this.setData({
- hidden1: true,
- hidden2: false,
- page: 1,
- goodsType: 3,
- noMore: false,
- noResult: false,
- noCoupon: false,
- noPrize: true,
- goodsItemList: [],
- })
- this.getUserPrizeList()
- },
- turnPrize: function() {
- console.log("开始查看")
- if (this.lock || !this.data.isLogin) {
- return
- }
- this.lock = true
- },
- // 授权手机号
- getPhoneNumber(e) {
- getPhoneNumberSync(e, _ => {
- this.setData({
- isLogin: true,
- mobileTop: getMobileCache(),
- hidden1: false,
- hidden2: true,
- noCoupon: true,
- noPrize: false,
- })
- this.getUserPrizeList()
- })
- },
- toRecordPrize(e) {
- const url = "recordPrize?id=" + e.currentTarget.dataset.id
- wx.redirectTo({
- url
- })
- },
- toLookHitPhoto(e) {
- console.log(e)
- let url = e.currentTarget.dataset.src;
- this.setData({
- showCustomPreview: true,
- previewImgSrc: url,
- })
- // url = 'https://ks3-cn-shanghai.ksyun.com/pb001/web/hsay/publicPath/a2623624-caf1-4877-99d0-c9355984e964.jpg';
- // // url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F19100120461512E-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642243223&t=d67f73c97f32e30932e5ee49bbce6dbd'
- // wx.previewImage({
- // current: url, // 当前显示图片的http链接
- // urls: [url] // 需要预览的图片http链接列表
- // })
- },
- closePreviewImage() {
- this.setData({
- showCustomPreview: false
- })
- }
- })
|