<!DOCTYPE html>
|
<html>
|
|
<head>
|
<meta charset="UTF-8">
|
<meta name="renderer" content="webkit">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
<meta name="viewport"
|
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
|
<title>下单设备列表</title>
|
<link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
|
<link rel="stylesheet" type="text/css" href="css/admin.css" />
|
<style>
|
.layui-table-cell {
|
height: auto;
|
white-space: normal;
|
}
|
#add_client{
|
padding: 10px;
|
}
|
</style>
|
</head>
|
|
<body>
|
<div class="page-content-wrap">
|
<form class="layui-form" action="" lay-filter='search'>
|
<div class="layui-form-item">
|
<div class="layui-inline">
|
<input type="text" name="account" id="account" placeholder="按登录账号搜索" autocomplete="off"
|
class="layui-input">
|
</div>
|
<div class="layui-inline">
|
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="search" id="search"><i class="layui-icon layui-icon-search"></i>搜索</button>
|
<a href="javascript:void();" class="layui-btn layui-btn-warm" onclick="showCreateClient()"><i class="layui-icon layui-icon-add-circle"></i> 添加设备</a>
|
</div>
|
</div>
|
</form>
|
<div class="layui-form" id="table-list">
|
<table class="layui-table" lay-even lay-skin="nob" id="table" lay-filter="table">
|
|
</table>
|
</div>
|
</div>
|
|
<div id="add_client" style="display: none;">
|
<form class="layui-form" action="" lay-filter='add-client'>
|
<div class="layui-form-item">
|
<label class="layui-form-label">默认密码</label>
|
<div class="layui-input-block">
|
<input type="password" name="pwd" required lay-verify="required" placeholder="输入默认密码" autocomplete="off" class="layui-input">
|
</div>
|
</div>
|
<div class="layui-form-item">
|
<label class="layui-form-label">数量</label>
|
<div class="layui-input-block">
|
<input type="text" name="count" required lay-verify="required|num" placeholder="输入创建的数量" autocomplete="off" class="layui-input">
|
</div>
|
</div>
|
<div class="layui-form-item">
|
<div class="layui-input-block">
|
<button class="layui-btn" lay-submit lay-filter="add-client">立即创建</button>
|
</div>
|
</div>
|
</form>
|
</div>
|
|
<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
|
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
|
<script>
|
// 修改设备信息
|
function updateClient(id) {
|
var layerIndex = layer.open({
|
title: "修改下单设备信息",
|
type: 2,
|
area: ['600px', '500px'],
|
shade: 0.3,
|
shadeClose: false,
|
resize: false,
|
content: 'order-client-update.html?id=' + id,
|
btn: ['确定', '取消'],
|
yes: function(index) {
|
//submit方法为弹框内容中的方法
|
window["layui-layer-iframe" + index].submit(function(res) {
|
let fdata = {
|
id: id
|
};
|
for (let key in res) {
|
if (key.indexOf(".") >= 0) {
|
let k1 = key.split(".")[0];
|
let k2 = key.split(".")[1];
|
if (k1 in fdata) {
|
} else {
|
fdata[k1] = {};
|
}
|
fdata[k1][k2] = res[key];
|
} else {
|
fdata[key] = res[key]
|
}
|
}
|
for (let key in fdata) {
|
if (typeof (fdata[key]) == 'object') {
|
fdata[key] = JSON.stringify(fdata[key]);
|
}
|
}
|
try {
|
var loadIndex = layer.load(1);
|
$.post("/admin/api/clientinfo/js2/update", fdata, function(response) {
|
layer.close(loadIndex);
|
if (response.code == 0) {
|
layer.close(layerIndex);
|
layer.msg("更改成功");
|
// 重新加载表格
|
tableIns.reload();
|
} else {
|
layer.msg(response.msg);
|
}
|
}, 'json').fail(function(jqXHR, textStatus, errorThrown) {
|
layer.close(loadIndex);
|
layer.msg("网络请求失败");
|
});
|
} catch (e) {
|
console.log(e);
|
}
|
});
|
},
|
cancel: function() {
|
}
|
});
|
}
|
|
|
function showCreateClient(){
|
// 创建设备
|
var index = layer.open({
|
type:1,
|
title:"设备账号创建",
|
content: $("#add_client"),
|
end:function(e){
|
$("#add_client").css("display","none");
|
}
|
});
|
}
|
|
layui.use(['form', 'jquery', 'layer', 'table'], function() {
|
var table = layui.table;
|
var form = layui.form;
|
var $ = layui.jquery;
|
|
let table_option = {
|
elem: '#table',
|
url: '/admin/api/clientinfo/js2/list', //数据接口
|
where: {
|
'account': $("#account").val()
|
},
|
parseData: function(res) { //res 即为原始返回的数据
|
let flist = new Array();
|
var list = res.data.list;
|
list.forEach(function(e) {
|
var fdata = {}
|
for (let key in e.client) {
|
// 判断属性是否是对象自身的属性而非继承的属性
|
if (e.client.hasOwnProperty(key)) {
|
fdata["client." + key] = e.client[key];
|
}
|
}
|
|
if (e.additionalInfo != null) {
|
for (let key in e.additionalInfo) {
|
if (e.additionalInfo.hasOwnProperty(key)) {
|
fdata["additionalInfo." + key] = e.additionalInfo[key];
|
}
|
}
|
}
|
flist.push(fdata);
|
});
|
return {
|
"code": res.code, //解析接口状态
|
"msg": res.msg, //解析提示文本
|
"count": res.data.count, //解析数据长度
|
"data": flist //解析数据列表
|
}
|
},
|
page: true, //开启分页
|
cols: [
|
[ //表头
|
{
|
field: 'client.id',
|
title: '设备ID',
|
width: 100,
|
fixed: 'left'
|
},{
|
field: 'client.name',
|
title: '设备名称',
|
width: 100,
|
fixed: 'left'
|
},
|
{
|
field: 'client.account',
|
title: '登录账号',
|
width: 150
|
},
|
{
|
field: 'additionalInfo.mobile',
|
title: '手机号',
|
width: 120
|
},
|
{
|
field: 'additionalInfo.alipayAccount',
|
title: '支付宝账号',
|
width: 180
|
},
|
{
|
field: 'client.createTime',
|
title: '创建时间',
|
width: 180
|
}, {
|
field: 'client.activeTime',
|
title: '活跃时间',
|
width: 180
|
},
|
{
|
field: '',
|
title: '操作',
|
width: 120,
|
fixed: 'right',
|
align: 'center',
|
templet: function(d) {
|
return '<div><a href="javascript:void(0)" onclick="updateClient(' + d["client.id"] + ')" class="layui-table-link">修改</a></div>';
|
}
|
}
|
]
|
]
|
};
|
|
//第一个实例
|
let tableIns = table.render(table_option);
|
|
//监听提交
|
form.on('submit(search)', function(data) {
|
tableIns.reload({
|
where: data.field,
|
page: {
|
curr: 1 //重新从第 1 页开始
|
}
|
});
|
return false;
|
});
|
|
form.on('submit(add-client)', function(data) {
|
$.post("/admin/api/clientinfo/js2/add", data.field, function(response) {
|
if (response.code == 0) {
|
layer.msg("添加成功");
|
// 关闭弹窗
|
layer.closeAll('page');
|
// 重新加载表格
|
tableIns.reload();
|
} else {
|
layer.msg(response.msg);
|
}
|
}, 'json').fail(function(jqXHR, textStatus, errorThrown) {
|
layer.msg("网络请求失败");
|
});
|
|
return false;
|
});
|
});
|
</script>
|
</body>
|
|
</html>
|