223 lines
7.7 KiB
JavaScript
Executable File
223 lines
7.7 KiB
JavaScript
Executable File
layui.use(['form', 'table'], function () {
|
|
var $ = layui.jquery,
|
|
form = layui.form,
|
|
table = layui.table;
|
|
// 获取当前语言
|
|
var currentLang = localStorage.getItem('language') || 'zh';
|
|
var lang = langConfig[currentLang];
|
|
var operationBar = $('#currentTableBar').html();
|
|
if (operationBar) {
|
|
var newHtml = operationBar
|
|
.replace(/编辑/g, lang.carlist.operations.edit)
|
|
.replace(/删除/g, lang.carlist.operations.delete)
|
|
$('#currentTableBar').html(newHtml);
|
|
}
|
|
var toolbarDemo = $('#toolbarDemo').html();
|
|
if (toolbarDemo) {
|
|
var newHtmlt = toolbarDemo
|
|
.replace(/添加/g, lang.userlist.add)
|
|
$('#toolbarDemo').html(newHtmlt);
|
|
}
|
|
var tableInitb = table.render({
|
|
elem: '#currentTableId',
|
|
url: lang.baseUrl+'console/models/list',
|
|
headers: {
|
|
Authorization: 'Bearer ' + sessionStorage.tokencar,
|
|
lang:localStorage.getItem('language')?localStorage.getItem('language'):"zh"
|
|
},
|
|
toolbar: '#toolbarDemo',
|
|
defaultToolbar: ['filter', 'exports', 'print', {
|
|
title: '提示',
|
|
layEvent: 'LAYTABLE_TIPS',
|
|
icon: 'layui-icon-tips'
|
|
}],
|
|
parseData: function(res) { //res 即为原始返回的数据
|
|
console.log(res)
|
|
return {
|
|
"code": 0, //解析接口状态
|
|
"msg": 'message', //解析提示文本
|
|
"count": res.data.meta.total, //解析数据长度
|
|
"data": res.data.list //解析数据列表
|
|
};
|
|
},
|
|
cols: [[
|
|
{type: "checkbox"},
|
|
{field: 'id', title: 'ID', sort: true},
|
|
{field: 'name', title: lang.alllist.name},
|
|
{field: 'brand', title: lang.alllist.brand},
|
|
{field: 'status',title: lang.alllist.status,
|
|
// templet: function(d){
|
|
// var img= '<input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">'
|
|
// return img;
|
|
// },
|
|
templet: function (d) {
|
|
form.on("switch(status)", function (data) {
|
|
let load = layer.load();
|
|
let postData = {};
|
|
postData.status = data.elem.checked ? 1 : 0;
|
|
postData.id = d.id;
|
|
postData.name = d.name;
|
|
self.brandupdate({
|
|
type:'post',
|
|
data: postData,
|
|
successCallBack: function (result) {
|
|
layer.msg(result.message)
|
|
layer.close(load);
|
|
},
|
|
failCallBack: function (result) {
|
|
layer.msg(result.message)
|
|
layer.closeAll('loading');
|
|
tableInitb.reload()
|
|
}
|
|
})
|
|
});
|
|
let checked = d['status'] === 1 ? "checked" : "";
|
|
return '<input type="checkbox" value="'+d.status+'" lay-filter="status" lay-skin="switch" lay-text="" '+checked+'/>';
|
|
}
|
|
},
|
|
|
|
{field: 'sort', title:lang.alllist.sort},
|
|
{field: 'created_at',title: lang.alllist.create_time},
|
|
{title: lang.alllist.operation, minWidth: 150, toolbar: '#currentTableBar', align: "center"}
|
|
]],
|
|
limits: [10, 15, 20, 25, 50, 100],
|
|
limit: 10,
|
|
page: true,
|
|
skin: 'line',
|
|
done: function(res, curr, count){
|
|
window.i18n.updatePageContent();
|
|
}
|
|
});
|
|
// 监听搜索操作
|
|
form.on('submit(data-search-btn)', function (data) {
|
|
var result = JSON.stringify(data.field);
|
|
table.reload('currentTableId', {
|
|
page: {
|
|
curr: 1
|
|
}
|
|
, where: {
|
|
name: data.field.name,
|
|
status: data.field.status,
|
|
}
|
|
}, 'data');
|
|
|
|
return false;
|
|
});
|
|
|
|
/**
|
|
* toolbar监听事件
|
|
*/
|
|
table.on('toolbar(currentTableFilter)', function (obj) {
|
|
if (obj.event === 'add') { // 监听添加操作
|
|
var index = layer.open({
|
|
title: lang.userlist.add,
|
|
type: 2,
|
|
shade: 0.2,
|
|
maxmin:true,
|
|
shadeClose: true,
|
|
area: ['70%', '80%'],
|
|
btn: [lang.audit.confirm, lang.audit.cancel],
|
|
content: '../page/table/modeladd.html',
|
|
yes: function (index, layero) {
|
|
var iframeWindow = window['layui-layer-iframe' + index]
|
|
, submitID = 'saveBtn'
|
|
, submit = layero.find('iframe').contents().find('#' + submitID);
|
|
//监听提交
|
|
iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
|
|
var field = data.field; //获取提交的字段
|
|
self.modelsadd({
|
|
type: 'post',
|
|
data: data.field,
|
|
successCallBack: function (result) {
|
|
layer.msg(result.message)
|
|
layer.close(index); //关闭弹层
|
|
tableInitb.reload()
|
|
},
|
|
failCallBack: function (result) {
|
|
alert(result.message);
|
|
}
|
|
})
|
|
console.log(field)
|
|
|
|
});
|
|
submit.trigger('click');
|
|
}
|
|
});
|
|
$(window).on("resize", function () {
|
|
layer.full(index);
|
|
});
|
|
} else if (obj.event === 'delete') { // 监听删除操作
|
|
var checkStatus = table.checkStatus('currentTableId')
|
|
, data = checkStatus.data;
|
|
layer.alert(JSON.stringify(data));
|
|
}
|
|
});
|
|
|
|
//监听表格复选框选择
|
|
table.on('checkbox(currentTableFilter)', function (obj) {
|
|
console.log(obj)
|
|
});
|
|
|
|
table.on('tool(currentTableFilter)', function (obj) {
|
|
var data = obj.data;
|
|
if (obj.event === 'edit') {
|
|
|
|
var index = layer.open({
|
|
title: lang.audit.edit_title,
|
|
type: 2,
|
|
shade: 0.2,
|
|
maxmin:true,
|
|
shadeClose: true,
|
|
area: ['70%', '80%'],
|
|
btn: [lang.audit.confirm, lang.audit.cancel],
|
|
content: '../page/table/modeledit.html?id='+data.id,
|
|
yes: function(index, layero){
|
|
var iframeWindow = window['layui-layer-iframe'+ index]
|
|
,submitID = 'saveBtn'
|
|
,submit = layero.find('iframe').contents().find('#'+ submitID);
|
|
//监听提交
|
|
iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
|
|
var field = data.field; //获取提交的字段
|
|
self.modelsupdate({
|
|
type:'post',
|
|
data:data.field,
|
|
successCallBack: function(result){
|
|
layer.msg(result.message)
|
|
layer.close(index); //关闭弹层
|
|
tableInitb.reload()
|
|
},
|
|
failCallBack: function(result){
|
|
alert(result.message);
|
|
}
|
|
})
|
|
});
|
|
submit.trigger('click');
|
|
}
|
|
});
|
|
$(window).on("resize", function () {
|
|
layer.full(index);
|
|
});
|
|
return false;
|
|
}else if (obj.event === 'delete') {
|
|
layer.confirm(lang.audit.confirm_delete, function(index) {
|
|
self.modelsdelete({
|
|
type:'post',
|
|
data:{id:data.id},
|
|
successCallBack: function(result){
|
|
layer.msg(result.message, {
|
|
icon: 1,
|
|
time: 1000
|
|
});
|
|
tableInitb.reload()
|
|
},
|
|
failCallBack: function(result){
|
|
alert(result.message);
|
|
window.location.reload()
|
|
}
|
|
})
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
}); |