s_index.js 6.36 KB
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
var mta= require('../../utils/mta_analysis.js')
import App from '../../utils/api.js'
Page({
    data: {
      hasTips:false,
        showhide:true,
        alllist:[
            {
                name:'菜品管理',
                hide:true,
                list:[
                    {
                        id:1,
                        name:'我的菜品',
                        icon:'../image/my-food.png',
                        url:'../cookbook/cb_alllist'
                    },
                    {
                        id:2,
                        name:'沽清设置',
                        icon:'../image/estimate-food.png',
                        url:'../cookclear/cc_list'
                    },
                    {
                        id:5,
                        name:'计价单位管理',
                        icon:'../image/unit.png',
                        url:'../cookbook/cb_unit'
                    },
                ]

            },
        ],
        totalfunction:[
            {
                imgurl:'../image/manage-active.png',
                title:'经营中心',
                isActive:false,
            },
            {
                imgurl:'../image/store-active.png',
                title:'门店管理',
                isActive:true
            }
        ],
        coderight:20,
        codebottom:140
    },
  onReady(){
  },
    onLoad:function(opt){
        // mta.Page.init()
        console.log(opt)
		this.setData({
			hasTips:util.cache('hasTips')?false:true
		})
        //有缓存----登录
        if(util.cache("openid")){
            var openid=util.cache("openid");
            this.setData({
                openid:openid
            })
            //通用设置选择店铺进入/成为店员首次进入
            if(opt.sellerid){
                util.cache('sellerid',opt.sellerid);
                this.setData({
                    sellerid:opt.sellerid,
                })
                //获取商家信息
				this.getsellerinfo();
				this.getsellerlist();

            }else if(util.cache("sellerid")){
                //注册店铺后再进入
                this.setData({
                    sellerid:util.cache("sellerid"),
                })
				this.getsellerinfo();
				this.getsellerlist();
            }else{
				this.getsellerlist();
            }
        }else{
			console.log('rrrrrr')
            this.getopenid();
        }
        if(util.cache('openid') && this.data.sellerid){
            this.setData({
                showhide:false,
            })
        }
    },
	getopenid(){
		wx.login({
		    //获取code
		    success: (login_res)=>{
		        console.log('cc',login_res.code)
		        var data = {
		            code: login_res.code,
		            appid: 'wx418f1d7cdeda26c1',
		        }
		        //获取openid
				App.Wechat.GetSellerOpenidByCode(data).then((json)=>{
					var openid = JSON.parse(json.data[0]).openid;//返回openid
					this.setData({
					    openid:openid
					})
					util.cache('openid',openid);
					this.getsellerlist();
				})
		
		    },
			fail:(res)=>{
		        console.log('dddddd',res)
		    }
		})
	},
	getsellerinfo(){
		App.Seller.GetSellerById({sellerid:this.data.sellerid,openid:this.data.openid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				this.setData({
					auth:json.data.auth,
					seller:json.data.seller,
				})
				util.cache('role_name',json.data.auth.role_name);
				util.cache('sellername',json.data.seller.sellername);
				if(json.data.auth.is_first==1){
					console.log('hahaha',json.data.auth.is_first);
					util.cache('identity',json.data.auth.is_first);
				}else{
					util.cache('identity')
				}
				
			}
			
		})
	},
	getsellerlist(){
		App.Seller.GetSystemByOpenid({openid:this.data.openid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				if(json.data.auth==0){
					// wx.navigateTo({
					// 	url:'../login/l_login'
					// })
				}else{
					if(json.data.length==1){
						this.setData({
							auth:json.data[0].auth,
							seller:json.data[0].seller,
						})
						util.cache('sellerid',json.data[0].seller.id);
						util.cache('sellername',json.data[0].seller.sellername);
						util.cache('role_name',json.data[0].auth.role_name);
						if(json.data[0].auth.is_first==1){
							util.cache('identity',json.data[0].auth.is_first);
						}else{
							util.cache('identity')
						}
					}else{
						if(util.cache("sellerid")){
							this.setData({
								sellerlist:json.data
							})
						}else{
							wx.reLaunch({
								url:'../currency/c_store'
							})
						}
						
					}
				}
				
			}
		})
	},
    onShow:function(){
       
    },
    //列表收起/展开
    setting:function(e){
	   if(this.data.sellerid){
		   var index=e.currentTarget.dataset.id;
		   var list=this.data.alllist;
		   if(list[index].list){
		   		 list.forEach(function(v,i){
		   		     if(index==i){
		   		         v.hide=!v.hide
		   		     }
		   		 })
		   		 this.setData({
		   		   alllist:list
		   		 })  
		   }
	   }
       
       
    },
    //扫描二维码
    takeCode:function(e){
        console.log(e)
        util.linkTo('s_loading',this.data.sellerid,'')
    },
    sellerreport:function () {
        wx.redirectTo({
            url:'t_index?sellerid='+this.data.seller.id+'&sellername='+this.data.seller.sellername
        })
    },
    //运营切换
    manageseller:function(){
        wx.navigateTo({
            url:'../currency/c_store'
        })
    },
   
    //退出
    exit:function(){
        wx.removeStorage({key:'sellerid'})
        wx.removeStorage({key:'idenity'})
        wx.reLaunch({
            url:'../login/l_login'
        })
    },
    //交接店铺
    handoverseller:function(){
        wx.navigateTo({
            url:'../store/s_handover'
        })
    },
    netchange:function(e){
        this.onShow();
    },
    //修改授权页---2019-09-10
    togetpromise:function(){
        wx.navigateTo({
            url:'../login/promise'
        })
    },
  closeTip(){
    this.setData({
      hasTips:false,
    })
    util.cache('hasTips','close');
  },
  onShareAppMessage(){
  	return {
  		title:'"'+this.data.seller.sellername+'"店铺邀请您点餐',
  		path:'pages/custom/enter/enter?id='+this.data.seller.id+'&share='+true,
  		imageUrl:this.data.seller.seller_image ? this.data.seller.seller_image : ''
  	}
  },
});