Leaders_Admin.js 18 KB

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