agent_list.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 username = '';
  11. let authInfo = JSON.parse(localStorage.getItem(window._AUTH_INFO_));
  12. let authInfoDeductionSwitch = authInfo.detail.deduction_switch;
  13. if (GetQueryString('username')) {
  14. username = GetQueryString('username');
  15. }
  16. let agent_status = '';
  17. if (GetQueryString('status')) {
  18. agent_status = GetQueryString('status');
  19. }
  20. let parent_uid = '';
  21. if (GetQueryString('parent_uid')) {
  22. parent_uid = GetQueryString('parent_uid');
  23. }
  24. let cols = [];
  25. if (authInfoDeductionSwitch === 2) {
  26. //cpa
  27. $('#searchAdd').append('<div class="layui-form-item layui-inline">\n' +
  28. ' <label class="layui-form-label">状态</label>\n' +
  29. ' <div class="layui-input-inline input-narrow">\n' +
  30. ' <select name="status" lay-search>\n' +
  31. ' <option value=""></option>\n' +
  32. ' <option class="status_1" value="1">开启</option>\n' +
  33. ' <option class="status_2" value="2">关闭</option>\n' +
  34. ' </select>\n' +
  35. ' </div>\n' +
  36. ' </div>');
  37. $('.status_' + agent_status).attr('selected', 'selected');
  38. form.render();
  39. //cpa
  40. // cpa 数据
  41. cols = [
  42. [
  43. {
  44. title: '代理UID',
  45. field: 'uid',
  46. align: 'center'
  47. },
  48. {
  49. title: '代理昵称',
  50. field: 'nick',
  51. align: 'center'
  52. },
  53. {
  54. title: '代理账号',
  55. field: 'username',
  56. align: 'center'
  57. },
  58. {
  59. title: '上级代理',
  60. field: 'parent_uid',
  61. align: 'center'
  62. },
  63. {
  64. title: '代理类型',
  65. field: 'deduction_switch',
  66. align: 'center',
  67. templet: function (d) {
  68. if (d.deduction_switch === 1) {
  69. return "CPS";
  70. } else if (d.deduction_switch === 2) {
  71. return "CPA";
  72. }
  73. }
  74. },
  75. {
  76. title: '代理等级',
  77. field: 'agent_level',
  78. align: 'center',
  79. templet: function (d) {
  80. if (authInfo.detail.agent_level === d.agent_level) {
  81. return '本级代理';
  82. } else {
  83. return '子级代理';
  84. }
  85. }
  86. },
  87. {
  88. title: '代理状态',
  89. field: 'status',
  90. align: 'center',
  91. templet: function (d) {
  92. if (d.status === 1) {
  93. return '开启';
  94. }
  95. return '关闭';
  96. }
  97. },
  98. {
  99. title: '创建时间',
  100. field: 'created_at',
  101. align: 'center'
  102. },
  103. {
  104. title: '操作',
  105. field: '',
  106. templet: function (d) {
  107. return '<button lay-event="edit" class="btn-nd pear-btn pear-btn-primary pear-btn-xs">编辑</button>';
  108. },
  109. align: 'center'
  110. },
  111. ]
  112. ]
  113. } else if (authInfoDeductionSwitch === 1) {
  114. // cps
  115. var searchHtml = '<div class="layui-form-item layui-inline">\n' +
  116. ' <label class="layui-form-label">状态</label>\n' +
  117. ' <div class="layui-input-inline input-narrow">\n' +
  118. ' <select name="status" lay-search>\n' +
  119. ' <option value=""></option>\n' +
  120. ' <option class="status_1" value="1">开启</option>\n' +
  121. ' <option class="status_2" value="2">关闭</option>\n' +
  122. ' </select>\n' +
  123. ' </div>\n' +
  124. ' </div>';
  125. $('.status_' + agent_status).attr('selected', 'selected');
  126. searchHtml += '<div class="layui-form-item layui-inline">\n' +
  127. ' <label class="layui-form-label">查询下级</label>\n' +
  128. ' <div class="layui-input-inline">\n' +
  129. ' <input type="text" name="parent_uid" placeholder="查询下级(输入上级UID)" class="layui-input parent_uid">\n' +
  130. ' </div>\n' +
  131. ' </div>';
  132. $('#searchAdd').append(searchHtml);
  133. form.render();
  134. cols = [
  135. [
  136. {
  137. title: '代理UID',
  138. field: 'uid',
  139. align: 'center'
  140. },
  141. {
  142. title: '代理名称',
  143. field: 'nick',
  144. align: 'center'
  145. },
  146. {
  147. title: '代理账号',
  148. field: 'username',
  149. align: 'center'
  150. },
  151. {
  152. title: '上级代理',
  153. field: 'parent_uid',
  154. align: 'center'
  155. },
  156. {
  157. title: '代理类型',
  158. field: 'cps',
  159. align: 'center',
  160. templet: function (d) {
  161. return 'CPS';
  162. }
  163. },
  164. {
  165. title: '代理等级',
  166. field: 'agent_level',
  167. align: 'center',
  168. templet: function (d) {
  169. return '( ' + (parseInt(d.agent_level) - parseInt(authInfo.detail.agent_level)) + ' 级 )代理'
  170. }
  171. },
  172. {
  173. title: '分成比例(%)',
  174. field: 'commission_ratio',
  175. align: 'center'
  176. },
  177. {
  178. title: '总收益¥',
  179. field: 'commission_money',
  180. align: 'center'
  181. },
  182. {
  183. title: '代理状态',
  184. field: 'status',
  185. align: 'center',
  186. templet: function (d) {
  187. if (d.status === 1) {
  188. return '开启';
  189. }
  190. return '关闭';
  191. }
  192. },
  193. {
  194. title: '添加时间',
  195. field: 'created_at',
  196. align: 'center'
  197. },
  198. {
  199. title: '查看下级',
  200. field: '',
  201. templet: function (d) {
  202. return '<a href="?parent_uid=' + d.uid + '">查看下级</a>';
  203. },
  204. align: 'center'
  205. },
  206. {
  207. title: '操作',
  208. field: '',
  209. templet: function (d) {
  210. if (parseInt(authInfo.detail.agent_level) + 1 === (parseInt(d.agent_level))) {
  211. return '<button lay-event="edit" class="btn-nd pear-btn pear-btn-primary pear-btn-xs">编辑</button>';
  212. }
  213. return '不可操作';
  214. },
  215. align: 'center'
  216. },
  217. ]
  218. ]
  219. } else {
  220. // 查询下级
  221. $('#searchAdd').append('<div class="layui-form-item layui-inline">\n' +
  222. ' <label class="layui-form-label">查询下级</label>\n' +
  223. ' <div class="layui-input-inline">\n' +
  224. ' <input type="text" name="parent_uid" placeholder="查询下级(输入上级UID)" class="layui-input parent_uid">\n' +
  225. ' </div>\n' +
  226. ' </div>');
  227. form.render();
  228. cols = [
  229. [
  230. {
  231. title: 'UID',
  232. field: 'uid',
  233. align: 'center'
  234. },
  235. {
  236. title: '账号',
  237. field: 'username',
  238. align: 'center'
  239. },
  240. {
  241. title: '上级代理',
  242. field: 'parent_uid',
  243. align: 'center'
  244. },
  245. {
  246. title: '分成比例(%)',
  247. field: 'commission_ratio',
  248. align: 'center'
  249. },
  250. {
  251. title: '今日抽成',
  252. field: 'td_commission_money',
  253. align: 'center'
  254. },
  255. {
  256. title: '今日注册',
  257. field: 'td_users_total',
  258. align: 'center'
  259. },
  260. {
  261. title: '总抽成',
  262. field: 'commission_money',
  263. align: 'center'
  264. },
  265. {
  266. title: '总注册',
  267. field: 'users_total',
  268. align: 'center'
  269. },
  270. {
  271. title: '操作',
  272. field: '',
  273. templet: function (d) {
  274. return '<a href="?parent_uid=' + d.uid + '">查看下级</a>';
  275. },
  276. align: 'center'
  277. },
  278. ]
  279. ]
  280. }
  281. $('.username').val(username);
  282. $('.parent_uid').val(parent_uid);
  283. let search = httpRequestPostData({
  284. username: username,
  285. parent_uid: parent_uid,
  286. status: agent_status
  287. });
  288. table.render({
  289. elem: '#agent-table',
  290. method: 'POST',
  291. request: {
  292. pageName: 'page',
  293. limitName: 'page_size'
  294. },
  295. async: false,
  296. headers: {
  297. "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN')
  298. },
  299. contentType: 'application/json',
  300. where: search,
  301. url: getMyApiUrl('/agent/lists'),
  302. limit: 20,
  303. limits: [20, 30, 40, 50, 80, 100],
  304. parseData: function (res) {
  305. return httpRequestPagesParseData(res);
  306. },
  307. response: {
  308. "statusCode": 200,
  309. },
  310. done: function (data, page, total) {
  311. var intCode = parseInt(data.code);
  312. if (intCode === 403) {
  313. cbRespnseRedirectLogin(data);
  314. } else if (intCode === 401) {
  315. // 仅仅是过期了,这里可以有其他逻辑补偿.
  316. // 暂时跳到登陆页面
  317. cbRespnse401(data);
  318. }
  319. onloadRender();
  320. },
  321. error: function (obj, message) {
  322. cbRespnseReloadPage(obj, message);
  323. },
  324. page: true,
  325. cols: cols,
  326. skin: 'line',
  327. toolbar: '#agent-toolbar',
  328. defaultToolbar: [{
  329. title: '刷新',
  330. layEvent: 'refresh',
  331. icon: 'layui-icon-refresh',
  332. }, 'filter', 'print', 'exports']
  333. });
  334. table.on('toolbar(agent-table)', function (obj) {
  335. if (obj.event === 'add') {
  336. window.add();
  337. }
  338. });
  339. table.on('tool(agent-table)', function (obj) {
  340. if (obj.event === 'edit') {
  341. window.edit(obj.data);
  342. }
  343. });
  344. window.add = function () {
  345. layer.open({
  346. id: 'agent_create',
  347. type: 2,
  348. title: '添加',
  349. shade: 0.1,
  350. offset: '0px',
  351. area: ['450px', '550px'],
  352. maxWidth: 500,
  353. maxHeight: 1000,
  354. scrollbar: true,
  355. content: 'agent_create.html',
  356. });
  357. }
  358. window.edit = function (edit_agent) {
  359. console.debug(edit_agent);
  360. layer.open({
  361. id: 'agent_create',
  362. type: 2,
  363. title: '添加',
  364. shade: 0.1,
  365. offset: '0px',
  366. area: ['450px', '460px'],
  367. maxWidth: 500,
  368. maxHeight: 1000,
  369. scrollbar: true,
  370. content: 'agent_edit.html?uid=' + edit_agent.uid
  371. + '&username=' + edit_agent.username
  372. + '&own_app_uids=' + edit_agent.own_app_uids
  373. + '&status=' + edit_agent.status
  374. + '&commission_ratio=' + edit_agent.commission_ratio
  375. ,
  376. });
  377. }
  378. window.refresh = function (param) {
  379. table.reload('agent-table');
  380. }
  381. $('.reset').click(function () {
  382. if (agent_status) {
  383. $('.status_' + agent_status).removeAttr('selected')
  384. }
  385. form.render();
  386. });
  387. })