SysAdminOperate_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. var ExcelData;
  2. var clickflag = 0;
  3. function ConfirmImport() {
  4. $.ajax({
  5. type: "POST",
  6. url: "/Admin/SysAdminOperate/Import?r=" + Math.random(1),
  7. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  8. dataType: "text",
  9. success: function (data) {
  10. if (data == "success") {
  11. layer.msg("导入成功", {
  12. time: 2000
  13. }, function () {
  14. window.location.reload();
  15. });
  16. } else {
  17. layer.msg(data);
  18. }
  19. }
  20. });
  21. }
  22. var excel;
  23. layui.config({
  24. base: '/layuiadmin/' //静态资源所在路径
  25. }).extend({
  26. myexcel: 'layui/lay/modules/excel',
  27. index: 'lib/index' //主入口模块
  28. }).use(['index', 'table', 'excel', 'laydate'], function () {
  29. var $ = layui.$,
  30. form = layui.form,
  31. table = layui.table;
  32. //- 筛选条件-日期
  33. var laydate = layui.laydate;
  34. var layCreateDateData = laydate.render({
  35. elem: '#CreateDateData',
  36. trigger: 'click',
  37. type: 'date',
  38. range: true,
  39. change: function (value, date, endDate) {
  40. var op = true;
  41. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  42. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  43. op = false;
  44. layCreateDateData.hint('日期范围请不要超过1个月');
  45. setTimeout(function () {
  46. $(".laydate-btns-confirm").addClass("laydate-disabled");
  47. }, 1);
  48. }
  49. } else {
  50. op = false;
  51. layCreateDateData.hint('日期范围请不要超过1个月');
  52. setTimeout(function () {
  53. $(".laydate-btns-confirm").addClass("laydate-disabled");
  54. }, 1);
  55. }
  56. if (op) {
  57. $('#CreateDateData').val(value);
  58. }
  59. }
  60. });
  61. //excel导入
  62. excel = layui.excel;
  63. $('#ExcelFile').change(function (e) {
  64. var files = e.target.files;
  65. excel.importExcel(files, {}, function (data) {
  66. ExcelData = data[0].sheet1;
  67. });
  68. });
  69. //监听单元格编辑
  70. table.on('edit(LAY-list-manage)', function (obj) {
  71. var value = obj.value //得到修改后的值
  72. ,
  73. data = obj.data //得到所在行所有键值
  74. ,
  75. field = obj.field; //得到字段
  76. if (field == "Sort") {
  77. $.ajax({
  78. type: "POST",
  79. url: "/Admin/SysAdminOperate/Sort?r=" + Math.random(1),
  80. data: "Id=" + data.Id + "&Sort=" + value,
  81. dataType: "text",
  82. success: function (data) { }
  83. });
  84. }
  85. });
  86. //列表数据
  87. table.render({
  88. elem: '#LAY-list-manage',
  89. url: '/Admin/SysAdminOperate/IndexData' //模拟接口
  90. ,
  91. cols: [
  92. [{
  93. type: 'checkbox',
  94. fixed: 'left'
  95. }, {
  96. field: 'Id',
  97. fixed: 'left',
  98. title: 'ID',
  99. width: 80,
  100. sort: true,
  101. unresize: true
  102. }, {
  103. field: 'OpCode',
  104. title: '运营中心编号',
  105. sort: true
  106. }, {
  107. field: 'LoginUrl',
  108. title: '登陆地址',
  109. sort: true
  110. }, {
  111. field: 'RealName',
  112. title: '名称',
  113. sort: true
  114. }, {
  115. field: 'MakerCode',
  116. title: '所属创客编号',
  117. sort: true
  118. }, {
  119. field: 'MakerName',
  120. title: '所属真实姓名',
  121. sort: true
  122. }, {
  123. field: 'CreateDate',
  124. title: '创建时间',
  125. sort: true
  126. }, {
  127. field: 'TotalAmt',
  128. title: '实缴额度',
  129. sort: true
  130. }, {
  131. field: 'ValidAmount',
  132. title: '当前额度',
  133. sort: true
  134. }, {
  135. field: 'WithdrawAmount',
  136. title: '已提现金额',
  137. sort: true
  138. }, {
  139. field: 'WithdrawingAmount',
  140. title: '提现中金额',
  141. sort: true
  142. }, {
  143. field: 'StoreCount',
  144. title: '分仓数量',
  145. sort: true
  146. }
  147. // , { field: 'Role', title: '角色', sort: true }
  148. // , { field: 'LastLoginDate', title: '最后登录时间', sort: true }
  149. // , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  150. , {
  151. title: '操作',
  152. align: 'center',
  153. width: 400,
  154. fixed: 'right',
  155. toolbar: '#table-list-tools'
  156. }
  157. ]
  158. ],
  159. where: {
  160. },
  161. page: true,
  162. limit: 30,
  163. height: 'full-' + String($('.layui-card-header').height() + 130),
  164. text: '对不起,加载出现异常!',
  165. done: function (res, curr, count) {
  166. $(".layui-none").text("无数据");
  167. }
  168. });
  169. //监听工具条
  170. table.on('tool(LAY-list-manage)', function (obj) {
  171. var data = obj.data;
  172. if (obj.event === 'del') {
  173. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  174. $.ajax({
  175. type: "POST",
  176. url: "/Admin/SysAdminOperate/Delete?r=" + Math.random(1),
  177. data: "Id=" + data.Id,
  178. dataType: "text",
  179. success: function (data) {
  180. if (data == "success") {
  181. obj.del();
  182. layer.close(index);
  183. } else {
  184. parent.layer.msg(data);
  185. }
  186. }
  187. });
  188. });
  189. } else if (obj.event === 'EditAmt') {
  190. var tr = $(obj.tr);
  191. var perContent = layer.open({
  192. type: 2,
  193. title: '修改运营中心可用金额',
  194. content: 'EditAmt?Id=' + data.Id,
  195. maxmin: false,
  196. area: ['550px', '550px'],
  197. btn: ['确定', '取消'],
  198. yes: function (index, layero) {
  199. var iframeWindow = window['layui-layer-iframe' + index],
  200. submitID = 'LAY-list-front-submit',
  201. submit = layero.find('iframe').contents().find('#' + submitID);
  202. //监听提交
  203. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  204. if (clickflag == 0) {
  205. clickflag = 1;
  206. var field = data.field; //获取提交的字段
  207. var userdata = "";
  208. for (var prop in field) {
  209. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  210. }
  211. //提交 Ajax 成功后,静态更新表格中的数据
  212. //$.ajax({});
  213. $.ajax({
  214. type: "POST",
  215. url: "/Admin/SysAdminOperate/EditAmt?r=" + Math.random(1),
  216. data: userdata,
  217. dataType: "text",
  218. success: function (data) {
  219. clickflag = 0;
  220. layer.close(index); //关闭弹层
  221. if (data == "success") {
  222. layer.msg("保存成功", {
  223. time: 1500
  224. }, function () {
  225. table.reload('LAY-list-manage'); //数据刷新
  226. });
  227. } else {
  228. layer.msg(data);
  229. }
  230. }
  231. });
  232. }
  233. });
  234. submit.trigger('click');
  235. },
  236. success: function (layero, index) {
  237. }
  238. });
  239. } else if (obj.event === 'EditBalance') {
  240. var tr = $(obj.tr);
  241. var perContent = layer.open({
  242. type: 2,
  243. title: '修改运营中心金额',
  244. content: 'EditBalance?Id=' + data.Id,
  245. maxmin: false,
  246. area: ['550px', '550px'],
  247. btn: ['确定', '取消'],
  248. yes: function (index, layero) {
  249. var iframeWindow = window['layui-layer-iframe' + index],
  250. submitID = 'LAY-list-front-submit',
  251. submit = layero.find('iframe').contents().find('#' + submitID);
  252. //监听提交
  253. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  254. if (clickflag == 0) {
  255. clickflag = 1;
  256. var field = data.field; //获取提交的字段
  257. var userdata = "";
  258. for (var prop in field) {
  259. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  260. }
  261. //提交 Ajax 成功后,静态更新表格中的数据
  262. //$.ajax({});
  263. $.ajax({
  264. type: "POST",
  265. url: "/Admin/SysAdminOperate/EditBalance?r=" + Math.random(1),
  266. data: userdata,
  267. dataType: "text",
  268. success: function (data) {
  269. clickflag = 0;
  270. layer.close(index); //关闭弹层
  271. if (data == "success") {
  272. layer.msg("保存成功", {
  273. time: 1500
  274. }, function () {
  275. table.reload('LAY-list-manage'); //数据刷新
  276. });
  277. } else {
  278. layer.msg(data);
  279. }
  280. }
  281. });
  282. }
  283. });
  284. submit.trigger('click');
  285. },
  286. success: function (layero, index) {
  287. }
  288. });
  289. } else if (obj.event === 'edit') {
  290. var tr = $(obj.tr);
  291. var perContent = layer.open({
  292. type: 2,
  293. title: '后台管理员-编辑',
  294. content: 'Edit?Id=' + data.Id + '',
  295. maxmin: true,
  296. area: ['500px', '450px'],
  297. btn: ['确定', '取消'],
  298. yes: function (index, layero) {
  299. var iframeWindow = window['layui-layer-iframe' + index],
  300. submitID = 'LAY-list-front-submit',
  301. submit = layero.find('iframe').contents().find('#' + submitID);
  302. setTimeout(function () {
  303. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  304. var errObj = $(this).find('.layui-form-danger');
  305. if (errObj.length > 0) {
  306. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  307. submit.click();
  308. }
  309. });
  310. }, 300);
  311. //监听提交
  312. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  313. var field = data.field; //获取提交的字段
  314. var userdata = "";
  315. for (var prop in field) {
  316. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  317. }
  318. //提交 Ajax 成功后,静态更新表格中的数据
  319. //$.ajax({});
  320. $.ajax({
  321. type: "POST",
  322. url: "/Admin/SysAdminOperate/Edit?r=" + Math.random(1),
  323. data: userdata,
  324. dataType: "text",
  325. success: function (data) {
  326. layer.close(index); //关闭弹层
  327. if (data == "success") {
  328. table.reload('LAY-list-manage'); //数据刷新
  329. } else {
  330. layer.msg(data);
  331. }
  332. }
  333. });
  334. });
  335. submit.trigger('click');
  336. },
  337. success: function (layero, index) {
  338. }
  339. });
  340. layer.full(perContent);
  341. }
  342. });
  343. //监听搜索
  344. form.on('submit(LAY-list-front-search)', function (data) {
  345. var field = data.field;
  346. //执行重载
  347. table.reload('LAY-list-manage', {
  348. where: field
  349. });
  350. });
  351. form.on('submit(LAY-list-front-searchall)', function (data) {
  352. table.reload('LAY-list-manage', {
  353. where: null
  354. });
  355. });
  356. //事件
  357. var active = {
  358. batchdel: function () {
  359. var checkStatus = table.checkStatus('LAY-list-manage'),
  360. data = checkStatus.data; //得到选中的数据
  361. if (data.length < 1) {
  362. parent.layer.msg("请选择要删除的项");
  363. } else {
  364. var ids = "";
  365. $.each(data, function (index, value) {
  366. ids += data[index].Id + ",";
  367. });
  368. ids = ids.substring(0, ids.length - 1);
  369. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  370. $.ajax({
  371. type: "POST",
  372. url: "/Admin/SysAdminOperate/Delete?r=" + Math.random(1),
  373. data: "Id=" + ids,
  374. dataType: "text",
  375. success: function (data) {
  376. layer.close(index);
  377. if (data == "success") {
  378. table.reload('LAY-list-manage');
  379. } else {
  380. layer.msg(data);
  381. }
  382. }
  383. });
  384. });
  385. }
  386. },
  387. add: function () {
  388. var perContent = layer.open({
  389. type: 2,
  390. title: '后台管理员-添加',
  391. content: 'Add',
  392. maxmin: true,
  393. area: ['500px', '450px'],
  394. btn: ['确定', '取消'],
  395. yes: function (index, layero) {
  396. var iframeWindow = window['layui-layer-iframe' + index],
  397. submitID = 'LAY-list-front-submit',
  398. submit = layero.find('iframe').contents().find('#' + submitID);
  399. setTimeout(function () {
  400. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  401. var errObj = $(this).find('.layui-form-danger');
  402. if (errObj.length > 0) {
  403. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  404. submit.click();
  405. }
  406. });
  407. }, 300);
  408. //监听提交
  409. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  410. var field = data.field; //获取提交的字段
  411. var userdata = "";
  412. for (var prop in field) {
  413. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  414. }
  415. //提交 Ajax 成功后,静态更新表格中的数据
  416. //$.ajax({});
  417. $.ajax({
  418. type: "POST",
  419. url: "/Admin/SysAdminOperate/Add?r=" + Math.random(1),
  420. data: userdata,
  421. dataType: "text",
  422. success: function (data) {
  423. layer.close(index); //关闭弹层
  424. if (data == "success") {
  425. layer.msg("添加成功", { time: 1500 }, function () {
  426. table.reload('LAY-list-manage'); //数据刷新
  427. });
  428. } else {
  429. layer.msg(data);
  430. }
  431. }
  432. });
  433. });
  434. submit.trigger('click');
  435. }
  436. });
  437. layer.full(perContent);
  438. },
  439. ImportData: function () {
  440. layer.open({
  441. type: 1,
  442. title: '导入',
  443. maxmin: false,
  444. area: ['460px', '180px'],
  445. content: $('#excelForm'),
  446. cancel: function () { }
  447. });
  448. },
  449. ExportExcel: function () {
  450. var userdata = '';
  451. $(".layuiadmin-card-header-auto input").each(function (i) {
  452. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  453. });
  454. $(".layuiadmin-card-header-auto select").each(function (i) {
  455. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  456. });
  457. $.ajax({
  458. type: "GET",
  459. url: "/Admin/SysAdminOperate/ExportExcel?r=" + Math.random(1),
  460. data: userdata,
  461. dataType: "json",
  462. success: function (data) {
  463. data.Obj.unshift(data.Fields);
  464. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  465. }
  466. });
  467. },
  468. Open: function () {
  469. var checkStatus = table.checkStatus('LAY-list-manage'),
  470. data = checkStatus.data; //得到选中的数据
  471. if (data.length < 1) {
  472. parent.layer.msg("请选择要开启的项");
  473. } else {
  474. var ids = "";
  475. $.each(data, function (index, value) {
  476. ids += data[index].Id + ",";
  477. });
  478. ids = ids.substring(0, ids.length - 1);
  479. var index = layer.confirm('确定要开启吗?', function (index) {
  480. $.ajax({
  481. type: "POST",
  482. url: "/Admin/SysAdminOperate/Open?r=" + Math.random(1),
  483. data: "Id=" + ids,
  484. dataType: "text",
  485. success: function (data) {
  486. layer.close(index);
  487. if (data == "success") {
  488. table.reload('LAY-list-manage');
  489. } else {
  490. layer.msg(data);
  491. }
  492. }
  493. });
  494. });
  495. }
  496. },
  497. Close: function () {
  498. var checkStatus = table.checkStatus('LAY-list-manage'),
  499. data = checkStatus.data; //得到选中的数据
  500. if (data.length < 1) {
  501. parent.layer.msg("请选择要关闭的项");
  502. } else {
  503. var ids = "";
  504. $.each(data, function (index, value) {
  505. ids += data[index].Id + ",";
  506. });
  507. ids = ids.substring(0, ids.length - 1);
  508. var index = layer.confirm('确定要关闭吗?', function (index) {
  509. $.ajax({
  510. type: "POST",
  511. url: "/Admin/SysAdminOperate/Close?r=" + Math.random(1),
  512. data: "Id=" + ids,
  513. dataType: "text",
  514. success: function (data) {
  515. layer.close(index);
  516. if (data == "success") {
  517. table.reload('LAY-list-manage');
  518. } else {
  519. layer.msg(data);
  520. }
  521. }
  522. });
  523. });
  524. }
  525. }
  526. };
  527. $('.layui-btn').on('click', function () {
  528. var type = $(this).data('type');
  529. active[type] ? active[type].call(this) : '';
  530. });
  531. });