507 lines
24 KiB
JavaScript
507 lines
24 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, undefined, Backend, Table, Form) {
|
||
|
||
var Controller = {
|
||
index: function () {
|
||
// 初始化表格参数配置
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'orders/dispatch2/index' + location.search,
|
||
//add_url: 'orders/dispatch/add',
|
||
// edit_url: 'orders/dispatch2/edit',
|
||
//del_url: 'orders/dispatc2h/del',
|
||
multi_url: 'orders/dispatch2/multi',
|
||
import_url: 'orders/dispatch2/import',
|
||
table: 'order_dispatch',
|
||
}
|
||
});
|
||
|
||
var table = $("#table");
|
||
|
||
// 初始化表格
|
||
table.bootstrapTable({
|
||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
pk: 'id',
|
||
sortName: 'id',
|
||
fixedColumns: true,
|
||
fixedRightNumber: 1,
|
||
searchFormVisible:true,
|
||
columns: [
|
||
[
|
||
//{checkbox: true},
|
||
{checkbox: true, formatter: function (value, row, index) {
|
||
// 根据 is_selectable 字段控制是否禁用
|
||
// return row.is_selectable ? '' : {disabled: true};
|
||
if(row.is_disabled === true){
|
||
return {
|
||
disabled: true
|
||
};
|
||
}
|
||
return '';
|
||
}},
|
||
|
||
{field: 'id', title: __('Id'), operate: false},
|
||
|
||
{field: 'orderb.order_no', title: __('Order.order_no'), operate: '='},
|
||
|
||
{
|
||
field: 'follow',
|
||
title: '跟进状态',
|
||
searchList: {
|
||
'0':'待跟进',
|
||
"1": '已跟进',
|
||
"2": '已结束',
|
||
},
|
||
formatter: Table.api.formatter.label,
|
||
custom: {
|
||
'0': 'warning', // 待跟进:灰蓝色(默认 Bootstrap info)
|
||
'1': 'success', // 已跟进:绿色
|
||
'2': 'default', // 已结束:红色
|
||
},
|
||
defaultValue: '0'
|
||
//sortable:true,
|
||
},
|
||
|
||
{field: 'record_count', title: '跟进次数',operate: false},
|
||
|
||
{field: 'work_progress', title: '跟进内容',operate: false, class: 'autocontent', formatter:function(value,row)
|
||
{
|
||
if(row.type == 2){
|
||
return value;
|
||
}else{
|
||
if (row.last_record?.remark !== undefined) {
|
||
return row.last_record.remark;
|
||
}
|
||
return '';
|
||
}
|
||
}
|
||
},
|
||
|
||
|
||
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"10":__('Status 10'),"20":__('Status 20'),"25":__('Status 25'),"30":__('Status 30'),"60":__('Status 60'),"-10":__('Status -10'),
|
||
//"-20":__('Status -20'),
|
||
"-30":__('Status -30')},
|
||
formatter: Table.api.formatter.status,
|
||
custom:{25:"red"}
|
||
},
|
||
{field: 'orderb.customer', title: __('Order.customer'), operate: 'like'},
|
||
{field: 'orderb.source_shop', title: __('Order.source_shop'), operate: 'like'},
|
||
{field: 'orderb.tel', title: __('Order.tel'), operate: 'like'},
|
||
|
||
{field: 'worker_name', title: __('Worker_name'), operate: 'LIKE'},
|
||
{field: 'worker_tel', title: __('Worker_tel'), operate: 'LIKE'},
|
||
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('自动')}, formatter: Table.api.formatter.normal
|
||
// defaultValue: '1'
|
||
},
|
||
|
||
|
||
{field: 'got_time', title: __('接单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
|
||
{field: 'plan_time', title: __('Plan_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,
|
||
formatter:function(value,row,index){
|
||
if(row.status == 25){
|
||
return' <span style="color:red;font-weight: bold">'+value+'</span>';
|
||
}else{
|
||
return value;
|
||
}
|
||
}},
|
||
|
||
|
||
{field: 'worker_remark', title: __('师傅备注'), operate: false},
|
||
{
|
||
field: 'is_finish_today',
|
||
title: '今日完成',
|
||
searchList: {
|
||
'0':'不能',
|
||
"1": '能',
|
||
},
|
||
formatter: Table.api.formatter.label,
|
||
custom: {
|
||
'0': 'warning',
|
||
'1': 'success',
|
||
},
|
||
},
|
||
{field: 'work_progress', title: __('当前施工进度'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
|
||
|
||
//{field: 'order.source_shop', title: __('Order.source_shop'), operate: '='},
|
||
// {field: 'order.source', title: __('Order.source')},
|
||
|
||
{field: 'orderb.address', title: __('Order.address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
|
||
|
||
{field: 'orderb.item_title', title: __('Order.item_title'), operate: 'like'},
|
||
{field: 'orderb.detail', title: __('Order.detail'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
|
||
|
||
{field: 'order.images', title: __('Order.images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
|
||
{field: 'arrive_time', title: __('上门时间'), operate:false, addclass:'datetimerange', autocomplete:false},
|
||
{field: 'arrive_image', title: __('上门照片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
|
||
|
||
{field: 'admin_user', title: __('Admin_user'), operate: 'LIKE'},
|
||
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
//{field: 'update_time', title: __('Update_time'), operate:false, addclass:'datetimerange', autocomplete:false},
|
||
{field: 'estimated_finish_time', title: __('预估完成时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
|
||
{field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
|
||
{field: 'area_id', title: __('地区'), searchList: function (column) {
|
||
return Template('categorytpl', {});
|
||
}, formatter: function (value, row, index) {
|
||
return '无';
|
||
}, visible: false
|
||
},
|
||
|
||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
|
||
|
||
align:'left',
|
||
buttons: [
|
||
|
||
{
|
||
name: 'dispatchlog',
|
||
text:"查看轨迹图",
|
||
title:"查看轨迹图",
|
||
icon: 'fa fa-list',
|
||
url: function(row){
|
||
return 'orders/dispatchlog/index?dispatch_id='+row.id;
|
||
},
|
||
extend: 'data-toggle="tooltip" data-container="body"',
|
||
classname: 'btn btn-xs btn-default btn-dialog',
|
||
visible:function(row){
|
||
return true;
|
||
}
|
||
},
|
||
|
||
{
|
||
name: 'addrecord',
|
||
text:"跟进",
|
||
title:"跟进信息",
|
||
icon: 'fa fa-pencil',
|
||
url: 'orders/dispatchrecord/add',
|
||
extend: 'data-toggle="tooltip" data-container="body"',
|
||
classname: 'btn btn-xs btn-warning btn-dialog',
|
||
visible:function(row){
|
||
/*if(row.btn_record){
|
||
return true;
|
||
}
|
||
return false;*/
|
||
return row.btn_record;
|
||
}
|
||
},
|
||
|
||
{
|
||
name: 'finish',
|
||
text:"完成",
|
||
title:"完成当前任务",
|
||
icon: 'fa fa-check',
|
||
url:'orders/dispatch2/finish',
|
||
extend: 'data-toggle="tooltip" data-container="body"',
|
||
classname: 'btn btn-xs btn-success btn-dialog',
|
||
visible:function(row){
|
||
if(row.btn_finished){
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
},
|
||
|
||
{
|
||
name: 'deleteOrder',
|
||
text: '取消订单',
|
||
title: '取消订单',
|
||
classname: 'btn btn-dialog',
|
||
icon: 'fa fa-trash',
|
||
url: function(row){
|
||
return 'order/delete/ids/'+row.order_id;
|
||
},
|
||
|
||
dropdown: "更多",
|
||
visible: function (row) {
|
||
//return true;
|
||
if (row.orderb.status >= 0 && row.orderb.status < 60 && row.status >=0 && row.status < 60) {
|
||
return true;
|
||
}
|
||
return false;
|
||
},
|
||
},
|
||
{
|
||
name:"error",
|
||
text:"订单报错",
|
||
title:"订单报错",
|
||
extend: 'data-toggle="tooltip" data-container="body"',
|
||
classname: 'btn btn-dialog',
|
||
icon: 'fa fa-bolt',
|
||
url: function(row) {
|
||
return 'order/addAbnormal/ids/' + row.order_id;
|
||
},
|
||
refresh:true,
|
||
dropdown: "更多",
|
||
visible: function (row) {
|
||
return true;
|
||
if (row.orderb.status != 60 && row.status >=0 && row.status < 60) {
|
||
return true;
|
||
}
|
||
return false;
|
||
},
|
||
},
|
||
{
|
||
name: 'invoice',
|
||
text: '申请开票',
|
||
title: '申请开票',
|
||
classname: 'btn btn-dialog',
|
||
icon: 'fa fa-send',
|
||
url: function(row){
|
||
return 'order/invoice/ids/'+row.order_id;
|
||
},
|
||
dropdown: "更多",
|
||
|
||
visible: function (row) {
|
||
return true;
|
||
if (row.orderb.status == 60 && row.status>=0) {
|
||
return true;
|
||
}
|
||
return false;
|
||
},
|
||
},
|
||
{
|
||
name: 'aftersale',
|
||
text: '申请售后',
|
||
title: '申请售后',
|
||
classname: 'btn btn-dialog',
|
||
icon: 'fa fa-phone-square',
|
||
url: function(row){
|
||
return 'aftersales/aftersale/add/ids/'+row.order_id;
|
||
},
|
||
dropdown: "更多",
|
||
visible: function (row) {
|
||
return true;
|
||
if (row.orderb.status !== -10 && row.orderb.status !== 70) {
|
||
return true;
|
||
}
|
||
return false;
|
||
},
|
||
},
|
||
],
|
||
|
||
}
|
||
]
|
||
]
|
||
});
|
||
|
||
// 为表格绑定事件
|
||
Table.api.bindevent(table);
|
||
table.off('dbl-click-row.bs.table');
|
||
$("#select_city").on("cp:updated", function () {
|
||
var citypicker = $(this).data("citypicker");
|
||
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
|
||
$("#select_area_id").val(code);
|
||
});
|
||
|
||
// 获取选中项
|
||
$(document).on("click", ".btn-cancel-selected", function () {
|
||
//Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
|
||
|
||
// 获取选中项的 ID
|
||
var selectedData = Table.api.selecteddata(table);
|
||
var selectedIds = selectedData.map(item => item.id); // 假设每行数据有 `id` 字段
|
||
|
||
if (selectedIds.length === 0) {
|
||
Layer.alert("请先选择至少一项数据!");
|
||
return;
|
||
}
|
||
|
||
// 弹出确认框并要求输入文本
|
||
|
||
Layer.open({
|
||
type: 1,
|
||
title: '请输入操作理由',
|
||
area: ['520px', '280px'], // 宽高可调
|
||
btn: ['提交', '取消'],
|
||
content: '<div style="padding: 20px;">' +
|
||
'<div style="margin-bottom: 10px; color: #f39c12; font-size: 14px;">' +
|
||
'提示:取消后该订单会重新进入待派单状态' +
|
||
'</div>' +
|
||
//'<input id="input-title" data-field="title" data-params=\'{"custom[type]":"1"}\' data-rule="required" data-source="setting/abnormal/index" class="form-control selectpage" type="text" value="">'+
|
||
Config.abnormal_select +
|
||
'<textarea style="margin-top: 10px" id="input-reason" class="form-control" data-rule="required" rows="2" placeholder="请输入操作理由"></textarea>' +
|
||
'</div>',
|
||
yes: function(index, layero) {
|
||
var inputTitle = $("#reason_title").val()+',';
|
||
var inputValue = $("#input-reason").val().trim();
|
||
|
||
if (!inputValue) {
|
||
Layer.msg('输入内容不能为空!');
|
||
return;
|
||
}
|
||
inputValue = inputTitle + inputValue
|
||
|
||
|
||
Layer.close(index);
|
||
|
||
var loadingIndex = Layer.load(1, {
|
||
shade: [0.2, '#ccc']
|
||
});
|
||
|
||
$.ajax({
|
||
url: 'orders/dispatch2/del',
|
||
type: 'POST',
|
||
data: {
|
||
ids: selectedIds, // 确保 selectedIds 已定义
|
||
reason: inputValue
|
||
},
|
||
success: function(response) {
|
||
Layer.close(loadingIndex);
|
||
if (response.code == 1) {
|
||
Toastr.success(response.message || "操作成功!");
|
||
table.bootstrapTable('refresh');
|
||
} else {
|
||
Toastr.error(response.msg || "操作失败!");
|
||
}
|
||
},
|
||
error: function() {
|
||
Layer.close(loadingIndex);
|
||
Toastr.error("操作失败,请重试!");
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
// 获取选中项
|
||
$(document).on("click", ".btn-add-normal", function () {
|
||
// 获取选中项的 ID
|
||
var selectedData = Table.api.selecteddata(table);
|
||
var selectedIds = selectedData.map(item => item.id); // 假设每行数据有 `id` 字段
|
||
|
||
if (selectedIds.length === 0) {
|
||
Layer.alert("请先选择至少一项数据!");
|
||
return;
|
||
}
|
||
|
||
if(selectedIds.length > 1){
|
||
Layer.alert("创建异常,一次只能选择一条订单!");
|
||
return;
|
||
}
|
||
|
||
// 拼接 ids 到 URL 后面
|
||
var url = 'orders/abnormal/add?ids=' + selectedIds.join(',');
|
||
|
||
// 打开弹窗
|
||
Fast.api.open(
|
||
url,
|
||
"新增订单异常", // 弹窗标题
|
||
{
|
||
area: ['800px', '600px'] // 设置弹窗宽度和高度,可以根据需求调整
|
||
}
|
||
);
|
||
});
|
||
|
||
|
||
// 默认设置 type=1,并触发表格筛选
|
||
if (typeof Fast.api.query !== 'undefined' && !Fast.api.query('type')) {
|
||
// 修改 URL 参数为 type=1
|
||
// Fast.api.replace('type', '1');
|
||
|
||
// 主动触发 tab 点击事件,自动选中“手动派单”并刷新数据
|
||
setTimeout(function () {
|
||
$('.nav-tabs[data-field="type"] a[data-value="1"]').trigger('click');
|
||
}, 10);
|
||
}
|
||
|
||
},
|
||
add: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
edit: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
finish: function () {
|
||
Controller.api.bindevent();
|
||
|
||
console.log("sb:init...");
|
||
// 判断 #c-action 是否存在且有值
|
||
const $action = $("#c-action");
|
||
if ($action.length && $action.val()) {
|
||
function calculatePerformance() {
|
||
//console.log("sb:计算利润...");
|
||
const orderOnlineAmount = parseFloat($("#order-online-amount").val()) || 0;
|
||
//console.log("sb:计算利润:预收款..."+orderOnlineAmount);
|
||
const onlineAmountLast = parseFloat($("#c-online_total").val()) || 0; //线上尾款
|
||
//console.log("sb:计算利润:线上尾款..."+onlineAmountLast);
|
||
const offlineAmount = parseFloat($("#c-total").val()) || 0; //线下尾款
|
||
//console.log("sb:计算利润:线下尾款..."+offlineAmount);
|
||
const cost = parseFloat($("#order-cost").val()) || 0; //成本
|
||
//console.log("sb:计算利润:师傅成本..."+cost);
|
||
const materialCost = parseFloat($("#order-material_cost").val()) || 0;//材料
|
||
//console.log("sb:计算利润:材料成本..."+materialCost);
|
||
const performance = (orderOnlineAmount + onlineAmountLast + offlineAmount) - (cost + materialCost);
|
||
|
||
$("#c-performance").val(performance.toFixed(2));
|
||
}
|
||
|
||
/* ["c-online_total", "c-total", "order-cost", "order-material_cost"].forEach(function(id) {
|
||
$("#" + id).on("input", calculatePerformance);
|
||
});*/
|
||
|
||
$('#c-online_total, #c-total, #order-cost, #order-material_cost').on('input', function () {
|
||
//calcProfit();
|
||
calculatePerformance();
|
||
});
|
||
|
||
// 页面加载时先算一次
|
||
calculatePerformance();
|
||
}
|
||
},
|
||
addrecord: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
dispatchlog: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
|
||
|
||
addabnormal: function () {
|
||
Form.api.bindevent($("#add-form"));
|
||
},
|
||
deleteOrder: function () {
|
||
Form.api.bindevent($("form[role=form]"));
|
||
},
|
||
invoice: function () {
|
||
function toggleInvoiceFields() {
|
||
const type = $('#c-source').val();
|
||
if (type === '1') {
|
||
// 公司发票
|
||
$('#c-tax_number').closest('.form-group').show();
|
||
$('#c-company_address').closest('.form-group').show();
|
||
$('#c-company_phone').closest('.form-group').show();
|
||
$('#c-bank_name').closest('.form-group').show();
|
||
$('#c-bank_account').closest('.form-group').show();
|
||
} else {
|
||
// 个人发票
|
||
$('#c-tax_number').closest('.form-group').hide();
|
||
$('#c-company_address').closest('.form-group').hide();
|
||
$('#c-company_phone').closest('.form-group').hide();
|
||
$('#c-bank_name').closest('.form-group').hide();
|
||
$('#c-bank_account').closest('.form-group').hide();
|
||
}
|
||
}
|
||
// 初始化时执行一次
|
||
toggleInvoiceFields();
|
||
|
||
// 监听 select 改变
|
||
$('#c-source').on('change',function () {
|
||
toggleInvoiceFields();
|
||
});
|
||
Form.api.bindevent($("form[role=form]"));
|
||
},
|
||
|
||
|
||
api: {
|
||
bindevent: function () {
|
||
Form.api.bindevent($("form[role=form]"));
|
||
}
|
||
}
|
||
};
|
||
return Controller;
|
||
});
|