// packageH/consumerReward/consumerRewardApply/consumerRewardApply.js
var app = getApp();
let defaultTitle="消费";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    profitShow: false,
    diyform: {
      form_id: '',
      diyform_data_id: '',
      pre_id: '',
    },
    networkLoading: false,
    userInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  getData() {
    let urlStr = app.getNetAddresss(
      'plugin.consumer-reward.frontend.controllers.reward.index',
    );
    app._postNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        this.setData({
          userInfo: res.data,
          'diyform.form_id': res.data.form_id,
          networkLoading: true,
        });
        wx.setNavigationBarTitle({
          title: res.data.plugin_name||defaultTitle,
        });
      },
    });
  },

  receive() {
    // if (this.data.userInfo.is_form == 1) {
    //   this.setProfitShow();
    // } else {
    this.sendBtn();
    // }
  },

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

  gotoRewardRecord() {
    wx.navigateTo({
      url: '/packageH/consumerReward/consumerRewardRecord/consumerRewardRecord',
    });
  },

  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);
    }
  },

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

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

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

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

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

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

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

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