| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () {
- let table = layui.table;
- let $ = layui.jquery;
- let admin = layui.madmin;
- let layer = layui.layer;
- let form = layui.form;
- let common = layui.common;
- let mhttp = layui.mhttp;
- admin.getConfig();
- let username = '';
- let authInfo = JSON.parse(localStorage.getItem(window._AUTH_INFO_));
- let authInfoDeductionSwitch = authInfo.detail.deduction_switch;
- if (GetQueryString('username')) {
- username = GetQueryString('username');
- }
- let agent_status = '';
- if (GetQueryString('status')) {
- agent_status = GetQueryString('status');
- }
- let parent_uid = '';
- if (GetQueryString('parent_uid')) {
- parent_uid = GetQueryString('parent_uid');
- }
- let cols = [];
- if (authInfoDeductionSwitch === 2) {
- //cpa
- $('#searchAdd').append('<div class="layui-form-item layui-inline">\n' +
- ' <label class="layui-form-label">状态</label>\n' +
- ' <div class="layui-input-inline input-narrow">\n' +
- ' <select name="status" lay-search>\n' +
- ' <option value=""></option>\n' +
- ' <option class="status_1" value="1">开启</option>\n' +
- ' <option class="status_2" value="2">关闭</option>\n' +
- ' </select>\n' +
- ' </div>\n' +
- ' </div>');
- $('.status_' + agent_status).attr('selected', 'selected');
- form.render();
- //cpa
- // cpa 数据
- cols = [
- [
- {
- title: '代理UID',
- field: 'uid',
- align: 'center'
- },
- {
- title: '代理昵称',
- field: 'nick',
- align: 'center'
- },
- {
- title: '代理账号',
- field: 'username',
- align: 'center'
- },
- {
- title: '上级代理',
- field: 'parent_uid',
- align: 'center'
- },
- {
- title: '代理类型',
- field: 'deduction_switch',
- align: 'center',
- templet: function (d) {
- if (d.deduction_switch === 1) {
- return "CPS";
- } else if (d.deduction_switch === 2) {
- return "CPA";
- }
- }
- },
- {
- title: '代理等级',
- field: 'agent_level',
- align: 'center',
- templet: function (d) {
- if (authInfo.detail.agent_level === d.agent_level) {
- return '本级代理';
- } else {
- return '子级代理';
- }
- }
- },
- {
- title: '代理状态',
- field: 'status',
- align: 'center',
- templet: function (d) {
- if (d.status === 1) {
- return '开启';
- }
- return '关闭';
- }
- },
- {
- title: '创建时间',
- field: 'created_at',
- align: 'center'
- },
- {
- title: '操作',
- field: '',
- templet: function (d) {
- return '<button lay-event="edit" class="btn-nd pear-btn pear-btn-primary pear-btn-xs">编辑</button>';
- },
- align: 'center'
- },
- ]
- ]
- } else if (authInfoDeductionSwitch === 1) {
- // cps
- var searchHtml = '<div class="layui-form-item layui-inline">\n' +
- ' <label class="layui-form-label">状态</label>\n' +
- ' <div class="layui-input-inline input-narrow">\n' +
- ' <select name="status" lay-search>\n' +
- ' <option value=""></option>\n' +
- ' <option class="status_1" value="1">开启</option>\n' +
- ' <option class="status_2" value="2">关闭</option>\n' +
- ' </select>\n' +
- ' </div>\n' +
- ' </div>';
- $('.status_' + agent_status).attr('selected', 'selected');
- searchHtml += '<div class="layui-form-item layui-inline">\n' +
- ' <label class="layui-form-label">查询下级</label>\n' +
- ' <div class="layui-input-inline">\n' +
- ' <input type="text" name="parent_uid" placeholder="查询下级(输入上级UID)" class="layui-input parent_uid">\n' +
- ' </div>\n' +
- ' </div>';
- $('#searchAdd').append(searchHtml);
- form.render();
- cols = [
- [
- {
- title: '代理UID',
- field: 'uid',
- align: 'center'
- },
- {
- title: '代理名称',
- field: 'nick',
- align: 'center'
- },
- {
- title: '代理账号',
- field: 'username',
- align: 'center'
- },
- {
- title: '上级代理',
- field: 'parent_uid',
- align: 'center'
- },
- {
- title: '代理类型',
- field: 'cps',
- align: 'center',
- templet: function (d) {
- return 'CPS';
- }
- },
- {
- title: '代理等级',
- field: 'agent_level',
- align: 'center',
- templet: function (d) {
- return '( ' + (parseInt(d.agent_level) - parseInt(authInfo.detail.agent_level)) + ' 级 )代理'
- }
- },
- {
- title: '分成比例(%)',
- field: 'commission_ratio',
- align: 'center'
- },
- {
- title: '总收益¥',
- field: 'commission_money',
- align: 'center'
- },
- {
- title: '代理状态',
- field: 'status',
- align: 'center',
- templet: function (d) {
- if (d.status === 1) {
- return '开启';
- }
- return '关闭';
- }
- },
- {
- title: '添加时间',
- field: 'created_at',
- align: 'center'
- },
- {
- title: '查看下级',
- field: '',
- templet: function (d) {
- return '<a href="?parent_uid=' + d.uid + '">查看下级</a>';
- },
- align: 'center'
- },
- {
- title: '操作',
- field: '',
- templet: function (d) {
- if (parseInt(authInfo.detail.agent_level) + 1 === (parseInt(d.agent_level))) {
- return '<button lay-event="edit" class="btn-nd pear-btn pear-btn-primary pear-btn-xs">编辑</button>';
- }
- return '不可操作';
- },
- align: 'center'
- },
- ]
- ]
- } else {
- // 查询下级
- $('#searchAdd').append('<div class="layui-form-item layui-inline">\n' +
- ' <label class="layui-form-label">查询下级</label>\n' +
- ' <div class="layui-input-inline">\n' +
- ' <input type="text" name="parent_uid" placeholder="查询下级(输入上级UID)" class="layui-input parent_uid">\n' +
- ' </div>\n' +
- ' </div>');
- form.render();
- cols = [
- [
- {
- title: 'UID',
- field: 'uid',
- align: 'center'
- },
- {
- title: '账号',
- field: 'username',
- align: 'center'
- },
- {
- title: '上级代理',
- field: 'parent_uid',
- align: 'center'
- },
- {
- title: '分成比例(%)',
- field: 'commission_ratio',
- align: 'center'
- },
- {
- title: '今日抽成',
- field: 'td_commission_money',
- align: 'center'
- },
- {
- title: '今日注册',
- field: 'td_users_total',
- align: 'center'
- },
- {
- title: '总抽成',
- field: 'commission_money',
- align: 'center'
- },
- {
- title: '总注册',
- field: 'users_total',
- align: 'center'
- },
- {
- title: '操作',
- field: '',
- templet: function (d) {
- return '<a href="?parent_uid=' + d.uid + '">查看下级</a>';
- },
- align: 'center'
- },
- ]
- ]
- }
- $('.username').val(username);
- $('.parent_uid').val(parent_uid);
- let search = httpRequestPostData({
- username: username,
- parent_uid: parent_uid,
- status: agent_status
- });
- table.render({
- elem: '#agent-table',
- method: 'POST',
- request: {
- pageName: 'page',
- limitName: 'page_size'
- },
- async: false,
- headers: {
- "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN')
- },
- contentType: 'application/json',
- where: search,
- url: getMyApiUrl('/agent/lists'),
- limit: 20,
- limits: [20, 30, 40, 50, 80, 100],
- parseData: function (res) {
- return httpRequestPagesParseData(res);
- },
- response: {
- "statusCode": 200,
- },
- done: function (data, page, total) {
- var intCode = parseInt(data.code);
- if (intCode === 403) {
- cbRespnseRedirectLogin(data);
- } else if (intCode === 401) {
- // 仅仅是过期了,这里可以有其他逻辑补偿.
- // 暂时跳到登陆页面
- cbRespnse401(data);
- }
- onloadRender();
- },
- error: function (obj, message) {
- cbRespnseReloadPage(obj, message);
- },
- page: true,
- cols: cols,
- skin: 'line',
- toolbar: '#agent-toolbar',
- defaultToolbar: [{
- title: '刷新',
- layEvent: 'refresh',
- icon: 'layui-icon-refresh',
- }, 'filter', 'print', 'exports']
- });
- table.on('toolbar(agent-table)', function (obj) {
- if (obj.event === 'add') {
- window.add();
- }
- });
- table.on('tool(agent-table)', function (obj) {
- if (obj.event === 'edit') {
- window.edit(obj.data);
- }
- });
- window.add = function () {
- layer.open({
- id: 'agent_create',
- type: 2,
- title: '添加',
- shade: 0.1,
- offset: '0px',
- area: ['450px', '550px'],
- maxWidth: 500,
- maxHeight: 1000,
- scrollbar: true,
- content: 'agent_create.html',
- });
- }
- window.edit = function (edit_agent) {
- console.debug(edit_agent);
- layer.open({
- id: 'agent_create',
- type: 2,
- title: '添加',
- shade: 0.1,
- offset: '0px',
- area: ['450px', '460px'],
- maxWidth: 500,
- maxHeight: 1000,
- scrollbar: true,
- content: 'agent_edit.html?uid=' + edit_agent.uid
- + '&username=' + edit_agent.username
- + '&own_app_uids=' + edit_agent.own_app_uids
- + '&status=' + edit_agent.status
- + '&commission_ratio=' + edit_agent.commission_ratio
- ,
- });
- }
- window.refresh = function (param) {
- table.reload('agent-table');
- }
- $('.reset').click(function () {
- if (agent_status) {
- $('.status_' + agent_status).removeAttr('selected')
- }
- form.render();
- });
- })
|