CustomQueryDo_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. var ExcelData,ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/CustomQueryDo/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. function resetClickFlag() {
  20. setTimeout(function(){
  21. clickFlag = true;
  22. }, 10000);
  23. }
  24. function resetExportFlag() {
  25. setTimeout(function(){
  26. exportFlag = true;
  27. }, 10000);
  28. }
  29. var excel;
  30. var clickFlag = true;
  31. var exportFlag = true;
  32. layui.config({
  33. base: '/layuiadmin/' //静态资源所在路径
  34. }).extend({
  35. myexcel: 'layui/lay/modules/excel',
  36. index: 'lib/index' //主入口模块
  37. }).use(['index', 'table', 'excel', 'laydate'], function () {
  38. var $ = layui.$
  39. , form = layui.form
  40. , table = layui.table;
  41. //- 筛选条件-日期
  42. var laydate = layui.laydate;
  43. //excel导入
  44. excel = layui.excel;
  45. $('#ExcelFile').change(function (e) {
  46. var files = e.target.files;
  47. excel.importExcel(files, { }, function (data) {
  48. ExcelData = data[0].sheet1;
  49. });
  50. });
  51. //监听单元格编辑
  52. table.on('edit(LAY-list-manage)', function(obj){
  53. var value = obj.value //得到修改后的值
  54. ,data = obj.data //得到所在行所有键值
  55. ,field = obj.field; //得到字段
  56. if(field == "Sort"){
  57. $.ajax({
  58. type: "POST",
  59. url: "/Admin/CustomQueryDo/Sort?r=" + Math.random(1),
  60. data: "Id=" + data.Id + "&Sort=" + value,
  61. dataType: "text",
  62. success: function (data) {
  63. }
  64. });
  65. }
  66. });
  67. //列表数据
  68. table.render({
  69. elem: '#LAY-list-manage'
  70. , url: '/Admin/CustomQueryDo/IndexData' //模拟接口
  71. , cols: mycols
  72. , where: {
  73. Id: Id
  74. }
  75. , page: true
  76. , limit: 30
  77. , height: 'full-220'
  78. , text: '对不起,加载出现异常!'
  79. , done: function (res, curr, count) {
  80. $(".layui-none").text("无数据");
  81. }
  82. });
  83. //监听工具条
  84. table.on('tool(LAY-list-manage)', function (obj) {
  85. var data = obj.data;
  86. if (obj.event === 'del') {
  87. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  88. $.ajax({
  89. type: "POST",
  90. url: "/Admin/CustomQueryDo/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. });
  103. } else if (obj.event === 'edit') {
  104. var tr = $(obj.tr);
  105. var perContent = layer.open({
  106. type: 2
  107. , title: '自定义查询-编辑'
  108. , content: 'Edit?Id=' + data.Id + ''
  109. , maxmin: true
  110. , area: ['500px', '450px']
  111. , btn: ['确定', '取消']
  112. , yes: function (index, layero) {
  113. var iframeWindow = window['layui-layer-iframe' + index]
  114. , submitID = 'LAY-list-front-submit'
  115. , submit = layero.find('iframe').contents().find('#' + submitID);
  116. setTimeout(function () {
  117. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  118. var errObj = $(this).find('.layui-form-danger');
  119. if (errObj.length > 0) {
  120. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  121. submit.click();
  122. }
  123. });
  124. }, 300);
  125. //监听提交
  126. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  127. var field = data.field; //获取提交的字段
  128. var userdata = "";
  129. for (var prop in field) {
  130. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  131. }
  132. //提交 Ajax 成功后,静态更新表格中的数据
  133. //$.ajax({});
  134. $.ajax({
  135. type: "POST",
  136. url: "/Admin/CustomQueryDo/Edit?r=" + Math.random(1),
  137. data: userdata,
  138. dataType: "text",
  139. success: function (data) {
  140. layer.close(index); //关闭弹层
  141. if (data == "success") {
  142. table.reload('LAY-list-manage'); //数据刷新
  143. } else {
  144. layer.msg(data);
  145. }
  146. }
  147. });
  148. });
  149. submit.trigger('click');
  150. }
  151. , success: function (layero, index) {
  152. }
  153. });
  154. layer.full(perContent);
  155. }
  156. });
  157. //监听搜索
  158. form.on('submit(LAY-list-front-search)', function (data) {
  159. if(!clickFlag) {
  160. layer.msg('请勿重复操作');
  161. return;
  162. }
  163. clickFlag = false;
  164. resetClickFlag();
  165. var field = data.field;
  166. //执行重载
  167. table.reload('LAY-list-manage', {
  168. where: field,
  169. page: {
  170. curr: 1
  171. }
  172. });
  173. });
  174. form.on('submit(LAY-list-front-searchall)', function (data) {
  175. if(!clickFlag) {
  176. layer.msg('请勿重复操作');
  177. return;
  178. }
  179. clickFlag = false;
  180. resetClickFlag();
  181. table.reload('LAY-list-manage', {
  182. where: {
  183. Id: Id
  184. },
  185. page: {
  186. curr: 1
  187. }
  188. });
  189. });
  190. //事件
  191. var active = {
  192. batchdel: function () {
  193. var checkStatus = table.checkStatus('LAY-list-manage')
  194. , data = checkStatus.data; //得到选中的数据
  195. if (data.length < 1) {
  196. parent.layer.msg("请选择要删除的项");
  197. } else {
  198. var ids = "";
  199. $.each(data, function (index, value) {
  200. ids += data[index].Id + ",";
  201. });
  202. ids = ids.substring(0, ids.length - 1);
  203. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  204. $.ajax({
  205. type: "POST",
  206. url: "/Admin/CustomQueryDo/Delete?r=" + Math.random(1),
  207. data: "Id=" + ids,
  208. dataType: "text",
  209. success: function (data) {
  210. layer.close(index);
  211. if (data == "success") {
  212. table.reload('LAY-list-manage');
  213. } else {
  214. layer.msg(data);
  215. }
  216. }
  217. });
  218. });
  219. }
  220. }
  221. , add: function () {
  222. var perContent = layer.open({
  223. type: 2
  224. , title: '自定义查询-添加'
  225. , content: 'Add'
  226. , maxmin: true
  227. , area: ['500px', '450px']
  228. , btn: ['确定', '取消']
  229. , yes: function (index, layero) {
  230. var iframeWindow = window['layui-layer-iframe' + index]
  231. , submitID = 'LAY-list-front-submit'
  232. , submit = layero.find('iframe').contents().find('#' + submitID);
  233. setTimeout(function () {
  234. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  235. var errObj = $(this).find('.layui-form-danger');
  236. if (errObj.length > 0) {
  237. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  238. submit.click();
  239. }
  240. });
  241. }, 300);
  242. //监听提交
  243. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  244. var field = data.field; //获取提交的字段
  245. var userdata = "";
  246. for (var prop in field) {
  247. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  248. }
  249. //提交 Ajax 成功后,静态更新表格中的数据
  250. //$.ajax({});
  251. $.ajax({
  252. type: "POST",
  253. url: "/Admin/CustomQueryDo/Add?r=" + Math.random(1),
  254. data: userdata,
  255. dataType: "text",
  256. success: function (data) {
  257. layer.close(index); //关闭弹层
  258. if (data == "success") {
  259. table.reload('LAY-list-manage'); //数据刷新
  260. } else {
  261. layer.msg(data);
  262. }
  263. }
  264. });
  265. });
  266. submit.trigger('click');
  267. }
  268. });
  269. layer.full(perContent);
  270. }
  271. , ImportData: function () {
  272. ExcelKind = 1;
  273. layer.open({
  274. type: 1,
  275. title: '导入',
  276. maxmin: false,
  277. area: ['460px', '280px'],
  278. content: $('#excelForm'),
  279. cancel: function () {
  280. }
  281. });
  282. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  283. }
  284. , ExportExcel: function () {
  285. if(!exportFlag) {
  286. layer.msg('请勿重复操作');
  287. return;
  288. }
  289. exportFlag = false;
  290. resetExportFlag();
  291. var userdata = '';
  292. $(".layuiadmin-card-header-auto input").each(function (i) {
  293. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  294. });
  295. $(".layuiadmin-card-header-auto select").each(function (i) {
  296. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  297. });
  298. $.ajax({
  299. type: "GET",
  300. url: "/Admin/CustomQueryDo/ExportExcel?r=" + Math.random(1),
  301. data: userdata,
  302. dataType: "text",
  303. success: function (data) {
  304. if (data == "success") {
  305. layer.msg('导出成功,请到我的下载中点击下载文件', {
  306. time: 3000
  307. }, function () {
  308. });
  309. } else {
  310. layer.msg(data);
  311. }
  312. }
  313. });
  314. }
  315. , Excute: function () {
  316. if(!exportFlag) {
  317. layer.msg('请勿重复操作');
  318. return;
  319. }
  320. exportFlag = false;
  321. resetExportFlag();
  322. var userdata = '';
  323. $(".layuiadmin-card-header-auto input").each(function (i) {
  324. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  325. });
  326. $(".layuiadmin-card-header-auto select").each(function (i) {
  327. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  328. });
  329. $.ajax({
  330. type: "GET",
  331. url: "/Admin/CustomQueryDo/Excute?r=" + Math.random(1),
  332. data: userdata,
  333. dataType: "text",
  334. success: function (data) {
  335. if (data == "success") {
  336. layer.msg('提交成功,请等待执行结果', {
  337. time: 3000
  338. }, function () {
  339. });
  340. } else {
  341. layer.msg(data);
  342. }
  343. }
  344. });
  345. }
  346. , Open: function () {
  347. var checkStatus = table.checkStatus('LAY-list-manage')
  348. , data = checkStatus.data; //得到选中的数据
  349. if(data.length < 1){
  350. parent.layer.msg("请选择要开启的项");
  351. }else{
  352. var ids = "";
  353. $.each(data, function (index, value) {
  354. ids += data[index].Id + ",";
  355. });
  356. ids = ids.substring(0, ids.length - 1);
  357. var index = layer.confirm('确定要开启吗?', function (index) {
  358. $.ajax({
  359. type: "POST",
  360. url: "/Admin/CustomQueryDo/Open?r=" + Math.random(1),
  361. data: "Id=" + ids,
  362. dataType: "text",
  363. success: function (data) {
  364. layer.close(index);
  365. if (data == "success") {
  366. table.reload('LAY-list-manage');
  367. } else {
  368. layer.msg(data);
  369. }
  370. }
  371. });
  372. });
  373. }
  374. }
  375. , Close: function () {
  376. var checkStatus = table.checkStatus('LAY-list-manage')
  377. , data = checkStatus.data; //得到选中的数据
  378. if(data.length < 1){
  379. parent.layer.msg("请选择要关闭的项");
  380. }else{
  381. var ids = "";
  382. $.each(data, function (index, value) {
  383. ids += data[index].Id + ",";
  384. });
  385. ids = ids.substring(0, ids.length - 1);
  386. var index = layer.confirm('确定要关闭吗?', function (index) {
  387. $.ajax({
  388. type: "POST",
  389. url: "/Admin/CustomQueryDo/Close?r=" + Math.random(1),
  390. data: "Id=" + ids,
  391. dataType: "text",
  392. success: function (data) {
  393. layer.close(index);
  394. if (data == "success") {
  395. table.reload('LAY-list-manage');
  396. } else {
  397. layer.msg(data);
  398. }
  399. }
  400. });
  401. });
  402. }
  403. }
  404. };
  405. $('.layui-btn').on('click', function () {
  406. var type = $(this).data('type');
  407. active[type] ? active[type].call(this) : '';
  408. });
  409. });