Users_City_Admin.js 26 KB

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