const app = getApp()
const util = require("../../../utils/util");
const api = require('../../../api/api.js');
const user = require('../../../utils/user.js');




Page({
	data: {
		finishedSubmit: false,
		masterName: '',
		rid: '',
		shareType: '',
		name: '',
		mobile: '',
		city: '',
		showPicker: false,
		columns: [
			'上海市',
			'北京市',
			'深圳市',
			'南京市',
			'苏州市',
			'无锡市',
			'杭州市',
			'青岛市',
			'宜昌市',
			'重庆市',
			'成都市',
			'广州市',
			'昆山市',
			'长沙市',
			'西安市',
			'武汉市'
		],
	},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		console.log(options,"111");
		if(options.scene){
			var scene = decodeURIComponent(options.scene);
			console.log(scene);
			var sceneStr = scene.split(',')[1];
			var shareType = scene.split(',')[3];
			console.log(sceneStr);
			this.setData({
				rid: sceneStr,
				shareType: shareType
			});
			this.getMasterInfo();
		}

		if(options.shareType&&options.shareType!=''){
			this.setData({
				rid: options.rid,
				shareType: options.shareType
			});
			this.getMasterInfo();
		}
		// this.getMasterInfo()
	},
	getMasterInfo() {
		util.request(api.getTransferIntroductionInfo, {
			transferSponsorNo: this.data.rid
		}, 'GET').then(res => {
			if (res.errno === 0) {
				this.setData({
					masterName: res.data
				});
			} else {
				// wx.showToast({
				//   title: res.errmsg,
				//   icon: 'none'
				// });
			}
		})
	},
	bindName(e) {
		this.setData({
			name: e.detail.value
		});
	},
	bindMobile(e) {
		this.setData({
			mobile: e.detail.value
		});
	},
	cityTap() {
		this.setData({
			showPicker: true,
		});
	},
	pickerCancel() {
		this.setData({
			showPicker: false,
		})
	},
	pickerConfirm(e) {
		console.log(e);

		this.setData({
			city: e.detail.value,
			showPicker: false,
		});



	},

	onReachBottom() {

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

	},

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


	},

	onHide: function () {

	},

	onUnload: function () {

	},
	submit() {
		if (this.data.finishedSubmit) {
			return false;
		}
		if (this.data.name == '') {
			wx.showToast({
				title: '请输入姓名',
				icon: 'none'
			});
			return false;
		} else if (this.data.mobile == '') {
			wx.showToast({
				title: '请输入手机号码',
				icon: 'none'
			});
			return false;
		} else if (!/^1\d{10}$/.test(this.data.mobile)) {
			wx.showToast({
				title: '请输入正确的手机号码',
				icon: 'none'
			});

			return false;
		} else if (this.data.city == '') {
			wx.showToast({
				title: '请选择城市',
				icon: 'none'
			});
			return false;
		} else {
			wx.showLoading({
				title: '加载中...',
			});
			util.request(api.transferIntroduction, {
				city: this.data.city,
				name: this.data.name,
				tel: this.data.mobile,
				transferSponsorNo: this.data.rid,
				shareType: this.data.shareType
			}, 'POST').then(res => {
				wx.hideLoading();
				if (res.errno === 0) {
					this.setData({
						finishedSubmit: true
					});
					wx.showToast({
						title: '提交成功'
					});

				} else {
					wx.showToast({
						title: res.errmsg,
						icon: 'none'
					});
				}
			}).catch(err => {
				wx.hideLoading();
			});
		}
	},

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

	},

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

	},

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

	},

})