const wx2my = require('../../wx2my');
const Behavior = require('../../Behavior');
// pages/integralMallDetail/integralMallDetail.js
const app = getApp();

const wxService = require('../../utils/wxService');

const utils = require('../../utils/util');

const envInfo = require('../../config/index').envInfo;

wxService.page({
  /**
   * 页面的初始数据
   */
  data: {
    isExchange: false,
    integralMallDetail: {}
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const {
      id
    } = this.options; // this.getIntegralCouponDetail('579702812007600128')

    this.getIntegralCouponDetail(id);
  },

  //立即兑换
  exchange() {
    this.setData({
      isExchange: true
    });
  },

  //获取积分兑换优惠券详情
  getIntegralCouponDetail(id) {
    wx2my.showLoading({
      title: '加载中'
    });
    wxService.get(`/coupon/pointsRedemptionCouponSetting/get/${id}`).then(res => {
      const {
        result,
        data
      } = res.data;

      if (result == 0) {
        wx2my.hideLoading();
        data.desc = JSON.parse(data.desc);

        for (let i in data.desc) {
          if (data.desc[i].type == 1) {
            data.desc[i].value = data.startTime.substring(0, 10) + ' 至 ' + data.endTime.substring(0, 10);
          }
        }

        this.setData({
          integralMallDetail: data
        });
      }
    }).finally(() => {
      wx2my.hideLoading();
    });
  }

});