ToChargeBackRecord_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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: 'KindName', width: 200, title: '扣款类别', sort: true }
  151. , { field: 'UpdateDate', width: 200, title: '扣款/更新时间', sort: true }
  152. , { field: 'StatusName', width: 200, title: '扣款状态', sort: true }
  153. , { field: 'Remark', 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. layer.close(index); //关闭弹层
  368. if (data == "success") {
  369. table.reload('LAY-list-manage'); //数据刷新
  370. } else {
  371. layer.msg(data);
  372. }
  373. }
  374. });
  375. }
  376. });
  377. submit.trigger('click');
  378. }
  379. });
  380. layer.full(perContent);
  381. }
  382. , ChargeImport: function () {
  383. ExcelKind = 1;
  384. layer.open({
  385. type: 1,
  386. title: '导入',
  387. maxmin: false,
  388. area: ['460px', '280px'],
  389. content: $('#excelForm'),
  390. cancel: function () {
  391. }
  392. });
  393. $("#excelTemp").html('<a href="/users/预扣款模版.xlsx">点击下载预扣款模版文件</a>');
  394. }
  395. , ImportData: function () {
  396. ExcelKind = 1;
  397. layer.open({
  398. type: 1,
  399. title: '导入',
  400. maxmin: false,
  401. area: ['460px', '280px'],
  402. content: $('#excelForm'),
  403. cancel: function () {
  404. }
  405. });
  406. $("#excelTemp").html('<a href="/users/机具扣款退还模版.xlsx">点击下载机具扣款退还模版文件</a>');
  407. }
  408. , ImportDatas: function () {
  409. ExcelKind = 1;
  410. layer.open({
  411. type: 1,
  412. title: '导入',
  413. maxmin: false,
  414. area: ['460px', '280px'],
  415. content: $('#excelForm'),
  416. cancel: function () {
  417. }
  418. });
  419. $("#excelTemp").html('<a href="/users/机具扣款退还模版.xlsx">点击下载机具扣款退还模版文件</a>');
  420. }
  421. , ExportExcel: function () {
  422. var userdata = '';
  423. $(".layuiadmin-card-header-auto input").each(function (i) {
  424. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  425. });
  426. $(".layuiadmin-card-header-auto select").each(function (i) {
  427. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  428. });
  429. // $.ajax({
  430. // type: "GET",
  431. // url: "/Admin/ToChargeBackRecord/ExportExcel?r=" + Math.random(1),
  432. // data: userdata,
  433. // dataType: "json",
  434. // success: function (data) {
  435. // data.Obj.unshift(data.Fields);
  436. // excel.exportExcel(data.Obj, data.Info, 'xlsx');
  437. // }
  438. // });
  439. var index = layer.confirm('确定导出吗?', function (index) {
  440. var indexs = layer.load(1, {
  441. shade: [0.5, '#000']
  442. });
  443. $.ajax({
  444. type: "POST",
  445. url: "/Admin/ToChargeBackRecord/QuickExportExcelDo?r=" + Math.random(1),
  446. data: userdata,
  447. dataType: "text",
  448. success: function (data) {
  449. layer.close(index); //关闭弹层
  450. if (data == "success") {
  451. layer.close(indexs); //关闭弹层
  452. layer.msg('导出成功,请到我的下载中点击下载文件', {
  453. time: 1000
  454. }, function () {
  455. window.location.reload();
  456. });
  457. } else {
  458. layer.close(indexs); //关闭弹层
  459. layer.msg(data);
  460. }
  461. }
  462. });
  463. });
  464. }
  465. , Open: function () {
  466. var checkStatus = table.checkStatus('LAY-list-manage')
  467. , data = checkStatus.data; //得到选中的数据
  468. if (data.length < 1) {
  469. parent.layer.msg("请选择要开启的项");
  470. } else {
  471. var ids = "";
  472. $.each(data, function (index, value) {
  473. ids += data[index].Id + ",";
  474. });
  475. ids = ids.substring(0, ids.length - 1);
  476. var index = layer.confirm('确定要开启吗?', function (index) {
  477. $.ajax({
  478. type: "POST",
  479. url: "/Admin/ToChargeBackRecord/Open?r=" + Math.random(1),
  480. data: "Id=" + ids,
  481. dataType: "text",
  482. success: function (data) {
  483. layer.close(index);
  484. if (data == "success") {
  485. table.reload('LAY-list-manage');
  486. } else {
  487. layer.msg(data);
  488. }
  489. }
  490. });
  491. });
  492. }
  493. }
  494. , Close: function () {
  495. var checkStatus = table.checkStatus('LAY-list-manage')
  496. , data = checkStatus.data; //得到选中的数据
  497. if (data.length < 1) {
  498. parent.layer.msg("请选择要关闭的项");
  499. } else {
  500. var ids = "";
  501. $.each(data, function (index, value) {
  502. ids += data[index].Id + ",";
  503. });
  504. ids = ids.substring(0, ids.length - 1);
  505. var index = layer.confirm('确定要关闭吗?', function (index) {
  506. $.ajax({
  507. type: "POST",
  508. url: "/Admin/ToChargeBackRecord/Close?r=" + Math.random(1),
  509. data: "Id=" + ids,
  510. dataType: "text",
  511. success: function (data) {
  512. layer.close(index);
  513. if (data == "success") {
  514. table.reload('LAY-list-manage');
  515. } else {
  516. layer.msg(data);
  517. }
  518. }
  519. });
  520. });
  521. }
  522. }
  523. };
  524. $('.layui-btn').on('click', function () {
  525. var type = $(this).data('type');
  526. active[type] ? active[type].call(this) : '';
  527. });
  528. });