shop.Administrator.js 5.97 KB
webpackJsonp([167],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	//商家管理
	'use strict';
	var $ = __webpack_require__(1),
	    common=__webpack_require__(2);

	    // 筛选项
	    new common.dropDown({el:"#shop-name",ajax:"shopsRest"});
	    selectAllManagerInfo();

		var g=new common.grid({
			el:'#basicTable',
	        parms: function() {
	            return {
	                'shopsId': common.util.__input('shop-name'),
	                'adminPid': common.util.__input('admin-name')
	            }
	        },
			columns:[
	            {display:"ID",name:"id"},
	            {display:"店铺名称",name:"shopName"},
	            {display:"店铺管理员",name:"adminName"},
	            {display:"部门",name:"deptName"},
	            {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");
	                        }
	                        var content = item.truename;
	                        if(item.deptName) {
	                            content += '(' + item.deptName +')';
	                        }
	                        $option.html(content);
	                        $("#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);
	    });


	function selectAllManagerInfo() {
	    common.util.__ajax({
	        url: '/supplier/storeadmin/adminList'
	    }, function(res) {
	        $('#admin-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);
	                var content = item.truename;
	                // 将"真实姓名"为空的数据排除
	                if(content === undefined || content.length === 0) {
	                    return;
	                }

	                if(item.deptName) {
	                    content += '(' + item.deptName +')';
	                }
	                $option.html(content);
	                $("#admin-name").append($option);
	            })
	        };
	        new common.dropDown({el:"#admin-name"});
	    }, true);
	}

	$(document).on('click', '#filter-btn', function() {
	    g.reload(1);
	});




/***/ }
]);