// packageH/ApplyForMerchants/ApplyForMerchants.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: "",
    condition_state: "",
    apply_state: 0,
    goods_list: [],
    member_levels: [],
    commission_levels: [],
    team_levels: [],
    check_list: []
  },

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

  },
  getData() {
    app._postNetWork({
      url: app.getNetAddresss("plugin.area-merchant.frontend.modules.apply.controllers.page.index"),
      success: (res) => {
        if (res.data.result == 1) {
          let {
            goods_list,
            member_levels,
            check_list,
            commission_levels,
            team_levels,
            apply_state,
            condition_state
          } = res.data.data;
          this.setData({
            condition_state,
            goods_list,
            member_levels,
            check_list,
            commission_levels,
            team_levels,
            apply_state
          })
          if (apply_state == 0 || apply_state == 1 || apply_state == -1) {
            this.setData({text:"申请招商员"})
          } else if (apply_state == 2) {
            this.setData({text:"已通过"})
          }
        }
      }
    })
  },
  handle(){
    if(this.data.apply_state==1||this.data.apply_state==2){
      return;
    }
    app._postNetWork({
      url: app.getNetAddresss("plugin.area-merchant.frontend.modules.apply.controllers.store.index"),
      success: (res) => {
        console.log(res)
        if (res.data.result == 1) {
          wx.showToast({
            icon:"none",
            title: '已申请，等待后台审批'
          })
          this.setData({apply_state:2})
        }else{
          wx.showToast({
            title: res.data.data.msg,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})