allocatr/public/assets/js/backend/orders/dispatch.js
2025-07-03 11:34:42 +08:00

402 lines
19 KiB
JavaScript

define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'orders/dispatch/index' + location.search,
add_url: 'orders/dispatch/add',
edit_url: 'orders/dispatch/edit',
del_url: 'orders/dispatch/del',
multi_url: 'orders/dispatch/multi',
import_url: 'orders/dispatch/import',
table: 'order_dispatch',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
//{checkbox: true},
{field: 'id', title: __('Id')},
//{field: 'order_id', title: __('Order_id')},
{field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
{
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
},
// {field: 'worker_id', title: __('Worker_id')},
{field: 'worker_name', title: __('Worker_name'), operate: 'LIKE'},
{field: 'worker_tel', title: __('Worker_tel'), operate: 'LIKE'},
{
field: 'type',
title: __('Type'),
searchList: {"1": __('Type 1')},
formatter: Table.api.formatter.normal
},
{field: 'order.source_shop', title: __('Order.source_shop'), operate: 'LIKE'},
{field: 'order.source', title: __('Order.source')},
{field: 'order.customer', title: __('Order.customer'), operate: 'LIKE'},
{field: 'order.tel', title: __('Order.tel'), operate: 'LIKE'},
{
field: 'order.address',
title: __('Order.address'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{field: 'order.item_title', title: __('Order.item_title'), operate: 'LIKE'},
{
field: 'order.detail',
title: __('Order.detail'),
operate: 'LIKE',
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: 'remark',
title: __('Remark'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{
field: 'plan_time',
title: __('Plan_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false
},
// {field: 'is_notice', title: __('Is_notice'), searchList: {"0":__('Is_notice 0'),"1":__('Is_notice 1')}, formatter: Table.api.formatter.normal},
{
field: 'finish_time',
title: __('Finish_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false
},
// {field: 'admin_id', title: __('Admin_id')},
{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: 'RANGE',
addclass: 'datetimerange',
autocomplete: false
},
{
field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'edit',
text: "修改",
title: "修改",
icon: 'fa fa-pencil',
//title: __('Edit'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-success btn-editone',
visible: function (row) {
if (row.btn_edit) {
return true;
}
return false;
}
},
{
name: "income",
text: "新增收款",
title: "新增收款",
classname: "btn-view btn-dialog",
extend: 'data-toggle="tooltip" data-container="body"',
icon: 'fa fa-money',
url: function (row) {
return 'orders/income/add?order_id=' + row.order_id;
},
dropdown: "更多",
visible: function (row) {
if (row.btn_income) {
return true;
}
return false;
},
refresh: true,
},
{
name: "abnormal",
text: "创建异常",
title: "创建异常",
classname: "btn-add btn-dialog",
extend: 'data-toggle="tooltip" data-container="body"',
icon: 'fa fa-question',
url: function (row) {
return "orders/abnormal/add?order_id=" + row.order_id
},
dropdown: "更多",
visible: function (row) {
if (row.btn_income) {
return true;
}
return false;
},
//refresh:true,
},
{
name: 'del',
text: "取消任务",
title: "取消任务",
icon: 'fa fa-trash red',
//title: __('Del'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: '',
dropdown: "更多",
click: function (data, row) {
layer.prompt({
formType: 1,
value: '',
title: '请输入备注',
maxlength: 140,
}, function (value, index, elem) {
var url = 'orders/dispatch/del' + row.id;
var options = {url: url, data: {remark: value}};
Fast.api.ajax(options, function (data, ret) {
// table.trigger("uncheckbox");
table.bootstrapTable('refresh');
})
}, function (data, ret) {
var error = $(this).data("error") || $.noop;
if (typeof error === 'function') {
if (false === error.call(this, data, ret)) {
return false;
}
}
});
layer.close(index);
},
visible: function (row) {
if (row.btn_cancel) {
return true;
}
return false;
},
},
],
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'workers/worker/dispatchList',
table: 'worker',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
pk: 'id',
sortName: 'id',
fixedColumns: false,
fixedRightNumber: 1,
columns: [
[
// {checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'finish_order', title: '接单总数'},
{field: 'doing_order', title: '当前服务订单数'},
{field: 'star', title: '星级'},
{field: 'tel', title: '电话', operate: 'LIKE'},
// {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
//{field: 'area_id', title: __('Area_id')},
//{field: 'lng', title: __('Lng'), operate:'BETWEEN'},
//{field: 'lat', title: __('Lat'), operate:'BETWEEN'},
{field: 'area.short_merge_name', title: '区域', operate: 'LIKE'},
// {field: 'deposit_amount', title: __('Deposit_amount'), operate:'BETWEEN'},
{
field: 'id', title: '操作', formatter: function (id) {
return `<p class="btn btn-primary tab_chose" data-id="${id}">选择</p>
<p class="btn btn-info tab_dispatch" data-id="${id}">派单</p>`;
}
},
]
],
search: false,
commonSearch: false,
});
function getQueryData() {
const
area_id = $('#area_id').val(),
item_id = $('#item_id').data('myvalue'),
keyword = $('#keyword').val()
;
let res = '';
if (area_id && area_id !== '') {
res += '&area_id=' + area_id;
}
if (item_id && item_id !== '') {
res += '&item_id=' + item_id;
}
if (keyword && keyword !== '') {
res += '&keyword=' + keyword;
}
return res;
}
$("#c-city-search").on("cp:updated", function () {
var citypicker = $(this).data("citypicker");
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
// table.bootstrapTable('refresh',{query: {area_code: code}});
$('#area_id').val(code);
});
$("#search_btn").on("click", function () {
console.log($.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData());
table.bootstrapTable('refresh', {
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
});
});
var _data = items;
$("#reset_btn").on("click", function () {
$("#c-city-search").citypicker('reset');
$("#area_id").val('');
$("#item_id").data('myvalue', '');
$("#keyword").val('');
table.bootstrapTable('refresh', {
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
});
});
Form.events.citypicker($("#select-form"));
$(document).on('click', '.tab_chose', function () {
var dataId = $(this).data('id'); // 获取 data-id 的值
const worker = Table.api.getrowbyid(table, dataId);
$('#c-worker_name').val(worker.name + '--' + worker.tel).trigger('input').trigger('change');
$('#c-worker_id').val(worker.id).trigger('input').trigger('change');
});
$(document).on('click', '.tab_dispatch', function () {
var dataId = $(this).data('id'); // 获取 data-id 的值
const worker = Table.api.getrowbyid(table, dataId);
$('#c-worker_name').val(worker.name + '--' + worker.tel).trigger('input').trigger('change');
$('#c-worker_id').val(worker.id).trigger('input').trigger('change');
// 弹出确认框
Layer.confirm("确认派单给 " + worker.name + " 吗?", {
icon: 3,
title: '确认派单'
}, function (index) {
// 用户确认后再进行校验和提交
const res = $("#add-form").isValid();
if (res) {
Form.api.submit($("#add-form"), function (data) {
var index = parent.Layer.getFrameIndex(window.name);
parent.Layer.close(index); // 关闭当前弹窗
});
} else {
Toastr.error('请完整填写表单');
}
Layer.close(index); // 关闭确认弹窗
});
});
$('#add_worker').on('click',function (){
Fast.api.open('workers/worker/add?type=2', '添加工人',{
callback: function (value) {
table.bootstrapTable('refresh', {
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
});
}
});
});
$('#item_id').zdCascader({
data: _data,
onChange: function ($this, data, allPathData) {
$('#item_id').data('myvalue', data.value);
},
// clear:true,
// clickParent:true
});
$('#item_id').val($('#item_id').data('value'));
// 为表格绑定事件
Table.api.bindevent(table);
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("#add-form"), null, null, function (data) {
// Form.api.submit($("#add-form"));
// return false;
});
Form.api.bindevent($("#select-form"));
}
}
};
return Controller;
});