adminindex.js
4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//商家管理
'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($('#url').val());
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);
});