examine.js 3.93 KB
//商家管理
'use strict';
var $ = require('jquery'),
    Handlebars = require('yoho.handlebars');

var dropDown=require('../common/dropDown');
require('../util/jquery.gritter');
var grid=require('../common/grid');

exports.init=function(){
	new dropDown({el:"#status"});
	new dropDown({el:"#brand-name",ajax:"brand"});
	new dropDown({el:"#supplier-name",ajax:"supplier"});
    $('#filter-btn').on('click',function(){
        g.reload();
    });
	var g=new grid({
		el:'#storeadmin_Tabel',        
        parms:function(){
            var supplierid=!!~$.trim($('#supplier-name').val())?$('#supplier-name').val():"0",
                brandId = !!~$.trim($('#brand-name').val())?$('#brand-name').val():"0",
                checkStatus = !!~$.trim($('#status').val())?$('#status').val():"0";
            return {
                "supplierId":supplierid,
                "brandId":brandId,
                "operationStatus":2,
                "checkStatus":checkStatus,
                "checkStatusArr":"300,200,900"
            };
        },
		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:"status"},
            {display:"操作",name:"",render:function(item){
            	var pushAll =[]
                pushAll.push('<a href="/supplier/store/info/'+item.shopsId+'" class="btn btn-info btn-xs">查看</a>');
                pushAll.push('<a href="/supplier/store/update/'+item.shopsId+'" class="btn btn-success btn-xs">编辑</a>');
                pushAll.push('<input type="hidden" value="'+item.status+'" />');
                if(item.status == 0){
                    pushAll.push('<button data-status="'+item.status+'" data-shopsid="'+item.shopsId+'" class="shopsstatus btn btn-warning btn-xs">开店</button>');                   
                }else{
                    pushAll.push('<button data-status="'+item.status+'" data-shopsid="'+item.shopsId+'" class="shopsstatus btn btn-danger btn-xs">关店</button>');                   
                }
                return pushAll.join('');
            }}
        ]
	})
	console.log($('#url').val());
    g.init($('#url').val());

        function __ajax(options,callback){
        $.ajax({
            type: 'POST',
            url: options.url,
            dataType: 'json',
            data:options.data||{},
            success: function(res) {
                res=res.data;
                if (res.code === 200) {
                    $.gritter.add({
                        title: options.msg||"提交成功",
                        class_name: 'growl-success',
                        sticky: false,
                        time: '1000',
                        after_open: function() {
                            callback&&callback();
                        }
                     });
                } else {
                    $.gritter.add({
                        title: '提交失败',
                        class_name: 'growl-danger',
                        sticky: false,
                        time: '1000'
                     });
                }
            }
        });
    }

    //提交操作
    $(document).on('click', '.shopsstatus', function() {
        var that = this,
            url;

        if($(that).data('status')==1){
            url = "/supplier/store/closeShops";
        }else{
            url = "/supplier/store/openShops";
        }
        __ajax({
            url: url,
            data:{shopsId:$(that).data("shopsid")}
        },function(){
            g.reload();
        });
    });
}