// index.js
let myPro = require("../../utils/wxRequest.js");
let util = require("../../utils/util.js");
// 获取应用实例
const app = getApp();

Page({
    data: {
		current: 0, // 轮播图展示第几个
		interval: 3000, // 自动切换时间间隔
		adList: ['/statics/img/join/1.png','/statics/img/join/2.png','/statics/img/join/3.png'],
		name: '',
		phone: '',
		city: '',
		remark: '',
		showBack: true,
		pageTitle: "招商加盟",
		showHeader: false, // header显示状态
		setBgHeight: getApp().globalData.setBgHeight,
		loading: false // 全局loading
    },
    onLoad: function (options) {
        // Do some initialize when page load.
    },
    onShow: function () {
        // Do something when page show.
		let that = this;
    },
    onReady: function () {
        // Do something when page ready.
    },
    onHide: function () {
        // Do something when page hide.
    },
    onUnload: function () {
        // Do something when page close.
    },
    onPullDownRefresh: function () {
        // Do something when pull down.
		
    },
    onReachBottom: function () {
        // Do something when page reach bottom.
    },
    onPageScroll: function (event) {
        // Do something when page scroll
		let that = this;
		let scrollTop = event.scrollTop;
		if(scrollTop >= that.data.setBgHeight){
			that.setData({
				showHeader: true
			});
		}else{
			that.setData({
				showHeader: false
			});
		}
    },
    onResize: function () {
        // Do something when page resize
    },
	// 广告轮播图切换
	changeAd(event){
		let that = this;
		that.setData({
			current: event.detail.current,
		});
	},
	// 加盟人姓名
	getName(event){
		let that = this;
		that.setData({
			name: event.detail
		});
	},
	// 加盟人电话
	getPhone(event){
		let that = this;
		that.setData({
			phone: event.detail
		});
	},
	// 加盟人地址
	getCity(event){
		let that = this;
		that.setData({
			city: event.detail
		});
	},
	// 加盟人留言
	getRemark(event){
		let that = this;
		that.setData({
			remark: event.detail
		});
	},
	// 提交
	tijiao(){
		let that = this;
		if(!that.data.name){
			wx.showToast({
				title: "请填写您的姓名",
                icon: "none",
			});
			return;
		};
		if(!that.data.phone || !(/^1[3456789]\d{9}$/.test(that.data.phone))){
			wx.showToast({
                title: "手机号有误,请重新填写",
                icon: "none",
            });
			return;
		};
		if(!that.data.city){
			wx.showToast({
                title: "请填写您所在的城市",
                icon: "none",
            });
			return;
		};
		let params = {
			name: that.data.name,
			phone: that.data.phone,
			city: that.data.city
		};
		if(that.data.remark){
			params.remark = that.data.remark
		};
		myPro.wxRequest("user/v2/joinUs","GET",params).then(res=>{
			wx.showToast({
				title: res.msg,
				icon: "none"
			});
			that.setData({
				name: "",
				phone: "",
				city: "",
				remark: ""
			});
		}).catch(err=>{
			console.log("报错信息",err);
			wx.showToast({
				title: err,
				icon: "none"
			})
		})
	}
});
