ck_list.js 6.93 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')


Page({
    data: {
        loading: true,
        scrollHeight: 0,
        isscroll: true,
        atn_ishidden: true,
        specs: [],
    //    搜索框宽度
        searchWidth: '',
        inputKey: '',
        sellerid: '',
        auto_focus: false
    },
    onLoad: function () {
        var that=this;
        //获取系统信息
        var sys=wx.getSystemInfo({
            success:function(res){
                that.setData({
                    scrollHeight:res.windowHeight,
                    scrollHeight1:res.windowHeight-93,
                    scrollHeight2:res.windowHeight-200,
                    windowWidth:res.windowWidth,
                    margin:(res.windowWidth*0.92-228)/10,
                    searchWidth:res.windowWidth*0.84-35,
					topheight:util.cache('headerHeight')
                });
            }
        });
        wx.setNavigationBarTitle({
            title:'我的菜品' ,
        })
        this.setData({
          sellerid: util.cache("sellerid"),
        });
    },

    onShow:function(){
        var that=this;
        this.cookList();
        util.postSuccessFun=function(json,uri_code){
            switch(uri_code){
                case uri.CGI__USER_GETCOOKBOOKBYCLASS__CODE:            //获取所有分类下所有菜品列表(估清管理)
                    console.log(json.data[0]['list']);
                    if(json.ret==200){
                        var arr=json.data[0]['list'];
                        if(typeof arr!='string' && arr.length>0){
                            arr.forEach(function(v,i){
                                if(i==0){
                                    v.isactive=true;
                                }else{
                                    v.isactive=false;
                                }
                                if(typeof v.cookbooklist[0]!='string' && v.cookbooklist[0].length>0){
                                    v.cookbooklist[0].forEach(function(r,n){
                                        if(r.name.length>6){
                                            r.name=r.name.slice(0,6)+'...'
                                        }
                                        r.isactive=false;
                                        if(n%2==0){
                                            r.bg_color='bg-pink'
                                        }else{
                                            r.bg_color='bg-blue'
                                        }
                                    })
                                }
                            })
                            var thislist=[];
                            arr.forEach(function(v,i){
                                if(v.class_type!=1){
                                    if(typeof v.cookbooklist[0]!='string' && v.cookbooklist[0].length>0){
                                        thislist.push(v);
                                    }
                                }
                            })
                            arr=thislist;
                        }
                        var mtop=0;
                        if(arr.length>0){
                            arr[0].isactive=true;
                            mtop=Math.ceil(arr.length/3)*90+30
                        }
                        that.setData({
                            classlist:arr.length>0 ? arr : null,
                            cooklist:arr.length>0 ? arr[0] : null,
                            mtop:mtop
                        })
                    }
                break
                case uri.CGI__USER_SETCLEARCOOKBOOKBYID__CODE:          //设置商家菜品估清(估清管理)
                    console.log(json)
                    if(json.ret==200){
                        wx.navigateBack({
                            url: 'ck_list',
                        })
                    }
                break
                case uri.CGI__USER_SEARCHCOOKBOOK__CODE:
                    if(json.ret==200){
                        console.log(66666,json.data[0])
                        if(json.data[0].length>0){
                            json.data[0].forEach(function(v,i){
                                if(i%2==0){
                                    v.bg_color='bg-pink'
                                }else{
                                    v.bg_color='bg-blue'
                                }
                            })
                        }
                        that.setData({
                            newlist:json.data[0].length>0 ? json.data[0] : null
                        })
                    }

                break
            }
        }

    },
    getcooklist:function(e){
       var classid=e.detail;
       var classlist=this.data.classlist;
       var cooklist=[];
       classlist.forEach(function(v,i){
           if(v.id==classid){
               cooklist=v;
           }
       })
        this.setData({
            cooklist:cooklist
        })
    },
    selectcook:function(e){
       var cookid=e.detail.id;
       var cooklist=this.data.cooklist;
       var title='';
       var clear_num='';
       cooklist.cookbooklist[0].forEach(function (v,i) {
           if(v.id==cookid){
               title=v.name;
               clear_num=v.clear_num ? v.clear_num : null
           }
       })
        this.setData({
            auto_focus:true,
            atn_ishidden:false,
            title:title,
            cookbookid:cookid,
            clear_num:clear_num
        })
    },

    cookList:function(){
        util.post(uri.CGI__USER_GETCOOKBOOKBYCLASS,{sellerid:this.data.sellerid},uri.CGI__USER_GETCOOKBOOKBYCLASS__CODE)
    },
    searchsubmit:function(e){
        console.log(e.detail.value)
        this.setData({
            inputKey:e.detail.value
        })
        util.post(uri.CGI__USER_SEARCHCOOKBOOK,{sellerid:this.data.sellerid,name:e.detail.value},uri.CGI__USER_SEARCHCOOKBOOK__CODE)
    },
    //对无规格菜品的点击事件,有弹出框
    onlyClear:function(e){
        console.log(e);
        this.setData({
            auto_focus:true,
            atn_ishidden:false,
            title:e.currentTarget.dataset.name,
            cookbookid:e.currentTarget.dataset.id,
            clear_num:e.currentTarget.dataset.num
        })
        console.log('无规格:',this.data.cookbookid)
    },

    //对无规格菜品的弹出框取消
    onlyCancelModel:function(){
        this.setData({
            atn_ishidden:true,
        })
    },
    //对无规格菜品的弹出框确认
    onlyConfirmModel:function(e){
        util.post(uri.CGI__USER_SETCLEARCOOKBOOKBYID,{cookbookid:this.data.cookbookid,clear_num:this.data.clear_num},uri.CGI__USER_SETCLEARCOOKBOOKBYID__CODE)
    },

    //获取无规格菜品输入框数据
    onlyModalInput:function(e){
        console.log(e);
        this.setData({
            clear_num:e.detail.value
        })
    },
    netchange:function(){
        this.onShow();
    }
})