// pages/integral/exchange.js import Integralinfo from '../../api/integralinfo' import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user' import { parseTime } from '../../utils/util' Page({ /** * 页面的初始数据 */ data: { tabStatus: 'a', cardList: [], row:{}, listStatus:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this.data.row = JSON.parse(options.obj) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, // 排序 cardsSortRule(pre, next) { if (!pre.order_status && pre.order_status === next.order_status) { // 一级分类内部的二级排序:没过期时,激活时间倒序 return next.order_status - pre.order_status // -1 } else { // 最外层一级大类排序:没过期排在过期前面 if (pre.order_status && !next.order_status) { return 1 } else { return -1 } } }, getList() { Integralinfo.getOrderList({ channelid: '', shopid: '', storeid: '', mobile: getMobileCache() }).then(res => { const data = res.data data.forEach((v) => { let starttime = Math.round(new Date(v.starttime).getTime() / 1000) let endDate = Math.round(new Date(v.endtime).getTime() / 1000) let current = Math.round(new Date().getTime() / 1000) v.start = parseTime(starttime, '{y}-{m}-{d} {h}:{i}:{s}') v.end = parseTime(endDate, '{y}-{m}-{d} {h}:{i}:{s}') if (v.order_status === 0 && endDate < current) { v.order_status = 2 } }) data.sort(this.cardsSortRule) this.setData({ cardList: data, listStatus: true }) }); }, toInstructions(){ wx.navigateTo({ url: '../welfareMall/buyInfo/buyInfo' }) } })