ToChargeBackRecord_Admin.js 22 KB

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