allocatr/public/assets/js/backend/orders/dispatch.js
2025-03-20 21:39:38 +08:00

264 lines
14 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/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: true,
fixedRightNumber: 1,
columns: [
[
// {checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'tel', title: __('Tel'), 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: __('Area.short_merge_name'), 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>`;
}},
]
],
search:false,
commonSearch:false,
});
function getQueryData(){
return $('#select-form').serialize();
}
$("#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() {
table.bootstrapTable('refresh',{
url:$.fn.bootstrapTable.defaults.extend.index_url +'?' + getQueryData(),
});
});
$("#reset_btn").on("click", function() {
$("#c-city-search").citypicker('reset');
$("#area_id").val('');
$("#citem").val('').selectpicker('refresh');
$("#keyword").val('');
console.log(1);
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');
});
// 为表格绑定事件
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;
});