Leaders_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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: 'BusinessFlag', width: 100, title: '是否对公', sort: true }
  150. , { field: 'LeaderLevel', width: 100, title: '盟主等级', sort: true }
  151. , { field: 'LeaderReserve', width: 150, title: '盟主储蓄金', sort: true }
  152. , { field: 'LeaderBalanceAmount', width: 150, title: '盟主可提现余额', sort: true }
  153. , { field: 'LastMonthReserve', width: 150, title: '上月盟主储蓄金', sort: true }
  154. , { field: 'LastMonthBalanceAmount', width: 150, title: '上月可提现余额', sort: true }
  155. , { title: '操作', align: 'center', width: 350, fixed: 'right', toolbar: '#table-list-tools' }
  156. ]]
  157. , where: {
  158. }
  159. , page: true
  160. , limit: 30
  161. , height: 'full-220'
  162. , text: '对不起,加载出现异常!'
  163. , done: function (res, curr, count) {
  164. $(".layui-none").text("无数据");
  165. }
  166. });
  167. //监听工具条
  168. table.on('tool(LAY-list-manage)', function (obj) {
  169. var data = obj.data;
  170. if (obj.event === 'del') {
  171. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  172. $.ajax({
  173. type: "POST",
  174. url: "/Admin/Leaders/Delete?r=" + Math.random(1),
  175. data: "Id=" + data.Id,
  176. dataType: "text",
  177. success: function (data) {
  178. if (data == "success") {
  179. obj.del();
  180. layer.close(index);
  181. } else {
  182. parent.layer.msg(data);
  183. }
  184. }
  185. });
  186. });
  187. } else if (obj.event === 'ChangeLeaderAmount') {
  188. var tr = $(obj.tr);
  189. var perContent = layer.open({
  190. type: 2
  191. , title: '修改盟主金额'
  192. , content: 'ChangeLeaderAmount?Id=' + data.Id
  193. , maxmin: false
  194. , area: ['450px', '550px']
  195. , btn: ['确定', '取消']
  196. , yes: function (index, layero) {
  197. var iframeWindow = window['layui-layer-iframe' + index]
  198. , submitID = 'LAY-list-front-submit'
  199. , submit = layero.find('iframe').contents().find('#' + submitID);
  200. //监听提交
  201. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  202. var field = data.field; //获取提交的字段
  203. var userdata = "";
  204. for (var prop in field) {
  205. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  206. }
  207. //提交 Ajax 成功后,静态更新表格中的数据
  208. //$.ajax({});
  209. $.ajax({
  210. type: "POST",
  211. url: "/Admin/Leaders/ChangeLeaderAmount?r=" + Math.random(1),
  212. data: userdata,
  213. dataType: "text",
  214. success: function (data) {
  215. layer.close(index); //关闭弹层
  216. if (data == "success") {
  217. layer.msg("修改成功", { time: 1500 }, function () {
  218. table.reload('LAY-list-manage'); //数据刷新
  219. });
  220. } else {
  221. layer.msg(data);
  222. }
  223. }
  224. });
  225. });
  226. submit.trigger('click');
  227. }
  228. , success: function (layero, index) {
  229. }
  230. });
  231. } else if (obj.event === 'edit') {
  232. var tr = $(obj.tr);
  233. var perContent = layer.open({
  234. type: 2
  235. , title: '盟主管理-编辑'
  236. , content: 'Edit?Id=' + data.Id + ''
  237. , maxmin: true
  238. , area: ['500px', '450px']
  239. , btn: ['确定', '取消']
  240. , yes: function (index, layero) {
  241. var iframeWindow = window['layui-layer-iframe' + index]
  242. , submitID = 'LAY-list-front-submit'
  243. , submit = layero.find('iframe').contents().find('#' + submitID);
  244. setTimeout(function () {
  245. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  246. var errObj = $(this).find('.layui-form-danger');
  247. if (errObj.length > 0) {
  248. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  249. submit.click();
  250. }
  251. });
  252. }, 300);
  253. //监听提交
  254. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  255. var field = data.field; //获取提交的字段
  256. var userdata = "";
  257. for (var prop in field) {
  258. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  259. }
  260. //提交 Ajax 成功后,静态更新表格中的数据
  261. //$.ajax({});
  262. $.ajax({
  263. type: "POST",
  264. url: "/Admin/Leaders/Edit?r=" + Math.random(1),
  265. data: userdata,
  266. dataType: "text",
  267. success: function (data) {
  268. layer.close(index); //关闭弹层
  269. if (data == "success") {
  270. table.reload('LAY-list-manage'); //数据刷新
  271. } else {
  272. layer.msg(data);
  273. }
  274. }
  275. });
  276. });
  277. submit.trigger('click');
  278. }
  279. , success: function (layero, index) {
  280. }
  281. });
  282. layer.full(perContent);
  283. }
  284. });
  285. //监听搜索
  286. form.on('submit(LAY-list-front-search)', function (data) {
  287. var field = data.field;
  288. //执行重载
  289. table.reload('LAY-list-manage', {
  290. where: field,
  291. page: {
  292. curr: 1
  293. }
  294. });
  295. });
  296. form.on('submit(LAY-list-front-searchall)', function (data) {
  297. table.reload('LAY-list-manage', {
  298. where: null,
  299. page: {
  300. curr: 1
  301. }
  302. });
  303. });
  304. //事件
  305. var active = {
  306. batchdel: function () {
  307. var checkStatus = table.checkStatus('LAY-list-manage')
  308. , data = checkStatus.data; //得到选中的数据
  309. if (data.length < 1) {
  310. parent.layer.msg("请选择要删除的项");
  311. } else {
  312. var ids = "";
  313. $.each(data, function (index, value) {
  314. ids += data[index].Id + ",";
  315. });
  316. ids = ids.substring(0, ids.length - 1);
  317. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  318. $.ajax({
  319. type: "POST",
  320. url: "/Admin/Leaders/Delete?r=" + Math.random(1),
  321. data: "Id=" + ids,
  322. dataType: "text",
  323. success: function (data) {
  324. layer.close(index);
  325. if (data == "success") {
  326. table.reload('LAY-list-manage');
  327. } else {
  328. layer.msg(data);
  329. }
  330. }
  331. });
  332. });
  333. }
  334. }
  335. , add: function () {
  336. var perContent = layer.open({
  337. type: 2
  338. , title: '盟主管理-添加'
  339. , content: 'Add'
  340. , maxmin: true
  341. , area: ['500px', '450px']
  342. , btn: ['确定', '取消']
  343. , yes: function (index, layero) {
  344. var iframeWindow = window['layui-layer-iframe' + index]
  345. , submitID = 'LAY-list-front-submit'
  346. , submit = layero.find('iframe').contents().find('#' + submitID);
  347. setTimeout(function () {
  348. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  349. var errObj = $(this).find('.layui-form-danger');
  350. if (errObj.length > 0) {
  351. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  352. submit.click();
  353. }
  354. });
  355. }, 300);
  356. //监听提交
  357. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  358. var field = data.field; //获取提交的字段
  359. var userdata = "";
  360. for (var prop in field) {
  361. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  362. }
  363. //提交 Ajax 成功后,静态更新表格中的数据
  364. //$.ajax({});
  365. $.ajax({
  366. type: "POST",
  367. url: "/Admin/Leaders/Add?r=" + Math.random(1),
  368. data: userdata,
  369. dataType: "text",
  370. success: function (data) {
  371. layer.close(index); //关闭弹层
  372. if (data == "success") {
  373. table.reload('LAY-list-manage'); //数据刷新
  374. } else {
  375. layer.msg(data);
  376. }
  377. }
  378. });
  379. });
  380. submit.trigger('click');
  381. }
  382. });
  383. layer.full(perContent);
  384. }
  385. , ImportData: function () {
  386. ExcelKind = 1;
  387. layer.open({
  388. type: 1,
  389. title: '导入',
  390. maxmin: false,
  391. area: ['460px', '280px'],
  392. content: $('#excelForm'),
  393. cancel: function () {
  394. }
  395. });
  396. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  397. }
  398. , ExportExcel: function () {
  399. var userdata = '';
  400. $(".layuiadmin-card-header-auto input").each(function (i) {
  401. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  402. });
  403. $(".layuiadmin-card-header-auto select").each(function (i) {
  404. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  405. });
  406. // $.ajax({
  407. // type: "GET",
  408. // url: "/Admin/Leaders/ExportExcel?r=" + Math.random(1),
  409. // data: userdata,
  410. // dataType: "json",
  411. // success: function (data) {
  412. // data.Obj.unshift(data.Fields);
  413. // excel.exportExcel(data.Obj, data.Info, 'xlsx');
  414. // }
  415. // });
  416. var index = layer.confirm('确定导出吗?', function (index) {
  417. var indexs = layer.load(1, {
  418. shade: [0.5, '#000']
  419. });
  420. $.ajax({
  421. type: "POST",
  422. url: "/Admin/Leaders/QuickExportExcelDo?r=" + Math.random(1),
  423. data: userdata,
  424. dataType: "text",
  425. success: function (data) {
  426. layer.close(index); //关闭弹层
  427. if (data == "success") {
  428. layer.close(indexs); //关闭弹层
  429. layer.msg('导出成功,请到我的下载中点击下载文件', {
  430. time: 1000
  431. }, function () {
  432. window.location.reload();
  433. });
  434. } else {
  435. layer.close(indexs); //关闭弹层
  436. layer.msg(data);
  437. }
  438. }
  439. });
  440. });
  441. }
  442. , Open: function () {
  443. var checkStatus = table.checkStatus('LAY-list-manage')
  444. , data = checkStatus.data; //得到选中的数据
  445. if (data.length < 1) {
  446. parent.layer.msg("请选择要开启的项");
  447. } else {
  448. var ids = "";
  449. $.each(data, function (index, value) {
  450. ids += data[index].Id + ",";
  451. });
  452. ids = ids.substring(0, ids.length - 1);
  453. var index = layer.confirm('确定要开启吗?', function (index) {
  454. $.ajax({
  455. type: "POST",
  456. url: "/Admin/Leaders/Open?r=" + Math.random(1),
  457. data: "Id=" + ids,
  458. dataType: "text",
  459. success: function (data) {
  460. layer.close(index);
  461. if (data == "success") {
  462. table.reload('LAY-list-manage');
  463. } else {
  464. layer.msg(data);
  465. }
  466. }
  467. });
  468. });
  469. }
  470. }
  471. , Close: function () {
  472. var checkStatus = table.checkStatus('LAY-list-manage')
  473. , data = checkStatus.data; //得到选中的数据
  474. if (data.length < 1) {
  475. parent.layer.msg("请选择要关闭的项");
  476. } else {
  477. var ids = "";
  478. $.each(data, function (index, value) {
  479. ids += data[index].Id + ",";
  480. });
  481. ids = ids.substring(0, ids.length - 1);
  482. var index = layer.confirm('确定要关闭吗?', function (index) {
  483. $.ajax({
  484. type: "POST",
  485. url: "/Admin/Leaders/Close?r=" + Math.random(1),
  486. data: "Id=" + ids,
  487. dataType: "text",
  488. success: function (data) {
  489. layer.close(index);
  490. if (data == "success") {
  491. table.reload('LAY-list-manage');
  492. } else {
  493. layer.msg(data);
  494. }
  495. }
  496. });
  497. });
  498. }
  499. }
  500. };
  501. $('.layui-btn').on('click', function () {
  502. var type = $(this).data('type');
  503. active[type] ? active[type].call(this) : '';
  504. });
  505. });