allocatr/public/assets/js/backend/order.js
2025-03-02 17:06:34 +08:00

236 lines
11 KiB
JavaScript

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
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',
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: '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_id', title: __('Area_id')},
{field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'work_tel_id', title: __('Work_tel_id')},
{field: 'worker_id', title: __('Worker_id')},
{field: 'source', title: __('Source')},
{field: 'source_uid', title: __('Source_uid'), operate: 'LIKE'},
{field: 'service_id', title: __('Service_id')},
{field: 'service_title', title: __('Service_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: 'collect', title: __('Collect'), searchList: {"0":__('Collect 0'),"1":__('Collect 1')}, formatter: Table.api.formatter.normal},
{field: 'collect_remark', title: __('Collect_remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'enter_admin_id', title: __('Enter_admin_id')},
{field: 'dispatch_admin_id', title: __('Dispatch_admin_id')},
{field: 'dispatch_type', title: __('Dispatch_type'), searchList: {"10":__('Dispatch_type 10'),"11":__('Dispatch_type 11'),"20":__('Dispatch_type 20')}, formatter: Table.api.formatter.normal},
{field: 'total', title: __('Total'), operate:'BETWEEN'},
{field: 'cost', title: __('Cost'), operate:'BETWEEN'},
{field: 'performance', title: __('Performance'), operate:'BETWEEN'},
{field: 'sb_amount', title: __('Sb_amount'), operate:'BETWEEN'},
{field: 'real_amount', title: __('Real_amount'), operate:'BETWEEN'},
{field: 'cancel_reason_id', title: __('Cancel_reason_id')},
{field: 'cancel_detail', title: __('Cancel_detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'abolish_reason_id', title: __('Abolish_reason_id')},
{field: 'abolish_detail', title: __('Abolish_detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{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: 'payment_time', title: __('Payment_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'finishe_time', title: __('Finishe_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'dispatch_time', title: __('Dispatch_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'delete_time', title: __('Delete_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:"income",
text:"新增收款",
title:"新增收款",
classname:"btn-view btn-dialog",
icon:'fa fa-money',
url: function(row){
return 'orders/income/add?order_id='+row.id
},
dropdown:"更多",
visible:function(row){
return true;
},
refresh:true,
}
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
function parseAndFill() {
// 获取左侧输入框的内容
}
let $input = $("#c-area_id");
let $dropdown = $("#address-list");
let $hiddenField = $("#selected-area-code");
let timer = null; // 定义定时器
// 监听输入框
$input.on("input", function () {
clearTimeout(timer); // 清除上次的定时器
let keyword = $(this).val().trim();
if (keyword.length === 0) {
$dropdown.hide();
return;
}
// 延迟 500 毫秒后执行 AJAX 查询(防止过快触发)
timer = setTimeout(() => {
$.ajax({
url: "/admin/area/search", // 你的 API 地址
type: "GET",
data: { keyword: keyword },
dataType: "json",
success: function (data) {
renderDropdown(data.data);
},
error: function () {
console.error("请求失败");
}
});
}, 200); // 500 毫秒防抖
});
// 渲染城市下拉选项
function renderDropdown(data) {
$dropdown.empty(); // 清空列表
if (data.length === 0){
let $option = $("<li class='dropdown-item'></li>")
.text('未搜索到结果')
.attr("data-value", 0);
$dropdown.append($option);
}else{
data.forEach(item => {
let $option = $("<li class='dropdown-item'></li>")
.text(item.merge_name)
.attr("data-value", item.area_code) // 绑定 area_code
.on("click", function () {
$input.val(item.merge_name); // 选中后填充输入框
$hiddenField.val($(this).attr("data-value")); // 存储 area_code
$dropdown.hide();
});
$dropdown.append($option);
});
}
$dropdown.show(); // 显示下拉框
}
let $inputService = $("#c-service_title");
let $dropdownService = $("#service-list");
let $hiddenFieldService = $("#c-service_id");
let timerService = null; // 定义定时器
$inputService.on("input", function () {
clearTimeout(timerService); // 清除上次的定时器
let keyword = $(this).val().trim();
if (keyword.length === 0) {
$dropdown.hide();
return;
}
// 延迟 500 毫秒后执行 AJAX 查询(防止过快触发)
timerService = setTimeout(() => {
$.ajax({
url: "/admin/area/search", // 你的 API 地址
type: "GET",
data: { keyword: keyword },
dataType: "json",
success: function (data) {
renderDropdownService(data.data);
},
error: function () {
console.error("请求失败");
}
});
}, 200); // 500 毫秒防抖
});
// 渲染城市下拉选项
function renderDropdownService(data) {
$dropdownService.empty(); // 清空列表
if (data.length === 0){
let $option = $("<li class='dropdown-item'></li>")
.text('未搜索到结果')
.attr("data-value", 0);
$dropdownService.append($option);
}else{
data.forEach(item => {
let $option = $("<li class='dropdown-item'></li>")
.text(item.merge_name)
.attr("data-value", item.area_code) // 绑定 area_code
.on("click", function () {
$inputService.val(item.merge_name); // 选中后填充输入框
$hiddenFieldService.val($(this).attr("data-value")); // 存储 area_code
$dropdownService.hide();
});
$dropdownService.append($option);
});
}
$dropdownService.show(); // 显示下拉框
}
// 点击外部隐藏下拉框
$(document).on("click", function (e) {
if (!$(e.target).closest("#c-address, #address-list").length) {
$dropdown.hide();
}
});
return Controller;
});