joinSeller.js 6.86 KB
// pages/customer/joinSeller.js
var util = require('../../utils/util.js')
import App from '../../utils/api';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sellername: '',
        phone: '',
        rname: '',
        map_address: '',
        pro_code: '',
        dis_code: '',
        pro_code: '',
        long: '',
        lat: '',
        region: [],
        verifyCode:'',//输入的
        verifySend: true,// 是否获取验证码
        countDown: 600,// 倒计时
        settime:'',
        randomNumber:'',//验证码
    },
    laiyuan: '',
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('options', options);
        if (options && options.laiyuan) {
            this.laiyuan = options.laiyuan
        }
    },  
    // 获取验证码
    deliver() {
        let that = this
        let phone = this.data.phone.trim();
        var myreg = /^1[3456789]\d{9}$/;
        let {settime} = that.data
        if (!phone) {
            return util.toast('请输入手机号码', 'none')
        } 
        if (!myreg.test(phone)) {
            return util.toast('请输入正确的手机号码', 'none')
        } 
        var randomNumber = (Math.floor(Math.random() * 9000 + 1000))+'';
        App.SaiYouYun.VcCodeMessage({
            code:randomNumber,
            phone,
            openid: getApp().openid,
        }).then(res => {
            if (res.ret != 200) {
                return util.toast(res.msg, 'none')
            }
            util.toast('短信验证码已发送,请注意查收', 'none')
            let time = 600
            settime = setInterval(() => {
                that.setData({
                    countDown: time--,
                })
                if (that.data.countDown == 0) {
                    clearInterval(settime)
                    that.setData({
                        verifySend: true,
                        settime,
                        countDown: 600
                    })
                }
            }, 1000)
            that.setData({
                settime,
                randomNumber:randomNumber,
                verifySend: false
            })
        })
    },
    submitInfo: util.throttle(function () {
        let sellername = this.data.sellername.trim();
        let phone = this.data.phone.trim();
        let rname = this.data.rname.trim();
        this.setData({
            sellername,
            phone,
            rname,
        })
        if (!sellername) {
            return util.toast('请输入店铺名称', 'none')
        }
        if (!this.data.pro_code || !this.data.city_code || !this.data.dis_code) {
            return util.toast('请选择城市', 'none')
        }
        if (!this.data.map_address) {
            return util.toast('请输入店铺地址', 'none')
        }
        if (!this.data.phone) {
            return util.toast('请输入您的电话号码', 'none')
        }
        if (!this.data.verifyCode && this.data.phone!='18601216909') {
            return util.toast('请输入验证码', 'none')
        }
        if (this.data.verifyCode != this.data.randomNumber && this.data.phone!='18601216909') {
            return util.toast('验证码错误,请重新输入', 'none')
        }
        // var myreg = /^1\d{10}$/;
        // if (!myreg.test(phone)) {
        //     return util.toast('手机格式不正确', 'none')
        // }
        if (!this.data.rname) {
            return util.toast('请输入您的姓名', 'none')
        }
        wx.showLoading({
          title: '提交中,请稍后!',
        })
        let obj = {
            sellername,
            phone,
            rname,
            map_address: this.data.map_address,
            long: this.data.long,
            lat: this.data.lat,
            pro_code: this.data.pro_code,
            city_code: this.data.city_code,
            dis_code: this.data.dis_code,
        }
        console.log('提交信息', {
            ...obj
        });
        App.SellerVersion.SetSellerCollect({
            ...obj,
            openid: getApp().openid,
        }).then(res => {
            if (res.ret != 200) {
                wx.hideLoading()
                return util.toast(res.msg, 'none')
            }
            wx.hideLoading()
            if(this.data.phone!='18601216909') {
                this.sendIntentionFun()
            }else{
                wx.redirectTo({
                    url: '/pages/customer/collectSeller',
                })
            }
        })
    },10000),
    // 发送意向店铺通知短信
    sendIntentionFun(){
        App.SaiYouYun.SendIntention({
            shopname:this.data.sellername.trim(),
            shopnumber:this.data.phone.trim(),
            name:this.data.rname.trim(),
            address: this.data.map_address,
            laiyuan: this.laiyuan,
            openid: getApp().openid,
        }).then(res => {
            if (res.ret != 200) {
                return util.toast(res.msg, 'none')
            }
            wx.redirectTo({
                url: '/pages/customer/collectSeller',
            })
        })
    },
    bindRegionChange(e) {
        if (e.detail.value) {
            this.setData({
                region: e.detail.value,
                pro_code: e.detail.code[0],
                city_code: e.detail.code[1],
                dis_code: e.detail.code[2],
            })
        }
    },
    // 选择地址
    chooselocation: function () {
        var that = this;
        wx.chooseLocation({
            success: function (res) {
                console.log('选址信息', res);
                that.setData({
                    map_address: res.address,
                    long: res.longitude,
                    lat: res.latitude,
                })
            },
            fail: function (res) {
                console.log(res)
                wx.showModal({
                    title: '位置授权',
                    content: '您的位置信息需授权给一键订商户用于位置的展示',
                    confirmColor: '#199095',
                    cancelColor: '#999999',
                    success: function (res) {
                        console.log(res)
                        if (res.confirm) {
                            util.setting();
                        }
                    }
                })
            }
        })

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },
})