AppBottomNavs_Admin.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/AppBottomNavs/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(LAY-list-manage)', 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/AppBottomNavs/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/AppBottomNavs/IndexData' //模拟接口
  58. , cols: [[
  59. { type: 'checkbox', fixed: 'left' }
  60. , {field:'Id', fixed: 'left', title:'ID', width:80, sort: true, unresize: true}
  61. ,{field:'Title', title:'标题', sort: true}
  62. ,{field:'SelectIcon', title:'选中图标', width:60, templet: '#imgTpl', unresize: true}
  63. ,{field:'NormalIcon', title:'未选中图标', width:60, templet: '#imgTpl2', unresize: true}
  64. ,{field:'SelectTextColor', title:'选中文字颜色', sort: true}
  65. ,{field:'NormalTextColor', title:'未选中文字颜色', sort: true}
  66. ,{field:'PageName', title:'关联页面文件', sort: true}
  67. ,{field:'NoPageHint', title:'为关联页面提示信息', sort: true}
  68. ,{field:'BgColor', title:'背景色', sort: true}
  69. , {field:'Sort', fixed: 'right', title:'排序', width:80, edit: 'text'}
  70. , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  71. ]]
  72. , where: {
  73. }
  74. , page: true
  75. , limit: 30
  76. , height: 'full-220'
  77. , text: '对不起,加载出现异常!'
  78. , done: function (res, curr, count) {
  79. $(".layui-none").text("无数据");
  80. }
  81. });
  82. //监听工具条
  83. table.on('tool(LAY-list-manage)', function (obj) {
  84. var data = obj.data;
  85. if (obj.event === 'del') {
  86. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  87. $.ajax({
  88. type: "POST",
  89. url: "/Admin/AppBottomNavs/Delete?r=" + Math.random(1),
  90. data: "Id=" + data.Id,
  91. dataType: "text",
  92. success: function (data) {
  93. if (data == "success") {
  94. obj.del();
  95. layer.close(index);
  96. } else {
  97. parent.layer.msg(data);
  98. }
  99. }
  100. });
  101. });
  102. } else if (obj.event === 'edit') {
  103. var tr = $(obj.tr);
  104. var perContent = layer.open({
  105. type: 2
  106. , title: 'App底部导航-编辑'
  107. , content: 'Edit?Id=' + data.Id + ''
  108. , maxmin: true
  109. , area: ['500px', '450px']
  110. , btn: ['确定', '取消']
  111. , yes: function (index, layero) {
  112. var iframeWindow = window['layui-layer-iframe' + index]
  113. , submitID = 'LAY-list-front-submit'
  114. , submit = layero.find('iframe').contents().find('#' + submitID);
  115. setTimeout(function () {
  116. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  117. var errObj = $(this).find('.layui-form-danger');
  118. if (errObj.length > 0) {
  119. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  120. submit.click();
  121. }
  122. });
  123. }, 300);
  124. //监听提交
  125. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  126. var field = data.field; //获取提交的字段
  127. var userdata = "";
  128. for (var prop in field) {
  129. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  130. }
  131. //提交 Ajax 成功后,静态更新表格中的数据
  132. //$.ajax({});
  133. $.ajax({
  134. type: "POST",
  135. url: "/Admin/AppBottomNavs/Edit?r=" + Math.random(1),
  136. data: userdata,
  137. dataType: "text",
  138. success: function (data) {
  139. layer.close(index); //关闭弹层
  140. if (data == "success") {
  141. table.reload('LAY-list-manage'); //数据刷新
  142. } else {
  143. layer.msg(data);
  144. }
  145. }
  146. });
  147. });
  148. submit.trigger('click');
  149. }
  150. , success: function (layero, index) {
  151. }
  152. });
  153. layer.full(perContent);
  154. }
  155. });
  156. //监听搜索
  157. form.on('submit(LAY-list-front-search)', function (data) {
  158. var field = data.field;
  159. //执行重载
  160. table.reload('LAY-list-manage', {
  161. where: field
  162. });
  163. });
  164. form.on('submit(LAY-list-front-searchall)', function (data) {
  165. table.reload('LAY-list-manage', {
  166. where: null
  167. });
  168. });
  169. //事件
  170. var active = {
  171. batchdel: function () {
  172. var checkStatus = table.checkStatus('LAY-list-manage')
  173. , data = checkStatus.data; //得到选中的数据
  174. if (data.length < 1) {
  175. parent.layer.msg("请选择要删除的项");
  176. } else {
  177. var ids = "";
  178. $.each(data, function (index, value) {
  179. ids += data[index].Id + ",";
  180. });
  181. ids = ids.substring(0, ids.length - 1);
  182. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  183. $.ajax({
  184. type: "POST",
  185. url: "/Admin/AppBottomNavs/Delete?r=" + Math.random(1),
  186. data: "Id=" + ids,
  187. dataType: "text",
  188. success: function (data) {
  189. layer.close(index);
  190. if (data == "success") {
  191. table.reload('LAY-list-manage');
  192. } else {
  193. layer.msg(data);
  194. }
  195. }
  196. });
  197. });
  198. }
  199. }
  200. , add: function () {
  201. var perContent = layer.open({
  202. type: 2
  203. , title: 'App底部导航-添加'
  204. , content: 'Add'
  205. , maxmin: true
  206. , area: ['500px', '450px']
  207. , btn: ['确定', '取消']
  208. , yes: function (index, layero) {
  209. var iframeWindow = window['layui-layer-iframe' + index]
  210. , submitID = 'LAY-list-front-submit'
  211. , submit = layero.find('iframe').contents().find('#' + submitID);
  212. setTimeout(function () {
  213. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  214. var errObj = $(this).find('.layui-form-danger');
  215. if (errObj.length > 0) {
  216. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  217. submit.click();
  218. }
  219. });
  220. }, 300);
  221. //监听提交
  222. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  223. var field = data.field; //获取提交的字段
  224. var userdata = "";
  225. for (var prop in field) {
  226. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  227. }
  228. //提交 Ajax 成功后,静态更新表格中的数据
  229. //$.ajax({});
  230. $.ajax({
  231. type: "POST",
  232. url: "/Admin/AppBottomNavs/Add?r=" + Math.random(1),
  233. data: userdata,
  234. dataType: "text",
  235. success: function (data) {
  236. layer.close(index); //关闭弹层
  237. if (data == "success") {
  238. table.reload('LAY-list-manage'); //数据刷新
  239. } else {
  240. layer.msg(data);
  241. }
  242. }
  243. });
  244. });
  245. submit.trigger('click');
  246. }
  247. });
  248. layer.full(perContent);
  249. }
  250. , ImportData: function () {
  251. layer.open({
  252. type: 2,
  253. title: '导入',
  254. maxmin: false,
  255. area: ['460px', '180px'],
  256. content: $('#excelForm'),
  257. cancel: function () {
  258. }
  259. });
  260. }
  261. , ExportExcel: function () {
  262. var userdata = '';
  263. $(".layuiadmin-card-header-auto input").each(function (i) {
  264. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  265. });
  266. $(".layuiadmin-card-header-auto select").each(function (i) {
  267. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  268. });
  269. $.ajax({
  270. type: "GET",
  271. url: "/Admin/AppBottomNavs/ExportExcel?r=" + Math.random(1),
  272. data: userdata,
  273. dataType: "json",
  274. success: function (data) {
  275. data.Obj.unshift(data.Fields);
  276. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  277. }
  278. });
  279. }
  280. , Open: function () {
  281. var checkStatus = table.checkStatus('LAY-list-manage')
  282. , data = checkStatus.data; //得到选中的数据
  283. if(data.length < 1){
  284. parent.layer.msg("请选择要开启的项");
  285. }else{
  286. var ids = "";
  287. $.each(data, function (index, value) {
  288. ids += data[index].Id + ",";
  289. });
  290. ids = ids.substring(0, ids.length - 1);
  291. var index = layer.confirm('确定要开启吗?', function (index) {
  292. $.ajax({
  293. type: "POST",
  294. url: "/Admin/AppBottomNavs/Open?r=" + Math.random(1),
  295. data: "Id=" + ids,
  296. dataType: "text",
  297. success: function (data) {
  298. layer.close(index);
  299. if (data == "success") {
  300. table.reload('LAY-list-manage');
  301. } else {
  302. layer.msg(data);
  303. }
  304. }
  305. });
  306. });
  307. }
  308. }
  309. , Close: function () {
  310. var checkStatus = table.checkStatus('LAY-list-manage')
  311. , data = checkStatus.data; //得到选中的数据
  312. if(data.length < 1){
  313. parent.layer.msg("请选择要关闭的项");
  314. }else{
  315. var ids = "";
  316. $.each(data, function (index, value) {
  317. ids += data[index].Id + ",";
  318. });
  319. ids = ids.substring(0, ids.length - 1);
  320. var index = layer.confirm('确定要关闭吗?', function (index) {
  321. $.ajax({
  322. type: "POST",
  323. url: "/Admin/AppBottomNavs/Close?r=" + Math.random(1),
  324. data: "Id=" + ids,
  325. dataType: "text",
  326. success: function (data) {
  327. layer.close(index);
  328. if (data == "success") {
  329. table.reload('LAY-list-manage');
  330. } else {
  331. layer.msg(data);
  332. }
  333. }
  334. });
  335. });
  336. }
  337. }
  338. };
  339. $('.layui-btn').on('click', function () {
  340. var type = $(this).data('type');
  341. active[type] ? active[type].call(this) : '';
  342. });
  343. });