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

	var g=new common.grid({
		el:'#basicTable',
		columns:[
            {display:"ID",name:"id"},
            {display:"店铺名称",name:"shopName"},
            {display:"店铺管理员",name:"adminName"},
            {display:"创建时间",name:"createTime"},
            {display:"更新时间",name:"updateTime"},
            {display:"操作",name:"",render:function(item){
            	var HtmArr=[];
                HtmArr.push('<a href="javascript:void(0);" data-index="'+item.__index+'" class="edit btn btn-info btn-xs">编辑</a>');
                HtmArr.push('<a href="javascript:void(0);" data-index="'+item.__index+'" class="delete btn btn-danger btn-xs">删除</button>');
                return HtmArr.join('');
            }}
        ]
	})
    g.init('/supplier/storeadmin/indexPage');

    var Bll={
        toast:function(content,id){
            common.dialog.confirm("温馨提示",content,function(){
                common.util.__ajax({
                    url:'/supplier/storeadmin/delete',
                    data:{id:id}
                },function(){
                    g.reload();
                });
            });
        },
        selectManagerName:function(id,eqid){
            if(!~id){
                return false;
            }
            common.util.__ajax({
                url:'/supplier/storeadmin/managerName',
                data:{
                    identity:id,//$('#identity-type option:selected').val()
                    shopsId:$('#store-name option:selected').val()
                }
            },function(res){
                $('#manager-name').html('<option value="">请选择管理员</option>');
                if(res.data&&res.data.length>0){
                    $.each(res.data,function(index,item){
                        var $option=$("<option></option>");
                        $option.attr("value",item.pid);
                        if(+item.pid==eqid){
                            $option.attr("selected","selected");
                        }
                        $option.html(item.truename);
                        $("#manager-name").append($option);
                    })
                };
                new common.dropDown({el:"#manager-name"});
                
            },true);
        },
        dialog:function(title,url,item){
            common.dialog.confirm("创建店铺管理员关系",$("#template").html(),function(){
            var data=function(){
                var sn=$('#store-name').val();
                var obj={
                    id:item.id,
                    shopsId:sn?sn:item.shopsId,
                    identity: $('#identity-type').val(),
                    adminPid:$('#manager-name').val()
                };
                console.log(obj);
                for(var key in obj){
                    if(+obj[key]==-1){
                        return "请选择完所有的必填项!";
                    }
                }
                return obj;
            }
           return common.util.__ajax({
                url:url,
                async:true,
                data:data()
            },function(){
                g.reload();
            });
        });
        new common.dropDown({el:"#store-name",ajax:"shopsRest"});
        new common.dropDown({el:"#manager-name"});
        //
        $('#identity-type').on('change',function(){
           Bll.selectManagerName($(this).val());
        });
        }
    }
    $('#basicTable').on('click', '.delete', function() {
        var item=g.rows[$(this).data("index")];
        Bll.toast("你确定要删除吗?",item.id);
     });
    
    $(document).on('click', '.add', function() {
        Bll.dialog("创建店铺管理员关系",'/supplier/storeadmin/addguanxi',{});
    });

    $('#basicTable').on('click', '.edit', function() {
        var item=g.rows[$(this).data("index")];
        Bll.dialog("修改店铺管理员关系",'/supplier/storeadmin/updateguanxi',item);
        //赋值
        $("#store-name").val(item.shopsId);
        $("#select2-store-name-container").text(item.shopName);
        $('#identity-type').val(item.identity);
        
        Bll.selectManagerName($('#identity-type option:selected').val(),item.adminPid);
    });