提交 | 用户 | 时间
|
71e81e
|
1 |
layui.use(['table', 'admin', 'ax', 'func'], function () { |
懒 |
2 |
var $ = layui.$; |
|
3 |
var table = layui.table; |
|
4 |
var $ax = layui.ax; |
|
5 |
var admin = layui.admin; |
|
6 |
var func = layui.func; |
|
7 |
var form = layui.form; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* 产品序列号配置管理 |
|
12 |
*/ |
|
13 |
var SerialNumbersConf = { |
|
14 |
tableId: "serialNumbersConfTable" |
|
15 |
}; |
|
16 |
|
|
17 |
/** |
|
18 |
* 初始化表格的列 |
|
19 |
*/ |
|
20 |
SerialNumbersConf.initColumn = function () { |
|
21 |
return [[ |
|
22 |
{type: 'checkbox'}, |
|
23 |
{field: 'id', hide: true, title: '主键id'}, |
|
24 |
{field: 'years', sort: true, title: '年份'}, |
|
25 |
{field: 'serialNumber', sort: true, title: '序列号'}, |
|
26 |
{field: 'lengths', sort: true, title: '长度'}, |
|
27 |
// {field: 'state', sort: true, title: '状态(启用、禁用)'}, |
|
28 |
{field: 'state', sort: true, templet: '#stateTpl', title: '状态'}, |
|
29 |
{field: 'createTime', sort: true, title: '创建时间',minWidth:160}, |
|
30 |
{field: 'createUser', sort: true, title: '创建用户'}, |
|
31 |
{field: 'updateTime', sort: true, title: '更改时间',minWidth:160}, |
|
32 |
{field: 'updateUser', sort: true, title: '更改用户'}, |
|
33 |
{align: 'center', toolbar: '#tableBar', title: '操作'} |
|
34 |
]]; |
|
35 |
}; |
|
36 |
|
|
37 |
form.on('switch(status)', function (obj) { |
|
38 |
var id = obj.elem.value; |
|
39 |
var checked = obj.elem.checked ? 1 : 0; |
|
40 |
SerialNumbersConf.changeStatus(id, checked); |
|
41 |
}); |
|
42 |
|
|
43 |
// 修改状态方法 |
|
44 |
SerialNumbersConf.changeStatus = function (id, checked) { |
|
45 |
var ajax = new $ax(Feng.ctxPath + "/serialNumbersConf/editItem", function (data) { |
|
46 |
Feng.success("修改成功!"); |
|
47 |
}, function (data) { |
|
48 |
Feng.error("修改失败!" + data.message); |
|
49 |
}); |
|
50 |
ajax.set("id", id); |
|
51 |
ajax.set("state", checked); |
|
52 |
ajax.start(); |
|
53 |
}; |
|
54 |
|
|
55 |
/** |
|
56 |
* 点击查询按钮 |
|
57 |
*/ |
|
58 |
SerialNumbersConf.search = function () { |
|
59 |
var queryData = {}; |
|
60 |
queryData['years'] = $("#years").val(); |
|
61 |
queryData['serialNumber'] = $("#serialNumber").val(); |
|
62 |
queryData['lengths'] = $("#lengths").val(); |
|
63 |
// queryData['state'] = $("#state").val(); |
|
64 |
|
|
65 |
table.reload(SerialNumbersConf.tableId, { |
|
66 |
where: queryData, page: {curr: 1} |
|
67 |
}); |
|
68 |
}; |
|
69 |
|
|
70 |
/** |
|
71 |
* 跳转到添加页面 |
|
72 |
*/ |
|
73 |
SerialNumbersConf.jumpAddPage = function () { |
|
74 |
window.location.href = Feng.ctxPath + '/serialNumbersConf/add' |
|
75 |
}; |
|
76 |
|
|
77 |
/** |
|
78 |
* 跳转到编辑页面 |
|
79 |
* |
|
80 |
* @param data 点击按钮时候的行数据 |
|
81 |
*/ |
|
82 |
SerialNumbersConf.jumpEditPage = function (data) { |
|
83 |
window.location.href = Feng.ctxPath + '/serialNumbersConf/edit?id=' + data.id |
|
84 |
}; |
|
85 |
|
|
86 |
/** |
|
87 |
* 导出excel按钮 |
|
88 |
*/ |
|
89 |
SerialNumbersConf.exportExcel = function () { |
|
90 |
var checkRows = table.checkStatus(SerialNumbersConf.tableId); |
|
91 |
if (checkRows.data.length === 0) { |
|
92 |
Feng.error("请选择要导出的数据"); |
|
93 |
} else { |
|
94 |
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); |
|
95 |
} |
|
96 |
}; |
|
97 |
|
|
98 |
/** |
|
99 |
* 点击删除 |
|
100 |
* |
|
101 |
* @param data 点击按钮时候的行数据 |
|
102 |
*/ |
|
103 |
SerialNumbersConf.onDeleteItem = function (data) { |
|
104 |
var operation = function () { |
|
105 |
var ajax = new $ax(Feng.ctxPath + "/serialNumbersConf/delete", function (data) { |
|
106 |
Feng.success("删除成功!"); |
|
107 |
table.reload(SerialNumbersConf.tableId); |
|
108 |
}, function (data) { |
|
109 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
110 |
}); |
|
111 |
ajax.set("id", data.id); |
|
112 |
ajax.start(); |
|
113 |
}; |
|
114 |
Feng.confirm("是否删除?", operation); |
|
115 |
}; |
|
116 |
|
|
117 |
// 渲染表格 |
|
118 |
var tableResult = table.render({ |
|
119 |
elem: '#' + SerialNumbersConf.tableId, |
|
120 |
url: Feng.ctxPath + '/serialNumbersConf/list', |
|
121 |
page: true, |
|
122 |
height: "full-158", |
|
123 |
cellMinWidth: 100, |
|
124 |
cols: SerialNumbersConf.initColumn() |
|
125 |
}); |
|
126 |
|
|
127 |
// 搜索按钮点击事件 |
|
128 |
$('#btnSearch').click(function () { |
|
129 |
SerialNumbersConf.search(); |
|
130 |
}); |
|
131 |
|
|
132 |
// 添加按钮点击事件 |
|
133 |
$('#btnAdd').click(function () { |
|
134 |
|
|
135 |
SerialNumbersConf.jumpAddPage(); |
|
136 |
|
|
137 |
}); |
|
138 |
|
|
139 |
// 导出excel |
|
140 |
$('#btnExp').click(function () { |
|
141 |
SerialNumbersConf.exportExcel(); |
|
142 |
}); |
|
143 |
|
|
144 |
// 工具条点击事件 |
|
145 |
table.on('tool(' + SerialNumbersConf.tableId + ')', function (obj) { |
|
146 |
var data = obj.data; |
|
147 |
var layEvent = obj.event; |
|
148 |
|
|
149 |
if (layEvent === 'edit') { |
|
150 |
SerialNumbersConf.jumpEditPage(data); |
|
151 |
} else if (layEvent === 'delete') { |
|
152 |
SerialNumbersConf.onDeleteItem(data); |
|
153 |
} |
|
154 |
}); |
|
155 |
}); |