Leaders_Admin.js 20 KB

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