Col_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/Col/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', 'treeTable'], function () {
  25. var $ = layui.$
  26. , form = layui.form
  27. , table = layui.table
  28. , treeTable = layui.treeTable;
  29. //- 筛选条件-日期
  30. var laydate = layui.laydate;
  31. //excel导入
  32. var excel = layui.excel;
  33. $('#ExcelFile').change(function (e) {
  34. var files = e.target.files;
  35. excel.importExcel(files, {}, function (data) {
  36. ExcelData = data[0].Sheet1;
  37. });
  38. });
  39. //监听单元格编辑
  40. table.on('edit(LAY-list-manage)', function (obj) {
  41. var value = obj.value //得到修改后的值
  42. , data = obj.data //得到所在行所有键值
  43. , field = obj.field; //得到字段
  44. if (field == "Sort") {
  45. $.ajax({
  46. type: "POST",
  47. url: "/Admin/Col/Sort?r=" + Math.random(1),
  48. data: "Id=" + data.Id + "&Sort=" + value,
  49. dataType: "text",
  50. success: function (data) {
  51. }
  52. });
  53. }
  54. });
  55. //列表数据
  56. // table.render({
  57. // elem: '#LAY-list-manage'
  58. // , url: '/Admin/Col/IndexData' //模拟接口
  59. // , where: { CurColId: CurColId }
  60. // , cols: [[
  61. // { type: 'checkbox', fixed: 'left' }
  62. // , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
  63. // , { field: 'ColId', title: '编码' }
  64. // , { field: 'ColName', title: '名称' }
  65. // , { field: 'Status', title: '状态' }
  66. // , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  67. // , { title: '操作', width: 370, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  68. // ]]
  69. // , page: true
  70. // , limit: 3000
  71. // , height: 'full'
  72. // , text: '对不起,加载出现异常!'
  73. // , done: function (res, curr, count) {
  74. // $(".layui-none").text("无数据");
  75. // }
  76. // });
  77. var re = treeTable.render({
  78. elem: '#LAY-list-manage',
  79. url: '/Admin/Col/IndexData?CurColId='+CurColId,
  80. icon_key: 'title',
  81. is_checkbox: true,
  82. end: function(e){
  83. form.render();
  84. },
  85. cols: [
  86. {
  87. key: 'title',
  88. title: '名称',
  89. template: function(item){
  90. return '<span style="color:#333;">'+item.title+'</span>';
  91. }
  92. },
  93. {
  94. key: 'id',
  95. title: 'ID',
  96. width: '100px',
  97. align: 'center',
  98. },
  99. {
  100. key: 'pid',
  101. title: '父ID',
  102. width: '100px',
  103. align: 'center',
  104. },
  105. {
  106. key: 'Status',
  107. title: '状态',
  108. width: '100px',
  109. align: 'center',
  110. },
  111. {
  112. title: '操作',
  113. width: '350px',
  114. align: 'center',
  115. template: function (item) {
  116. var tmp = '';
  117. tmp += '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-filter="addsub">添加子栏目</a>';
  118. tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-filter="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
  119. tmp += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-filter="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
  120. tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" href="'+item.url+'" target="_blank">预览</a>';
  121. tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="/Admin/ColFields/Index?ColId='+item.id+'&right='+right+'">字段管理</a>';
  122. return tmp;
  123. }
  124. }
  125. ]
  126. });
  127. treeTable.on('tree(addsub)', function (res) {
  128. var data = res.item;
  129. if (data.ColId.length >= 12) {
  130. layer.msg("请勿创建超过3级栏目,如有需要请联系管理员");
  131. return;
  132. }
  133. var perContent = layer.open({
  134. type: 2
  135. , title: '分类设置-添加子栏目'
  136. , content: 'Add?CurColId=' + CurColId + '&PColId=' + data.ColId
  137. , maxmin: false
  138. , area: ['500px', '450px']
  139. , btn: ['确定', '取消']
  140. , yes: function (index, layero) {
  141. var iframeWindow = window['layui-layer-iframe' + index]
  142. , submitID = 'LAY-list-front-submit'
  143. , submit = layero.find('iframe').contents().find('#' + submitID);
  144. //详细内容
  145. iframeWindow.Contentsedit.sync();
  146. //监听提交
  147. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  148. var field = data.field; //获取提交的字段
  149. var userdata = "";
  150. for (var prop in field) {
  151. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  152. }
  153. //提交 Ajax 成功后,静态更新表格中的数据
  154. //$.ajax({});
  155. $.ajax({
  156. type: "POST",
  157. url: "/Admin/Col/Add?r=" + Math.random(1),
  158. data: userdata,
  159. dataType: "text",
  160. success: function (data) {
  161. layer.close(index); //关闭弹层
  162. if (data == "success") {
  163. treeTable.render(re);
  164. } else {
  165. layer.msg(data);
  166. }
  167. }
  168. });
  169. });
  170. submit.trigger('click');
  171. }
  172. });
  173. layer.full(perContent);
  174. });
  175. treeTable.on('tree(edit)', function (res) {
  176. var data = res.item;
  177. var perContent = layer.open({
  178. type: 2
  179. , title: '分类设置-编辑'
  180. , content: 'Edit?CurColId=' + CurColId + '&PColId=' + data.ColId.substring(0, data.ColId.length - 3) + '&ColId=' + data.ColId
  181. , maxmin: false
  182. , area: ['500px', '450px']
  183. , btn: ['确定', '取消']
  184. , yes: function (index, layero) {
  185. var iframeWindow = window['layui-layer-iframe' + index]
  186. , submitID = 'LAY-list-front-submit'
  187. , submit = layero.find('iframe').contents().find('#' + submitID);
  188. //详细内容
  189. iframeWindow.Contentsedit.sync();
  190. //监听提交
  191. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  192. var field = data.field; //获取提交的字段
  193. var userdata = "";
  194. for (var prop in field) {
  195. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  196. }
  197. //提交 Ajax 成功后,静态更新表格中的数据
  198. //$.ajax({});
  199. $.ajax({
  200. type: "POST",
  201. url: "/Admin/Col/Edit?r=" + Math.random(1),
  202. data: userdata,
  203. dataType: "text",
  204. success: function (data) {
  205. layer.close(index); //关闭弹层
  206. if (data == "success") {
  207. treeTable.render(re);
  208. } else {
  209. layer.msg(data);
  210. }
  211. }
  212. });
  213. });
  214. submit.trigger('click');
  215. }
  216. , success: function (layero, index) {
  217. }
  218. });
  219. layer.full(perContent);
  220. });
  221. treeTable.on('tree(del)', function (res) {
  222. var data = res.item;
  223. layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  224. $.ajax({
  225. type: "POST",
  226. url: "/Admin/Col/Delete?r=" + Math.random(1),
  227. data: "Id=" + data.id,
  228. dataType: "text",
  229. success: function (data) {
  230. if (data == "success") {
  231. treeTable.render(re);
  232. layer.close(index);
  233. } else {
  234. parent.layer.msg(data);
  235. }
  236. }
  237. });
  238. });
  239. });
  240. treeTable.on('tree(status)', function (res) {
  241. console.log(res);
  242. });
  243. //事件
  244. var active = {
  245. batchdel: function () {
  246. var ids = treeTable.checked(re).join(',');
  247. if (ids == '') {
  248. parent.layer.msg("请选择要删除的项");
  249. } else {
  250. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  251. $.ajax({
  252. type: "POST",
  253. url: "/Admin/Col/Delete?r=" + Math.random(1),
  254. data: "Id=" + ids,
  255. dataType: "text",
  256. success: function (data) {
  257. layer.close(index);
  258. if (data == "success") {
  259. treeTable.render(re);
  260. } else {
  261. layer.msg(data);
  262. }
  263. }
  264. });
  265. });
  266. }
  267. }
  268. , add: function () {
  269. var perContent = layer.open({
  270. type: 2
  271. , title: '分类设置-添加'
  272. , content: 'Add?CurColId=' + CurColId
  273. , maxmin: true
  274. , area: ['500px', '450px']
  275. , btn: ['确定', '取消']
  276. , yes: function (index, layero) {
  277. var iframeWindow = window['layui-layer-iframe' + index]
  278. , submitID = 'LAY-list-front-submit'
  279. , submit = layero.find('iframe').contents().find('#' + submitID);
  280. if (CurColId.substring(1, 3) == '001' || CurColId.substring(1, 3) == '002' || CurColId.substring(1, 3) == '003') {
  281. //详细内容
  282. iframeWindow.Contentsedit.sync();
  283. }
  284. //监听提交
  285. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  286. var field = data.field; //获取提交的字段
  287. var userdata = "";
  288. for (var prop in field) {
  289. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  290. }
  291. //提交 Ajax 成功后,静态更新表格中的数据
  292. //$.ajax({});
  293. $.ajax({
  294. type: "POST",
  295. url: "/Admin/Col/Add?r=" + Math.random(1),
  296. data: userdata,
  297. dataType: "text",
  298. success: function (data) {
  299. layer.close(index); //关闭弹层
  300. if (data == "success") {
  301. treeTable.render(re);
  302. } else {
  303. layer.msg(data);
  304. }
  305. }
  306. });
  307. });
  308. submit.trigger('click');
  309. }
  310. });
  311. layer.full(perContent);
  312. }
  313. , ImportData: function () {
  314. layer.open({
  315. type: 2,
  316. title: '导入',
  317. maxmin: false,
  318. area: ['460px', '180px'],
  319. content: $('#excelForm'),
  320. cancel: function () {
  321. }
  322. });
  323. }
  324. , ExportExcel: function () {
  325. var userdata = '';
  326. $(".layuiadmin-card-header-auto input").each(function (i) {
  327. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  328. });
  329. $(".layuiadmin-card-header-auto select").each(function (i) {
  330. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  331. });
  332. $.ajax({
  333. type: "GET",
  334. url: "/Admin/Col/ExportExcel?r=" + Math.random(1),
  335. data: userdata,
  336. dataType: "json",
  337. success: function (data) {
  338. data.Obj.unshift(data.Fields);
  339. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  340. }
  341. });
  342. }
  343. , Open: function () {
  344. var ids = treeTable.checked(re).join(',');
  345. if (ids == '') {
  346. parent.layer.msg("请选择要开启的项");
  347. } else {
  348. var index = layer.confirm('确定要开启吗?', function (index) {
  349. $.ajax({
  350. type: "POST",
  351. url: "/Admin/Col/Open?r=" + Math.random(1),
  352. data: "Id=" + ids,
  353. dataType: "text",
  354. success: function (data) {
  355. layer.close(index);
  356. if (data == "success") {
  357. treeTable.render(re);
  358. } else {
  359. layer.msg(data);
  360. }
  361. }
  362. });
  363. });
  364. }
  365. }
  366. , Close: function () {
  367. var ids = treeTable.checked(re).join(',');
  368. if (ids == '') {
  369. parent.layer.msg("请选择要关闭的项");
  370. } else {
  371. var index = layer.confirm('确定要关闭吗?', function (index) {
  372. $.ajax({
  373. type: "POST",
  374. url: "/Admin/Col/Close?r=" + Math.random(1),
  375. data: "Id=" + ids,
  376. dataType: "text",
  377. success: function (data) {
  378. layer.close(index);
  379. if (data == "success") {
  380. treeTable.render(re);
  381. } else {
  382. layer.msg(data);
  383. }
  384. }
  385. });
  386. });
  387. }
  388. }
  389. , Unfold: function () {
  390. treeTable.openAll(re);
  391. }
  392. , PackUp: function () {
  393. treeTable.closeAll(re);
  394. }
  395. };
  396. $('.layui-btn').on('click', function () {
  397. var type = $(this).data('type');
  398. active[type] ? active[type].call(this) : '';
  399. });
  400. });