123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- // pages/signIn/record/record.js
- import SignIn from '../../../api/signIn'
- import { parseTime } from '../../../utils/util'
- import {getMobileCache, getPhoneNumberNew 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: true,
- hiddenDetail: true,
- hiddenUtility: true,
- mobileTop: 'TONY WU',
- couponNum: 0,
- productNum: 0,
- couponList: [],
- detailList: [],
- stateList: [],
- notUseNum: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- isLogin: getMobileCache() != ''
- })
- 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
- }
- const couponListT = []
- data.forEach(v => {
- v.coupon.isSn = true
- v.coupon.couponStartTime = v.coupon.couponBeginTimestamp
- v.coupon.couponEndTime = v.coupon.couponEndTimestamp
- couponListT.push(v.coupon)
- })
- this.data.couponList = this.data.couponList.concat(...couponListT)
- 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,
- hiddenCoupon: false,
- hiddenDetail: true,
- hiddenUtility: 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,
- couponList: [],
- detailList: [],
- stateList: [],
- })
- this.getUserAwardCouponList()
- },
- //明细
- getDetail(e) {
- this.setData({
- hiddenCoupon: true,
- hiddenDetail: false,
- hiddenUtility: true,
- page: 1,
- goodsType: 2,
- noMore: false,
- noResult: false,
- noDetail: true,
- noCoupon: false,
- noUtility: false,
- couponList: [],
- detailList: [],
- stateList: [],
- })
- this.getUserSignInList()
-
- },
- //使用失效
- getUtility(e) {
- this.setData({
- hiddenCoupon: true,
- hiddenDetail: true,
- hiddenUtility: false,
- page: 1,
- goodsType: 2,
- noMore: false,
- noResult: false,
- noUtility: true,
- noCoupon: false,
- noDetail: false,
- couponList: [],
- detailList: [],
- stateList: [],
- })
- this.getCouponStateList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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();
- },
- scrollToBottom() {
- if (this.data.lock || this.data.noMore) {
- return
- }
- this.data.lock = true
- this.data.page++
- this.getRequestData();
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|