// packageH/consumerReward/consumerRewardPaySuccess/consumerRewardPaySuccess.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {},
    popup:false,
    pay_id:0,
    order:[],

    diyform: {
      form_id: '',
      diyform_data_id: '',
      pre_id: '',
    },

    profitShow:false,

    withdrawal:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.pay_id){
      this.setData({pay_id:options.pay_id});
      this.getData();
    }
  },

  getData() {
    let urlStr = app.getNetAddresss("plugin.consumer-reward.frontend.controllers.payment-jump.index");
    app._getNetWork({
      url: urlStr,
      data: {
        pay_id:this.data.pay_id
      },
      success: (resdata)=> {
        let res = resdata.data;
        if(res.result!=1) return app.tips(res.msg);
        let popup=false;
        if (res.data.popup == 1) popup = true;
        this.setData({
          detail:res.data,
          order:res.data.order,
          popup
        });
      }
    });
  },
  receive() {
    let urlStr = app.getNetAddresss("plugin.consumer-reward.frontend.controllers.reward.receive-reward");
    app._getNetWork({
      url: urlStr,
      data: {
        pay_id:this.data.pay_id
      },
      success: (resdata)=> {
        let res = resdata.data;
        app.tips(res.msg);
        if(res.result!=1) return ;
        setTimeout(()=>{
          if(this.data.detail.is_withdraw == 1){
            if(this.data.detail.is_bind == 1){
              this.setData({
                popup:false,
                withdrawal:true,
                'diyform.form_id': res.data.form_id,
                networkLoading: true,
                is_form:res.data.is_form,
                cash:res.data.cash,
                dividend_id:res.data.dividend_id
              });
            }
          }else {
            wx.navigateTo({
              url: '/packageG/member_v2/member_v2',
            });
          }
          
        },1000);
     
      }
    });
  },

  handWithBtn(){
    
    // if(this.data.is_form == 1){
    //   this.setData({profitShow:true});
    // }else {
    this.sendBtn();
    // }
  },

  traCheckedData(e) {
    let diyform_data_id = e.detail.diyform_data_id;
    console.log(e);
    if (diyform_data_id) {
      // this.setProfitShow();
      this.sendBtn(diyform_data_id);
    }
  },

  setProfitShow() {
    this.setData({
      profitShow: !this.data.profitShow,
    });
  },

  sendBtn(diyform_data_id = 0) {
    let json = {
      form_data_id: diyform_data_id,
      form_id: this.data.diyform.form_id,
      dividend_id:this.data.dividend_id,
      cash:this.data.cash
    };
    let urlStr = app.getNetAddresss(
      'plugin.consumer-reward.frontend.controllers.withdraw.withdraw',
    );
    app._getNetWork({
      url: urlStr,
      data: json,
      success: (resdata) => {
        var res = resdata.data;
        app.tips(res.msg);
        if (res.result == 1) {
          this.setData({
            withdrawal:false,
            profitShow: false,
          });
        }
      },
    });
  },

  gotoBannerUrl(){
    wx.navigateTo({
      url: this.data.detail.min_link,
    });
  },

  setPopup(){
    this.setData({
      popup:!this.data.popup
    });
  },

  setWithdrawal(){
    this.setData({withdrawal:!this.data.withdrawal});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
});