RightDicNew_Admin.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/RightDicNew/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("导入成功", {
  11. time: 2000
  12. }, function () {
  13. window.location.reload();
  14. });
  15. } else {
  16. layer.msg(data);
  17. }
  18. }
  19. });
  20. }
  21. var table;
  22. var iconindex;
  23. layui.config({
  24. base: '/layuiadmin/' //静态资源所在路径
  25. }).extend({
  26. myexcel: 'layui/lay/modules/excel',
  27. index: 'lib/index' //主入口模块
  28. }).use(['index', 'table', 'excel', 'laydate'], function () {
  29. var $ = layui.$,
  30. form = layui.form;
  31. table = layui.table;
  32. //- 筛选条件-日期
  33. var laydate = layui.laydate;
  34. //excel导入
  35. var excel = layui.excel;
  36. $('#ExcelFile').change(function (e) {
  37. var files = e.target.files;
  38. excel.importExcel(files, {}, function (data) {
  39. ExcelData = data[0].Sheet1;
  40. });
  41. });
  42. //监听单元格编辑
  43. table.on('edit(LAY-list-manage)', function (obj) {
  44. var value = obj.value //得到修改后的值
  45. ,
  46. data = obj.data //得到所在行所有键值
  47. ,
  48. field = obj.field; //得到字段
  49. console.log(field);
  50. if (field == "sort") {
  51. $.ajax({
  52. type: "POST",
  53. url: "/Admin/RightDicNew/Sort?r=" + Math.random(1),
  54. data: "Id=" + data.id + "&Sort=" + value,
  55. dataType: "text",
  56. success: function (data) {
  57. table.reload('LAY-list-manage');
  58. }
  59. });
  60. }
  61. });
  62. //列表数据
  63. table.render({
  64. elem: '#LAY-list-manage',
  65. url: '/Admin/RightDicNew/IndexData' //模拟接口
  66. ,
  67. cols: [
  68. [{
  69. type: 'checkbox',
  70. fixed: 'left'
  71. }, {
  72. field: 'Icon',
  73. fixed: 'left',
  74. title: '图标',
  75. width: 60,
  76. templet: '#iconShow',
  77. event: 'icon'
  78. }, {
  79. width: 60,
  80. field: 'id',
  81. title: 'ID'
  82. }, {
  83. field: 'title',
  84. title: '标题'
  85. }, {
  86. field: 'sort',
  87. fixed: 'right',
  88. title: '排序',
  89. width: 80,
  90. edit: 'text'
  91. }, {
  92. title: '操作',
  93. align: 'center',
  94. fixed: 'right',
  95. width: 180,
  96. toolbar: '#table-list-tools'
  97. }]
  98. ],
  99. limit: 1000,
  100. height: 'full-60',
  101. text: '对不起,加载出现异常!',
  102. done: function (res, curr, count) {
  103. $(".layui-none").text("无数据");
  104. }
  105. });
  106. //监听工具条
  107. table.on('tool(LAY-list-manage)', function (obj) {
  108. var data = obj.data;
  109. if (obj.event === 'icon') {
  110. var iconlist = ['layui-icon-heart-fill', 'layui-icon-heart', 'layui-icon-light', 'layui-icon-time', 'layui-icon-bluetooth', 'layui-icon-at', 'layui-icon-mute', 'layui-icon-mike', 'layui-icon-key', 'layui-icon-gift', 'layui-icon-email', 'layui-icon-rss', 'layui-icon-wifi', 'layui-icon-logout', 'layui-icon-android', 'layui-icon-ios', 'layui-icon-windows', 'layui-icon-transfer', 'layui-icon-service', 'layui-icon-subtraction', 'layui-icon-addition', 'layui-icon-slider', 'layui-icon-print', 'layui-icon-export', 'layui-icon-cols', 'layui-icon-screen-restore', 'layui-icon-screen-full', 'layui-icon-rate-half', 'layui-icon-rate', 'layui-icon-rate-solid', 'layui-icon-cellphone', 'layui-icon-vercode', 'layui-icon-login-wechat', 'layui-icon-login-qq', 'layui-icon-login-weibo', 'layui-icon-password', 'layui-icon-username', 'layui-icon-refresh-3', 'layui-icon-auz', 'layui-icon-spread-left', 'layui-icon-shrink-right', 'layui-icon-snowflake', 'layui-icon-tips', 'layui-icon-note', 'layui-icon-home', 'layui-icon-senior', 'layui-icon-refresh', 'layui-icon-refresh-1', 'layui-icon-flag', 'layui-icon-theme', 'layui-icon-notice', 'layui-icon-website', 'layui-icon-console', 'layui-icon-face-surprised', 'layui-icon-set', 'layui-icon-template-1', 'layui-icon-app', 'layui-icon-template', 'layui-icon-praise', 'layui-icon-tread', 'layui-icon-male', 'layui-icon-female', 'layui-icon-camera', 'layui-icon-camera-fill', 'layui-icon-more', 'layui-icon-more-vertical', 'layui-icon-rmb', 'layui-icon-dollar', 'layui-icon-diamond', 'layui-icon-fire', 'layui-icon-return', 'layui-icon-location', 'layui-icon-read', 'layui-icon-survey', 'layui-icon-face-smile', 'layui-icon-face-cry', 'layui-icon-cart-simple', 'layui-icon-cart', 'layui-icon-next', 'layui-icon-prev', 'layui-icon-upload-drag', 'layui-icon-upload', 'layui-icon-download-circle', 'layui-icon-component', 'layui-icon-file-b', 'layui-icon-user', 'layui-icon-find-fill', 'layui-icon-loading', 'layui-icon-loading-1', 'layui-icon-add-1', 'layui-icon-play', 'layui-icon-pause', 'layui-icon-headset', 'layui-icon-video', 'layui-icon-voice', 'layui-icon-speaker', 'layui-icon-fonts-del', 'layui-icon-fonts-code', 'layui-icon-fonts-html', 'layui-icon-fonts-strong', 'layui-icon-unlink', 'layui-icon-picture', 'layui-icon-link', 'layui-icon-face-smile-b', 'layui-icon-align-left', 'layui-icon-align-right', 'layui-icon-align-center', 'layui-icon-fonts-u', 'layui-icon-fonts-i', 'layui-icon-tabs', 'layui-icon-radio', 'layui-icon-circle', 'layui-icon-edit', 'layui-icon-share', 'layui-icon-delete', 'layui-icon-form', 'layui-icon-cellphone-fine', 'layui-icon-dialogue', 'layui-icon-fonts-clear', 'layui-icon-layer', 'layui-icon-date', 'layui-icon-water', 'layui-icon-code-circle', 'layui-icon-carousel', 'layui-icon-prev-circle', 'layui-icon-layouts', 'layui-icon-util', 'layui-icon-templeate-1', 'layui-icon-upload-circle', 'layui-icon-tree', 'layui-icon-table', 'layui-icon-chart', 'layui-icon-chart-screen', 'layui-icon-engine', 'layui-icon-triangle-d', 'layui-icon-triangle-r', 'layui-icon-file', 'layui-icon-set-sm', 'layui-icon-reduce-circle', 'layui-icon-add-circle', 'layui-icon-404', 'layui-icon-about', 'layui-icon-up', 'layui-icon-down', 'layui-icon-left', 'layui-icon-right', 'layui-icon-circle-dot', 'layui-icon-search', 'layui-icon-set-fill', 'layui-icon-group', 'layui-icon-friends', 'layui-icon-reply-fill', 'layui-icon-menu-fill', 'layui-icon-log', 'layui-icon-picture-fine', 'layui-icon-face-smile-fine', 'layui-icon-list', 'layui-icon-release', 'layui-icon-ok', 'layui-icon-help', 'layui-icon-chat', 'layui-icon-top', 'layui-icon-star', 'layui-icon-star-fill', 'layui-icon-close-fill', 'layui-icon-close', 'layui-icon-ok-circle', 'layui-icon-add-circle-fine'];
  111. var content = '';
  112. content += '<li style="width: 40px; height:40px; line-height:40px; text-align:center; float: left;" onclick="setIcon(\'' + data.id + '\', \'\')">无</li>';
  113. for (var i = 0; i < iconlist.length; i++) {
  114. content += '<li style="width: 40px; height:40px; line-height:40px; text-align:center; float: left;" onclick="setIcon(\'' + data.id + '\', \'' + iconlist[i] + '\')"><i class="layui-icon ' + iconlist[i] + '" style="font-size:20px;"></i></li>';
  115. }
  116. iconindex = layer.open({
  117. type: 1,
  118. title: false,
  119. closeBtn: 0,
  120. shadeClose: true,
  121. skin: 'yourclass',
  122. area: ['600px', 'auto'],
  123. content: '<div><ul>' + content + '</ul></div>'
  124. });
  125. } else if (obj.event === 'edit') {
  126. var tr = $(obj.tr);
  127. var perContent = layer.open({
  128. type: 2,
  129. title: '编辑',
  130. content: 'Edit?Id=' + data.id + '',
  131. maxmin: true,
  132. area: ['500px', '450px'],
  133. btn: ['确定', '取消'],
  134. yes: function (index, layero) {
  135. var iframeWindow = window['layui-layer-iframe' + index],
  136. submitID = 'LAY-list-front-submit',
  137. submit = layero.find('iframe').contents().find('#' + submitID);
  138. setTimeout(function () {
  139. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  140. var errObj = $(this).find('.layui-form-danger');
  141. if (errObj.length > 0) {
  142. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  143. submit.click();
  144. }
  145. });
  146. }, 300);
  147. //监听提交
  148. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  149. var field = data.field; //获取提交的字段
  150. var userdata = "";
  151. for (var prop in field) {
  152. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  153. }
  154. //提交 Ajax 成功后,静态更新表格中的数据
  155. //$.ajax({});
  156. $.ajax({
  157. type: "POST",
  158. url: "/Admin/RightDicNew/EditPost?r=" + Math.random(1),
  159. data: userdata,
  160. dataType: "text",
  161. success: function (data) {
  162. layer.close(index); //关闭弹层
  163. if (data == "success") {
  164. table.reload('LAY-list-manage'); //数据刷新
  165. } else {
  166. layer.msg(data);
  167. }
  168. }
  169. });
  170. });
  171. submit.trigger('click');
  172. },
  173. success: function (layero, index) {
  174. }
  175. });
  176. layer.full(perContent);
  177. } else if (obj.event === 'right') {
  178. var tr = $(obj.tr);
  179. var perContent = layer.open({
  180. type: 2,
  181. title: '权限配置',
  182. content: 'RightSet?Id=' + data.id + '',
  183. maxmin: true,
  184. area: ['500px', '450px'],
  185. btn: ['确定', '取消'],
  186. yes: function (index, layero) {
  187. var iframeWindow = window['layui-layer-iframe' + index],
  188. submitID = 'LAY-list-front-submit',
  189. submit = layero.find('iframe').contents().find('#' + submitID);
  190. setTimeout(function () {
  191. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  192. var errObj = $(this).find('.layui-form-danger');
  193. if (errObj.length > 0) {
  194. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  195. submit.click();
  196. }
  197. });
  198. }, 300);
  199. //监听提交
  200. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  201. var field = data.field; //获取提交的字段
  202. var userdata = "";
  203. for (var prop in field) {
  204. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  205. }
  206. var RightList = '';
  207. layero.find('iframe').contents().find('input[type=checkbox][name=RightString]:checked').each(function (i) {
  208. RightList += $(this).val() + ',';
  209. });
  210. userdata += '&RightList=' + RightList;
  211. //提交 Ajax 成功后,静态更新表格中的数据
  212. //$.ajax({});
  213. $.ajax({
  214. type: "POST",
  215. url: "/Admin/RightDicNew/RightSetPost?r=" + Math.random(1),
  216. data: userdata,
  217. dataType: "text",
  218. success: function (data) {
  219. if (data == "success") {
  220. layer.msg('设置成功');
  221. layer.close(index); //关闭弹层
  222. // table.reload('LAY-list-manage'); //数据刷新
  223. } else {
  224. layer.msg(data);
  225. }
  226. }
  227. });
  228. });
  229. submit.trigger('click');
  230. },
  231. success: function (layero, index) {
  232. }
  233. });
  234. layer.full(perContent);
  235. }
  236. });
  237. //监听搜索
  238. form.on('submit(LAY-list-front-search)', function (data) {
  239. var field = data.field;
  240. //执行重载
  241. table.reload('LAY-list-manage', {
  242. where: field
  243. });
  244. });
  245. form.on('submit(LAY-list-front-searchall)', function (data) {
  246. table.reload('LAY-list-manage', {
  247. where: null
  248. });
  249. });
  250. form.on('switch(MainMenu)', function (obj) {
  251. $.ajax({
  252. type: "POST",
  253. url: "/Admin/RightDicNew/SetMainMenu?r=" + Math.random(1),
  254. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  255. dataType: "text",
  256. success: function (data) {
  257. }
  258. });
  259. });
  260. form.on('switch(MainStat)', function (obj) {
  261. $.ajax({
  262. type: "POST",
  263. url: "/Admin/RightDicNew/SetMainStat?r=" + Math.random(1),
  264. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  265. dataType: "text",
  266. success: function (data) {
  267. }
  268. });
  269. });
  270. form.on('switch(MainDataList)', function (obj) {
  271. $.ajax({
  272. type: "POST",
  273. url: "/Admin/RightDicNew/SetMainDataList?r=" + Math.random(1),
  274. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  275. dataType: "text",
  276. success: function (data) {
  277. }
  278. });
  279. });
  280. //事件
  281. var active = {
  282. batchdel: function () {
  283. var checkStatus = table.checkStatus('LAY-list-manage')
  284. , data = checkStatus.data; //得到选中的数据
  285. if (data.length < 1) {
  286. parent.layer.msg("请选择要删除的项");
  287. } else {
  288. var ids = "";
  289. $.each(data, function (index, value) {
  290. ids += data[index].id + ",";
  291. });
  292. ids = ids.substring(0, ids.length - 1);
  293. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  294. $.ajax({
  295. type: "POST",
  296. url: "/Admin/RightDicNew/Delete?r=" + Math.random(1),
  297. data: "Id=" + ids,
  298. dataType: "text",
  299. success: function (data) {
  300. layer.close(index);
  301. if (data == "success") {
  302. table.reload('LAY-list-manage');
  303. } else {
  304. layer.msg(data);
  305. }
  306. }
  307. });
  308. });
  309. }
  310. },
  311. add: function () {
  312. var perContent = layer.open({
  313. type: 2
  314. , title: '添加'
  315. , content: 'Add'
  316. , maxmin: true
  317. , area: ['500px', '450px']
  318. , btn: ['确定', '取消']
  319. , yes: function (index, layero) {
  320. var iframeWindow = window['layui-layer-iframe' + index]
  321. , submitID = 'LAY-list-front-submit'
  322. , submit = layero.find('iframe').contents().find('#' + submitID);
  323. setTimeout(function () {
  324. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  325. var errObj = $(this).find('.layui-form-danger');
  326. if (errObj.length > 0) {
  327. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  328. submit.click();
  329. }
  330. });
  331. }, 300);
  332. //监听提交
  333. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  334. var field = data.field; //获取提交的字段
  335. var userdata = "";
  336. for (var prop in field) {
  337. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  338. }
  339. $.ajax({
  340. type: "POST",
  341. url: "/Admin/RightDicNew/AddPost?r=" + Math.random(1),
  342. data: userdata,
  343. dataType: "text",
  344. success: function (data) {
  345. layer.close(index); //关闭弹层
  346. if (data == "success") {
  347. table.reload('LAY-list-manage'); //数据刷新
  348. } else {
  349. layer.msg(data);
  350. }
  351. }
  352. });
  353. });
  354. submit.trigger('click');
  355. }
  356. });
  357. layer.full(perContent);
  358. }
  359. };
  360. $('.layui-btn').on('click', function () {
  361. var type = $(this).data('type');
  362. active[type] ? active[type].call(this) : '';
  363. });
  364. });
  365. function setIcon(id, icon) {
  366. $.ajax({
  367. type: "POST",
  368. url: "/Admin/RightDicNew/SetIcon?r=" + Math.random(1),
  369. data: "Id=" + id + "&value=" + icon,
  370. dataType: "text",
  371. success: function (data) {
  372. layer.close(iconindex);
  373. table.reload('LAY-list-manage');
  374. }
  375. });
  376. }