UserAccount_Admin.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/UserAccount/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 layCreateDate = laydate.render({
  34. elem: '#CreateDate',
  35. type: 'date',
  36. range: true,
  37. trigger: 'click',
  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. layCreateDate.hint('日期范围请不要超过1个月');
  44. setTimeout(function () {
  45. $(".laydate-btns-confirm").addClass("laydate-disabled");
  46. }, 1);
  47. }
  48. } else {
  49. op = false;
  50. layCreateDate.hint('日期范围请不要超过1个月');
  51. setTimeout(function () {
  52. $(".laydate-btns-confirm").addClass("laydate-disabled");
  53. }, 1);
  54. }
  55. if (op) {
  56. $('#CreateDate').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/UserAccount/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/UserAccount/IndexData' //模拟接口
  89. ,
  90. cols: [
  91. [{
  92. type: 'checkbox',
  93. fixed: 'left'
  94. },
  95. { field: 'MakerCode', width: 200, title: '创客编号' ,sort: true},
  96. { field: 'RealName', width: 200, title: '创客姓名' ,sort: true},
  97. { field: 'TopMakerCode', width: 200, title: '顶级创客编号' ,sort: true},
  98. { field: 'TopRealName', width: 200, title: '顶级创客姓名' ,sort: true},
  99. { field: 'TotalAmount', width: 200, title: '账户总金额' ,sort: true},
  100. { field: 'FreezeAmount', width: 200, title: '冻结金额' ,sort: true},
  101. { field: 'BalanceAmount', width: 200, title: '余额' ,sort: true},
  102. { field: 'AccountStatusName', width: 200, title: '账户状态' ,sort: true},
  103. { field: 'CreateDate', width: 200, title: '创建时间' ,sort: true},
  104. {
  105. title: '操作',
  106. width: 200,
  107. align: 'center',
  108. fixed: 'right',
  109. toolbar: '#table-list-tools'
  110. }
  111. ]
  112. ],
  113. where: {
  114. UserId: UserId
  115. },
  116. page: true,
  117. limit: 30,
  118. height: 'full-' + String($('.layui-card-header').height() + 130),
  119. text: '对不起,加载出现异常!',
  120. done: function (res, curr, count) {
  121. $("#TotalAmount").text(res.other.TotalAmount.toFixed(2));
  122. $("#FreezeAmount").text(res.other.FreezeAmount.toFixed(2));
  123. $("#BalanceAmount").text(res.other.BalanceAmount.toFixed(2));
  124. $(".layui-none").text("无数据");
  125. }
  126. });
  127. //监听工具条
  128. table.on('tool(LAY-list-manage)', function (obj) {
  129. var data = obj.data;
  130. if (obj.event === 'del') {
  131. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  132. $.ajax({
  133. type: "POST",
  134. url: "/Admin/UserAccount/Delete?r=" + Math.random(1),
  135. data: "Id=" + data.Id,
  136. dataType: "text",
  137. success: function (data) {
  138. if (data == "success") {
  139. obj.del();
  140. layer.close(index);
  141. } else {
  142. parent.layer.msg(data);
  143. }
  144. }
  145. });
  146. });
  147. } else if (obj.event === 'edit') {
  148. var tr = $(obj.tr);
  149. var perContent = layer.open({
  150. type: 2,
  151. title: '创客账户-编辑',
  152. content: 'Edit?Id=' + data.Id + '',
  153. maxmin: true,
  154. area: ['500px', '450px'],
  155. btn: ['确定', '取消'],
  156. yes: function (index, layero) {
  157. var iframeWindow = window['layui-layer-iframe' + index],
  158. submitID = 'LAY-list-front-submit',
  159. submit = layero.find('iframe').contents().find('#' + submitID);
  160. setTimeout(function () {
  161. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  162. var errObj = $(this).find('.layui-form-danger');
  163. if (errObj.length > 0) {
  164. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  165. submit.click();
  166. }
  167. });
  168. }, 300);
  169. //监听提交
  170. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  171. var field = data.field; //获取提交的字段
  172. var userdata = "";
  173. for (var prop in field) {
  174. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  175. }
  176. //提交 Ajax 成功后,静态更新表格中的数据
  177. //$.ajax({});
  178. $.ajax({
  179. type: "POST",
  180. url: "/Admin/UserAccount/Edit?r=" + Math.random(1),
  181. data: userdata,
  182. dataType: "text",
  183. success: function (data) {
  184. layer.close(index); //关闭弹层
  185. if (data == "success") {
  186. table.reload('LAY-list-manage'); //数据刷新
  187. } else {
  188. layer.msg(data);
  189. }
  190. }
  191. });
  192. });
  193. submit.trigger('click');
  194. },
  195. success: function (layero, index) {
  196. }
  197. });
  198. layer.full(perContent);
  199. } else if (obj.event === 'Open') {
  200. var index = layer.confirm('是否确定解冻' + data.RealName + '的账户,恢复他提现?', function (index) {
  201. $.ajax({
  202. type: "POST",
  203. url: "/Admin/UserAccount/Open?r=" + Math.random(1),
  204. data: "Id=" + data.Id,
  205. dataType: "text",
  206. success: function (data) {
  207. layer.close(index); //关闭弹层
  208. if (data == "success") {
  209. layer.msg("已解冻", { time: 1500 }, function () {
  210. table.reload('LAY-list-manage'); //数据刷新
  211. });
  212. } else {
  213. parent.layer.msg(data);
  214. }
  215. }
  216. });
  217. });
  218. } else if (obj.event === 'Close') {
  219. var index = layer.confirm('是否确定冻结' + data.RealName + '的账户,禁止他提现?', function (index) {
  220. $.ajax({
  221. type: "POST",
  222. url: "/Admin/UserAccount/Close?r=" + Math.random(1),
  223. data: "Id=" + data.Id,
  224. dataType: "text",
  225. success: function (data) {
  226. layer.close(index); //关闭弹层
  227. if (data == "success") {
  228. layer.msg("已冻结", { time: 1500 }, function () {
  229. table.reload('LAY-list-manage'); //数据刷新
  230. });
  231. } else {
  232. parent.layer.msg(data);
  233. }
  234. }
  235. });
  236. });
  237. }
  238. });
  239. //监听搜索
  240. form.on('submit(LAY-list-front-search)', function (data) {
  241. var field = data.field;
  242. //执行重载
  243. table.reload('LAY-list-manage', {
  244. where: field
  245. });
  246. });
  247. form.on('submit(LAY-list-front-searchall)', function (data) {
  248. table.reload('LAY-list-manage', {
  249. where: {
  250. UserId: UserId
  251. }
  252. });
  253. });
  254. //事件
  255. var active = {
  256. batchdel: function () {
  257. var checkStatus = table.checkStatus('LAY-list-manage'),
  258. data = checkStatus.data; //得到选中的数据
  259. if (data.length < 1) {
  260. parent.layer.msg("请选择要删除的项");
  261. } else {
  262. var ids = "";
  263. $.each(data, function (index, value) {
  264. ids += data[index].Id + ",";
  265. });
  266. ids = ids.substring(0, ids.length - 1);
  267. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  268. $.ajax({
  269. type: "POST",
  270. url: "/Admin/UserAccount/Delete?r=" + Math.random(1),
  271. data: "Id=" + ids,
  272. dataType: "text",
  273. success: function (data) {
  274. layer.close(index);
  275. if (data == "success") {
  276. table.reload('LAY-list-manage');
  277. } else {
  278. layer.msg(data);
  279. }
  280. }
  281. });
  282. });
  283. }
  284. },
  285. add: function () {
  286. var perContent = layer.open({
  287. type: 2,
  288. title: '创客账户-添加',
  289. content: 'Add',
  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/UserAccount/Add?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. });
  333. layer.full(perContent);
  334. },
  335. ImportData: function () {
  336. layer.open({
  337. type: 1,
  338. title: '导入',
  339. maxmin: false,
  340. area: ['460px', '180px'],
  341. content: $('#excelForm'),
  342. cancel: function () {}
  343. });
  344. },
  345. ExportExcel: function () {
  346. var userdata = $('#QueryForm').serialize();
  347. $.ajax({
  348. type: "POST",
  349. url: "/Admin/UserAccount/ExportExcel?r=" + Math.random(1),
  350. data: userdata,
  351. dataType: "json",
  352. success: function (data) {
  353. data.Obj.unshift(data.Fields);
  354. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  355. }
  356. });
  357. },
  358. Open: 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/UserAccount/Open?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. Close: function () {
  388. var checkStatus = table.checkStatus('LAY-list-manage'),
  389. data = checkStatus.data; //得到选中的数据
  390. if (data.length < 1) {
  391. parent.layer.msg("请选择要关闭的项");
  392. } else {
  393. var ids = "";
  394. $.each(data, function (index, value) {
  395. ids += data[index].Id + ",";
  396. });
  397. ids = ids.substring(0, ids.length - 1);
  398. var index = layer.confirm('确定要关闭吗?', function (index) {
  399. $.ajax({
  400. type: "POST",
  401. url: "/Admin/UserAccount/Close?r=" + Math.random(1),
  402. data: "Id=" + ids,
  403. dataType: "text",
  404. success: function (data) {
  405. layer.close(index);
  406. if (data == "success") {
  407. table.reload('LAY-list-manage');
  408. } else {
  409. layer.msg(data);
  410. }
  411. }
  412. });
  413. });
  414. }
  415. }
  416. };
  417. $('.layui-btn').on('click', function () {
  418. var type = $(this).data('type');
  419. active[type] ? active[type].call(this) : '';
  420. });
  421. });