// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    status: "", //当前申请状态
    config_status: "", //后台申请条件
    config2: {}, //后台条件2
    config3: {}, //后台条件3
    config4: {}, //后台条件4
    config5: {}, //后台条件5
    username: '',
    password: '',
    password_again: ''
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function (options) {
    this.setData({
      status: '',//当前申请状态
      config_status: ''//后台申请条件
    });
    this.getData(); //获取申请状态以及商城配置信息
  },
  onChange(e) {
    let inp = e.detail;
    this.setData({
      username: inp
    });
  },
  onChange_p() {
    let inp = e.detail;
    this.setData({
      password: inp
    });
  },
  onChange_p2() {
    let inp = e.detail;
    this.setData({
      password_again: inp
    });
  },
  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function () { },

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

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

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

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

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

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function () { },
  //获取申请状态以及商城配置信息
  getData() {
    let that = this;
    let urlStr = app.getNetAddresss('plugin.merchant.frontend.get-center-condition');
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          that.setData({
            status: resdata.data.status,
            config_status: resdata.data.config_status,
            config2: resdata.data.config2,
            config3: resdata.data.config3,
            config4: resdata.data.config4,
            config5: resdata.data.config5,
            independent_backend:res.data.independent_backend
          });
          if(resdata.data.lang){
            that.setData({
              title:resdata.data.lang.title,
              merchant_center:resdata.data.lang.merchant_center
            });
            wx.setNavigationBarTitle({
              title: `${that.data.merchant_center}申请`,
            });
          }
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },

  //提交数据
  submit() {
    let that = this;
    if(that.data.config_status != 3 && that.data.independent_backend == 1){
      if(app._isTextEmpty(username) || app._isTextEmpty(password) || app._isTextEmpty(password_again)){
        wx.showToast({
          title: '请填写账号信息',
          icon:'none',
          duration:1000
        });
        return;
      }
			
    }
    let json = {
      config_status: this.data.config_status,
      user: {
        username: that.data.username,
        password: that.data.password,
        password_again: that.data.password_again
      }
    };
    let urlStr = app.getNetAddresss('plugin.merchant.frontend.merchant-apply.center');
    app._getNetWork({
      url: urlStr,
      data: json,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          that.setData({
            status: resdata.data.status
          });
        } else {
          if(resdata.data.status == -4){
            wx.showToast({
              title: resdata.msg,
              icon: 'none',
              success:(res)=>{
                wx.navigateTo({
                  url: 'packageB/member/enterprise/enterprise_apply/enterprise_apply',
                });
              }
            });
            return;
          }
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  //去商城
  goHome() {
    wx.reLaunch({
      url: '/packageG/index/index'
    });
  },

  //去商品页面
  goToGoods(Val) {
    let goods_id = Val.currentTarget.dataset.id || Val.target.dataset.id;
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2?id=' + goods_id
    });
  },

  //去招商中心
  goEnterproseCentre() {
    wx.navigateTo({
      url: '/packageB/member/enterprise/enterprise_index/enterprise_index'
    });
  }
});
