const format = require("../../../utils/util.js");
const config = require("../../../config/config.js");
const app = getApp();
const Http = require("../../../utils/HttpBasics");
Page({
  data: {
    list: [],
    current: "0",
    current_scroll: "0",
    page: 1,
    allow_load: true
  },
  onLoad(options) {
    this.getList(0, 0);
    if (options.quanid){
      this.setData({
        quanid: options.quanid
      })
    }
  },
 
  /**
   * 选择使用的优惠券
   */
  choicecoupon: function(e) {
    wx.navigateBack();
    console.log(e);
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2] //上一个页面
    var that = this;
    var quantitle = e.currentTarget.dataset.title;
    var quanid = e.currentTarget.dataset.id;
    prevPage.setData({
      quantitle: quantitle,
      quanid: quanid,
    });
    wx.setStorage({
      key: 'chosed',
      data: 'chosed',
    })
  },
  getList(key, pageNum) {
    var that = this;
    console.log(key);
    console.log(pageNum);
    if (that.data.allow_load) {
      Http.get({
        url: config.api.couponOrderList + "?type=5",
        data: {
          pageNum: pageNum,
          pageSize: 20,
          couponOrderStatus: key
        }
      }).then(res => {
        console.log(res);
        res.data.list.map(file => {
          file.expiredTime = format.formatTime(
            file.expiredTime,
            "yyyy-MM-dd hh:mm:ss"
          );
        });
        if (pageNum > res.data.pages) {
          that.setData({
            allow_load: false
          });
        }
        that.data.list = that.data.list.concat(res.data.list);
        that.setData({
          list: that.data.list
        });
      });
    }
  },
});