allocatr/public/assets/js/backend/order.js
2025-04-16 17:51:41 +08:00

420 lines
18 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function ($, undefined, Backend, Table, Form) {
function clearInfo() {
$('[name^="row["]').val('');
$("#c-city").citypicker('reset');
$(".selectpicker").val('').selectpicker('refresh');
}
function copyToClipboard(text) {
// 创建一个隐藏的 textarea 元素
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
// 选中内容并复制
textarea.select();
document.execCommand('copy');
// 移除 textarea 元素
document.body.removeChild(textarea);
Toastr.info('复制成功');
}
// 拼装文本
function assembleOrderMessage(data) {
const message = `
【订单详情】
录单员: ${data.user.nickname}
订单编号: ${data.order_no}
客户姓名: ${data.customer}
客户电话: ${data.tel}
订单状态: ${data.status_text}
地域: ${data.area.merge_name}
详细地址: ${data.address}
派单方式: ${data.dispatch_type === 1 ? '手动派单' : '自动派单'}
收款方式: ${data.collect_text || '未收款'}
订单来源: ${data.source_shop}
服务名称: ${data.item_title}
请查收以上订单信息。`;
return message;
}
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'order/index' + location.search,
add_url: 'order/add',
edit_url: 'order/edit',
//del_url: 'order/del',
multi_url: 'order/multi',
import_url: 'order/import',
push_url: 'order/status',
addabnormal: 'order/addAbnormal',
table: 'order',
}
});
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: 'user.nickname', title: '录单员'},
{field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
{field: 'customer', title: __('Customer'), operate: 'LIKE'},
{field: 'tel', title: __('Tel'), operate: 'LIKE'},
{
field: 'status',
title: __('Status'),
searchList: {
"10": __('Status 10'),
"20": __('Status 20'),
"30": __('Status 30'),
"40": __('Status 40'),
"50": __('Status 50'),
"-10": __('Status -10'),
"-20": __('Status -20'),
"-30": __('Status -30')
},
formatter: Table.api.formatter.status
},
{field: 'area.merge_name', title: __('Area_id')},
{
field: 'address',
title: __('Address'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{
field: 'dispatch_type',
title: '派单方式',
searchList: {
"1": '手动派单',
"2": '自动派单',
},
formatter: Table.api.formatter.label
},
{
field: 'receive_type',
title: '收款方式',
searchList: {
"1": '已收全款',
"2": '已收定金',
},
formatter: Table.api.formatter.label
},
// {field: 'worker_id', title: __('Worker_id')},
{field: 'source_shop', title: __('Source')},
// {field: 'source_uid', title: __('Source_uid'), operate: 'LIKE'},
{field: 'item_title', title: __('Item_title'), operate: 'LIKE'},
{
field: 'detail',
title: __('Detail'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{
field: 'remark',
title: __('Remark'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{
field: 'images',
title: __('Images'),
operate: false,
events: Table.api.events.image,
formatter: Table.api.formatter.images
},
{
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,
align: "left",
buttons: [
{
name: 'edit',
text: "编辑",
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs button-edit btn-editone',
},
{
name: 'push',
icon: 'fa fa-copy',
title: '复制',
text: "复制",
url: 'order/copy',
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs button-copy btn-dialog',
callback: function ($data) {
console.log($data);
},
dropdown: "更多"
},
{
name: "dispatch",
text: "派单",
title: "派单",
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs button-dispatch btn-dialog',
//classname:"btn-view btn-dialog",
icon: 'fa fa-add',
url: function (row) {
return 'orders/dispatch/add?order_id=' + row.id;
},
visible: function (row) {
if (row.status == 10) {
return true;
}
return false;
},
refresh: true,
},
{
name: "reminder",
text: "催单",
title: "派单",
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs button-remind btn-magic btn-ajax',
icon: 'fa fa-bolt',
url: 'order/reminder',
dropdown: "更多",
success: function (data, ret) {
if (ret.code === 1) {
Layer.alert('催单成功');
} else {
Layer.alert(ret.msg);
}
return false;
//如果需要阻止成功提示则必须使用return false;
//return false;
},
error: function (data, ret) {
console.log(data, ret);
Layer.alert(ret.msg);
return false;
},
visible: function (row) {
if (row.status > 0) {
return true;
}
return false;
},
},
{
name: "copy_text",
text: "复制信息",
title: "复制信息",
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs button-error btn-click',
icon: 'fa fa-text',
click: function (data, item) {
const text = assembleOrderMessage(item);
copyToClipboard(text);
}
}, {
name: 'delete',
text: '取消',
title: '取消',
classname: 'btn btn-xs button-cancel btn-dialog',
icon: 'fa fa-trash',
url: 'order/delete',
dropdown: "更多",
visible: function (row) {
if (row.status >= 0) {
return true;
}
return false;
},
},
{
name: 'invoice',
text: '申请开票',
title: '申请开票',
classname: 'btn btn-xs button-cancel btn-dialog',
icon: 'fa fa-send',
url: 'order/invoice/',
dropdown: "更多",
visible: function (row) {
if (row.status >= 0) {
return true;
}
return false;
},
},
],
}
]
],
});
// 为表格绑定事件
Table.api.bindevent(table);
let cloneQueryParams = null;
//绑定tab事件
$('a[data-toggle="tab"]').on('show.bs.tab', function (event) {
let type = $(this).attr("data-value");
let options = table.bootstrapTable('getOptions');
$('.nav-tabs li').attr('class', '');
$(this).parent().attr("class", 'active');
options.pageNumber = 1;
if (cloneQueryParams == null) {
cloneQueryParams = options.queryParams;
}
options.queryParams = function (params) {
params.type = type;
return cloneQueryParams(params);
};
table.bootstrapTable('refresh', {});
return false;
});
},
add: function () {
$("#mybuttom").on("click", function () {
Form.api.submit($("form[role=form]"));
Toastr.success('录入成功');
return false;
});
Form.api.bindevent($("form[role=form]"), function (success, ret) {
clearInfo();
Toastr.success('操作成功');
return false;
},);
$("#c-city").on("cp:updated", function () {
var citypicker = $(this).data("citypicker");
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
$("#area_id").val(code);
$("#area_name").val(citypicker.getVal());
});
$("[data-toggle='addresspicker']").data("callback", function (res) {
Form.api.target($('#c-address'));
});
var _data = items;
$('#item_id').zdCascader({
data: _data,
onChange: function ($this, data, allPathData) {
// console.log(data,allPathData);
$('#item_id_value').val(data.value);
}
});
$('#item_id').val($('#item_id').data('value')).focus();
$("#smart").on("click", function () {
$.ajax({
url: "order/smart", // 你的 API 地址
type: "GET",
dataType: "json",
data: {
str: $('#smart_text').val()
},
success: function (data) {
if (data.code === 1) {
data = data.data;
if (data.mobile !== '') {
$('#c-tel').val(data.mobile);
}
if (data.name !== '') {
$('#c-customer').val(data.name);
}
if (data.item.id !== 0) {
$('#item_id_value').val(data.item.id);
$('#item_id').val(data.item.item);
}
if (data.idn) {
$('#c-source-id').val(data.idn);
}
let citypicker = $('#c-city');
// $city.citypicker({
// province: data.province,
// city: data.city,
// district: data.region
// });
citypicker.val(data.province + '/' + data.city + '/' + data.region);
citypicker = citypicker.data("citypicker");
citypicker.refresh();
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
$("#area_id").val(code);
$("#area_name").val(citypicker.getVal());
}
},
error: function () {
console.error("请求失败");
}
});
});
},
edit: function () {
Controller.api.bindevent();
},
copy: function () {
Controller.api.bindevent();
},
addabnormal: function () {
console.log('abnormal');
Form.api.bindevent($("#add-form"), null, null, function (data) {
Form.api.submit($("#add-form"));
// console.log(data);
// return false;
});
},
delete: function () {
console.log('delete');
Form.api.bindevent($("form[role=form]"));
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});