gz_car_ui/js/car_basic/car_list.js

255 lines
8.1 KiB
JavaScript
Raw Normal View History

2025-01-16 18:47:38 +08:00
let form, table, laydate;
let tableIns;
let pageNum = 1; // 定义分页
layui.use(["form", "table"], function () {
form = layui.form;
table = layui.table;
initTable();
});
// 查询/重置
function queryTable(type) {
if (type === 1) {
let carNum = $('#carNum').val();
let flag = checkValue(carNum);
if (flag) {
$('#carNum').val('');
return layer.msg('车牌号查询包含特殊字符,请重新输入', { icon: 2 });
}
let supName = $('#supName').val();
let flag2 = checkValue(supName);
if (flag2) {
$('#supName').val('');
return layer.msg('供应商查询包含特殊字符,请重新输入', { icon: 2 });
}
reloadTable(1);
} else if (type === 2) {
$('#carNum').val('');
$('#supName').val('');
layui.form.render();
reloadTable(1);
}
}
// 刷新页面数据
function reloadData() {
reloadTable(1);
}
// 重载表格
function reloadTable(pageNum) {
table.reload("currentTableId", {
page: {
curr: pageNum ? pageNum : 1,
},
where: {
encryptedData: JSON.stringify({
'carNum': $('#carNum').val(),
'supName': $('#supName').val(),
}),
},
},
);
}
// 初始化表格
function initTable() {
tableIns = table.render({
elem: "#currentTableId",
id: 'currentTableId',
headers: {
authorization: sessionStorage.getItem("gz-token"),
},
height: "full-170",
url: dataUrl + "backstage/carCar/getCarPageList",
where: {
encryptedData: JSON.stringify({
'carNum': $('#carNum').val(),
'supName': $('#supName').val(),
}),
},
request: {
pageName: 'pageNum',
limitName: 'pageSize'
},
parseData: function (res) { // res 即为原始返回的数据
if (res.code === 401) {
closeWindowOpen();
}
return {
"code": 0, // 解析接口状态
"msg": '获取成功', // 解析提示文本
"count": res.total, // 解析数据长度
"data": res.list // 解析数据列表
};
},
cols: [
[
{
width: '6.9%',
title: "序号",
align: "center",
templet: function (d) {
return d.LAY_NUM;
},
},
{
field: "carNum",
2025-01-17 18:28:32 +08:00
width: '9%',
2025-01-16 18:47:38 +08:00
title: "车牌号",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
},
{
field: "brand",
width: '9%',
title: "车辆品牌",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
},
{
field: "type",
width: '8%',
title: "车辆类型",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
},
{
field: "ton",
2025-01-17 18:28:32 +08:00
width: '11%',
2025-01-16 18:47:38 +08:00
title: "车辆吨位T",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
templet: function (d) {
return (d.ton ? d.ton : 0) + '吨';
},
},
{
field: "xyNum",
width: '8%',
title: "挂靠协议",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
templet: function (d) {
return '<span style="color:#409eff;font-weight:bold;">'+d.xyNum+'</span>';
},
},
{
field: "bxNum",
width: '8%',
title: "车辆保险",
unresize: true,
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
align: "center",
templet: function (d) {
return '<span style="color:#409eff;font-weight:bold;">'+d.bxNum+'</span>';
},
},
{
field: "xszNum",
width: '8%',
title: "行驶证",
unresize: true,
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
align: "center",
templet: function (d) {
return '<span style="color:#409eff;font-weight:bold;">'+d.xszNum+'</span>';
},
},
{
field: "bxDay",
2025-01-17 18:28:32 +08:00
width: '12%',
2025-01-16 18:47:38 +08:00
title: "车辆保险到期日期",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
},
{
field: "supName",
width: '10%',
title: "所属供应商",
unresize: true,
align: "center",
2025-01-17 15:04:06 +08:00
sort:true,
2025-01-16 18:47:38 +08:00
},
{
title: "操作",
2025-01-17 18:28:32 +08:00
width: '10%',
2025-01-16 18:47:38 +08:00
align: "center",
unresize: true,
templet: function (d) {
let html = "";
html += "<a onclick='addOrUpdateCar(" + JSON.stringify(d) + ",3)'>详情</a>";
html += "<div class='splitLine'>|</div><a onclick='addOrUpdateCar(" + JSON.stringify(d) + ",2)'>修改</a>";
html += "<div class='splitLine'>|</div><a style='color:#f56c6c;' onclick='delData(" + JSON.stringify(d) + ")'>删除</a>";
return html;
},
},
],
],
limits: [10, 15, 20, 25, 50, 100],
limit: 10,
page: true,
done: function (res, curr, count) {
pageNum = tableIns.config.page.curr;
table.resize("currentTableId");
},
});
}
// 导出
function exportExcel() {
let params = {
'carNum': $('#carNum').val(),
'supName': $('#supName').val()
}
let url = dataUrl + "backstage/carCar/export";
exportExcelUtil(url, '车辆管理', JSON.stringify(params));
}
// 新增/修改/详情
function addOrUpdateCar(obj, type) {
let title = '', content = './child/car_form.html';
if (type === 1) {
title = '车辆信息新增';
} else if (type === 2) {
title = '车辆信息修改';
content = './child/car_edit_form.html';
} else if (type === 3) {
title = '车辆信息详情';
content = './child/car_detail.html';
}
obj.type = type;
openIframeByParamObj("addOrUpdateCar", title, content, "50%", "92%", obj);
}
// 删除车辆数据
function delData(data) {
layer.confirm("确定删除此条数据吗?", { 'title': '操作提示', move: false }, function () {
let loadingMsg = layer.msg('数据删除中,请稍候...', { icon: 16, scrollbar: false, time: 0 });
let url = dataUrl + "backstage/carCar/deleteCarData"
let obj = { 'id': data.id }
let params = {
encryptedData: JSON.stringify(obj)
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
console.error(result);
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
layer.msg(result.msg, { icon: 1 })
queryTable(1);
} else {
layer.msg(result.msg, { icon: 2 })
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
});
})
}