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

const app = getApp();

Page({
  data: {
    List: [],
  },
  onLoad: function (options) {
    this.setData({
      Containnerheight: common.getSystemHeight(),
      ProgramList: server.getProgramList(),
      ProgramID:app.globalData.ProgramID,
      canGive:false,
    });
    this.init(options.id);
  },
  init: function (id) {
    var that = this;
    var url = "GetGiftInfoByUserID500?ID=" + id + "&ProductID=" + app.globalData.ProgramID;
    server.getData(url, function (data) {
      if (data) {
        that.setData({
          GiftInfo: data,
        });
      }
    });
  },
  gotoFeedback: function () {
    server.gotoFeedback();
  },
  getRemind:function(){
    var that=this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo']) {
          wx.navigateTo({
            url: '../../pages/main/accredit?url=giftinfo'
          });
        }
        else {
          wx.showModal({
            title: '慎重转发',
            content: '请勿转发到群。如误转，只能在聊天窗口中撤回（1分钟内）。',
            confirmText: '知道了',
            showCancel: false,
          });
          that.setData({
            canGive: true,
          });
        }
      }
    });
    
  },
  onShareAppMessage: function () {
    if (this.data.GiftInfo.PayType == 5 && this.data.GiftInfo.ExchangeUserID>0){
      return {
        title: app.globalData.ShareTitle,
        path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
        imageUrl: app.globalData.ShareImage,
      }
    }
    else{
      return {
        title: "有价商品尽快领取",
        path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + '&GiftID=' + this.data.GiftInfo.ID,
        imageUrl: '../images/program_screenshot_giftcard.png',
      }
    }
  },
})