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

var app = getApp();

Page({
  data: {
    DayNumber: 365,
    Price: 199,
    SearchUserID: "",
    Remark: ""
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      Containnerheight: main.getWindowHeight(),
      ShareDisabled:true,
    });
  },
  onKeyInput: function (e) {
    var value = e.detail.value;
    var inputType = e.currentTarget.dataset.type;
    var that = this;
    that.data[inputType] = value;
    if (!that.data.SearchUserID || !that.data.DayNumber || !that.data.Price || !that.data.Remark){
      that.data["ShareDisabled"] = true;
    }
    else
      that.data["ShareDisabled"] = false;
    that.setData(that.data);
  },
  getUserInfo: function (e) {
    var that = this;
    if (!that.data.SearchUserID) {
      that.showToast('输入用户ID');
    }
    else {
      main.getData("GetMiaoguoWXUserInfo?FieldStr=UserID,NickName,AvatarUrl &UserID=" + that.data.SearchUserID, function (data) {
        if (data) {
          that.setData({
            UserInfo: data,
          })
        }
        else {
          that.showToast('无效用户ID');
        }
      });
    }
  },
  showToast: function (str) {
    wx.showToast({
      title: str,
      image: "../images/universalpic_wrong_white_120x120.png",
    });
  },
  onShareAppMessage: function () {
    var that = this;
    var path = '/pages/index/index?type=paycustom&PayUserID=' + that.data.SearchUserID;
    path += "&DayNumber=" + that.data.DayNumber;
    path += "&Price=" + that.data.Price;
    path += "&Remark=" + that.data.Remark;
    var time = common.formatTime(new Date());
    console.log(path);
    return {
      title: "点开续费 "+time,
      path: path,
      imageUrl: app.globalData.uploadImageUrl + "web/program_screenshot_custompayment.png",
    };

  },
})