Leaders_Admin.js 18 KB

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