index.js
6.53 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* 创建供应商
*/
'use strict';
var $ = require('jquery'),
dropDown=require('../common/dropDown');
require('../util/jquery.gritter');
/*
* status数字转换文字
* @param: status(type: String, 传入的status数值)
*/
function statusCovert(status) {
switch (status) {
case 100:
return '暂存';
break;
case 200:
return '审核中';
break;
case 300:
return '通过';
break;
case 900:
return '驳回';
break;
}
}
function isFreezeCovert(status){
switch (status) {
case 'Y':
return '已冻结';
break;
default:
return '生效中';
break;
}
}
function operationsCovert(status){
switch (status) {
case 1:
return '创建';
break;
case 2:
return '编辑';
break;
case 3:
return '冻结';
break;
case 4:
return '解冻';
break;
}
}
var grid=require('../common/grid');
exports.init = function() {
new dropDown({
el:'#supplier-name',
ajax:'supplier'
});
new dropDown({el:"#status"});
new dropDown({el:"#time-sort"});
new dropDown({el:"#isFreeze"});
var btnAuthority=JSON.parse($("#btnAuthority").val());
var g=new grid({
el:"#basicTable",
parms:function(){
return {
id:!!~$.trim($('#supplier-name').val())?$('#supplier-name').val():"",
status:!!~$.trim($('#status').val())?$('#status').val():"",
timeSort:!!~$.trim($('#time-sort').val())?$('#time-sort').val():"",
isFreeze:!!~$.trim($('#isFreeze').val())?$('#isFreeze').val():""
};
},
columns:[
{display:"供应商",name:"supplierName"},
{display:"更新时间",name:"foundTime"},
{display:"最近操作",name:"operations",hidden:btnAuthority.columnsHidOper,render:function(item){
return operationsCovert(item.operations);
}},
{display:"状态",name:"status",render:function(item){
return statusCovert(item.status);
}},
{display:"是否生效",name:"isFreeze",hidden:btnAuthority.columnsHidisFr,render:function(item){
return isFreezeCovert(item.isFreeze);
}},
{display:"操作",name:"id",render:function(items){
var HtmArr=[];
// 是否冻结 Y-是,N-否
// 状态 100-暂存,200-审核中,300-通过,900-驳回
// 最近操作 1-创建,2-编辑, 3-冻结, 4-解冻
if(btnAuthority.edit){
HtmArr.push('<a href="/supplier/infoopt/'+ items.id+'" class="btn btn-info btn-xs">查看</a>');
}else{
HtmArr.push('<a href="/supplier/info/'+ items.id+'" class="btn btn-info btn-xs">查看</a>');
}
if(items.status!="200"){
HtmArr.push('<a href="/supplier/update/'+ items.id+'" class="btn btn-success btn-xs btn-edit">编辑</a>');
}
//暂存时,有提交
if(items.status=="100"){
HtmArr.push('<a href="JavaScript:;" mid='+items.id+' moperations='+items.operations+' class="btn btn-primary btn-xs btn-submit">提交</a>');
}
if(btnAuthority.resetlock&&items.isFreeze=="Y"&&items.status=="300"){
HtmArr.push('<a href="javascript:;" mid='+items.id+' class="btn btn-warning btn-xs btn-recovery">恢复</a>');
}
if(btnAuthority.resetlock&&items.isFreeze=="N"&&items.status=="300"){
HtmArr.push('<a href="javascript:;" mid='+items.id+' class="btn btn-danger btn-xs btn-freeze">冻结</a>');
}
return HtmArr.join('');
}}
]
})
g.init($("#gridurl").val());
$("#filter-btn").click(function(){
g.reload();
});
$("#all-btn").click(function(){
$('#supplier-name').val("-1").trigger("change");
$('#status').val("-1").trigger("change");
$('#time-sort').val("-1").trigger("change");
$('#isFreeze').val("-1").trigger("change");
g.reload();
});
//提交操作
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', '.btn-submit', function() {
var that = this;
__ajax({
url:'/supplier/index/status',
data:{id:$(that).attr("mid"),status:"200",operations:$(that).attr("moperations")},
msg:'提交成功'
},function(){
g.reload();
});
});
//冻结操作
$(document).on('click', '.btn-freeze', function() {
var that = this;
__ajax({
url:'/supplier/index/status',
data:{id:$(that).attr("mid"),isFreeze:"Y",operations:"3"},
msg:'提交成功'
},function(){
g.reload();
});
});
//解冻操作
$(document).on('click', '.btn-recovery', function() {
var that = this;
__ajax({
url:'/supplier/index/status',
data:{id:$(that).attr("mid"),isFreeze:"N",operations:"4"},
msg:'提交成功'
},function(){
g.reload();
});
});
}