coupon.js 2.64 KB
// coupon.js
const xnService = require('../../service/service.js');
const util = require('../../utils/util.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    isEnd: false,
    isLoading: false,
    tip: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList();
  },


  getList() {
    let _this = this;
    var memberId = app.getMemberId();
    var vm = {
      memberIdList: [memberId] ,
      pageSize: 0,
      status:'unuse',
      isUsefulEndOut:false
    }
    console.log(vm);

    _this.setData({
      isLoading: true,
      tip: "查询中"
    })

    xnService.promotionCouponEntityFind(vm, function (data) {

      _this.setData({
        isLoading: false,
        tip: ''
      })
      if (data.firstErrorMessage) {
        _this.setData({
          isEnd: true,
          tip: data.firstErrorMessage
        })
      } else {
        if (data.result && data.result.length > 0) {

          var dataList = data.result;

          // 优惠券
          let ids = [];
          for (let i = 0; i < dataList.length; i++) {
            ids.push(dataList[i].couponDefinitionId);
             dataList[i].usefulStart = util.formatDay(dataList[i].usefulStart);
             dataList[i].usefulEnd = util.formatDay(dataList[i].usefulEnd);
            // dataList[i].debit = dataList[i].debit.toFixed(2);
            // dataList[i].credit = dataList[i].credit.toFixed(2);
            // dataList[i].balance = dataList[i].balance.toFixed(2);
          }

          xnService.promotionCouponDefinitionFind({ ids: ids, pageSize: 0 }, function (coupon) {
            let couponList = coupon.result;
            for (let j = 0; j < dataList.length; j++) {
              for (let k = 0; k < couponList.length; k++) {
                if (dataList[j].couponDefinitionId == couponList[k].id) {
                  dataList[j].couponDefinition = couponList[k];
                  dataList[j].couponDefinition.profitQuantityFixed = dataList[j].couponDefinition.profitQuantity.toFixed(2);
                  
                  break;
                }
              }
            }     
            _this.setData({
              dataList: _this.data.dataList.concat(dataList)
            })
          });
         
        } else {
          _this.setData({
            isEnd: true,
            tip: "暂无优惠券"
          })
        }
      }
    });
  },
   // 下拉刷新
  onPullDownRefresh: function () {
    let _this = this;
    _this.setData({
      dataList: [],
      isEnd: false,
      isLoading: false,
      tip: ""
    })
    this.getList();
    wx.stopPullDownRefresh()
  }
 
})