distribution.js 3.76 KB
// packageA//pages/distribution/main/main.js
const app =  getApp();
let self = null;

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  self = this;//保存全局指针

		app.isLogin().then(function(data) {//进入页面前已经授权登录成功
			self.setData({
				userInfo: data,
			});
		});
		
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
		console.log('onshow');
		let url = '/api/weshop/users/distribut/getMoney';
		if(app.globalData.userInfo) {
			if(!this.data.isLogin) {
				this.setData({
					userInfo: app.globalData.userInfo,
					imghost: app.globalData.setting.imghost,
					isLogin: true,
				});
				
				// 请求数据
				app.request.get(url + '/' + this.data.userInfo.store_id + '/' + this.data.userInfo.user_id, {
				  success: function(res) {
						console.log('success~~`', self.data.userInfo);
					  if(res.data.code == 0){
		
							self.setData({
								data: res.data.data,
							});

						} else {
							// if(!res.data.data.is_distribut) {//如果不是分销商:0不是,1是
								
								app.request.promiseGet('/api/weshop/users/distribut/getIsDistribut', {
									data: {
										storeId: self.data.userInfo.store_id,
										userId: self.data.userInfo.user_id,
										first_leader: self.data.userInfo.first_leader,
									},
									isShowLoading: true,
								}).then(function(res) {
									console.log('!!!===>', res);
									self.setData({
										fenxiao: res.data.data,
									});
								});
								
							// };
						};
				  },

				});
				
			
			};
		};
		
		
  },

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

  },

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

  },

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

  },

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

  },

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

  },
	
	/**
	 * 点击跳转
	 */
	goto(e) {
		let url = '';
		if(e.target.dataset.url) {
			url = e.target.dataset.url;
		} else {
			url = e.currentTarget.dataset.url;
		}
		console.log(url);
		app.goto(url);
	},
	

	
	/**
	 * 获取输入框
	 */
	getInput(e) {
		this.setData({
			inputValue: e.detail.value,
		});
	},
	
	
	/**
	 * 验证
	 */
	verify(e) {
		let pass = e.target.dataset.pass;
		let mobile = 0;
		if(this.data.inputValue) {
			mobile = this.data.inputValue;
			if(!pass) {
				app.request.put('/api/weshop/users/distribut/updateUserRecommender', {
				  data: {
				    storeId: self.data.userInfo.store_id,
				    userId: self.data.userInfo.user_id,
				    mobile: mobile,
				  },
				  success: function (res) {
						if(res.code = -1) {
							wx.showToast({
							  title: res.data.msg,
							  icon: 'none',
							  duration: 2000
							});
						};
				    console.log('!!!===>', res);
 
						if(res.data.msg == '绑定上下级关系成功!') {
							app.request.promiseGet('/api/weshop/users/distribut/getIsDistribut', {
								data: {
									storeId: self.data.userInfo.store_id,
									userId: self.data.userInfo.user_id,
									first_leader: self.data.userInfo.first_leader,
								},
								isShowLoading: true,
							}).then(function(res) {
								console.log('!!!===>', res);
								self.setData({
									fenxiao: res.data.data,
								});
							});
						};
						
				  }
				});
				
			}
		} else {
			wx.showToast({
			  title: '手机号码不能为空',
			  icon: 'none',
			  duration: 2000
			});
		};
		
	},
})