deduction_cps_list.js 5.2 KB

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