Leaders_Admin.js 22 KB

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