// pages/integral/integral.js import Integralinfo from '../../api/integralinfo' Page({ /** * 页面的初始数据 */ data: { lock: false, noResult: false, noMore: false, bannerList: [], couponList: [], channelid: '', shopid: '', storeid: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getBannerList() this.getCouponList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, getBannerList: function() { Integralinfo.getBannerList({ channelid: this.data.channelid, shopid: this.data.shopid, storeid: this.data.storeid }).then(res => { console.log(res.data) this.setData({ bannerList: res.data }) }).catch(err => { console.log(err) }) }, getCouponList: function() { Integralinfo.getList({ channelid: this.data.channelid, shopid: this.data.shopid, storeid: this.data.storeid }).then(res => { this.couponListView(res.data) this.data.lock = false }).catch(_ => { console.log(_) this.data.lock = false }) }, couponListView: function(data) { if (!Array.isArray(data) || data.length == 0) { console.log("优惠券列表数据为空"); } data.forEach((v) => { v.quantity = 0 v.integral = v.price * v.ratio }) if (this.mobile != '********') { let num = this.integralNum > 20000 ? 19999 : this.integralNum const arr = [] for (let i = 0; i < data.length; i++) { data[i].quantity = parseInt(num / data[i].integral) if (data[i].quantity > 0) { num -= (data[i].quantity * data[i].price) * data[i].ratio this.total += (data[i].quantity * data[i].price) * data[i].ratio arr.push(data[i]) data.splice(i, 1) i-- } } this.setData({ couponList: [...arr, ...data] }) console.log(this.data.couponList) } } })