/**
|
* 派单页面管理初始化
|
*/
|
var TOrderCheckDispatch = {
|
id: "DriverTable", // 表格ID
|
orderId: 0, // 订单ID
|
dispatchType: 1, // 派单类型:1=派单,2=改派
|
selectedDriverId: null, // 选中的司机ID
|
driverTable: null, // Bootstrap Table实例
|
dispatchData: null // 派单数据
|
};
|
|
/**
|
* 初始化司机列表表格的列
|
*/
|
TOrderCheckDispatch.initDriverColumn = function() {
|
return [
|
{field: 'selectItem', radio: true},
|
{title: '司机姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
|
{title: '手机号', field: 'phone', visible: true, align: 'center', valign: 'middle'},
|
{title: '所属代理商', field: 'agentName', visible: true, align: 'center', valign: 'middle'},
|
{title: '分公司名称', field: 'branchOfficeName', visible: true, align: 'center', valign: 'middle'}
|
];
|
};
|
|
/**
|
* 初始化司机列表Bootstrap Table
|
*/
|
TOrderCheckDispatch.initDriverTable = function() {
|
var columns = this.initDriverColumn();
|
var table = new BSTable(this.id, "/tOrderCheck/dispatchData", columns);
|
table.setPaginationType("server");
|
|
// 设置初始查询参数
|
table.setQueryParams({
|
orderId: this.orderId,
|
dispatchType: this.dispatchType
|
});
|
|
this.driverTable = table.init();
|
return this;
|
};
|
|
/**
|
* 搜索司机
|
*/
|
TOrderCheckDispatch.searchDriver = function() {
|
var queryData = {};
|
queryData['orderId'] = this.orderId;
|
queryData['dispatchType'] = this.dispatchType;
|
queryData['keyword'] = $("#keyword").val();
|
this.driverTable.refresh({query: queryData});
|
};
|
|
/**
|
* 重置搜索条件
|
*/
|
TOrderCheckDispatch.resetDriverSearch = function() {
|
$("#keyword").val('');
|
this.searchDriver();
|
};
|
|
|
|
/**
|
* 初始化页面
|
*/
|
TOrderCheckDispatch.init = function() {
|
// 初始化司机列表表格
|
this.initDriverTable();
|
};
|
|
|
|
|
|
/**
|
* 获取选中的司机
|
*/
|
TOrderCheckDispatch.getSelectedDriver = function() {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if (selected.length === 0) {
|
return null;
|
}
|
return selected[0];
|
};
|
|
|
|
|
|
/**
|
* 确认派单
|
*/
|
TOrderCheckDispatch.confirmDispatch = function() {
|
var selectedDriver = this.getSelectedDriver();
|
if (!selectedDriver) {
|
Feng.info("请选择要派单的司机!");
|
return;
|
}
|
|
this.selectedDriverId = selectedDriver.id;
|
var actionText = this.dispatchType === 1 ? "派单" : "改派";
|
|
swal({
|
title: "确认" + actionText + "?",
|
text: "请确认要将该订单" + actionText + "给选中的司机",
|
type: "warning",
|
showCancelButton: true,
|
confirmButtonColor: "#DD6B55",
|
confirmButtonText: "确认" + actionText,
|
cancelButtonText: "取消",
|
closeOnConfirm: false
|
}, function() {
|
TOrderCheckDispatch.executeDispatch();
|
});
|
};
|
|
/**
|
* 执行派单操作
|
*/
|
TOrderCheckDispatch.executeDispatch = function() {
|
var me = this;
|
var ajax = new $ax(Feng.ctxPath + "/tOrderCheck/executeDispatch", function(data) {
|
if (data.code === 500) {
|
Feng.error("派单失败: " + data.message);
|
swal.close();
|
return;
|
}
|
if (data.code === 200) {
|
swal.close();
|
Feng.success("派单成功!");
|
// 调用父页面的成功回调函数(如果存在)
|
if (window.parent && typeof window.onDispatchSuccess === 'function') {
|
window.onDispatchSuccess();
|
} else {
|
// 如果没有回调函数,则执行默认的关闭和刷新逻辑
|
parent.layer.close(window.parent.TOrderCheck.layerIndex);
|
if (window.parent.TOrderCheck && window.parent.TOrderCheck.table) {
|
window.parent.TOrderCheck.table.refresh();
|
}
|
}
|
}
|
}, function(data) {
|
Feng.error("派单失败, 系统异常,请稍后重试");
|
swal.close();
|
});
|
|
ajax.set("orderId", this.orderId);
|
ajax.set("driverId", this.selectedDriverId);
|
ajax.set("dispatchType", this.dispatchType);
|
ajax.start();
|
};
|
|
/**
|
* 关闭派单页面
|
*/
|
TOrderCheckDispatch.close = function() {
|
// 优先尝试调用成功回调来关闭,如果没有则执行默认关闭
|
if (window.parent && typeof window.onDispatchSuccess === 'function') {
|
var index = parent.layer.getFrameIndex(window.name);
|
parent.layer.close(index);
|
} else {
|
parent.layer.close(window.parent.TOrderCheck.layerIndex);
|
}
|
};
|