SchoolMakerStudy_Admin.js 16 KB

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