// pages/signIn/record/record.js import SignIn from '../../../api/signIn' import { parseTime } from '../../../utils/util' import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user' Page({ /** * 页面的初始数据 */ data: { page: 1, pageSize: 10, lock: false, noResult: false, noMore: false, noCoupon: false, noDetail: false, noUtility: false, isLogin: false, hiddenCoupon: false, hiddenDetail: false, hiddenUtility: false, mobileTop: 'TONY WU', couponNum: 0, productNum: 0, couponList: [], detailList: [], stateList: [], notUseNum: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ isLogin: getMobileCache() != '' }) wx.setNavigationBarTitle({ title: '我的优惠', }) if(this.data.isLogin){ this.setData({ hiddenCoupon: false, hiddenDetail: true, hiddenUtility: true, noCoupon: true, noDetail: false, noUtility: false, }) this.getUserAwardCouponNum(); this.getRequestData(); } }, // 类型区分 getRequestData() { if (this.data.noCoupon) { this.getUserAwardCouponList(); } if (this.data.noDetail) { this.getUserSignInList(); } if (this.data.noUtility) { this.getCouponStateList(); } }, builtPublicParams() { return { page: this.data.page, pageSize: this.data.pageSize, mobile: getMobileCache(), } }, // 优惠券数据 getUserAwardCouponList: function() { SignIn.getUserAwardCouponList(this.builtPublicParams()).then(res => { if (res.code == 200) { this.userCouponListView(res.data) } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, userCouponListView: function(data) { if (!Array.isArray(data) || data.length == 0) { console.log("优惠券数据为空"); if (this.data.page == 1) { this.setData({ mobileTop:getMobileCache(), noResult: true }) } else { this.setData({ mobileTop:getMobileCache(), noMore: true }) } return } data.forEach(v => { let beginTime = v.coupon.couponBeginTimestamp let endTime = v.coupon.couponEndTimestamp v.coupon.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}") v.coupon.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}") }) this.data.couponList = this.data.couponList.concat(...data) this.setData({ mobileTop:getMobileCache(), couponList: this.data.couponList }) }, //未使用的券数量 getUserAwardCouponNum: function() { SignIn.getUserAwardCouponNum(this.builtPublicParams()).then(res => { if (res.code == 200) { this.setData({ notUseNum: res.data.notUseNum }) } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, // 签到明细 getUserSignInList: function() { SignIn.getUserSignInList(this.builtPublicParams()).then(res => { if (res.code == 200) { this.userDetailListView(res.data) } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, userDetailListView: function(data) { if (!Array.isArray(data) || data.length == 0) { console.log("获取明细数据为空"); if (this.data.page == 1) { this.setData({ mobileTop:getMobileCache(), noResult: true }) } else { this.setData({ mobileTop:getMobileCache(), noMore: true }) } return } data.forEach(v => { let crateTime = v.crateTime v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}") }) this.data.detailList = this.data.detailList.concat(...data) this.setData({ mobileTop:getMobileCache(), detailList: this.data.detailList }) }, // 使用失效 getCouponStateList: function() { SignIn.getUserAwardCouponUseStateList(this.builtPublicParams()).then(res => { if (res.code == 200) { this.userStateListView(res.data) } this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, userStateListView: function(data) { if (!Array.isArray(data) || data.length == 0) { console.log("使用失效数据为空"); if (this.data.page == 1) { this.setData({ mobileTop:getMobileCache(), noResult: true }) } else { this.setData({ mobileTop:getMobileCache(), noMore: true }) } return } data.forEach(v => { let crateTime = v.crateTime v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}") }) this.data.stateList = this.data.stateList.concat(...data) this.setData({ mobileTop:getMobileCache(), stateList: this.data.stateList }) }, // 授权手机号 getPhoneNumber(e) { getPhoneNumberSync(e, _ => { this.setData({ isLogin: true, mobileTop: getMobileCache(), noCoupon: true, }) this.getRequestData(); this.getUserAwardCouponNum(); }) }, // 优惠券 getCoupon(e) { this.setData({ hiddenCoupon: false, hiddenDetail: true, hiddenUtility: true, page: 1, goodsType: 1, noMore: false, noResult: false, noCoupon: true, noDetail: false, noUtility: false, }) this.data.couponList= [], this.data.detailList= [], this.data.stateList= [], this.getUserAwardCouponList() wx.setNavigationBarTitle({ title: '我的优惠', }) }, //明细 getDetail(e) { this.setData({ hiddenCoupon: true, hiddenDetail: false, hiddenUtility: true, page: 1, goodsType: 2, noMore: false, noResult: false, noDetail: true, noCoupon: false, noUtility: false, }) this.data.couponList= [], this.data.detailList= [], this.data.stateList= [], this.getUserSignInList() wx.setNavigationBarTitle({ title: '获取明细', }) }, //使用失效 getUtility(e) { this.setData({ hiddenCoupon: true, hiddenDetail: true, hiddenUtility: false, page: 1, goodsType: 2, noMore: false, noResult: false, noUtility: true, noCoupon: false, noDetail: false, }) this.data.couponList= [], this.data.detailList= [], this.data.stateList= [], this.getCouponStateList() wx.setNavigationBarTitle({ title: '使用/失效', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.lock || this.data.noMore) { return } this.data.lock = true this.data.page++ this.getRequestData(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })