define(['jquery', 'bootstrap', 'backend', 'table', 'form','clipboard'],
function ($, undefined, Backend, Table, Form,clipboard) {
var Controller = {
index: async function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile_order/index' + location.search,
add_url: 'mobile_order/add',
edit_url: 'mobile_order/edit',
del_url: 'mobile_order/del',
multi_url: 'mobile_order/multi',
import_url: 'mobile_order/import',
show_open_data_url: 'mobile_order/show_open_data',
table: 'mobile_order',
}
});
var table = $("#table");
table.on('post-common-search.bs.table', function (event, table) {
var form = $("form", table.$commonsearch);
$("input[name='s_id']", form).addClass("selectpage").data("source", "auth/admin/index2").data("primaryKey", "id").data("params",{"custom[proxy]":"0","custom[sub]":"1"}).data("field", "nickname").data("orderBy", "id asc");
Form.events.cxselect(form);
Form.events.selectpage(form);
});
let is_proxy = Config.is_proxy;
let is_proxy_operate = false;
let is_proxy_operate_eq = false;
if(is_proxy==0){
is_proxy_operate = 'LIKE';
is_proxy_operate_eq = '=';
}
let clip=new clipboard('.btn-pay_link',{
text(a){
let link=$(a).data('link')
return link
}
})
clip.on('success',function (){
parent.layer.msg('复制成功')
})
//订单信息复制
let order_clip=new clipboard('.btn-order_link',{
text(a){
// let link=$(a).data('link').replace(/<[^>]*>/g, '')
let link=$(a).data('link');
// console.log(JSON.stringify(link));
return link + ''
}
})
console.log(order_clip,'22222222')
order_clip.on('success',function (){
console.log(order_clip);
parent.layer.msg('复制成功')
})
let status = await $.getJSON('mobile_order/status');
let statusColor={};
let colors=['label-daifukuan','label-info','label-danger','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success'];
Object.keys(status).forEach((item,idx)=>{
statusColor[item]=colors[idx];
});
statusColor[50]='label-default';
let payType = await $.getJSON('mobile_order/pay_type');
let mobileRules = await $.getJSON('mobile/mobile_rules');
table.on('load-success.bs.table', function (_, data) {
let e=data.extend;
$('#orderAmount').html(`收入:${e.total},支付宝:${e.alipay},微信:${e.wechat},抖音:${e.dy},快手:${e.ks},成本:${e.di},利润:${e.profit},退款:${e.refund}`)
});
$(document).on('click','.btn-click-show-open',function (){
if($(this).data('open')!==1){
parent.layer.msg('该用户未上传开卡资料')
return
}
Fast.api.open($.fn.bootstrapTable.defaults.extend.show_open_data_url+'/id/'+$(this).data('id'),'查看资料',{
shade:.3,
shadeClose:false,
})
})
$(document).on('click','.btn-sub-remark',function (){
let id=$(this).data('id')
let url=table.data('url-sub-remark')+`/id/${id}`
Fast.api.open(url,'备注')
})
let columns=[
//{checkbox: true},
{field: 'id', title: __('ID'),operate:false,},
{field: 'order_no', title: __('订单号'),visible:false,operate: 'like'},
{field: 'pay_no', title: __('支付单号'),visible: false,operate: '='},
{field: 's_id', title: __('来源渠道'),formatter(_, order) {
let a=[]
a.push(`
${order.s_id}
`);
a.push(`${order.s_name}
`);
return a.join('')
}},
// {field: 'anchor.name', title:__('主播名称') ,searchList(){return Template('anchor-sub-search',{});},width: 100},
{field: 'pay_type', title: __('支付方式'),searchList: payType,visible: false, operate: is_proxy_operate},
{field: 'no', title: __('手机号'),visible: false,operate: 'LIKE'},
{field: 'phone', title: __('收货人手机'),visible: false,operate: 'LIKE'},
{field: 'name', title: __('收货人'),visible: false,operate: 'LIKE'},
{field: 'id_no', title: __('收货人身份证'),visible: false,operate: "like"},
{field: 'pay_mid_wechat', title: __('微信商户号'),visible: false, operate: is_proxy_operate},
{field: 'pay_mid_alipay', title: __('支付宝商户号'),visible: false,operate: is_proxy_operate},
{field: 'pay_mid_dy', title: __('抖音商户号'),visible: false,operate: is_proxy_operate},
{field: 'pay_mid_ks', title: __('快手商户号'),visible: false,operate: is_proxy_operate},
{field: 'order_no', title: __('订单信息'),operate: false,formatter(_,order){
let a=[]
a.push(`订单号:${order.order_no}
`)
if(order.pay_no){
a.push(`支付单号:${order.pay_no}
`)
}
a.push(`商品信息:${order.no}
`)
a.push(`归属地:${order.info.mobile.province}/${order.info.mobile.city}
`)
if(adminInfo.is_manager){
a.push(`供应商:${order.proxy?order.proxy.nickname:''}
`)
}
a.push(`运营商:${order.info?order.info.mobile.network:''}
`)
a.push(`卡品牌:${order.brand}
`)
if(showAmountDi && is_proxy==0) {
a.push(`底价:${order.amount_di}
`)
}
a.push(`预存:${order.amount_charge}
`)
if(is_proxy == 0 ) {
a.push(`售价:${order.info.mobile.is_activity?order.info.mobile.amount_kill:order.info.mobile.amount_base}
`)
a.push(`订单价格:${order.amount}
`)
}
a.push(`套餐:${order.info?order.info.info.describe:''}
`)
a.push(`备注:${order.info?order.info.mobile.remark:''}
`)
// a.push(`点击复制`)
return `${a.join('')}
`
},width:250,valign:'top',align:'left'},
{field: 'order_no', title: __('收货人'),operate: false,formatter(_,order){
let a=[]
a.push(`收货人:${order.name}
`)
a.push(`手机号:${order.phone}(${order.phone_order_count})
`)
a.push(`地址:${order.address}
`)
if(is_proxy == 0 ) {
a.push(`支付方式:${payType[order.pay_type]}
`)
a.push(`微信商户号:${order.pay_mid_wechat}
`)
a.push(`支付宝商户号:${order.pay_mid_alipay}
`)
a.push(`抖音商户号:${order.pay_mid_dy}
`)
a.push(`快手商户号:${order.pay_mid_ks}
`)
}
a.push(`备注:${order.remark}
`)
a.push(`快递名称:${order.trans_name}
`)
a.push(`快递单号:${order.trans_no}
`)
a.push(`查看资料`)
return `${a.join('')}
`
},width:200,valign:'top',align:'left'},
{field: 'status', title: __('Status'),formatter(a,order){
if(a===30) {
return `${status[order.status_bak]||''}-${status[a]}`
}
if(`${status[a]}` == '待付款'){
return `${status[a]}`
}
if(`${status[a]}` == '已完成'){
return `${status[a]}`
}
return `${status[a]}`
},searchList:status,operate: is_proxy_operate_eq},
{field: 'platform_source', title: __('来源'),operate: is_proxy_operate},
{field: 'anchor.name', title:__('主播名称') ,searchList(){return Template('anchor-search',{});},width: 100},
{field: 'sub_anchor.mobile_anchor.name', title: __(adminInfo.is_sub?'主播名称':'分站主播'),searchList(){return Template('anchor-sub-search',{});},width: 100,operate: is_proxy_operate,visible:is_proxy_operate},
{field: 'rules.rule', title: __('规律'),visible: false,searchList:mobileRules},
{field: '', title: __('退款记录'),formatter(_,order){
let a=[]
order.refund_log.forEach(item=>{
a.push(`${item.create_time_format} ${item.pass?'同意':'驳回'} ${item.reason}
`)
})
return `${a.join('')}
`
},operate:false,valign:'top',align:'left',width: 200,visible:is_proxy_operate},
{field: 'sub_log', title: __(adminInfo.is_manager?'分站备注':'备注'),formatter(_,order){
let a=[]
order.sub_remark.forEach(item=>{
a.push(`${item.create_time_format} ${item.admin?item.admin.nickname:'-'} ${item.content}
`)
})
if(table.data('auth-url-sub-remark')) {
a.push(``)
}
return `${a.join('')}
`
},operate:false,valign:'top',align:'left',width:200},
{field: 'operation_log', title: __('客服记录'),formatter(_,order){
let a=[]
order.operation.forEach(item=>{
a.push(`${item.create_time_format} ${item.admin?item.admin.nickname:'-'} ${item.content}
`)
})
return `${a.join('')}
`
},operate:false,valign:'top',align:'left',width:200},
{field: 'admin.admin_id', title: __('操作员'),formatter(_,order){
let a=[]
order.admin.forEach(item=>{
a.push(`${item.admin.nickname}
`)
})
return `${a.join('')}
`
},operate:"=",searchList: admins,valign:'top',align:'left',width: 100},
{field: 'pay_link', title: __('付款链接'),formatter(_,order){
if(order.status!==0){
return ''
}
return ``
},operate:false,width: 150,visible:is_proxy_operate},
{field: 'create_time', title: __('Create_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
//{field: 'update_time', title: __('更新时间'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
/* {field: 'pay_time', title: __('Pay_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
{field: 'trans_name', title: __('Trans_name')},
{field: 'trans_no', title: __('Trans_no')},
{field: 'amount_original', title: __('Amount_original'), operate: 'BETWEEN'},
{field: 'amount_hd', title: __('Amount_hd'), operate: 'BETWEEN'},
{field: 'amount_charge', title: __('Amount_charge'), operate: 'BETWEEN'},
{field: 'amount', title: __('Amount'), operate: 'BETWEEN'},
{field: 'open_idcard_face_img', title: __('开卡身份证正面照'),formatter: Table.api.formatter.image,events: Table.api.events.image,opera: false},
{field: 'open_idcard_back_img', title: __('开卡身份证背面照'),formatter: Table.api.formatter.image,events: Table.api.events.image,operate:false},
{field: 'open_face_img', title: __('开卡人头像'),formatter: Table.api.formatter.image,events: Table.api.events.image,operate:false},
{field: 'open_name', title: __('开卡人姓名')},
{field: 'open_id_no', title: __('开卡人身份证号码')},
{field: 'open_phone', title: __('开卡人手机号')},*/
{field: 'trans_no', title: __('Trans_no'),visible: false,operate: "like"},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.buttons,
formatter: Table.api.formatter.buttons,
buttons:[
{
name: 'detail',
text: __('设置主播'),
title: __('设置主播'),
classname: 'btn btn-xs btn-info btn-dialog period',
url: table.data('url-set_anchor'),
callback: function (data) {
},
visible: function (row) {
return $('#table').data('auth-set_anchor');
}
},
{
name: 'detail',
text: __('添加备注'),
title: __('添加备注'),
classname: 'btn btn-xs btn-info btn-dialog period',
url: 'mobile_order/add_operation?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('add_operation');
}
},
{
name: 'detail',
text: __('编辑'),
title: __('编辑'),
classname: 'btn btn-xs btn-info btn-dialog period',
url: 'mobile_order/edit?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('add_operation');
}
},
{
name: 'detail',
text: __('退款'),
title: __('退款'),
classname: 'btn btn-xs btn-danger btn-dialog period',
url: 'mobile_order/refund?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('mobile_order_refund') && row.status>0 && row.status!=90;
}
},
{
name: 'detail',
text: __('发货'),
title: __('发货'),
classname: 'btn btn-xs btn-info btn-dialog period',
url: 'mobile_order/send?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('mobile_order_send') && row.status>0;
}
},
{
name:'detail',
title:'查看物流',
text: __('查看物流'),
classname: 'btn btn-xs btn-danger btn-dialog',
url: 'mobile_order/see_logistics?a=1',
visible:(row)=>{
return $('#table').data('see_logistics') && row.trans_id>0 && row.trans_no
}
},
{
name: 'detail',
text: __('上架'),
title: __('上架'),
classname: 'btn btn-xs btn-success btn-dialog period',
url: 'mobile_order/mobile_up?a=1',
callback: function (data) {
if(data && data.say){
parent.layer.alert(data.say)
}
},
visible: function (row) {
return $('#table').data('auth-mobile_up') && [90].indexOf(row.status)>-1;
},
disable(row){
return row.mobile_can_up
}
},
{
name: 'detail',
text: __('抖音结算'),
title: __('抖音结算'),
classname: 'btn btn-xs btn-success btn-ajax',
url: 'mobile_order/dy_settle',
confirm:'确认结算吗?',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('auth-dy_settle') && row.pay_type===4 && row.pay_time>0 && row.payment && row.payment.settle_status===0;
},
disable(row){
}
},
]
}
]
if(!adminInfo.is_manager){
Table.api.removeColumn('operation_log',columns)
Table.api.removeColumn('anchor.name',columns)
Table.api.removeColumn('s_id',columns)
Table.api.removeColumn('admin.admin_id',columns)
}
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search:false,
searchFormVisible:true,
columns: [
columns
],
fixedColumns:true,
fixedRightNumber:1,
onLoadSuccess(a){
$('.btn-export').attr('href',a.link).show()
// 角标
let arr1 = [];let status_all=0;
a.status_list.forEach(function(item, index) {
$(".nav li .nav_id_"+item.status).text(item.total);
arr1.push(item.status);
status_all = status_all+item.total;
});
// 全部
$(".nav li .nav_id_all").text(status_all);
// 无数据的置0
let arr2 = [0,10,15,17,20,25,30,50,60,70,80,90];
let diff=arr2.filter(item=>arr1.indexOf(item)==-1);
diff.forEach(function (i,k){
$(".nav li .nav_id_"+i).text(0);
});
$(".nav li .nav_id_10").text(a.status_10_count);
/*table.find('thead').css('position','fixed').css('background','white').css('top','370px')
table.css('margin-top',41)
table.find('tbody>tr:first-child>td').each((a,b)=>{
table.find('thead tr th').eq(a).css('width',b.offsetWidth).css('max-width',b.offsetWidth)
})*/
}
});
// 为表格绑定事件
Table.api.bindevent(table);
/* let innerHeight=window.innerHeight
$('.fixed-table-container').css('height',`${innerHeight-420}px`)
window.addEventListener('resize',function (){
let innerHeight=window.innerHeight
$('.fixed-table-container').css('height',`${innerHeight-420}px`)
})*/
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
$(document).on('input propertychange','#c-trans_no',function (){
let no=$(this).val()
if(!no){
return
}
Form.api.guessLogistics(no,'#c-trans_id')
})
},
add_operation(){
Controller.api.bindevent();
$('#c-no').focus()
},
sub_remark(){
Controller.api.bindevent();
$('#c-no').focus()
},
set_anchor(){
Controller.api.bindevent();
},
refund(){
Controller.api.bindevent();
},
mobile_up(){
Controller.api.bindevent()
if(!row){
Fast.api.close({say:'此号码已被删除,无法上架'})
}else if(row.status===0){
//Fast.api.close({say:'此号码已是上架状态'})
}
},
send(){
Controller.api.bindevent();
$(document).on('input propertychange','#c-trans_no',function (){
let no=$(this).val()
if(!no){
return
}
Form.api.guessLogistics(no,'#c-trans_id')
})
},
show_open_data(){
Controller.api.bindevent()
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
},
refund_log(){
Table.api.init();
var table = $("#table");
let columns=[
//{field:'id',title:'ID',operate:false},
{field:'od.mobile_id',title:'商品ID',operate:'='},
{field:'od.s_id',title:'代理商ID',operate:'='},
{field:'od.order_no',title:'订单号',operate:'='},
{field:'od.no',title:'手机号',operate:'like'},
{field:'pass',title:'审核状态',searchList:{1:'通过',0:'驳回'},formatter: Table.api.formatter.label},
{field:'reason',title:'备注',formatter: Table.api.formatter.content,width:200},
{field:'od.amount',title:'订单金额',operate:'between'},
{field:'amount_backend',title:'退款金额',operate:'between'},
{field:'create_time',title:'创建时间',operate:'range',addClass:'datetimerange',formatter:Table.api.formatter.datetime},
{field:'admin.nickname',title:' 操作员',operate:'like'},
];
if(!admin.is_manager){
Table.api.removeColumn('od.s_id',columns)
}
table.bootstrapTable({
url: 'mobile_order/refund_log',
pk: 'id',
sortName: 'id',
search:false,
searchFormVisible:true,
columns: columns,
onLoadSuccess(a){
}
});
Table.api.bindevent(table);
}
};
return Controller;
});