ToChargeBackRecord_Admin.js 22 KB

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