123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- // 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)
- }
- }
-
- })
|