cb_fadd.js 2.58 KB
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')

Page({
    data: {
    },
    onLoad:function(opt){
        var that=this;
        console.log('opt:',opt);
        util.setBarTitle('添加菜品')

        this.setData({
            classid:opt.cid ? opt.cid : '',
            sellerid: util.cache("sellerid"),
            url:opt.url ? opt.url : null
        })
        wx.removeStorage({key:'cook_name'})
    },
    onShow:function(){
        console.log(util.cache("cook_name"))
        this.setData({
            cook_name:util.cache("cook_name") ? util.cache("cook_name") : '',
            reminderInfo:null,
        })
        var that=this;
        util.postSuccessFun=function(json,uri_code) {
            switch (uri_code) {
                case  uri.CGI__USER_GETCOOKBOOKISEXITS__CODE:
                    if(json.ret==200){
                        if(json.data[0]==true){
                            that.setData({
                                reminderInfo:'该菜品已存在'
                            })
                        }else{
                            if(that.data.url){
                                wx.navigateTo({
                                    url: 'cb_sadd?url='+that.data.url,

                                })
                            }else{
                                wx.navigateTo({
                                    url: 'cb_sadd?cid='+that.data.classid,

                                })
                            }
                        }
                    }
                break
            }
        }
    },
    //设置缓存数据
    setCatchdate:function(e) {
        var cook_name;
        cook_name = e;
        util.cache("cook_name",cook_name);
    },
    //记录输入信息
    cooknameInput:function(e){
        var cook_name=''
        if(e.detail.keyCode==32){
            cook_name=e.detail.value.slice(0,-1);
        }else{
            cook_name = e.detail.value
        }
        this.setData({
            cook_name:cook_name,
            reminderInfo:cook_name!='' ? null : '请输入菜品名'
        })
    },
    nextStep:function(){
        console.log(this.data.cook_name)
        if(this.data.cook_name!=''){
            this.setCatchdate(this.data.cook_name);
            util.post(uri.CGI__USER_GETCOOKBOOKISEXITS,{sellerid:this.data.sellerid,name:this.data.cook_name},uri.CGI__USER_GETCOOKBOOKISEXITS__CODE);
        }else{
            this.setData({
                reminderInfo:'请输入菜品名'
            })
        }
    },
    netchange:function(){
        this.onShow();
    }

});