l_info.js 7.44 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
//测试
var app=getApp();

Page({
    data:{
        buttonhide:true,
        map_address:'',
        long:'',
        lat:'',
        storename:'',
        storephone:'',
        openid:'',
        reminderinfo:'',
        namehide:true,
        phonehide:true,
    },
    onLoad:function(){
        this.setData({
            openid:util.cache('openid'),
            nickName:wx.getStorageSync('nickname')
        })
        //测试
        app.scence=1
    },
    onShow:function(){
        var that=this;
        util.postSuccessFun=function(json,uri_code){
            switch (uri_code){
                case uri.CGI__USER_ADDSELLER__CODE:
                    console.log(json)
                    wx.hideToast();
                    if(json.ret==200){
                        wx.showToast({
                            title:'注册成功',
                            mask:true,
                            duration:2000,
                            success:function(){
                                setTimeout(function(){
                                    wx.reLaunch({
                                        url:'../me/s_index?sellerid='+json.data.sellerid
                                    })
                                },2000)
                            }
                        })
                    }else{
                        that.setData({
                            reminderinfo:json.msg.split(':')[1]
                        })
                        if(json.msg.split(':')[1]=='名称已存在'){
                            that.setData({
                                namehide:false,
                                phonehide:true
                            })
                        }else{
                            that.setData({
                                namehide:true,
                                phonehide:false
                            })
                        }
                    }
                break;
            }
        }
    },
    bindPickerChange:function(e){
        this.setData({
            typename:this.data.typelist[e.detail.value]
        })
    },
    storename:function(e){
        this.setData({
            storename:util.strtrim(e.detail.value)
        })
        var name=this.data.storename;
        var phone=this.data.storephone;
        var address=this.data.map_address;
        if(phone!=''){
            var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
            if (!myreg.test(phone)) {
                this.setData({
                    reminderinfo:'手机格式不正确',
                    phonehide:false
                })
            } else {
                this.setData({
                    reminderinfo:'',
                    phonehide:true
                })
            }
            this.setData({
                reminderinfo:'',
                phonehide:true
            })
        }
        if(this.data.reminderinfo!=''){
            console.log(1)
            if(name!='' && phone!='' && address!=''){
                this.setData({
                    buttonhide:false
                })
            }
        }
    },
    storephone:function(e){
        this.setData({
            storephone:e.detail.value
        })
        var name=this.data.storename;
        var phone=this.data.storephone;
        var address=this.data.map_address;
        if(this.data.reminderinfo==''){
            console.log(1)
            if(name!='' && phone!='' && address!=''){
                this.setData({
                    buttonhide:false
                })
            }
        }
    },
    condition:function(e){
        var name=this.data.storename;
        var phone=this.data.storephone;
        var address=this.data.map_address;
        if(phone!=''){
            var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
            if (!myreg.test(phone)) {
                this.setData({
                    reminderinfo:'手机格式不正确',
                    buttonhide:true,
                    phonehide:false
                })
            } else {
                this.setData({
                    reminderinfo:'',
                    phonehide:true
                })
            }
            this.setData({
                reminderinfo:'',
                phonehide:true
            })
        }
        if(this.data.reminderinfo==''){
            console.log(1)
            if(name!='' && phone!='' && address!=''){
                this.setData({
                    buttonhide:false
                })
            }
        }
    },
    chooselocation:function(){
        var that=this;
        console.log('xxxxxxx')
        wx.chooseLocation({
            success:function(res){
                console.log('11111111')
                that.setData({
                    map_address:res.address,
                    long:res.longitude,
                    lat:res.latitude,
                })
                var name=that.data.storename;
                var phone=that.data.storephone;
                var address=that.data.map_address;
                if(phone!=''){
                    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
                    if (!myreg.test(phone)) {
                        that.setData({
                            reminderinfo:'手机格式不正确',
                            buttonhide:true,
                            phonehide:false
                        })
                    } else {
                        that.setData({
                            reminderinfo:'',
                            buttonhide:false,
                            phonehide:true
                        })
                    }
                    that.setData({
                        reminderinfo:'',
                        buttonhide:false,
                        phonehide:true
                    })
                }
                if(that.data.reminderinfo==''){
                    console.log(1)
                    if(name!='' && phone!='' && address!=''){
                        that.setData({
                            buttonhide:false
                        })
                    }
                }

            },
            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();
                        }
                    }
                })
            }
        })

    },
    formSubmit:function(){
        console.log(this.data.openid)
        var formdata={};
        formdata.name=this.data.storename;
        formdata.phone=this.data.storephone;
        formdata.map_address=this.data.map_address;
        formdata.long=this.data.long;
        formdata.lat=this.data.lat;
        formdata.openid=this.data.openid;
        console.log(formdata)
        wx.showToast({
            title:'正在注册',
            mask:true,
            duration:10000,
            icon:'loading'
        })
		
        util.post(uri.CGI__USER_ADDSELLER,{name:formdata.name,phone:formdata.phone,map_address:formdata.map_address,long:formdata.long,lat:formdata.lat,openid:formdata.openid},uri.CGI__USER_ADDSELLER__CODE)

    },

})