ColFields_Admin.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/ColFields/Import?r=" + Math.random(1),
  6. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  7. dataType: "text",
  8. success: function (data) {
  9. if (data == "success") {
  10. layer.msg("导入成功", { time: 2000 }, function () {
  11. window.location.reload();
  12. });
  13. } else {
  14. layer.msg(data);
  15. }
  16. }
  17. });
  18. }
  19. layui.config({
  20. base: '/layuiadmin/' //静态资源所在路径
  21. }).extend({
  22. myexcel: 'layui/lay/modules/excel',
  23. index: 'lib/index' //主入口模块
  24. }).use(['index', 'table', 'excel', 'laydate'], function () {
  25. var $ = layui.$
  26. , form = layui.form
  27. , table = layui.table;
  28. //- 筛选条件-日期
  29. var laydate = layui.laydate;
  30. //excel导入
  31. var excel = layui.excel;
  32. $('#ExcelFile').change(function (e) {
  33. var files = e.target.files;
  34. excel.importExcel(files, {}, function (data) {
  35. ExcelData = data[0].Sheet1;
  36. });
  37. });
  38. //监听单元格编辑
  39. table.on('edit(table1)', function (obj) {
  40. var value = obj.value //得到修改后的值
  41. , data = obj.data //得到所在行所有键值
  42. , field = obj.field; //得到字段
  43. if (field == "Sort") {
  44. $.ajax({
  45. type: "POST",
  46. url: "/Admin/ColFields/Sort?r=" + Math.random(1),
  47. data: "Id=" + data.Id + "&Sort=" + value,
  48. dataType: "text",
  49. success: function (data) {
  50. }
  51. });
  52. }
  53. });
  54. //列表数据
  55. table.render({
  56. elem: '#LAY-list-manage'
  57. , url: '/Admin/ColFields/IndexData' //模拟接口
  58. , cols: [[
  59. { type: 'checkbox', fixed: 'left' }
  60. , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
  61. , { field: 'FieldType', title: '字段类型', sort: true }
  62. , { field: 'FieldName', title: '字段名称', sort: true }
  63. , { field: 'FieldTag', title: '字段标签', sort: true }
  64. , { field: 'IsAdmin', title: '后台列表显示', sort: true }
  65. , { field: 'IsQuery', title: '后台查询条件', sort: true }
  66. , { field: 'Status', title: '状态', sort: true }
  67. , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  68. , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  69. ]]
  70. , where: {
  71. ColId: ColId
  72. }
  73. , page: true
  74. , limit: 30
  75. , height: 'full'
  76. , text: '对不起,加载出现异常!'
  77. , done: function (res, curr, count) {
  78. $(".layui-none").text("无数据");
  79. }
  80. });
  81. //监听工具条
  82. table.on('tool(LAY-list-manage)', function (obj) {
  83. var data = obj.data;
  84. if (obj.event === 'del') {
  85. layer.confirm('确定要删除吗?删除后不能恢复!', {
  86. btn: ['确定', '应用到子栏目', '取消'] //按钮
  87. }, function () {
  88. $.ajax({
  89. type: "POST",
  90. url: "/Admin/ColFields/Delete?r=" + Math.random(1),
  91. data: "Id=" + data.Id,
  92. dataType: "text",
  93. success: function (data) {
  94. if (data == "success") {
  95. obj.del();
  96. layer.close(index);
  97. } else {
  98. parent.layer.msg(data);
  99. }
  100. }
  101. });
  102. }, function () {
  103. $.ajax({
  104. type: "POST",
  105. url: "/Admin/ColFields/Delete?r=" + Math.random(1),
  106. data: "Id=" + data.Id + "&include=true",
  107. dataType: "text",
  108. success: function (data) {
  109. if (data == "success") {
  110. obj.del();
  111. layer.close(index);
  112. } else {
  113. parent.layer.msg(data);
  114. }
  115. }
  116. });
  117. });
  118. } else if (obj.event === 'edit') {
  119. var tr = $(obj.tr);
  120. var perContent = layer.open({
  121. type: 2
  122. , title: '栏目扩展字段-编辑'
  123. , content: 'Edit?ColId=' + ColId + '&Id=' + data.Id
  124. , maxmin: true
  125. , area: ['500px', '450px']
  126. , btn: ['确定', '取消']
  127. , yes: function (index, layero) {
  128. var iframeWindow = window['layui-layer-iframe' + index]
  129. , submitID = 'LAY-list-front-submit'
  130. , submit = layero.find('iframe').contents().find('#' + submitID);
  131. var FieldCheck = "|";
  132. layero.find('iframe').contents().find("input[type=checkbox][name=FieldCheckList]:checked").each(function (i) {
  133. FieldCheck += $(this).val() + "|";
  134. });
  135. layero.find('iframe').contents().find("#FieldCheck").val(FieldCheck);
  136. //监听提交
  137. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  138. var field = data.field; //获取提交的字段
  139. var userdata = "";
  140. for (var prop in field) {
  141. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  142. }
  143. //提交 Ajax 成功后,静态更新表格中的数据
  144. //$.ajax({});
  145. $.ajax({
  146. type: "POST",
  147. url: "/Admin/ColFields/Edit?r=" + Math.random(1),
  148. data: userdata,
  149. dataType: "text",
  150. success: function (data) {
  151. layer.close(index); //关闭弹层
  152. if (data == "success") {
  153. table.reload('LAY-list-manage'); //数据刷新
  154. } else {
  155. layer.msg(data);
  156. }
  157. }
  158. });
  159. });
  160. submit.trigger('click');
  161. }
  162. , success: function (layero, index) {
  163. }
  164. });
  165. layer.full(perContent);
  166. }
  167. });
  168. //监听搜索
  169. form.on('submit(LAY-list-front-search)', function (data) {
  170. var field = data.field;
  171. //执行重载
  172. table.reload('LAY-list-manage', {
  173. where: field
  174. });
  175. });
  176. form.on('submit(LAY-list-front-searchall)', function (data) {
  177. table.reload('LAY-list-manage', {
  178. where: null
  179. });
  180. });
  181. //事件
  182. var active = {
  183. batchdel: function () {
  184. var checkStatus = table.checkStatus('LAY-list-manage')
  185. , data = checkStatus.data; //得到选中的数据
  186. if (data.length < 1) {
  187. parent.layer.msg("请选择要删除的项");
  188. } else {
  189. var ids = "";
  190. $.each(data, function (index, value) {
  191. ids += data[index].Id + ",";
  192. });
  193. ids = ids.substring(0, ids.length - 1);
  194. layer.confirm('确定要删除吗?删除后不能恢复!', {
  195. btn: ['确定', '应用到子栏目', '取消'] //按钮
  196. }, function () {
  197. $.ajax({
  198. type: "POST",
  199. url: "/Admin/ColFields/Delete?r=" + Math.random(1),
  200. data: "Id=" + ids,
  201. dataType: "text",
  202. success: function (data) {
  203. layer.close(index);
  204. if (data == "success") {
  205. table.reload('LAY-list-manage');
  206. } else {
  207. layer.msg(data);
  208. }
  209. }
  210. });
  211. }, function () {
  212. $.ajax({
  213. type: "POST",
  214. url: "/Admin/ColFields/Delete?r=" + Math.random(1),
  215. data: "Id=" + ids +"&include=true",
  216. dataType: "text",
  217. success: function (data) {
  218. layer.close(index);
  219. if (data == "success") {
  220. table.reload('LAY-list-manage');
  221. } else {
  222. layer.msg(data);
  223. }
  224. }
  225. });
  226. });
  227. }
  228. }
  229. , add: function () {
  230. var perContent = layer.open({
  231. type: 2
  232. , title: '栏目扩展字段-添加'
  233. , content: 'Add?ColId=' + ColId
  234. , maxmin: true
  235. , area: ['500px', '450px']
  236. , btn: ['确定', '取消']
  237. , yes: function (index, layero) {
  238. var iframeWindow = window['layui-layer-iframe' + index]
  239. , submitID = 'LAY-list-front-submit'
  240. , submit = layero.find('iframe').contents().find('#' + submitID);
  241. var FieldCheck = "|";
  242. layero.find('iframe').contents().find("input[type=checkbox][name=FieldCheckList]:checked").each(function (i) {
  243. FieldCheck += $(this).val() + "|";
  244. });
  245. layero.find('iframe').contents().find("#FieldCheck").val(FieldCheck);
  246. //监听提交
  247. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  248. var field = data.field; //获取提交的字段
  249. var userdata = "";
  250. for (var prop in field) {
  251. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  252. }
  253. //提交 Ajax 成功后,静态更新表格中的数据
  254. //$.ajax({});
  255. $.ajax({
  256. type: "POST",
  257. url: "/Admin/ColFields/Add?r=" + Math.random(1),
  258. data: userdata,
  259. dataType: "text",
  260. success: function (data) {
  261. layer.close(index); //关闭弹层
  262. if (data == "success") {
  263. table.reload('LAY-list-manage'); //数据刷新
  264. } else {
  265. layer.msg(data);
  266. }
  267. }
  268. });
  269. });
  270. submit.trigger('click');
  271. }
  272. });
  273. layer.full(perContent);
  274. , ExportExcel: function () {
  275. var userdata = '';
  276. $(".layuiadmin-card-header-auto input").each(function (i) {
  277. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  278. });
  279. $(".layuiadmin-card-header-auto select").each(function (i) {
  280. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  281. });
  282. $.ajax({
  283. type: "GET",
  284. title: '导入',
  285. maxmin: false,
  286. area: ['460px', '180px'],
  287. content: $('#excelForm'),
  288. cancel: function () {
  289. }
  290. });
  291. }
  292. , ExportExcel: function () {
  293. var userdata = $('#QueryForm').serialize();
  294. $.ajax({
  295. type: "POST",
  296. url: "/Admin/ColFields/ExportExcel?r=" + Math.random(1),
  297. data: userdata,
  298. dataType: "json",
  299. success: function (data) {
  300. data.Obj.unshift(data.Fields);
  301. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  302. }
  303. });
  304. }
  305. , Open: function () {
  306. var checkStatus = table.checkStatus('LAY-list-manage')
  307. , data = checkStatus.data; //得到选中的数据
  308. if (data.length < 1) {
  309. parent.layer.msg("请选择要开启的项");
  310. } else {
  311. var ids = "";
  312. $.each(data, function (index, value) {
  313. ids += data[index].Id + ",";
  314. });
  315. ids = ids.substring(0, ids.length - 1);
  316. var index = layer.confirm('确定要开启吗?', function (index) {
  317. $.ajax({
  318. type: "POST",
  319. url: "/Admin/ColFields/Open?r=" + Math.random(1),
  320. data: "Id=" + ids,
  321. dataType: "text",
  322. success: function (data) {
  323. layer.close(index);
  324. if (data == "success") {
  325. table.reload('LAY-list-manage');
  326. } else {
  327. layer.msg(data);
  328. }
  329. }
  330. });
  331. });
  332. }
  333. }
  334. , Close: function () {
  335. var checkStatus = table.checkStatus('LAY-list-manage')
  336. , data = checkStatus.data; //得到选中的数据
  337. if (data.length < 1) {
  338. parent.layer.msg("请选择要关闭的项");
  339. } else {
  340. var ids = "";
  341. $.each(data, function (index, value) {
  342. ids += data[index].Id + ",";
  343. });
  344. ids = ids.substring(0, ids.length - 1);
  345. var index = layer.confirm('确定要关闭吗?', function (index) {
  346. $.ajax({
  347. type: "POST",
  348. url: "/Admin/ColFields/Close?r=" + Math.random(1),
  349. data: "Id=" + ids,
  350. dataType: "text",
  351. success: function (data) {
  352. layer.close(index);
  353. if (data == "success") {
  354. table.reload('LAY-list-manage');
  355. } else {
  356. layer.msg(data);
  357. }
  358. }
  359. });
  360. });
  361. }
  362. }
  363. };
  364. $('.layui-btn').on('click', function () {
  365. var type = $(this).data('type');
  366. active[type] ? active[type].call(this) : '';
  367. });
  368. });