import common from '../../utils/util';
import server from '../../utils/main';

const app = getApp();

Page({
  data: {
    IsGift:true,
  },
  onLoad: function (options) {
    var isgift = Number(options.IsGift);
    this.setData({
      Containnerheight: common.getSystemHeight(),
      ProgramList: server.getProgramList(),
      ProgramID:app.globalData.ProgramID,
      MathShow: false,
      ChineseShow: false,
      AllShow: false,
      MathGiftShow: false,
      AllGiftShow: false,
      IsGift: isgift,
    });

    if (isgift==1){
      wx.setNavigationBarTitle({
        title: '购买礼品卡',
      })
    }

    this.init();
  },
  init:function(){
    var arrProduct = wx.getStorageSync("ProductPrice");
    var arr=[];
    for(var i=0;i<arrProduct.length;i++){
      if (arrProduct[i].ProductNum.indexOf(",")>0){
        arr.push(arrProduct[i]);
      }
    }

    var CurrentProduct;
    for (var i = 0; i < arrProduct.length; i++) {
      if (arrProduct[i].ProductNum == app.globalData.ProgramID) {
        CurrentProduct=arrProduct[i];
      }
    }
    this.setData({
      ProductList:arr,
      CurrentProduct: CurrentProduct,
    });
  },
  showList: function (e) {
    var id = e.currentTarget.dataset.id;
    this.data[id] = true;
    this.setData(this.data);
  }, 
  gotoOrder: function (e) {
    var id = e.currentTarget.dataset.id;
    var paytype = e.currentTarget.dataset.paytype;
    wx.navigateTo({
      url: "./order?id=" + id + "&paytype=" + paytype,
    });
  },
  switchProgram: function (e) {
    wx.navigateToMiniProgram({
      appId: e.currentTarget.dataset.appid,
      path: e.currentTarget.dataset.path,
      extraData: {
      },
      success(res) {
        // 打开成功
      }
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})