deduction_cpa_list.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () {
  2. let table = layui.table;
  3. let $ = layui.jquery;
  4. let admin = layui.madmin;
  5. let layer = layui.layer;
  6. let form = layui.form;
  7. let common = layui.common;
  8. let mhttp = layui.mhttp;
  9. admin.getConfig();
  10. let cols = [
  11. [
  12. {
  13. title: 'UID',
  14. field: 'uid',
  15. align: 'center'
  16. },
  17. {
  18. title: '所属应用',
  19. field: 'app_name',
  20. align: 'center',
  21. },
  22. {
  23. title: '扣量比例',
  24. field: 'deduction_pro',
  25. align: 'center',
  26. },
  27. {
  28. title: '操作',
  29. align: 'center',
  30. toolbar: '#deduction-bar'
  31. }
  32. ]
  33. ];
  34. let search = httpRequestPostData({
  35. deduction_type:'cpa',
  36. });
  37. table.render({
  38. elem: '#deduction-table',
  39. method: 'POST',
  40. request: {
  41. pageName: 'page',
  42. limitName: 'page_size'
  43. },
  44. async: false,
  45. headers: {
  46. "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? ''
  47. },
  48. contentType: 'application/json',
  49. url: getMyApiUrl('/deduction/lists'),
  50. limit: 20,
  51. limits: [20, 30, 40, 50, 80, 100],
  52. parseData: function (res) {
  53. return httpRequestPagesParseData(res);
  54. },
  55. response: {
  56. "statusCode": 200,
  57. },
  58. where:search,
  59. done: function (data, page, total) {
  60. var intCode = parseInt(data.code);
  61. if (intCode === 403) {
  62. cbRespnseRedirectLogin(data);
  63. } else if (intCode === 401) {
  64. // 仅仅是过期了,这里可以有其他逻辑补偿.
  65. // 暂时跳到登陆页面
  66. cbRespnse401(data);
  67. }
  68. onloadRender();
  69. },
  70. error: function (obj, message) {
  71. cbRespnseReloadPage(obj, message);
  72. },
  73. page: true,
  74. cols: cols,
  75. skin: 'line',
  76. toolbar: '#deduction-toolbar',
  77. defaultToolbar: [{
  78. title: '刷新',
  79. layEvent: 'refresh',
  80. icon: 'layui-icon-refresh',
  81. }, 'filter', 'print', 'exports']
  82. });
  83. table.on('toolbar(deduction-table)', function (obj) {
  84. if (obj.event === 'add') {
  85. window.add();
  86. } else if (obj.event === 'refresh') {
  87. window.refresh();
  88. }
  89. });
  90. window.add = function () {
  91. layer.open({
  92. id: 'deduction_create',
  93. type: 2,
  94. title: '添加',
  95. shade: 0.1,
  96. offset: '20px',
  97. area: ['410px', '450px'],
  98. maxWidth: 500,
  99. maxHeight: 600,
  100. scrollbar: true,
  101. content: 'deduction_cpa_create.html',
  102. });
  103. }
  104. // 表单内
  105. table.on('tool(deduction-table)', function (obj) {
  106. if (obj.event === 'remove') {
  107. window.remove(obj);
  108. } else if (obj.event === 'edit') {
  109. window.edit(obj);
  110. }
  111. });
  112. window.edit = function (obj) {
  113. layer.open({
  114. id: 'deduction-edit',
  115. type: 2,
  116. title: '修改',
  117. shade: 0.1,
  118. offset: '20px',
  119. area: ['410px', '500px'],
  120. maxWidth: 500,
  121. maxHeight: 600,
  122. scrollbar: true,
  123. content: 'deduction_cpa_edit.html?uid=' + obj.data.uid,
  124. });
  125. }
  126. // 删除
  127. window.remove = function (obj) {
  128. layer.confirm('确定要删除:' + obj.data.uid + '?', {
  129. icon: 3,
  130. title: '提示'
  131. }, function () {
  132. let deleteLoading = layer.msg('操作数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
  133. let postData = {
  134. uid: obj.data.uid
  135. };
  136. let ret = mhttp.ajax({
  137. url: '/deduction/delete',
  138. data: postData,
  139. });
  140. ret.then((data) => {
  141. layer.close(deleteLoading);
  142. if (data.code === 200) {
  143. layer.msg(data.message, {icon: 1, time: 1000});
  144. obj.del();
  145. } else {
  146. layer.msg(data.message, {icon: 2, time: 1000});
  147. }
  148. });
  149. });
  150. }
  151. // 删除
  152. window.refresh = function (param) {
  153. table.reload('deduction-table');
  154. }
  155. })