index.js 4.41 KB
//商家管理
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var ENUM={//    审核状态;100 暂存 200 待审核 300 审核通过 900 驳回
    status:{100:'暂存',200:'审核中',300:'通过',900:'驳回'}
}


	new common.dropDown({el:"#status"});
	new common.dropDown({el:"#store-type"});
	new common.dropDown({el:"#store-model"});
	new common.dropDown({el:"#brand-name",ajax:"brand"});
	new common.dropDown({el:"#supplier-name",ajax:"supplier"});

    var authority=JSON.parse($("#authority").val());

    $('#filter-btn').on('click',function(){
        g.reload();
    });
    $("#all-btn").click(function(){
        $("#status").val("-1").trigger("change");;
        $("#supplier-name").val("-1").trigger("change");;
        $("#supplier-name").val("-1").trigger("change");;
        g.reload();
    });
	var g=new common.grid({
		el:'#basicTable',        
        parms:function(){
            return {
                "supplierId":common.util.__input("supplier-name"),
                "brandId":common.util.__input("brand-name"),
                "checkStatus":common.util.__input("status"),
                "operationStatus":authority.operationStatus,
                "checkStatusArr":authority.checkStatusArr
            };
        },
		columns:[
            {display:"店铺ID",name:"shopsId"},
            {display:"店铺名称",name:"shopName"},
            {display:"包含品牌",name:"shopRelationList",render:function(item){
                var str='';
                $.each(item.shopRelationList,function (index,a) {
                        str+='<p>'+a.brandName+'</p>';
                })
                    return str;
            }},
            {display:"创建时间",name:"createTime"},
            {display:"更新时间",name:"updateTime"},
            {display:"状态",name:"checkStatus",render:function(item){
                return ENUM.status[item.checkStatus];
            }},
            {display:"操作",name:"",render:function(item){
                var HtmArr=[];
                if(authority.info){
                    HtmArr.push('<a href="/supplier/store/infocmd/'+item.shopsId+'" href="javascript:void(0);" class="btn btn-info btn-xs">查看</a>');
                }else{
                    HtmArr.push('<a href="/supplier/store/info/'+item.shopsId+'" href="javascript:void(0);" class="btn btn-info btn-xs">查看</a>');
                }
                //创建
                if(authority.create){
                    if(+item.checkStatus==100||+item.checkStatus==900){
                        HtmArr.push('<a href="/supplier/store/update/'+item.shopsId+'" href="javascript:void(0);" class="btn btn-success btn-xs">编辑</a>');
                    }
                }
                
                if(authority.btn){
                    if(+item.checkStatus!=200){
                        HtmArr.push('<a href="/supplier/store/update/'+item.shopsId+'" href="javascript:void(0);" class="btn btn-success btn-xs">编辑</a>');
                    }
                    if(+item.checkStatus!=900){
                        if(+item.status){
                            // 1开启 0 关闭
                            HtmArr.push('<a data-index="'+item.__index+'" href="javascript:void(0);" class="openshops btn btn-success btn-xs">开店</a>');
                        }else{
                            HtmArr.push('<a data-index="'+item.__index+'" href="javascript:void(0);" class="closeshops btn btn-danger btn-xs">关店</a>');
                        }
                    }
                }
                return HtmArr.join('');
            }}
        ]
	})
    g.init($('#url').val());

    var Bll={
        toast:function(content,url,id){
            common.dialog.confirm("温馨提示",content,function(){
                common.util.__ajax({
                    url:url,
                    data:{shopsId:id}
                },function(){
                    g.reload();
                });
            });
        }
    }
    //关闭店铺
     $('#basicTable').on('click', '.closeshops', function() {
        var item=g.rows[$(this).data("index")];
        Bll.toast("确定要关闭此店铺吗?","/supplier/store/closeShops",item.shopsId);
     });
     //开启店铺
     $('#basicTable').on('click', '.openshops', function() {
        var item=g.rows[$(this).data("index")];
        Bll.toast("确定要关闭此店铺吗?","/supplier/store/openShops",item.shopsId);
     });
    //shopsstatus