s_detail.js 4.43 KB
var util = require('../../utils/util.js')
var uri = require('../../utils/uri.js')

Page({
    data:{
        reminder:''
    },
    onLoad:function(opt){
        var seller_tel=opt.type=='phone' && opt.info!='' ? opt.info.split('/') : null;
        var seller_tel1='',seller_tel2='';
        if(opt.type=='phone' && opt.info!=''){
            if(seller_tel && seller_tel.length>1){
                seller_tel1=seller_tel[0];
                seller_tel2=seller_tel[1]
            }else{
                seller_tel1=seller_tel[0];
            }
        }
        this.setData({
            opt:opt,
            sellerid:util.cache('sellerid'),
            // optdaily:opt.type=='daily_time' && opt.info!='' ? opt.info.split('-') : null,
            seller_tel1:opt.type=='phone' ? seller_tel1 : null,
            seller_tel2:opt.type=='phone' ? seller_tel2 : null,
        })

        // console.log(opt)
    },
    onShow:function () {
        var that=this;
        util.postSuccessFun=function(json,uri_code){
            switch (uri_code) {
                case uri.CGI__USER_SETSELLERBYID__CODE:
                    console.log(json)
                    if(json.ret==200){
                        wx.navigateBack()
                    }else{
                        that.setData({
                            reminder:json.msg.split(':')[1]
                        })
                    }
                break;
            }
        }
    },
    inputphone:function(e){
        // var RegExp = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
        // if(util.strtrim(e.detail.value)!=''){
        //     if(!RegExp.test(util.strtrim(e.detail.value))){
        //         this.setData({
        //             reminder:'电话格式不正确或位数不正确'
        //         })
        //     }else{
        //         this.setData({
        //             reminder:''
        //         })
        //     }
        // }
        if(e.detail.value==''){
            this.setData({
                reminder:'请输入电话号码'
            })
        }else{
            this.setData({
                reminder:''
            })
        }
    },
    inputtime:function(e){
        // var reg = /^(20|21|22|23|[0-1]\d):[0-5]\d$/;
        // var regExp = new RegExp(reg);
        if(e.detail.value!='' && util.strtrim(e.detail.value)!=''){
            this.setData({
                reminder:''
            })
        }else{
            this.setData({
                reminder:'请输入营业时间'
            })
        }
    },
    formSubmit:function(e){
        var formdata={};
        if(this.data.opt.type=='daily_time'){
            console.log(e)
            if(this.data.reminder==''){
                formdata=e.detail.value;
                formdata.id=this.data.sellerid;
                util.post(uri.CGI__USER_SETSELLERBYID,formdata,uri.CGI__USER_SETSELLERBYID__CODE);
            }
        }else{
            if(this.data.opt.type=='phone'){
                if(this.data.reminder==''){
                    if(e.detail.value['seller_tel1']!='' || e.detail.value['seller_tel2']!=''){
                        var sellertel=[];
                        for(var key in e.detail.value){
                            if(e.detail.value[key]!=''){
                                sellertel.push(e.detail.value[key])
                            }
                        }
                        formdata.seller_tel=sellertel.toString();
                        formdata.id=this.data.sellerid;
                        util.post(uri.CGI__USER_SETSELLERBYID,formdata,uri.CGI__USER_SETSELLERBYID__CODE);

                    }else{
                        this.setData({
                            reminder:'请输入电话号码'
                        })
                    }
                }
            }else{
                var type=this.data.opt.type;
                console.log(type)
                if(e.detail.value[type]!='' && util.strtrim(e.detail.value[type])!=''){
                    formdata[type]=util.strtrim(e.detail.value[type]);
                    formdata.id=this.data.sellerid;
                    console.log(formdata)
                    util.post(uri.CGI__USER_SETSELLERBYID,formdata,uri.CGI__USER_SETSELLERBYID__CODE);
                }else{
                    this.setData({
                        reminder:'店铺'+this.data.opt.typeinfo+'不能为空'
                    })
                }
            }


        }

    },
    netchange:function () {
       this.onShow();
    }

})