SysAdminOperate_Admin.js 22 KB

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