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('
');
$('.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 '编辑 ';
},
align: 'center'
},
]
]
} else if (authInfoDeductionSwitch === 1) {
// cps
var searchHtml = '';
$('.status_' + agent_status).attr('selected', 'selected');
searchHtml += '';
$('#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 '查看下级 ';
},
align: 'center'
},
{
title: '操作',
field: '',
templet: function (d) {
if (parseInt(authInfo.detail.agent_level) + 1 === (parseInt(d.agent_level))) {
return '编辑 ';
}
return '不可操作';
},
align: 'center'
},
]
]
} else {
// 查询下级
$('#searchAdd').append('');
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 '查看下级 ';
},
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();
});
})