提交 | 用户 | 时间
|
1ac2bc
|
1 |
layui.use(['table', 'admin', 'ax'], function () { |
懒 |
2 |
var $ = layui.$; |
|
3 |
var table = layui.table; |
|
4 |
var $ax = layui.ax; |
|
5 |
var admin = layui.admin; |
|
6 |
|
|
7 |
/** |
|
8 |
* Guns复杂表单的示例管理 |
|
9 |
*/ |
|
10 |
var EgForm = { |
|
11 |
tableId: "egFormTable" |
|
12 |
}; |
|
13 |
|
|
14 |
/** |
|
15 |
* 初始化表格的列 |
|
16 |
*/ |
|
17 |
EgForm.initColumn = function () { |
|
18 |
return [[ |
|
19 |
{type: 'checkbox'}, |
|
20 |
{field: 'formId', align: "center", hide: true, title: '主键id'}, |
|
21 |
{field: 'name', align: "center", sort: true, title: '名称'}, |
|
22 |
{field: 'singleTime', align: "center", sort: true, title: '单个时间', minWidth: 160}, |
|
23 |
{field: 'betweenTime', align: "center", sort: true, title: '时间段', minWidth: 187}, |
|
24 |
{field: 'simpleSelect', align: "center", sort: true, title: '单行选择'}, |
|
25 |
{field: 'fenzuSelect', align: "center", sort: true, title: '分组选择', minWidth: 104}, |
|
26 |
{field: 'modules', align: "center", sort: true, title: '搜索选择'}, |
|
27 |
{field: 'multiSelectHidden', align: "center", sort: true, title: '多个选择', minWidth: 143}, |
|
28 |
{ |
|
29 |
align: 'center', templet: function (d) { |
|
30 |
// var url = d.imgUrl; |
|
31 |
var url = 'https://pic.qqtn.com/up/2018-9/15367146917869444.jpg'; |
|
32 |
return '<img src="' + url + '" class="tdImg" />'; |
|
33 |
}, title: '缩略图', width: 90, unresize: true |
|
34 |
}, |
|
35 |
{field: 'fileInputHidden', align: "center", sort: true, title: '文件id'}, |
|
36 |
{field: 'closeFlag', align: "center", sort: true, title: '开关标识'}, |
|
37 |
{field: 'sex', align: "center", sort: true, title: '单选'}, |
|
38 |
{field: 'checkbox', align: "center", sort: true, title: '复选框'}, |
|
39 |
{field: 'number', align: "center", sort: true, title: '数字'}, |
|
40 |
{field: 'longText', align: "center", sort: true, title: '长字段'}, |
|
41 |
{align: 'center', toolbar: '#tableBar', title: '操作'} |
|
42 |
]]; |
|
43 |
}; |
|
44 |
|
|
45 |
/** |
|
46 |
* 点击查询按钮 |
|
47 |
*/ |
|
48 |
EgForm.search = function () { |
|
49 |
var queryData = {}; |
|
50 |
queryData['condition'] = $("#condition").val(); |
|
51 |
table.reload(EgForm.tableId, { |
|
52 |
where: queryData, page: {curr: 1} |
|
53 |
}); |
|
54 |
}; |
|
55 |
|
|
56 |
/** |
|
57 |
* 弹出添加对话框 |
|
58 |
*/ |
|
59 |
EgForm.openAddDlg = function () { |
|
60 |
admin.putTempData('formOk', false); |
|
61 |
top.layui.admin.open({ |
|
62 |
type: 2, |
|
63 |
title: '添加Guns复杂表单的示例', |
|
64 |
content: Feng.ctxPath + '/egForm/add', |
|
65 |
end: function () { |
|
66 |
admin.getTempData('formOk') && table.reload(EgForm.tableId); |
|
67 |
} |
|
68 |
}); |
|
69 |
}; |
|
70 |
|
|
71 |
/** |
|
72 |
* 导出excel按钮 |
|
73 |
*/ |
|
74 |
EgForm.exportExcel = function () { |
|
75 |
var checkRows = table.checkStatus(EgForm.tableId); |
|
76 |
if (checkRows.data.length === 0) { |
|
77 |
Feng.error("请选择要导出的数据"); |
|
78 |
} else { |
|
79 |
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); |
|
80 |
} |
|
81 |
}; |
|
82 |
|
|
83 |
/** |
|
84 |
* 点击删除 |
|
85 |
* |
|
86 |
* @param data 点击按钮时候的行数据 |
|
87 |
*/ |
|
88 |
EgForm.onDeleteItem = function (data) { |
|
89 |
var operation = function () { |
|
90 |
var ajax = new $ax(Feng.ctxPath + "/egForm/delete", function (data) { |
|
91 |
Feng.success("删除成功!"); |
|
92 |
table.reload(EgForm.tableId); |
|
93 |
}, function (data) { |
|
94 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
95 |
}); |
|
96 |
ajax.set("formId", data.formId); |
|
97 |
ajax.start(); |
|
98 |
}; |
|
99 |
Feng.confirm("是否删除?", operation); |
|
100 |
}; |
|
101 |
|
|
102 |
// 渲染表格 |
|
103 |
var tableResult = table.render({ |
|
104 |
elem: '#' + EgForm.tableId, |
|
105 |
url: Feng.ctxPath + '/egForm/list', |
|
106 |
page: true, |
|
107 |
height: "full-98", |
|
108 |
cellMinWidth: 100, |
|
109 |
cols: EgForm.initColumn() |
|
110 |
}); |
|
111 |
|
|
112 |
// 搜索按钮点击事件 |
|
113 |
$('#btnSearch').click(function () { |
|
114 |
EgForm.search(); |
|
115 |
}); |
|
116 |
|
|
117 |
// 添加按钮点击事件 |
|
118 |
$('#btnAdd').click(function () { |
|
119 |
window.location.href = Feng.ctxPath + "/egForm/add"; |
|
120 |
}); |
|
121 |
|
|
122 |
// 导出excel |
|
123 |
$('#btnExp').click(function () { |
|
124 |
EgForm.exportExcel(); |
|
125 |
}); |
|
126 |
|
|
127 |
// 工具条点击事件 |
|
128 |
table.on('tool(' + EgForm.tableId + ')', function (obj) { |
|
129 |
var data = obj.data; |
|
130 |
var layEvent = obj.event; |
|
131 |
|
|
132 |
if (layEvent === 'delete') { |
|
133 |
EgForm.onDeleteItem(data); |
|
134 |
} |
|
135 |
}); |
|
136 |
}); |