RightDic_Admin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/RightDic/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/RightDic/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/RightDic/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. field: 'name',
  80. title: '标题'
  81. }, {
  82. field: 'MainMenu',
  83. fixed: 'right',
  84. title: '快捷方式',
  85. width: 120,
  86. templet: '#switchMainMenu'
  87. }, {
  88. field: 'MainStat',
  89. fixed: 'right',
  90. title: '统计',
  91. width: 120,
  92. templet: '#switchMainStat'
  93. }, {
  94. field: 'MainDataList',
  95. fixed: 'right',
  96. title: '主界面数据列表',
  97. width: 150,
  98. templet: '#switchMainDataList'
  99. }, {
  100. field: 'sort',
  101. fixed: 'right',
  102. title: '排序',
  103. width: 80,
  104. edit: 'text'
  105. }, {
  106. title: '操作',
  107. align: 'center',
  108. fixed: 'right',
  109. width: 120,
  110. toolbar: '#table-list-tools'
  111. }]
  112. ],
  113. limit: 1000,
  114. height: 'full-60',
  115. text: '对不起,加载出现异常!',
  116. done: function (res, curr, count) {
  117. $(".layui-none").text("无数据");
  118. }
  119. });
  120. //监听工具条
  121. table.on('tool(LAY-list-manage)', function (obj) {
  122. var data = obj.data;
  123. if (obj.event === 'icon') {
  124. 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'];
  125. var content = '';
  126. content += '<li style="width: 40px; height:40px; line-height:40px; text-align:center; float: left;" onclick="setIcon(\'' + data.id + '\', \'\')">无</li>';
  127. for (var i = 0; i < iconlist.length; i++) {
  128. 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>';
  129. }
  130. iconindex = layer.open({
  131. type: 1,
  132. title: false,
  133. closeBtn: 0,
  134. shadeClose: true,
  135. skin: 'yourclass',
  136. area: ['600px', 'auto'],
  137. content: '<div><ul>' + content + '</ul></div>'
  138. });
  139. } else if (obj.event === 'edit') {
  140. var tr = $(obj.tr);
  141. var perContent = layer.open({
  142. type: 2,
  143. title: '分润对象-编辑',
  144. content: 'Edit?Id=' + data.id + '',
  145. maxmin: true,
  146. area: ['500px', '450px'],
  147. btn: ['确定', '取消'],
  148. yes: function (index, layero) {
  149. var iframeWindow = window['layui-layer-iframe' + index],
  150. submitID = 'LAY-list-front-submit',
  151. submit = layero.find('iframe').contents().find('#' + submitID);
  152. setTimeout(function () {
  153. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  154. var errObj = $(this).find('.layui-form-danger');
  155. if (errObj.length > 0) {
  156. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  157. submit.click();
  158. }
  159. });
  160. }, 300);
  161. //监听提交
  162. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  163. var field = data.field; //获取提交的字段
  164. var userdata = "";
  165. for (var prop in field) {
  166. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  167. }
  168. //提交 Ajax 成功后,静态更新表格中的数据
  169. //$.ajax({});
  170. $.ajax({
  171. type: "POST",
  172. url: "/Admin/RightDic/EditPost?r=" + Math.random(1),
  173. data: userdata,
  174. dataType: "text",
  175. success: function (data) {
  176. layer.close(index); //关闭弹层
  177. if (data == "success") {
  178. table.reload('LAY-list-manage'); //数据刷新
  179. } else {
  180. layer.msg(data);
  181. }
  182. }
  183. });
  184. });
  185. submit.trigger('click');
  186. },
  187. success: function (layero, index) {
  188. }
  189. });
  190. layer.full(perContent);
  191. }
  192. });
  193. //监听搜索
  194. form.on('submit(LAY-list-front-search)', function (data) {
  195. var field = data.field;
  196. //执行重载
  197. table.reload('LAY-list-manage', {
  198. where: field
  199. });
  200. });
  201. form.on('submit(LAY-list-front-searchall)', function (data) {
  202. table.reload('LAY-list-manage', {
  203. where: null
  204. });
  205. });
  206. form.on('switch(MainMenu)', function (obj) {
  207. $.ajax({
  208. type: "POST",
  209. url: "/Admin/RightDic/SetMainMenu?r=" + Math.random(1),
  210. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  211. dataType: "text",
  212. success: function (data) {
  213. }
  214. });
  215. });
  216. form.on('switch(MainStat)', function (obj) {
  217. $.ajax({
  218. type: "POST",
  219. url: "/Admin/RightDic/SetMainStat?r=" + Math.random(1),
  220. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  221. dataType: "text",
  222. success: function (data) {
  223. }
  224. });
  225. });
  226. form.on('switch(MainDataList)', function (obj) {
  227. $.ajax({
  228. type: "POST",
  229. url: "/Admin/RightDic/SetMainDataList?r=" + Math.random(1),
  230. data: "Id=" + obj.value + "&value=" + obj.elem.checked,
  231. dataType: "text",
  232. success: function (data) {
  233. }
  234. });
  235. });
  236. //事件
  237. var active = {
  238. };
  239. $('.layui-btn').on('click', function () {
  240. var type = $(this).data('type');
  241. active[type] ? active[type].call(this) : '';
  242. });
  243. });
  244. function setIcon(id, icon) {
  245. $.ajax({
  246. type: "POST",
  247. url: "/Admin/RightDic/SetIcon?r=" + Math.random(1),
  248. data: "Id=" + id + "&value=" + icon,
  249. dataType: "text",
  250. success: function (data) {
  251. layer.close(iconindex);
  252. table.reload('LAY-list-manage');
  253. }
  254. });
  255. }