define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: async function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile_order_flow/index' + location.search,
add_url: 'mobile_order_flow/add',
edit_url: 'mobile_order_flow/edit',
del_url: 'mobile_order_flow/del',
multi_url: 'mobile_order_flow/multi',
import_url: 'mobile_order_flow/import',
table: 'mobile_order',
show_open_data_url: 'mobile_order_flow/show_open_data',
}
});
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 status = await $.getJSON('mobile_order_flow/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')
table.on('load-success.bs.table', function (_, data) {
let e=data.extend;
});
$(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,'备注')
})
$(document).on('click','.btn-click-show-open',function (){
if(!$(this).data('open')){
parent.layer.msg('该用户未上传开卡资料')
return
}
Fast.api.open($.fn.bootstrapTable.defaults.extend.show_open_data_url+'/id/'+$(this).data('id'),'查看资料',{
shade:.3,
shadeClose:false,
})
})
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: 'mobile.name', title: __('商品信息'),visible:false,operate: 'like'},
{field: 'mobile.product_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: 'pay_type', title: __('支付方式'),searchList: payType,visible: false},
{field: 'pay_mid_wechat', title: __('微信商户号'),visible: false,operate: 'LIKE'},
{field: 'pay_mid_alipay', title: __('支付宝商户号'),visible: false,operate: 'LIKE'},
{field: 'pay_mid_dy', title: __('抖音商户号'),visible: false,operate: 'LIKE'},
{field: 'pay_mid_ks', title: __('快手商户号'),visible: false,operate: 'LIKE'},
{field: 'name', title: __('收货人'),visible: false,operate: 'LIKE'},
{field: 'phone', title: __('收货人手机'),visible: false,operate: 'LIKE'},
{field: 'id_no', title: __('收货人身份证'),visible: false,operate: "like"},
{field: 'order_no', title: __('订单信息'),operate: false,formatter(_,order){
let a=[], product_no = '', product_brand = brands[order.brand];
if(order.info.mobile.product_no && order.info.mobile.product_no != undefined){
product_no = order.info.mobile.product_no;
}
if(order.info.mobile.logo){
a.push(``)
}
a.push(`订单号:${order.order_no}
`)
if(order.pay_no){
a.push(`支付单号:${order.pay_no}
`)
}
if(product_brand == undefined){
product_brand = order.brand;
}
a.push(`产品编码:${product_no}
`)
a.push(`商品信息:${order.info.mobile.name}
`)
a.push(`运营商:${product_brand}
`)
a.push(`商品名称:${order.info.mobile.name}
`)
a.push(`套餐:${order.info?order.info.mobile.summary:''}
`)
return `${a.join('')}
`
},width:300,align:'left',valign:'top'},
{
field:'amount',
title:'支付信息',
operate: false,
align:'left',
valign: 'top',
width: 125,
formatter(_, order) {
let a=[]
a.push(`支付金额:${order.amount}
`)
a.push(`支付方式:${payType[order.pay_type]}
`)
return a.join('')
}
},
{field: 'order_no', title: __('收货人'),operate: false,formatter(_,order){
let a=[]
a.push(`收货人:${order.name}
`)
a.push(`手机号:${order.phone}(${order.phone_order_flow_count})
`)
a.push(`地址:${order.address}
`)
a.push(`备注:${order.remark}
`)
a.push(`快递名称:${order.trans_name||''}
`)
a.push(`快递单号:${order.trans_no||''}
`)
a.push(`查看资料`)
// if(order.open_idcard_face_img){
// a.push(`
`)
// }
// if(order.open_idcard_back_img){
// a.push(`
`)
// }
// if(order.open_face_img){
// a.push(`
`)
// }
return `${a.join('')}
`
},width:200,align:'left',valign:'top'},
{field: 'order_no', title: __('生产信息'),operate: false,formatter(_,order){
let a=[], product_no = '';
a.push(`生产号码:${order.gantanhao_data_notify?order.gantanhao_data_notify.plan_mobile_produced:''}
`)
return `${a.join('')}
`
},width:140,align:'left',valign:'top'},
{field: 'status', title: __('Status'),formatter(a,order){
if(a===30) {
return `${status[order.status_bak]||''}-${status[a]}`;
}
return `${status[a]}`
},searchList:status},
{field: 'gantanhao_status', title: __('运营商结果'),formatter(a,order){
var str = '';
if(order.gantanhao_data_notify && order.status == '110' && order.gantanhao_data_notify.reason != undefined){
str = `${order.gantanhao_data_notify.reason}
`;
}
if(order.gantanhao_data_notify && order.gantanhao_data_notify.is_activated == 1){
str += `已激活
`;
}
return str;
},searchable:false},
{field: 'anchor.name', title:__('主播名称') ,searchList(){return Template('anchor-search',{});},width:100,formatter:Table.api.formatter.width},
{field: 'sub_anchor.mobile_anchor.name', title: __(adminInfo.is_sub?'主播名称':'分站主播'),searchList(){return Template('anchor-sub-search',{});},width:100,formatter:Table.api.formatter.width},
{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.admin?item.admin.job:'-'} ${item.content}
`)
})
return `${a.join('')}
`
},operate:false,align:'left',valign:'top',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,align:'left',valign:'top',width: 100},
{field: 'create_time', title: __('创建时间'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
{field: 'update_time', title: __('更新时间'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
{field: 'trans_no', title: __('快递单号'),visible: false},
{
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',
url: 'mobile_order_flow/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',
url: 'mobile_order_flow/edit?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('operate-edit');
}
},
{
name: 'detail',
text: __('发货'),
title: __('发货'),
classname: 'btn btn-xs btn-info btn-dialog period',
url: 'mobile_order_flow/send?a=1',
callback: function (data) {
},
visible: function (row) {
return $('#table').data('mobile_order_send') && row.status>0;
}
},
{
name: '重新提交',
text: __('重新提交'),
title: __('重新提交'),
classname: 'btn btn-xs btn-info btn-ajax',
url: 'mobile_order_flow/resubmit?a=1',
refresh: true,
callback: function (data) {
},
visible: function (row) {
return row.status==10;
}
},
{
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-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){
}
},
{
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==10 && row.amount>0;
}
},
]
}
]
if(adminInfo.is_sub){
Table.api.removeColumn('operation_log',columns)
Table.api.removeColumn('anchor.name',columns)
Table.api.removeColumn('sub',columns)
Table.api.removeColumn('admin.admin_id',columns)
Table.api.removeColumn('s_id',columns)
}
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
searchFormVisible:true,
search:false,
fixedColumns:true,
fixedRightNumber:1,
columns: [
columns
],
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,20,23,25,30,50,90,110];
let diff=arr2.filter(item=>arr1.indexOf(item)==-1);
diff.forEach(function (i,k){
$(".nav li .nav_id_"+i).text(0);
});
/*table.find('thead').css('position','fixed').css('background','white').css('top','365px')
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.find('thead tr th .th-inner').eq(a).css('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`)
})*/
},
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();
},
sub_remark(){
Controller.api.bindevent();
$('#c-no').focus()
},
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')
})
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});