define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode'], function ($, undefined, Backend, Table, Form, Qrcode) {
$(document).on("click",'.qrcode',function(){
var qrUrl = $(this).data("qrcode");
$('#tong').html("");
$('#tong').qrcode(qrUrl);
layer.open({
type: 1,
title: false,
area: '258px',
skin: 'layui-layer-nobg', //没有背景色
shadeClose: true,
content: $('#tong')
});
});
//book_but
$(document).on('click','.book_but',function () {
Fast.api.open($(this).attr('href'), '订单详情', {});
return false;
});
$(document).on('click','.btn-look',function(){
layer.open({
type: 2,
title: '查看代理商推广链接',
maxmin: true,
area: ['90%', '90%'],
shadeClose: true, //点击遮罩关闭层
content: 'referral/lookAgentReferral'
});
});
$(document).on('click','.short_link_but',function(){
var $this = $(this);
$this.hide().siblings('.short_link').show();
})
if(Config.rtype == 1){
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: Config.referralUrl,
add_url: 'referral/referral/add?type=2',
export_url: 'referral/export',
edit_url: 'referral/referral/edit',
del_url: 'referral/referral/del',
multi_url: 'referral/referral/multi',
table: 'referral',
},
showToggle: false,
showColumns: false,
visible: false,
commonSearch: true,
showExport: true,
searchFormVisible: true,
search:false
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
//{field: 'id', title: 'ID'},
{field: 'source_url', title: '推广链接',formatter:Controller.api.source_url, operate:false},
{field: 'entry_page', title: '入口页面',formatter:Controller.api.entry_page, operate:false},
{field: 'book_id', title: '书籍ID', visible:false},
{field: 'book.name', title: '书籍名称', visible:false,operate: 'LIKE %...%'},
{field: 'chapter_idx', title: '章节序号', visible:false, operate:false},
{field: 'admin_id', title: __('Admin_id'), visible:false, operate:false},
{field: 'name', title: __('Name'),operate: 'LIKE %...%'},
{field: 'wx_type', title: __('Wx_type'), visible:false, searchList: {"wx_type 1":__('Wx_type 1'),"wx_type 2":__('Wx_type 2')}, operate:false},
{field: 'wx_type_text', title: __('Wx_type'), visible:false, operate:false},
{field: 'type', title: __('Type'), visible:false, searchList: {"type 1":'阅读页推广',"type 2":'首页推广'}, operate:false},
{field: 'type_text', title: __('Type'), visible:false, operate:false},
{field: 'uv', title: '累计阅读人数(今日阅读人数)', operate:false,formatter:function(value,row,index){
return value+"("+row.dayuv+")";
}},
{field: 'follow', title: '累计关注人数(今日关注人数)', operate:false,formatter:function(value,row,index){
return value+"("+row.dayut+")";
}},
{field: 'cost',title:'推广成本', operate:false},
{field: 'money', title: '累计充值金额(今日充值金额)', operate:false,formatter:function(value,row,index){
return value+"("+row.daymt+")";
}},
{field: 'createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: '更新时间', visible:false, operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{
field: 'tongji', title: __("统计"), operate: false, formatter: function (value, row, index) {
return '订单详情';
}
},
]
],
exportOptions: {
type: 'excel',
fileName:'推广链接',
ignoreColumn: [8,9],
onMsoNumberFormat: function(cell, row, col) {
return (row > 0 && col == 1) ? '\\@' : '';
}}
});
// 为表格绑定事件
Table.api.bindevent(table);
},
lookagentreferral:function(){
// 初始化表格参数配置
Table.api.init({
extend: {
look_url: "referral/referral/lookAgentReferral",
table: 'referral',
},
showColumns:false,
showToggle:false,
searchFormVisible: true,
search:false,
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.look_url,
pk: 'id',
sortName: 'id',
columns: [
[
//{checkbox: true},
//{field: 'id', title: 'ID'},
{field: 'source_url', title: '推广链接',formatter:Controller.api.source_url, operate:false},
{field: 'entry_page', title: '入口页面',formatter:Controller.api.entry_page, operate:false},
{field: 'book_id', title: '书籍ID', visible:false},
{field: 'book.name', title: '书籍名称', visible:false,operate: 'LIKE %...%'},
{field: 'chapter_idx', title: '章节序号', visible:false, operate:false},
{field: 'admin_id', title: '代理商',formatter: Controller.api.formatter.agent_text,searchList: Controller.api.formatter.agent_select()},
{field: 'wx_type', title: __('Wx_type'), visible:false, searchList: {"wx_type 1":__('Wx_type 1'),"wx_type 2":__('Wx_type 2')}, operate:false},
{field: 'wx_type_text', title: __('Wx_type'), visible:false, operate:false},
{field: 'type', title: __('Type'), visible:false, searchList: {"type 1":'阅读页推广',"type 2":'首页推广'}, operate:false},
{field: 'type_text', title: __('Type'), visible:false, operate:false},
{field: 'uv', title: '阅读人数', operate:false},
{field: 'follow', title: '关注人数', operate:false},
{field: 'cost',title:'推广成本', operate:false},
{field: 'money', title: '充值金额', operate:false},
{field: 'createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: '更新时间', visible:false, operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: '操作', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
{
field: 'tongji', title: __("统计"), operate: false, formatter: function (value, row, index) {
return '订单详情';
}
},
]
],
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Form.api.bindevent($("form[role=form]"), function (data) {
Toastr.success('添加成功');
$('.url_txt').eq(0).text(data.jmp_url);
$('.url_txt').eq(1).text(data.short_url_weibo);
$('.url_txt').eq(2).text(data.short_url_qq);
$('.copy').eq(0).attr('data-clipboard-text',data.jmp_url);
$('.copy').eq(1).attr('data-clipboard-text',data.short_url_weibo);
$('.copy').eq(2).attr('data-clipboard-text',data.short_url_qq);
$('#erweima').html("");
$('#erweima').qrcode(data.jmp_url);
$('#erweima').html('');
$('#add-form').hide();
$('#add-dialog').show();
return false;
});
$(document).on('click','.btn-close',function () {
Fast.api.close();
})
},
edit: function () {
Controller.api.bindevent();
},
select: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'referral/referral/index',
},
showColumns:false,
showToggle:false,
showExport:false,
searchFormVisible: false,
search:false,
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
//{field: 'id', title: __('Id')},
{field: 'source_url', title: '推广链接',formatter:Controller.api.source_url, operate:false},
{field: 'entry_page', title: '入口页面',formatter:Controller.api.entry_page, operate:false},
{field: 'book_id', title: __('Book_id'), visible:false},
{field: 'book.name', title: '书籍名称', visible:false,operate: 'LIKE %...%'},
{field: 'chapter_idx', title: __('Chapter_idx'), visible:false, operate:false},
{field: 'admin_id', title: __('Admin_id'), visible:false, operate:false},
{field: 'name', title: __('Name'), visible:false,operate: 'LIKE %...%'},
{field: 'wx_type', title: __('Wx_type'), visible:false, searchList: {"wx_type 1":__('Wx_type 1'),"wx_type 2":__('Wx_type 2')}, operate:false},
{field: 'wx_type_text', title: __('Wx_type'), visible:false, operate:false},
{field: 'type', title: __('Type'), visible:false, searchList: {"type 1":'阅读页推广',"type 2":'首页推广'}},
{field: 'type_text', title: __('Type'), visible:false, operate:false},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), visible:false, operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), events: {
'click .btn-chooseone': function (e, value, row, index) {
Fast.api.close([row]);
},
}, formatter: function () {
return ' ' + __('Choose') + '';
}}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
//获取选中数据
$(document).on('click', "#btn-chooseone", function () {
Fast.api.close(table.bootstrapTable('getSelections'));
});
},
api: {
formatter:{
agent_text:function(value, row, index){
var name = '';
$.each( Config.adminExtend, function( key, val ) {
if(row.admin_id == val.admin_id){
name = val.card_holder;
return ;
}
} );
return name;
},
agent_select:function(){
var data = {};
$.each( Config.adminExtend, function( key, val ) {
data[val.admin_id] = val.card_holder;
} );
return data;
},
},
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
source_url: function (value, row, index) {
var html = [];
html.push((row.wx_type == 1 ? '认证公众号' : '未认证公众号'));
if(Config.url_referral){
value = Config.url_referral + '/t/' + row.id;
}
html.push('